@trycourier/cli 2.7.1 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/bin/.gitkeep +0 -0
  2. package/install.js +115 -0
  3. package/package.json +22 -87
  4. package/LICENSE +0 -21
  5. package/README.md +0 -105
  6. package/dist/bulk.d.ts +0 -15
  7. package/dist/bulk.js +0 -53
  8. package/dist/cli.d.ts +0 -2
  9. package/dist/cli.js +0 -24
  10. package/dist/commands/AudienceSearch.d.ts +0 -3
  11. package/dist/commands/AudienceSearch.js +0 -113
  12. package/dist/commands/AutomationInvokeBulk.d.ts +0 -3
  13. package/dist/commands/AutomationInvokeBulk.js +0 -139
  14. package/dist/commands/Config.d.ts +0 -4
  15. package/dist/commands/Config.js +0 -45
  16. package/dist/commands/DigestFlush.d.ts +0 -5
  17. package/dist/commands/DigestFlush.js +0 -28
  18. package/dist/commands/Help.d.ts +0 -16
  19. package/dist/commands/Help.js +0 -38
  20. package/dist/commands/Inbox/ArchiveAll.d.ts +0 -8
  21. package/dist/commands/Inbox/ArchiveAll.js +0 -180
  22. package/dist/commands/Inbox/ArchiveAllBulk.d.ts +0 -5
  23. package/dist/commands/Inbox/ArchiveAllBulk.js +0 -99
  24. package/dist/commands/Inbox/MarkAllRead.d.ts +0 -5
  25. package/dist/commands/Inbox/MarkAllRead.js +0 -110
  26. package/dist/commands/MessagesSearch.d.ts +0 -3
  27. package/dist/commands/MessagesSearch.js +0 -120
  28. package/dist/commands/NotYetImplemented.d.ts +0 -3
  29. package/dist/commands/NotYetImplemented.js +0 -5
  30. package/dist/commands/Send.d.ts +0 -5
  31. package/dist/commands/Send.js +0 -144
  32. package/dist/commands/Templates/List.d.ts +0 -3
  33. package/dist/commands/Templates/List.js +0 -114
  34. package/dist/commands/TenantsBulk.d.ts +0 -3
  35. package/dist/commands/TenantsBulk.js +0 -171
  36. package/dist/commands/TenantsGetMembership.d.ts +0 -3
  37. package/dist/commands/TenantsGetMembership.js +0 -127
  38. package/dist/commands/TenantsMembershipBulk.d.ts +0 -3
  39. package/dist/commands/TenantsMembershipBulk.js +0 -203
  40. package/dist/commands/Track.d.ts +0 -5
  41. package/dist/commands/Track.js +0 -40
  42. package/dist/commands/TrackBulk.d.ts +0 -3
  43. package/dist/commands/TrackBulk.js +0 -89
  44. package/dist/commands/TranslationsDownload.d.ts +0 -10
  45. package/dist/commands/TranslationsDownload.js +0 -30
  46. package/dist/commands/TranslationsUpload.d.ts +0 -9
  47. package/dist/commands/TranslationsUpload.js +0 -37
  48. package/dist/commands/Upgrade.d.ts +0 -3
  49. package/dist/commands/Upgrade.js +0 -38
  50. package/dist/commands/UserToken.d.ts +0 -3
  51. package/dist/commands/UserToken.js +0 -78
  52. package/dist/commands/UsersBulk.d.ts +0 -3
  53. package/dist/commands/UsersBulk.js +0 -205
  54. package/dist/commands/UsersGet.d.ts +0 -5
  55. package/dist/commands/UsersGet.js +0 -37
  56. package/dist/commands/UsersPreferences.d.ts +0 -3
  57. package/dist/commands/UsersPreferences.js +0 -73
  58. package/dist/commands/UsersSet.d.ts +0 -5
  59. package/dist/commands/UsersSet.js +0 -34
  60. package/dist/commands/UsersTokensBulk.d.ts +0 -3
  61. package/dist/commands/UsersTokensBulk.js +0 -215
  62. package/dist/commands/WhoAmI.d.ts +0 -3
  63. package/dist/commands/WhoAmI.js +0 -27
  64. package/dist/components/Context.d.ts +0 -55
  65. package/dist/components/Context.js +0 -94
  66. package/dist/components/Elemental.d.ts +0 -13
  67. package/dist/components/Elemental.js +0 -23
  68. package/dist/components/KVP.d.ts +0 -11
  69. package/dist/components/KVP.js +0 -12
  70. package/dist/components/Request.d.ts +0 -23
  71. package/dist/components/Request.js +0 -17
  72. package/dist/components/Response.d.ts +0 -16
  73. package/dist/components/Response.js +0 -29
  74. package/dist/components/Router.d.ts +0 -4
  75. package/dist/components/Router.js +0 -60
  76. package/dist/components/SdkResponse.d.ts +0 -9
  77. package/dist/components/SdkResponse.js +0 -21
  78. package/dist/components/Spinner.d.ts +0 -6
  79. package/dist/components/Spinner.js +0 -41
  80. package/dist/components/Table.d.ts +0 -19
  81. package/dist/components/Table.js +0 -62
  82. package/dist/components/UhOh.d.ts +0 -5
  83. package/dist/components/UhOh.js +0 -10
  84. package/dist/components/Version.d.ts +0 -3
  85. package/dist/components/Version.js +0 -53
  86. package/dist/constants.d.ts +0 -8
  87. package/dist/constants.js +0 -8
  88. package/dist/lib/api.d.ts +0 -17
  89. package/dist/lib/api.js +0 -39
  90. package/dist/lib/args.d.ts +0 -2
  91. package/dist/lib/args.js +0 -13
  92. package/dist/lib/courier.d.ts +0 -3
  93. package/dist/lib/courier.js +0 -7
  94. package/dist/lib/delay.d.ts +0 -2
  95. package/dist/lib/delay.js +0 -7
  96. package/dist/lib/load-env.d.ts +0 -2
  97. package/dist/lib/load-env.js +0 -16
  98. package/dist/lib/uuid.d.ts +0 -2
  99. package/dist/lib/uuid.js +0 -4
  100. package/dist/mappings.d.ts +0 -6
  101. package/dist/mappings.js +0 -559
  102. package/dist/version.d.ts +0 -2
  103. package/dist/version.js +0 -2
package/bin/.gitkeep ADDED
File without changes
package/install.js ADDED
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const https = require("https");
6
+ const http = require("http");
7
+ const fs = require("fs");
8
+ const path = require("path");
9
+ const { execSync } = require("child_process");
10
+
11
+ const REPO = "trycourier/courier-cli";
12
+ const VERSION = require("./package.json").version;
13
+ const BIN_DIR = path.join(__dirname, "bin");
14
+
15
+ const PLATFORM_MAP = {
16
+ "darwin-arm64": { archive: `courier_${VERSION}_macos_arm64.zip`, binary: "courier" },
17
+ "darwin-x64": { archive: `courier_${VERSION}_macos_amd64.zip`, binary: "courier" },
18
+ "linux-x64": { archive: `courier_${VERSION}_linux_amd64.tar.gz`, binary: "courier" },
19
+ "linux-arm64": { archive: `courier_${VERSION}_linux_arm64.tar.gz`, binary: "courier" },
20
+ "linux-ia32": { archive: `courier_${VERSION}_linux_386.tar.gz`, binary: "courier" },
21
+ "linux-arm": { archive: `courier_${VERSION}_linux_armv6.tar.gz`, binary: "courier" },
22
+ "win32-x64": { archive: `courier_${VERSION}_windows_amd64.zip`, binary: "courier.exe" },
23
+ "win32-arm64": { archive: `courier_${VERSION}_windows_arm64.zip`, binary: "courier.exe" },
24
+ "win32-ia32": { archive: `courier_${VERSION}_windows_386.zip`, binary: "courier.exe" },
25
+ };
26
+
27
+ const key = `${process.platform}-${process.arch}`;
28
+ const target = PLATFORM_MAP[key];
29
+
30
+ if (!target) {
31
+ console.error(
32
+ `Unsupported platform: ${key}\n` +
33
+ `Supported: ${Object.keys(PLATFORM_MAP).join(", ")}\n` +
34
+ `You can download the binary directly from:\n` +
35
+ ` https://github.com/${REPO}/releases/tag/v${VERSION}`
36
+ );
37
+ process.exit(1);
38
+ }
39
+
40
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${target.archive}`;
41
+ const archivePath = path.join(BIN_DIR, target.archive);
42
+
43
+ function follow(requestUrl, redirects) {
44
+ if (redirects > 10) {
45
+ throw new Error("Too many redirects");
46
+ }
47
+ return new Promise((resolve, reject) => {
48
+ const lib = requestUrl.startsWith("https") ? https : http;
49
+ lib.get(requestUrl, { headers: { "User-Agent": `@trycourier/cli-npm/${VERSION}` } }, (res) => {
50
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
51
+ resolve(follow(res.headers.location, redirects + 1));
52
+ return;
53
+ }
54
+ if (res.statusCode !== 200) {
55
+ reject(new Error(`Download failed: HTTP ${res.statusCode} from ${requestUrl}`));
56
+ return;
57
+ }
58
+ resolve(res);
59
+ }).on("error", reject);
60
+ });
61
+ }
62
+
63
+ async function download() {
64
+ console.log(`Downloading Courier CLI v${VERSION} for ${key}...`);
65
+
66
+ const res = await follow(url, 0);
67
+ const file = fs.createWriteStream(archivePath);
68
+ await new Promise((resolve, reject) => {
69
+ res.pipe(file);
70
+ file.on("finish", () => { file.close(resolve); });
71
+ file.on("error", reject);
72
+ });
73
+ }
74
+
75
+ function extract() {
76
+ const binPath = path.join(BIN_DIR, target.binary);
77
+
78
+ if (target.archive.endsWith(".tar.gz")) {
79
+ execSync(`tar -xzf "${archivePath}" -C "${BIN_DIR}" "${target.binary}"`, { stdio: "pipe" });
80
+ } else if (target.archive.endsWith(".zip")) {
81
+ if (process.platform === "win32") {
82
+ execSync(
83
+ `powershell -Command "Expand-Archive -Force '${archivePath}' '${BIN_DIR}'"`,
84
+ { stdio: "pipe" }
85
+ );
86
+ } else {
87
+ execSync(`unzip -o -j "${archivePath}" "${target.binary}" -d "${BIN_DIR}"`, { stdio: "pipe" });
88
+ }
89
+ }
90
+
91
+ if (process.platform !== "win32") {
92
+ fs.chmodSync(binPath, 0o755);
93
+ }
94
+
95
+ fs.unlinkSync(archivePath);
96
+
97
+ console.log(`Courier CLI v${VERSION} installed successfully.`);
98
+ }
99
+
100
+ async function main() {
101
+ try {
102
+ fs.mkdirSync(BIN_DIR, { recursive: true });
103
+ await download();
104
+ extract();
105
+ } catch (err) {
106
+ console.error(
107
+ `Failed to install Courier CLI: ${err.message}\n` +
108
+ `You can download the binary manually from:\n` +
109
+ ` https://github.com/${REPO}/releases/tag/v${VERSION}`
110
+ );
111
+ process.exit(1);
112
+ }
113
+ }
114
+
115
+ main();
package/package.json CHANGED
@@ -1,89 +1,24 @@
1
1
  {
2
- "name": "@trycourier/cli",
3
- "version": "2.7.1",
4
- "license": "MIT",
5
- "bin": {
6
- "courier": "dist/cli.js"
7
- },
8
- "type": "module",
9
- "engines": {
10
- "node": ">=20"
11
- },
12
- "scripts": {
13
- "build": "tsc",
14
- "dev": "tsc --watch",
15
- "test": "prettier --check . && xo && ava",
16
- "format": "prettier --write .",
17
- "clean": "rm -rf dist && rm -rf node_modules && yarn install"
18
- },
19
- "files": [
20
- "dist"
21
- ],
22
- "dependencies": {
23
- "@babel/runtime": "^7.24.7",
24
- "@inkjs/ui": "^2.0.0",
25
- "@trycourier/client-graphql": "^6.0.0",
26
- "@trycourier/core": "^6.0.0",
27
- "@trycourier/courier": "^6.2.1",
28
- "cli-spinners": "^3.0.0",
29
- "csv-stringify": "^6.5.0",
30
- "dotenv": "^16.0.3",
31
- "duckdb": "^1.0.0",
32
- "execa": "^9.1.0",
33
- "ink": "^5.0.1",
34
- "ink-link": "^4.0.0",
35
- "ink-spinner": "^5.0.0",
36
- "lodash": "^4.17.21",
37
- "luxon": "^3.4.4",
38
- "ms": "3.0.0-canary.1",
39
- "react": "^18.2.0",
40
- "usehooks-ts": "^3.1.0",
41
- "yargs-parser": "^21.1.1"
42
- },
43
- "devDependencies": {
44
- "@sindresorhus/tsconfig": "^5.0.0",
45
- "@types/lodash": "^4.17.4",
46
- "@types/luxon": "^3.4.2",
47
- "@types/node": "^20.13.0",
48
- "@types/react": "^18.0.32",
49
- "@types/yargs-parser": "^21.0.0",
50
- "@vdemedes/prettier-config": "^2.0.1",
51
- "ava": "^5.2.0",
52
- "chalk": "^5.2.0",
53
- "eslint-config-xo-react": "^0.27.0",
54
- "eslint-plugin-react": "^7.32.2",
55
- "eslint-plugin-react-hooks": "^4.6.0",
56
- "ink-testing-library": "^3.0.0",
57
- "prettier": "^2.8.7",
58
- "ts-node": "^10.9.1",
59
- "typescript": "^5.4.5",
60
- "xo": "^0.53.1"
61
- },
62
- "ava": {
63
- "extensions": {
64
- "ts": "module",
65
- "tsx": "module"
66
- },
67
- "nodeArguments": [
68
- "--loader=ts-node/esm"
69
- ]
70
- },
71
- "xo": {
72
- "extends": "xo-react",
73
- "prettier": true,
74
- "rules": {
75
- "react/prop-types": "off"
76
- }
77
- },
78
- "prettier": "@vdemedes/prettier-config",
79
- "repository": {
80
- "type": "git",
81
- "url": "https://github.com/trycourier/courier-cli.git"
82
- },
83
- "publishConfig": {
84
- "access": "public",
85
- "registry": "https://registry.npmjs.org/"
86
- },
87
- "homepage": "https://github.com/trycourier/courier-cli#readme",
88
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
2
+ "name": "@trycourier/cli",
3
+ "version": "3.1.4",
4
+ "description": "Courier CLI – manage notifications from the command line",
5
+ "bin": {
6
+ "courier": "./bin/courier"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "files": [
12
+ "bin/",
13
+ "install.js"
14
+ ],
15
+ "license": "Apache-2.0",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/trycourier/courier-cli.git"
19
+ },
20
+ "homepage": "https://github.com/trycourier/courier-cli",
21
+ "engines": {
22
+ "node": ">=14"
23
+ }
89
24
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Courier
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,105 +0,0 @@
1
- # Courier CLI
2
-
3
- ### Build, test, and manage your [Courier](https://www.courier.com) integration directly from the command line.
4
-
5
- The Courier CLI is a developer tool to help you build, test, and manage your integration with Courier directly from the command line. It’s simple to install, works on macOS, Windows, and Linux, and offers a range of functionality to enhance your developer experience with Courier. You can use the Courier CLI to:
6
-
7
- - Send messages from the command line to users, lists, or audiences
8
- - Track events to trigger your Courier Automations
9
- - Push & pull industry-standard translation files for internationalizing your content
10
-
11
- ## Installing the Courier CLI
12
-
13
- From the command-line, use the following command to install the Courier CLI and set your API key:
14
-
15
- ```bash
16
- $ yarn install -g @trycourier/cli
17
- $ courier config --apikey <your-api-key>
18
- ```
19
-
20
- ### Requirements
21
-
22
- - Courier CLI has only been tested on node.js v18+
23
-
24
- ## Authenticate the CLI
25
-
26
- The fastest way to get started is to run:
27
-
28
- ```
29
- $ courier config --apikey <your-api-key>
30
- ```
31
-
32
- Courier CLI looks for environment variables prefixed with `COURIER_AUTH_TOKEN`. It will load keys from the first location it finds in the following list:
33
-
34
- - A `.courier` file in the current working directory
35
- - `~/.courier` (in your home directory)
36
- - A `COURIER_AUTH_TOKEN` or `COURIER_AUTH_TOKEN_*` value otherwise set in your environment (such as via `~/.profile` or `~/.zshrc`)
37
-
38
- You can find your Courier API key in your [Courier Settings](https://app.courier.com/settings/api-keys).
39
-
40
- ## Commands
41
-
42
- - `courier config` – Set your Courier API key
43
- - `courier whoami` – Display the currently authenticated workspace
44
- - `courier send` - Send a notification to a user, list, tenant, or audience
45
- - `courier track` - Send a track event to trigger a Courier Automations
46
- - `courier users:get` - Fetch the data for a given user ID
47
- - `courier users:set` - Overwrite a user's profile with the provided data
48
- - `courier users:bulk` - Bulk upload users via csv, json, or parquet
49
- - `courier translations:upload` - Upload .PO files to your Courier workspace
50
- - `courier translations:download` - Download .PO files from your Courier workspace
51
-
52
- For more details, run `courier` to see a list of commands and their arguments & options.
53
-
54
- ## Examples
55
-
56
- ```
57
- courier --help
58
- courier --version
59
- courier upgrade
60
-
61
- courier send --tel 555-867-5309 --body "Hey Jenny\!"
62
- courier send --user user123 --template my-template-id --foo bar
63
- courier send -P --user=test123 --body "hello world" --title="hello" --channels=inbox
64
- courier send --tenant=kewl --title=hello --body="hello world" --channel=inbox
65
- courier send --user="1" --tenant-context=kewl --title=hello --body="hello world" --channel=inbox
66
-
67
- courier users:get user123
68
- courier users:set user123 --email user@example.com
69
- courier users:bulk examples/users.csv --replace
70
- courier users:bulk examples/users.parquet --list new-list-id --tenant new-tenant-id
71
-
72
- courier track EXAMPLE_EVENT user123 --name "Pip the Pigeon"
73
-
74
- courier translations:upload en-US ./translations/en-US.po
75
- courier translations:download en-US --text > example.en-US.po
76
-
77
- courier config --apikey MY_API_KEY -P --override
78
- courier config --apikey MY_API_KEY --mock
79
- courier config --apikey MY_API_KEY --draft
80
- ```
81
-
82
- ## Common Flags
83
-
84
- There are a number flags you can use for any command
85
-
86
- | Flags | Description |
87
- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
88
- | -M --mock | Use the API key that simulates sending using the simulating routing |
89
- | -P --production | Use the production environment API key |
90
- | -D --draft | Use the draft document scope API key. Use draft or submitted, will default to published key if neither are provided |
91
- | -S --submitted | Use the submitted document scope API key |
92
- | --apikey <Courier API Key> | Use the provided Courier API key, otherwise use the approprate environment variable |
93
- | --apiurl <Courier API URL> | Use the provided Courier API URL, otherwise use COURIER_API_URL environment variable. Default is https://api.courier.com |
94
-
95
- ## Misc
96
-
97
- - If you need to change the Courier API URL, you can set COURIER_API_URL in .courier or other methods to set the environment variables.
98
-
99
- ## License
100
-
101
- [MIT License](http://www.opensource.org/licenses/mit-license.php)
102
-
103
- ## Author
104
-
105
- [Courier](https://github.com/trycourier) ([support@courier.com](mailto:support@courier.com))
package/dist/bulk.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import duckdb from 'duckdb';
2
- export declare const installExtension: (db: duckdb.Database, type?: TFileType) => void;
3
- export declare const getFrom: (filename: string, type: TFileType) => string;
4
- export declare const getFileType: (filename: string) => TFileType | undefined;
5
- export declare const getSql: (filename: string, type: TFileType) => string;
6
- declare const getDb: (filename: string) => {
7
- db: duckdb.Database;
8
- filetype: TFileType | undefined;
9
- sql: string;
10
- };
11
- export declare const getChunk: (data: duckdb.TableData, chunk_size?: number) => {
12
- rows: duckdb.RowData[];
13
- data: duckdb.TableData;
14
- };
15
- export default getDb;
package/dist/bulk.js DELETED
@@ -1,53 +0,0 @@
1
- import duckdb from 'duckdb';
2
- export const installExtension = (db, type) => {
3
- if (['json', 'parquet'].includes(type || '')) {
4
- db.exec(`
5
- INSTALL ${type};
6
- LOAD ${type};`);
7
- }
8
- };
9
- export const getFrom = (filename, type) => {
10
- switch (type) {
11
- case 'csv':
12
- return `read_csv(['${filename}'], union_by_name = true)`;
13
- case 'json':
14
- return `read_json_auto(['${filename}'])`;
15
- case 'parquet':
16
- return `read_parquet(['${filename}'])`;
17
- }
18
- };
19
- export const getFileType = (filename) => {
20
- if (filename.endsWith('.csv')) {
21
- return 'csv';
22
- }
23
- else if (filename.endsWith('.json') || filename.endsWith('.jsonl')) {
24
- return 'json';
25
- }
26
- else if (filename.endsWith('.parquet') ||
27
- filename.endsWith('.pq') ||
28
- filename.endsWith('.parq')) {
29
- return 'parquet';
30
- }
31
- else {
32
- return undefined;
33
- }
34
- };
35
- export const getSql = (filename, type) => `SELECT * FROM ${getFrom(filename, type)} ;`;
36
- const getDb = (filename) => {
37
- const filetype = getFileType(filename);
38
- const db = new duckdb.Database(':memory:'); // or a file name for a persistent DB
39
- installExtension(db, filetype);
40
- return {
41
- db,
42
- filetype,
43
- sql: getSql(filename, filetype || 'csv'),
44
- };
45
- };
46
- export const getChunk = (data, chunk_size = 1) => {
47
- let rows = data.splice(0, chunk_size);
48
- return {
49
- rows,
50
- data
51
- };
52
- };
53
- export default getDb;
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/cli.js DELETED
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env node
2
- import { render } from 'ink';
3
- import React from 'react';
4
- import { CliContextProvider } from './components/Context.js';
5
- import args from './lib/args.js';
6
- import loadEnv from './lib/load-env.js';
7
- import Version from './components/Version.js';
8
- // @ts-ignore
9
- BigInt.prototype.toJSON = function () {
10
- return this.toString();
11
- };
12
- const CLI = async () => {
13
- process.removeAllListeners('warning');
14
- await loadEnv();
15
- const params = args(process.argv);
16
- const mappings = (await import('./mappings.js')).default;
17
- const Router = (await import('./components/Router.js')).default;
18
- render(React.createElement(CliContextProvider, { args: params, mappings },
19
- React.createElement(Router, null),
20
- React.createElement(Version, null)));
21
- };
22
- (async () => {
23
- await CLI();
24
- })();
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const AudienceSearch: () => React.JSX.Element;
3
- export default AudienceSearch;
@@ -1,113 +0,0 @@
1
- import { Alert } from '@inkjs/ui';
2
- import { stringify } from 'csv-stringify/sync';
3
- import fs from 'fs/promises';
4
- import _ from 'lodash';
5
- import { DateTime } from 'luxon';
6
- import React, { useEffect, useState } from 'react';
7
- import { useBoolean, useCounter } from 'usehooks-ts';
8
- import { useCliContext } from '../components/Context.js';
9
- import Spinner from '../components/Spinner.js';
10
- import UhOh from '../components/UhOh.js';
11
- const FILENAME = 'audiences';
12
- const AudienceSearch = () => {
13
- const { parsedParams, courier } = useCliContext();
14
- const processing = useBoolean(true);
15
- const running = useBoolean(true);
16
- const counter = useCounter(0);
17
- const [audiences, setAudiences] = useState([]);
18
- const [error, setError] = useState();
19
- const { maxPages, json, csv, webhook, filename, name, id } = parsedParams;
20
- const out_file = (filename?.length
21
- ? filename.substring(0, filename.includes('.') ? filename.lastIndexOf('.') : filename.length)
22
- : FILENAME) + (csv ? '.csv' : '.json');
23
- const MAX_PAGES = Number(maxPages) || 10;
24
- useEffect(() => {
25
- if (!processing.value) {
26
- if (json || csv || webhook?.length) {
27
- runExport();
28
- }
29
- else {
30
- running.setFalse();
31
- }
32
- }
33
- }, [processing.value]);
34
- useEffect(() => {
35
- getAudiences();
36
- }, []);
37
- const getAudiences = async (cursor, count = 0) => {
38
- counter.increment();
39
- const r = await courier.audiences.listAudiences({
40
- cursor,
41
- });
42
- let items = r.items;
43
- if (name) {
44
- items = items.filter(a => a.name.includes(name));
45
- }
46
- if (id) {
47
- items = items.filter(a => a.id.includes(id));
48
- }
49
- setAudiences(p => [...p, ...items]);
50
- if (r.paging.more && count < MAX_PAGES) {
51
- await getAudiences(r.paging.cursor, count + 1);
52
- }
53
- else {
54
- processing.setFalse();
55
- }
56
- };
57
- const runExport = async () => {
58
- const flat = csv ? flattenData(audiences) : audiences;
59
- if (csv) {
60
- await fs.writeFile(out_file, stringify(flat, { header: true }));
61
- }
62
- else if (json) {
63
- await fs.writeFile(out_file, JSON.stringify(flat, null, 2), {
64
- encoding: 'utf-8',
65
- });
66
- }
67
- if (webhook?.length) {
68
- try {
69
- await fetch(webhook, {
70
- method: 'POST',
71
- headers: {
72
- 'Content-Type': 'application/json',
73
- },
74
- body: JSON.stringify(flat),
75
- });
76
- }
77
- catch (e) {
78
- setError(e instanceof Error ? e.message : String(e));
79
- }
80
- }
81
- running.setFalse();
82
- };
83
- if (error?.length) {
84
- return React.createElement(UhOh, { text: error });
85
- }
86
- else if (running.value) {
87
- return React.createElement(Spinner, { text: `Fetching audiences - page ${counter.count}` });
88
- }
89
- else {
90
- return (React.createElement(React.Fragment, null,
91
- React.createElement(Alert, { variant: "success", title: `Finished ${counter.count} pages` }, csv || json
92
- ? `Output ${audiences.length} audiences to ${out_file}`
93
- : JSON.stringify(audiences, null, 2))));
94
- }
95
- };
96
- const flattenData = (data) => {
97
- return data.map(row => {
98
- return Object.keys(row).reduce((p, key) => {
99
- const v = _.get(row, [key]);
100
- if (typeof v === 'number') {
101
- p[key] = DateTime.fromMillis(v, { zone: 'utc' }).toISO();
102
- }
103
- else if (typeof v === 'object') {
104
- p[key] = JSON.stringify(v);
105
- }
106
- else if (v) {
107
- p[key] = v;
108
- }
109
- return p;
110
- }, {});
111
- });
112
- };
113
- export default AudienceSearch;
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const AutomationInvokeBulk: () => React.JSX.Element;
3
- export default AutomationInvokeBulk;