@trycourier/cli 1.0.0 → 1.0.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/dist/commands/DigestFlush.js +2 -2
- package/dist/commands/Send.js +16 -2
- package/dist/components/Elemental.d.ts +13 -0
- package/dist/components/Elemental.js +24 -0
- package/dist/components/Request.d.ts +5 -1
- package/dist/components/Request.js +9 -2
- package/dist/lib/render-elemental.d.ts +2 -0
- package/dist/lib/render-elemental.js +1 -0
- package/package.json +1 -1
|
@@ -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',
|
package/dist/commands/Send.js
CHANGED
|
@@ -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,19 @@ 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(
|
|
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,
|
|
105
|
+
' ',
|
|
106
|
+
"Elemental")),
|
|
107
|
+
React.createElement(Box, null,
|
|
108
|
+
React.createElement(Elemental, { elemental: payload.message.content })))) : null,
|
|
109
|
+
React.createElement(Request, { request: request, response: resp })));
|
|
96
110
|
};
|
|
@@ -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,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Text, Spacer } 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(Spacer, null)),
|
|
22
|
+
React.createElement(Box, { borderStyle: 'round', flexDirection: 'column', paddingX: 1 },
|
|
23
|
+
React.createElement(Text, null, property.value))))))));
|
|
24
|
+
};
|
|
@@ -5,10 +5,14 @@ interface IRequest {
|
|
|
5
5
|
body?: object | string;
|
|
6
6
|
}
|
|
7
7
|
interface IResponse {
|
|
8
|
-
res:
|
|
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
14
|
props.request.body && (React.createElement(Text, null, JSON.stringify(props.request.body, undefined, ' '))),
|
|
14
|
-
!props.request.body ?
|
|
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)
|
|
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 @@
|
|
|
1
|
+
export default () => { return; };
|