@prismatic-io/prism 3.0.5 → 3.1.0
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/README.md +9 -8
- package/lib/commands/alerts/events/list.js +8 -6
- package/lib/commands/alerts/events/list.js.map +1 -1
- package/lib/commands/alerts/groups/create.js +2 -0
- package/lib/commands/alerts/groups/create.js.map +1 -1
- package/lib/commands/alerts/monitors/create.js +11 -0
- package/lib/commands/alerts/monitors/create.js.map +1 -1
- package/lib/commands/alerts/webhooks/create.js +1 -0
- package/lib/commands/alerts/webhooks/create.js.map +1 -1
- package/lib/commands/components/actions/list.js +1 -1
- package/lib/commands/components/init.js +3 -2
- package/lib/commands/components/init.js.map +1 -1
- package/lib/commands/components/list.js +1 -0
- package/lib/commands/components/list.js.map +1 -1
- package/lib/commands/components/publish.js +13 -3
- package/lib/commands/components/publish.js.map +1 -1
- package/lib/commands/{instances/credentials → components/triggers}/list.js +24 -35
- package/lib/commands/components/triggers/list.js.map +1 -0
- package/lib/commands/customers/create.js +1 -0
- package/lib/commands/customers/create.js.map +1 -1
- package/lib/commands/customers/update.js +2 -0
- package/lib/commands/customers/update.js.map +1 -1
- package/lib/commands/customers/users/create.js +5 -1
- package/lib/commands/customers/users/create.js.map +1 -1
- package/lib/commands/customers/users/list.js +8 -6
- package/lib/commands/customers/users/list.js.map +1 -1
- package/lib/commands/customers/users/update.js +12 -2
- package/lib/commands/customers/users/update.js.map +1 -1
- package/lib/commands/instances/config-vars/list.js +8 -6
- package/lib/commands/instances/config-vars/list.js.map +1 -1
- package/lib/commands/instances/create.js +2 -0
- package/lib/commands/instances/create.js.map +1 -1
- package/lib/commands/instances/flow-configs/list.js +3 -1
- package/lib/commands/instances/flow-configs/list.js.map +1 -1
- package/lib/commands/instances/flow-configs/test.js +8 -1
- package/lib/commands/instances/flow-configs/test.js.map +1 -1
- package/lib/commands/integrations/export.js +1 -1
- package/lib/commands/integrations/flows/list.js +7 -1
- package/lib/commands/integrations/flows/list.js.map +1 -1
- package/lib/commands/integrations/flows/test.js +6 -1
- package/lib/commands/integrations/flows/test.js.map +1 -1
- package/lib/commands/organization/updateAvatarUrl.js +1 -0
- package/lib/commands/organization/updateAvatarUrl.js.map +1 -1
- package/lib/generate/auth.js +2 -2
- package/lib/generate/auth.js.map +1 -1
- package/lib/generate/util.js +3 -3
- package/lib/generate/util.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
- package/templates/component/openapi/auth.ts +98 -0
- package/templates/component/openapi/request.ts +161 -0
- package/templates/component/src/index.test.ts +16 -1
- package/templates/component/src/index.ts +2 -0
- package/templates/component/src/triggers.ts +18 -0
- package/lib/commands/instances/credentials/list.js.map +0 -1
- package/lib/generate/templates/auth.js +0 -64
- package/lib/generate/templates/auth.js.map +0 -1
- package/lib/generate/templates/request.js +0 -139
- package/lib/generate/templates/request.js.map +0 -1
|
@@ -0,0 +1,161 @@
|
|
|
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 = {
|
|
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
|
+
const result = await EnhancedOpenAPI.CLIENT.request({
|
|
129
|
+
url,
|
|
130
|
+
method: options.method,
|
|
131
|
+
headers: await getHeaders(options),
|
|
132
|
+
data: getRequestBody(options),
|
|
133
|
+
params: options.query ? { ...options.query } : undefined,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Request using Axios client
|
|
141
|
+
* @param options The request options from the the service
|
|
142
|
+
* @returns Partial<AxiosResponse> & {
|
|
143
|
+
body: AxiosResponse["data"];
|
|
144
|
+
}
|
|
145
|
+
*/
|
|
146
|
+
export async function request(
|
|
147
|
+
options: ApiRequestOptions
|
|
148
|
+
): Promise<
|
|
149
|
+
Partial<AxiosResponse> & {
|
|
150
|
+
body: AxiosResponse["data"];
|
|
151
|
+
}
|
|
152
|
+
> {
|
|
153
|
+
const url = getUrl(options);
|
|
154
|
+
|
|
155
|
+
const response = await sendRequest({
|
|
156
|
+
options,
|
|
157
|
+
url,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return { ...response, body: await response.data };
|
|
161
|
+
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { myAction } from "./actions";
|
|
2
|
-
import {
|
|
2
|
+
import { myTrigger } from "./triggers";
|
|
3
|
+
import {
|
|
4
|
+
invoke,
|
|
5
|
+
invokeTrigger,
|
|
6
|
+
defaultTriggerPayload,
|
|
7
|
+
} from "@prismatic-io/spectral/dist/testing";
|
|
3
8
|
|
|
4
9
|
describe("test my action", () => {
|
|
5
10
|
test("verify the return value of my action", async () => {
|
|
@@ -9,3 +14,13 @@ describe("test my action", () => {
|
|
|
9
14
|
expect(result.data).toBe("Hello, some input");
|
|
10
15
|
});
|
|
11
16
|
});
|
|
17
|
+
|
|
18
|
+
describe("test my trigger", () => {
|
|
19
|
+
test("verify the return value of my trigger", async () => {
|
|
20
|
+
const expectedPayload = defaultTriggerPayload();
|
|
21
|
+
const {
|
|
22
|
+
result: { payload },
|
|
23
|
+
} = await invokeTrigger(myTrigger, {}, defaultTriggerPayload());
|
|
24
|
+
expect(payload).toStrictEqual(expectedPayload);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { component } from "@prismatic-io/spectral";
|
|
2
2
|
import actions from "./actions";
|
|
3
|
+
import triggers from "./triggers";
|
|
3
4
|
|
|
4
5
|
export default component({
|
|
5
6
|
key: "<<COMPONENT_NAME>>",
|
|
@@ -10,4 +11,5 @@ export default component({
|
|
|
10
11
|
iconPath: "icon.png",
|
|
11
12
|
},
|
|
12
13
|
actions,
|
|
14
|
+
triggers,
|
|
13
15
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { trigger } from "@prismatic-io/spectral";
|
|
2
|
+
|
|
3
|
+
export const myTrigger = trigger({
|
|
4
|
+
display: {
|
|
5
|
+
label: "My Trigger",
|
|
6
|
+
description: "This is my trigger",
|
|
7
|
+
},
|
|
8
|
+
perform: async (context, payload, params) => {
|
|
9
|
+
return {
|
|
10
|
+
payload,
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
inputs: {},
|
|
14
|
+
synchronousResponseSupport: "valid",
|
|
15
|
+
scheduleSupport: "valid",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export default { myTrigger };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../../src/commands/instances/credentials/list.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAgD;AAChD,4DAA+C;AAC/C,mCAA6B;AAE7B,MAAqB,WAAY,SAAQ,iBAAO;IAWxC,GAAG;;YACP,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YAC1C,MAAM,EAAE,QAAQ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ugRequest, maxRetries, retryDelayMS, retryOnAllErrors, timeout, useExponentialBackoff, }) => {
|
|
3
|
-
if (url) {
|
|
4
|
-
EnhancedOpenAPI.BASE = util.types.toString(url);
|
|
5
|
-
}
|
|
6
|
-
EnhancedOpenAPI.timeout =
|
|
7
|
-
typeof timeout !== undefined ? util.types.toNumber(timeout) : undefined;
|
|
8
|
-
EnhancedOpenAPI.CLIENT = Axios.create();
|
|
9
|
-
if (maxRetries) {
|
|
10
|
-
const axiosRetryConfig = {
|
|
11
|
-
retries: util.types.toInt(maxRetries),
|
|
12
|
-
shouldResetTimeout: true,
|
|
13
|
-
};
|
|
14
|
-
if (retryDelayMS) {
|
|
15
|
-
// Use a specified delay.
|
|
16
|
-
axiosRetryConfig.retryDelay = () => {
|
|
17
|
-
return util.types.toInt(retryDelayMS);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
else if (useExponentialBackoff &&
|
|
21
|
-
util.types.toBool(useExponentialBackoff)) {
|
|
22
|
-
// Use a predefined exponential backoff.
|
|
23
|
-
axiosRetryConfig.retryDelay = exponentialDelay;
|
|
24
|
-
}
|
|
25
|
-
if (retryOnAllErrors && util.types.toBool(retryOnAllErrors)) {
|
|
26
|
-
// Retry on all errors regardless of type or HTTP method.
|
|
27
|
-
axiosRetryConfig.retryCondition = () => {
|
|
28
|
-
return true;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
axiosRetry(EnhancedOpenAPI.CLIENT, axiosRetryConfig);
|
|
32
|
-
}
|
|
33
|
-
if (util.types.toBool(debugRequest) === true) {
|
|
34
|
-
EnhancedOpenAPI.CLIENT.interceptors.request.use((request) => {
|
|
35
|
-
console.log(JSON.stringify(request));
|
|
36
|
-
return request;
|
|
37
|
-
});
|
|
38
|
-
EnhancedOpenAPI.CLIENT.interceptors.response.use(({ headers, status, statusText, config, data }) => {
|
|
39
|
-
console.log({ headers, status, statusText, config, data });
|
|
40
|
-
return { headers, status, statusText, config, data };
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
switch (credential.authorizationMethod) {
|
|
44
|
-
case "basic": {
|
|
45
|
-
const { fields: { username, password }, } = credential;
|
|
46
|
-
EnhancedOpenAPI.USERNAME = username;
|
|
47
|
-
EnhancedOpenAPI.PASSWORD = password;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
case "oauth2": {
|
|
51
|
-
const { token: { access_token }, } = credential;
|
|
52
|
-
EnhancedOpenAPI.TOKEN = access_token;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case "api_key": {
|
|
56
|
-
const { fields: { api_key }, } = credential;
|
|
57
|
-
EnhancedOpenAPI.TOKEN = api_key;
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
default:
|
|
61
|
-
throw new Error(`Unsupported authorization method: \${credential.authorizationMethod}`);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
//# sourceMappingURL=auth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/generate/templates/auth.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,CAAC,EACC,UAAU,EACV,GAAG,EACH,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,OAAO,EACP,qBAAqB,GACC,EAAE,EAAE;IAC1B,IAAI,GAAG,EAAE;QACP,eAAe,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;KACjD;IAED,eAAe,CAAC,OAAO;QACrB,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE1E,eAAe,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;IAExC,IAAI,UAAU,EAAE;QACd,MAAM,gBAAgB,GAAsB;YAC1C,OAAO,EAAE,IAAI,CAAC,KAAK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AE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACvD,CAAC,CACF,CAAC;KACH;IAED,QAAQ,UAAU,CAAC,mBAAmB,EAAE;QACtC,KAAK,OAAO,CAAC,CAAC;YACZ,MAAM,EACJ,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAC/B,GAAG,UAAU,CAAC;YAEf,eAAe,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAEpC,eAAe,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACpC,MAAM;SACP;QAED,KAAK,QAAQ,CAAC,CAAC;YACb,MAAM,EACJ,KAAK,EAAE,EAAE,YAAY,EAAE,GACxB,GAAG,UAAU,CAAC;YAEf,eAAe,CAAC,KAAK,GAAG,YAAY,CAAC;YACrC,MAAM;SACP;QAED,KAAK,SAAS,CAAC,CAAC;YACd,MAAM,EACJ,MAAM,EAAE,EAAE,OAAO,EAAE,GACpB,GAAG,UAAU,CAAC;YAEf,eAAe,CAAC,KAAK,GAAG,OAAO,CAAC;YAChC,MAAM;SACP;QAED;YACE,MAAM,IAAI,KAAK,CACb,sEAAsE,CACvE,CAAC;KACL;AACH,CAAC,CAAC"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.request = void 0;
|
|
16
|
-
/* istanbul ignore file */
|
|
17
|
-
/* tslint:disable */
|
|
18
|
-
/* eslint-disable */
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
const form_data_1 = __importDefault(require("form-data"));
|
|
21
|
-
const spectral_1 = require("@prismatic-io/spectral");
|
|
22
|
-
const util_1 = require("util");
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
const OpenAPI_1 = require("./OpenAPI");
|
|
25
|
-
function isDefined(value) {
|
|
26
|
-
return value !== undefined && value !== null;
|
|
27
|
-
}
|
|
28
|
-
function isString(value) {
|
|
29
|
-
return typeof value === "string";
|
|
30
|
-
}
|
|
31
|
-
function isStringWithValue(value) {
|
|
32
|
-
return isString(value) && value !== "";
|
|
33
|
-
}
|
|
34
|
-
function isBinary(value) {
|
|
35
|
-
const isBuffer = Buffer.isBuffer(value);
|
|
36
|
-
const isArrayBuffer = util_1.types.isArrayBuffer(value);
|
|
37
|
-
const isArrayBufferView = util_1.types.isArrayBufferView(value);
|
|
38
|
-
return isBuffer || isArrayBuffer || isArrayBufferView;
|
|
39
|
-
}
|
|
40
|
-
function getUrl(options) {
|
|
41
|
-
const path = options.path.replace(/[:]/g, "_");
|
|
42
|
-
const url = `${OpenAPI_1.EnhancedOpenAPI.BASE}${path}`;
|
|
43
|
-
return url;
|
|
44
|
-
}
|
|
45
|
-
function getFormData(params) {
|
|
46
|
-
const formData = new form_data_1.default();
|
|
47
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
48
|
-
if (isDefined(value)) {
|
|
49
|
-
formData.append(key, value);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return formData;
|
|
53
|
-
}
|
|
54
|
-
function resolve(options, resolver) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
if (typeof resolver === "function") {
|
|
57
|
-
return resolver(options);
|
|
58
|
-
}
|
|
59
|
-
return resolver;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function getHeaders(options) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const [token, username, password, defaultHeaders] = yield Promise.all([
|
|
65
|
-
resolve(options, OpenAPI_1.EnhancedOpenAPI.TOKEN),
|
|
66
|
-
resolve(options, OpenAPI_1.EnhancedOpenAPI.USERNAME),
|
|
67
|
-
resolve(options, OpenAPI_1.EnhancedOpenAPI.PASSWORD),
|
|
68
|
-
resolve(options, OpenAPI_1.EnhancedOpenAPI.HEADERS),
|
|
69
|
-
]);
|
|
70
|
-
const headers = Object.assign(Object.assign({ Accept: "application/json" }, defaultHeaders), options.headers);
|
|
71
|
-
if (OpenAPI_1.EnhancedOpenAPI.timeout) {
|
|
72
|
-
headers["timeout"] = spectral_1.util.types.toInt(OpenAPI_1.EnhancedOpenAPI.timeout);
|
|
73
|
-
}
|
|
74
|
-
if (isStringWithValue(token)) {
|
|
75
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
76
|
-
}
|
|
77
|
-
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
78
|
-
const credentials = Buffer.from(`${username}:${password}`).toString("base64");
|
|
79
|
-
headers["Authorization"] = `Basic ${credentials}`;
|
|
80
|
-
}
|
|
81
|
-
if (options.body) {
|
|
82
|
-
if (isBinary(options.body)) {
|
|
83
|
-
headers["Content-Type"] = "application/octet-stream";
|
|
84
|
-
}
|
|
85
|
-
else if (isString(options.body)) {
|
|
86
|
-
headers["Content-Type"], "text/plain";
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
headers["Content-Type"] = "application/json";
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return headers;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function getRequestBody(options) {
|
|
96
|
-
if (options.formData) {
|
|
97
|
-
return getFormData(options.formData);
|
|
98
|
-
}
|
|
99
|
-
if (options.body) {
|
|
100
|
-
if (isString(options.body) || isBinary(options.body)) {
|
|
101
|
-
return options.body;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
return JSON.stringify(options.body);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
function sendRequest({ options, url, }) {
|
|
110
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
const result = yield OpenAPI_1.EnhancedOpenAPI.CLIENT.request({
|
|
112
|
-
url,
|
|
113
|
-
method: options.method,
|
|
114
|
-
headers: yield getHeaders(options),
|
|
115
|
-
data: getRequestBody(options),
|
|
116
|
-
params: options.query ? Object.assign({}, options.query) : undefined,
|
|
117
|
-
});
|
|
118
|
-
return result;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Request using Axios client
|
|
123
|
-
* @param options The request options from the the service
|
|
124
|
-
* @returns Partial<AxiosResponse> & {
|
|
125
|
-
body: AxiosResponse["data"];
|
|
126
|
-
}
|
|
127
|
-
*/
|
|
128
|
-
function request(options) {
|
|
129
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const url = getUrl(options);
|
|
131
|
-
const response = yield sendRequest({
|
|
132
|
-
options,
|
|
133
|
-
url,
|
|
134
|
-
});
|
|
135
|
-
return Object.assign(Object.assign({}, response), { body: yield response.data });
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
exports.request = request;
|
|
139
|
-
//# sourceMappingURL=request.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/generate/templates/request.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0BAA0B;AAC1B,oBAAoB;AACpB,oBAAoB;AACpB,aAAa;AACb,0DAAiC;AAEjC,qDAA8C;AAC9C,+BAA6B;AAG7B,aAAa;AACb,uCAA4C;AAE5C,S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