@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.
Files changed (103) hide show
  1. package/README.md +21 -92
  2. package/bin/.gitkeep +0 -0
  3. package/install.js +115 -0
  4. package/package.json +22 -87
  5. package/LICENSE +0 -21
  6. package/dist/bulk.d.ts +0 -15
  7. package/dist/bulk.js +0 -53
  8. package/dist/cli.d.ts +0 -2
  9. package/dist/cli.js +0 -24
  10. package/dist/commands/AudienceSearch.d.ts +0 -3
  11. package/dist/commands/AudienceSearch.js +0 -113
  12. package/dist/commands/AutomationInvokeBulk.d.ts +0 -3
  13. package/dist/commands/AutomationInvokeBulk.js +0 -139
  14. package/dist/commands/Config.d.ts +0 -4
  15. package/dist/commands/Config.js +0 -45
  16. package/dist/commands/DigestFlush.d.ts +0 -5
  17. package/dist/commands/DigestFlush.js +0 -28
  18. package/dist/commands/Help.d.ts +0 -16
  19. package/dist/commands/Help.js +0 -38
  20. package/dist/commands/Inbox/ArchiveAll.d.ts +0 -8
  21. package/dist/commands/Inbox/ArchiveAll.js +0 -180
  22. package/dist/commands/Inbox/ArchiveAllBulk.d.ts +0 -5
  23. package/dist/commands/Inbox/ArchiveAllBulk.js +0 -99
  24. package/dist/commands/Inbox/MarkAllRead.d.ts +0 -5
  25. package/dist/commands/Inbox/MarkAllRead.js +0 -110
  26. package/dist/commands/MessagesSearch.d.ts +0 -3
  27. package/dist/commands/MessagesSearch.js +0 -120
  28. package/dist/commands/NotYetImplemented.d.ts +0 -3
  29. package/dist/commands/NotYetImplemented.js +0 -5
  30. package/dist/commands/Send.d.ts +0 -5
  31. package/dist/commands/Send.js +0 -144
  32. package/dist/commands/Templates/List.d.ts +0 -3
  33. package/dist/commands/Templates/List.js +0 -114
  34. package/dist/commands/TenantsBulk.d.ts +0 -3
  35. package/dist/commands/TenantsBulk.js +0 -171
  36. package/dist/commands/TenantsGetMembership.d.ts +0 -3
  37. package/dist/commands/TenantsGetMembership.js +0 -127
  38. package/dist/commands/TenantsMembershipBulk.d.ts +0 -3
  39. package/dist/commands/TenantsMembershipBulk.js +0 -203
  40. package/dist/commands/Track.d.ts +0 -5
  41. package/dist/commands/Track.js +0 -40
  42. package/dist/commands/TrackBulk.d.ts +0 -3
  43. package/dist/commands/TrackBulk.js +0 -89
  44. package/dist/commands/TranslationsDownload.d.ts +0 -10
  45. package/dist/commands/TranslationsDownload.js +0 -30
  46. package/dist/commands/TranslationsUpload.d.ts +0 -9
  47. package/dist/commands/TranslationsUpload.js +0 -37
  48. package/dist/commands/Upgrade.d.ts +0 -3
  49. package/dist/commands/Upgrade.js +0 -38
  50. package/dist/commands/UserToken.d.ts +0 -3
  51. package/dist/commands/UserToken.js +0 -96
  52. package/dist/commands/UsersBulk.d.ts +0 -3
  53. package/dist/commands/UsersBulk.js +0 -205
  54. package/dist/commands/UsersGet.d.ts +0 -5
  55. package/dist/commands/UsersGet.js +0 -37
  56. package/dist/commands/UsersPreferences.d.ts +0 -3
  57. package/dist/commands/UsersPreferences.js +0 -73
  58. package/dist/commands/UsersSet.d.ts +0 -5
  59. package/dist/commands/UsersSet.js +0 -34
  60. package/dist/commands/UsersTokensBulk.d.ts +0 -3
  61. package/dist/commands/UsersTokensBulk.js +0 -215
  62. package/dist/commands/WhoAmI.d.ts +0 -3
  63. package/dist/commands/WhoAmI.js +0 -27
  64. package/dist/components/Context.d.ts +0 -55
  65. package/dist/components/Context.js +0 -94
  66. package/dist/components/Elemental.d.ts +0 -13
  67. package/dist/components/Elemental.js +0 -23
  68. package/dist/components/KVP.d.ts +0 -11
  69. package/dist/components/KVP.js +0 -12
  70. package/dist/components/Request.d.ts +0 -23
  71. package/dist/components/Request.js +0 -17
  72. package/dist/components/Response.d.ts +0 -16
  73. package/dist/components/Response.js +0 -29
  74. package/dist/components/Router.d.ts +0 -4
  75. package/dist/components/Router.js +0 -60
  76. package/dist/components/SdkResponse.d.ts +0 -9
  77. package/dist/components/SdkResponse.js +0 -21
  78. package/dist/components/Spinner.d.ts +0 -6
  79. package/dist/components/Spinner.js +0 -41
  80. package/dist/components/Table.d.ts +0 -19
  81. package/dist/components/Table.js +0 -62
  82. package/dist/components/UhOh.d.ts +0 -5
  83. package/dist/components/UhOh.js +0 -10
  84. package/dist/components/Version.d.ts +0 -3
  85. package/dist/components/Version.js +0 -53
  86. package/dist/constants.d.ts +0 -8
  87. package/dist/constants.js +0 -8
  88. package/dist/lib/api.d.ts +0 -17
  89. package/dist/lib/api.js +0 -39
  90. package/dist/lib/args.d.ts +0 -2
  91. package/dist/lib/args.js +0 -13
  92. package/dist/lib/courier.d.ts +0 -3
  93. package/dist/lib/courier.js +0 -7
  94. package/dist/lib/delay.d.ts +0 -2
  95. package/dist/lib/delay.js +0 -7
  96. package/dist/lib/load-env.d.ts +0 -2
  97. package/dist/lib/load-env.js +0 -16
  98. package/dist/lib/uuid.d.ts +0 -2
  99. package/dist/lib/uuid.js +0 -4
  100. package/dist/mappings.d.ts +0 -6
  101. package/dist/mappings.js +0 -565
  102. package/dist/version.d.ts +0 -2
  103. package/dist/version.js +0 -2
@@ -1,215 +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 = true;
32
- useEffect(() => {
33
- if (filetype) {
34
- getData();
35
- }
36
- else {
37
- setError('File type not supported.');
38
- }
39
- }, []);
40
- useEffect(() => {
41
- if (data) {
42
- processData();
43
- }
44
- }, [data]);
45
- useEffect(() => {
46
- if (!processing.value) {
47
- handleErrors();
48
- }
49
- }, [processing.value]);
50
- const getData = () => {
51
- db.all(sql, (err, result) => {
52
- if (err) {
53
- setError(err.message);
54
- }
55
- else {
56
- setData(result);
57
- }
58
- });
59
- };
60
- const processChunkRows = (data, start_index) => {
61
- return data.map((row, i) => {
62
- const curr_index = start_index + i;
63
- let { user_id, token, provider_key, device, tracking, expiry_date, ...properties } = row || {};
64
- if (!device)
65
- device = {};
66
- if (!tracking)
67
- tracking = {};
68
- if (!properties)
69
- properties = {};
70
- if (!user_id) {
71
- return Promise.resolve({
72
- success: false,
73
- userId: '__unknown__',
74
- error: `user_id not found in index ${curr_index}`,
75
- index: curr_index,
76
- });
77
- }
78
- else if (!provider_key) {
79
- return Promise.resolve({
80
- success: false,
81
- userId: user_id,
82
- error: `provider_key not found in index ${curr_index}`,
83
- index: curr_index,
84
- });
85
- }
86
- else if (!token) {
87
- return Promise.resolve({
88
- success: false,
89
- userId: user_id,
90
- error: `token not found in index ${curr_index}`,
91
- index: curr_index,
92
- });
93
- }
94
- else {
95
- Object.entries(properties).forEach(([key, value]) => {
96
- if (key.startsWith('device.')) {
97
- _.unset(properties, key);
98
- _.set(device, key.replace('device.', ''), value);
99
- }
100
- else if (key.startsWith('tracking.')) {
101
- _.unset(properties, key);
102
- _.set(tracking, key.replace('tracking.', ''), value);
103
- }
104
- else {
105
- _.unset(properties, key);
106
- _.set(properties, key.replace('properties.', ''), value);
107
- }
108
- });
109
- return processRow({
110
- user_id: String(user_id),
111
- token: token,
112
- provider_key,
113
- device,
114
- tracking,
115
- expiry_date,
116
- properties,
117
- index: curr_index,
118
- });
119
- }
120
- });
121
- };
122
- const processRow = async ({ user_id, token, index, ...body }) => {
123
- return new Promise(async (resolve) => {
124
- let promises = [];
125
- try {
126
- promises.push(courier.users.tokens.add(user_id, token, body, {
127
- maxRetries: 5,
128
- timeoutInSeconds: DEFAULT_TIMEOUT,
129
- }));
130
- await Promise.all(promises);
131
- counter.increment();
132
- return resolve({ userId: user_id, success: true, index });
133
- }
134
- catch (error) {
135
- counter.increment();
136
- return resolve({
137
- userId: user_id,
138
- success: false,
139
- index,
140
- error: (String(error) ??
141
- error?.message ??
142
- error.message ??
143
- 'Unknown Error') + `+ ${user_id}`,
144
- });
145
- }
146
- });
147
- };
148
- const processData = async () => {
149
- if (data?.length) {
150
- let data_copy = [...data];
151
- let counter = 0;
152
- let { rows, data: rest } = getChunk(data_copy, chunk_size);
153
- while (rows?.length) {
154
- const chunk = processChunkRows(rows, counter);
155
- const processed_chunks = await Promise.all(chunk);
156
- const errors = processed_chunks.filter(r => !r.success);
157
- if (errors.length) {
158
- setDataErrors(p => [
159
- ...p,
160
- ...errors.map(r => {
161
- return `user_id (${r.userId}) failed to update in index ${r.index}: ${String(r.error)}`;
162
- }),
163
- ]);
164
- setRowErrors(r => [
165
- ...r,
166
- ...errors.map(e => data[e.index]),
167
- ]);
168
- }
169
- if (rest.length > 0) {
170
- await delay(delay_between_chunks);
171
- counter += rows.length;
172
- const next = getChunk(rest, chunk_size);
173
- rows = next.rows;
174
- rest = next.data;
175
- }
176
- else {
177
- processing.setFalse();
178
- break;
179
- }
180
- }
181
- }
182
- };
183
- const handleErrors = async () => {
184
- if (row_errors.length && log_errors) {
185
- await fs.writeFile(DEFAULT_ERROR_FILENAME, JSON.stringify(row_errors, null, 2), {
186
- encoding: 'utf-8',
187
- });
188
- running.setFalse();
189
- }
190
- else {
191
- running.setFalse();
192
- }
193
- };
194
- if (!filename?.length) {
195
- return React.createElement(UhOh, { text: "You must specify a filename." });
196
- }
197
- else if (error?.length) {
198
- return React.createElement(UhOh, { text: error });
199
- }
200
- else if (data && running.value) {
201
- return (React.createElement(React.Fragment, null,
202
- React.createElement(ProgressBar, { value: Math.floor((counter.count / data.length) * 100) }),
203
- React.createElement(Spinner, { text: `Completed Rows: ${counter.count} / ${data.length}` })));
204
- }
205
- else {
206
- return (React.createElement(Box, { flexDirection: "column", marginY: 1 },
207
- React.createElement(Text, { color: 'green' }, `Completed Rows: ${counter.count} / ${data?.length || 0}`),
208
- data_errors.map((err, i) => {
209
- return React.createElement(UhOh, { key: i, text: err });
210
- }),
211
- log_errors && data_errors.length ? (React.createElement(Text, null,
212
- "Errors output to ",
213
- DEFAULT_ERROR_FILENAME)) : (React.createElement(React.Fragment, null))));
214
- }
215
- };
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const _default: () => React.JSX.Element;
3
- export default _default;
@@ -1,27 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { Box } from 'ink';
3
- import KVP from '../components/KVP.js';
4
- import Request from '../components/Request.js';
5
- import Response from '../components/Response.js';
6
- import api from '../lib/api.js';
7
- import { useCliContext } from '../components/Context.js';
8
- // import constants from '../constants.js';
9
- export default () => {
10
- const { apikey, url } = useCliContext();
11
- const [resp, setResp] = useState();
12
- const request = {
13
- url: '/debug',
14
- method: 'POST',
15
- };
16
- useEffect(() => {
17
- api(request, url, apikey).then(res => setResp(res));
18
- }, []);
19
- return (React.createElement(Box, { flexDirection: "column", width: "100%" },
20
- React.createElement(Request, { request: request, response: resp }),
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
- };
@@ -1,55 +0,0 @@
1
- import { CourierClient } from '@trycourier/courier';
2
- import { IssueTokenResponse } from '@trycourier/courier/api/index.js';
3
- import React from 'react';
4
- import yargsParser from 'yargs-parser';
5
- export type TEnvironment = 'test' | 'production';
6
- export type TAPIRouting = 'normal' | 'simulated';
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>;
12
- interface ICliContextProvider {
13
- args: string[];
14
- mappings: Map<string, IMapping>;
15
- current?: string;
16
- latest?: string;
17
- children: JSX.Element[] | JSX.Element;
18
- }
19
- interface ICliContext {
20
- map?: string;
21
- env_var: string;
22
- apikey?: string;
23
- environment: TEnvironment;
24
- routing: TAPIRouting;
25
- document_scope: TDocumentScope;
26
- mappings: Map<string, IMapping>;
27
- mapping?: IMapping;
28
- parsedParams: yargsParser.Arguments;
29
- args: string[];
30
- url: string;
31
- courier: CourierClient;
32
- version: {
33
- current?: string;
34
- latest?: string;
35
- };
36
- setVersion: React.Dispatch<React.SetStateAction<{
37
- current: string;
38
- latest?: string;
39
- }>>;
40
- getJWT: TGetJWT;
41
- }
42
- type IUseCliContext = () => ICliContext;
43
- export declare const useCliContext: IUseCliContext;
44
- export declare const CliContextProvider: ({ args, mappings, children, }: ICliContextProvider) => React.JSX.Element;
45
- export declare const getApiKeyFlags: ({ environment, routing, document_scope, }: {
46
- environment: TEnvironment;
47
- routing: TAPIRouting;
48
- document_scope: TDocumentScope;
49
- }) => string;
50
- export declare const getApiKeyVariable: ({ environment, routing, document_scope, }: {
51
- environment: TEnvironment;
52
- routing: TAPIRouting;
53
- document_scope: TDocumentScope;
54
- }) => string;
55
- export {};
@@ -1,94 +0,0 @@
1
- import { CourierClient } from '@trycourier/courier';
2
- import React, { createContext, useContext, useState } from 'react';
3
- import yargsParser from 'yargs-parser';
4
- import VERSION from '../version.js';
5
- const CliContext = createContext({});
6
- const PREFIX = 'COURIER_AUTH_TOKEN';
7
- export const useCliContext = () => useContext(CliContext);
8
- export const CliContextProvider = ({ args, mappings, children, }) => {
9
- const [version, setVersion] = useState({
10
- current: VERSION,
11
- });
12
- const [map, ...params] = args;
13
- const mapping = mappings.get(map || '');
14
- const parsedParams = yargsParser(params);
15
- const environment = parsedParams['production'] || parsedParams['P'] ? 'production' : 'test';
16
- const routing = parsedParams['mock'] || parsedParams['M'] ? 'simulated' : 'normal';
17
- let document_scope = 'Published';
18
- if (parsedParams['draft'] || parsedParams['D']) {
19
- document_scope = 'Draft';
20
- }
21
- else if (parsedParams['submitted'] || parsedParams['S']) {
22
- document_scope = 'Submitted';
23
- }
24
- const env_var = getApiKeyVariable({ environment, routing, document_scope });
25
- const apikey = parsedParams['apikey'] ?? process.env[env_var];
26
- const url = parsedParams['apiurl'] ??
27
- process.env['COURIER_API_URL'] ??
28
- 'https://api.courier.com';
29
- const courier = new CourierClient({
30
- authorizationToken: apikey,
31
- environment: url,
32
- });
33
- const getJWT = async (user_id, additional_scopes, options) => {
34
- const { write_brands = [], expires_in = '5 min' } = options || {};
35
- let scopes = [`user_id:${user_id}`, ...additional_scopes];
36
- if (write_brands.length) {
37
- write_brands.forEach(brand => {
38
- scopes.push(`write:brands:${brand}`);
39
- });
40
- }
41
- const token = await courier.authTokens.issueToken({
42
- scope: scopes.join(' '),
43
- expires_in,
44
- });
45
- return token;
46
- };
47
- const context = {
48
- apikey,
49
- mappings,
50
- mapping,
51
- parsedParams,
52
- args,
53
- environment,
54
- routing,
55
- document_scope,
56
- env_var,
57
- courier,
58
- url,
59
- map,
60
- getJWT,
61
- version,
62
- setVersion,
63
- };
64
- return React.createElement(CliContext.Provider, { value: context }, children);
65
- };
66
- export const getApiKeyFlags = ({ environment, routing, document_scope, }) => {
67
- let extra_flags = [];
68
- if (environment === 'production') {
69
- extra_flags.push('-P');
70
- }
71
- if (routing === 'simulated') {
72
- extra_flags.push('-M');
73
- }
74
- if (document_scope === 'Draft') {
75
- extra_flags.push('-D');
76
- }
77
- else if (document_scope === 'Submitted') {
78
- extra_flags.push('-S');
79
- }
80
- return extra_flags.join(' ');
81
- };
82
- export const getApiKeyVariable = ({ environment, routing, document_scope, }) => {
83
- let var_name = [PREFIX];
84
- if (environment === 'test') {
85
- var_name.push('TEST');
86
- }
87
- if (routing === 'simulated') {
88
- var_name.push('MOCK');
89
- }
90
- if (document_scope !== 'Published') {
91
- var_name.push(document_scope.toUpperCase());
92
- }
93
- return var_name.join('_').toUpperCase();
94
- };
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- interface IElement {
3
- type: string;
4
- }
5
- interface IElemental {
6
- version: string;
7
- elements: IElement[];
8
- }
9
- type Props = {
10
- elemental: IElemental;
11
- };
12
- declare const _default: ({ elemental }: Props) => React.JSX.Element;
13
- export default _default;
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import { Box, Text } from 'ink';
3
- export default ({ elemental }) => {
4
- const buckets = [];
5
- elemental.elements.map(element => {
6
- const { type, ...rest } = element;
7
- buckets.push({
8
- type: element.type,
9
- properties: Object.keys(rest).map(key => ({
10
- name: key,
11
- value: rest[key],
12
- })),
13
- });
14
- });
15
- return (React.createElement(Box, { flexDirection: "column" }, buckets.map(bucket => bucket.properties.map(property => (React.createElement(Box, null,
16
- React.createElement(Box, { width: 16, paddingTop: 1 },
17
- React.createElement(Text, null,
18
- bucket.type,
19
- ".",
20
- property.name)),
21
- React.createElement(Box, { borderStyle: "round", flexDirection: "column", paddingX: 1 },
22
- React.createElement(Text, null, property.value))))))));
23
- };
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- type Props = {
3
- label?: string;
4
- value?: string;
5
- width?: number;
6
- indent?: string;
7
- labelColor?: string;
8
- labelBold?: boolean;
9
- };
10
- declare const _default: ({ label, labelColor, labelBold, value, width, indent, }: Props) => React.JSX.Element;
11
- export default _default;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { Box, Spacer, Text } from 'ink';
3
- export default ({ label, labelColor, labelBold, value, width, indent, }) => {
4
- return (React.createElement(Box, { flexDirection: "column" },
5
- React.createElement(Box, { width: width || '100%', flexDirection: "row" },
6
- React.createElement(Text, null, indent),
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))));
12
- };
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- interface IRequest {
3
- url: string;
4
- method: string;
5
- body?: object | string;
6
- }
7
- interface IResponse {
8
- res: IHttpResponse;
9
- json?: any;
10
- err?: Error;
11
- }
12
- interface IHttpResponse {
13
- status: number;
14
- statusText: string;
15
- headers?: Headers;
16
- }
17
- type Props = {
18
- request: IRequest;
19
- response?: IResponse;
20
- spinnerText?: string;
21
- };
22
- declare const _default: (props: Props) => React.JSX.Element;
23
- export default _default;
@@ -1,17 +0,0 @@
1
- import React from 'react';
2
- import { Box, Text } from 'ink';
3
- import Spinner from './Spinner.js';
4
- const defaultSpinnerText = 'blipping those bits and blooping those bytes';
5
- export default (props) => {
6
- const url = `${process.env['COURIER_DOMAIN'] || 'https://api.courier.com'}${props.request.url}`;
7
- return (React.createElement(Box, { flexDirection: "column" },
8
- React.createElement(Box, { borderStyle: "bold", borderColor: "blue" },
9
- React.createElement(Text, null,
10
- ' ',
11
- React.createElement(Text, { bold: true }, props.request.method),
12
- " ",
13
- url)),
14
- props.request.body ? (typeof props.request.body === 'string' ? (React.createElement(Text, null, props.request.body)) : (React.createElement(Text, null, JSON.stringify(props.request.body, undefined, ' ')))) : null,
15
- !props.request.body ? React.createElement(Text, { color: "gray" }, "No request body") : null,
16
- !props.response ? (React.createElement(Spinner, { text: props.spinnerText || defaultSpinnerText })) : null));
17
- };
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- interface IResponse {
3
- res: IHttpResponse;
4
- json?: any;
5
- err?: Error;
6
- }
7
- interface IHttpResponse {
8
- status: number;
9
- statusText: string;
10
- headers?: Headers;
11
- }
12
- type Props = {
13
- response?: IResponse;
14
- };
15
- declare const _default: (props: Props) => React.JSX.Element | null;
16
- export default _default;
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import { Box, Text } from 'ink';
3
- function getContentType(res) {
4
- return res.res.headers?.get('content-type') || 'none';
5
- }
6
- export default (props) => {
7
- if (!props.response)
8
- return null;
9
- return (React.createElement(Box, { flexDirection: "column" },
10
- React.createElement(Box, { flexDirection: "column", borderStyle: "bold", borderColor: props.response?.err ? 'red' : 'green' },
11
- React.createElement(Text, null,
12
- ' ',
13
- "HTTP",
14
- ' ',
15
- React.createElement(Text, { bold: true }, props.response.err
16
- ? props.response.err.message
17
- : props.response?.res?.status),
18
- ' ',
19
- !props.response.err ? (React.createElement(React.Fragment, null,
20
- React.createElement(Text, null,
21
- "\u2022 ",
22
- props.response.res.statusText))) : null),
23
- !props.response.err &&
24
- getContentType(props.response) !== 'application/json' ? (React.createElement(Box, null,
25
- React.createElement(Text, null,
26
- " Content-Type: ",
27
- getContentType(props.response)))) : null),
28
- props.response.json ? (React.createElement(Text, null, JSON.stringify(props.response.json, undefined, ' '))) : (React.createElement(Text, { color: "gray" }, "No response body"))));
29
- };
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- type Props = {};
3
- declare const _default: ({}: Props) => React.JSX.Element;
4
- export default _default;
@@ -1,60 +0,0 @@
1
- import { Text } from 'ink';
2
- import React from 'react';
3
- import Help from '../commands/Help.js';
4
- import { getApiKeyFlags, useCliContext } from './Context.js';
5
- import VERSION from '../version.js';
6
- export default ({}) => {
7
- const { args, mapping, parsedParams, mappings, apikey, env_var, environment, routing, document_scope, map, } = useCliContext();
8
- if (args.filter(a => ['--version', '-V'].includes(a)).length) {
9
- return React.createElement(Text, null,
10
- "courier v",
11
- VERSION);
12
- }
13
- else if (!args.length || !args[0]) {
14
- return React.createElement(Help, { mappings: mappings });
15
- }
16
- else {
17
- if (mapping) {
18
- if (parsedParams['help']) {
19
- return React.createElement(Help, { mappings: new Map([[map, mapping]]) });
20
- }
21
- else if ((apikey && apikey.length) || mapping.noApiKeyRequired) {
22
- return mapping.component(parsedParams);
23
- }
24
- else {
25
- const extra_flags = getApiKeyFlags({
26
- environment,
27
- routing,
28
- document_scope,
29
- });
30
- return (React.createElement(React.Fragment, null,
31
- React.createElement(Text, { bold: true, color: "red" },
32
- "No ",
33
- env_var,
34
- " specified, please set via one of these options:"),
35
- React.createElement(Text, { bold: true, color: "red" },
36
- "\u2022 running \"courier config --apikey <your-api-key>",
37
- ' ',
38
- extra_flags,
39
- "\""),
40
- React.createElement(Text, { bold: true, color: "red" },
41
- "\u2022 setting ",
42
- env_var,
43
- " in your shell via \"export ",
44
- env_var,
45
- "=<your-api-key>\""),
46
- React.createElement(Text, { bold: true, color: "red" },
47
- "\u2022 setting ",
48
- env_var,
49
- " in a \".courier\" file in your current working directory"),
50
- React.createElement(Text, { bold: true, color: "red" },
51
- "\u2022 setting ",
52
- env_var,
53
- " in a \".courier\" file in your user's home directory")));
54
- }
55
- }
56
- else {
57
- return React.createElement(Help, { mappings: mappings });
58
- }
59
- }
60
- };
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { CourierError } from '@trycourier/courier';
3
- type IProps<T> = {
4
- error?: CourierError;
5
- response?: T | string;
6
- content?: React.ReactNode;
7
- };
8
- declare const SdkResponse: <T extends object>({ error, response, content, }: IProps<T>) => React.JSX.Element;
9
- export default SdkResponse;
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import { Box, Text } from 'ink';
3
- const Spacing = () => React.createElement(Text, null, " ");
4
- const SdkResponse = ({ error, response, content, }) => {
5
- const status_code = error ? error.statusCode : '200';
6
- const response_text = typeof response === 'string' ? response : JSON.stringify(response, null, 2);
7
- return (React.createElement(Box, { flexDirection: "column" },
8
- React.createElement(Box, { flexDirection: "column", borderStyle: "bold", borderColor: error ? 'red' : 'green' }, content ? (content) : (React.createElement(React.Fragment, null,
9
- React.createElement(Text, null,
10
- React.createElement(Spacing, null),
11
- "HTTP",
12
- React.createElement(Spacing, null),
13
- React.createElement(Text, { bold: true }, status_code)),
14
- error?.message?.length && (React.createElement(React.Fragment, null,
15
- React.createElement(Text, { color: 'red' }, error.message),
16
- React.createElement(Text, null, error.stack))),
17
- response && Object.keys(response).length > 0 ? (React.createElement(React.Fragment, null,
18
- React.createElement(Text, null, response_text))) : (React.createElement(React.Fragment, null,
19
- React.createElement(Text, { color: "grey" }, "No response body"))))))));
20
- };
21
- export default SdkResponse;
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- type Props = {
3
- text?: string;
4
- };
5
- declare const _default: ({ text }: Props) => React.JSX.Element;
6
- export default _default;