@trycourier/cli 1.5.0 → 2.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.
Files changed (62) hide show
  1. package/README.md +57 -21
  2. package/dist/cli.js +38 -2
  3. package/dist/commands/Config.d.ts +2 -7
  4. package/dist/commands/Config.js +36 -9
  5. package/dist/commands/DigestFlush.js +3 -1
  6. package/dist/commands/Help.js +12 -16
  7. package/dist/commands/Send.js +45 -31
  8. package/dist/commands/Track.js +3 -1
  9. package/dist/commands/TranslationsDownload.js +3 -1
  10. package/dist/commands/TranslationsUpload.js +3 -1
  11. package/dist/commands/Upgrade.js +36 -0
  12. package/dist/commands/UsersBulk.js +159 -0
  13. package/dist/commands/UsersGet.js +3 -1
  14. package/dist/commands/UsersPreferences.js +41 -0
  15. package/dist/commands/UsersSet.js +3 -1
  16. package/dist/commands/WhoAmI.js +5 -2
  17. package/dist/components/Context.d.ts +43 -0
  18. package/dist/components/Context.js +75 -0
  19. package/dist/components/Router.d.ts +2 -9
  20. package/dist/components/Router.js +51 -20
  21. package/dist/components/SdkResponse.d.ts +8 -0
  22. package/dist/components/SdkResponse.js +20 -0
  23. package/dist/components/Table.d.ts +24 -0
  24. package/dist/components/Table.js +62 -0
  25. package/dist/constants.d.ts +1 -0
  26. package/dist/constants.js +1 -0
  27. package/dist/lib/api.d.ts +1 -1
  28. package/dist/lib/api.js +4 -4
  29. package/dist/lib/courier.d.ts +3 -0
  30. package/dist/lib/courier.js +7 -0
  31. package/dist/lib/load-env.js +1 -1
  32. package/dist/mappings.d.ts +4 -13
  33. package/dist/mappings.js +118 -15
  34. package/dist/version.d.ts +2 -0
  35. package/dist/version.js +2 -0
  36. package/package.json +24 -7
  37. package/dist/Counter.js +0 -16
  38. package/dist/Error.js +0 -4
  39. package/dist/Help.js +0 -13
  40. package/dist/app.d.ts +0 -6
  41. package/dist/app.js +0 -7
  42. package/dist/commands/DigestsFlush.d.ts +0 -5
  43. package/dist/commands/DigestsFlush.js +0 -23
  44. package/dist/commands/EventsTrack.d.ts +0 -5
  45. package/dist/commands/EventsTrack.js +0 -34
  46. package/dist/commands/TranslationUpload.d.ts +0 -5
  47. package/dist/commands/TranslationUpload.js +0 -28
  48. package/dist/components/Counter.d.ts +0 -3
  49. package/dist/components/Counter.js +0 -16
  50. package/dist/components/Error.d.ts +0 -5
  51. package/dist/components/Error.js +0 -5
  52. package/dist/components/Hello.d.ts +0 -5
  53. package/dist/components/Hello.js +0 -7
  54. package/dist/components/Help.d.ts +0 -9
  55. package/dist/components/Help.js +0 -23
  56. package/dist/components/WhoAmI.d.ts +0 -3
  57. package/dist/components/WhoAmI.js +0 -42
  58. package/dist/lib/render-elemental.d.ts +0 -2
  59. package/dist/lib/render-elemental.js +0 -1
  60. /package/dist/{Counter.d.ts → commands/Upgrade.d.ts} +0 -0
  61. /package/dist/{Error.d.ts → commands/UsersBulk.d.ts} +0 -0
  62. /package/dist/{Help.d.ts → commands/UsersPreferences.d.ts} +0 -0
@@ -3,7 +3,7 @@ import fs from 'fs';
3
3
  import dotenv from 'dotenv';
4
4
  export default async () => {
5
5
  const paths = [
6
- `${process.cwd()}/.courier`,
6
+ `${process.cwd()}/.courier`, // current working directory
7
7
  `${os.homedir()}/.courier`, // user home directory
8
8
  ];
9
9
  for (const path of paths) {
@@ -1,15 +1,6 @@
1
- import React from 'react';
2
- interface IMapping {
3
- noApiKeyRequired?: boolean;
4
- params?: string;
5
- instructions?: string;
6
- example?: string | string[];
7
- options?: {
8
- option: string;
9
- value?: string;
10
- instructions?: string;
11
- }[];
12
- component: (params?: any) => React.ReactElement;
13
- }
14
1
  declare const mappings: Map<string, IMapping>;
2
+ export declare const COMMON_OPTIONS: {
3
+ option: string;
4
+ value: string;
5
+ }[];
15
6
  export default mappings;
package/dist/mappings.js CHANGED
@@ -6,10 +6,38 @@ import Track from './commands/Track.js';
6
6
  import UsersGet from './commands/UsersGet.js';
7
7
  import UsersSet from './commands/UsersSet.js';
8
8
  import Send from './commands/Send.js';
9
- import DigestFlush from './commands/DigestFlush.js';
10
9
  import TranslationsDownload from './commands/TranslationsDownload.js';
11
10
  import TranslationsUpload from './commands/TranslationsUpload.js';
11
+ import UsersBulk from './commands/UsersBulk.js';
12
+ import UsersPreferences from './commands/UsersPreferences.js';
13
+ import Upgrade from './commands/Upgrade.js';
12
14
  const mappings = new Map();
15
+ export const COMMON_OPTIONS = [
16
+ {
17
+ option: '-M --mock',
18
+ value: 'Use the API key that simulates sending using the simulating routing',
19
+ },
20
+ {
21
+ option: '-P --production',
22
+ value: 'Use the production environment API key',
23
+ },
24
+ {
25
+ option: '-D --draft',
26
+ value: 'Use the draft document scope API key. Use draft or submitted, will default to published key if neither are provided',
27
+ },
28
+ {
29
+ option: '-S --submitted',
30
+ value: 'Use the submitted document scope API key',
31
+ },
32
+ {
33
+ option: '--apikey <Courier API Key>',
34
+ value: 'Use the provided Courier API key, otherwise use the approprate environment variable',
35
+ },
36
+ {
37
+ option: '--apiurl <Courier API URL>',
38
+ value: 'Use the provided Courier API URL, otherwise use COURIER_API_URL environment variable. Default is https://api.courier.com',
39
+ },
40
+ ];
13
41
  mappings.set('help', {
14
42
  component: () => {
15
43
  return React.createElement(Help, { mappings: mappings });
@@ -18,20 +46,20 @@ mappings.set('help', {
18
46
  });
19
47
  mappings.set('config', {
20
48
  instructions: 'Persist your Courier API key into a .courier file in your current working directory',
21
- component: params => {
22
- return React.createElement(Config, { params: params });
49
+ component: () => {
50
+ return React.createElement(Config, null);
23
51
  },
24
52
  options: [
25
- {
26
- option: '--apikey <Courier API Key>',
27
- value: '',
28
- },
29
53
  {
30
54
  option: '--overwrite',
31
- value: 'overwrite an existing .courier file',
55
+ value: 'Overwrite this apikey in the existing .courier file',
32
56
  },
33
57
  ],
34
- example: `courier config --apikey MY_API_KEY`,
58
+ example: [
59
+ `courier config --apikey MY_API_KEY -P --override`,
60
+ `courier config --apikey MY_API_KEY --mock`,
61
+ `courier config --apikey MY_API_KEY --draft`,
62
+ ],
35
63
  noApiKeyRequired: true,
36
64
  });
37
65
  mappings.set('whoami', {
@@ -71,6 +99,18 @@ mappings.set('send', {
71
99
  option: '--audience <audience ID>',
72
100
  value: 'ID of a Courier Audience in your workspace',
73
101
  },
102
+ {
103
+ option: '--tenant <tenant ID>',
104
+ value: 'ID of a Courier Tenant in your workspace. Will be used to send',
105
+ },
106
+ {
107
+ option: '--include-children',
108
+ value: 'When sending to a tenant, include all the children of the tenant',
109
+ },
110
+ {
111
+ option: '--tenant-context <tenant ID>',
112
+ value: 'ID of a Courier Tenant in your workspace. Applies the tenant context to the message',
113
+ },
74
114
  {
75
115
  option: '--body <message body>',
76
116
  value: '',
@@ -99,6 +139,9 @@ mappings.set('send', {
99
139
  example: [
100
140
  `courier send --tel 555-867-5309 --body "Hey Jenny\\!"`,
101
141
  `courier send --user user123 --template my-template-id --foo bar`,
142
+ `courier send -P --user=test123 --body "hello world" --title="hello" --channels=inbox`,
143
+ `courier send --tenant=kewl --title=hello --body="hello world" --channel=inbox`,
144
+ `courier send --user="1" --tenant-context=kewl --title=hello --body="hello world" --channel=inbox`,
102
145
  ],
103
146
  component: params => {
104
147
  return React.createElement(Send, { params: params });
@@ -148,14 +191,63 @@ mappings.set('users:set', {
148
191
  return React.createElement(UsersSet, { params: params });
149
192
  },
150
193
  });
151
- mappings.set('digests:flush', {
152
- params: '<user> <digest>',
153
- instructions: 'Flush any currently queued events for a given user + digest',
154
- example: `courier digests:flush user123 MY_DIGEST_TOPIC`,
155
- component: params => {
156
- return React.createElement(DigestFlush, { params: params });
194
+ mappings.set('users:bulk', {
195
+ params: '<filename>',
196
+ instructions: 'Bulk import users from a file (csv, json, jsonl, xls, xlsx, .parquet)." For CSVs, we will unpack nested objects based on the header. E.g., "address.city" becomes {"address": {"city": "value"}}. Lodash path syntax is used for created the nested object. Supports wildcard syntax for multiple files, must surround with quotes (see examples)',
197
+ options: [
198
+ {
199
+ option: '--replace',
200
+ value: 'Replace existing users with the same ID, if not set, will do a merge based on key',
201
+ },
202
+ {
203
+ option: '--keep-flat',
204
+ value: 'When using a CSV, do not unpack nested objects based on the header. E.g., "address.city" stays as {"address.city": "value"}',
205
+ },
206
+ {
207
+ option: '--remove-nulls',
208
+ value: 'Remove null values from the object before updating the profile',
209
+ },
210
+ {
211
+ option: '--list <List ID>',
212
+ value: 'Add all users to the specified list. Accepts comma-separated list',
213
+ },
214
+ {
215
+ option: '--tenant <Tenant ID>',
216
+ value: 'Add all users to the specified tenant. Accepts comma-separated list. Note this will not automatically create the tenant, but the tenant memberships will exist and sending to this tenant_id will still succeed. ',
217
+ },
218
+ ],
219
+ example: [
220
+ `courier users:bulk examples/users.csv --replace`,
221
+ `courier users:bulk "examples/users/*.csv" --keep-flat`,
222
+ `courier users:bulk "examples/*.json" --remove-nulls`,
223
+ 'courier users:bulk examples/users.parquet --list new-list-id',
224
+ 'courier users:bulk examples/users.xlsx --tenant new-tenant-id',
225
+ ],
226
+ component: () => React.createElement(UsersBulk, null),
227
+ });
228
+ mappings.set('users:preferences', {
229
+ params: '<user>',
230
+ instructions: 'Fetch the preferences for a given user ID',
231
+ example: `courier users:preferences user123`,
232
+ options: [
233
+ {
234
+ option: '--verbose',
235
+ value: 'Show the full preference object',
236
+ },
237
+ ],
238
+ component: () => {
239
+ return React.createElement(UsersPreferences, null);
157
240
  },
158
241
  });
242
+ // NOT IMPLEMENTED YET
243
+ // mappings.set('digests:flush', {
244
+ // params: '<user> <digest>',
245
+ // instructions: 'Flush any currently queued events for a given user + digest',
246
+ // example: `courier digests:flush user123 MY_DIGEST_TOPIC`,
247
+ // component: params => {
248
+ // return <DigestFlush params={params} />;
249
+ // },
250
+ // });
159
251
  mappings.set('translations:upload', {
160
252
  params: '<locale> <filepath>',
161
253
  instructions: 'Upload a .PO file to Courier for a given locale',
@@ -188,4 +280,15 @@ mappings.set('translations:download', {
188
280
  return React.createElement(TranslationsDownload, { params: params });
189
281
  },
190
282
  });
283
+ mappings.set('upgrade', {
284
+ instructions: `Upgrade the Courier CLI to the latest versionw`,
285
+ component: () => React.createElement(Upgrade, null),
286
+ });
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');
191
294
  export default mappings;
@@ -0,0 +1,2 @@
1
+ declare let VERSION: string;
2
+ export default VERSION;
@@ -0,0 +1,2 @@
1
+ let VERSION = '${GITHUB_REF_NAME#v}';
2
+ export default VERSION;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@trycourier/cli",
3
- "version": "1.5.0",
3
+ "version": "2.0.1",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "courier": "dist/cli.js"
7
7
  },
8
8
  "type": "module",
9
9
  "engines": {
10
- "node": ">=16"
10
+ "node": ">=18"
11
11
  },
12
12
  "scripts": {
13
13
  "build": "tsc",
@@ -19,14 +19,22 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "cli-spinners": "^2.9.0",
22
+ "@inkjs/ui": "^2.0.0",
23
+ "@trycourier/courier": "^6.1.2",
24
+ "cli-spinners": "^3.0.0",
23
25
  "dotenv": "^16.0.3",
24
- "ink": "^4.1.0",
26
+ "duckdb": "^0.10.2",
27
+ "execa": "^9.1.0",
28
+ "ink": "^5.0.1",
29
+ "lodash": "^4.17.21",
25
30
  "react": "^18.2.0",
31
+ "usehooks-ts": "^3.1.0",
26
32
  "yargs-parser": "^21.1.1"
27
33
  },
28
34
  "devDependencies": {
29
- "@sindresorhus/tsconfig": "^3.0.1",
35
+ "@sindresorhus/tsconfig": "^5.0.0",
36
+ "@types/lodash": "^4.17.4",
37
+ "@types/node": "^20.13.0",
30
38
  "@types/react": "^18.0.32",
31
39
  "@types/yargs-parser": "^21.0.0",
32
40
  "@vdemedes/prettier-config": "^2.0.1",
@@ -38,7 +46,7 @@
38
46
  "ink-testing-library": "^3.0.0",
39
47
  "prettier": "^2.8.7",
40
48
  "ts-node": "^10.9.1",
41
- "typescript": "^5.0.3",
49
+ "typescript": "^5.4.5",
42
50
  "xo": "^0.53.1"
43
51
  },
44
52
  "ava": {
@@ -57,5 +65,14 @@
57
65
  "react/prop-types": "off"
58
66
  }
59
67
  },
60
- "prettier": "@vdemedes/prettier-config"
68
+ "prettier": "@vdemedes/prettier-config",
69
+ "repository": {
70
+ "type": "git",
71
+ "url": "https://github.com/trycourier/courier-cli.git"
72
+ },
73
+ "publishConfig": {
74
+ "access": "public",
75
+ "registry": "https://registry.npmjs.org/"
76
+ },
77
+ "homepage": "https://github.com/trycourier/courier-cli#readme"
61
78
  }
package/dist/Counter.js DELETED
@@ -1,16 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { Text } from 'ink';
3
- export default () => {
4
- const [counter, setCounter] = useState(0);
5
- useEffect(() => {
6
- const timer = setInterval(() => {
7
- setCounter(previousCounter => previousCounter + 1);
8
- }, 100);
9
- return () => {
10
- clearInterval(timer);
11
- };
12
- }, []);
13
- return React.createElement(Text, { color: "green" },
14
- counter,
15
- " tests passed");
16
- };
package/dist/Error.js DELETED
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import { Box, Text } from 'ink';
3
- export default () => (React.createElement(Box, { flexDirection: "column" },
4
- React.createElement(Text, { color: "red" }, "ERROR")));
package/dist/Help.js DELETED
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- import { Box, Text, Newline } from 'ink';
3
- export default () => (React.createElement(Box, { flexDirection: "column" },
4
- React.createElement(Text, null,
5
- "Usage $ %NAME%",
6
- React.createElement(Newline, null)),
7
- React.createElement(Text, null, "Options"),
8
- React.createElement(Text, null,
9
- " --name Your name",
10
- React.createElement(Newline, null)),
11
- React.createElement(Text, null, "Examples"),
12
- React.createElement(Text, null, " $ %NAME% --name=Jane"),
13
- React.createElement(Text, null, " Hello, Jane")));
package/dist/app.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- type Props = {
3
- name: string | undefined;
4
- };
5
- export default function App({ name }: Props): React.JSX.Element;
6
- export {};
package/dist/app.js DELETED
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import { Text } from 'ink';
3
- export default function App({ name = 'Stranger' }) {
4
- return (React.createElement(Text, null,
5
- "Hello, ",
6
- React.createElement(Text, { color: "green" }, name)));
7
- }
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- declare const _default: ({ params }: {
3
- params: any;
4
- }) => React.JSX.Element;
5
- export default _default;
@@ -1,23 +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 api from '../lib/api.js';
5
- export default ({ params }) => {
6
- const [resp, setResp] = useState();
7
- const userId = params?._?.[0];
8
- if (!userId) {
9
- return React.createElement(UhOh, { text: "You must specify the ID of the user whose digest you want to flush." });
10
- }
11
- const topicId = params?._?.[1];
12
- if (!topicId) {
13
- return React.createElement(UhOh, { text: "You must specify the ID of the Digest Topic you want to flush for the given user." });
14
- }
15
- const request = {
16
- method: 'POST',
17
- url: `/users/${userId}/topic/${topicId}/flush`,
18
- };
19
- useEffect(() => {
20
- api(request).then(res => setResp(res));
21
- }, []);
22
- return React.createElement(Request, { request: request, response: resp });
23
- };
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- declare const _default: ({ params }: {
3
- params: any;
4
- }) => React.JSX.Element;
5
- export default _default;
@@ -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 api from '../lib/api.js';
5
- export default ({ params }) => {
6
- const [resp, setResp] = useState();
7
- const eventId = params?._?.[0];
8
- if (!eventId) {
9
- return React.createElement(UhOh, { text: "You must specify an event ID to trigger." });
10
- }
11
- const userId = params?._?.[1];
12
- if (!userId) {
13
- return React.createElement(UhOh, { text: "You must specify a user ID for the event." });
14
- }
15
- const { _, ...properties } = params;
16
- const payload = {
17
- type: 'track',
18
- event: eventId,
19
- messageId: Math.random().toString(36).substring(2),
20
- properties: {
21
- userId,
22
- ...properties,
23
- },
24
- };
25
- const request = {
26
- method: 'POST',
27
- url: '/inbound/courier',
28
- body: payload,
29
- };
30
- useEffect(() => {
31
- api(request).then(res => setResp(res));
32
- }, []);
33
- return React.createElement(Request, { request: request, response: resp });
34
- };
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- declare const _default: ({ params }: {
3
- params: any;
4
- }) => React.JSX.Element;
5
- export default _default;
@@ -1,28 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import fs from 'fs';
3
- import UhOh from '../components/UhOh.js';
4
- import Request from '../components/Request.js';
5
- import api from '../lib/api.js';
6
- export default ({ params }) => {
7
- const [resp, setResp] = useState();
8
- const locale = params?._?.[0];
9
- if (!locale) {
10
- return React.createElement(UhOh, { text: "You must specify a locale, e.g. en-US." });
11
- }
12
- const filepath = params?._?.[1];
13
- if (!filepath) {
14
- return React.createElement(UhOh, { text: "You must specify a path to the .PO file." });
15
- }
16
- else if (!fs.existsSync(filepath)) {
17
- return React.createElement(UhOh, { text: "No .PO file found at given path." });
18
- }
19
- const request = {
20
- method: 'PUT',
21
- url: `/translations/global/${locale}`,
22
- body: fs.readFileSync(filepath, 'utf8'),
23
- };
24
- useEffect(() => {
25
- api(request).then(res => setResp(res));
26
- }, []);
27
- return React.createElement(Request, { request: request, response: resp });
28
- };
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const _default: () => React.JSX.Element;
3
- export default _default;
@@ -1,16 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { Text } from 'ink';
3
- export default () => {
4
- const [counter, setCounter] = useState(0);
5
- useEffect(() => {
6
- const timer = setInterval(() => {
7
- setCounter(previousCounter => previousCounter + 1);
8
- }, 100);
9
- return () => {
10
- clearInterval(timer);
11
- };
12
- }, []);
13
- return React.createElement(Text, { color: "green" },
14
- counter,
15
- " tests passed");
16
- };
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- declare const _default: ({ text }: {
3
- text: string;
4
- }) => React.JSX.Element;
5
- export default _default;
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import { Text } from 'ink';
3
- export default ({ text }) => {
4
- return React.createElement(Text, { color: "red" }, text);
5
- };
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- declare const _default: ({ name }: {
3
- name?: string | undefined;
4
- }) => React.JSX.Element;
5
- export default _default;
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import { Text } from 'ink';
3
- export default ({ name = 'Stranger' }) => {
4
- return (React.createElement(Text, null,
5
- "Hello, ",
6
- React.createElement(Text, { color: "green" }, name)));
7
- };
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- interface IMapping {
3
- instructions?: string;
4
- component: (params: (string | undefined)[]) => React.ReactElement;
5
- }
6
- declare const _default: ({ mappings }: {
7
- mappings: Map<string, IMapping>;
8
- }) => React.JSX.Element;
9
- export default _default;
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import { Box, Text, Newline } from 'ink';
3
- import KVP from './KVP.js';
4
- import constants from '../constants.js';
5
- export default ({ mappings }) => {
6
- const keys = [...mappings.keys()]; // convert to array
7
- return React.createElement(Box, { flexDirection: "column" },
8
- React.createElement(Text, { bold: true }, "Usage"),
9
- React.createElement(Text, null,
10
- " $ ",
11
- React.createElement(Text, { color: constants.colors.primary }, "courier"),
12
- " ",
13
- React.createElement(Text, { color: "gray" }, "<command>"),
14
- React.createElement(Newline, null)),
15
- React.createElement(Text, { bold: true }, "Commands"),
16
- keys.map((k) => {
17
- const v = mappings.get(k);
18
- if (!v || !v.instructions || !v.instructions.length) {
19
- return null;
20
- }
21
- return React.createElement(KVP, { key: k, width: 12, indent: " \u2022 ", label: k, labelColor: constants.colors.primary, labelBold: false, value: v.instructions });
22
- }));
23
- };
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const _default: () => React.JSX.Element;
3
- export default _default;
@@ -1,42 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { Box } from 'ink';
3
- import Spinner from './Spinner.js';
4
- import KVP from './KVP.js';
5
- import UhOh from './UhOh.js';
6
- import api from '../lib/api.js';
7
- function delay(ms) {
8
- if (ms === 0) {
9
- return Promise.resolve();
10
- }
11
- return new Promise(resolve => setTimeout(resolve, ms));
12
- }
13
- export default () => {
14
- const [resp, setResp] = useState();
15
- const [error, setError] = useState();
16
- useEffect(() => {
17
- delay(2000)
18
- .then(() => api('/debug', 'POST'))
19
- .then(res => {
20
- if (res.status > 400) {
21
- throw new Error(`${res.status}: ${res.statusText}`);
22
- }
23
- else {
24
- return res.json();
25
- }
26
- })
27
- .then(json => setResp(json), (err) => setError(err.message));
28
- }, []);
29
- if (error) {
30
- return React.createElement(UhOh, { text: error });
31
- }
32
- else if (resp) {
33
- return React.createElement(Box, { flexDirection: "column" },
34
- React.createElement(KVP, { width: 20, label: "Workspace Name", value: resp.tenantName }),
35
- React.createElement(KVP, { width: 20, label: "Workspace ID", value: resp.tenantId }),
36
- React.createElement(KVP, { width: 20, label: "API Key Environment", value: resp.environment }),
37
- React.createElement(KVP, { width: 20, label: "API Key Scope", value: resp.scope }));
38
- }
39
- else {
40
- return React.createElement(Spinner, { text: "pondering your existence..." });
41
- }
42
- };
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
@@ -1 +0,0 @@
1
- export default () => { return; };
File without changes
File without changes