@trycourier/cli 2.1.0 → 2.1.2

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/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import React from 'react';
2
+ import React, { useEffect, useState } from 'react';
3
3
  import { Box, Text, render } from 'ink';
4
4
  import args from './lib/args.js';
5
5
  import loadEnv from './lib/load-env.js';
@@ -8,40 +8,47 @@ import { execa } from 'execa';
8
8
  import _ from 'lodash';
9
9
  import VERSION from './version.js';
10
10
  import constants from './constants.js';
11
- 2;
12
11
  const CLI = async () => {
13
12
  process.removeAllListeners('warning');
14
13
  await loadEnv();
15
14
  const params = args(process.argv);
16
15
  const mappings = (await import('./mappings.js')).default;
17
16
  const Router = (await import('./components/Router.js')).default;
18
- let current;
19
- let latest;
20
- if (VERSION !== 'local') {
21
- try {
22
- const exc = await execa('npm', ['-g', 'outdated', constants.package_name, '--json'], {
23
- shell: true,
24
- reject: false,
25
- });
26
- const stdout = JSON.parse(exc.stdout);
27
- current = _.get(stdout, ['npm', 'current']);
28
- latest = _.get(stdout, ['npm', 'latest']);
17
+ const [version, setVersion] = useState({});
18
+ useEffect(() => {
19
+ getVersion();
20
+ }, []);
21
+ const getVersion = async () => {
22
+ if (VERSION !== 'local') {
23
+ try {
24
+ const exc = await execa('npm', ['-g', 'outdated', constants.package_name, '--json'], {
25
+ shell: true,
26
+ reject: false,
27
+ });
28
+ const stdout = JSON.parse(exc.stdout);
29
+ setVersion({
30
+ current: _.get(stdout, [constants.package_name, 'current']),
31
+ latest: _.get(stdout, [constants.package_name, 'latest']),
32
+ });
33
+ }
34
+ catch (e) {
35
+ console.log(e);
36
+ }
29
37
  }
30
- catch (e) {
31
- console.log(e);
32
- }
33
- }
34
- const version_text = `Upgrade available (${current} > ${latest}), run courier upgrade`;
35
- render(React.createElement(CliContextProvider, { args: params, mappings, current, latest },
38
+ };
39
+ const version_text = version.current && version.latest && version.current !== version.latest
40
+ ? `Upgrade available (${version.current} > ${version.latest}), run courier upgrade`
41
+ : undefined;
42
+ render(React.createElement(CliContextProvider, { args: params, mappings, ...version },
36
43
  React.createElement(Router, null),
37
- current && latest && current !== latest ? (React.createElement(Box, { flexDirection: "column", marginY: 1, flexShrink: 1, width: version_text.length + 2, borderColor: "gray", borderStyle: 'single' },
44
+ version_text ? (React.createElement(Box, { flexDirection: "column", marginY: 1, flexShrink: 1, width: version_text.length + 2, borderColor: "gray", borderStyle: 'single' },
38
45
  React.createElement(Text, null,
39
46
  "Upgrade available (",
40
- current,
47
+ version.current,
41
48
  " ",
42
49
  '>',
43
50
  " ",
44
- latest,
51
+ version.latest,
45
52
  "), run",
46
53
  ' ',
47
54
  React.createElement(Text, { color: "green" }, "courier upgrade")))) : (React.createElement(React.Fragment, null))));
@@ -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
- setError(text + '\n' + JSON.stringify({ tenant, tag, user_id, args }));
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,5 @@
1
+ import React from 'react';
2
+ interface IArchiveAllBulk {
3
+ }
4
+ declare const ArchiveAllBulk: ({}: IArchiveAllBulk) => React.JSX.Element;
5
+ export default ArchiveAllBulk;
@@ -0,0 +1,99 @@
1
+ import { Alert } from '@inkjs/ui';
2
+ import _ from 'lodash';
3
+ import React, { useEffect, useState } from 'react';
4
+ import { useBoolean, useCounter } from 'usehooks-ts';
5
+ import getDb from '../../bulk.js';
6
+ import { useCliContext } from '../../components/Context.js';
7
+ import Spinner from '../../components/Spinner.js';
8
+ import UhOh from '../../components/UhOh.js';
9
+ import ArchiveAll from './ArchiveAll.js';
10
+ const ArchiveAllBulk = ({}) => {
11
+ const [error, setError] = useState();
12
+ const running = useBoolean(true);
13
+ const processing = useBoolean(false);
14
+ const { parsedParams } = useCliContext();
15
+ const [data, setData] = useState();
16
+ const current = useCounter(0);
17
+ const [finished, setFinished] = useState([]);
18
+ const { _: [filename], } = parsedParams;
19
+ const { db, filetype, sql } = getDb(filename || '');
20
+ const getData = () => {
21
+ db.all(sql, (err, result) => {
22
+ if (err) {
23
+ setError(err.message);
24
+ }
25
+ else {
26
+ setData(result);
27
+ }
28
+ });
29
+ };
30
+ useEffect(() => {
31
+ if (filetype) {
32
+ getData();
33
+ }
34
+ else {
35
+ setError('File type not supported.');
36
+ }
37
+ }, []);
38
+ useEffect(() => {
39
+ if (data) {
40
+ processData();
41
+ }
42
+ }, [data]);
43
+ useEffect(() => {
44
+ if (error?.length) {
45
+ running.setFalse();
46
+ }
47
+ }, [error]);
48
+ const processData = () => {
49
+ if (data?.length) {
50
+ processing.setTrue();
51
+ }
52
+ };
53
+ const getNext = () => {
54
+ if (data?.length && current.count < data.length - 1) {
55
+ current.increment();
56
+ }
57
+ else {
58
+ running.setFalse();
59
+ processing.setFalse();
60
+ }
61
+ };
62
+ if (error?.length) {
63
+ return React.createElement(UhOh, { text: error });
64
+ }
65
+ else if (processing.value) {
66
+ const current_user = _.get(data, [current.count, 'user_id']);
67
+ if (!current_user) {
68
+ getNext();
69
+ return React.createElement(UhOh, { text: "No user_id found" });
70
+ }
71
+ else {
72
+ return (React.createElement(React.Fragment, null,
73
+ finished.map((t, i) => (React.createElement(Alert, { key: i, variant: t.type }, t.message))),
74
+ React.createElement(Spinner, { text: `Processing ${current_user}` }),
75
+ React.createElement(ArchiveAll, { key: current_user, user_id_override: current_user, onError: (error) => {
76
+ const text = `user_id: ${current_user} | ${error}`;
77
+ setFinished(p => [...p, { type: 'error', message: text }]);
78
+ getNext();
79
+ }, user_finished: (messages) => {
80
+ const text = `user_id: ${current_user} | Archived ${messages} messages`;
81
+ setFinished(p => [
82
+ ...p,
83
+ { type: messages > 0 ? 'success' : 'info', message: text },
84
+ ]);
85
+ getNext();
86
+ } })));
87
+ }
88
+ }
89
+ else if (running.value) {
90
+ return React.createElement(Spinner, { text: "Gathering data" });
91
+ }
92
+ else if (finished.length) {
93
+ return (React.createElement(React.Fragment, null, finished.map((t, i) => (React.createElement(Alert, { key: i, variant: t.type }, t.message)))));
94
+ }
95
+ else {
96
+ return React.createElement(UhOh, { text: "No data found" });
97
+ }
98
+ };
99
+ export default ArchiveAllBulk;
@@ -18,10 +18,10 @@ export default () => {
18
18
  }, []);
19
19
  return (React.createElement(Box, { flexDirection: "column", width: "100%" },
20
20
  React.createElement(Request, { request: request, response: resp }),
21
- resp && resp.err ? (React.createElement(Response, { response: resp })) : resp && resp.json ? (React.createElement(React.Fragment, null,
22
- React.createElement(KVP, { width: 20, label: "Workspace Name", value: resp.json.tenantName }),
23
- React.createElement(KVP, { width: 20, label: "Workspace ID", value: resp.json.tenantId }),
24
- React.createElement(KVP, { width: 20, label: "API Key Environment", value: resp.json.environment }),
25
- React.createElement(KVP, { width: 20, label: "API Key Scope", value: resp.json.scope }),
26
- resp.json.mock && (React.createElement(KVP, { width: 20, label: "API Key Simulated (Mock)", value: resp.json.scope })))) : null));
21
+ resp && resp.err ? (React.createElement(Response, { response: resp })) : resp && resp.json ? (React.createElement(Box, { flexDirection: "column", width: "100%" },
22
+ React.createElement(KVP, { label: "Workspace Name", value: resp.json.tenantName }),
23
+ React.createElement(KVP, { label: "Workspace ID", value: resp.json.tenantId }),
24
+ React.createElement(KVP, { label: "API Key Environment", value: resp.json.environment }),
25
+ React.createElement(KVP, { label: "API Key Scope", value: resp.json.scope }),
26
+ resp.json.mock && (React.createElement(KVP, { label: "API Key Simulated (Mock)", value: resp.json.scope })))) : null));
27
27
  };
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { Box, Spacer, Text } from 'ink';
3
3
  export default ({ label, labelColor, labelBold, value, width, indent, }) => {
4
4
  return (React.createElement(Box, { flexDirection: "column" },
5
- React.createElement(Box, { width: width, flexDirection: "row" },
5
+ React.createElement(Box, { width: width || '100%', flexDirection: "row" },
6
6
  React.createElement(Text, null, indent),
7
7
  React.createElement(Text, { bold: labelBold === false ? false : true, color: labelColor }, label),
8
8
  React.createElement(Spacer, null),
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.0';
1
+ let VERSION = '2.1.2';
2
2
  export default VERSION;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/cli",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "courier": "dist/cli.js"