@trycourier/cli 2.0.9 → 2.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 +11 -19
- package/dist/bulk.d.ts +11 -0
- package/dist/bulk.js +46 -0
- package/dist/cli.js +3 -3
- package/dist/commands/Inbox/ArchiveAll.d.ts +6 -0
- package/dist/commands/Inbox/ArchiveAll.js +173 -0
- package/dist/commands/Inbox/MarkAllRead.d.ts +5 -0
- package/dist/commands/Inbox/MarkAllRead.js +110 -0
- package/dist/commands/TenantsBulk.d.ts +3 -0
- package/dist/commands/TenantsBulk.js +173 -0
- package/dist/commands/Track.js +2 -1
- package/dist/commands/UsersBulk.js +6 -43
- package/dist/commands/UsersPreferences.js +40 -8
- package/dist/commands/WhoAmI.js +2 -1
- package/dist/components/Context.d.ts +6 -0
- package/dist/components/Context.js +15 -0
- package/dist/components/KVP.js +8 -7
- package/dist/components/SdkResponse.d.ts +3 -2
- package/dist/components/SdkResponse.js +5 -4
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/lib/uuid.d.ts +2 -0
- package/dist/lib/uuid.js +4 -0
- package/dist/mappings.js +79 -10
- package/dist/version.js +1 -1
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -84,25 +84,20 @@ courier config --apikey MY_API_KEY --draft
|
|
|
84
84
|
## Common Flags
|
|
85
85
|
|
|
86
86
|
There are a number flags you can use for any command
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
├────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
|
98
|
-
│--apikey <Courier API Key> │Use the provided Courier API key, otherwise use the approprate environment variable │
|
|
99
|
-
├────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
|
|
100
|
-
│--apiurl <Courier API URL> │Use the provided Courier API URL, otherwise use COURIER_API_URL environment variable. Default is https://api.courier.com │
|
|
101
|
-
└────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
|
87
|
+
|
|
88
|
+
| Flags | Description |
|
|
89
|
+
| ---------------------------- | ---------------------------- |
|
|
90
|
+
| -M --mock | Use the API key that simulates sending using the simulating routing |
|
|
91
|
+
| -P --production | Use the production environment API key |
|
|
92
|
+
| -D --draft | Use the draft document scope API key. Use draft or submitted, will default to published key if neither are provided |
|
|
93
|
+
| -S --submitted | Use the submitted document scope API key |
|
|
94
|
+
| --apikey <Courier API Key> | Use the provided Courier API key, otherwise use the approprate environment variable |
|
|
95
|
+
| --apiurl <Courier API URL> | Use the provided Courier API URL, otherwise use COURIER_API_URL environment variable. Default is https://api.courier.com |
|
|
96
|
+
|
|
102
97
|
|
|
103
98
|
## Misc
|
|
104
99
|
|
|
105
|
-
- If you need to change the Courier API URL, you can set COURIER_API_URL in .courier or
|
|
100
|
+
- If you need to change the Courier API URL, you can set COURIER_API_URL in .courier or other methods to set the environment variables.
|
|
106
101
|
|
|
107
102
|
## License
|
|
108
103
|
|
|
@@ -111,6 +106,3 @@ There are a number flags you can use for any command
|
|
|
111
106
|
## Author
|
|
112
107
|
|
|
113
108
|
[Courier](https://github.com/trycourier) ([support@courier.com](mailto:support@courier.com))
|
|
114
|
-
|
|
115
|
-
TODO - COURIER_DOMAIN
|
|
116
|
-
TODO - Common Flags
|
package/dist/bulk.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import duckdb from 'duckdb';
|
|
2
|
+
export declare const installExtension: (db: duckdb.Database, type?: TFileType) => void;
|
|
3
|
+
export declare const getFrom: (filename: string, type: TFileType) => string;
|
|
4
|
+
export declare const getFileType: (filename: string) => TFileType | undefined;
|
|
5
|
+
export declare const getSql: (filename: string, type: TFileType) => string;
|
|
6
|
+
declare const getDb: (filename: string) => {
|
|
7
|
+
db: duckdb.Database;
|
|
8
|
+
filetype: TFileType | undefined;
|
|
9
|
+
sql: string;
|
|
10
|
+
};
|
|
11
|
+
export default getDb;
|
package/dist/bulk.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import duckdb from 'duckdb';
|
|
2
|
+
export const installExtension = (db, type) => {
|
|
3
|
+
if (['json', 'parquet'].includes(type || '')) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
INSTALL ${type};
|
|
6
|
+
LOAD ${type};`);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export const getFrom = (filename, type) => {
|
|
10
|
+
switch (type) {
|
|
11
|
+
case 'csv':
|
|
12
|
+
return `read_csv(['${filename}'], union_by_name = true)`;
|
|
13
|
+
case 'json':
|
|
14
|
+
return `read_json_auto(['${filename}'])`;
|
|
15
|
+
case 'parquet':
|
|
16
|
+
return `read_parquet(['${filename}'])`;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const getFileType = (filename) => {
|
|
20
|
+
if (filename.endsWith('.csv')) {
|
|
21
|
+
return 'csv';
|
|
22
|
+
}
|
|
23
|
+
else if (filename.endsWith('.json') || filename.endsWith('.jsonl')) {
|
|
24
|
+
return 'json';
|
|
25
|
+
}
|
|
26
|
+
else if (filename.endsWith('.parquet') ||
|
|
27
|
+
filename.endsWith('.pq') ||
|
|
28
|
+
filename.endsWith('.parq')) {
|
|
29
|
+
return 'parquet';
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export const getSql = (filename, type) => `SELECT * FROM ${getFrom(filename, type)} ;`;
|
|
36
|
+
const getDb = (filename) => {
|
|
37
|
+
const filetype = getFileType(filename);
|
|
38
|
+
const db = new duckdb.Database(':memory:'); // or a file name for a persistent DB
|
|
39
|
+
installExtension(db, filetype);
|
|
40
|
+
return {
|
|
41
|
+
db,
|
|
42
|
+
filetype,
|
|
43
|
+
sql: getSql(filename, filetype || 'csv'),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export default getDb;
|
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ import { CliContextProvider } from './components/Context.js';
|
|
|
7
7
|
import { execa } from 'execa';
|
|
8
8
|
import _ from 'lodash';
|
|
9
9
|
import VERSION from './version.js';
|
|
10
|
+
import constants from './constants.js';
|
|
10
11
|
2;
|
|
11
12
|
const CLI = async () => {
|
|
12
13
|
process.removeAllListeners('warning');
|
|
@@ -16,9 +17,9 @@ const CLI = async () => {
|
|
|
16
17
|
const Router = (await import('./components/Router.js')).default;
|
|
17
18
|
let current;
|
|
18
19
|
let latest;
|
|
19
|
-
if (VERSION !== 'local'
|
|
20
|
+
if (VERSION !== 'local') {
|
|
20
21
|
try {
|
|
21
|
-
const exc = await execa('npm', ['-g', 'outdated',
|
|
22
|
+
const exc = await execa('npm', ['-g', 'outdated', constants.package_name, '--json'], {
|
|
22
23
|
shell: true,
|
|
23
24
|
reject: false,
|
|
24
25
|
});
|
|
@@ -29,7 +30,6 @@ const CLI = async () => {
|
|
|
29
30
|
catch (e) {
|
|
30
31
|
console.log(e);
|
|
31
32
|
}
|
|
32
|
-
console.log({ current, latest });
|
|
33
33
|
}
|
|
34
34
|
const version_text = `Upgrade available (${current} > ${latest}), run courier upgrade`;
|
|
35
35
|
render(React.createElement(CliContextProvider, { args: params, mappings, current, latest },
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Inbox } from '@trycourier/client-graphql';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
|
+
import { useBoolean, useCounter } from 'usehooks-ts';
|
|
5
|
+
import { useCliContext } from '../../components/Context.js';
|
|
6
|
+
import Spinner from '../../components/Spinner.js';
|
|
7
|
+
import UhOh from '../../components/UhOh.js';
|
|
8
|
+
import uuid from '../../lib/uuid.js';
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
import ms from 'ms';
|
|
11
|
+
import _ from 'lodash';
|
|
12
|
+
const LIMIT = 10;
|
|
13
|
+
const ArchiveAll = ({ user_id_override }) => {
|
|
14
|
+
const [error, setError] = useState();
|
|
15
|
+
const [InboxClient, setInboxClient] = useState();
|
|
16
|
+
const [jwt, setJwt] = useState('');
|
|
17
|
+
const total_messages = useCounter(0);
|
|
18
|
+
const running = useBoolean(true);
|
|
19
|
+
const gathering_messages = useBoolean(true);
|
|
20
|
+
const pages = useCounter(0);
|
|
21
|
+
const { getJWT, parsedParams } = useCliContext();
|
|
22
|
+
const archived_messages = useCounter(0);
|
|
23
|
+
const [messages, setMessages] = useState([]);
|
|
24
|
+
const { tenant, tag, before, batchSize, includePinned, _: [userId, ...args], } = parsedParams;
|
|
25
|
+
const user_id = user_id_override || userId;
|
|
26
|
+
const tenant_id = tenant ? String(tenant) : undefined;
|
|
27
|
+
const until = before
|
|
28
|
+
? new Date(new Date().getTime() - Math.abs(ms(before)))
|
|
29
|
+
: undefined;
|
|
30
|
+
const limit = Number(batchSize) || LIMIT;
|
|
31
|
+
const handleError = (text) => {
|
|
32
|
+
setError(text + '\n' + JSON.stringify({ tenant, tag, user_id, args }));
|
|
33
|
+
};
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
getInboxClient();
|
|
36
|
+
}, [user_id]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (jwt?.length && InboxClient) {
|
|
39
|
+
getAllMessages();
|
|
40
|
+
}
|
|
41
|
+
}, [jwt, InboxClient]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!gathering_messages.value) {
|
|
44
|
+
handleMessageArchive();
|
|
45
|
+
}
|
|
46
|
+
}, [gathering_messages.value]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (error?.length) {
|
|
49
|
+
running.setFalse();
|
|
50
|
+
}
|
|
51
|
+
}, [error]);
|
|
52
|
+
const getInboxClient = async () => {
|
|
53
|
+
try {
|
|
54
|
+
if (user_id) {
|
|
55
|
+
const jwt = await getJWT(user_id, [
|
|
56
|
+
'inbox:read:messages',
|
|
57
|
+
'inbox:write:events',
|
|
58
|
+
]);
|
|
59
|
+
if (jwt.token) {
|
|
60
|
+
setJwt(jwt.token);
|
|
61
|
+
setInboxClient(Inbox({
|
|
62
|
+
authorization: jwt.token,
|
|
63
|
+
userId: user_id,
|
|
64
|
+
clientSourceId: uuid(),
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
handleError('No JWT token returned.');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
handleError('No user ID provided.');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
handleError(e instanceof Error ? e.message : String(e) || 'An error occurred.');
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const handleMessageArchive = async () => {
|
|
80
|
+
if (messages.length) {
|
|
81
|
+
for (var i = 0; i < messages.length; i++) {
|
|
82
|
+
try {
|
|
83
|
+
const message = messages[i];
|
|
84
|
+
if (message?.messageId) {
|
|
85
|
+
await InboxClient?.markArchive(message.messageId);
|
|
86
|
+
}
|
|
87
|
+
archived_messages.increment();
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
handleError(`Failed to archive message ${messages[i]?.messageId || 'unknown'}: ${e instanceof Error ? e.message : String(e) || 'An error occurred.'}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
running.setFalse();
|
|
95
|
+
};
|
|
96
|
+
const getAllMessages = async () => {
|
|
97
|
+
let cursor;
|
|
98
|
+
let counter = -1;
|
|
99
|
+
if (jwt?.length && InboxClient) {
|
|
100
|
+
let params = {
|
|
101
|
+
archived: false,
|
|
102
|
+
limit,
|
|
103
|
+
};
|
|
104
|
+
if (tag) {
|
|
105
|
+
params.tags = Array.isArray(tag) ? tag : [tag];
|
|
106
|
+
}
|
|
107
|
+
if (tenant_id) {
|
|
108
|
+
params.tenantId = tenant_id;
|
|
109
|
+
}
|
|
110
|
+
while (counter < 0) {
|
|
111
|
+
counter++;
|
|
112
|
+
pages.increment();
|
|
113
|
+
let filtered_messages = [];
|
|
114
|
+
const r = await InboxClient.getMessages(params, cursor);
|
|
115
|
+
_.get(r, 'messages', []).forEach(m => {
|
|
116
|
+
if (until) {
|
|
117
|
+
if (new Date(m.created) < until) {
|
|
118
|
+
filtered_messages.push(m);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
filtered_messages.push(m);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
// handle pins on first iteration, ignore after
|
|
126
|
+
if (counter === 0 && Boolean(includePinned)) {
|
|
127
|
+
_.get(r, 'pinned', []).forEach(m => {
|
|
128
|
+
if (until) {
|
|
129
|
+
if (new Date(m.created) < until) {
|
|
130
|
+
filtered_messages.push(m);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
filtered_messages.push(m);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (filtered_messages.length) {
|
|
139
|
+
total_messages.setCount(c => c + filtered_messages.length);
|
|
140
|
+
setMessages(p => [...p, ...filtered_messages]);
|
|
141
|
+
}
|
|
142
|
+
if (!r?.startCursor) {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
cursor = r.startCursor;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
handleError('No JWT generated, but GQL client called.');
|
|
152
|
+
}
|
|
153
|
+
gathering_messages.setFalse();
|
|
154
|
+
};
|
|
155
|
+
if (error?.length) {
|
|
156
|
+
return React.createElement(UhOh, { text: error });
|
|
157
|
+
}
|
|
158
|
+
else if (gathering_messages.value) {
|
|
159
|
+
return (React.createElement(Spinner, { text: `Finding messages: Found ${messages.length} in ${pages.count} pages ` }));
|
|
160
|
+
}
|
|
161
|
+
else if (running.value) {
|
|
162
|
+
return (React.createElement(Spinner, { text: `Archiving ${archived_messages.count} / ${messages.length} for ${user_id}` }));
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
return (React.createElement(Box, null,
|
|
166
|
+
React.createElement(Text, null,
|
|
167
|
+
"Marked ",
|
|
168
|
+
archived_messages.count,
|
|
169
|
+
" messages as archived for ",
|
|
170
|
+
user_id)));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
export default ArchiveAll;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Inbox } from '@trycourier/client-graphql';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
|
+
import { useBoolean } from 'usehooks-ts';
|
|
5
|
+
import { useCliContext } from '../../components/Context.js';
|
|
6
|
+
import Spinner from '../../components/Spinner.js';
|
|
7
|
+
import UhOh from '../../components/UhOh.js';
|
|
8
|
+
import uuid from '../../lib/uuid.js';
|
|
9
|
+
const MarkAllRead = ({}) => {
|
|
10
|
+
const [error, setError] = useState();
|
|
11
|
+
const [jwt, setJwt] = useState('');
|
|
12
|
+
const [unread, setUnread] = useState();
|
|
13
|
+
const running = useBoolean(true);
|
|
14
|
+
const { getJWT, parsedParams } = useCliContext();
|
|
15
|
+
const [response, setResponse] = useState();
|
|
16
|
+
const { tenant, tag, _: [user_id, ...args], } = parsedParams;
|
|
17
|
+
const handleError = (text) => {
|
|
18
|
+
setError(text + '\n' + JSON.stringify({ tenant, tag, user_id, args }));
|
|
19
|
+
};
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
runJwt();
|
|
22
|
+
}, [user_id]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (jwt?.length) {
|
|
25
|
+
runMarkRead();
|
|
26
|
+
}
|
|
27
|
+
}, [jwt]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (error?.length) {
|
|
30
|
+
running.setFalse();
|
|
31
|
+
}
|
|
32
|
+
else if (response) {
|
|
33
|
+
running.setFalse();
|
|
34
|
+
}
|
|
35
|
+
}, [error, response]);
|
|
36
|
+
const runJwt = async () => {
|
|
37
|
+
try {
|
|
38
|
+
if (user_id) {
|
|
39
|
+
const jwt = await getJWT(user_id, [
|
|
40
|
+
'inbox:read:messages',
|
|
41
|
+
'inbox:write:events',
|
|
42
|
+
]);
|
|
43
|
+
if (jwt.token) {
|
|
44
|
+
setJwt(jwt.token);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
handleError('No JWT token returned.');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
handleError('No user ID provided.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
handleError(e instanceof Error ? e.message : String(e) || 'An error occurred.');
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const runMarkRead = async () => {
|
|
59
|
+
if (jwt) {
|
|
60
|
+
const gql_client = Inbox({
|
|
61
|
+
authorization: jwt,
|
|
62
|
+
userId: user_id,
|
|
63
|
+
clientSourceId: uuid(),
|
|
64
|
+
});
|
|
65
|
+
try {
|
|
66
|
+
const res = await gql_client.getInboxCount({
|
|
67
|
+
status: 'unread',
|
|
68
|
+
});
|
|
69
|
+
if (res) {
|
|
70
|
+
if (typeof res.count === 'number') {
|
|
71
|
+
setUnread(res?.count || 0);
|
|
72
|
+
const res2 = await gql_client.markAllRead();
|
|
73
|
+
if (res2) {
|
|
74
|
+
setResponse(res2);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
handleError('No response from markAllRead');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
handleError('No count returned from getInboxCount');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
handleError('No response from getInboxCount');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
handleError(e instanceof Error ? e.message : String(e) || 'An error occurred.');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
handleError('No JWT generated, but GQL client called.');
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
if (error?.length) {
|
|
97
|
+
return React.createElement(UhOh, { text: error });
|
|
98
|
+
}
|
|
99
|
+
else if (running.value) {
|
|
100
|
+
return React.createElement(Spinner, { text: "Marking all read" });
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return (React.createElement(Box, null,
|
|
104
|
+
React.createElement(Text, null,
|
|
105
|
+
"Marked ",
|
|
106
|
+
unread,
|
|
107
|
+
" messages as read")));
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
export default MarkAllRead;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { ProgressBar } from '@inkjs/ui';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import { useBoolean, useCounter } from 'usehooks-ts';
|
|
6
|
+
import getDb from '../bulk.js';
|
|
7
|
+
import { useCliContext } from '../components/Context.js';
|
|
8
|
+
import Spinner from '../components/Spinner.js';
|
|
9
|
+
import UhOh from '../components/UhOh.js';
|
|
10
|
+
import delay from '../lib/delay.js';
|
|
11
|
+
const tenantToModifed = (t) => {
|
|
12
|
+
const modified = {
|
|
13
|
+
...t,
|
|
14
|
+
default_preferences: _.get(t, ['default_preferences', 'items'], []).reduce((p, { id, ...r }) => {
|
|
15
|
+
_.set(p, [id], r);
|
|
16
|
+
return p;
|
|
17
|
+
}, {}),
|
|
18
|
+
};
|
|
19
|
+
return modified;
|
|
20
|
+
};
|
|
21
|
+
const modifiedToTenant = (t) => {
|
|
22
|
+
const tenant = {
|
|
23
|
+
...t,
|
|
24
|
+
default_preferences: {
|
|
25
|
+
items: Object.entries(t.default_preferences).map(([id, r]) => {
|
|
26
|
+
return { id, ...r };
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
return tenant;
|
|
31
|
+
};
|
|
32
|
+
export default () => {
|
|
33
|
+
const { parsedParams, courier } = useCliContext();
|
|
34
|
+
const [error, setError] = useState();
|
|
35
|
+
const processing = useBoolean(false);
|
|
36
|
+
const [data, setData] = useState();
|
|
37
|
+
const [data_errors, setDataErrors] = useState([]);
|
|
38
|
+
const counter = useCounter(0);
|
|
39
|
+
const filename = String(_.get(parsedParams, ['_', 0], ''));
|
|
40
|
+
const { db, filetype, sql } = getDb(filename);
|
|
41
|
+
const merge = Boolean(parsedParams['merge']);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (filetype) {
|
|
44
|
+
getData();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
setError('File type not supported.');
|
|
48
|
+
}
|
|
49
|
+
}, []);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (data) {
|
|
52
|
+
processData();
|
|
53
|
+
}
|
|
54
|
+
}, [data]);
|
|
55
|
+
const getData = () => {
|
|
56
|
+
processing.setTrue();
|
|
57
|
+
db.all(sql, (err, result) => {
|
|
58
|
+
if (err) {
|
|
59
|
+
setError(err.message);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
setData(result);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const processData = async () => {
|
|
67
|
+
if (data?.length) {
|
|
68
|
+
for (let i = 0; i < data.length; i++) {
|
|
69
|
+
let { tenant_id, parent_tenant_id, name, brand_id, user_profile = {}, default_preferences = {}, properties = {}, ...rest } = data[i] || {};
|
|
70
|
+
tenant_id = tenant_id ? String(tenant_id) : undefined;
|
|
71
|
+
parent_tenant_id = parent_tenant_id
|
|
72
|
+
? String(parent_tenant_id)
|
|
73
|
+
: undefined;
|
|
74
|
+
brand_id = brand_id ? String(brand_id) : undefined;
|
|
75
|
+
name = name ? String(name) : tenant_id;
|
|
76
|
+
if (!tenant_id) {
|
|
77
|
+
setDataErrors(p => [...p, `tenant_id not found in index ${i}`]);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
try {
|
|
81
|
+
// handle rest, all should go into properties unlness they are user_profile or default_preferences
|
|
82
|
+
Object.entries(rest).forEach(([key, value]) => {
|
|
83
|
+
if (key.startsWith('user_profile.')) {
|
|
84
|
+
_.set(user_profile, key.slice('user_profile.'.length - 1), value);
|
|
85
|
+
}
|
|
86
|
+
else if (key.startsWith('default_preferences.')) {
|
|
87
|
+
_.set(default_preferences, key.slice('default_preferences.'.length - 1), value);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
_.set(properties, key, value);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
let curr;
|
|
94
|
+
let next = {
|
|
95
|
+
parent_tenant_id,
|
|
96
|
+
name,
|
|
97
|
+
brand_id,
|
|
98
|
+
user_profile,
|
|
99
|
+
default_preferences,
|
|
100
|
+
properties,
|
|
101
|
+
};
|
|
102
|
+
if (merge) {
|
|
103
|
+
try {
|
|
104
|
+
curr = await courier.tenants.get(tenant_id);
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
curr = undefined;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
if (curr) {
|
|
111
|
+
const modified = tenantToModifed(curr);
|
|
112
|
+
next = {
|
|
113
|
+
...curr,
|
|
114
|
+
...next,
|
|
115
|
+
user_profile: {
|
|
116
|
+
...next.user_profile,
|
|
117
|
+
...curr.user_profile,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
next = {
|
|
121
|
+
...next,
|
|
122
|
+
default_preferences: {
|
|
123
|
+
...modified?.default_preferences,
|
|
124
|
+
...next.default_preferences,
|
|
125
|
+
},
|
|
126
|
+
user_profile: {
|
|
127
|
+
...modified?.user_profile,
|
|
128
|
+
...next.user_profile,
|
|
129
|
+
},
|
|
130
|
+
properties: {
|
|
131
|
+
...modified?.properties,
|
|
132
|
+
...next.properties,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const add = modifiedToTenant(next);
|
|
139
|
+
console.log(JSON.stringify(add, null, 2));
|
|
140
|
+
await delay(20000);
|
|
141
|
+
await courier.tenants.createOrReplace(tenant_id, modifiedToTenant(next));
|
|
142
|
+
counter.increment();
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
setDataErrors(p => [
|
|
146
|
+
...p,
|
|
147
|
+
`tenant_id (${tenant_id}) failed to update in index ${i}: ${String(err)}`,
|
|
148
|
+
]);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
processing.setFalse();
|
|
154
|
+
};
|
|
155
|
+
if (!filename?.length) {
|
|
156
|
+
return React.createElement(UhOh, { text: "You must specify a filename." });
|
|
157
|
+
}
|
|
158
|
+
else if (error?.length) {
|
|
159
|
+
return React.createElement(UhOh, { text: error });
|
|
160
|
+
}
|
|
161
|
+
else if (data && processing.value) {
|
|
162
|
+
return (React.createElement(React.Fragment, null,
|
|
163
|
+
React.createElement(ProgressBar, { value: Math.floor(((counter.count + 1) / data.length) * 100) }),
|
|
164
|
+
React.createElement(Spinner, { text: `Completed Rows: ${counter.count} / ${data.length}` })));
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return (React.createElement(Box, { flexDirection: "column", marginY: 1 },
|
|
168
|
+
React.createElement(Text, { color: 'green' }, `Completed Rows: ${counter.count} / ${data?.length || 0}`),
|
|
169
|
+
data_errors.map((err, i) => {
|
|
170
|
+
return React.createElement(UhOh, { key: i, text: err });
|
|
171
|
+
})));
|
|
172
|
+
}
|
|
173
|
+
};
|
package/dist/commands/Track.js
CHANGED
|
@@ -4,6 +4,7 @@ import Request from '../components/Request.js';
|
|
|
4
4
|
import Response from '../components/Response.js';
|
|
5
5
|
import api from '../lib/api.js';
|
|
6
6
|
import { useCliContext } from '../components/Context.js';
|
|
7
|
+
import uuid from '../lib/uuid.js';
|
|
7
8
|
export default ({ params }) => {
|
|
8
9
|
const { apikey, url } = useCliContext();
|
|
9
10
|
const [resp, setResp] = useState();
|
|
@@ -19,7 +20,7 @@ export default ({ params }) => {
|
|
|
19
20
|
const payload = {
|
|
20
21
|
type: 'track',
|
|
21
22
|
event: eventId,
|
|
22
|
-
messageId:
|
|
23
|
+
messageId: uuid(),
|
|
23
24
|
properties: {
|
|
24
25
|
userId,
|
|
25
26
|
...properties,
|
|
@@ -1,46 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ProgressBar } from '@inkjs/ui';
|
|
2
2
|
import { Box, Text } from 'ink';
|
|
3
|
+
import _ from 'lodash';
|
|
3
4
|
import React, { useEffect, useState } from 'react';
|
|
4
5
|
import { useBoolean, useCounter } from 'usehooks-ts';
|
|
6
|
+
import getDb from '../bulk.js';
|
|
5
7
|
import { useCliContext } from '../components/Context.js';
|
|
6
8
|
import Spinner from '../components/Spinner.js';
|
|
7
9
|
import UhOh from '../components/UhOh.js';
|
|
8
|
-
import _ from 'lodash';
|
|
9
10
|
import delay from '../lib/delay.js';
|
|
10
|
-
import { ProgressBar } from '@inkjs/ui';
|
|
11
|
-
const installExtension = (db, type) => {
|
|
12
|
-
if (['json', 'parquet'].includes(type || '')) {
|
|
13
|
-
db.exec(`
|
|
14
|
-
INSTALL ${type};
|
|
15
|
-
LOAD ${type};`);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const getFrom = (filename, type) => {
|
|
19
|
-
switch (type) {
|
|
20
|
-
case 'csv':
|
|
21
|
-
return `read_csv(['${filename}'], union_by_name = true)`;
|
|
22
|
-
case 'json':
|
|
23
|
-
return `read_json_auto(['${filename}'])`;
|
|
24
|
-
case 'parquet':
|
|
25
|
-
return `read_parquet(['${filename}'])`;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const getFileType = (filename) => {
|
|
29
|
-
if (filename.endsWith('.csv')) {
|
|
30
|
-
return 'csv';
|
|
31
|
-
}
|
|
32
|
-
else if (filename.endsWith('.json') || filename.endsWith('.jsonl')) {
|
|
33
|
-
return 'json';
|
|
34
|
-
}
|
|
35
|
-
else if (filename.endsWith('.parquet') ||
|
|
36
|
-
filename.endsWith('.pq') ||
|
|
37
|
-
filename.endsWith('.parq')) {
|
|
38
|
-
return 'parquet';
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
11
|
export default () => {
|
|
45
12
|
const { parsedParams, courier } = useCliContext();
|
|
46
13
|
const [error, setError] = useState();
|
|
@@ -48,11 +15,8 @@ export default () => {
|
|
|
48
15
|
const [data, setData] = useState();
|
|
49
16
|
const [data_errors, setDataErrors] = useState([]);
|
|
50
17
|
const counter = useCounter(0);
|
|
51
|
-
// const [resp, setResp] = useState<IResponse | undefined>();
|
|
52
18
|
const filename = String(_.get(parsedParams, ['_', 0], ''));
|
|
53
|
-
const filetype =
|
|
54
|
-
const db = new duckdb.Database(':memory:'); // or a file name for a persistent DB
|
|
55
|
-
installExtension(db, filetype);
|
|
19
|
+
const { db, filetype, sql } = getDb(filename);
|
|
56
20
|
const keep_flat = Boolean(parsedParams['keep-flat']);
|
|
57
21
|
const remove_nulls = Boolean(parsedParams['remove-nulls']);
|
|
58
22
|
const replace = Boolean(parsedParams['replace']);
|
|
@@ -66,7 +30,7 @@ export default () => {
|
|
|
66
30
|
.filter(t => t.length > 0);
|
|
67
31
|
useEffect(() => {
|
|
68
32
|
if (filetype) {
|
|
69
|
-
getData(
|
|
33
|
+
getData();
|
|
70
34
|
}
|
|
71
35
|
else {
|
|
72
36
|
setError('File type not supported.');
|
|
@@ -77,9 +41,8 @@ export default () => {
|
|
|
77
41
|
processData();
|
|
78
42
|
}
|
|
79
43
|
}, [data]);
|
|
80
|
-
const getData = (
|
|
44
|
+
const getData = () => {
|
|
81
45
|
processing.setTrue();
|
|
82
|
-
const sql = `SELECT * FROM ${getFrom(filename, type)} ;`;
|
|
83
46
|
db.all(sql, (err, result) => {
|
|
84
47
|
if (err) {
|
|
85
48
|
setError(err.message);
|
|
@@ -5,13 +5,29 @@ import { useCliContext } from '../components/Context.js';
|
|
|
5
5
|
import SdkResponse from '../components/SdkResponse.js';
|
|
6
6
|
import UhOh from '../components/UhOh.js';
|
|
7
7
|
import Spinner from '../components/Spinner.js';
|
|
8
|
+
import KVP from '../components/KVP.js';
|
|
9
|
+
import api from '../lib/api.js';
|
|
10
|
+
import constants from '../constants.js';
|
|
11
|
+
import Link from 'ink-link';
|
|
12
|
+
import InkSpinner from 'ink-spinner';
|
|
8
13
|
export default () => {
|
|
9
|
-
const { courier, parsedParams } = useCliContext();
|
|
14
|
+
const { courier, parsedParams, url: baseUrl, apikey } = useCliContext();
|
|
10
15
|
const params = parsedParams;
|
|
11
16
|
const [resp, setResp] = useState();
|
|
17
|
+
const [urlResp, setUrlResp] = useState();
|
|
12
18
|
const [err, setErr] = useState();
|
|
13
19
|
const userId = lodash.get(params, ['_', 0]);
|
|
14
20
|
const verbose = lodash.get(params, ['verbose'], false);
|
|
21
|
+
const url = lodash.get(params, ['url'], false);
|
|
22
|
+
const brand = lodash.get(params, ['brand']);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (url) {
|
|
25
|
+
api({
|
|
26
|
+
url: '/debug',
|
|
27
|
+
method: 'POST',
|
|
28
|
+
}, baseUrl, apikey).then(res => setUrlResp(res));
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
15
31
|
useEffect(() => {
|
|
16
32
|
getPreferences();
|
|
17
33
|
}, []);
|
|
@@ -29,13 +45,29 @@ export default () => {
|
|
|
29
45
|
}
|
|
30
46
|
else {
|
|
31
47
|
const short_preferences = lodash.map(lodash.get(resp, ['items']), item => {
|
|
32
|
-
return
|
|
48
|
+
return (React.createElement(KVP, { key: item.topic_id, label: item.topic_name, value: item.status }));
|
|
33
49
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
React.createElement(
|
|
50
|
+
const whoami = lodash.get(urlResp, ['json'], {});
|
|
51
|
+
const preference_url = urlResp
|
|
52
|
+
? getUrl({ ...whoami, userId, brand })
|
|
53
|
+
: undefined;
|
|
54
|
+
return (React.createElement(Box, { marginY: 1, flexDirection: "column" },
|
|
55
|
+
!(resp || err) ? (React.createElement(Spinner, { text: `Fetching user preferences for ${userId}...` })) : (React.createElement(React.Fragment, null,
|
|
56
|
+
React.createElement(Text, { color: "green" },
|
|
57
|
+
"User preferences for ",
|
|
58
|
+
userId,
|
|
59
|
+
":"),
|
|
60
|
+
React.createElement(SdkResponse, { response: verbose ? resp : undefined, error: err, content: !(err || verbose) ? short_preferences : undefined }))),
|
|
61
|
+
url && (React.createElement(Text, null,
|
|
62
|
+
!urlResp ? React.createElement(InkSpinner, { type: "dots" }) : React.createElement(Text, null, " "),
|
|
63
|
+
React.createElement(Text, null, " "),
|
|
64
|
+
React.createElement(Link, { url: preference_url || '' },
|
|
65
|
+
React.createElement(Text, { color: "cyan" }, "Open Preference Page"))))));
|
|
40
66
|
}
|
|
41
67
|
};
|
|
68
|
+
const getUrl = ({ userId, tenantId, scope, environment, brand, }) => {
|
|
69
|
+
const is_draft = (scope || '').includes('draft');
|
|
70
|
+
const tenant = environment === 'test' ? tenantId + '/test' : tenantId;
|
|
71
|
+
const encoded = btoa([tenant, brand, userId, is_draft].join('#'));
|
|
72
|
+
return `${constants.hosted_preference_page}/${encoded}`;
|
|
73
|
+
};
|
package/dist/commands/WhoAmI.js
CHANGED
|
@@ -5,6 +5,7 @@ import Request from '../components/Request.js';
|
|
|
5
5
|
import Response from '../components/Response.js';
|
|
6
6
|
import api from '../lib/api.js';
|
|
7
7
|
import { useCliContext } from '../components/Context.js';
|
|
8
|
+
// import constants from '../constants.js';
|
|
8
9
|
export default () => {
|
|
9
10
|
const { apikey, url } = useCliContext();
|
|
10
11
|
const [resp, setResp] = useState();
|
|
@@ -15,7 +16,7 @@ export default () => {
|
|
|
15
16
|
useEffect(() => {
|
|
16
17
|
api(request, url, apikey).then(res => setResp(res));
|
|
17
18
|
}, []);
|
|
18
|
-
return (React.createElement(Box, { flexDirection: "column" },
|
|
19
|
+
return (React.createElement(Box, { flexDirection: "column", width: "100%" },
|
|
19
20
|
React.createElement(Request, { request: request, response: resp }),
|
|
20
21
|
resp && resp.err ? (React.createElement(Response, { response: resp })) : resp && resp.json ? (React.createElement(React.Fragment, null,
|
|
21
22
|
React.createElement(KVP, { width: 20, label: "Workspace Name", value: resp.json.tenantName }),
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { CourierClient } from '@trycourier/courier';
|
|
2
|
+
import { IssueTokenResponse } from '@trycourier/courier/api/index.js';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import yargsParser from 'yargs-parser';
|
|
4
5
|
export type TEnvironment = 'test' | 'production';
|
|
5
6
|
export type TAPIRouting = 'normal' | 'simulated';
|
|
6
7
|
export type TDocumentScope = 'Published' | 'Draft' | 'Submitted';
|
|
8
|
+
type TGetJWT = (user_id: string, additional_scopes: TJWTScope[], other?: {
|
|
9
|
+
write_brands: string[];
|
|
10
|
+
expires_in?: string;
|
|
11
|
+
}) => Promise<IssueTokenResponse>;
|
|
7
12
|
interface ICliContextProvider {
|
|
8
13
|
args: string[];
|
|
9
14
|
mappings: Map<string, IMapping>;
|
|
@@ -26,6 +31,7 @@ interface ICliContext {
|
|
|
26
31
|
courier: CourierClient;
|
|
27
32
|
current?: string;
|
|
28
33
|
latest?: string;
|
|
34
|
+
getJWT: TGetJWT;
|
|
29
35
|
}
|
|
30
36
|
type IUseCliContext = () => ICliContext;
|
|
31
37
|
export declare const useCliContext: IUseCliContext;
|
|
@@ -26,6 +26,20 @@ export const CliContextProvider = ({ args, mappings, current, latest, children,
|
|
|
26
26
|
authorizationToken: apikey,
|
|
27
27
|
environment: url,
|
|
28
28
|
});
|
|
29
|
+
const getJWT = async (user_id, additional_scopes, options) => {
|
|
30
|
+
const { write_brands = [], expires_in = '5 min' } = options || {};
|
|
31
|
+
let scopes = [`user_id:${user_id}`, ...additional_scopes];
|
|
32
|
+
if (write_brands.length) {
|
|
33
|
+
write_brands.forEach(brand => {
|
|
34
|
+
scopes.push(`write:brands:${brand}`);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const token = await courier.authTokens.issueToken({
|
|
38
|
+
scope: scopes.join(' '),
|
|
39
|
+
expires_in,
|
|
40
|
+
});
|
|
41
|
+
return token;
|
|
42
|
+
};
|
|
29
43
|
const context = {
|
|
30
44
|
apikey,
|
|
31
45
|
mappings,
|
|
@@ -41,6 +55,7 @@ export const CliContextProvider = ({ args, mappings, current, latest, children,
|
|
|
41
55
|
map,
|
|
42
56
|
current,
|
|
43
57
|
latest,
|
|
58
|
+
getJWT,
|
|
44
59
|
};
|
|
45
60
|
return React.createElement(CliContext.Provider, { value: context }, children);
|
|
46
61
|
};
|
package/dist/components/KVP.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Box, Text } from 'ink';
|
|
2
|
+
import { Box, Spacer, Text } from 'ink';
|
|
3
3
|
export default ({ label, labelColor, labelBold, value, width, indent, }) => {
|
|
4
|
-
return (React.createElement(Box,
|
|
5
|
-
React.createElement(Box, { width: width },
|
|
4
|
+
return (React.createElement(Box, { flexDirection: "column" },
|
|
5
|
+
React.createElement(Box, { width: width, flexDirection: "row" },
|
|
6
6
|
React.createElement(Text, null, indent),
|
|
7
|
-
React.createElement(Text, { bold: labelBold === false ? false : true, color: labelColor }, label)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
React.createElement(Text, { bold: labelBold === false ? false : true, color: labelColor }, label),
|
|
8
|
+
React.createElement(Spacer, null),
|
|
9
|
+
React.createElement(Text, null,
|
|
10
|
+
" ",
|
|
11
|
+
value))));
|
|
11
12
|
};
|
|
@@ -2,7 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import { CourierError } from '@trycourier/courier';
|
|
3
3
|
type IProps<T> = {
|
|
4
4
|
error?: CourierError;
|
|
5
|
-
response?: T;
|
|
5
|
+
response?: T | string;
|
|
6
|
+
content?: React.ReactNode;
|
|
6
7
|
};
|
|
7
|
-
declare const SdkResponse: <T extends object>({ error, response }: IProps<T>) => React.JSX.Element;
|
|
8
|
+
declare const SdkResponse: <T extends object>({ error, response, content, }: IProps<T>) => React.JSX.Element;
|
|
8
9
|
export default SdkResponse;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Box, Text } from 'ink';
|
|
3
3
|
const Spacing = () => React.createElement(Text, null, " ");
|
|
4
|
-
const SdkResponse = ({ error, response }) => {
|
|
4
|
+
const SdkResponse = ({ error, response, content, }) => {
|
|
5
5
|
const status_code = error ? error.statusCode : '200';
|
|
6
|
+
const response_text = typeof response === 'string' ? response : JSON.stringify(response, null, 2);
|
|
6
7
|
return (React.createElement(Box, { flexDirection: "column" },
|
|
7
|
-
React.createElement(Box, { flexDirection: "column", borderStyle: "bold", borderColor: error ? 'red' : 'green' },
|
|
8
|
+
React.createElement(Box, { flexDirection: "column", borderStyle: "bold", borderColor: error ? 'red' : 'green' }, content ? (content) : (React.createElement(React.Fragment, null,
|
|
8
9
|
React.createElement(Text, null,
|
|
9
10
|
React.createElement(Spacing, null),
|
|
10
11
|
"HTTP",
|
|
@@ -14,7 +15,7 @@ const SdkResponse = ({ error, response }) => {
|
|
|
14
15
|
React.createElement(Text, { color: 'red' }, error.message),
|
|
15
16
|
React.createElement(Text, null, error.stack))),
|
|
16
17
|
response && Object.keys(response).length > 0 ? (React.createElement(React.Fragment, null,
|
|
17
|
-
React.createElement(Text, null,
|
|
18
|
-
React.createElement(Text, { color: "grey" }, "No response body"))))));
|
|
18
|
+
React.createElement(Text, null, response_text))) : (React.createElement(React.Fragment, null,
|
|
19
|
+
React.createElement(Text, { color: "grey" }, "No response body"))))))));
|
|
19
20
|
};
|
|
20
21
|
export default SdkResponse;
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
package/dist/lib/uuid.js
ADDED
package/dist/mappings.js
CHANGED
|
@@ -11,6 +11,9 @@ import TranslationsUpload from './commands/TranslationsUpload.js';
|
|
|
11
11
|
import UsersBulk from './commands/UsersBulk.js';
|
|
12
12
|
import UsersPreferences from './commands/UsersPreferences.js';
|
|
13
13
|
import Upgrade from './commands/Upgrade.js';
|
|
14
|
+
import TenantsBulk from './commands/TenantsBulk.js';
|
|
15
|
+
import MarkAllRead from './commands/Inbox/MarkAllRead.js';
|
|
16
|
+
import ArchiveAll from './commands/Inbox/ArchiveAll.js';
|
|
14
17
|
const mappings = new Map();
|
|
15
18
|
export const COMMON_OPTIONS = [
|
|
16
19
|
{
|
|
@@ -44,6 +47,10 @@ mappings.set('help', {
|
|
|
44
47
|
},
|
|
45
48
|
noApiKeyRequired: true,
|
|
46
49
|
});
|
|
50
|
+
mappings.set('upgrade', {
|
|
51
|
+
instructions: `Upgrade the Courier CLI to the latest versionw`,
|
|
52
|
+
component: () => React.createElement(Upgrade, null),
|
|
53
|
+
});
|
|
47
54
|
mappings.set('config', {
|
|
48
55
|
instructions: 'Persist your Courier API key into a .courier file in your current working directory',
|
|
49
56
|
component: () => {
|
|
@@ -234,6 +241,15 @@ mappings.set('users:preferences', {
|
|
|
234
241
|
option: '--verbose',
|
|
235
242
|
value: 'Show the full preference object',
|
|
236
243
|
},
|
|
244
|
+
{
|
|
245
|
+
option: '--url',
|
|
246
|
+
value: 'Generate the Courier Hosted Preference Page URL',
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
option: '--brand <brand ID>',
|
|
250
|
+
value: 'Only used with --url, optionally specify the brand_id. Generate the Courier Hosted Preference Page URL',
|
|
251
|
+
},
|
|
252
|
+
// TODO - add tenants when API is ready
|
|
237
253
|
],
|
|
238
254
|
component: () => {
|
|
239
255
|
return React.createElement(UsersPreferences, null);
|
|
@@ -280,15 +296,68 @@ mappings.set('translations:download', {
|
|
|
280
296
|
return React.createElement(TranslationsDownload, { params: params });
|
|
281
297
|
},
|
|
282
298
|
});
|
|
283
|
-
mappings.set('
|
|
284
|
-
|
|
285
|
-
|
|
299
|
+
mappings.set('tenants:bulk', {
|
|
300
|
+
params: '<filename>',
|
|
301
|
+
instructions: 'Bulk import tenants from a file (csv, json, jsonl, xls, xlsx, .parquet). Supports wildcard syntax for multiple files, must surround with quotes (see examples)',
|
|
302
|
+
component: () => React.createElement(TenantsBulk, null),
|
|
303
|
+
options: [
|
|
304
|
+
{
|
|
305
|
+
option: '--merge',
|
|
306
|
+
value: 'Create or merge existing tenants with the same ID. If the tenant exists, this will get the current values and merge the new values into the existing tenant',
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
});
|
|
310
|
+
mappings.set('inbox:mark-all-read', {
|
|
311
|
+
params: '<user_id>',
|
|
312
|
+
instructions: 'Mark all messages in the inbox as read for a given user',
|
|
313
|
+
example: [`courier inbox:mark-all-read user123`],
|
|
314
|
+
options: [
|
|
315
|
+
// TODO - coming soon when mark all read with tags/tenants is ready
|
|
316
|
+
// {
|
|
317
|
+
// option: '--tenant <tenant_id>',
|
|
318
|
+
// value: 'The tenant_id to mark all messages as read',
|
|
319
|
+
// },
|
|
320
|
+
// {
|
|
321
|
+
// option: '--tag <tag>',
|
|
322
|
+
// value: 'The tag to mark all messages as read. Can provide multiple',
|
|
323
|
+
// },
|
|
324
|
+
],
|
|
325
|
+
component: () => {
|
|
326
|
+
return React.createElement(MarkAllRead, null);
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
mappings.set('inbox:archive-all', {
|
|
330
|
+
params: '<user_id>',
|
|
331
|
+
instructions: 'Archive all messages in the inbox for a given user',
|
|
332
|
+
example: [
|
|
333
|
+
`courier inbox:archive-all user123 --before="7 day"`,
|
|
334
|
+
`courier inbox:archive-all user123 --tenant=workspace123`,
|
|
335
|
+
`courier inbox:archive-all user123 --tag product --tag marketing"`,
|
|
336
|
+
],
|
|
337
|
+
options: [
|
|
338
|
+
{
|
|
339
|
+
option: '--tenant <tenant_id>',
|
|
340
|
+
value: 'The tenant_id to mark all messages as read',
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
option: '--tag <tag>',
|
|
344
|
+
value: 'The tag to mark all messages as read. Can provide multiple tags',
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
option: '--before',
|
|
348
|
+
value: 'Archive all messages before a given duration using ms: https://www.npmjs.com/package/ms',
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
option: '--batch-size',
|
|
352
|
+
value: 'Control the batch size of the archive operation',
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
option: '--include-pinned',
|
|
356
|
+
value: 'Include pinned messages in the archive operation',
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
component: () => {
|
|
360
|
+
return React.createElement(ArchiveAll, null);
|
|
361
|
+
},
|
|
286
362
|
});
|
|
287
|
-
// console.log('REMOVE ME');
|
|
288
|
-
// var test: any = [];
|
|
289
|
-
// mappings.forEach(value => {
|
|
290
|
-
// test = test.concat(value.example);
|
|
291
|
-
// });
|
|
292
|
-
// console.log(test.filter(Boolean).join('\n'));
|
|
293
|
-
// console.log('REMOVE ME');
|
|
294
363
|
export default mappings;
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let VERSION = '2.0
|
|
1
|
+
let VERSION = '2.1.0';
|
|
2
2
|
export default VERSION;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycourier/cli",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"courier": "dist/cli.js"
|
|
@@ -13,25 +13,32 @@
|
|
|
13
13
|
"build": "tsc",
|
|
14
14
|
"dev": "tsc --watch",
|
|
15
15
|
"test": "prettier --check . && xo && ava",
|
|
16
|
-
"format": "prettier --write ."
|
|
16
|
+
"format": "prettier --write .",
|
|
17
|
+
"clean": "rm -rf dist && rm -rf node_modules && yarn install"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"dist"
|
|
20
21
|
],
|
|
21
22
|
"dependencies": {
|
|
22
23
|
"@inkjs/ui": "^2.0.0",
|
|
24
|
+
"@trycourier/client-graphql": "^6.0.0",
|
|
25
|
+
"@trycourier/core": "^6.0.0",
|
|
23
26
|
"@trycourier/courier": "^6.1.2",
|
|
24
27
|
"cli-spinners": "^3.0.0",
|
|
25
28
|
"dotenv": "^16.0.3",
|
|
26
29
|
"duckdb": "^0.10.2",
|
|
27
30
|
"execa": "^9.1.0",
|
|
28
31
|
"ink": "^5.0.1",
|
|
32
|
+
"ink-link": "^4.0.0",
|
|
33
|
+
"ink-spinner": "^5.0.0",
|
|
29
34
|
"lodash": "^4.17.21",
|
|
35
|
+
"ms": "3.0.0-canary.1",
|
|
30
36
|
"react": "^18.2.0",
|
|
31
37
|
"usehooks-ts": "^3.1.0",
|
|
32
38
|
"yargs-parser": "^21.1.1"
|
|
33
39
|
},
|
|
34
40
|
"devDependencies": {
|
|
41
|
+
"@babel/runtime": "^7.24.7",
|
|
35
42
|
"@sindresorhus/tsconfig": "^5.0.0",
|
|
36
43
|
"@types/lodash": "^4.17.4",
|
|
37
44
|
"@types/node": "^20.13.0",
|
|
@@ -74,5 +81,6 @@
|
|
|
74
81
|
"access": "public",
|
|
75
82
|
"registry": "https://registry.npmjs.org/"
|
|
76
83
|
},
|
|
77
|
-
"homepage": "https://github.com/trycourier/courier-cli#readme"
|
|
84
|
+
"homepage": "https://github.com/trycourier/courier-cli#readme",
|
|
85
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
78
86
|
}
|