@trycourier/cli 1.2.0 → 1.3.2

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
@@ -37,6 +37,7 @@ You can find your Courier API key in your [Courier Settings](https://app.courier
37
37
  - `courier track` - Send an event to test your Courier Automations
38
38
  - `courier digests:flush` - Send an event to test your Courier Automations
39
39
  - `courier translations:upload` - Upload .PO files to your Courier workspace
40
+ - `courier translations:download` - Download .PO files from your Courier workspace
40
41
 
41
42
  For more details, run `courier` to see a list of commands and their arguments & options.
42
43
 
@@ -20,7 +20,7 @@ export default ({ params }) => {
20
20
  useEffect(() => {
21
21
  api(request).then(res => setResp(res));
22
22
  }, []);
23
- return React.createElement(React.Fragment, null,
23
+ return (React.createElement(React.Fragment, null,
24
24
  React.createElement(Request, { request: request, response: resp }),
25
- React.createElement(Response, { response: resp }));
25
+ React.createElement(Response, { response: resp })));
26
26
  };
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  interface IMapping {
3
3
  params?: string;
4
4
  instructions?: string;
5
- example?: string;
5
+ example?: string | string[];
6
6
  options?: {
7
7
  option: string;
8
8
  value?: string;
@@ -39,7 +39,9 @@ export default ({ mappings }) => {
39
39
  " ",
40
40
  o.value)))))
41
41
  : null,
42
- v.example ? (React.createElement(Text, { color: "cyan" },
42
+ v.example && Array.isArray(v.example) ? (v.example.map((e, i) => (React.createElement(Text, { color: "cyan", key: i },
43
+ ' ',
44
+ e)))) : v.example ? (React.createElement(Text, { color: "cyan" },
43
45
  ' ',
44
46
  v.example)) : null));
45
47
  })));
@@ -29,18 +29,18 @@ const constructPayload = (params) => {
29
29
  if (params.fcm) {
30
30
  to.push({ firebaseToken: params.fcm });
31
31
  }
32
- let content = {
32
+ let contentElemental = {
33
33
  title: undefined,
34
34
  body: undefined,
35
35
  };
36
36
  if (params.title) {
37
- content.title = params.title;
37
+ contentElemental.title = params.title;
38
38
  }
39
39
  if (params.body) {
40
- content.body = params.body;
40
+ contentElemental.body = params.body;
41
41
  }
42
42
  else if (params.message) {
43
- content.body = params.message;
43
+ contentElemental.body = params.message;
44
44
  }
45
45
  let routing = {
46
46
  channels: [],
@@ -61,36 +61,56 @@ const constructPayload = (params) => {
61
61
  if ((params.apn && params.apn.length) || (params.fcm && params.fcm.length)) {
62
62
  routing.channels.push('push');
63
63
  }
64
- const { _, user, list, audience, email, tel, apn, fcm, title, body, elemental, mock, ...data } = params;
65
- return {
66
- message: {
67
- to: to.length === 1 ? to[0] : to,
68
- content,
69
- routing: routing.channels.length ? routing : undefined,
70
- data: data ? data : undefined,
71
- },
72
- };
64
+ const { _, user, list, audience, email, tel, apn, fcm, title, body, message, template, channel, channels, all, elemental, mock, ...data } = params;
65
+ if (params.template) {
66
+ return {
67
+ type: 'template',
68
+ message: {
69
+ to: to.length === 1 ? to[0] : to,
70
+ template: params.template,
71
+ routing: routing.channels.length ? routing : undefined,
72
+ data: data ? data : undefined,
73
+ },
74
+ };
75
+ }
76
+ else {
77
+ return {
78
+ type: 'elemental',
79
+ message: {
80
+ to: to.length === 1 ? to[0] : to,
81
+ content: contentElemental,
82
+ routing: routing.channels.length ? routing : undefined,
83
+ data: data ? data : undefined,
84
+ },
85
+ };
86
+ }
73
87
  };
74
88
  export default ({ params }) => {
75
89
  const [resp, setResp] = useState();
76
- const payload = constructPayload(params);
90
+ if (!params.body && !params.template && !params.elemental) {
91
+ return (React.createElement(UhOh, { text: "You must specify a message body, template, or Elemental file path." }));
92
+ }
93
+ let payload = constructPayload(params);
77
94
  if (!payload.message.to) {
78
95
  return React.createElement(UhOh, { text: "You must specify a recipient." });
79
96
  }
80
- if (!params.elemental &&
97
+ if (payload.type === 'elemental' &&
98
+ !params.elemental &&
81
99
  (!payload.message.content.body || !payload.message.content.body?.length)) {
82
- return React.createElement(UhOh, { text: "You must specify a body for the message." });
100
+ throw new Error('You must specify a body for the message.');
83
101
  }
84
- if (params.elemental) {
102
+ if (params.elemental && payload.type === 'elemental') {
85
103
  if (!fs.existsSync(params.elemental)) {
86
- return React.createElement(UhOh, { text: "Invalid file path to Elemental document." });
104
+ throw new Error('Invalid file path to Elemental document.');
87
105
  }
88
106
  payload.message.content = JSON.parse(fs.readFileSync(params.elemental, 'utf8'));
89
107
  }
90
108
  const request = {
91
109
  method: 'POST',
92
110
  url: '/send',
93
- body: payload,
111
+ body: {
112
+ message: payload.message,
113
+ },
94
114
  };
95
115
  useEffect(() => {
96
116
  if (params.mock) {
@@ -103,8 +123,7 @@ export default ({ params }) => {
103
123
  params.elemental ? (React.createElement(React.Fragment, null,
104
124
  React.createElement(Box, { borderStyle: "bold", borderColor: "white" },
105
125
  React.createElement(Text, null, " Elemental")),
106
- React.createElement(Box, null,
107
- React.createElement(Elemental, { elemental: payload.message.content })))) : null,
126
+ React.createElement(Box, null, payload.type === 'elemental' ? (React.createElement(Elemental, { elemental: payload.message.content })) : null))) : null,
108
127
  React.createElement(React.Fragment, null,
109
128
  React.createElement(Request, { request: request, response: resp }),
110
129
  React.createElement(Response, { response: resp }))));
@@ -31,7 +31,7 @@ export default ({ params }) => {
31
31
  useEffect(() => {
32
32
  api(request).then(res => setResp(res));
33
33
  }, []);
34
- return React.createElement(React.Fragment, null,
34
+ return (React.createElement(React.Fragment, null,
35
35
  React.createElement(Request, { request: request, response: resp }),
36
- React.createElement(Response, { response: resp }));
36
+ React.createElement(Response, { response: resp })));
37
37
  };
@@ -29,7 +29,7 @@ export default ({ params }) => {
29
29
  useEffect(() => {
30
30
  api(request).then(res => setResp(res));
31
31
  }, []);
32
- return React.createElement(React.Fragment, null,
32
+ return (React.createElement(React.Fragment, null,
33
33
  React.createElement(Request, { request: request, response: resp }),
34
- React.createElement(Response, { response: resp }));
34
+ React.createElement(Response, { response: resp })));
35
35
  };
@@ -3,14 +3,14 @@ import { Box, Text } from 'ink';
3
3
  import Spinner from './Spinner.js';
4
4
  const defaultSpinnerText = 'blipping those bits and blooping those bytes';
5
5
  export default (props) => {
6
+ const url = `${process.env['COURIER_DOMAIN'] || 'https://api.courier.com'}${props.request.url}`;
6
7
  return (React.createElement(Box, { flexDirection: "column" },
7
8
  React.createElement(Box, { borderStyle: "bold", borderColor: "blue" },
8
9
  React.createElement(Text, null,
9
10
  ' ',
10
11
  React.createElement(Text, { bold: true }, props.request.method),
11
12
  ' ',
12
- "https://api.courier.com",
13
- props.request.url)),
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,
16
16
  !props.response ? (React.createElement(Spinner, { text: props.spinnerText || defaultSpinnerText })) : null));
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  interface IMapping {
3
3
  params?: string;
4
4
  instructions?: string;
5
- example?: string;
5
+ example?: string | string[];
6
6
  options?: {
7
7
  option: string;
8
8
  value?: string;
package/dist/mappings.js CHANGED
@@ -19,7 +19,7 @@ mappings.set('whoami', {
19
19
  },
20
20
  });
21
21
  mappings.set('send', {
22
- instructions: 'Send a notification to a user, list, or audience',
22
+ instructions: 'Send a notification to a user, list, or audience. Unrecognized parameters will be sent as message data.',
23
23
  options: [
24
24
  {
25
25
  option: '--email <email address>',
@@ -61,6 +61,10 @@ mappings.set('send', {
61
61
  option: '--elemental <filepath>',
62
62
  value: 'path to Courier Elemental JSON file',
63
63
  },
64
+ {
65
+ option: '--template <template ID or alias>',
66
+ value: 'ID or alias of a template stored in Courier',
67
+ },
64
68
  {
65
69
  option: '--channels <channel>',
66
70
  value: 'comma-delimted list of channels to send to',
@@ -70,7 +74,10 @@ mappings.set('send', {
70
74
  value: 'send to all channels for each recipient (default is "single")',
71
75
  },
72
76
  ],
73
- example: `courier send --tel 555-867-5309 --body "Hey Jenny\\!"`,
77
+ example: [
78
+ `courier send --tel 555-867-5309 --body "Hey Jenny\\!"`,
79
+ `courier send --user user123 --template my-template-id --foo bar`,
80
+ ],
74
81
  component: params => {
75
82
  return React.createElement(Send, { params: params });
76
83
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/cli",
3
- "version": "1.2.0",
3
+ "version": "1.3.2",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "courier": "dist/cli.js"