@prismatic-io/prism 4.1.1 → 4.2.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/lib/commands/alerts/events/list.js +4 -1
- package/lib/commands/alerts/groups/list.js +23 -10
- package/lib/commands/alerts/monitors/list.js +41 -11
- package/lib/commands/alerts/webhooks/list.js +26 -13
- package/lib/commands/components/actions/list.js +60 -19
- package/lib/commands/components/dev/run.js +19 -5
- package/lib/commands/components/dev/test.js +1 -1
- package/lib/commands/components/init/index.js +39 -100
- package/lib/commands/components/list.js +42 -19
- package/lib/commands/components/triggers/list.js +61 -20
- package/lib/commands/customers/list.js +29 -11
- package/lib/commands/customers/users/list.js +34 -15
- package/lib/commands/instances/config-vars/list.js +44 -19
- package/lib/commands/instances/flow-configs/list.js +29 -16
- package/lib/commands/instances/list.js +45 -21
- package/lib/commands/integrations/flows/list.js +29 -16
- package/lib/commands/integrations/list.js +32 -15
- package/lib/commands/organization/users/list.js +37 -12
- package/lib/generate/action.js +14 -66
- package/lib/generate/index.js +3 -9
- package/lib/generate/parse.js +8 -60
- package/lib/generate/sourceFile.js +7 -40
- package/lib/generate/util.js +1 -105
- package/lib/yeoman.js +1 -0
- package/oclif.manifest.json +1 -1
- package/package.json +5 -7
- package/lib/generate/client.js +0 -93
- package/lib/generate/connection.js +0 -77
- package/templates/component/assets/icon.png +0 -0
- package/templates/component/openapi/client.ts +0 -75
- package/templates/component/openapi/request.ts +0 -163
package/lib/generate/client.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.generateClient = void 0;
|
|
27
|
-
const ts_morph_1 = require("ts-morph");
|
|
28
|
-
const fs_1 = require("fs");
|
|
29
|
-
const path = __importStar(require("path"));
|
|
30
|
-
const generateClient = async (project) => {
|
|
31
|
-
const { clientFile } = project;
|
|
32
|
-
if (clientFile === undefined) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
clientFile.addImportDeclarations([
|
|
36
|
-
{
|
|
37
|
-
moduleSpecifier: `../${project.definitionDirectory}/core/OpenAPI`,
|
|
38
|
-
namedImports: [{ name: "EnhancedOpenAPI" }],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
moduleSpecifier: "@prismatic-io/spectral",
|
|
42
|
-
namedImports: [
|
|
43
|
-
{ name: "util" },
|
|
44
|
-
{ name: "Connection" },
|
|
45
|
-
{ name: "ConnectionError" },
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
moduleSpecifier: "axios",
|
|
50
|
-
defaultImport: "Axios",
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
moduleSpecifier: "axios-retry",
|
|
54
|
-
defaultImport: "axiosRetry",
|
|
55
|
-
namedImports: [
|
|
56
|
-
{ name: "IAxiosRetryConfig" },
|
|
57
|
-
{ name: "exponentialDelay" },
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
]);
|
|
61
|
-
clientFile.addInterface({
|
|
62
|
-
name: "InitializeClientProps",
|
|
63
|
-
properties: [
|
|
64
|
-
{ name: "connection", type: "Connection", hasQuestionToken: true },
|
|
65
|
-
{ name: "apiBaseUrl", type: "unknown", hasQuestionToken: true },
|
|
66
|
-
{ name: "debugRequest", type: "unknown", hasQuestionToken: true },
|
|
67
|
-
{ name: "maxRetries", type: "unknown", hasQuestionToken: true },
|
|
68
|
-
{ name: "retryDelayMS", type: "unknown", hasQuestionToken: true },
|
|
69
|
-
{ name: "retryOnAllErrors", type: "unknown", hasQuestionToken: true },
|
|
70
|
-
{ name: "timeout", type: "unknown", hasQuestionToken: true },
|
|
71
|
-
{
|
|
72
|
-
name: "useExponentialBackoff",
|
|
73
|
-
type: "unknown",
|
|
74
|
-
hasQuestionToken: true,
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
});
|
|
78
|
-
clientFile.addVariableStatements([
|
|
79
|
-
{
|
|
80
|
-
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
81
|
-
declarations: [
|
|
82
|
-
{
|
|
83
|
-
name: "initializeClient",
|
|
84
|
-
initializer: String(await fs_1.promises.readFile(path.resolve(__dirname, "..", "..", "templates", "component", "openapi", "client.ts"))),
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
isExported: true,
|
|
88
|
-
},
|
|
89
|
-
]);
|
|
90
|
-
clientFile.formatText();
|
|
91
|
-
await clientFile.save();
|
|
92
|
-
};
|
|
93
|
-
exports.generateClient = generateClient;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateConnections = void 0;
|
|
4
|
-
const ts_morph_1 = require("ts-morph");
|
|
5
|
-
const generateConnections = async (project) => {
|
|
6
|
-
const { connectionsFile } = project;
|
|
7
|
-
if (connectionsFile === undefined) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
connectionsFile.addImportDeclarations([
|
|
11
|
-
{
|
|
12
|
-
moduleSpecifier: "@prismatic-io/spectral",
|
|
13
|
-
namedImports: [{ name: "connection" }],
|
|
14
|
-
},
|
|
15
|
-
]);
|
|
16
|
-
const placeholder = connectionsFile.addVariableStatement({
|
|
17
|
-
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
18
|
-
declarations: [
|
|
19
|
-
{ name: "connectionPlaceholder", initializer: ts_morph_1.Writers.object({}) },
|
|
20
|
-
],
|
|
21
|
-
});
|
|
22
|
-
const object = placeholder
|
|
23
|
-
.getDeclarations()[0]
|
|
24
|
-
.getInitializer();
|
|
25
|
-
object.addPropertyAssignments([
|
|
26
|
-
{
|
|
27
|
-
name: "key",
|
|
28
|
-
initializer: `"basicAuth"`,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: "label",
|
|
32
|
-
initializer: `"Example Basic Auth"`,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: "comments",
|
|
36
|
-
initializer: `"Example Basic Auth comments"`,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "inputs",
|
|
40
|
-
initializer: `{
|
|
41
|
-
username: {
|
|
42
|
-
label: "Username",
|
|
43
|
-
placeholder: "Username",
|
|
44
|
-
type: "string",
|
|
45
|
-
required: true,
|
|
46
|
-
comments: "Username for auth",
|
|
47
|
-
},
|
|
48
|
-
password: {
|
|
49
|
-
label: "Password",
|
|
50
|
-
placeholder: "Password",
|
|
51
|
-
type: "password",
|
|
52
|
-
required: true,
|
|
53
|
-
comments: "Password for auth",
|
|
54
|
-
},
|
|
55
|
-
}`,
|
|
56
|
-
},
|
|
57
|
-
]);
|
|
58
|
-
connectionsFile.addVariableStatement({
|
|
59
|
-
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
60
|
-
declarations: [
|
|
61
|
-
{
|
|
62
|
-
name: "basicAuthConnection",
|
|
63
|
-
initializer: `connection(${object.print()})`,
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
isExported: true,
|
|
67
|
-
});
|
|
68
|
-
placeholder.remove();
|
|
69
|
-
connectionsFile.addExportAssignment({
|
|
70
|
-
isExportEquals: false,
|
|
71
|
-
expression: `[basicAuthConnection]`,
|
|
72
|
-
});
|
|
73
|
-
connectionsFile.organizeImports();
|
|
74
|
-
connectionsFile.formatText();
|
|
75
|
-
await connectionsFile.save();
|
|
76
|
-
};
|
|
77
|
-
exports.generateConnections = generateConnections;
|
|
Binary file
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
({
|
|
2
|
-
connection,
|
|
3
|
-
apiBaseUrl,
|
|
4
|
-
debugRequest,
|
|
5
|
-
maxRetries,
|
|
6
|
-
retryDelayMS,
|
|
7
|
-
retryOnAllErrors,
|
|
8
|
-
timeout,
|
|
9
|
-
useExponentialBackoff,
|
|
10
|
-
}: InitializeClientProps) => {
|
|
11
|
-
if (apiBaseUrl) {
|
|
12
|
-
EnhancedOpenAPI.BASE = util.types.toString(apiBaseUrl);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
EnhancedOpenAPI.timeout =
|
|
16
|
-
typeof timeout !== undefined ? util.types.toNumber(timeout) : undefined;
|
|
17
|
-
|
|
18
|
-
EnhancedOpenAPI.CLIENT = Axios.create();
|
|
19
|
-
|
|
20
|
-
if (maxRetries) {
|
|
21
|
-
const axiosRetryConfig: IAxiosRetryConfig = {
|
|
22
|
-
retries: util.types.toInt(maxRetries),
|
|
23
|
-
shouldResetTimeout: true,
|
|
24
|
-
};
|
|
25
|
-
if (retryDelayMS) {
|
|
26
|
-
// Use a specified delay.
|
|
27
|
-
axiosRetryConfig.retryDelay = () => {
|
|
28
|
-
return util.types.toInt(retryDelayMS);
|
|
29
|
-
};
|
|
30
|
-
} else if (
|
|
31
|
-
useExponentialBackoff &&
|
|
32
|
-
util.types.toBool(useExponentialBackoff)
|
|
33
|
-
) {
|
|
34
|
-
// Use a predefined exponential backoff.
|
|
35
|
-
|
|
36
|
-
axiosRetryConfig.retryDelay = exponentialDelay;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (retryOnAllErrors && util.types.toBool(retryOnAllErrors)) {
|
|
40
|
-
// Retry on all errors regardless of type or HTTP method.
|
|
41
|
-
axiosRetryConfig.retryCondition = () => {
|
|
42
|
-
return true;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
axiosRetry(EnhancedOpenAPI.CLIENT, axiosRetryConfig);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (util.types.toBool(debugRequest) === true) {
|
|
50
|
-
EnhancedOpenAPI.CLIENT.interceptors.request.use((request) => {
|
|
51
|
-
console.log(JSON.stringify(request));
|
|
52
|
-
return request;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
EnhancedOpenAPI.CLIENT.interceptors.response.use(
|
|
56
|
-
({ headers, status, statusText, config, data }) => {
|
|
57
|
-
console.log({ headers, status, statusText, config, data });
|
|
58
|
-
return { headers, status, statusText, config, data };
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (connection) {
|
|
64
|
-
const { key, fields } = connection;
|
|
65
|
-
if (key === "basicAuth") {
|
|
66
|
-
EnhancedOpenAPI.USERNAME = fields.username as string;
|
|
67
|
-
EnhancedOpenAPI.PASSWORD = fields.password as string;
|
|
68
|
-
} else {
|
|
69
|
-
throw new ConnectionError(
|
|
70
|
-
connection,
|
|
71
|
-
`Invalid connection type provided: ${key}`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
/* tslint:disable */
|
|
3
|
-
/* eslint-disable */
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import FormData from "form-data";
|
|
6
|
-
import { AxiosResponse } from "axios";
|
|
7
|
-
import { util } from "@prismatic-io/spectral";
|
|
8
|
-
import { types } from "util";
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
import type { ApiRequestOptions } from "./ApiRequestOptions";
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
import { EnhancedOpenAPI } from "./OpenAPI";
|
|
13
|
-
|
|
14
|
-
function isDefined<T>(
|
|
15
|
-
value: T | null | undefined
|
|
16
|
-
): value is Exclude<T, null | undefined> {
|
|
17
|
-
return value !== undefined && value !== null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function isString(value: any): value is string {
|
|
21
|
-
return typeof value === "string";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function isStringWithValue(value: any): value is string {
|
|
25
|
-
return isString(value) && value !== "";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function isBinary(value: any): value is Buffer | ArrayBuffer | ArrayBufferView {
|
|
29
|
-
const isBuffer = Buffer.isBuffer(value);
|
|
30
|
-
const isArrayBuffer = types.isArrayBuffer(value);
|
|
31
|
-
const isArrayBufferView = types.isArrayBufferView(value);
|
|
32
|
-
return isBuffer || isArrayBuffer || isArrayBufferView;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getUrl(options: ApiRequestOptions): string {
|
|
36
|
-
const path = options.path.replace(/[:]/g, "_");
|
|
37
|
-
const url = `${EnhancedOpenAPI.BASE}${path}`;
|
|
38
|
-
|
|
39
|
-
return url;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function getFormData(params: Record<string, any>): FormData {
|
|
43
|
-
const formData = new FormData();
|
|
44
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
45
|
-
if (isDefined(value)) {
|
|
46
|
-
formData.append(key, value);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return formData;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
|
|
53
|
-
|
|
54
|
-
async function resolve<T>(
|
|
55
|
-
options: ApiRequestOptions,
|
|
56
|
-
resolver?: T | Resolver<T>
|
|
57
|
-
): Promise<T | undefined> {
|
|
58
|
-
if (typeof resolver === "function") {
|
|
59
|
-
return (resolver as Resolver<T>)(options);
|
|
60
|
-
}
|
|
61
|
-
return resolver;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function getHeaders(options: ApiRequestOptions): Promise<any> {
|
|
65
|
-
const [token, username, password, defaultHeaders] = await Promise.all([
|
|
66
|
-
resolve(options, EnhancedOpenAPI.TOKEN),
|
|
67
|
-
resolve(options, EnhancedOpenAPI.USERNAME),
|
|
68
|
-
resolve(options, EnhancedOpenAPI.PASSWORD),
|
|
69
|
-
resolve(options, EnhancedOpenAPI.HEADERS),
|
|
70
|
-
]);
|
|
71
|
-
|
|
72
|
-
const headers: Record<string, string | number> = {
|
|
73
|
-
Accept: "application/json",
|
|
74
|
-
...defaultHeaders,
|
|
75
|
-
...options.headers,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if (EnhancedOpenAPI.timeout) {
|
|
79
|
-
headers["timeout"] = util.types.toInt(EnhancedOpenAPI.timeout);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (isStringWithValue(token)) {
|
|
83
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
87
|
-
const credentials = Buffer.from(`${username}:${password}`).toString(
|
|
88
|
-
"base64"
|
|
89
|
-
);
|
|
90
|
-
headers["Authorization"] = `Basic ${credentials}`;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (options.body) {
|
|
94
|
-
if (isBinary(options.body)) {
|
|
95
|
-
headers["Content-Type"] = "application/octet-stream";
|
|
96
|
-
} else if (isString(options.body)) {
|
|
97
|
-
headers["Content-Type"], "text/plain";
|
|
98
|
-
} else {
|
|
99
|
-
headers["Content-Type"] = "application/json";
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return headers;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function getRequestBody(options: ApiRequestOptions) {
|
|
107
|
-
if (options.formData) {
|
|
108
|
-
return getFormData(options.formData);
|
|
109
|
-
}
|
|
110
|
-
if (options.body) {
|
|
111
|
-
if (isString(options.body) || isBinary(options.body)) {
|
|
112
|
-
return options.body;
|
|
113
|
-
} else {
|
|
114
|
-
return JSON.stringify(options.body);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
interface RequestProps {
|
|
120
|
-
options: ApiRequestOptions;
|
|
121
|
-
url: string;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async function sendRequest({
|
|
125
|
-
options,
|
|
126
|
-
url,
|
|
127
|
-
}: RequestProps): Promise<Partial<AxiosResponse>> {
|
|
128
|
-
if (!EnhancedOpenAPI.CLIENT) {
|
|
129
|
-
throw new Error("Client was not initialized.");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const result = await EnhancedOpenAPI.CLIENT.request({
|
|
133
|
-
url,
|
|
134
|
-
method: options.method,
|
|
135
|
-
headers: await getHeaders(options),
|
|
136
|
-
data: getRequestBody(options),
|
|
137
|
-
params: options.query ? { ...options.query } : undefined,
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Request using Axios client
|
|
145
|
-
* @param options The request options from the the service
|
|
146
|
-
* @returns Partial<AxiosResponse> & {
|
|
147
|
-
body: AxiosResponse["data"];
|
|
148
|
-
}
|
|
149
|
-
*/
|
|
150
|
-
export async function request(options: ApiRequestOptions): Promise<
|
|
151
|
-
Partial<AxiosResponse> & {
|
|
152
|
-
body: AxiosResponse["data"];
|
|
153
|
-
}
|
|
154
|
-
> {
|
|
155
|
-
const url = getUrl(options);
|
|
156
|
-
|
|
157
|
-
const response = await sendRequest({
|
|
158
|
-
options,
|
|
159
|
-
url,
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
return { ...response, body: await response.data };
|
|
163
|
-
}
|