@trycourier/cli 1.4.0 → 1.5.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 CHANGED
@@ -39,16 +39,38 @@ You can find your Courier API key in your [Courier Settings](https://app.courier
39
39
 
40
40
  ## Commands
41
41
 
42
- - `courier config` – Set your Courier API key in `~/.courier`
42
+ - `courier config` – Set your Courier API key
43
43
  - `courier whoami` – Display the currently authenticated workspace
44
44
  - `courier send` - Send a notification to a user, list, or audience
45
- - `courier track` - Send an event to test your Courier Automations
46
- - `courier digests:flush` - Send an event to test your Courier Automations
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 digests:flush` – Flush any currently queued events for a given user + digest
47
49
  - `courier translations:upload` - Upload .PO files to your Courier workspace
48
50
  - `courier translations:download` - Download .PO files from your Courier workspace
49
51
 
50
52
  For more details, run `courier` to see a list of commands and their arguments & options.
51
53
 
54
+ ## Examples
55
+
56
+ ```
57
+ $ courier send --tel 555-867-5309 --body "Hey Jenny\\!"
58
+ $ courier send --user user123 --template my-template-id --foo bar
59
+ $ courier send --email user@example.com --title "My Subject" --body "My Body"
60
+ $ courier send --user user123 --title "Important\\!" --body "Lorem Ipsum" --channels sms,push
61
+ $ courier send --user user123 --elemental my-template.json --foo bar
62
+
63
+ $ courier track my-event user123 --foo bar
64
+
65
+ $ courier users:get user123
66
+ $ courier users:set user123 --email user@example.com --tel 555-867-5309
67
+
68
+ $ courier digests:flush user123 my-digest-id
69
+
70
+ $ courier translations:upload en-US ./translations/en-US.po
71
+ $ courier translations:download en-US --text > example.en-US.po
72
+ ```
73
+
52
74
  ## License
53
75
 
54
76
  [MIT License](http://www.opensource.org/licenses/mit-license.php)
@@ -5,10 +5,10 @@ import fs from 'fs';
5
5
  export default ({ params }) => {
6
6
  const FILE_PATH = `${process.cwd()}/.courier`;
7
7
  if (!params?.apikey) {
8
- return React.createElement(UhOh, { text: "You must specify your API key using --apikey <your-api-key>" });
8
+ return (React.createElement(UhOh, { text: "You must specify your API key using --apikey <your-api-key>" }));
9
9
  }
10
10
  if (fs.existsSync(FILE_PATH) && !params.overwrite) {
11
- return React.createElement(UhOh, { text: `${FILE_PATH} already exists. Consider adding the --overwrite option` });
11
+ return (React.createElement(UhOh, { text: `${FILE_PATH} already exists. Consider adding the --overwrite option` }));
12
12
  }
13
13
  fs.writeFileSync(FILE_PATH, `COURIER_API_KEY=${params.apikey}\n`);
14
14
  return (React.createElement(Text, { bold: true, color: "green" },
@@ -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' &&
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ declare const _default: ({ params }: {
3
+ params: any;
4
+ }) => React.JSX.Element;
5
+ export default _default;
@@ -0,0 +1,22 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import UhOh from '../components/UhOh.js';
3
+ import Request from '../components/Request.js';
4
+ import Response from '../components/Response.js';
5
+ import api from '../lib/api.js';
6
+ export default ({ params }) => {
7
+ const [resp, setResp] = useState();
8
+ const userId = params?._?.[0];
9
+ if (!userId) {
10
+ return React.createElement(UhOh, { text: "You must specify a user ID." });
11
+ }
12
+ const request = {
13
+ method: 'GET',
14
+ url: `/profiles/${userId}`,
15
+ };
16
+ useEffect(() => {
17
+ api(request).then(res => setResp(res));
18
+ }, []);
19
+ return (React.createElement(React.Fragment, null,
20
+ React.createElement(Request, { request: request, response: resp }),
21
+ React.createElement(Response, { response: resp })));
22
+ };
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ declare const _default: ({ params }: {
3
+ params: any;
4
+ }) => React.JSX.Element;
5
+ export default _default;
@@ -0,0 +1,32 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import UhOh from '../components/UhOh.js';
3
+ import Request from '../components/Request.js';
4
+ import Response from '../components/Response.js';
5
+ import api from '../lib/api.js';
6
+ export default ({ params }) => {
7
+ const [resp, setResp] = useState();
8
+ const userId = params?._?.[0];
9
+ if (!userId) {
10
+ return React.createElement(UhOh, { text: "You must specify a user ID." });
11
+ }
12
+ const { _, ...properties } = params;
13
+ if (properties.tel) {
14
+ properties.phone_number = properties.tel;
15
+ delete properties.tel;
16
+ }
17
+ const request = {
18
+ method: 'PUT',
19
+ url: `/profiles/${userId}`,
20
+ body: {
21
+ profile: {
22
+ ...properties,
23
+ },
24
+ },
25
+ };
26
+ useEffect(() => {
27
+ api(request).then(res => setResp(res));
28
+ }, []);
29
+ return (React.createElement(React.Fragment, null,
30
+ React.createElement(Request, { request: request, response: resp }),
31
+ React.createElement(Response, { response: resp })));
32
+ };
@@ -9,7 +9,7 @@ export default (props) => {
9
9
  React.createElement(Text, null,
10
10
  ' ',
11
11
  React.createElement(Text, { bold: true }, props.request.method),
12
- ' ',
12
+ " ",
13
13
  url)),
14
14
  props.request.body ? (typeof props.request.body === 'string' ? (React.createElement(Text, null, props.request.body)) : (React.createElement(Text, null, JSON.stringify(props.request.body, undefined, ' ')))) : null,
15
15
  !props.request.body ? React.createElement(Text, { color: "gray" }, "No request body") : null,
@@ -15,12 +15,12 @@ export default ({ args, mappings }) => {
15
15
  return mapping.component(parsedParams);
16
16
  }
17
17
  else {
18
- return React.createElement(React.Fragment, null,
18
+ return (React.createElement(React.Fragment, null,
19
19
  React.createElement(Text, { bold: true, color: "red" }, "No COURIER_API_KEY specified, please set via one of these options:"),
20
20
  React.createElement(Text, { bold: true, color: "red" }, "\u2022 running \"courier config --apikey <your-api-key>\""),
21
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
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"));
23
+ React.createElement(Text, { bold: true, color: "red" }, "\u2022 setting COURIER_API_KEY in a \".courier\" file in your user's home directory")));
24
24
  }
25
25
  }
26
26
  else {
package/dist/mappings.js CHANGED
@@ -3,6 +3,8 @@ import Help from './commands/Help.js';
3
3
  import Config from './commands/Config.js';
4
4
  import WhoAmI from './commands/WhoAmI.js';
5
5
  import Track from './commands/Track.js';
6
+ import UsersGet from './commands/UsersGet.js';
7
+ import UsersSet from './commands/UsersSet.js';
6
8
  import Send from './commands/Send.js';
7
9
  import DigestFlush from './commands/DigestFlush.js';
8
10
  import TranslationsDownload from './commands/TranslationsDownload.js';
@@ -12,7 +14,7 @@ mappings.set('help', {
12
14
  component: () => {
13
15
  return React.createElement(Help, { mappings: mappings });
14
16
  },
15
- noApiKeyRequired: true
17
+ noApiKeyRequired: true,
16
18
  });
17
19
  mappings.set('config', {
18
20
  instructions: 'Persist your Courier API key into a .courier file in your current working directory',
@@ -30,7 +32,7 @@ mappings.set('config', {
30
32
  },
31
33
  ],
32
34
  example: `courier config --apikey MY_API_KEY`,
33
- noApiKeyRequired: true
35
+ noApiKeyRequired: true,
34
36
  });
35
37
  mappings.set('whoami', {
36
38
  instructions: 'Display the currently authenticated workspace',
@@ -116,6 +118,36 @@ mappings.set('track', {
116
118
  return React.createElement(Track, { params: params });
117
119
  },
118
120
  });
121
+ mappings.set('users:get', {
122
+ params: '<user>',
123
+ instructions: 'Fetch the data for a given user ID',
124
+ example: `courier users:get user123`,
125
+ component: params => {
126
+ return React.createElement(UsersGet, { params: params });
127
+ },
128
+ });
129
+ mappings.set('users:set', {
130
+ params: '<user>',
131
+ instructions: "Overwrite a user's profile with the provided data",
132
+ options: [
133
+ {
134
+ option: '--email <email address>',
135
+ value: '',
136
+ },
137
+ {
138
+ option: '--tel <phone number>',
139
+ value: '',
140
+ },
141
+ {
142
+ option: '--<key> <value>',
143
+ value: 'arbitrary key/value properties for your user',
144
+ },
145
+ ],
146
+ example: `courier users:set user123 --email user@example.com`,
147
+ component: params => {
148
+ return React.createElement(UsersSet, { params: params });
149
+ },
150
+ });
119
151
  mappings.set('digests:flush', {
120
152
  params: '<user> <digest>',
121
153
  instructions: 'Flush any currently queued events for a given user + digest',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/cli",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "courier": "dist/cli.js"