@prismatic-io/spectral 5.3.0 → 6.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.
Files changed (41) hide show
  1. package/dist/clients/http/index.d.ts +13 -0
  2. package/dist/clients/http/index.js +46 -0
  3. package/dist/clients/http/inputs.d.ts +116 -0
  4. package/dist/clients/http/inputs.js +134 -0
  5. package/dist/clients/soap/index.js +5 -1
  6. package/dist/clients/soap/types.js +1 -2
  7. package/dist/clients/soap/utils.js +12 -12
  8. package/dist/errors.js +1 -1
  9. package/dist/index.d.ts +6 -10
  10. package/dist/index.js +8 -57
  11. package/dist/serverTypes/convert.d.ts +3 -0
  12. package/dist/serverTypes/convert.js +60 -0
  13. package/dist/serverTypes/index.d.ts +169 -0
  14. package/dist/serverTypes/index.js +7 -0
  15. package/dist/testing.d.ts +5 -5
  16. package/dist/testing.js +20 -15
  17. package/dist/types/ActionDefinition.d.ts +6 -6
  18. package/dist/types/ActionInputParameters.d.ts +3 -3
  19. package/dist/types/ActionLogger.d.ts +1 -1
  20. package/dist/types/ActionLogger.js +1 -1
  21. package/dist/types/ActionPerformFunction.d.ts +4 -2
  22. package/dist/types/ActionPerformReturn.d.ts +4 -2
  23. package/dist/types/ComponentDefinition.d.ts +28 -6
  24. package/dist/types/DataPayload.d.ts +10 -0
  25. package/dist/types/DataPayload.js +2 -0
  26. package/dist/types/Inputs.d.ts +9 -3
  27. package/dist/types/TriggerDefinition.d.ts +6 -6
  28. package/dist/types/TriggerPayload.d.ts +8 -0
  29. package/dist/types/TriggerPerformFunction.d.ts +1 -1
  30. package/dist/types/TriggerResult.d.ts +5 -3
  31. package/dist/types/conditional-logic.d.ts +1 -1
  32. package/dist/types/conditional-logic.js +1 -1
  33. package/dist/types/index.d.ts +1 -1
  34. package/dist/types/index.js +6 -15
  35. package/dist/util.d.ts +9 -3
  36. package/dist/util.js +20 -7
  37. package/package.json +31 -44
  38. package/dist/types/server-types.d.ts +0 -172
  39. package/dist/types/server-types.js +0 -8
  40. package/dist/util.test.d.ts +0 -1
  41. package/dist/util.test.js +0 -305
package/dist/util.d.ts CHANGED
@@ -3,8 +3,13 @@
3
3
  * Many functions in the `util` module are used to coerce data into a particular type, and can be accessed through `util.types`.
4
4
  * For example, `util.types.toInt("5.5")` will return an integer, `5`.
5
5
  */
6
- import { DataPayload } from "./types/server-types";
7
- import { KeyValuePair } from "./types";
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;
8
13
  /**
9
14
  * This function returns a lower cased version of the headers passed to it.
10
15
  *
@@ -33,8 +38,9 @@ declare const _default: {
33
38
  isData: (value: unknown) => boolean;
34
39
  toData: (value: unknown) => DataPayload;
35
40
  toString: (value: unknown, defaultValue?: string) => string;
36
- keyValPairListToObject: (kvpList?: KeyValuePair<unknown>[]) => Record<string, unknown>;
41
+ keyValPairListToObject: <TValue = unknown>(kvpList?: KeyValuePair<unknown>[], valueConverter?: ((value: unknown) => TValue) | undefined) => Record<string, TValue>;
37
42
  isJSON: (value: string) => boolean;
43
+ toJSON: (value: unknown) => string;
38
44
  lowerCaseHeaders: (headers: Record<string, string>) => Record<string, string>;
39
45
  };
40
46
  docs: {
package/dist/util.js CHANGED
@@ -8,11 +8,12 @@ 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 = void 0;
11
+ exports.lowerCaseHeaders = exports.toJSON = void 0;
12
12
  /** */
13
13
  const parseISO_1 = __importDefault(require("date-fns/parseISO"));
14
14
  const isValid_1 = __importDefault(require("date-fns/isValid"));
15
15
  const isDate_1 = __importDefault(require("date-fns/isDate"));
16
+ const safe_stable_stringify_1 = require("safe-stable-stringify");
16
17
  const valid_url_1 = require("valid-url");
17
18
  /**
18
19
  * Determine if a variable is a boolean (true or false).
@@ -152,7 +153,7 @@ const toBigInt = (value) => {
152
153
  }
153
154
  };
154
155
  /** This function returns true if `value` is a variable of type `Date`, and false otherwise. */
155
- const isDate = (value) => isDate_1.default(value);
156
+ const isDate = (value) => (0, isDate_1.default)(value);
156
157
  /**
157
158
  * This function parses an ISO date if possible, or throws an error if the value provided
158
159
  * cannot be coerced into a Date object.
@@ -168,8 +169,8 @@ const toDate = (value) => {
168
169
  return value;
169
170
  }
170
171
  if (typeof value === "string") {
171
- const dt = parseISO_1.default(value);
172
- if (isValid_1.default(dt)) {
172
+ const dt = (0, parseISO_1.default)(value);
173
+ if ((0, isValid_1.default)(dt)) {
173
174
  return dt;
174
175
  }
175
176
  }
@@ -185,7 +186,7 @@ const toDate = (value) => {
185
186
  * @param value The URL to test.
186
187
  * @returns This function returns true if `value` is a valid URL, and false otherwise.
187
188
  */
188
- const isUrl = (value) => valid_url_1.isWebUri(value) !== undefined;
189
+ const isUrl = (value) => (0, valid_url_1.isWebUri)(value) !== undefined;
189
190
  /**
190
191
  * This function helps to transform key-value lists to objects.
191
192
  * This is useful for transforming inputs that are key-value collections into objects.
@@ -194,9 +195,10 @@ const isUrl = (value) => valid_url_1.isWebUri(value) !== undefined;
194
195
  * If that array were passed into `util.types.keyValPairListToObject()`, an object would be returned of the form
195
196
  * `{foo: "bar", baz: 5}`.
196
197
  * @param kvpList An array of objects with `key` and `value` properties.
198
+ * @param valueConverter Optional function to call for each `value`.
197
199
  */
198
- const keyValPairListToObject = (kvpList = []) => {
199
- return kvpList.reduce((result, { key, value }) => (Object.assign(Object.assign({}, result), { [key]: value })), {});
200
+ const keyValPairListToObject = (kvpList = [], valueConverter) => {
201
+ return kvpList.reduce((result, { key, value }) => (Object.assign(Object.assign({}, result), { [key]: valueConverter ? valueConverter(value) : value })), {});
200
202
  };
201
203
  /**
202
204
  * This function tests if the object provided is a Prismatic `DataPayload` object.
@@ -311,6 +313,16 @@ const isJSON = (value) => {
311
313
  return false;
312
314
  }
313
315
  };
316
+ /** This function accepts an arbitrary object/value and safely serializes it (handles cyclic references).
317
+ *
318
+ * @param value Arbitrary object/value to serialize.
319
+ * @returns JSON serialized text that can be safely logged.
320
+ */
321
+ const toJSON = (value) => {
322
+ const stringify = (0, safe_stable_stringify_1.configure)({ circularValue: undefined });
323
+ return stringify(value, null, 2);
324
+ };
325
+ exports.toJSON = toJSON;
314
326
  /**
315
327
  * This function returns a lower cased version of the headers passed to it.
316
328
  *
@@ -344,6 +356,7 @@ exports.default = {
344
356
  toString,
345
357
  keyValPairListToObject,
346
358
  isJSON,
359
+ toJSON: exports.toJSON,
347
360
  lowerCaseHeaders: exports.lowerCaseHeaders,
348
361
  },
349
362
  docs: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "5.3.0",
3
+ "version": "6.1.0",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"
@@ -15,6 +15,10 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/prismatic-io/spectral.git"
17
17
  },
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "registry": "https://registry.npmjs.org/"
21
+ },
18
22
  "license": "MIT",
19
23
  "scripts": {
20
24
  "clean": "rm -rf dist",
@@ -23,68 +27,51 @@
23
27
  "format": "yarn run lint-fix && prettier --loglevel error --write 'src/**/*.ts' '*.{ts,js,json}' '!sidebars.{js,jse}'",
24
28
  "check-format": "prettier --check 'src/**/*.ts' '*.{ts,js,json}' '!sidebars.{js,jse}'",
25
29
  "check": "yarn run check-format && yarn run lint",
26
- "lint": "eslint --ext .ts,.js src/",
27
- "lint-fix": "eslint --fix --ext .ts,.js src/",
30
+ "lint": "eslint --ext .ts .",
31
+ "lint-fix": "eslint --fix --ext .ts .",
28
32
  "test": "jest --maxWorkers=4",
33
+ "tsd": "tsd",
29
34
  "docs": "rm -f sidebars.{js,jse} && typedoc"
30
35
  },
31
36
  "files": [
32
37
  "dist/"
33
38
  ],
34
39
  "dependencies": {
35
- "axios": "0.24.0",
36
- "date-fns": "2.17.0",
40
+ "axios": "0.26.1",
41
+ "axios-retry": "3.2.4",
42
+ "date-fns": "2.28.0",
37
43
  "jest-mock": "27.0.3",
38
44
  "soap": "0.43.0",
39
- "uuid": "8.3.1",
40
- "valid-url": "1.0.9"
45
+ "uuid": "8.3.2",
46
+ "valid-url": "1.0.9",
47
+ "url-join": "5.0.0",
48
+ "safe-stable-stringify": "2.3.1",
49
+ "serialize-error": "8.1.0"
41
50
  },
42
51
  "devDependencies": {
43
- "@types/axios": "0.14.0",
44
- "@types/jest": "26.0.23",
52
+ "@types/jest": "27.4.1",
45
53
  "@types/node": "14.14.35",
46
54
  "@types/sax": "1.2.4",
47
- "@types/uuid": "8.3.1",
55
+ "@types/uuid": "8.3.4",
56
+ "@types/url-join": "4.0.1",
48
57
  "@types/valid-url": "1.0.3",
49
- "@typescript-eslint/eslint-plugin": "4.27.0",
50
- "@typescript-eslint/parser": "4.27.0",
51
- "eslint": "7.28.0",
52
- "eslint-config-prettier": "8.3.0",
53
- "eslint-plugin-jest": "24.3.6",
54
- "eslint-plugin-prettier": "3.4.0",
58
+ "@typescript-eslint/eslint-plugin": "5.18.0",
59
+ "@typescript-eslint/parser": "5.18.0",
60
+ "eslint": "8.12.0",
61
+ "eslint-config-prettier": "8.5.0",
62
+ "eslint-plugin-jest": "26.1.3",
63
+ "eslint-plugin-prettier": "4.0.0",
55
64
  "fast-check": "2.16.0",
56
- "jest": "27.0.4",
57
- "prettier": "2.3.1",
65
+ "jest": "27.5.1",
66
+ "prettier": "2.6.2",
58
67
  "ts-jest": "27.0.3",
59
68
  "typedoc": "0.17.7",
60
69
  "typedoc-plugin-markdown": "2.4.2",
61
70
  "typedoc-plugin-remove-references": "0.0.5",
62
- "typescript": "4.3.4"
71
+ "typescript": "4.6.3",
72
+ "tsd": "0.20.0"
63
73
  },
64
- "eslintConfig": {
65
- "root": true,
66
- "parser": "@typescript-eslint/parser",
67
- "env": {
68
- "node": true
69
- },
70
- "parserOptions": {
71
- "project": [
72
- "./tsconfig.json"
73
- ]
74
- },
75
- "plugins": [
76
- "@typescript-eslint"
77
- ],
78
- "extends": [
79
- "eslint:recommended",
80
- "plugin:@typescript-eslint/eslint-recommended",
81
- "plugin:@typescript-eslint/recommended",
82
- "plugin:@typescript-eslint/recommended-requiring-type-checking",
83
- "prettier"
84
- ],
85
- "rules": {
86
- "@typescript-eslint/explicit-function-return-type": "off",
87
- "@typescript-eslint/restrict-template-expressions": "off"
88
- }
74
+ "tsd": {
75
+ "directory": "./src/types-tests"
89
76
  }
90
77
  }
@@ -1,172 +0,0 @@
1
- /**
2
- * Types defined in this module describe the shape of objects that are
3
- * sent to Prismatic's API when a component is published. Types defined
4
- * should not generally be imported directly, but they're the types of
5
- * objects that are created by `component()` and `action()` helper functions.
6
- */
7
- /// <reference types="node" />
8
- /** Import shared types from types/ */
9
- import { OAuth2Type, InputFieldType, InputFieldDefaultMap } from ".";
10
- import { ActionContext } from "./ActionPerformFunction";
11
- import { ActionDisplayDefinition, ComponentDisplayDefinition } from "./DisplayDefinition";
12
- import { InputFieldChoice, InputFieldCollection } from "./Inputs";
13
- import { TriggerOptionChoice } from "./TriggerDefinition";
14
- import { TriggerPayload as _TriggerPayload } from "./TriggerPayload";
15
- import { TriggerBaseResult, TriggerBranchingResult } from "./TriggerResult";
16
- /** Defines attributes of a Component. */
17
- interface ComponentBase<TPublic extends boolean> {
18
- /** Specifies unique key for this Component. */
19
- key: string;
20
- /** Specifies if this Component is available for all Organizations or only your own @default false */
21
- public?: TPublic;
22
- /** Defines how the Component is displayed in the Prismatic interface. */
23
- display: ComponentDisplayDefinition<TPublic>;
24
- /** Specifies the supported Actions of this Component. */
25
- actions?: Record<string, Action>;
26
- /** Specifies the supported Triggers of this Component. */
27
- triggers?: Record<string, Trigger>;
28
- /** Specifies the supported Connections of this Component. */
29
- connections?: Connection[];
30
- }
31
- export declare type Component<TPublic extends boolean> = ComponentBase<TPublic> & (TPublic extends true ? {
32
- /** Specified the URL for the Component Documentation. */
33
- documentationUrl: string;
34
- } : {
35
- /** Specified the URL for the Component Documentation. */
36
- documentationUrl?: string;
37
- });
38
- /** Base properties of Actions and Triggers. */
39
- interface BaseAction {
40
- /** Key used for the Actions map and to uniquely identify this Component in your tenant. */
41
- key: string;
42
- /** Defines how the Action is displayed in the Prismatic interface. */
43
- display: ActionDisplayDefinition;
44
- /** InputFields to present in the Prismatic interface for configuration of this Action. */
45
- inputs: InputField[];
46
- /** Optional attribute that specifies whether an Action will terminate execution. */
47
- terminateExecution?: boolean;
48
- /** Specifies whether an Action will break out of a loop. */
49
- breakLoop?: boolean;
50
- /** Determines whether an Action will allow Conditional Branching. */
51
- allowsBranching?: boolean;
52
- /** Static Branch names associated with an Action. */
53
- staticBranchNames?: string[];
54
- /** The Input associated with Dynamic Branching. */
55
- dynamicBranchInput?: string;
56
- }
57
- /** Configuration of an Action. */
58
- export interface Action extends BaseAction {
59
- /** Function to perform when this Action is used and invoked. */
60
- perform: ActionPerformFunction;
61
- /** An example of the payload outputted by an Action. */
62
- examplePayload?: ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn;
63
- }
64
- /** Configuration of a Trigger. */
65
- export interface Trigger extends BaseAction {
66
- /** Function to perform when this Trigger is used and invoked. */
67
- perform: TriggerPerformFunction;
68
- /** Specifies whether this Trigger supports executing the Integration on a recurring schedule. */
69
- scheduleSupport: TriggerOptionChoice;
70
- /** Specifies whether this Trigger supports synchronous responses to an Integration webhook request. */
71
- synchronousResponseSupport: TriggerOptionChoice;
72
- /** An example of the payload outputted by this Trigger. */
73
- examplePayload?: TriggerBaseResult | TriggerBranchingResult;
74
- /** Specifies if this Trigger appears in the list of 'common' Triggers. Only configurable by Prismatic. @default false */
75
- isCommonTrigger?: boolean;
76
- }
77
- export interface Connection {
78
- key: string;
79
- label: string;
80
- comments?: string;
81
- oauth2Type?: OAuth2Type;
82
- iconPath?: string;
83
- inputs: (InputField & {
84
- shown?: boolean;
85
- })[];
86
- }
87
- /** Collection of input parameters provided by the user or previous steps' outputs */
88
- interface ActionInputParameters {
89
- [key: string]: unknown;
90
- }
91
- /** Used to represent returning conventional data and does not require content type to be specified */
92
- export interface ServerPerformDataStructureReturn {
93
- /** Data structure to return from the action */
94
- data: boolean | number | string | Record<string, unknown> | unknown[] | unknown;
95
- /** The Content Type of the payload data that can be optionally specified */
96
- contentType?: string;
97
- /** The HTTP Status code that will be used if this terminates a synchronous invocation */
98
- statusCode?: number;
99
- /** An optional object, the keys and values of which will be persisted in the instanceState and available for subsequent actions and executions */
100
- instanceState?: Record<string, unknown>;
101
- /** An optional object, the keys and values of which will be persisted in the executionState and available for the duration of the execution */
102
- executionState?: Record<string, unknown>;
103
- }
104
- /** Used to represent a binary or serialized data return as content type must be specified */
105
- interface ServerPerformDataReturn {
106
- /** Data payload containing data of the specified contentType */
107
- data: Buffer | string | unknown;
108
- /** The Content Type of the payload data */
109
- contentType: string;
110
- /** The HTTP Status code that will be used if this terminates a synchronous invocation */
111
- statusCode?: number;
112
- /** An optional object, the keys and values of which will be persisted in the instanceState and available for subsequent actions and executions */
113
- instanceState?: Record<string, unknown>;
114
- /** An optional object, the keys and values of which will be persisted in the executionState and available for the duration of the execution */
115
- executionState?: Record<string, unknown>;
116
- }
117
- /** Used to represent a branching return of conventional data and does not require content type to be specified */
118
- export interface ServerPerformBranchingDataStructureReturn extends ServerPerformDataStructureReturn {
119
- /** Name of the Branch to take. */
120
- branch: string;
121
- }
122
- /** Used to represent a binary or serialized data branching return as content type must be specified */
123
- interface ServerPerformBranchingDataReturn extends ServerPerformDataReturn {
124
- /** Name of the Branch to take. */
125
- branch: string;
126
- }
127
- /** Required return type of all action perform functions */
128
- export declare type ActionPerformReturn = ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn | ServerPerformDataReturn | ServerPerformBranchingDataReturn | undefined;
129
- /** Definition of the function to perform when an Action is invoked. */
130
- export declare type ActionPerformFunction = (context: ActionContext, params: ActionInputParameters) => Promise<ActionPerformReturn>;
131
- export declare type TriggerResult = TriggerBranchingResult | TriggerBaseResult | undefined;
132
- /** Definition of the function to perform when a Trigger is invoked. */
133
- export declare type TriggerPerformFunction = (context: ActionContext, payload: TriggerPayload, params: ActionInputParameters) => Promise<TriggerResult>;
134
- export declare type TriggerPayload = _TriggerPayload;
135
- export declare type InputField = DefaultInputField | CodeInputField;
136
- /** Defines attributes of a InputField. */
137
- interface DefaultInputField {
138
- /** Unique identifier of the InputField. Must be unique within an Action. */
139
- key: string;
140
- /** Interface label of the InputField. */
141
- label: string;
142
- /** Data type the InputField will collect. */
143
- type: InputFieldType;
144
- /** Collection type of the InputField */
145
- collection?: InputFieldCollection;
146
- /** Text to show as the InputField placeholder. */
147
- placeholder?: string;
148
- /** Default value for this field. */
149
- default?: typeof InputFieldDefaultMap[this["type"]];
150
- /** Additional text to give guidance to the user configuring the InputField. */
151
- comments?: string;
152
- /** Example valid input for this InputField. */
153
- example?: string;
154
- /** Indicate if this InputField is required. */
155
- required?: boolean;
156
- /** Dictates possible choices for the input. */
157
- model?: InputFieldChoice[];
158
- }
159
- interface CodeInputField extends DefaultInputField {
160
- type: "code";
161
- language?: string;
162
- }
163
- /** Binary data payload */
164
- export interface DataPayload {
165
- /** Raw binary data as a Buffer */
166
- data: Buffer;
167
- /** Content type of data contained within this payload */
168
- contentType: string;
169
- /** Suggested extension to use when writing the data */
170
- suggestedExtension?: string;
171
- }
172
- export {};
@@ -1,8 +0,0 @@
1
- "use strict";
2
- /**
3
- * Types defined in this module describe the shape of objects that are
4
- * sent to Prismatic's API when a component is published. Types defined
5
- * should not generally be imported directly, but they're the types of
6
- * objects that are created by `component()` and `action()` helper functions.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export {};