diff --git a/config/tilt/dev.Tiltfile b/config/tilt/dev.Tiltfile index 21192f5..eed0db8 100644 --- a/config/tilt/dev.Tiltfile +++ b/config/tilt/dev.Tiltfile @@ -23,3 +23,15 @@ def start(landscape, platform, service, port, live): ] ) + + reverter_image_name = platform + "-" + service + "-reverter" + docker_build( + reverter_image_name, + '.', + dockerfile = './infra/dev.Dockerfile', + entrypoint='bun run ./src/index.ts reverter', + live_update=[ + sync('.', '/app'), + ] + + ) \ No newline at end of file diff --git a/config/tilt/prod.Tiltfile b/config/tilt/prod.Tiltfile index 7f22c41..12683f7 100644 --- a/config/tilt/prod.Tiltfile +++ b/config/tilt/prod.Tiltfile @@ -16,6 +16,14 @@ def start(landscape, platform, service, port, live): dockerfile = './infra/Dockerfile', ) + # build API image + reverter_image_name = platform + "-" + service + "-reverter" + docker_build( + reverter_image_name, + '.', + dockerfile = './infra/Dockerfile', + ) + # Add Link k8s_resource( workload = api_image_name, diff --git a/flake.lock b/flake.lock index b256c40..b9d3edb 100644 --- a/flake.lock +++ b/flake.lock @@ -3,6 +3,35 @@ "atomipkgs": { "inputs": { "dev-atomi": "dev-atomi", + "dev-atomi_classic": "dev-atomi_classic_3", + "dev-npkgs": "dev-npkgs_3", + "dev-npkgs-unstable-05-Jun-2024": "dev-npkgs-unstable-05-Jun-2024", + "dev-npkgs-unstable-05-Oct-2022": "dev-npkgs-unstable-05-Oct-2022_3", + "dev-npkgs-unstable-07-Feb-2024": "dev-npkgs-unstable-07-Feb-2024_3", + "dev-npkgs-unstable-11-Dec-2022": "dev-npkgs-unstable-11-Dec-2022_3", + "fenix": "fenix_3", + "flake-utils": "flake-utils_6", + "npkgs": "npkgs_3", + "npkgs-unstable": "npkgs-unstable_3" + }, + "locked": { + "lastModified": 1720858656, + "narHash": "sha256-k/EE+GrQYP0BDYhdS/YWULMNrewZm4Y7+wWncal4Udk=", + "owner": "kirinnee", + "repo": "test-nix-repo", + "rev": "164d6fd91e41410bfd0d8737ec77388346045665", + "type": "github" + }, + "original": { + "owner": "kirinnee", + "ref": "v27.0.0", + "repo": "test-nix-repo", + "type": "github" + } + }, + "dev-atomi": { + "inputs": { + "dev-atomi": "dev-atomi_2", "dev-atomi_classic": "dev-atomi_classic_2", "dev-npkgs": "dev-npkgs_2", "dev-npkgs-unstable-05-Oct-2022": "dev-npkgs-unstable-05-Oct-2022_2", @@ -28,7 +57,7 @@ "type": "github" } }, - "dev-atomi": { + "dev-atomi_2": { "inputs": { "dev-atomi_classic": "dev-atomi_classic", "dev-npkgs": "dev-npkgs", @@ -97,6 +126,27 @@ "type": "github" } }, + "dev-atomi_classic_3": { + "inputs": { + "flake-utils": "flake-utils_5", + "pkgs": "pkgs_3", + "pkgs_25_Jul_2021": "pkgs_25_Jul_2021_3" + }, + "locked": { + "lastModified": 1689236000, + "narHash": "sha256-MEqyIPlD4ueJji6FtfDs8qqZifM9hyYH1svBs3oxrrc=", + "owner": "kirinnee", + "repo": "test-nix-repo", + "rev": "2d9d80544d2e81ff736fa23345ad0a9cc5a6c8ab", + "type": "github" + }, + "original": { + "owner": "kirinnee", + "ref": "classic", + "repo": "test-nix-repo", + "type": "github" + } + }, "dev-npkgs": { "locked": { "lastModified": 1704290814, @@ -113,6 +163,21 @@ "type": "github" } }, + "dev-npkgs-unstable-05-Jun-2024": { + "locked": { + "lastModified": 1717196966, + "narHash": "sha256-yZKhxVIKd2lsbOqYd5iDoUIwsRZFqE87smE2Vzf6Ck0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "57610d2f8f0937f39dbd72251e9614b1561942d8", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "rev": "57610d2f8f0937f39dbd72251e9614b1561942d8", + "type": "indirect" + } + }, "dev-npkgs-unstable-05-Oct-2022": { "locked": { "lastModified": 1664847737, @@ -143,6 +208,21 @@ "type": "indirect" } }, + "dev-npkgs-unstable-05-Oct-2022_3": { + "locked": { + "lastModified": 1664847737, + "narHash": "sha256-Wxl0CtRH3Vo8+qEZ/PbCcx+9D8wEEi56tJPmROum2ss=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "de80d1d04ee691279e1302a1128c082bbda3ab01", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "rev": "de80d1d04ee691279e1302a1128c082bbda3ab01", + "type": "indirect" + } + }, "dev-npkgs-unstable-07-Feb-2024": { "locked": { "lastModified": 1707092692, @@ -173,6 +253,21 @@ "type": "indirect" } }, + "dev-npkgs-unstable-07-Feb-2024_3": { + "locked": { + "lastModified": 1707092692, + "narHash": "sha256-ZbHsm+mGk/izkWtT4xwwqz38fdlwu7nUUKXTOmm4SyE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "faf912b086576fd1a15fca610166c98d47bc667e", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "rev": "faf912b086576fd1a15fca610166c98d47bc667e", + "type": "indirect" + } + }, "dev-npkgs-unstable-11-Dec-2022": { "locked": { "lastModified": 1670681895, @@ -203,6 +298,21 @@ "type": "indirect" } }, + "dev-npkgs-unstable-11-Dec-2022_3": { + "locked": { + "lastModified": 1670681895, + "narHash": "sha256-kZH9DSU36W4fn1z81a/24JCGkU517TcY50VE0RFJ9k4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f82f0ec1b70b2879c3f3d9a1015a05c73a90a17c", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "rev": "f82f0ec1b70b2879c3f3d9a1015a05c73a90a17c", + "type": "indirect" + } + }, "dev-npkgs_2": { "locked": { "lastModified": 1704290814, @@ -219,6 +329,22 @@ "type": "github" } }, + "dev-npkgs_3": { + "locked": { + "lastModified": 1704290814, + "narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, "fenix": { "inputs": { "nixpkgs": "nixpkgs", @@ -257,6 +383,25 @@ "type": "github" } }, + "fenix_3": { + "inputs": { + "nixpkgs": "nixpkgs_3", + "rust-analyzer-src": "rust-analyzer-src_3" + }, + "locked": { + "lastModified": 1706941198, + "narHash": "sha256-t6/qloMYdknVJ9a3QzjylQIZnQfgefJ5kMim50B7dwA=", + "owner": "nix-community", + "repo": "fenix", + "rev": "28dbd8b43ea328ee708f7da538c63e03d5ed93c8", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -349,6 +494,24 @@ "inputs": { "systems": "systems_5" }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_6": { + "inputs": { + "systems": "systems_6" + }, "locked": { "lastModified": 1705309234, "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", @@ -363,9 +526,27 @@ "type": "github" } }, - "flake-utils_6": { + "flake-utils_7": { "inputs": { - "systems": "systems_6" + "systems": "systems_7" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_8": { + "inputs": { + "systems": "systems_8" }, "locked": { "lastModified": 1701680307, @@ -481,6 +662,22 @@ } }, "nixpkgs_3": { + "locked": { + "lastModified": 1706732774, + "narHash": "sha256-hqJlyJk4MRpcItGYMF+3uHe8HvxNETWvlGtLuVpqLU0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b8b232ae7b8b144397fdb12d20f592e5e7c1a64d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { "locked": { "lastModified": 1693714546, "narHash": "sha256-3EMJZeGSZT6pD1eNwI/6Yc0R4rxklNvJ2SDFcsCnjpM=", @@ -495,7 +692,7 @@ "type": "indirect" } }, - "nixpkgs_4": { + "nixpkgs_5": { "locked": { "lastModified": 1704842529, "narHash": "sha256-OTeQA+F8d/Evad33JMfuXC89VMetQbsU4qcaePchGr4=", @@ -511,7 +708,7 @@ "type": "github" } }, - "nixpkgs_5": { + "nixpkgs_6": { "locked": { "lastModified": 1708475490, "narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=", @@ -575,6 +772,22 @@ "type": "github" } }, + "npkgs-unstable_3": { + "locked": { + "lastModified": 1707092692, + "narHash": "sha256-ZbHsm+mGk/izkWtT4xwwqz38fdlwu7nUUKXTOmm4SyE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "faf912b086576fd1a15fca610166c98d47bc667e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "npkgs_2": { "locked": { "lastModified": 1704290814, @@ -591,6 +804,22 @@ "type": "github" } }, + "npkgs_3": { + "locked": { + "lastModified": 1704290814, + "narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, "pkgs": { "locked": { "lastModified": 1643805626, @@ -651,12 +880,42 @@ "type": "indirect" } }, + "pkgs_25_Jul_2021_3": { + "locked": { + "lastModified": 1627107260, + "narHash": "sha256-CwvSwz3kvpp7uEFyOj2Dq6bdtY6P2N0Bzd7ZVgsIICw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "537678cb1ead06fca831077c3b193566cbc3f406", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "rev": "537678cb1ead06fca831077c3b193566cbc3f406", + "type": "indirect" + } + }, + "pkgs_3": { + "locked": { + "lastModified": 1643805626, + "narHash": "sha256-AXLDVMG+UaAGsGSpOtQHPIKB+IZ0KSd9WS77aanGzgc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "554d2d8aa25b6e583575459c297ec23750adb6cb", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "rev": "554d2d8aa25b6e583575459c297ec23750adb6cb", + "type": "indirect" + } + }, "pre-commit-hooks": { "inputs": { "flake-compat": "flake-compat", - "flake-utils": "flake-utils_6", + "flake-utils": "flake-utils_8", "gitignore": "gitignore", - "nixpkgs": "nixpkgs_4", + "nixpkgs": "nixpkgs_5", "nixpkgs-stable": "nixpkgs-stable" }, "locked": { @@ -676,8 +935,8 @@ "root": { "inputs": { "atomipkgs": "atomipkgs", - "flake-utils": "flake-utils_5", - "nixpkgs": "nixpkgs_3", + "flake-utils": "flake-utils_7", + "nixpkgs": "nixpkgs_4", "nixpkgs-2305": "nixpkgs-2305", "nixpkgs-feb-23-24": "nixpkgs-feb-23-24", "pre-commit-hooks": "pre-commit-hooks", @@ -718,6 +977,23 @@ "type": "github" } }, + "rust-analyzer-src_3": { + "flake": false, + "locked": { + "lastModified": 1706875368, + "narHash": "sha256-KOBXxNurIU2lEmO6lR2A5El32X9x8ITt25McxKZ/Ew0=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "8f6a72871ec87ed53cfe43a09fb284168a284e7e", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, "systems": { "locked": { "lastModified": 1681028828, @@ -808,9 +1084,39 @@ "type": "github" } }, + "systems_7": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_8": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "treefmt-nix": { "inputs": { - "nixpkgs": "nixpkgs_5" + "nixpkgs": "nixpkgs_6" }, "locked": { "lastModified": 1708681819, diff --git a/flake.nix b/flake.nix index c861c50..844aebe 100644 --- a/flake.nix +++ b/flake.nix @@ -9,7 +9,7 @@ nixpkgs.url = "nixpkgs/d816b5ab44187a2dd84806630ce77a733724f95f"; nixpkgs-2305.url = "nixpkgs/nixos-23.05"; nixpkgs-feb-23-24.url = "nixpkgs/0e74ca98a74bc7270d28838369593635a5db3260"; - atomipkgs.url = "github:kirinnee/test-nix-repo/v23.0.1"; + atomipkgs.url = "github:kirinnee/test-nix-repo/v27.0.0"; }; outputs = diff --git a/infra/root_chart/Chart.lock b/infra/root_chart/Chart.lock index e1fab65..7d99043 100644 --- a/infra/root_chart/Chart.lock +++ b/infra/root_chart/Chart.lock @@ -4,12 +4,15 @@ dependencies: version: 1.4.0 - name: root-chart repository: oci://ghcr.io/atomicloud/nitroso.zinc - version: 1.19.1 + version: 1.26.0 - name: bun-cron-chart repository: file://../cron_chart version: 0.1.0 - name: bun-cron-chart repository: file://../cron_chart version: 0.1.0 -digest: sha256:48b2f958b0d41e224bd3fb5188ad461d83d972e05d47bbd48d7ab72e7cf681fe -generated: "2024-02-29T12:31:01.139433+08:00" +- name: bun-cron-chart + repository: file://../cron_chart + version: 0.1.0 +digest: sha256:ca681a809c141337be5549b3853777a04203d07675e27507bc50ce6b961d8c2b +generated: "2024-07-13T22:50:56.162686+08:00" diff --git a/infra/root_chart/Chart.yaml b/infra/root_chart/Chart.yaml index b9e2ea7..cbf5fa3 100644 --- a/infra/root_chart/Chart.yaml +++ b/infra/root_chart/Chart.yaml @@ -13,7 +13,7 @@ dependencies: alias: bromine repository: oci://ghcr.io/atomicloud/sulfoxide.bromine - name: root-chart - version: 1.19.1 + version: 1.26.0 condition: zinc.enable alias: zinc repository: oci://ghcr.io/atomicloud/nitroso.zinc @@ -27,3 +27,8 @@ dependencies: repository: file://../cron_chart alias: refunder condition: refunder.enabled + - name: bun-cron-chart + version: 0.1.0 + repository: file://../cron_chart + alias: reverter + condition: reverter.enabled diff --git a/infra/root_chart/README.md b/infra/root_chart/README.md index a9f8538..d94d65a 100644 --- a/infra/root_chart/README.md +++ b/infra/root_chart/README.md @@ -10,7 +10,8 @@ Root Chart to a single Service |------------|------|---------| | file://../cron_chart | scheduler(bun-cron-chart) | 0.1.0 | | file://../cron_chart | refunder(bun-cron-chart) | 0.1.0 | -| oci://ghcr.io/atomicloud/nitroso.zinc | zinc(root-chart) | 1.19.1 | +| file://../cron_chart | reverter(bun-cron-chart) | 0.1.0 | +| oci://ghcr.io/atomicloud/nitroso.zinc | zinc(root-chart) | 1.26.0 | | oci://ghcr.io/atomicloud/sulfoxide.bromine | bromine(sulfoxide-bromine) | 1.4.0 | ## Values @@ -38,6 +39,20 @@ Root Chart to a single Service | refunder.serviceTree.<<.service | string | `"helium"` | | | refunder.serviceTree.module | string | `"refunder"` | | | refunder.timeZone | string | `"Asia/Singapore"` | | +| reverter.command[0] | string | `"bun"` | | +| reverter.command[1] | string | `"run"` | | +| reverter.command[2] | string | `"index.js"` | | +| reverter.command[3] | string | `"reverter"` | | +| reverter.envFromSecret | string | `"nitroso-helium"` | | +| reverter.restartPolicy | string | `"Never"` | | +| reverter.schedule | string | `"*/5 * * * *"` | | +| reverter.serviceTree.<<.landscape | string | `"lapras"` | | +| reverter.serviceTree.<<.layer | string | `"2"` | | +| reverter.serviceTree.<<.module | string | `"pollee"` | | +| reverter.serviceTree.<<.platform | string | `"nitroso"` | | +| reverter.serviceTree.<<.service | string | `"helium"` | | +| reverter.serviceTree.module | string | `"reverter"` | | +| reverter.timeZone | string | `"Asia/Singapore"` | | | scheduler.command[0] | string | `"bun"` | | | scheduler.command[1] | string | `"run"` | | | scheduler.command[2] | string | `"index.js"` | | diff --git a/infra/root_chart/values.lapras.yaml b/infra/root_chart/values.lapras.yaml index 37a6cd1..9620cdc 100644 --- a/infra/root_chart/values.lapras.yaml +++ b/infra/root_chart/values.lapras.yaml @@ -72,3 +72,12 @@ refunder: repository: nitroso-helium-refunder serviceTree: landscape: *landscape + +reverter: + schedule: "*/5 * * * *" + timeZone: "Asia/Singapore" + fullnameOverride: "helium-reverter" + image: + repository: nitroso-helium-reverter + serviceTree: + landscape: *landscape diff --git a/infra/root_chart/values.pichu.yaml b/infra/root_chart/values.pichu.yaml index 2b05970..cf31e98 100644 --- a/infra/root_chart/values.pichu.yaml +++ b/infra/root_chart/values.pichu.yaml @@ -60,3 +60,21 @@ refunder: limits: memory: "128Mi" cpu: "125m" + +reverter: + enable: true + schedule: "0 0 * * 0" + image: + repository: ghcr.io/atomicloud/nitroso.helium/nitroso-helium + serviceTree: + landscape: *landscape + securityContext: *securityContext + podSecurityContext: *podSecurityContext + fullnameOverride: "helium-reverter" + resources: + requests: + memory: "5Mi" + cpu: "5m" + limits: + memory: "128Mi" + cpu: "125m" diff --git a/infra/root_chart/values.pikachu.yaml b/infra/root_chart/values.pikachu.yaml index c89da54..7ff7ddd 100644 --- a/infra/root_chart/values.pikachu.yaml +++ b/infra/root_chart/values.pikachu.yaml @@ -60,3 +60,21 @@ refunder: limits: memory: "128Mi" cpu: "125m" + +reverter: + enable: true + schedule: "0 0 * * 0" + image: + repository: ghcr.io/atomicloud/nitroso.helium/nitroso-helium + serviceTree: + landscape: *landscape + securityContext: *securityContext + podSecurityContext: *podSecurityContext + fullnameOverride: "helium-reverter" + resources: + requests: + memory: "5Mi" + cpu: "5m" + limits: + memory: "128Mi" + cpu: "125m" diff --git a/infra/root_chart/values.raichu.yaml b/infra/root_chart/values.raichu.yaml index 085e2e7..6449e2e 100644 --- a/infra/root_chart/values.raichu.yaml +++ b/infra/root_chart/values.raichu.yaml @@ -60,3 +60,20 @@ refunder: limits: memory: "128Mi" cpu: "125m" + +reverter: + enable: true + image: + repository: ghcr.io/atomicloud/nitroso.helium/nitroso-helium + serviceTree: + landscape: *landscape + securityContext: *securityContext + podSecurityContext: *podSecurityContext + fullnameOverride: "helium-reverter" + resources: + requests: + memory: "5Mi" + cpu: "5m" + limits: + memory: "128Mi" + cpu: "125m" diff --git a/infra/root_chart/values.tauros.yaml b/infra/root_chart/values.tauros.yaml index 579dfb3..e8dd958 100644 --- a/infra/root_chart/values.tauros.yaml +++ b/infra/root_chart/values.tauros.yaml @@ -62,3 +62,9 @@ refunder: fullnameOverride: "helium-refunder" serviceTree: landscape: *landscape + +reverter: + enable: true + fullnameOverride: "helium-reverter" + serviceTree: + landscape: *landscape diff --git a/infra/root_chart/values.yaml b/infra/root_chart/values.yaml index 1fa72a1..f5d6734 100644 --- a/infra/root_chart/values.yaml +++ b/infra/root_chart/values.yaml @@ -63,3 +63,20 @@ refunder: restartPolicy: "Never" envFromSecret: *target + +reverter: + serviceTree: + <<: *serviceTree + module: reverter + + schedule: "*/5 * * * *" + timeZone: "Asia/Singapore" + command: + - "bun" + - "run" + - "index.js" + - "reverter" + + restartPolicy: "Never" + + envFromSecret: *target diff --git a/scripts/ci/release.sh b/scripts/ci/release.sh index f4eb43d..2e5c299 100755 --- a/scripts/ci/release.sh +++ b/scripts/ci/release.sh @@ -1,4 +1,3 @@ #! /bin/sh rm .git/hooks/* -npm i -D conventional-changelog-conventionalcommits@7.0.2 @semantic-release/release-notes-generator@12.0.0 @semantic-release/commit-analyzer@12.0.0 sg release -i npm || true diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 7189b10..3655257 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -8,6 +8,7 @@ import { Get } from "../lib/get.ts"; import { AsciiTable3 } from "ascii-table3"; import { Updater } from "../lib/updater.ts"; import { Refunder } from "../lib/refunder.ts"; +import { Reverter } from "../lib/reverter.ts"; class Cli { constructor( @@ -18,6 +19,7 @@ class Cli { private readonly getter: Get, private readonly updater: Updater, private readonly refunder: Refunder, + private readonly reverter: Reverter, ) {} err(message: string): never { @@ -67,6 +69,14 @@ class Cli { process.exit(0); }); + program + .command("reverter") + .description("Initiate Rerverting Process") + .action(async () => { + await this.reverter.Revert(); + process.exit(0); + }); + program .command("get ") .description("Get schedule for a fixed day and direction") diff --git a/src/index.ts b/src/index.ts index e043f52..2be0e32 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ import { Checker } from "./lib/checker.ts"; import { Updater } from "./lib/updater.ts"; import { Populator } from "./lib/populator.ts"; import { Refunder } from "./lib/refunder.ts"; +import { Reverter } from "./lib/reverter.ts"; // start up that cannot use DI const landscape = process.env.LANDSCAPE; @@ -64,7 +65,17 @@ const updater = new Updater( ); const refunder = new Refunder(logger, zinc, utility); +const reverter = new Reverter(logger, zinc, utility); -const cli = new Cli(logger, cfg, zincDate, watcher, getter, updater, refunder); +const cli = new Cli( + logger, + cfg, + zincDate, + watcher, + getter, + updater, + refunder, + reverter, +); await cli.start(); diff --git a/src/lib/reverter.ts b/src/lib/reverter.ts new file mode 100644 index 0000000..1a5c9bc --- /dev/null +++ b/src/lib/reverter.ts @@ -0,0 +1,66 @@ +import { Logger } from "pino"; +import { Api } from "./zinc/Api.ts"; +import { Utility } from "../utility.ts"; +import { Res } from "./core/result.ts"; +import { BookingPrincipalRes } from "./zinc/data-contracts.ts"; +import { ProblemDetails } from "../errors/problem_details.ts"; +import { AggregatedError } from "../errors/v1/aggregate_error.ts"; + +class Reverter { + constructor( + private readonly logger: Logger, + private readonly zinc: Api, + private readonly utility: Utility, + ) {} + + async Revert(): Promise { + this.logger.info("Starting reverting"); + + await this.utility + .toResult( + () => + this.zinc.vBookingDetail("1.0", { + Status: "Buying", + }), + "Failed to list of bookings that is in the buying state", + ) + .map(async (tix) => { + const res: (["err", ProblemDetails] | ["ok", BookingPrincipalRes])[] = + []; + + for (const ticket of tix) { + const r = await this.utility + .toResult(async () => { + this.logger.info({ ticket: ticket.id }, "Reverting ticket"); + return await this.zinc.vBookingRevertCreate(ticket.id, "1.0"); + }, `Failed to revert ticket ${ticket.id}`) + .serial(); + res.push(r); + } + + const results = Res.all(...res.map((x) => Res.fromSerial(x))); + + return results.mapErr( + (x) => + ({ + data: new AggregatedError( + "Failed to revert tickets", + x.map((y) => y), + ), + detail: "Failed to some revert tickets, see sub-problems", + type: "aggregate_error", + status: 400, + title: "Failed to revert tickets", + traceId: "see sub-problems", + }) satisfies ProblemDetails, + ); + }) + .match({ + err: (e) => this.logger.error({ error: e }, "Failed to revert tickets"), + ok: (ok) => this.logger.info({ result: ok }, "Completed reverting"), + }); + this.logger.info("Completed reverting"); + } +} + +export { Reverter }; diff --git a/src/lib/zinc/Api.ts b/src/lib/zinc/Api.ts index 7f55701..ddd65f4 100644 --- a/src/lib/zinc/Api.ts +++ b/src/lib/zinc/Api.ts @@ -10,6 +10,7 @@ */ import type { + AirwallexEvent, BookingCountRes, BookingPrincipalRes, BookingRes, @@ -19,6 +20,8 @@ import type { CreateCostReq, CreateDiscountReq, CreatePassengerReq, + CreatePaymentReq, + CreatePaymentRes, CreateUserReq, CreateWithdrawalReq, DiscountPrincipalRes, @@ -27,6 +30,8 @@ import type { MaterializedCostRes, PassengerPrincipalRes, PassengerRes, + PaymentPrincipalRes, + PaymentRes, RejectWithdrawalReq, ScheduleBulkUpdateReq, SchedulePrincipalRes, @@ -169,6 +174,26 @@ export class Api< format: "json", ...params, }); + /** + * No description + * + * @tags Booking + * @name VBookingRevertCreate + * @request POST:/api/v{version}/Booking/revert/{id} + * @secure + */ + vBookingRevertCreate = ( + id: string, + version: string, + params: RequestParams = {}, + ) => + this.request({ + path: `/api/v${version}/Booking/revert/${id}`, + method: "POST", + secure: true, + format: "json", + ...params, + }); /** * No description * @@ -701,6 +726,177 @@ export class Api< secure: true, ...params, }); + /** + * No description + * + * @tags Payment + * @name VPaymentDetail + * @request GET:/api/v{version}/Payment + * @secure + */ + vPaymentDetail = ( + version: string, + query?: { + /** @format uuid */ + Id?: string; + /** @format uuid */ + WalletId?: string; + /** @format uuid */ + TransactionId?: string; + Reference?: string; + Gateway?: string; + /** @format double */ + Min?: number; + /** @format double */ + Max?: number; + CreatedBefore?: string; + CreatedAfter?: string; + LastUpdatedBefore?: string; + LastUpdatedAfter?: string; + Status?: string; + /** @format int32 */ + Limit?: number; + /** @format int32 */ + Skip?: number; + }, + params: RequestParams = {}, + ) => + this.request({ + path: `/api/v${version}/Payment`, + method: "GET", + query: query, + secure: true, + format: "json", + ...params, + }); + /** + * No description + * + * @tags Payment + * @name VPaymentIdDetail + * @request GET:/api/v{version}/Payment/id/{id} + * @secure + */ + vPaymentIdDetail = ( + id: string, + version: string, + params: RequestParams = {}, + ) => + this.request({ + path: `/api/v${version}/Payment/id/${id}`, + method: "GET", + secure: true, + format: "json", + ...params, + }); + /** + * No description + * + * @tags Payment + * @name VPaymentIdDelete + * @request DELETE:/api/v{version}/Payment/id/{id} + * @secure + */ + vPaymentIdDelete = ( + id: string, + version: string, + params: RequestParams = {}, + ) => + this.request({ + path: `/api/v${version}/Payment/id/${id}`, + method: "DELETE", + secure: true, + format: "json", + ...params, + }); + /** + * No description + * + * @tags Payment + * @name VPaymentReferenceDetail + * @request GET:/api/v{version}/Payment/reference/{reference} + * @secure + */ + vPaymentReferenceDetail = ( + reference: string, + version: string, + params: RequestParams = {}, + ) => + this.request({ + path: `/api/v${version}/Payment/reference/${reference}`, + method: "GET", + secure: true, + format: "json", + ...params, + }); + /** + * No description + * + * @tags Payment + * @name VPaymentReferenceDelete + * @request DELETE:/api/v{version}/Payment/reference/{reference} + * @secure + */ + vPaymentReferenceDelete = ( + reference: string, + version: string, + params: RequestParams = {}, + ) => + this.request({ + path: `/api/v${version}/Payment/reference/${reference}`, + method: "DELETE", + secure: true, + format: "json", + ...params, + }); + /** + * No description + * + * @tags Payment + * @name VPaymentCreate + * @request POST:/api/v{version}/Payment/{walletId} + * @secure + */ + vPaymentCreate = ( + walletId: string, + version: string, + data: CreatePaymentReq, + query?: { + userId?: string; + }, + params: RequestParams = {}, + ) => + this.request({ + path: `/api/v${version}/Payment/${walletId}`, + method: "POST", + query: query, + body: data, + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }); + /** + * No description + * + * @tags Payment + * @name VPaymentWebhookCreate + * @request POST:/api/v{version}/Payment/webhook + * @secure + */ + vPaymentWebhookCreate = ( + version: string, + data: AirwallexEvent, + params: RequestParams = {}, + ) => + this.request({ + path: `/api/v${version}/Payment/webhook`, + method: "POST", + body: data, + secure: true, + type: ContentType.Json, + ...params, + }); /** * No description * diff --git a/src/lib/zinc/data-contracts.ts b/src/lib/zinc/data-contracts.ts index e1d631e..902ac0c 100644 --- a/src/lib/zinc/data-contracts.ts +++ b/src/lib/zinc/data-contracts.ts @@ -9,6 +9,41 @@ * --------------------------------------------------------------- */ +export interface AirwallexEvent { + id?: string | null; + name?: string | null; + account_id?: string | null; + accountId?: string | null; + data: AirwallexEventData; + created_at?: string | null; + createdAt?: string | null; + sourceId?: string | null; +} + +export interface AirwallexEventData { + object: AirwallexEventDataObject; +} + +export interface AirwallexEventDataObject { + /** @format double */ + amount: number; + /** @format double */ + base_amount: number; + base_currency?: string | null; + /** @format double */ + captured_amount: number; + created_at?: string | null; + currency?: string | null; + descriptor?: string | null; + id?: string | null; + /** @format uuid */ + merchant_order_id: string; + /** @format uuid */ + request_id: string; + status?: string | null; + updated_at?: string | null; +} + export interface BookingCountRes { date?: string | null; time?: string | null; @@ -90,6 +125,30 @@ export interface CreatePassengerReq { passportNumber?: string | null; } +export interface CreatePaymentReq { + /** @format double */ + amount: number; + currency?: string | null; +} + +export interface CreatePaymentRes { + /** @format uuid */ + id: string; + externalReference?: string | null; + gateway?: string | null; + secret?: string | null; + /** @format date-time */ + createdAt: string; + statuses?: Record; + /** @format double */ + amount: number; + currency?: string | null; + status?: string | null; + /** @format date-time */ + lastUpdated: string; + additionalData?: any; +} + export interface CreateUserReq { username?: string | null; } @@ -185,6 +244,31 @@ export interface PassengerRes { user: UserPrincipalRes; } +export interface PaymentPrincipalRes { + /** @format uuid */ + id: string; + externalReference?: string | null; + gateway?: string | null; + /** @format date-time */ + createdAt: string; + statuses?: Record; + /** @format double */ + amount: number; + /** @format double */ + capturedAmount: number; + currency?: string | null; + status?: string | null; + /** @format date-time */ + lastUpdated: string; + additionalData?: any; +} + +export interface PaymentRes { + principal: PaymentPrincipalRes; + wallet: WalletPrincipalRes; + transaction: TransactionPrincipalRes; +} + export interface RejectWithdrawalReq { note?: string | null; }