@trycourier/cli 2.1.0 → 2.1.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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
interface IArchiveAll {
|
|
3
3
|
user_id_override?: string;
|
|
4
|
+
user_finished?: (messages: number) => void;
|
|
5
|
+
onError?: (text: string) => void;
|
|
4
6
|
}
|
|
5
|
-
declare const ArchiveAll: ({ user_id_override }: IArchiveAll) => React.JSX.Element;
|
|
7
|
+
declare const ArchiveAll: ({ user_id_override, user_finished, onError, }: IArchiveAll) => React.JSX.Element;
|
|
6
8
|
export default ArchiveAll;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Inbox } from '@trycourier/client-graphql';
|
|
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';
|
|
5
6
|
import { useCliContext } from '../../components/Context.js';
|
|
@@ -8,9 +9,8 @@ import UhOh from '../../components/UhOh.js';
|
|
|
8
9
|
import uuid from '../../lib/uuid.js';
|
|
9
10
|
// @ts-ignore
|
|
10
11
|
import ms from 'ms';
|
|
11
|
-
import _ from 'lodash';
|
|
12
12
|
const LIMIT = 10;
|
|
13
|
-
const ArchiveAll = ({ user_id_override }) => {
|
|
13
|
+
const ArchiveAll = ({ user_id_override, user_finished, onError, }) => {
|
|
14
14
|
const [error, setError] = useState();
|
|
15
15
|
const [InboxClient, setInboxClient] = useState();
|
|
16
16
|
const [jwt, setJwt] = useState('');
|
|
@@ -29,7 +29,11 @@ const ArchiveAll = ({ user_id_override }) => {
|
|
|
29
29
|
: undefined;
|
|
30
30
|
const limit = Number(batchSize) || LIMIT;
|
|
31
31
|
const handleError = (text) => {
|
|
32
|
-
|
|
32
|
+
const t = text + '\n' + JSON.stringify({ tenant, tag, user_id, args });
|
|
33
|
+
setError(t);
|
|
34
|
+
if (onError) {
|
|
35
|
+
onError(t);
|
|
36
|
+
}
|
|
33
37
|
};
|
|
34
38
|
useEffect(() => {
|
|
35
39
|
getInboxClient();
|
|
@@ -92,6 +96,9 @@ const ArchiveAll = ({ user_id_override }) => {
|
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
running.setFalse();
|
|
99
|
+
if (user_finished) {
|
|
100
|
+
user_finished(messages.length);
|
|
101
|
+
}
|
|
95
102
|
};
|
|
96
103
|
const getAllMessages = async () => {
|
|
97
104
|
let cursor;
|
|
@@ -156,7 +163,7 @@ const ArchiveAll = ({ user_id_override }) => {
|
|
|
156
163
|
return React.createElement(UhOh, { text: error });
|
|
157
164
|
}
|
|
158
165
|
else if (gathering_messages.value) {
|
|
159
|
-
return (React.createElement(Spinner, { text: `Finding messages: Found ${messages.length} in ${pages.count} pages ` }));
|
|
166
|
+
return (React.createElement(Spinner, { text: `Finding messages: Found ${messages.length} in ${pages.count} pages for ${user_id}` }));
|
|
160
167
|
}
|
|
161
168
|
else if (running.value) {
|
|
162
169
|
return (React.createElement(Spinner, { text: `Archiving ${archived_messages.count} / ${messages.length} for ${user_id}` }));
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import { useBoolean, useCounter } from 'usehooks-ts';
|
|
4
|
+
import { useCliContext } from '../../components/Context.js';
|
|
5
|
+
import Spinner from '../../components/Spinner.js';
|
|
6
|
+
import UhOh from '../../components/UhOh.js';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { Alert } from '@inkjs/ui';
|
|
9
|
+
import getDb from '../../bulk.js';
|
|
10
|
+
import ArchiveAll from './ArchiveAll.js';
|
|
11
|
+
const ArchiveAllBulk = ({}) => {
|
|
12
|
+
const [error, setError] = useState();
|
|
13
|
+
const running = useBoolean(true);
|
|
14
|
+
const processing = useBoolean(false);
|
|
15
|
+
const { parsedParams } = useCliContext();
|
|
16
|
+
const [data, setData] = useState();
|
|
17
|
+
const current = useCounter(0);
|
|
18
|
+
const [finished, setFinished] = useState([]);
|
|
19
|
+
const { _: [filename], } = parsedParams;
|
|
20
|
+
const { db, filetype, sql } = getDb(filename || '');
|
|
21
|
+
const getData = () => {
|
|
22
|
+
db.all(sql, (err, result) => {
|
|
23
|
+
if (err) {
|
|
24
|
+
setError(err.message);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
setData(result);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (filetype) {
|
|
33
|
+
getData();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
setError('File type not supported.');
|
|
37
|
+
}
|
|
38
|
+
}, []);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (data) {
|
|
41
|
+
processData();
|
|
42
|
+
}
|
|
43
|
+
}, [data]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (error?.length) {
|
|
46
|
+
running.setFalse();
|
|
47
|
+
}
|
|
48
|
+
}, [error]);
|
|
49
|
+
const processData = () => {
|
|
50
|
+
if (data?.length) {
|
|
51
|
+
processing.setTrue();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const getNext = () => {
|
|
55
|
+
if (data?.length && current.count < data.length - 1) {
|
|
56
|
+
current.increment();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
running.setFalse();
|
|
60
|
+
processing.setFalse();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
if (error?.length) {
|
|
64
|
+
return React.createElement(UhOh, { text: error });
|
|
65
|
+
}
|
|
66
|
+
else if (processing.value) {
|
|
67
|
+
const current_user = _.get(data, [current.count, 'user_id']);
|
|
68
|
+
if (!current_user) {
|
|
69
|
+
getNext();
|
|
70
|
+
return React.createElement(UhOh, { text: "No user_id found" });
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return (React.createElement(React.Fragment, null,
|
|
74
|
+
finished.map((t, i) => (React.createElement(Alert, { key: i, variant: t.type }, t.message))),
|
|
75
|
+
React.createElement(Spinner, { text: `Processing ${current_user}` }),
|
|
76
|
+
React.createElement(ArchiveAll, { key: current_user, user_id_override: current_user, onError: (error) => {
|
|
77
|
+
const text = `${current_user} - ${error}`;
|
|
78
|
+
setFinished(p => [...p, { type: 'error', message: text }]);
|
|
79
|
+
getNext();
|
|
80
|
+
}, user_finished: (messages) => {
|
|
81
|
+
const text = `${current_user} - Archived ${messages} messages`;
|
|
82
|
+
setFinished(p => [...p, { type: 'success', message: text }]);
|
|
83
|
+
getNext();
|
|
84
|
+
} })));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (running.value) {
|
|
88
|
+
return React.createElement(Spinner, { text: "Gathering data" });
|
|
89
|
+
}
|
|
90
|
+
else if (finished.length) {
|
|
91
|
+
return (React.createElement(React.Fragment, null, finished.map((t, i) => (React.createElement(Alert, { key: i, variant: t.type }, t.message)))));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return React.createElement(UhOh, { text: "No data found" });
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
export default ArchiveAllBulk;
|
package/dist/mappings.js
CHANGED
|
@@ -14,6 +14,7 @@ import Upgrade from './commands/Upgrade.js';
|
|
|
14
14
|
import TenantsBulk from './commands/TenantsBulk.js';
|
|
15
15
|
import MarkAllRead from './commands/Inbox/MarkAllRead.js';
|
|
16
16
|
import ArchiveAll from './commands/Inbox/ArchiveAll.js';
|
|
17
|
+
import ArchiveAllBulk from './commands/Inbox/ArchiveAllBulk.js';
|
|
17
18
|
const mappings = new Map();
|
|
18
19
|
export const COMMON_OPTIONS = [
|
|
19
20
|
{
|
|
@@ -360,4 +361,17 @@ mappings.set('inbox:archive-all', {
|
|
|
360
361
|
return React.createElement(ArchiveAll, null);
|
|
361
362
|
},
|
|
362
363
|
});
|
|
364
|
+
mappings.set('inbox:archive-all:bulk', {
|
|
365
|
+
params: '<filename>',
|
|
366
|
+
instructions: 'Archive all messages in the inbox for each user in the file',
|
|
367
|
+
example: [
|
|
368
|
+
`courier inbox:archive-all:bulk archive-inbox.csv --before="7 day"`,
|
|
369
|
+
`courier inbox:archive-all user123 --tenant=workspace123`,
|
|
370
|
+
`courier inbox:archive-all user123 --tag product --tag marketing"`,
|
|
371
|
+
],
|
|
372
|
+
options: mappings.get('inbox:archive-all').options,
|
|
373
|
+
component: () => {
|
|
374
|
+
return React.createElement(ArchiveAllBulk, null);
|
|
375
|
+
},
|
|
376
|
+
});
|
|
363
377
|
export default mappings;
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let VERSION = '2.1.
|
|
1
|
+
let VERSION = '2.1.1';
|
|
2
2
|
export default VERSION;
|