@prismatic-io/spectral 6.4.0 → 6.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,159 @@
1
+ import { AxiosResponse } from "axios";
1
2
  import { AxiosInstance, AxiosRequestConfig } from "axios";
2
3
  import { IAxiosRetryConfig } from "axios-retry";
4
+ import { ActionInputParameters } from "../../types";
5
+ import { inputs } from "./inputs";
3
6
  export declare type HttpClient = AxiosInstance;
7
+ interface RetryConfig extends Omit<IAxiosRetryConfig, "retryDelay"> {
8
+ retryDelay?: IAxiosRetryConfig["retryDelay"] | number;
9
+ retryAllErrors?: boolean;
10
+ useExponentialBackoff?: boolean;
11
+ }
4
12
  export interface ClientProps {
5
13
  baseUrl?: string;
6
14
  responseType?: AxiosRequestConfig["responseType"];
7
15
  headers?: AxiosRequestConfig["headers"];
8
16
  timeout?: number;
9
17
  debug?: boolean;
10
- retryConfig?: IAxiosRetryConfig;
18
+ retryConfig?: RetryConfig;
11
19
  }
12
20
  export declare const createClient: ({ baseUrl, responseType, headers, timeout, debug, retryConfig, }: ClientProps) => HttpClient;
13
21
  export declare const handleErrors: (error: unknown) => unknown;
22
+ declare type SendRawRequestValues = ActionInputParameters<typeof inputs>;
23
+ export declare const sendRawRequest: (baseUrl: string, values: SendRawRequestValues, authorizationHeaders?: Record<string, string>) => Promise<AxiosResponse>;
24
+ export declare const buildRawRequestAction: (baseUrl: string, label?: string, description?: string) => import("../..").ActionDefinition<{
25
+ url: {
26
+ label: string;
27
+ placeholder: string;
28
+ type: "string";
29
+ required: true;
30
+ comments: string;
31
+ example: string;
32
+ clean: (value: unknown) => string;
33
+ };
34
+ method: {
35
+ label: string;
36
+ type: "string";
37
+ required: true;
38
+ model: {
39
+ label: import("axios").Method;
40
+ value: import("axios").Method;
41
+ }[];
42
+ comments: string;
43
+ clean: (value: unknown) => string;
44
+ };
45
+ data: {
46
+ label: string;
47
+ placeholder: string;
48
+ type: "string";
49
+ required: false;
50
+ comments: string;
51
+ example: string;
52
+ clean: (value: unknown) => string;
53
+ };
54
+ formData: {
55
+ label: string;
56
+ placeholder: string;
57
+ type: "string";
58
+ collection: "keyvaluelist";
59
+ required: false;
60
+ comments: string;
61
+ example: string;
62
+ };
63
+ fileData: {
64
+ label: string;
65
+ placeholder: string;
66
+ type: "string";
67
+ collection: "keyvaluelist";
68
+ required: false;
69
+ comments: string;
70
+ example: string;
71
+ };
72
+ queryParams: {
73
+ label: string;
74
+ placeholder: string;
75
+ type: "string";
76
+ collection: "keyvaluelist";
77
+ required: false;
78
+ comments: string;
79
+ };
80
+ headers: {
81
+ label: string;
82
+ placeholder: string;
83
+ type: "string";
84
+ collection: "keyvaluelist";
85
+ required: false;
86
+ comments: string;
87
+ example: string;
88
+ };
89
+ responseType: {
90
+ label: string;
91
+ placeholder: string;
92
+ type: "string";
93
+ default: string;
94
+ required: true;
95
+ comments: string;
96
+ model: {
97
+ label: import("axios").ResponseType;
98
+ value: import("axios").ResponseType;
99
+ }[];
100
+ clean: (value: unknown) => import("axios").ResponseType;
101
+ };
102
+ timeout: {
103
+ label: string;
104
+ type: "string";
105
+ required: false;
106
+ comments: string;
107
+ example: string;
108
+ clean: (value: unknown) => number;
109
+ };
110
+ debugRequest: {
111
+ label: string;
112
+ type: "boolean";
113
+ required: false;
114
+ comments: string;
115
+ clean: (value: unknown) => boolean;
116
+ };
117
+ retryDelayMS: {
118
+ label: string;
119
+ placeholder: string;
120
+ type: "string";
121
+ required: false;
122
+ comments: string;
123
+ default: string;
124
+ clean: (value: unknown) => number;
125
+ };
126
+ retryAllErrors: {
127
+ label: string;
128
+ type: "boolean";
129
+ default: string;
130
+ required: false;
131
+ comments: string;
132
+ clean: (value: unknown) => boolean;
133
+ };
134
+ maxRetries: {
135
+ label: string;
136
+ placeholder: string;
137
+ type: "string";
138
+ required: false;
139
+ comments: string;
140
+ default: string;
141
+ clean: (value: unknown) => number;
142
+ };
143
+ useExponentialBackoff: {
144
+ label: string;
145
+ type: "boolean";
146
+ default: string;
147
+ required: false;
148
+ comments: string;
149
+ clean: (value: unknown) => boolean;
150
+ };
151
+ connection: {
152
+ label: string;
153
+ type: "connection";
154
+ required: true;
155
+ };
156
+ }, boolean, {
157
+ data: any;
158
+ }>;
159
+ export { inputs };
@@ -1,12 +1,94 @@
1
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __rest = (this && this.__rest) || function (s, e) {
35
+ var t = {};
36
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
+ t[p] = s[p];
38
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
+ t[p[i]] = s[p[i]];
42
+ }
43
+ return t;
44
+ };
2
45
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
46
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
47
  };
5
48
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.handleErrors = exports.createClient = void 0;
49
+ exports.inputs = exports.buildRawRequestAction = exports.sendRawRequest = exports.handleErrors = exports.createClient = void 0;
50
+ const lodash_1 = require("lodash");
7
51
  const axios_1 = __importDefault(require("axios"));
8
- const axios_retry_1 = __importDefault(require("axios-retry"));
9
- const util_1 = require("../../util");
52
+ const axios_retry_1 = __importStar(require("axios-retry"));
53
+ const form_data_1 = __importDefault(require("form-data"));
54
+ const __1 = require("../..");
55
+ const util_1 = __importDefault(require("../../util"));
56
+ const inputs_1 = require("./inputs");
57
+ Object.defineProperty(exports, "inputs", { enumerable: true, get: function () { return inputs_1.inputs; } });
58
+ const toAuthorizationHeaders = (connection) => {
59
+ var _a, _b, _c, _d;
60
+ const accessToken = util_1.default.types.toString((_a = connection.token) === null || _a === void 0 ? void 0 : _a.access_token);
61
+ if (accessToken) {
62
+ return { Authorization: `Bearer ${accessToken}` };
63
+ }
64
+ const apiKey = util_1.default.types.toString((_b = connection.fields) === null || _b === void 0 ? void 0 : _b.apiKey);
65
+ if (apiKey) {
66
+ return { Authorization: `Bearer ${apiKey}` };
67
+ }
68
+ const username = util_1.default.types.toString((_c = connection.fields) === null || _c === void 0 ? void 0 : _c.username);
69
+ const password = util_1.default.types.toString((_d = connection.fields) === null || _d === void 0 ? void 0 : _d.password);
70
+ if (username && password) {
71
+ const encoded = Buffer.from(`${username}:${password}`).toString("base64");
72
+ return { Authorization: `Basic ${encoded}` };
73
+ }
74
+ throw new Error(`Failed to guess at authorization parameters for Connection: ${connection.key}`);
75
+ };
76
+ const toFormData = (formData, fileData) => {
77
+ const form = new form_data_1.default();
78
+ (formData || []).map(({ key, value }) => form.append(key, value));
79
+ (fileData || []).map(({ key, value }) => form.append(key, value, { filename: key }));
80
+ return form;
81
+ };
82
+ const computeRetryDelay = (retryDelay, useExponentialBackoff) => {
83
+ if (useExponentialBackoff) {
84
+ return axios_retry_1.exponentialDelay;
85
+ }
86
+ return typeof retryDelay === "number" ? () => retryDelay : retryDelay;
87
+ };
88
+ const toAxiosRetryConfig = (_a) => {
89
+ var { retryDelay, retryAllErrors, retryCondition, useExponentialBackoff } = _a, rest = __rest(_a, ["retryDelay", "retryAllErrors", "retryCondition", "useExponentialBackoff"]);
90
+ return (Object.assign(Object.assign({}, rest), { retryDelay: computeRetryDelay(retryDelay, useExponentialBackoff), retryCondition: retryAllErrors ? () => true : retryCondition }));
91
+ };
10
92
  const createClient = ({ baseUrl, responseType, headers, timeout, debug = false, retryConfig, }) => {
11
93
  const client = axios_1.default.create({
12
94
  baseURL: baseUrl,
@@ -18,17 +100,17 @@ const createClient = ({ baseUrl, responseType, headers, timeout, debug = false,
18
100
  });
19
101
  if (debug) {
20
102
  client.interceptors.request.use((request) => {
21
- console.log((0, util_1.toJSON)(request));
103
+ console.log(util_1.default.types.toJSON(request));
22
104
  return request;
23
105
  });
24
106
  client.interceptors.response.use((response) => {
25
- console.log((0, util_1.toJSON)(response));
107
+ console.log(util_1.default.types.toJSON(response));
26
108
  return response;
27
109
  });
28
110
  }
29
111
  if (retryConfig) {
30
112
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- (0, axios_retry_1.default)(client, retryConfig);
113
+ (0, axios_retry_1.default)(client, toAxiosRetryConfig(retryConfig));
32
114
  }
33
115
  return client;
34
116
  };
@@ -44,3 +126,39 @@ const handleErrors = (error) => {
44
126
  return error;
45
127
  };
46
128
  exports.handleErrors = handleErrors;
129
+ const sendRawRequest = (baseUrl, values, authorizationHeaders = {}) => __awaiter(void 0, void 0, void 0, function* () {
130
+ if (values.data && (!(0, lodash_1.isEmpty)(values.formData) || !(0, lodash_1.isEmpty)(values.fileData))) {
131
+ throw new Error("Cannot specify both Data and File/Form Data.");
132
+ }
133
+ const payload = values.data || toFormData(values.formData, values.fileData);
134
+ const client = (0, exports.createClient)({
135
+ baseUrl,
136
+ debug: values.debugRequest,
137
+ responseType: values.responseType,
138
+ timeout: values.timeout,
139
+ retryConfig: {
140
+ retries: values.maxRetries,
141
+ retryDelay: values.retryDelayMS,
142
+ retryAllErrors: values.retryAllErrors,
143
+ useExponentialBackoff: values.useExponentialBackoff,
144
+ },
145
+ });
146
+ return yield client.request({
147
+ method: values.method,
148
+ url: values.url,
149
+ headers: Object.assign(Object.assign(Object.assign({}, util_1.default.types.keyValPairListToObject(values.headers)), (payload instanceof form_data_1.default ? payload.getHeaders() : {})), authorizationHeaders),
150
+ params: util_1.default.types.keyValPairListToObject(values.queryParams),
151
+ data: payload,
152
+ });
153
+ });
154
+ exports.sendRawRequest = sendRawRequest;
155
+ const buildRawRequestAction = (baseUrl, label = "Raw Request", description = "Issue a raw HTTP request") => (0, __1.action)({
156
+ display: { label, description },
157
+ inputs: Object.assign({ connection: { label: "Connection", type: "connection", required: true } }, inputs_1.inputs),
158
+ perform: (context, _a) => __awaiter(void 0, void 0, void 0, function* () {
159
+ var { connection } = _a, httpInputValues = __rest(_a, ["connection"]);
160
+ const { data } = yield (0, exports.sendRawRequest)(baseUrl, httpInputValues, toAuthorizationHeaders(connection));
161
+ return { data };
162
+ }),
163
+ });
164
+ exports.buildRawRequestAction = buildRawRequestAction;
@@ -28,6 +28,7 @@ export declare const timeout: {
28
28
  export declare const method: {
29
29
  label: string;
30
30
  type: "string";
31
+ required: true;
31
32
  model: {
32
33
  label: Method;
33
34
  value: Method;
@@ -40,13 +41,13 @@ export declare const responseType: {
40
41
  placeholder: string;
41
42
  type: "string";
42
43
  default: string;
43
- required: false;
44
+ required: true;
44
45
  comments: string;
45
46
  model: {
46
47
  label: ResponseType;
47
48
  value: ResponseType;
48
49
  }[];
49
- clean: (value: unknown) => string;
50
+ clean: (value: unknown) => ResponseType;
50
51
  };
51
52
  export declare const headers: {
52
53
  label: string;
@@ -81,6 +82,7 @@ export declare const retryDelayMS: {
81
82
  required: false;
82
83
  comments: string;
83
84
  default: string;
85
+ clean: (value: unknown) => number;
84
86
  };
85
87
  export declare const useExponentialBackoff: {
86
88
  label: string;
@@ -90,7 +92,7 @@ export declare const useExponentialBackoff: {
90
92
  comments: string;
91
93
  clean: (value: unknown) => boolean;
92
94
  };
93
- export declare const retryOnAllErrors: {
95
+ export declare const retryAllErrors: {
94
96
  label: string;
95
97
  type: "boolean";
96
98
  default: string;
@@ -123,3 +125,131 @@ export declare const debugRequest: {
123
125
  comments: string;
124
126
  clean: (value: unknown) => boolean;
125
127
  };
128
+ export declare const inputs: {
129
+ url: {
130
+ label: string;
131
+ placeholder: string;
132
+ type: "string";
133
+ required: true;
134
+ comments: string;
135
+ example: string;
136
+ clean: (value: unknown) => string;
137
+ };
138
+ method: {
139
+ label: string;
140
+ type: "string";
141
+ required: true;
142
+ model: {
143
+ label: Method;
144
+ value: Method;
145
+ }[];
146
+ comments: string;
147
+ clean: (value: unknown) => string;
148
+ };
149
+ data: {
150
+ label: string;
151
+ placeholder: string;
152
+ type: "string";
153
+ required: false;
154
+ comments: string;
155
+ example: string;
156
+ clean: (value: unknown) => string;
157
+ };
158
+ formData: {
159
+ label: string;
160
+ placeholder: string;
161
+ type: "string";
162
+ collection: "keyvaluelist";
163
+ required: false;
164
+ comments: string;
165
+ example: string;
166
+ };
167
+ fileData: {
168
+ label: string;
169
+ placeholder: string;
170
+ type: "string";
171
+ collection: "keyvaluelist";
172
+ required: false;
173
+ comments: string;
174
+ example: string;
175
+ };
176
+ queryParams: {
177
+ label: string;
178
+ placeholder: string;
179
+ type: "string";
180
+ collection: "keyvaluelist";
181
+ required: false;
182
+ comments: string;
183
+ };
184
+ headers: {
185
+ label: string;
186
+ placeholder: string;
187
+ type: "string";
188
+ collection: "keyvaluelist";
189
+ required: false;
190
+ comments: string;
191
+ example: string;
192
+ };
193
+ responseType: {
194
+ label: string;
195
+ placeholder: string;
196
+ type: "string";
197
+ default: string;
198
+ required: true;
199
+ comments: string;
200
+ model: {
201
+ label: ResponseType;
202
+ value: ResponseType;
203
+ }[];
204
+ clean: (value: unknown) => ResponseType;
205
+ };
206
+ timeout: {
207
+ label: string;
208
+ type: "string";
209
+ required: false;
210
+ comments: string;
211
+ example: string;
212
+ clean: (value: unknown) => number;
213
+ };
214
+ debugRequest: {
215
+ label: string;
216
+ type: "boolean";
217
+ required: false;
218
+ comments: string;
219
+ clean: (value: unknown) => boolean;
220
+ };
221
+ retryDelayMS: {
222
+ label: string;
223
+ placeholder: string;
224
+ type: "string";
225
+ required: false;
226
+ comments: string;
227
+ default: string;
228
+ clean: (value: unknown) => number;
229
+ };
230
+ retryAllErrors: {
231
+ label: string;
232
+ type: "boolean";
233
+ default: string;
234
+ required: false;
235
+ comments: string;
236
+ clean: (value: unknown) => boolean;
237
+ };
238
+ maxRetries: {
239
+ label: string;
240
+ placeholder: string;
241
+ type: "string";
242
+ required: false;
243
+ comments: string;
244
+ default: string;
245
+ clean: (value: unknown) => number;
246
+ };
247
+ useExponentialBackoff: {
248
+ label: string;
249
+ type: "boolean";
250
+ default: string;
251
+ required: false;
252
+ comments: string;
253
+ clean: (value: unknown) => boolean;
254
+ };
255
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debugRequest = exports.fileData = exports.formData = exports.retryOnAllErrors = exports.useExponentialBackoff = exports.retryDelayMS = exports.maxRetries = exports.queryParams = exports.headers = exports.responseType = exports.method = exports.timeout = exports.data = exports.url = void 0;
3
+ exports.inputs = exports.debugRequest = exports.fileData = exports.formData = exports.retryAllErrors = exports.useExponentialBackoff = exports.retryDelayMS = exports.maxRetries = exports.queryParams = exports.headers = exports.responseType = exports.method = exports.timeout = exports.data = exports.url = void 0;
4
4
  const __1 = require("../..");
5
5
  const supportedMethods = [
6
6
  "DELETE",
@@ -49,6 +49,7 @@ exports.timeout = (0, __1.input)({
49
49
  exports.method = (0, __1.input)({
50
50
  label: "Method",
51
51
  type: "string",
52
+ required: true,
52
53
  model: supportedMethods.map((method) => ({ label: method, value: method })),
53
54
  comments: "The HTTP method to use.",
54
55
  clean: (value) => __1.util.types.toString(value),
@@ -58,7 +59,7 @@ exports.responseType = (0, __1.input)({
58
59
  placeholder: "Response Type",
59
60
  type: "string",
60
61
  default: "json",
61
- required: false,
62
+ required: true,
62
63
  comments: "The type of data you expect in the response. You can request json, text, or binary data.",
63
64
  model: supportedResponseTypes.map((responseType) => ({
64
65
  label: responseType,
@@ -99,6 +100,7 @@ exports.retryDelayMS = (0, __1.input)({
99
100
  required: false,
100
101
  comments: "The delay in milliseconds between retries.",
101
102
  default: "0",
103
+ clean: (value) => __1.util.types.toNumber(value, 0),
102
104
  });
103
105
  exports.useExponentialBackoff = (0, __1.input)({
104
106
  label: "Use Exponential Backoff",
@@ -108,7 +110,7 @@ exports.useExponentialBackoff = (0, __1.input)({
108
110
  comments: "Specifies whether to use a pre-defined exponential backoff strategy for retries.",
109
111
  clean: (value) => __1.util.types.toBool(value),
110
112
  });
111
- exports.retryOnAllErrors = (0, __1.input)({
113
+ exports.retryAllErrors = (0, __1.input)({
112
114
  label: "Retry On All Errors",
113
115
  type: "boolean",
114
116
  default: "false",
@@ -141,3 +143,19 @@ exports.debugRequest = (0, __1.input)({
141
143
  comments: "Enabling this flag will log out the current request.",
142
144
  clean: (value) => __1.util.types.toBool(value),
143
145
  });
146
+ exports.inputs = {
147
+ url: exports.url,
148
+ method: exports.method,
149
+ data: exports.data,
150
+ formData: exports.formData,
151
+ fileData: exports.fileData,
152
+ queryParams: exports.queryParams,
153
+ headers: exports.headers,
154
+ responseType: exports.responseType,
155
+ timeout: exports.timeout,
156
+ debugRequest: exports.debugRequest,
157
+ retryDelayMS: exports.retryDelayMS,
158
+ retryAllErrors: exports.retryAllErrors,
159
+ maxRetries: exports.maxRetries,
160
+ useExponentialBackoff: exports.useExponentialBackoff,
161
+ };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * authors create inputs, actions, and components that can
4
4
  * be processed by the Prismatic API.
5
5
  */
6
- import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition } from "./types";
6
+ import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult } from "./types";
7
7
  import { convertComponent } from "./serverTypes/convert";
8
8
  /**
9
9
  * This function creates a component object that can be
@@ -23,7 +23,7 @@ export declare const component: <T extends boolean>(definition: ComponentDefinit
23
23
  * @param definition An ActionDefinition type object that includes UI display information, a function to perform when the action is invoked, and a an object containing inputs for the perform function.
24
24
  * @returns This function validates the shape of the `definition` object provided, and returns the same action object.
25
25
  */
26
- export declare const action: <T extends Inputs>(definition: ActionDefinition<T>) => ActionDefinition<T>;
26
+ export declare const action: <TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>>(definition: ActionDefinition<TInputs, TAllowsBranching, TReturn>) => ActionDefinition<TInputs, TAllowsBranching, TReturn>;
27
27
  /**
28
28
  * This function creates a trigger object that can be referenced
29
29
  * by a custom component. It helps ensure that the shape of the
@@ -33,7 +33,7 @@ export declare const action: <T extends Inputs>(definition: ActionDefinition<T>)
33
33
  * @param definition A TriggerDefinition type object that includes UI display information, a function to perform when the trigger is invoked, and a an object containing inputs for the perform function.
34
34
  * @returns This function validates the shape of the `definition` object provided, and returns the same trigger object.
35
35
  */
36
- export declare const trigger: <T extends Inputs>(definition: TriggerDefinition<T>) => TriggerDefinition<T>;
36
+ export declare const trigger: <TInputs extends Inputs, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching>>(definition: TriggerDefinition<TInputs, TAllowsBranching, TResult>) => TriggerDefinition<TInputs, TAllowsBranching, TResult>;
37
37
  /**
38
38
  * For information and examples on how to write inputs
39
39
  * for custom component actions and triggers, see
@@ -87,6 +87,8 @@ interface TriggerBaseResult {
87
87
  instanceState?: Record<string, unknown>;
88
88
  crossFlowState?: Record<string, unknown>;
89
89
  executionState?: Record<string, unknown>;
90
+ failed?: boolean;
91
+ error?: Record<string, unknown>;
90
92
  }
91
93
  interface TriggerBranchingResult extends TriggerBaseResult {
92
94
  branch: string;
@@ -141,6 +143,8 @@ interface ServerPerformDataStructureReturn {
141
143
  instanceState?: Record<string, unknown>;
142
144
  crossFlowState?: Record<string, unknown>;
143
145
  executionState?: Record<string, unknown>;
146
+ failed?: boolean;
147
+ error?: Record<string, unknown>;
144
148
  }
145
149
  interface ServerPerformDataReturn {
146
150
  data: Buffer | string | unknown;
@@ -149,6 +153,8 @@ interface ServerPerformDataReturn {
149
153
  instanceState?: Record<string, unknown>;
150
154
  crossFlowState?: Record<string, unknown>;
151
155
  executionState?: Record<string, unknown>;
156
+ failed?: boolean;
157
+ error?: Record<string, unknown>;
152
158
  }
153
159
  interface ServerPerformBranchingDataStructureReturn extends ServerPerformDataStructureReturn {
154
160
  branch: string;
@@ -8,10 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.createPerform = void 0;
13
16
  const serialize_error_1 = require("serialize-error");
14
- const util_1 = require("../util");
17
+ const util_1 = __importDefault(require("../util"));
15
18
  const cleanParams = (params, cleaners) => Object.entries(params).reduce((result, [key, value]) => {
16
19
  const cleanFn = cleaners[key];
17
20
  return Object.assign(Object.assign({}, result), { [key]: cleanFn ? cleanFn(value) : value });
@@ -31,7 +34,7 @@ const createPerform = (performFn, { inputCleaners, errorHandler }) => {
31
34
  throw error;
32
35
  }
33
36
  const handled = errorHandler(error);
34
- const serialized = (0, util_1.toJSON)((0, serialize_error_1.serializeError)(handled));
37
+ const serialized = util_1.default.types.toJSON((0, serialize_error_1.serializeError)(handled));
35
38
  throw new Error(serialized);
36
39
  }
37
40
  });
package/dist/testing.d.ts CHANGED
@@ -4,9 +4,9 @@
4
4
  * information on unit testing, check out our docs:
5
5
  * https://prismatic.io/docs/custom-components/writing-custom-components/#testing-a-component
6
6
  */
7
- import { TriggerPayload, TriggerResult, Connection, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn } from "./serverTypes";
8
- import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters } from "./types";
9
- export declare const createConnection: <T extends Connection>({ key }: T, values: Record<string, unknown>) => ConnectionValue;
7
+ import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn } from "./serverTypes";
8
+ import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult } from "./types";
9
+ export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>) => ConnectionValue;
10
10
  /**
11
11
  * Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
12
12
  * See https://prismatic.io/docs/custom-components/writing-custom-components/#verifying-correct-logging-in-action-tests for information on testing correct logging behavior in your custom component.
@@ -25,7 +25,7 @@ interface InvokeReturn<ReturnData> {
25
25
  * to avoid extra casting within test methods. Returns an InvokeResult containing both the
26
26
  * action result and a mock logger for asserting logging.
27
27
  */
28
- export declare const invoke: <T extends Inputs>({ perform }: ActionDefinition<T>, params: ActionInputParameters<T>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<import("./types").ActionPerformReturn<boolean | undefined, unknown>>>;
28
+ export declare const invoke: <TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends InvokeActionPerformReturn<TAllowsBranching, unknown>>({ perform }: ActionDefinition<TInputs, TAllowsBranching, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn>>;
29
29
  export declare const defaultTriggerPayload: () => TriggerPayload;
30
30
  /**
31
31
  * Invokes specified TriggerDefinition perform function using supplied params
@@ -33,7 +33,7 @@ export declare const defaultTriggerPayload: () => TriggerPayload;
33
33
  * to avoid extra casting within test methods. Returns an InvokeResult containing both the
34
34
  * trigger result and a mock logger for asserting logging.
35
35
  */
36
- export declare const invokeTrigger: <T extends Inputs>({ perform }: TriggerDefinition<T>, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<T> | undefined) => Promise<InvokeReturn<import("./types").TriggerResult<boolean | undefined>>>;
36
+ export declare const invokeTrigger: <TInputs extends Inputs, TAllowsBranching extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching>>({ perform }: TriggerDefinition<TInputs, TAllowsBranching, TResult>, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs> | undefined) => Promise<InvokeReturn<TResult>>;
37
37
  export declare class ComponentTestHarness<TComponent extends Component> {
38
38
  component: TComponent;
39
39
  constructor(component: TComponent);
@@ -44,8 +44,8 @@ export declare class ComponentTestHarness<TComponent extends Component> {
44
44
  export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
45
45
  declare const _default: {
46
46
  loggerMock: () => ActionLogger;
47
- invoke: <T extends Inputs>({ perform }: ActionDefinition<T>, params: ActionInputParameters<T>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<import("./types").ActionPerformReturn<boolean | undefined, unknown>>>;
48
- invokeTrigger: <T_1 extends Inputs>({ perform }: TriggerDefinition<T_1>, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<T_1> | undefined) => Promise<InvokeReturn<import("./types").TriggerResult<boolean | undefined>>>;
47
+ invoke: <TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends InvokeActionPerformReturn<TAllowsBranching, unknown>>({ perform }: ActionDefinition<TInputs, TAllowsBranching, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn>>;
48
+ invokeTrigger: <TInputs_1 extends Inputs, TAllowsBranching_1 extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching_1>>({ perform }: TriggerDefinition<TInputs_1, TAllowsBranching_1, TResult>, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<TInputs_1> | undefined) => Promise<InvokeReturn<TResult>>;
49
49
  createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
50
50
  };
51
51
  export default _default;
@@ -1,13 +1,13 @@
1
- import { ActionDisplayDefinition, ActionPerformFunction, Inputs } from ".";
1
+ import { ActionDisplayDefinition, ActionPerformFunction, ActionPerformReturn, Inputs } from ".";
2
2
  /**
3
3
  * ActionDefinition is the type of the object that is passed in to `action` function to
4
4
  * define a component action.
5
5
  */
6
- export interface ActionDefinition<TInputs extends Inputs> {
6
+ export interface ActionDefinition<TInputs extends Inputs, TAllowsBranching extends boolean, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> {
7
7
  /** Defines how the Action is displayed in the Prismatic interface. */
8
8
  display: ActionDisplayDefinition;
9
9
  /** Function to perform when this Action is invoked. */
10
- perform: ActionPerformFunction<this["inputs"], this["allowsBranching"]>;
10
+ perform: ActionPerformFunction<TInputs, TAllowsBranching, TReturn>;
11
11
  /** InputFields to present in the Prismatic interface for configuration of this Action. */
12
12
  inputs: TInputs;
13
13
  /** Optional attribute that specifies whether an Action will terminate execution.*/
@@ -15,7 +15,7 @@ export interface ActionDefinition<TInputs extends Inputs> {
15
15
  /** Specifies whether an Action will break out of a loop. */
16
16
  breakLoop?: boolean;
17
17
  /** Determines whether an Action will allow Conditional Branching.*/
18
- allowsBranching?: boolean;
18
+ allowsBranching?: TAllowsBranching;
19
19
  /** Static Branch names associated with an Action. */
20
20
  staticBranchNames?: string[];
21
21
  /** The Input associated with Dynamic Branching.*/
@@ -1,6 +1,6 @@
1
1
  import { Inputs, ActionPerformReturn, ActionInputParameters, ActionLogger } from ".";
2
2
  /** Definition of the function to perform when an Action is invoked. */
3
- export declare type ActionPerformFunction<TInputs extends Inputs, AllowsBranching extends boolean | undefined> = (context: ActionContext, params: ActionInputParameters<TInputs>) => Promise<ActionPerformReturn<AllowsBranching, unknown>>;
3
+ export declare type ActionPerformFunction<TInputs extends Inputs, TAllowsBranching extends boolean | undefined, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> = (context: ActionContext, params: ActionInputParameters<TInputs>) => Promise<TReturn>;
4
4
  /** Context provided to perform method containing helpers and contextual data */
5
5
  export interface ActionContext {
6
6
  /** Logger for permanent logging; console calls are also captured */
@@ -12,6 +12,10 @@ export interface ActionPerformDataReturn<ReturnData> {
12
12
  crossFlowState?: Record<string, unknown>;
13
13
  /** An optional object, the keys and values of which will be persisted in the executionState and available for the duration of the execution */
14
14
  executionState?: Record<string, unknown>;
15
+ /** A field populated by the Prismatic platform which indicates whether the trigger failed with an error during execution. */
16
+ failed?: boolean;
17
+ /** A field populated by the Prismatic platform which may refer to an object that contains data about any error that resulted in failure. */
18
+ error?: Record<string, unknown>;
15
19
  }
16
20
  /** Used to represent a branching return of conventional data and does not require content type to be specified */
17
21
  /** Used to represent a binary or serialized data branching return as content type must be specified */
@@ -13,9 +13,9 @@ export declare type ComponentDefinition<TPublic extends boolean> = {
13
13
  /** Defines how the Component is displayed in the Prismatic interface. */
14
14
  display: ComponentDisplayDefinition<TPublic>;
15
15
  /** Specifies the supported Actions of this Component. */
16
- actions?: Record<string, ActionDefinition<any>>;
16
+ actions?: Record<string, ActionDefinition<any, boolean, any>>;
17
17
  /** Specifies the supported Triggers of this Component. */
18
- triggers?: Record<string, TriggerDefinition<any>>;
18
+ triggers?: Record<string, TriggerDefinition<any, boolean, any>>;
19
19
  /** Specifies the supported Connections of this Component. */
20
20
  connections?: ConnectionDefinition[];
21
21
  /** Hooks */
@@ -1,4 +1,4 @@
1
- import { ActionDisplayDefinition, TriggerPerformFunction, Inputs } from ".";
1
+ import { ActionDisplayDefinition, TriggerPerformFunction, Inputs, TriggerResult } from ".";
2
2
  declare const optionChoices: readonly ["invalid", "valid", "required"];
3
3
  export declare type TriggerOptionChoice = typeof optionChoices[number];
4
4
  export declare const TriggerOptionChoices: TriggerOptionChoice[];
@@ -6,11 +6,11 @@ export declare const TriggerOptionChoices: TriggerOptionChoice[];
6
6
  * TriggerDefinition is the type of the object that is passed in to `trigger` function to
7
7
  * define a component trigger.
8
8
  */
9
- export interface TriggerDefinition<TInputs extends Inputs> {
9
+ export interface TriggerDefinition<TInputs extends Inputs, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching>> {
10
10
  /** Defines how the Trigger is displayed in the Prismatic interface. */
11
11
  display: ActionDisplayDefinition;
12
12
  /** Function to perform when this Trigger is invoked. */
13
- perform: TriggerPerformFunction<this["inputs"], this["allowsBranching"]>;
13
+ perform: TriggerPerformFunction<TInputs, TAllowsBranching, TResult>;
14
14
  /** InputFields to present in the Prismatic interface for configuration of this Trigger. */
15
15
  inputs: TInputs;
16
16
  /** Specifies whether this Trigger supports executing the Integration on a recurring schedule. */
@@ -22,7 +22,7 @@ export interface TriggerDefinition<TInputs extends Inputs> {
22
22
  /** Specifies whether an Action will break out of a loop. */
23
23
  breakLoop?: boolean;
24
24
  /** Determines whether this Trigger allows Conditional Branching. */
25
- allowsBranching?: boolean;
25
+ allowsBranching?: TAllowsBranching;
26
26
  /** Static Branch names associated with this Trigger. */
27
27
  staticBranchNames?: string[];
28
28
  /** The Input associated with Dynamic Branching. */
@@ -1,3 +1,3 @@
1
1
  import { Inputs, TriggerResult, ActionInputParameters, ActionContext, TriggerPayload } from ".";
2
2
  /** Definition of the function to perform when a Trigger is invoked. */
3
- export declare type TriggerPerformFunction<T extends Inputs, AllowsBranching extends boolean | undefined> = (context: ActionContext, payload: TriggerPayload, params: ActionInputParameters<T>) => Promise<TriggerResult<AllowsBranching>>;
3
+ export declare type TriggerPerformFunction<T extends Inputs, TAllowsBranching extends boolean | undefined, TResult extends TriggerResult<TAllowsBranching>> = (context: ActionContext, payload: TriggerPayload, params: ActionInputParameters<T>) => Promise<TResult>;
@@ -12,6 +12,10 @@ export interface TriggerBaseResult {
12
12
  crossFlowState?: Record<string, unknown>;
13
13
  /** An optional object, the keys and values of which will be persisted in the executionState and available for the duration of the execution */
14
14
  executionState?: Record<string, unknown>;
15
+ /** A field populated by the Prismatic platform which indicates whether the trigger failed with an error during execution. */
16
+ failed?: boolean;
17
+ /** A field populated by the Prismatic platform which may refer to an object that contains data about any error that resulted in failure. */
18
+ error?: Record<string, unknown>;
15
19
  }
16
20
  /** Represents the result of a Trigger action that uses branching. */
17
21
  export interface TriggerBranchingResult extends TriggerBaseResult {
package/dist/util.d.ts CHANGED
@@ -4,12 +4,6 @@
4
4
  * For example, `util.types.toInt("5.5")` will return an integer, `5`.
5
5
  */
6
6
  import { KeyValuePair, DataPayload } from "./types";
7
- /** This function accepts an arbitrary object/value and safely serializes it (handles cyclic references).
8
- *
9
- * @param value Arbitrary object/value to serialize.
10
- * @returns JSON serialized text that can be safely logged.
11
- */
12
- export declare const toJSON: (value: unknown) => string;
13
7
  /**
14
8
  * This function returns a lower cased version of the headers passed to it.
15
9
  *
@@ -38,7 +32,7 @@ declare const _default: {
38
32
  isData: (value: unknown) => boolean;
39
33
  toData: (value: unknown) => DataPayload;
40
34
  toString: (value: unknown, defaultValue?: string) => string;
41
- keyValPairListToObject: <TValue = unknown>(kvpList?: KeyValuePair<unknown>[], valueConverter?: ((value: unknown) => TValue) | undefined) => Record<string, TValue>;
35
+ keyValPairListToObject: <TValue = unknown>(kvpList: KeyValuePair<unknown>[], valueConverter?: ((value: unknown) => TValue) | undefined) => Record<string, TValue>;
42
36
  isJSON: (value: string) => boolean;
43
37
  toJSON: (value: unknown) => string;
44
38
  lowerCaseHeaders: (headers: Record<string, string>) => Record<string, string>;
package/dist/util.js CHANGED
@@ -8,7 +8,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.lowerCaseHeaders = exports.toJSON = void 0;
11
+ exports.lowerCaseHeaders = void 0;
12
12
  /** */
13
13
  const parseISO_1 = __importDefault(require("date-fns/parseISO"));
14
14
  const isValid_1 = __importDefault(require("date-fns/isValid"));
@@ -197,8 +197,8 @@ const isUrl = (value) => (0, valid_url_1.isWebUri)(value) !== undefined;
197
197
  * @param kvpList An array of objects with `key` and `value` properties.
198
198
  * @param valueConverter Optional function to call for each `value`.
199
199
  */
200
- const keyValPairListToObject = (kvpList = [], valueConverter) => {
201
- return kvpList.reduce((result, { key, value }) => (Object.assign(Object.assign({}, result), { [key]: valueConverter ? valueConverter(value) : value })), {});
200
+ const keyValPairListToObject = (kvpList, valueConverter) => {
201
+ return (kvpList || []).reduce((result, { key, value }) => (Object.assign(Object.assign({}, result), { [key]: valueConverter ? valueConverter(value) : value })), {});
202
202
  };
203
203
  /**
204
204
  * This function tests if the object provided is a Prismatic `DataPayload` object.
@@ -322,7 +322,6 @@ const toJSON = (value) => {
322
322
  const stringify = (0, safe_stable_stringify_1.configure)({ circularValue: undefined });
323
323
  return stringify(value, null, 2);
324
324
  };
325
- exports.toJSON = toJSON;
326
325
  /**
327
326
  * This function returns a lower cased version of the headers passed to it.
328
327
  *
@@ -356,7 +355,7 @@ exports.default = {
356
355
  toString,
357
356
  keyValPairListToObject,
358
357
  isJSON,
359
- toJSON: exports.toJSON,
358
+ toJSON,
360
359
  lowerCaseHeaders: exports.lowerCaseHeaders,
361
360
  },
362
361
  docs: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "6.4.0",
3
+ "version": "6.5.1",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"
@@ -37,9 +37,10 @@
37
37
  "dist/"
38
38
  ],
39
39
  "dependencies": {
40
- "axios": "0.26.1",
41
- "axios-retry": "3.2.4",
40
+ "axios": "0.27.2",
41
+ "axios-retry": "3.2.5",
42
42
  "date-fns": "2.28.0",
43
+ "form-data": "4.0.0",
43
44
  "jest-mock": "27.0.3",
44
45
  "soap": "0.43.0",
45
46
  "uuid": "8.3.2",