@trycourier/cli 1.5.1 → 2.0.1
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.
- package/README.md +56 -20
- package/dist/cli.js +38 -2
- package/dist/commands/Config.d.ts +2 -7
- package/dist/commands/Config.js +36 -9
- package/dist/commands/DigestFlush.js +3 -1
- package/dist/commands/Help.js +12 -16
- package/dist/commands/Send.js +45 -31
- package/dist/commands/Track.js +3 -1
- package/dist/commands/TranslationsDownload.js +3 -1
- package/dist/commands/TranslationsUpload.js +3 -1
- package/dist/commands/Upgrade.js +36 -0
- package/dist/commands/UsersBulk.js +159 -0
- package/dist/commands/UsersGet.js +3 -1
- package/dist/commands/UsersPreferences.js +41 -0
- package/dist/commands/UsersSet.js +3 -1
- package/dist/commands/WhoAmI.js +5 -2
- package/dist/components/Context.d.ts +43 -0
- package/dist/components/Context.js +75 -0
- package/dist/components/Router.d.ts +2 -9
- package/dist/components/Router.js +51 -20
- package/dist/components/SdkResponse.d.ts +8 -0
- package/dist/components/SdkResponse.js +20 -0
- package/dist/components/Table.d.ts +24 -0
- package/dist/components/Table.js +62 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/lib/api.d.ts +1 -1
- package/dist/lib/api.js +4 -4
- package/dist/lib/courier.d.ts +3 -0
- package/dist/lib/courier.js +7 -0
- package/dist/lib/load-env.js +1 -1
- package/dist/mappings.d.ts +4 -13
- package/dist/mappings.js +118 -15
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +23 -6
- package/dist/Counter.js +0 -16
- package/dist/Error.js +0 -4
- package/dist/Help.js +0 -13
- package/dist/app.d.ts +0 -6
- package/dist/app.js +0 -7
- package/dist/commands/DigestsFlush.d.ts +0 -5
- package/dist/commands/DigestsFlush.js +0 -23
- package/dist/commands/EventsTrack.d.ts +0 -5
- package/dist/commands/EventsTrack.js +0 -34
- package/dist/commands/TranslationUpload.d.ts +0 -5
- package/dist/commands/TranslationUpload.js +0 -28
- package/dist/components/Counter.d.ts +0 -3
- package/dist/components/Counter.js +0 -16
- package/dist/components/Error.d.ts +0 -5
- package/dist/components/Error.js +0 -5
- package/dist/components/Hello.d.ts +0 -5
- package/dist/components/Hello.js +0 -7
- package/dist/components/Help.d.ts +0 -9
- package/dist/components/Help.js +0 -23
- package/dist/components/WhoAmI.d.ts +0 -3
- package/dist/components/WhoAmI.js +0 -42
- package/dist/lib/render-elemental.d.ts +0 -2
- package/dist/lib/render-elemental.js +0 -1
- /package/dist/{Counter.d.ts → commands/Upgrade.d.ts} +0 -0
- /package/dist/{Error.d.ts → commands/UsersBulk.d.ts} +0 -0
- /package/dist/{Help.d.ts → commands/UsersPreferences.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ The Courier CLI is a developer tool to help you build, test, and manage your int
|
|
|
13
13
|
From the command-line, use the following command to install the Courier CLI and set your API key:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
$
|
|
16
|
+
$ yarn install -g @trycourier/cli
|
|
17
17
|
$ courier config --apikey <your-api-key>
|
|
18
18
|
```
|
|
19
19
|
|
|
@@ -29,11 +29,11 @@ The fastest way to get started is to run:
|
|
|
29
29
|
$ courier config --apikey <your-api-key>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
Courier CLI looks for
|
|
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
33
|
|
|
34
34
|
- A `.courier` file in the current working directory
|
|
35
35
|
- `~/.courier` (in your home directory)
|
|
36
|
-
- A `
|
|
36
|
+
- A `COURIER_AUTH_TOKEN` or `COURIER_AUTH_TOKEN_*` value otherwise set in your environment (such as via `~/.profile` or `~/.zshrc`)
|
|
37
37
|
|
|
38
38
|
You can find your Courier API key in your [Courier Settings](https://app.courier.com/settings/api-keys).
|
|
39
39
|
|
|
@@ -41,11 +41,11 @@ You can find your Courier API key in your [Courier Settings](https://app.courier
|
|
|
41
41
|
|
|
42
42
|
- `courier config` – Set your Courier API key
|
|
43
43
|
- `courier whoami` – Display the currently authenticated workspace
|
|
44
|
-
- `courier send` - Send a notification to a user, list, or audience
|
|
44
|
+
- `courier send` - Send a notification to a user, list, tenant, or audience
|
|
45
45
|
- `courier track` - Send a track event to trigger a Courier Automations
|
|
46
46
|
- `courier users:get` - Fetch the data for a given user ID
|
|
47
47
|
- `courier users:set` - Overwrite a user's profile with the provided data
|
|
48
|
-
- `courier
|
|
48
|
+
- `courier users:bulk` - Bulk upload users via csv, json, or parquet
|
|
49
49
|
- `courier translations:upload` - Upload .PO files to your Courier workspace
|
|
50
50
|
- `courier translations:download` - Download .PO files from your Courier workspace
|
|
51
51
|
|
|
@@ -54,23 +54,56 @@ For more details, run `courier` to see a list of commands and their arguments &
|
|
|
54
54
|
## Examples
|
|
55
55
|
|
|
56
56
|
```
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
courier --help
|
|
58
|
+
courier upgrade
|
|
59
|
+
|
|
60
|
+
courier send --tel 555-867-5309 --body "Hey Jenny\!"
|
|
61
|
+
courier send --user user123 --template my-template-id --foo bar
|
|
62
|
+
courier send -P --user=test123 --body "hello world" --title="hello" --channels=inbox
|
|
63
|
+
courier send --tenant=kewl --title=hello --body="hello world" --channel=inbox
|
|
64
|
+
courier send --user="1" --tenant-context=kewl --title=hello --body="hello world" --channel=inbox
|
|
65
|
+
|
|
66
|
+
courier users:get user123
|
|
67
|
+
courier users:set user123 --email user@example.com
|
|
68
|
+
courier users:bulk examples/users.csv --replace
|
|
69
|
+
courier users:bulk "examples/users/*.csv" --keep-flat
|
|
70
|
+
courier users:bulk "examples/*.json" --remove-nulls
|
|
71
|
+
courier users:bulk examples/users.parquet --list new-list-id
|
|
72
|
+
courier users:bulk examples/users.xlsx --tenant new-tenant-id
|
|
73
|
+
|
|
74
|
+
courier track EXAMPLE_EVENT user123 --name "Pip the Pigeon"
|
|
75
|
+
|
|
76
|
+
courier translations:upload en-US ./translations/en-US.po
|
|
77
|
+
courier translations:download en-US --text > example.en-US.po
|
|
78
|
+
|
|
79
|
+
courier config --apikey MY_API_KEY -P --override
|
|
80
|
+
courier config --apikey MY_API_KEY --mock
|
|
81
|
+
courier config --apikey MY_API_KEY --draft
|
|
72
82
|
```
|
|
73
83
|
|
|
84
|
+
## Common Flags
|
|
85
|
+
|
|
86
|
+
There are a number flags you can use for any command
|
|
87
|
+
┌────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
|
88
|
+
│Flags │Description │
|
|
89
|
+
├────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
|
90
|
+
│-M --mock │Use the API key that simulates sending using the simulating routing │
|
|
91
|
+
├────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
|
92
|
+
│-P --production │Use the production environment API key │
|
|
93
|
+
├────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
|
94
|
+
│-D --draft │Use the draft document scope API key. Use draft or submitted, will default to published key if neither are provided │
|
|
95
|
+
├────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
|
96
|
+
│-S --submitted │Use the submitted document scope API key │
|
|
97
|
+
├────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
|
98
|
+
│--apikey <Courier API Key> │Use the provided Courier API key, otherwise use the approprate environment variable │
|
|
99
|
+
├────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
|
100
|
+
│--apiurl <Courier API URL> │Use the provided Courier API URL, otherwise use COURIER_API_URL environment variable. Default is https://api.courier.com │
|
|
101
|
+
└────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
|
102
|
+
|
|
103
|
+
## Misc
|
|
104
|
+
|
|
105
|
+
- If you need to change the Courier API URL, you can set COURIER_API_URL in .courier or make sure an environment variable is set with it.
|
|
106
|
+
|
|
74
107
|
## License
|
|
75
108
|
|
|
76
109
|
[MIT License](http://www.opensource.org/licenses/mit-license.php)
|
|
@@ -78,3 +111,6 @@ $ courier translations:download en-US --text > example.en-US.po
|
|
|
78
111
|
## Author
|
|
79
112
|
|
|
80
113
|
[Courier](https://github.com/trycourier) ([support@courier.com](mailto:support@courier.com))
|
|
114
|
+
|
|
115
|
+
TODO - COURIER_DOMAIN
|
|
116
|
+
TODO - Common Flags
|
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,50 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { render } from 'ink';
|
|
3
|
+
import { Box, Text, render } from 'ink';
|
|
4
4
|
import args from './lib/args.js';
|
|
5
5
|
import loadEnv from './lib/load-env.js';
|
|
6
|
+
import { CliContextProvider } from './components/Context.js';
|
|
7
|
+
import { execa } from 'execa';
|
|
8
|
+
import _ from 'lodash';
|
|
9
|
+
import VERSION from './version.js';
|
|
10
|
+
2;
|
|
6
11
|
const CLI = async () => {
|
|
12
|
+
process.removeAllListeners('warning');
|
|
7
13
|
await loadEnv();
|
|
8
14
|
const params = args(process.argv);
|
|
9
15
|
const mappings = (await import('./mappings.js')).default;
|
|
10
16
|
const Router = (await import('./components/Router.js')).default;
|
|
11
|
-
|
|
17
|
+
let current;
|
|
18
|
+
let latest;
|
|
19
|
+
if (VERSION !== 'local' && false) {
|
|
20
|
+
try {
|
|
21
|
+
const exc = await execa('npm', ['-g', 'outdated', 'npm', '--json'], {
|
|
22
|
+
shell: true,
|
|
23
|
+
reject: false,
|
|
24
|
+
});
|
|
25
|
+
const stdout = JSON.parse(exc.stdout);
|
|
26
|
+
current = _.get(stdout, ['npm', 'current']);
|
|
27
|
+
latest = _.get(stdout, ['npm', 'latest']);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
console.log(e);
|
|
31
|
+
}
|
|
32
|
+
console.log({ current, latest });
|
|
33
|
+
}
|
|
34
|
+
const version_text = `Upgrade available (${current} > ${latest}), run courier upgrade`;
|
|
35
|
+
render(React.createElement(CliContextProvider, { args: params, mappings, current, latest },
|
|
36
|
+
React.createElement(Router, null),
|
|
37
|
+
current && latest && current !== latest ? (React.createElement(Box, { flexDirection: "column", marginY: 1, flexShrink: 1, width: version_text.length + 2, borderColor: "gray", borderStyle: 'single' },
|
|
38
|
+
React.createElement(Text, null,
|
|
39
|
+
"Upgrade available (",
|
|
40
|
+
current,
|
|
41
|
+
" ",
|
|
42
|
+
'>',
|
|
43
|
+
" ",
|
|
44
|
+
latest,
|
|
45
|
+
"), run",
|
|
46
|
+
' ',
|
|
47
|
+
React.createElement(Text, { color: "green" }, "courier upgrade")))) : (React.createElement(React.Fragment, null))));
|
|
12
48
|
};
|
|
13
49
|
(async () => {
|
|
14
50
|
await CLI();
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
type Params = {
|
|
3
|
-
|
|
4
|
-
overwrite?: boolean;
|
|
5
|
-
};
|
|
6
|
-
declare const _default: ({ params }: {
|
|
7
|
-
params: Params;
|
|
8
|
-
}) => React.JSX.Element;
|
|
2
|
+
type Params = {};
|
|
3
|
+
declare const _default: ({}: Params) => React.JSX.Element;
|
|
9
4
|
export default _default;
|
package/dist/commands/Config.js
CHANGED
|
@@ -2,17 +2,44 @@ import React from 'react';
|
|
|
2
2
|
import UhOh from '../components/UhOh.js';
|
|
3
3
|
import { Text } from 'ink';
|
|
4
4
|
import fs from 'fs';
|
|
5
|
-
|
|
5
|
+
import { useCliContext } from '../components/Context.js';
|
|
6
|
+
import dotenv from 'dotenv';
|
|
7
|
+
export default ({}) => {
|
|
8
|
+
const { apikey, parsedParams, env_var } = useCliContext();
|
|
6
9
|
const FILE_PATH = `${process.cwd()}/.courier`;
|
|
7
|
-
|
|
10
|
+
const file_exists = fs.existsSync(FILE_PATH);
|
|
11
|
+
const overwrite = Boolean(parsedParams['overwrite']);
|
|
12
|
+
if (!apikey?.length) {
|
|
8
13
|
return (React.createElement(UhOh, { text: "You must specify your API key using --apikey <your-api-key>" }));
|
|
9
14
|
}
|
|
10
|
-
if (
|
|
11
|
-
|
|
15
|
+
else if (!file_exists) {
|
|
16
|
+
fs.writeFileSync(FILE_PATH, `${env_var}=${apikey}\n`);
|
|
17
|
+
return (React.createElement(Text, { bold: true, color: "green" },
|
|
18
|
+
"Your API key (",
|
|
19
|
+
env_var,
|
|
20
|
+
") has been saved to ",
|
|
21
|
+
FILE_PATH,
|
|
22
|
+
". Run \"courier whoami\" to verify API credentials."));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// open file as buffer
|
|
26
|
+
const buffer = fs.readFileSync(FILE_PATH);
|
|
27
|
+
let parsed = dotenv.parse(buffer);
|
|
28
|
+
if (typeof parsed[env_var] !== 'undefined') {
|
|
29
|
+
if (!overwrite) {
|
|
30
|
+
return (React.createElement(UhOh, { text: `${env_var} already exists. Consider adding the --overwrite option` }));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
parsed[env_var] = apikey;
|
|
34
|
+
let new_file = Object.entries(parsed)
|
|
35
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
36
|
+
.join('\n');
|
|
37
|
+
fs.writeFileSync(FILE_PATH, new_file);
|
|
38
|
+
return (React.createElement(Text, { bold: true, color: "green" },
|
|
39
|
+
"Your API key (",
|
|
40
|
+
env_var,
|
|
41
|
+
") has been saved to ",
|
|
42
|
+
FILE_PATH,
|
|
43
|
+
". Run \"courier whoami\" to verify API credentials."));
|
|
12
44
|
}
|
|
13
|
-
fs.writeFileSync(FILE_PATH, `COURIER_API_KEY=${params.apikey}\n`);
|
|
14
|
-
return (React.createElement(Text, { bold: true, color: "green" },
|
|
15
|
-
"Your API key has been saved to ",
|
|
16
|
-
FILE_PATH,
|
|
17
|
-
". Run \"courier whoami\" to verify API credentials."));
|
|
18
45
|
};
|
|
@@ -3,7 +3,9 @@ import UhOh from '../components/UhOh.js';
|
|
|
3
3
|
import Request from '../components/Request.js';
|
|
4
4
|
import Response from '../components/Response.js';
|
|
5
5
|
import api from '../lib/api.js';
|
|
6
|
+
import { useCliContext } from '../components/Context.js';
|
|
6
7
|
export default ({ params }) => {
|
|
8
|
+
const { apikey, url } = useCliContext();
|
|
7
9
|
const [resp, setResp] = useState();
|
|
8
10
|
const userId = params?._?.[0];
|
|
9
11
|
if (!userId) {
|
|
@@ -18,7 +20,7 @@ export default ({ params }) => {
|
|
|
18
20
|
url: `/users/${userId}/preferences/${topicId}/flush`,
|
|
19
21
|
};
|
|
20
22
|
useEffect(() => {
|
|
21
|
-
api(request).then(res => setResp(res));
|
|
23
|
+
api(request, url, apikey).then(res => setResp(res));
|
|
22
24
|
}, []);
|
|
23
25
|
return (React.createElement(React.Fragment, null,
|
|
24
26
|
React.createElement(Request, { request: request, response: resp }),
|
package/dist/commands/Help.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Box, Text, Newline } from 'ink';
|
|
3
3
|
import constants from '../constants.js';
|
|
4
|
+
import Table from '../components/Table.js';
|
|
5
|
+
import { COMMON_OPTIONS } from '../mappings.js';
|
|
6
|
+
const Space = () => React.createElement(React.Fragment, null, ' ');
|
|
4
7
|
export default ({ mappings }) => {
|
|
5
8
|
const keys = [...mappings.keys()]; // convert to array
|
|
6
|
-
return (React.createElement(Box, { flexDirection: "column" },
|
|
9
|
+
return (React.createElement(Box, { flexDirection: "column", paddingY: 2 },
|
|
7
10
|
React.createElement(Text, { bold: true }, "Usage"),
|
|
8
11
|
React.createElement(Text, null,
|
|
9
12
|
"$ ",
|
|
@@ -11,6 +14,9 @@ export default ({ mappings }) => {
|
|
|
11
14
|
' ',
|
|
12
15
|
React.createElement(Text, { color: "gray" }, "<command>"),
|
|
13
16
|
React.createElement(Newline, null)),
|
|
17
|
+
React.createElement(Text, { bold: true }, "Common Flags"),
|
|
18
|
+
React.createElement(Table, { data: COMMON_OPTIONS, headerLabels: { option: 'Flags', value: 'Description' } }),
|
|
19
|
+
React.createElement(Newline, null),
|
|
14
20
|
React.createElement(Text, { bold: true }, "Commands"),
|
|
15
21
|
keys.map(k => {
|
|
16
22
|
const v = mappings.get(k);
|
|
@@ -18,31 +24,21 @@ export default ({ mappings }) => {
|
|
|
18
24
|
return null;
|
|
19
25
|
}
|
|
20
26
|
return (React.createElement(React.Fragment, { key: k },
|
|
21
|
-
React.createElement(Box,
|
|
27
|
+
React.createElement(Box, { paddingTop: 2 },
|
|
22
28
|
React.createElement(Text, null,
|
|
23
|
-
' • ',
|
|
24
29
|
React.createElement(Text, { color: constants.colors.primary }, k),
|
|
25
30
|
v.params ? React.createElement(Text, { color: "gray" },
|
|
26
31
|
" ",
|
|
27
32
|
v.params) : null)),
|
|
28
33
|
React.createElement(Box, null,
|
|
29
34
|
React.createElement(Text, null,
|
|
30
|
-
|
|
35
|
+
React.createElement(Space, null),
|
|
31
36
|
v.instructions)),
|
|
32
|
-
v.options
|
|
33
|
-
? v.options.map(o => (React.createElement(React.Fragment, { key: o.option },
|
|
34
|
-
React.createElement(Box, null,
|
|
35
|
-
React.createElement(Text, { color: "gray" },
|
|
36
|
-
' ',
|
|
37
|
-
o.option),
|
|
38
|
-
React.createElement(Text, null,
|
|
39
|
-
" ",
|
|
40
|
-
o.value)))))
|
|
41
|
-
: null,
|
|
37
|
+
v.options?.length && (React.createElement(Table, { data: v.options, headerLabels: { option: 'Flags', value: 'Description' } })),
|
|
42
38
|
v.example && Array.isArray(v.example) ? (v.example.map((e, i) => (React.createElement(Text, { color: "cyan", key: i },
|
|
43
|
-
|
|
39
|
+
React.createElement(Space, null),
|
|
44
40
|
e)))) : v.example ? (React.createElement(Text, { color: "cyan" },
|
|
45
|
-
|
|
41
|
+
React.createElement(Space, null),
|
|
46
42
|
v.example)) : null));
|
|
47
43
|
})));
|
|
48
44
|
};
|
package/dist/commands/Send.js
CHANGED
|
@@ -6,68 +6,81 @@ import Response from '../components/Response.js';
|
|
|
6
6
|
import Elemental from '../components/Elemental.js';
|
|
7
7
|
import api from '../lib/api.js';
|
|
8
8
|
import { Box, Text } from 'ink';
|
|
9
|
+
import { useCliContext } from '../components/Context.js';
|
|
10
|
+
import lodash from 'lodash';
|
|
9
11
|
const constructPayload = (params) => {
|
|
10
12
|
const to = [];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const { _, user, list, audience, email, tel, apn, fcm, title, body, message, template, channel, channels, all, elemental, mock, tenant, 'include-children': includeChildren, 'tenant-context': tenantContext, includeChildren: _includeChildren, tenantContext: _tenantContext, ...data } = params;
|
|
14
|
+
if (user) {
|
|
15
|
+
to.push({ user_id: String(user) });
|
|
13
16
|
}
|
|
14
|
-
if (
|
|
15
|
-
to.push({ list_id:
|
|
17
|
+
if (list) {
|
|
18
|
+
to.push({ list_id: list });
|
|
16
19
|
}
|
|
17
|
-
if (
|
|
18
|
-
to.push({ audience_id:
|
|
20
|
+
if (audience) {
|
|
21
|
+
to.push({ audience_id: audience });
|
|
19
22
|
}
|
|
20
|
-
if (
|
|
21
|
-
to.push({
|
|
23
|
+
if (tenant) {
|
|
24
|
+
to.push({ tenant_id: tenant });
|
|
25
|
+
if (includeChildren) {
|
|
26
|
+
to.push({ include_children: true });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (email) {
|
|
30
|
+
to.push({ email: email });
|
|
31
|
+
}
|
|
32
|
+
if (tel) {
|
|
33
|
+
to.push({ phone_number: tel });
|
|
22
34
|
}
|
|
23
|
-
if (
|
|
24
|
-
to.push({
|
|
35
|
+
if (apn) {
|
|
36
|
+
to.push({ apn: { token: apn } });
|
|
25
37
|
}
|
|
26
|
-
if (
|
|
27
|
-
to.push({
|
|
38
|
+
if (fcm) {
|
|
39
|
+
to.push({ firebaseToken: fcm });
|
|
28
40
|
}
|
|
29
|
-
if (
|
|
30
|
-
to.
|
|
41
|
+
if (to.length && tenantContext) {
|
|
42
|
+
to.forEach((_t, i) => {
|
|
43
|
+
lodash.set(to, [i, 'context', 'tenant_id'], tenantContext);
|
|
44
|
+
});
|
|
31
45
|
}
|
|
32
46
|
let contentElemental = {
|
|
33
47
|
title: undefined,
|
|
34
48
|
body: undefined,
|
|
35
49
|
};
|
|
36
|
-
if (
|
|
37
|
-
contentElemental.title =
|
|
50
|
+
if (title) {
|
|
51
|
+
contentElemental.title = title;
|
|
38
52
|
}
|
|
39
|
-
if (
|
|
40
|
-
contentElemental.body =
|
|
53
|
+
if (body) {
|
|
54
|
+
contentElemental.body = body;
|
|
41
55
|
}
|
|
42
|
-
else if (
|
|
43
|
-
contentElemental.body =
|
|
56
|
+
else if (message) {
|
|
57
|
+
contentElemental.body = message;
|
|
44
58
|
}
|
|
45
59
|
let routing = {
|
|
46
60
|
channels: [],
|
|
47
61
|
method: params.all ? 'all' : 'single',
|
|
48
62
|
};
|
|
49
|
-
if (
|
|
50
|
-
routing.channels =
|
|
63
|
+
if (channel) {
|
|
64
|
+
routing.channels = channel.split(',');
|
|
51
65
|
}
|
|
52
|
-
else if (
|
|
53
|
-
routing.channels =
|
|
66
|
+
else if (channels) {
|
|
67
|
+
routing.channels = channels.split(',');
|
|
54
68
|
}
|
|
55
|
-
if (
|
|
69
|
+
if (email && email.length) {
|
|
56
70
|
routing.channels.push('email');
|
|
57
71
|
}
|
|
58
|
-
if (
|
|
72
|
+
if (tel && tel.length) {
|
|
59
73
|
routing.channels.push('sms');
|
|
60
74
|
}
|
|
61
|
-
if ((
|
|
75
|
+
if ((apn && apn.length) || (fcm && fcm.length)) {
|
|
62
76
|
routing.channels.push('push');
|
|
63
77
|
}
|
|
64
|
-
|
|
65
|
-
if (params.template) {
|
|
78
|
+
if (template) {
|
|
66
79
|
return {
|
|
67
80
|
type: 'template',
|
|
68
81
|
message: {
|
|
69
82
|
to: to.length === 1 ? to[0] : to,
|
|
70
|
-
template
|
|
83
|
+
template,
|
|
71
84
|
routing: routing.channels.length ? routing : undefined,
|
|
72
85
|
data: data ? data : undefined,
|
|
73
86
|
},
|
|
@@ -86,6 +99,7 @@ const constructPayload = (params) => {
|
|
|
86
99
|
}
|
|
87
100
|
};
|
|
88
101
|
export default ({ params }) => {
|
|
102
|
+
const { apikey, url } = useCliContext();
|
|
89
103
|
const [resp, setResp] = useState();
|
|
90
104
|
if (!params.body && !params.template && !params.elemental) {
|
|
91
105
|
return (React.createElement(UhOh, { text: "You must specify a message body, template, or Elemental file path." }));
|
|
@@ -117,7 +131,7 @@ export default ({ params }) => {
|
|
|
117
131
|
setResp({ res: { status: 999, statusText: 'MOCKED' } });
|
|
118
132
|
return;
|
|
119
133
|
}
|
|
120
|
-
api(request).then(res => setResp(res));
|
|
134
|
+
api(request, url, apikey).then(res => setResp(res));
|
|
121
135
|
}, []);
|
|
122
136
|
return (React.createElement(Box, { flexDirection: "column" },
|
|
123
137
|
params.elemental ? (React.createElement(React.Fragment, null,
|
package/dist/commands/Track.js
CHANGED
|
@@ -3,7 +3,9 @@ import UhOh from '../components/UhOh.js';
|
|
|
3
3
|
import Request from '../components/Request.js';
|
|
4
4
|
import Response from '../components/Response.js';
|
|
5
5
|
import api from '../lib/api.js';
|
|
6
|
+
import { useCliContext } from '../components/Context.js';
|
|
6
7
|
export default ({ params }) => {
|
|
8
|
+
const { apikey, url } = useCliContext();
|
|
7
9
|
const [resp, setResp] = useState();
|
|
8
10
|
const eventId = params?._?.[0];
|
|
9
11
|
if (!eventId) {
|
|
@@ -29,7 +31,7 @@ export default ({ params }) => {
|
|
|
29
31
|
body: payload,
|
|
30
32
|
};
|
|
31
33
|
useEffect(() => {
|
|
32
|
-
api(request).then(res => setResp(res));
|
|
34
|
+
api(request, url, apikey).then(res => setResp(res));
|
|
33
35
|
}, []);
|
|
34
36
|
return (React.createElement(React.Fragment, null,
|
|
35
37
|
React.createElement(Request, { request: request, response: resp }),
|
|
@@ -4,7 +4,9 @@ import UhOh from '../components/UhOh.js';
|
|
|
4
4
|
import Request from '../components/Request.js';
|
|
5
5
|
import Response from '../components/Response.js';
|
|
6
6
|
import api from '../lib/api.js';
|
|
7
|
+
import { useCliContext } from '../components/Context.js';
|
|
7
8
|
export default ({ params }) => {
|
|
9
|
+
const { apikey, url } = useCliContext();
|
|
8
10
|
const [resp, setResp] = useState();
|
|
9
11
|
const locale = params?._?.[0];
|
|
10
12
|
if (!locale) {
|
|
@@ -16,7 +18,7 @@ export default ({ params }) => {
|
|
|
16
18
|
url: `/translations/${params.domain || 'default'}/${locale}`,
|
|
17
19
|
};
|
|
18
20
|
useEffect(() => {
|
|
19
|
-
api(request).then(res => {
|
|
21
|
+
api(request, url, apikey).then(res => {
|
|
20
22
|
res.res.headers.get('content-type');
|
|
21
23
|
setResp(res);
|
|
22
24
|
});
|
|
@@ -4,7 +4,9 @@ import UhOh from '../components/UhOh.js';
|
|
|
4
4
|
import Request from '../components/Request.js';
|
|
5
5
|
import Response from '../components/Response.js';
|
|
6
6
|
import api from '../lib/api.js';
|
|
7
|
+
import { useCliContext } from '../components/Context.js';
|
|
7
8
|
export default ({ params }) => {
|
|
9
|
+
const { apikey, url } = useCliContext();
|
|
8
10
|
const [resp, setResp] = useState();
|
|
9
11
|
const locale = params?._?.[0];
|
|
10
12
|
if (!locale) {
|
|
@@ -27,7 +29,7 @@ export default ({ params }) => {
|
|
|
27
29
|
body: po,
|
|
28
30
|
};
|
|
29
31
|
useEffect(() => {
|
|
30
|
-
api(request).then(res => setResp(res));
|
|
32
|
+
api(request, url, apikey).then(res => setResp(res));
|
|
31
33
|
}, []);
|
|
32
34
|
return (React.createElement(React.Fragment, null,
|
|
33
35
|
React.createElement(Request, { request: request, response: resp }),
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Alert } from '@inkjs/ui';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import { useBoolean } from 'usehooks-ts';
|
|
4
|
+
import { useCliContext } from '../components/Context.js';
|
|
5
|
+
import Spinner from '../components/Spinner.js';
|
|
6
|
+
import { Box } from 'ink';
|
|
7
|
+
import { execa } from 'execa';
|
|
8
|
+
import constants from '../constants.js';
|
|
9
|
+
export default () => {
|
|
10
|
+
const { latest } = useCliContext();
|
|
11
|
+
const running = useBoolean(true);
|
|
12
|
+
const [error, setError] = useState();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
upgrade();
|
|
15
|
+
}, []);
|
|
16
|
+
const upgrade = async () => {
|
|
17
|
+
try {
|
|
18
|
+
await execa('npm', ['upgrade', '-g', `${constants.package_name}@${latest}`], {
|
|
19
|
+
shell: true,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
setError(e.message);
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
running.setFalse();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
if (running.value) {
|
|
30
|
+
return React.createElement(Spinner, { text: `Upgrading Courier CLI ${latest}` });
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const text = `Courier CLI upgraded to ${latest}`;
|
|
34
|
+
return (React.createElement(Box, { width: error ? undefined : text.length + 8 }, error?.length ? (React.createElement(Alert, { variant: "error", title: 'Error' }, error)) : (React.createElement(Alert, { variant: "success", title: 'Upgraded' }, text))));
|
|
35
|
+
}
|
|
36
|
+
};
|