@trycourier/cli 1.0.0 → 1.1.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
@@ -35,6 +35,8 @@ You can find your Courier API key in your [Courier Settings](https://app.courier
35
35
  - `courier whoami` – Display the currently authenticated workspace
36
36
  - `courier send` - Send a notification to a user, list, or audience
37
37
  - `courier track` - Send an event to test your Courier Automations
38
+ - `courier digests:flush` - Send an event to test your Courier Automations
39
+ - `courier translations:upload` - Upload .PO files to your Courier workspace
38
40
 
39
41
  For more details, run `courier` to see a list of commands and their arguments & options.
40
42
 
@@ -6,11 +6,11 @@ export default ({ params }) => {
6
6
  const [resp, setResp] = useState();
7
7
  const userId = params?._?.[0];
8
8
  if (!userId) {
9
- return React.createElement(UhOh, { text: "You must specify the ID of the user whose digest you want to flush." });
9
+ return (React.createElement(UhOh, { text: "You must specify the ID of the user whose digest you want to flush." }));
10
10
  }
11
11
  const topicId = params?._?.[1];
12
12
  if (!topicId) {
13
- return React.createElement(UhOh, { text: "You must specify the ID of the Digest-enabled Subscription Topic you want to flush for the given user." });
13
+ return (React.createElement(UhOh, { text: "You must specify the ID of the Digest-enabled Subscription Topic you want to flush for the given user." }));
14
14
  }
15
15
  const request = {
16
16
  method: 'POST',
@@ -2,7 +2,9 @@ import React, { useEffect, useState } from 'react';
2
2
  import fs from 'fs';
3
3
  import UhOh from '../components/UhOh.js';
4
4
  import Request from '../components/Request.js';
5
+ import Elemental from '../components/Elemental.js';
5
6
  import api from '../lib/api.js';
7
+ import { Box, Text } from 'ink';
6
8
  const constructPayload = (params) => {
7
9
  const to = [];
8
10
  if (params.user) {
@@ -58,7 +60,7 @@ const constructPayload = (params) => {
58
60
  if ((params.apn && params.apn.length) || (params.fcm && params.fcm.length)) {
59
61
  routing.channels.push('push');
60
62
  }
61
- const { _, user, list, audience, email, tel, apn, fcm, title, body, elemental, ...data } = params;
63
+ const { _, user, list, audience, email, tel, apn, fcm, title, body, elemental, mock, ...data } = params;
62
64
  return {
63
65
  message: {
64
66
  to: to.length === 1 ? to[0] : to,
@@ -90,7 +92,17 @@ export default ({ params }) => {
90
92
  body: payload,
91
93
  };
92
94
  useEffect(() => {
95
+ if (params.mock) {
96
+ setResp({ res: { status: 999, statusText: 'MOCKED' } });
97
+ return;
98
+ }
93
99
  api(request).then(res => setResp(res));
94
100
  }, []);
95
- return React.createElement(Request, { request: request, response: resp });
101
+ return (React.createElement(Box, { flexDirection: "column" },
102
+ params.elemental ? (React.createElement(React.Fragment, null,
103
+ React.createElement(Box, { borderStyle: "bold", borderColor: "white" },
104
+ React.createElement(Text, null, " Elemental")),
105
+ React.createElement(Box, null,
106
+ React.createElement(Elemental, { elemental: payload.message.content })))) : null,
107
+ React.createElement(Request, { request: request, response: resp })));
96
108
  };
@@ -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,28 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import fs from 'fs';
3
+ import UhOh from '../components/UhOh.js';
4
+ import Request from '../components/Request.js';
5
+ import api from '../lib/api.js';
6
+ export default ({ params }) => {
7
+ const [resp, setResp] = useState();
8
+ const locale = params?._?.[0];
9
+ if (!locale) {
10
+ return React.createElement(UhOh, { text: "You must specify a locale, e.g. en-US." });
11
+ }
12
+ const filepath = params?._?.[1];
13
+ if (!filepath) {
14
+ return React.createElement(UhOh, { text: "You must specify a path to the .PO file." });
15
+ }
16
+ else if (!fs.existsSync(filepath)) {
17
+ return React.createElement(UhOh, { text: "No .PO file found at given path." });
18
+ }
19
+ const request = {
20
+ method: 'PUT',
21
+ url: `/translations/global/${locale}`,
22
+ body: fs.readFileSync(filepath, 'utf8'),
23
+ };
24
+ useEffect(() => {
25
+ api(request).then(res => setResp(res));
26
+ }, []);
27
+ return React.createElement(Request, { request: request, response: resp });
28
+ };
@@ -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,28 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import fs from 'fs';
3
+ import UhOh from '../components/UhOh.js';
4
+ import Request from '../components/Request.js';
5
+ import api from '../lib/api.js';
6
+ export default ({ params }) => {
7
+ const [resp, setResp] = useState();
8
+ const locale = params?._?.[0];
9
+ if (!locale) {
10
+ return React.createElement(UhOh, { text: "You must specify a locale, e.g. en-US." });
11
+ }
12
+ const filepath = params?._?.[1];
13
+ if (!filepath) {
14
+ return React.createElement(UhOh, { text: "You must specify a path to the .PO file." });
15
+ }
16
+ else if (!fs.existsSync(filepath)) {
17
+ return React.createElement(UhOh, { text: "No .PO file found at given path." });
18
+ }
19
+ const request = {
20
+ method: 'PUT',
21
+ url: `/translations/global/${locale}`,
22
+ body: fs.readFileSync(filepath, 'utf8'),
23
+ };
24
+ useEffect(() => {
25
+ api(request).then(res => setResp(res));
26
+ }, []);
27
+ return React.createElement(Request, { request: request, response: resp });
28
+ };
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ interface IElement {
3
+ type: string;
4
+ }
5
+ interface IElemental {
6
+ version: string;
7
+ elements: IElement[];
8
+ }
9
+ type Props = {
10
+ elemental: IElemental;
11
+ };
12
+ declare const _default: ({ elemental }: Props) => React.JSX.Element;
13
+ export default _default;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { Box, Text } from 'ink';
3
+ export default ({ elemental }) => {
4
+ const buckets = [];
5
+ elemental.elements.map(element => {
6
+ const { type, ...rest } = element;
7
+ buckets.push({
8
+ type: element.type,
9
+ properties: Object.keys(rest).map(key => ({
10
+ name: key,
11
+ value: rest[key],
12
+ })),
13
+ });
14
+ });
15
+ return (React.createElement(Box, { flexDirection: "column" }, buckets.map(bucket => bucket.properties.map(property => (React.createElement(Box, null,
16
+ React.createElement(Box, { width: 16, paddingTop: 1 },
17
+ React.createElement(Text, null,
18
+ bucket.type,
19
+ ".",
20
+ property.name)),
21
+ React.createElement(Box, { borderStyle: "round", flexDirection: "column", paddingX: 1 },
22
+ React.createElement(Text, null, property.value))))))));
23
+ };
@@ -5,10 +5,14 @@ interface IRequest {
5
5
  body?: object | string;
6
6
  }
7
7
  interface IResponse {
8
- res: Response;
8
+ res: IHttpResponse;
9
9
  json?: any;
10
10
  err?: Error;
11
11
  }
12
+ interface IHttpResponse {
13
+ status: number;
14
+ statusText: string;
15
+ }
12
16
  type Props = {
13
17
  request: IRequest;
14
18
  response?: IResponse;
@@ -6,19 +6,26 @@ export default (props) => {
6
6
  return (React.createElement(Box, { flexDirection: "column" },
7
7
  React.createElement(Box, { borderStyle: "bold", borderColor: "blue" },
8
8
  React.createElement(Text, null,
9
+ ' ',
9
10
  React.createElement(Text, { bold: true }, props.request.method),
10
11
  ' ',
11
12
  "https://api.courier.com",
12
13
  props.request.url)),
13
- props.request.body && (React.createElement(Text, null, JSON.stringify(props.request.body, undefined, ' '))),
14
- !props.request.body ? (React.createElement(Text, { color: "gray" }, "No request body")) : null,
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
+ !props.request.body ? React.createElement(Text, { color: "gray" }, "No request body") : null,
15
16
  !props.response ? (React.createElement(Spinner, { text: props.spinnerText || defaultSpinnerText })) : null,
16
17
  props.response ? (React.createElement(Box, { borderStyle: "bold", borderColor: props.response?.err ? 'red' : 'green' },
17
18
  React.createElement(Text, null,
19
+ ' ',
18
20
  "HTTP",
19
21
  ' ',
20
22
  React.createElement(Text, { bold: true }, props.response.err
21
23
  ? props.response.err.message
22
- : props.response?.res?.status)))) : null,
24
+ : props.response?.res?.status),
25
+ ' ',
26
+ !props.response.err ? (React.createElement(React.Fragment, null,
27
+ React.createElement(Text, null,
28
+ "\u2022 ",
29
+ props.response.res.statusText))) : null))) : null,
23
30
  props.response && !props.hideResponse ? (props.response.json ? (React.createElement(Text, null, JSON.stringify(props.response.json, undefined, ' '))) : (React.createElement(Text, { color: "gray" }, "No response body"))) : null));
24
31
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: () => void;
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export default () => { return; };
package/dist/mappings.js CHANGED
@@ -4,6 +4,7 @@ import WhoAmI from './commands/WhoAmI.js';
4
4
  import Track from './commands/Track.js';
5
5
  import Send from './commands/Send.js';
6
6
  import DigestFlush from './commands/DigestFlush.js';
7
+ import TranslationsUpload from './commands/TranslationsUpload.js';
7
8
  const mappings = new Map();
8
9
  mappings.set('help', {
9
10
  component: () => {
@@ -95,4 +96,11 @@ mappings.set('digest:flush', {
95
96
  return React.createElement(DigestFlush, { params: params });
96
97
  },
97
98
  });
99
+ mappings.set('translations:upload', {
100
+ params: '<locale> <filepath>',
101
+ instructions: 'Upload a .PO file to Courier for a given locale',
102
+ component: params => {
103
+ return React.createElement(TranslationsUpload, { params: params });
104
+ },
105
+ });
98
106
  export default mappings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/cli",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "courier": "dist/cli.js"