@trycourier/cli 2.7.2 → 3.1.5
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 +21 -92
- package/bin/.gitkeep +0 -0
- package/install.js +115 -0
- package/package.json +22 -87
- package/LICENSE +0 -21
- package/dist/bulk.d.ts +0 -15
- package/dist/bulk.js +0 -53
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -24
- package/dist/commands/AudienceSearch.d.ts +0 -3
- package/dist/commands/AudienceSearch.js +0 -113
- package/dist/commands/AutomationInvokeBulk.d.ts +0 -3
- package/dist/commands/AutomationInvokeBulk.js +0 -139
- package/dist/commands/Config.d.ts +0 -4
- package/dist/commands/Config.js +0 -45
- package/dist/commands/DigestFlush.d.ts +0 -5
- package/dist/commands/DigestFlush.js +0 -28
- package/dist/commands/Help.d.ts +0 -16
- package/dist/commands/Help.js +0 -38
- package/dist/commands/Inbox/ArchiveAll.d.ts +0 -8
- package/dist/commands/Inbox/ArchiveAll.js +0 -180
- package/dist/commands/Inbox/ArchiveAllBulk.d.ts +0 -5
- package/dist/commands/Inbox/ArchiveAllBulk.js +0 -99
- package/dist/commands/Inbox/MarkAllRead.d.ts +0 -5
- package/dist/commands/Inbox/MarkAllRead.js +0 -110
- package/dist/commands/MessagesSearch.d.ts +0 -3
- package/dist/commands/MessagesSearch.js +0 -120
- package/dist/commands/NotYetImplemented.d.ts +0 -3
- package/dist/commands/NotYetImplemented.js +0 -5
- package/dist/commands/Send.d.ts +0 -5
- package/dist/commands/Send.js +0 -144
- package/dist/commands/Templates/List.d.ts +0 -3
- package/dist/commands/Templates/List.js +0 -114
- package/dist/commands/TenantsBulk.d.ts +0 -3
- package/dist/commands/TenantsBulk.js +0 -171
- package/dist/commands/TenantsGetMembership.d.ts +0 -3
- package/dist/commands/TenantsGetMembership.js +0 -127
- package/dist/commands/TenantsMembershipBulk.d.ts +0 -3
- package/dist/commands/TenantsMembershipBulk.js +0 -203
- package/dist/commands/Track.d.ts +0 -5
- package/dist/commands/Track.js +0 -40
- package/dist/commands/TrackBulk.d.ts +0 -3
- package/dist/commands/TrackBulk.js +0 -89
- package/dist/commands/TranslationsDownload.d.ts +0 -10
- package/dist/commands/TranslationsDownload.js +0 -30
- package/dist/commands/TranslationsUpload.d.ts +0 -9
- package/dist/commands/TranslationsUpload.js +0 -37
- package/dist/commands/Upgrade.d.ts +0 -3
- package/dist/commands/Upgrade.js +0 -38
- package/dist/commands/UserToken.d.ts +0 -3
- package/dist/commands/UserToken.js +0 -96
- package/dist/commands/UsersBulk.d.ts +0 -3
- package/dist/commands/UsersBulk.js +0 -205
- package/dist/commands/UsersGet.d.ts +0 -5
- package/dist/commands/UsersGet.js +0 -37
- package/dist/commands/UsersPreferences.d.ts +0 -3
- package/dist/commands/UsersPreferences.js +0 -73
- package/dist/commands/UsersSet.d.ts +0 -5
- package/dist/commands/UsersSet.js +0 -34
- package/dist/commands/UsersTokensBulk.d.ts +0 -3
- package/dist/commands/UsersTokensBulk.js +0 -215
- package/dist/commands/WhoAmI.d.ts +0 -3
- package/dist/commands/WhoAmI.js +0 -27
- package/dist/components/Context.d.ts +0 -55
- package/dist/components/Context.js +0 -94
- package/dist/components/Elemental.d.ts +0 -13
- package/dist/components/Elemental.js +0 -23
- package/dist/components/KVP.d.ts +0 -11
- package/dist/components/KVP.js +0 -12
- package/dist/components/Request.d.ts +0 -23
- package/dist/components/Request.js +0 -17
- package/dist/components/Response.d.ts +0 -16
- package/dist/components/Response.js +0 -29
- package/dist/components/Router.d.ts +0 -4
- package/dist/components/Router.js +0 -60
- package/dist/components/SdkResponse.d.ts +0 -9
- package/dist/components/SdkResponse.js +0 -21
- package/dist/components/Spinner.d.ts +0 -6
- package/dist/components/Spinner.js +0 -41
- package/dist/components/Table.d.ts +0 -19
- package/dist/components/Table.js +0 -62
- package/dist/components/UhOh.d.ts +0 -5
- package/dist/components/UhOh.js +0 -10
- package/dist/components/Version.d.ts +0 -3
- package/dist/components/Version.js +0 -53
- package/dist/constants.d.ts +0 -8
- package/dist/constants.js +0 -8
- package/dist/lib/api.d.ts +0 -17
- package/dist/lib/api.js +0 -39
- package/dist/lib/args.d.ts +0 -2
- package/dist/lib/args.js +0 -13
- package/dist/lib/courier.d.ts +0 -3
- package/dist/lib/courier.js +0 -7
- package/dist/lib/delay.d.ts +0 -2
- package/dist/lib/delay.js +0 -7
- package/dist/lib/load-env.d.ts +0 -2
- package/dist/lib/load-env.js +0 -16
- package/dist/lib/uuid.d.ts +0 -2
- package/dist/lib/uuid.js +0 -4
- package/dist/mappings.d.ts +0 -6
- package/dist/mappings.js +0 -565
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -2
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Box, Text } from 'ink';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import React, { useEffect, useRef, 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
|
-
const VALID_SCOPE_PREFIXES = [
|
|
9
|
-
'read:messages',
|
|
10
|
-
'read:user-tokens',
|
|
11
|
-
'write:user-tokens',
|
|
12
|
-
'read:brands',
|
|
13
|
-
'write:brands',
|
|
14
|
-
'inbox:read:messages',
|
|
15
|
-
'inbox:write:events',
|
|
16
|
-
'read:preferences',
|
|
17
|
-
'write:preferences',
|
|
18
|
-
];
|
|
19
|
-
const ALL = VALID_SCOPE_PREFIXES.filter(s => !s.endsWith('brand'));
|
|
20
|
-
const UserToken = () => {
|
|
21
|
-
const { parsedParams, getJWT } = useCliContext();
|
|
22
|
-
const running = useBoolean(true);
|
|
23
|
-
const [jwt, setJWT] = useState();
|
|
24
|
-
const [final_scopes, setFinalScopes] = useState([]);
|
|
25
|
-
const [error, setError] = useState();
|
|
26
|
-
let timeoutRef = useRef(null);
|
|
27
|
-
const { expires, scopes, all, quiet, _: [user_id], } = parsedParams;
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
getUserJWT();
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
timeoutRef.current = setTimeout(() => { }, 5000);
|
|
32
|
-
}, []);
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (jwt && timeoutRef.current) {
|
|
35
|
-
clearTimeout(timeoutRef.current);
|
|
36
|
-
}
|
|
37
|
-
return () => {
|
|
38
|
-
if (timeoutRef.current) {
|
|
39
|
-
clearTimeout(timeoutRef.current);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}, [jwt]);
|
|
43
|
-
const getUserJWT = async () => {
|
|
44
|
-
const exp = Number(expires);
|
|
45
|
-
const scope_input = scopes?.split(',') || [];
|
|
46
|
-
const sc = [...new Set([...scope_input, ...(all ? ALL : [])])];
|
|
47
|
-
const invalid_scopes = sc.filter(scope => !_.some(VALID_SCOPE_PREFIXES, val => scope.startsWith(val)));
|
|
48
|
-
setFinalScopes([`user_id:${user_id}`, ...sc]);
|
|
49
|
-
if (!user_id) {
|
|
50
|
-
setError('No User Specified');
|
|
51
|
-
}
|
|
52
|
-
else if (!(sc && sc.length)) {
|
|
53
|
-
setError('No scopes provided. They are required');
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
else if (invalid_scopes.length) {
|
|
57
|
-
setError(`Found invalid scopes (${invalid_scopes.join(', ')})`);
|
|
58
|
-
}
|
|
59
|
-
else if (exp && Number.isNaN(exp)) {
|
|
60
|
-
setError('Not a valid number');
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
try {
|
|
64
|
-
const r = await getJWT(user_id, sc, {
|
|
65
|
-
expires_in: `${exp || 5} mins`,
|
|
66
|
-
write_brands: [],
|
|
67
|
-
});
|
|
68
|
-
setJWT(r.token);
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
setError(String(e));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
running.setFalse();
|
|
75
|
-
};
|
|
76
|
-
if (quiet) {
|
|
77
|
-
return React.createElement(Text, null, jwt);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
if (error?.length) {
|
|
81
|
-
return React.createElement(UhOh, { text: error });
|
|
82
|
-
}
|
|
83
|
-
else if (running.value) {
|
|
84
|
-
return React.createElement(Spinner, { text: `Fetching JWT` });
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
return (React.createElement(React.Fragment, null,
|
|
88
|
-
React.createElement(Text, null, "Token has the following scopes:"),
|
|
89
|
-
React.createElement(Text, null, final_scopes.join(' ')),
|
|
90
|
-
React.createElement(Box, { flexDirection: "column", marginY: 1, borderColor: "gray", borderStyle: 'single', borderTop: false, borderLeft: false, borderRight: false }),
|
|
91
|
-
React.createElement(Text, null, jwt),
|
|
92
|
-
React.createElement(Box, { flexDirection: "column", marginY: 1, borderColor: "gray", borderStyle: 'single', borderBottom: false, borderLeft: false, borderRight: false })));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
export default UserToken;
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { ProgressBar } from '@inkjs/ui';
|
|
2
|
-
import { Box, Text } from 'ink';
|
|
3
|
-
import _ from 'lodash';
|
|
4
|
-
import fs from 'fs/promises';
|
|
5
|
-
import React, { useEffect, useState } from 'react';
|
|
6
|
-
import { useBoolean, useCounter } from 'usehooks-ts';
|
|
7
|
-
import getDb, { getChunk } from '../bulk.js';
|
|
8
|
-
import { useCliContext } from '../components/Context.js';
|
|
9
|
-
import Spinner from '../components/Spinner.js';
|
|
10
|
-
import UhOh from '../components/UhOh.js';
|
|
11
|
-
import delay from '../lib/delay.js';
|
|
12
|
-
const DEFAULT_DELAY = 5000;
|
|
13
|
-
const DEFAULT_CHUNK_SIZE = 500;
|
|
14
|
-
const DEFAULT_TIMEOUT = 10;
|
|
15
|
-
const DEFAULT_ERROR_FILENAME = 'errors.json';
|
|
16
|
-
export default () => {
|
|
17
|
-
const { parsedParams, courier } = useCliContext();
|
|
18
|
-
const [error, setError] = useState();
|
|
19
|
-
const processing = useBoolean(true);
|
|
20
|
-
const running = useBoolean(true);
|
|
21
|
-
const [data, setData] = useState();
|
|
22
|
-
const [data_errors, setDataErrors] = useState([]);
|
|
23
|
-
const counter = useCounter(0);
|
|
24
|
-
const [row_errors, setRowErrors] = useState([]);
|
|
25
|
-
const filename = String(_.get(parsedParams, ['_', 0], ''));
|
|
26
|
-
const { db, filetype, sql } = getDb(filename);
|
|
27
|
-
const delay_between_chunks = Number(parsedParams['delay']) ?? DEFAULT_DELAY;
|
|
28
|
-
const chunk_size = parsedParams['chunk_size']
|
|
29
|
-
? Number(parsedParams['chunk_size'])
|
|
30
|
-
: DEFAULT_CHUNK_SIZE;
|
|
31
|
-
const log_errors = Boolean(parsedParams['errors']);
|
|
32
|
-
const keep_flat = Boolean(parsedParams['keep-flat']);
|
|
33
|
-
const remove_nulls = Boolean(parsedParams['remove-nulls']);
|
|
34
|
-
const replace = Boolean(parsedParams['replace']);
|
|
35
|
-
const lists = String(_.get(parsedParams, ['list'], ''))
|
|
36
|
-
.split(',')
|
|
37
|
-
.map(l => l.trim())
|
|
38
|
-
.filter(l => l.length > 0);
|
|
39
|
-
const tenants = String(_.get(parsedParams, ['tenant'], ''))
|
|
40
|
-
.split(',')
|
|
41
|
-
.map(l => l.trim())
|
|
42
|
-
.filter(t => t.length > 0);
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (filetype) {
|
|
45
|
-
getData();
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
setError('File type not supported.');
|
|
49
|
-
}
|
|
50
|
-
}, []);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
if (data) {
|
|
53
|
-
processData();
|
|
54
|
-
}
|
|
55
|
-
}, [data]);
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
if (!processing.value) {
|
|
58
|
-
handleErrors();
|
|
59
|
-
}
|
|
60
|
-
}, [processing.value]);
|
|
61
|
-
const getData = () => {
|
|
62
|
-
db.all(sql, (err, result) => {
|
|
63
|
-
if (err) {
|
|
64
|
-
setError(err.message);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
setData(result);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
const processChunkRows = (data, start_index) => {
|
|
72
|
-
return data.map((row, i) => {
|
|
73
|
-
const curr_index = start_index + i;
|
|
74
|
-
let { user_id, tenant_id, ...profile } = row || {};
|
|
75
|
-
if (!user_id) {
|
|
76
|
-
return Promise.resolve({
|
|
77
|
-
success: false,
|
|
78
|
-
userId: '__unknown__',
|
|
79
|
-
error: `user_id not found in index ${curr_index}`,
|
|
80
|
-
index: curr_index,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
Object.entries(profile).forEach(([key, value]) => {
|
|
85
|
-
if (filetype === 'csv' && !keep_flat) {
|
|
86
|
-
_.unset(profile, key);
|
|
87
|
-
_.set(profile, key, value);
|
|
88
|
-
}
|
|
89
|
-
if (value === null && remove_nulls) {
|
|
90
|
-
_.unset(profile, key);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
return processRow(String(user_id), profile, curr_index, tenant_id?.length ? String(tenant_id) : undefined);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
const processRow = async (userId, profile, index, tenant_id) => {
|
|
98
|
-
return new Promise(async (resolve) => {
|
|
99
|
-
let promises = [];
|
|
100
|
-
try {
|
|
101
|
-
if (replace) {
|
|
102
|
-
promises.push(courier.profiles.replace(userId, { profile }, { maxRetries: 5, timeoutInSeconds: DEFAULT_TIMEOUT }));
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
promises.push(courier.profiles.create(userId, { profile }, { maxRetries: 5, timeoutInSeconds: DEFAULT_TIMEOUT }));
|
|
106
|
-
}
|
|
107
|
-
if (lists.length) {
|
|
108
|
-
promises.push(courier.profiles.subscribeToLists(userId, {
|
|
109
|
-
lists: lists.map(l => ({ listId: l })),
|
|
110
|
-
}, { maxRetries: 5, timeoutInSeconds: DEFAULT_TIMEOUT }));
|
|
111
|
-
}
|
|
112
|
-
if (tenants.length) {
|
|
113
|
-
promises.push(courier.users.tenants.addMultple(userId, {
|
|
114
|
-
tenants: tenants.map(t => ({ tenant_id: t })),
|
|
115
|
-
}, { maxRetries: 5, timeoutInSeconds: DEFAULT_TIMEOUT }));
|
|
116
|
-
}
|
|
117
|
-
if (tenant_id) {
|
|
118
|
-
promises.push(courier.users.tenants.add(userId, tenant_id, {}, { maxRetries: 5, timeoutInSeconds: DEFAULT_TIMEOUT }));
|
|
119
|
-
}
|
|
120
|
-
await Promise.all(promises);
|
|
121
|
-
counter.increment();
|
|
122
|
-
return resolve({ userId, success: true, index });
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
counter.increment();
|
|
126
|
-
return resolve({
|
|
127
|
-
userId,
|
|
128
|
-
success: false,
|
|
129
|
-
index,
|
|
130
|
-
error: (String(error) ??
|
|
131
|
-
error?.message ??
|
|
132
|
-
error.message ??
|
|
133
|
-
'Unknown Error') + `+ ${userId}`,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
const processData = async () => {
|
|
139
|
-
if (data?.length) {
|
|
140
|
-
let data_copy = [...data];
|
|
141
|
-
let counter = 0;
|
|
142
|
-
let { rows, data: rest } = getChunk(data_copy, chunk_size);
|
|
143
|
-
while (rows?.length) {
|
|
144
|
-
const chunk = processChunkRows(rows, counter);
|
|
145
|
-
const processed_chunks = await Promise.all(chunk);
|
|
146
|
-
const errors = processed_chunks.filter(r => !r.success);
|
|
147
|
-
if (errors.length) {
|
|
148
|
-
setDataErrors(p => [
|
|
149
|
-
...p,
|
|
150
|
-
...errors.map(r => {
|
|
151
|
-
return `user_id (${r.userId}) failed to update in index ${r.index}: ${String(r.error)}`;
|
|
152
|
-
}),
|
|
153
|
-
]);
|
|
154
|
-
setRowErrors(r => [
|
|
155
|
-
...r,
|
|
156
|
-
...errors.map(e => data[e.index]),
|
|
157
|
-
]);
|
|
158
|
-
}
|
|
159
|
-
if (rest.length > 0) {
|
|
160
|
-
await delay(delay_between_chunks);
|
|
161
|
-
counter += rows.length;
|
|
162
|
-
const next = getChunk(rest, chunk_size);
|
|
163
|
-
rows = next.rows;
|
|
164
|
-
rest = next.data;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
processing.setFalse();
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
const handleErrors = async () => {
|
|
174
|
-
if (row_errors.length && log_errors) {
|
|
175
|
-
await fs.writeFile(DEFAULT_ERROR_FILENAME, JSON.stringify(row_errors, null, 2), {
|
|
176
|
-
encoding: 'utf-8',
|
|
177
|
-
});
|
|
178
|
-
running.setFalse();
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
running.setFalse();
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
if (!filename?.length) {
|
|
185
|
-
return React.createElement(UhOh, { text: "You must specify a filename." });
|
|
186
|
-
}
|
|
187
|
-
else if (error?.length) {
|
|
188
|
-
return React.createElement(UhOh, { text: error });
|
|
189
|
-
}
|
|
190
|
-
else if (data && running.value) {
|
|
191
|
-
return (React.createElement(React.Fragment, null,
|
|
192
|
-
React.createElement(ProgressBar, { value: Math.floor((counter.count / data.length) * 100) }),
|
|
193
|
-
React.createElement(Spinner, { text: `Completed Rows: ${counter.count} / ${data.length}` })));
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
return (React.createElement(Box, { flexDirection: "column", marginY: 1 },
|
|
197
|
-
React.createElement(Text, { color: 'green' }, `Completed Rows: ${counter.count} / ${data?.length || 0}`),
|
|
198
|
-
data_errors.map((err, i) => {
|
|
199
|
-
return React.createElement(UhOh, { key: i, text: err });
|
|
200
|
-
}),
|
|
201
|
-
log_errors && data_errors.length ? (React.createElement(Text, null,
|
|
202
|
-
"Errors output to ",
|
|
203
|
-
DEFAULT_ERROR_FILENAME)) : (React.createElement(React.Fragment, null))));
|
|
204
|
-
}
|
|
205
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
import { useCliContext } from '../components/Context.js';
|
|
7
|
-
import get from 'lodash/get.js';
|
|
8
|
-
export default ({ params }) => {
|
|
9
|
-
const { apikey, url, parsedParams } = useCliContext();
|
|
10
|
-
const get_tenants = Boolean(get(parsedParams, ['tenants']));
|
|
11
|
-
const [resp, setResp] = useState();
|
|
12
|
-
const [tenants, setTenants] = useState();
|
|
13
|
-
const userId = params?._?.[0];
|
|
14
|
-
if (!userId) {
|
|
15
|
-
return React.createElement(UhOh, { text: "You must specify a user ID." });
|
|
16
|
-
}
|
|
17
|
-
const request = {
|
|
18
|
-
method: 'GET',
|
|
19
|
-
url: `/profiles/${userId}`,
|
|
20
|
-
};
|
|
21
|
-
const tenant_request = {
|
|
22
|
-
method: 'GET',
|
|
23
|
-
url: `/users/${userId}/tenants`,
|
|
24
|
-
};
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
api(request, url, apikey).then(res => setResp(res));
|
|
27
|
-
if (get_tenants) {
|
|
28
|
-
api(tenant_request, url, apikey).then(res => setTenants(res));
|
|
29
|
-
}
|
|
30
|
-
}, []);
|
|
31
|
-
return (React.createElement(React.Fragment, null,
|
|
32
|
-
React.createElement(Request, { request: request, response: resp }),
|
|
33
|
-
React.createElement(Response, { response: resp }),
|
|
34
|
-
get_tenants ? (React.createElement(React.Fragment, null,
|
|
35
|
-
React.createElement(Request, { request: tenant_request, response: tenants }),
|
|
36
|
-
React.createElement(Response, { response: tenants }))) : (React.createElement(React.Fragment, null))));
|
|
37
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Box, Text } from 'ink';
|
|
2
|
-
import lodash from 'lodash';
|
|
3
|
-
import React, { useEffect, useState } from 'react';
|
|
4
|
-
import { useCliContext } from '../components/Context.js';
|
|
5
|
-
import SdkResponse from '../components/SdkResponse.js';
|
|
6
|
-
import UhOh from '../components/UhOh.js';
|
|
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';
|
|
13
|
-
export default () => {
|
|
14
|
-
const { courier, parsedParams, url: baseUrl, apikey } = useCliContext();
|
|
15
|
-
const params = parsedParams;
|
|
16
|
-
const [resp, setResp] = useState();
|
|
17
|
-
const [urlResp, setUrlResp] = useState();
|
|
18
|
-
const [err, setErr] = useState();
|
|
19
|
-
const userId = lodash.get(params, ['_', 0]);
|
|
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
|
-
}, []);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
getPreferences();
|
|
33
|
-
}, []);
|
|
34
|
-
const getPreferences = async () => {
|
|
35
|
-
try {
|
|
36
|
-
const user = await courier.users.preferences.list(userId);
|
|
37
|
-
setResp(user);
|
|
38
|
-
}
|
|
39
|
-
catch (e) {
|
|
40
|
-
setErr(e);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
if (!userId) {
|
|
44
|
-
return React.createElement(UhOh, { text: "You must specify a user ID." });
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
const short_preferences = lodash.map(lodash.get(resp, ['items']), item => {
|
|
48
|
-
return (React.createElement(KVP, { key: item.topic_id, label: item.topic_name, value: item.status }));
|
|
49
|
-
});
|
|
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"))))));
|
|
66
|
-
}
|
|
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
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
import { useCliContext } from '../components/Context.js';
|
|
7
|
-
export default ({ params }) => {
|
|
8
|
-
const { apikey, url } = useCliContext();
|
|
9
|
-
const [resp, setResp] = useState();
|
|
10
|
-
const userId = params?._?.[0];
|
|
11
|
-
if (!userId) {
|
|
12
|
-
return React.createElement(UhOh, { text: "You must specify a user ID." });
|
|
13
|
-
}
|
|
14
|
-
const { _, ...properties } = params;
|
|
15
|
-
if (properties.tel) {
|
|
16
|
-
properties.phone_number = properties.tel;
|
|
17
|
-
delete properties.tel;
|
|
18
|
-
}
|
|
19
|
-
const request = {
|
|
20
|
-
method: 'PUT',
|
|
21
|
-
url: `/profiles/${userId}`,
|
|
22
|
-
body: {
|
|
23
|
-
profile: {
|
|
24
|
-
...properties,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
api(request, url, apikey).then(res => setResp(res));
|
|
30
|
-
}, []);
|
|
31
|
-
return (React.createElement(React.Fragment, null,
|
|
32
|
-
React.createElement(Request, { request: request, response: resp }),
|
|
33
|
-
React.createElement(Response, { response: resp })));
|
|
34
|
-
};
|