@trycourier/cli 2.7.1 → 3.1.4
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/bin/.gitkeep +0 -0
- package/install.js +115 -0
- package/package.json +22 -87
- package/LICENSE +0 -21
- package/README.md +0 -105
- 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 -78
- 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 -559
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -2
package/dist/commands/WhoAmI.js
DELETED
|
@@ -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
|
-
};
|
package/dist/components/KVP.d.ts
DELETED
|
@@ -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;
|
package/dist/components/KVP.js
DELETED
|
@@ -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,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,41 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import { Box, Text } from 'ink';
|
|
3
|
-
import spinners from 'cli-spinners';
|
|
4
|
-
import constants from '../constants.js';
|
|
5
|
-
/*
|
|
6
|
-
some of my favorites:
|
|
7
|
-
- spinners.dots
|
|
8
|
-
- spinners.triangle
|
|
9
|
-
- spinners.binary
|
|
10
|
-
- spinners.arc
|
|
11
|
-
- spinners.arrow
|
|
12
|
-
- spinners.bouncingBar
|
|
13
|
-
- spinners.pong
|
|
14
|
-
- spinners.aesthetic
|
|
15
|
-
*/
|
|
16
|
-
const spinner = spinners.aesthetic;
|
|
17
|
-
const spinnerColor = constants.colors.primary;
|
|
18
|
-
const textColor = 'white';
|
|
19
|
-
export default ({ text }) => {
|
|
20
|
-
const [index, setIndex] = useState(0);
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const timer = setInterval(() => {
|
|
23
|
-
setIndex(i => {
|
|
24
|
-
if (i + 1 >= spinner.frames.length) {
|
|
25
|
-
return 0;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return i + 1;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}, spinner.interval);
|
|
32
|
-
return () => {
|
|
33
|
-
clearInterval(timer);
|
|
34
|
-
};
|
|
35
|
-
}, []);
|
|
36
|
-
return (React.createElement(Box, { borderStyle: "classic", borderColor: "gray" },
|
|
37
|
-
React.createElement(Text, { bold: true, color: spinnerColor }, spinner.frames[index]),
|
|
38
|
-
text?.length ? React.createElement(Text, { color: textColor },
|
|
39
|
-
" ",
|
|
40
|
-
text) : React.createElement(React.Fragment, null)));
|
|
41
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { TextProps } from 'ink';
|
|
3
|
-
type Scalar = string | number | boolean | null | undefined;
|
|
4
|
-
type ScalarDict = {
|
|
5
|
-
[key: string]: Scalar;
|
|
6
|
-
};
|
|
7
|
-
type TableProps = {
|
|
8
|
-
data: ScalarDict[];
|
|
9
|
-
showHeaders?: boolean;
|
|
10
|
-
headerLabels?: {
|
|
11
|
-
[key: string]: string;
|
|
12
|
-
};
|
|
13
|
-
disableRowSeparators?: boolean;
|
|
14
|
-
disableBorders?: boolean;
|
|
15
|
-
headerStyles?: TextProps;
|
|
16
|
-
rowStyles?: TextProps;
|
|
17
|
-
};
|
|
18
|
-
declare const Table: ({ data, disableBorders, disableRowSeparators, headerStyles, headerLabels, rowStyles, showHeaders, }: TableProps) => React.JSX.Element;
|
|
19
|
-
export default Table;
|
package/dist/components/Table.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// Table.tsx
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { Box, Text } from 'ink';
|
|
4
|
-
const Table = ({ data, disableBorders, disableRowSeparators, headerStyles, headerLabels, rowStyles, showHeaders = true, }) => {
|
|
5
|
-
// Determine columns and their widths
|
|
6
|
-
const columns = getColumns(data, headerLabels);
|
|
7
|
-
return (React.createElement(Box, { flexDirection: "column", width: "100%" },
|
|
8
|
-
!disableBorders && renderHeaderSeparators(columns),
|
|
9
|
-
showHeaders && (React.createElement(React.Fragment, null,
|
|
10
|
-
renderRow(columns.reduce((p, v) => {
|
|
11
|
-
p[v.key] = v.label || v.key;
|
|
12
|
-
return p;
|
|
13
|
-
}, {}), columns, disableBorders, {
|
|
14
|
-
color: 'blue',
|
|
15
|
-
bold: true,
|
|
16
|
-
...headerStyles,
|
|
17
|
-
}),
|
|
18
|
-
!disableRowSeparators ? renderRowSeparators(columns) : null)),
|
|
19
|
-
data.map((row, index) => (React.createElement(React.Fragment, { key: `row-${index}` },
|
|
20
|
-
index !== 0 && !disableRowSeparators && renderRowSeparators(columns),
|
|
21
|
-
renderRow(row, columns, disableBorders, rowStyles)))),
|
|
22
|
-
!disableBorders && renderFooterSeparators(columns)));
|
|
23
|
-
};
|
|
24
|
-
// Helper function to determine columns and their widths
|
|
25
|
-
function getColumns(data, headerLabels) {
|
|
26
|
-
let columnWidths = {};
|
|
27
|
-
data.forEach(row => {
|
|
28
|
-
Object.keys(row).forEach(key => {
|
|
29
|
-
const valueLength = row[key]?.toString().length || 0;
|
|
30
|
-
columnWidths[key] = Math.max(columnWidths[key] || key.length, valueLength);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
return Object.keys(columnWidths).map(key => ({
|
|
34
|
-
key: key,
|
|
35
|
-
label: headerLabels?.[key] || key,
|
|
36
|
-
width: (columnWidths[key] ?? 0) + 2, // adding padding
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
// Helper function to render a row with separators
|
|
40
|
-
function renderRow(row, columns, disableBorders, textStyles) {
|
|
41
|
-
return (React.createElement(Box, { flexDirection: "row" },
|
|
42
|
-
!disableBorders && React.createElement(Text, null, "\u2502"),
|
|
43
|
-
columns.map((column, index) => (React.createElement(React.Fragment, { key: column.key },
|
|
44
|
-
index !== 0 && !disableBorders && React.createElement(Text, null, "\u2502"),
|
|
45
|
-
React.createElement(Box, { width: column.width, justifyContent: "flex-start" },
|
|
46
|
-
React.createElement(Text, { ...textStyles }, row[column.key]?.toString() || ''))))),
|
|
47
|
-
!disableBorders && React.createElement(Text, null, "\u2502")));
|
|
48
|
-
}
|
|
49
|
-
function renderHeaderSeparators(columns) {
|
|
50
|
-
return renderRowSeparators(columns, '┌', '┬', '┐');
|
|
51
|
-
}
|
|
52
|
-
function renderFooterSeparators(columns) {
|
|
53
|
-
return renderRowSeparators(columns, '└', '┴', '┘');
|
|
54
|
-
}
|
|
55
|
-
function renderRowSeparators(columns, leftChar = '├', midChar = '┼', rightChar = '┤') {
|
|
56
|
-
return (React.createElement(Box, { flexDirection: "row" },
|
|
57
|
-
React.createElement(Text, null, leftChar),
|
|
58
|
-
columns.map((column, index) => (React.createElement(React.Fragment, { key: column.key },
|
|
59
|
-
React.createElement(Text, null, '─'.repeat(column.width)),
|
|
60
|
-
index < columns.length - 1 ? (React.createElement(Text, null, midChar)) : (React.createElement(Text, null, rightChar)))))));
|
|
61
|
-
}
|
|
62
|
-
export default Table;
|
package/dist/components/UhOh.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { execa } from 'execa';
|
|
2
|
-
import { Box, Text } from 'ink';
|
|
3
|
-
import _ from 'lodash';
|
|
4
|
-
import React, { useEffect } from 'react';
|
|
5
|
-
import { useCliContext } from './Context.js';
|
|
6
|
-
import constants from '../constants.js';
|
|
7
|
-
const Version = () => {
|
|
8
|
-
const { version, setVersion, map, parsedParams } = useCliContext();
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
getVersion();
|
|
11
|
-
}, []);
|
|
12
|
-
const getVersion = async () => {
|
|
13
|
-
try {
|
|
14
|
-
const exc = await execa('npm', ['-g', 'outdated', constants.package_name, '--json'], {
|
|
15
|
-
shell: true,
|
|
16
|
-
reject: false,
|
|
17
|
-
});
|
|
18
|
-
const stdout = JSON.parse(exc.stdout);
|
|
19
|
-
setVersion(v => ({
|
|
20
|
-
...v,
|
|
21
|
-
latest: _.get(stdout, [constants.package_name, 'latest']),
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.log(e);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const version_text = version.latest && version.current !== version.latest
|
|
29
|
-
? `Upgrade available (${version.current} > ${version.latest}), run courier upgrade`
|
|
30
|
-
: undefined;
|
|
31
|
-
if (version_text?.length) {
|
|
32
|
-
if (map === 'upgrade' || _.get(parsedParams, ['quiet'], false)) {
|
|
33
|
-
return React.createElement(React.Fragment, null);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return (React.createElement(Box, { flexDirection: "column", marginY: 1, flexShrink: 1, width: version_text.length + 2, borderColor: "gray", borderStyle: 'single' },
|
|
37
|
-
React.createElement(Text, null,
|
|
38
|
-
"Upgrade available (",
|
|
39
|
-
version.current,
|
|
40
|
-
" ",
|
|
41
|
-
'>',
|
|
42
|
-
" ",
|
|
43
|
-
version.latest,
|
|
44
|
-
"), run",
|
|
45
|
-
' ',
|
|
46
|
-
React.createElement(Text, { color: "green" }, "courier upgrade"))));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return React.createElement(React.Fragment, null);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
export default Version;
|
package/dist/constants.d.ts
DELETED