@trycourier/cli 1.3.2 → 1.4.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 +29 -4
- package/dist/cli.js +1 -8
- package/dist/commands/Config.d.ts +9 -0
- package/dist/commands/Config.js +18 -0
- package/dist/commands/Send.js +1 -1
- package/dist/commands/WhoAmI.js +2 -1
- package/dist/components/Router.d.ts +1 -1
- package/dist/components/Router.js +14 -2
- package/dist/mappings.d.ts +1 -0
- package/dist/mappings.js +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,12 +8,13 @@ The Courier CLI is a developer tool to help you build, test, and manage your int
|
|
|
8
8
|
- Track events to trigger your Courier Automations
|
|
9
9
|
- Push & pull industry-standard translation files for internationalizing your content
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Installing the Courier CLI
|
|
12
12
|
|
|
13
|
-
From the command-line, use the following command to install the Courier CLI:
|
|
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
|
$ npm install -g @trycourier/cli
|
|
17
|
+
$ courier config --apikey <your-api-key>
|
|
17
18
|
```
|
|
18
19
|
|
|
19
20
|
### Requirements
|
|
@@ -22,6 +23,12 @@ $ npm install -g @trycourier/cli
|
|
|
22
23
|
|
|
23
24
|
## Authenticate the CLI
|
|
24
25
|
|
|
26
|
+
The fastest way to get started is to run:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
$ courier config --apikey <your-api-key>
|
|
30
|
+
```
|
|
31
|
+
|
|
25
32
|
Courier CLI looks for an environment variable named `COURIER_API_KEY`. It will load that key from the first location it finds in the following list:
|
|
26
33
|
|
|
27
34
|
- A `.courier` file in the current working directory
|
|
@@ -32,15 +39,33 @@ You can find your Courier API key in your [Courier Settings](https://app.courier
|
|
|
32
39
|
|
|
33
40
|
## Commands
|
|
34
41
|
|
|
42
|
+
- `courier config` – Set your Courier API key
|
|
35
43
|
- `courier whoami` – Display the currently authenticated workspace
|
|
36
44
|
- `courier send` - Send a notification to a user, list, or audience
|
|
37
|
-
- `courier track` - Send
|
|
38
|
-
- `courier digests:flush`
|
|
45
|
+
- `courier track` - Send a track event to trigger a Courier Automations
|
|
46
|
+
- `courier digests:flush` – Flush any currently queued events for a given user + digest
|
|
39
47
|
- `courier translations:upload` - Upload .PO files to your Courier workspace
|
|
40
48
|
- `courier translations:download` - Download .PO files from your Courier workspace
|
|
41
49
|
|
|
42
50
|
For more details, run `courier` to see a list of commands and their arguments & options.
|
|
43
51
|
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
$ courier send --tel 555-867-5309 --body "Hey Jenny\\!"
|
|
56
|
+
$ courier send --user user123 --template my-template-id --foo bar
|
|
57
|
+
$ courier send --email user@example.com --title "My Subject" --body "My Body"
|
|
58
|
+
$ courier send --user user123 --title "Important\\!" --body "Lorem Ipsum" --channels sms,push
|
|
59
|
+
$ courier send --user user123 --elemental my-template.json --foo bar
|
|
60
|
+
|
|
61
|
+
$ courier track my-event user123 --foo bar
|
|
62
|
+
|
|
63
|
+
$ courier digests:flush user123 my-digest-id
|
|
64
|
+
|
|
65
|
+
$ courier translations:upload en-US ./translations/en-US.po
|
|
66
|
+
$ courier translations:download en-US --text > example.en-US.po
|
|
67
|
+
```
|
|
68
|
+
|
|
44
69
|
## License
|
|
45
70
|
|
|
46
71
|
[MIT License](http://www.opensource.org/licenses/mit-license.php)
|
package/dist/cli.js
CHANGED
|
@@ -8,14 +8,7 @@ const CLI = async () => {
|
|
|
8
8
|
const params = args(process.argv);
|
|
9
9
|
const mappings = (await import('./mappings.js')).default;
|
|
10
10
|
const Router = (await import('./components/Router.js')).default;
|
|
11
|
-
|
|
12
|
-
const apiKey = process.env['COURIER_API_KEY'];
|
|
13
|
-
if (apiKey && apiKey.length) {
|
|
14
|
-
render(React.createElement(Router, { args: params, mappings: mappings }));
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
render(React.createElement(UhOh, { text: "No COURIER_API_KEY specified; add that to your environment or ~/.courier file" }));
|
|
18
|
-
}
|
|
11
|
+
render(React.createElement(Router, { args: params, mappings: mappings }));
|
|
19
12
|
};
|
|
20
13
|
(async () => {
|
|
21
14
|
await CLI();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import UhOh from '../components/UhOh.js';
|
|
3
|
+
import { Text } from 'ink';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
export default ({ params }) => {
|
|
6
|
+
const FILE_PATH = `${process.cwd()}/.courier`;
|
|
7
|
+
if (!params?.apikey) {
|
|
8
|
+
return React.createElement(UhOh, { text: "You must specify your API key using --apikey <your-api-key>" });
|
|
9
|
+
}
|
|
10
|
+
if (fs.existsSync(FILE_PATH) && !params.overwrite) {
|
|
11
|
+
return React.createElement(UhOh, { text: `${FILE_PATH} already exists. Consider adding the --overwrite option` });
|
|
12
|
+
}
|
|
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
|
+
};
|
package/dist/commands/Send.js
CHANGED
|
@@ -91,7 +91,7 @@ export default ({ params }) => {
|
|
|
91
91
|
return (React.createElement(UhOh, { text: "You must specify a message body, template, or Elemental file path." }));
|
|
92
92
|
}
|
|
93
93
|
let payload = constructPayload(params);
|
|
94
|
-
if (!payload.message.to) {
|
|
94
|
+
if (Array.isArray(payload.message.to) && !payload.message.to.length) {
|
|
95
95
|
return React.createElement(UhOh, { text: "You must specify a recipient." });
|
|
96
96
|
}
|
|
97
97
|
if (payload.type === 'elemental' &&
|
package/dist/commands/WhoAmI.js
CHANGED
|
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
|
|
|
2
2
|
import { Box } from 'ink';
|
|
3
3
|
import KVP from '../components/KVP.js';
|
|
4
4
|
import Request from '../components/Request.js';
|
|
5
|
+
import Response from '../components/Response.js';
|
|
5
6
|
import api from '../lib/api.js';
|
|
6
7
|
export default () => {
|
|
7
8
|
const [resp, setResp] = useState();
|
|
@@ -14,7 +15,7 @@ export default () => {
|
|
|
14
15
|
}, []);
|
|
15
16
|
return (React.createElement(Box, { flexDirection: "column" },
|
|
16
17
|
React.createElement(Request, { request: request, response: resp }),
|
|
17
|
-
resp && resp.json ? (React.createElement(React.Fragment, null,
|
|
18
|
+
resp && resp.err ? (React.createElement(Response, { response: resp })) : resp && resp.json ? (React.createElement(React.Fragment, null,
|
|
18
19
|
React.createElement(KVP, { width: 20, label: "Workspace Name", value: resp.json.tenantName }),
|
|
19
20
|
React.createElement(KVP, { width: 20, label: "Workspace ID", value: resp.json.tenantId }),
|
|
20
21
|
React.createElement(KVP, { width: 20, label: "API Key Environment", value: resp.json.environment }),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import Help from '../commands/Help.js';
|
|
3
2
|
import yargs from 'yargs-parser';
|
|
3
|
+
import { Text } from 'ink';
|
|
4
|
+
import Help from '../commands/Help.js';
|
|
4
5
|
export default ({ args, mappings }) => {
|
|
5
6
|
if (!args.length || !args[0]) {
|
|
6
7
|
return React.createElement(Help, { mappings: mappings });
|
|
@@ -9,7 +10,18 @@ export default ({ args, mappings }) => {
|
|
|
9
10
|
const [, ...params] = args;
|
|
10
11
|
const parsedParams = params.length ? yargs(params) : undefined;
|
|
11
12
|
if (mapping) {
|
|
12
|
-
|
|
13
|
+
const apiKey = process.env['COURIER_API_KEY'];
|
|
14
|
+
if ((apiKey && apiKey.length) || mapping.noApiKeyRequired) {
|
|
15
|
+
return mapping.component(parsedParams);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return React.createElement(React.Fragment, null,
|
|
19
|
+
React.createElement(Text, { bold: true, color: "red" }, "No COURIER_API_KEY specified, please set via one of these options:"),
|
|
20
|
+
React.createElement(Text, { bold: true, color: "red" }, "\u2022 running \"courier config --apikey <your-api-key>\""),
|
|
21
|
+
React.createElement(Text, { bold: true, color: "red" }, "\u2022 setting COURIER_API_KEY in your shell via \"export COURIER_API_KEY=<your-api-key>\""),
|
|
22
|
+
React.createElement(Text, { bold: true, color: "red" }, "\u2022 setting COURIER_API_KEY in a \".courier\" file in your current working directory"),
|
|
23
|
+
React.createElement(Text, { bold: true, color: "red" }, "\u2022 setting COURIER_API_KEY in a \".courier\" file in your user's home directory"));
|
|
24
|
+
}
|
|
13
25
|
}
|
|
14
26
|
else {
|
|
15
27
|
return React.createElement(Help, { mappings: mappings });
|
package/dist/mappings.d.ts
CHANGED
package/dist/mappings.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Help from './commands/Help.js';
|
|
3
|
+
import Config from './commands/Config.js';
|
|
3
4
|
import WhoAmI from './commands/WhoAmI.js';
|
|
4
5
|
import Track from './commands/Track.js';
|
|
5
6
|
import Send from './commands/Send.js';
|
|
@@ -11,6 +12,25 @@ mappings.set('help', {
|
|
|
11
12
|
component: () => {
|
|
12
13
|
return React.createElement(Help, { mappings: mappings });
|
|
13
14
|
},
|
|
15
|
+
noApiKeyRequired: true
|
|
16
|
+
});
|
|
17
|
+
mappings.set('config', {
|
|
18
|
+
instructions: 'Persist your Courier API key into a .courier file in your current working directory',
|
|
19
|
+
component: params => {
|
|
20
|
+
return React.createElement(Config, { params: params });
|
|
21
|
+
},
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
option: '--apikey <Courier API Key>',
|
|
25
|
+
value: '',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
option: '--overwrite',
|
|
29
|
+
value: 'overwrite an existing .courier file',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
example: `courier config --apikey MY_API_KEY`,
|
|
33
|
+
noApiKeyRequired: true
|
|
14
34
|
});
|
|
15
35
|
mappings.set('whoami', {
|
|
16
36
|
instructions: 'Display the currently authenticated workspace',
|