@trycourier/cli 1.3.2 → 1.4.0
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 +10 -2
- package/dist/cli.js +1 -8
- package/dist/commands/Config.d.ts +9 -0
- package/dist/commands/Config.js +18 -0
- 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,6 +39,7 @@ 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 in `~/.courier`
|
|
35
43
|
- `courier whoami` – Display the currently authenticated workspace
|
|
36
44
|
- `courier send` - Send a notification to a user, list, or audience
|
|
37
45
|
- `courier track` - Send an event to test your Courier Automations
|
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/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',
|