@prismatic-io/spectral 7.0.13-pre → 7.0.16-pre
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/dist/serverTypes/index.d.ts +6 -1
- package/dist/testing.d.ts +4 -4
- package/dist/testing.js +23 -10
- package/dist/types/DataSourcePerformFunction.d.ts +8 -2
- package/dist/types/Inputs.d.ts +25 -1
- package/dist/types/Inputs.js +2 -0
- package/dist/util.d.ts +2 -1
- package/dist/util.js +32 -0
- package/package.json +1 -1
|
@@ -115,6 +115,11 @@ export interface Trigger {
|
|
|
115
115
|
examplePayload?: unknown;
|
|
116
116
|
isCommonTrigger?: boolean;
|
|
117
117
|
}
|
|
118
|
+
export interface DataSourceContext {
|
|
119
|
+
logger: ActionLogger;
|
|
120
|
+
customer: Customer;
|
|
121
|
+
instance: Instance;
|
|
122
|
+
}
|
|
118
123
|
export declare type DataSourceResult = {
|
|
119
124
|
result: DataSourceResultType;
|
|
120
125
|
supplementalData?: {
|
|
@@ -122,7 +127,7 @@ export declare type DataSourceResult = {
|
|
|
122
127
|
contentType: string;
|
|
123
128
|
};
|
|
124
129
|
};
|
|
125
|
-
export declare type DataSourcePerformFunction = (params: Record<string, unknown>) => Promise<DataSourceResult>;
|
|
130
|
+
export declare type DataSourcePerformFunction = (context: DataSourceContext, params: Record<string, unknown>) => Promise<DataSourceResult>;
|
|
126
131
|
export interface DataSource {
|
|
127
132
|
key: string;
|
|
128
133
|
display: DisplayDefinition & {
|
package/dist/testing.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult } from "./serverTypes";
|
|
7
|
+
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult, DataSourceContext } from "./serverTypes";
|
|
8
8
|
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult } from "./types";
|
|
9
9
|
export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>) => ConnectionValue;
|
|
10
10
|
/**
|
|
@@ -55,7 +55,7 @@ export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType
|
|
|
55
55
|
objectSelection: import("./types").ObjectSelection;
|
|
56
56
|
objectFieldMap: import("./types").ObjectFieldMap;
|
|
57
57
|
jsonForm: import("./types").JSONForm;
|
|
58
|
-
}>({ perform }: DataSourceDefinition<TInputs, TDataSourceType>, params: ActionInputParameters<TInputs>) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
58
|
+
}>({ perform }: DataSourceDefinition<TInputs, TDataSourceType>, params: ActionInputParameters<TInputs>, context?: Partial<DataSourceContext> | undefined) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
59
59
|
export declare class ComponentTestHarness<TComponent extends Component> {
|
|
60
60
|
component: TComponent;
|
|
61
61
|
constructor(component: TComponent);
|
|
@@ -64,7 +64,7 @@ export declare class ComponentTestHarness<TComponent extends Component> {
|
|
|
64
64
|
connectionValue({ key }: ConnectionDefinition): ConnectionValue;
|
|
65
65
|
trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>;
|
|
66
66
|
action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<ActionPerformReturn>;
|
|
67
|
-
dataSource(key: string, params?: Record<string, unknown>): Promise<DataSourceResult>;
|
|
67
|
+
dataSource(key: string, params?: Record<string, unknown>, context?: Partial<DataSourceContext>): Promise<DataSourceResult>;
|
|
68
68
|
}
|
|
69
69
|
export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
|
|
70
70
|
declare const _default: {
|
|
@@ -88,6 +88,6 @@ declare const _default: {
|
|
|
88
88
|
objectSelection: import("./types").ObjectSelection;
|
|
89
89
|
objectFieldMap: import("./types").ObjectFieldMap;
|
|
90
90
|
jsonForm: import("./types").JSONForm;
|
|
91
|
-
}>({ perform }: DataSourceDefinition<TInputs_2, TDataSourceType>, params: ActionInputParameters<TInputs_2>) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
91
|
+
}>({ perform }: DataSourceDefinition<TInputs_2, TDataSourceType>, params: ActionInputParameters<TInputs_2>, context?: Partial<DataSourceContext> | undefined) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
92
92
|
};
|
|
93
93
|
export default _default;
|
package/dist/testing.js
CHANGED
|
@@ -37,7 +37,7 @@ const loggerMock = () => ({
|
|
|
37
37
|
error: (0, jest_mock_1.spyOn)(console, "error"),
|
|
38
38
|
});
|
|
39
39
|
exports.loggerMock = loggerMock;
|
|
40
|
-
const
|
|
40
|
+
const baseActionContext = {
|
|
41
41
|
logger: (0, exports.loggerMock)(),
|
|
42
42
|
instanceState: {},
|
|
43
43
|
crossFlowState: {},
|
|
@@ -68,7 +68,7 @@ const baseContext = {
|
|
|
68
68
|
* action result and a mock logger for asserting logging.
|
|
69
69
|
*/
|
|
70
70
|
const invoke = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
-
const realizedContext = Object.assign(Object.assign({},
|
|
71
|
+
const realizedContext = Object.assign(Object.assign({}, baseActionContext), context);
|
|
72
72
|
const result = yield perform(realizedContext, params);
|
|
73
73
|
return {
|
|
74
74
|
result,
|
|
@@ -120,7 +120,7 @@ exports.defaultTriggerPayload = defaultTriggerPayload;
|
|
|
120
120
|
* trigger result and a mock logger for asserting logging.
|
|
121
121
|
*/
|
|
122
122
|
const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
-
const realizedContext = Object.assign(Object.assign({},
|
|
123
|
+
const realizedContext = Object.assign(Object.assign({}, baseActionContext), context);
|
|
124
124
|
const realizedPayload = Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload);
|
|
125
125
|
const realizedParams = params || {};
|
|
126
126
|
const result = yield perform(realizedContext, realizedPayload, realizedParams);
|
|
@@ -130,13 +130,26 @@ const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void
|
|
|
130
130
|
};
|
|
131
131
|
});
|
|
132
132
|
exports.invokeTrigger = invokeTrigger;
|
|
133
|
+
const baseDataSourceContext = {
|
|
134
|
+
logger: (0, exports.loggerMock)(),
|
|
135
|
+
customer: {
|
|
136
|
+
id: "customerId",
|
|
137
|
+
name: "Customer 1",
|
|
138
|
+
externalId: "1234",
|
|
139
|
+
},
|
|
140
|
+
instance: {
|
|
141
|
+
id: "instanceId",
|
|
142
|
+
name: "Instance 1",
|
|
143
|
+
},
|
|
144
|
+
};
|
|
133
145
|
/**
|
|
134
146
|
* Invokes specified DataSourceDefinition perform function using supplied params.
|
|
135
147
|
* Accepts a generic type matching DataSourceResult as a convenience to avoid extra
|
|
136
148
|
* casting within test methods. Returns a DataSourceResult.
|
|
137
149
|
*/
|
|
138
|
-
const invokeDataSource = ({ perform }, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
-
const
|
|
150
|
+
const invokeDataSource = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
const realizedContext = Object.assign(Object.assign({}, baseDataSourceContext), context);
|
|
152
|
+
const result = yield perform(realizedContext, params);
|
|
140
153
|
return result;
|
|
141
154
|
});
|
|
142
155
|
exports.invokeDataSource = invokeDataSource;
|
|
@@ -144,7 +157,7 @@ class ComponentTestHarness {
|
|
|
144
157
|
constructor(component) {
|
|
145
158
|
this.component = component;
|
|
146
159
|
}
|
|
147
|
-
buildContext(context) {
|
|
160
|
+
buildContext(baseContext, context) {
|
|
148
161
|
return Object.assign(Object.assign({}, baseContext), context);
|
|
149
162
|
}
|
|
150
163
|
buildParams(inputs, params) {
|
|
@@ -162,19 +175,19 @@ class ComponentTestHarness {
|
|
|
162
175
|
trigger(key, payload, params, context) {
|
|
163
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
177
|
const trigger = this.component.triggers[key];
|
|
165
|
-
return trigger.perform(this.buildContext(context), Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), this.buildParams(trigger.inputs, params));
|
|
178
|
+
return trigger.perform(this.buildContext(baseActionContext, context), Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), this.buildParams(trigger.inputs, params));
|
|
166
179
|
});
|
|
167
180
|
}
|
|
168
181
|
action(key, params, context) {
|
|
169
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
170
183
|
const action = this.component.actions[key];
|
|
171
|
-
return action.perform(this.buildContext(context), this.buildParams(action.inputs, params));
|
|
184
|
+
return action.perform(this.buildContext(baseActionContext, context), this.buildParams(action.inputs, params));
|
|
172
185
|
});
|
|
173
186
|
}
|
|
174
|
-
dataSource(key, params) {
|
|
187
|
+
dataSource(key, params, context) {
|
|
175
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
189
|
const dataSource = this.component.dataSources[key];
|
|
177
|
-
return dataSource.perform(this.buildParams(dataSource.inputs, params));
|
|
190
|
+
return dataSource.perform(this.buildContext(baseDataSourceContext, context), this.buildParams(dataSource.inputs, params));
|
|
178
191
|
});
|
|
179
192
|
}
|
|
180
193
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import { Inputs, DataSourceResult, DataSourceType, ActionInputParameters } from ".";
|
|
1
|
+
import { Inputs, DataSourceResult, DataSourceType, ActionInputParameters, ActionLogger, Customer, Instance } from ".";
|
|
2
|
+
/** Context provided to perform method containing helpers and contextual data */
|
|
3
|
+
export interface DataSourceContext {
|
|
4
|
+
logger: ActionLogger;
|
|
5
|
+
customer: Customer;
|
|
6
|
+
instance: Instance;
|
|
7
|
+
}
|
|
2
8
|
/** Definition of the function to perform when a Data Source is invoked. */
|
|
3
|
-
export declare type DataSourcePerformFunction<TInputs extends Inputs, TDataSourceType extends DataSourceType> = (params: ActionInputParameters<TInputs>) => Promise<DataSourceResult<TDataSourceType>>;
|
|
9
|
+
export declare type DataSourcePerformFunction<TInputs extends Inputs, TDataSourceType extends DataSourceType> = (context: DataSourceContext, params: ActionInputParameters<TInputs>) => Promise<DataSourceResult<TDataSourceType>>;
|
package/dist/types/Inputs.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare type JSONForm = {
|
|
|
26
26
|
uiSchema: Record<string, unknown>;
|
|
27
27
|
data: unknown;
|
|
28
28
|
};
|
|
29
|
+
export declare type DynamicObjectSelection = string;
|
|
30
|
+
export declare type DynamicFieldSelection = string;
|
|
29
31
|
/** InputField type enumeration. */
|
|
30
32
|
export declare type InputFieldType = InputFieldDefinition["type"];
|
|
31
33
|
export declare const InputFieldDefaultMap: Record<InputFieldType, string | undefined>;
|
|
@@ -33,7 +35,7 @@ export declare type Inputs = Record<string, InputFieldDefinition>;
|
|
|
33
35
|
export declare type ConnectionInput = (StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField) & {
|
|
34
36
|
shown?: boolean;
|
|
35
37
|
};
|
|
36
|
-
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField | JSONFormInputField;
|
|
38
|
+
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField | JSONFormInputField | DynamicObjectSelectionInputField | DynamicFieldSelectionInputField;
|
|
37
39
|
export declare type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult;
|
|
38
40
|
interface BaseInputField {
|
|
39
41
|
/** Interface label of the InputField. */
|
|
@@ -192,6 +194,28 @@ export interface JSONFormInputField extends BaseInputField {
|
|
|
192
194
|
/** Clean function */
|
|
193
195
|
clean?: InputCleanFunction<NonNullable<this["default"]>>;
|
|
194
196
|
}
|
|
197
|
+
/** Defines attributes of a DynamicObjectSelectionInputField */
|
|
198
|
+
export interface DynamicObjectSelectionInputField extends BaseInputField {
|
|
199
|
+
/** Data type the InputField will collect. */
|
|
200
|
+
type: "dynamicObjectSelection";
|
|
201
|
+
/** Collection type of the InputField */
|
|
202
|
+
collection?: InputFieldCollection;
|
|
203
|
+
/** Default value for this field. */
|
|
204
|
+
default?: unknown;
|
|
205
|
+
/** Clean function */
|
|
206
|
+
clean?: InputCleanFunction<NonNullable<this["default"]>>;
|
|
207
|
+
}
|
|
208
|
+
/** Defines attributes of a SelectedFieldInputField */
|
|
209
|
+
export interface DynamicFieldSelectionInputField extends BaseInputField {
|
|
210
|
+
/** Data type the InputField will collect. */
|
|
211
|
+
type: "dynamicFieldSelection";
|
|
212
|
+
/** Collection type of the InputField */
|
|
213
|
+
collection?: InputFieldCollection;
|
|
214
|
+
/** Default value for this field. */
|
|
215
|
+
default?: unknown;
|
|
216
|
+
/** Clean function */
|
|
217
|
+
clean?: InputCleanFunction<NonNullable<this["default"]>>;
|
|
218
|
+
}
|
|
195
219
|
/** Defines a single Choice option for a InputField. */
|
|
196
220
|
export interface InputFieldChoice {
|
|
197
221
|
/** Label to display for this Choice. */
|
package/dist/types/Inputs.js
CHANGED
package/dist/util.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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 { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap, JSONForm } from "./types";
|
|
6
|
+
import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap, JSONForm, ConnectionDefinition } from "./types";
|
|
7
7
|
/**
|
|
8
8
|
* This function returns a lower cased version of the headers passed to it.
|
|
9
9
|
*
|
|
@@ -45,6 +45,7 @@ declare const _default: {
|
|
|
45
45
|
toJSONForm: (value: unknown) => JSONForm;
|
|
46
46
|
isPicklist: (value: unknown) => boolean;
|
|
47
47
|
isSchedule: (value: unknown) => boolean;
|
|
48
|
+
isConnection: (value: unknown) => value is ConnectionDefinition;
|
|
48
49
|
};
|
|
49
50
|
docs: {
|
|
50
51
|
formatJsonExample: (input: unknown) => string;
|
package/dist/util.js
CHANGED
|
@@ -405,6 +405,37 @@ const isString = (value) => typeof value === "string" || value instanceof String
|
|
|
405
405
|
* @returns This function returns the stringified version fo `value`, or `defaultValue` in the case that `value` is undefined or an empty string.
|
|
406
406
|
*/
|
|
407
407
|
const toString = (value, defaultValue = "") => `${value !== null && value !== void 0 ? value : defaultValue}`;
|
|
408
|
+
/**
|
|
409
|
+
* This function checks if value is a valid connection.
|
|
410
|
+
* @param value The variable to test.
|
|
411
|
+
* @returns This function returns true or false, depending on if `value` is a valid connection.
|
|
412
|
+
*/
|
|
413
|
+
const isConnection = (value) => {
|
|
414
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
415
|
+
return isConnection(JSON.parse(value));
|
|
416
|
+
}
|
|
417
|
+
if (Boolean(value) && typeof value === "object") {
|
|
418
|
+
const { inputs } = value;
|
|
419
|
+
if (isObjectWithTruthyKeys(value, ["key", "label", "oauth2Type"])) {
|
|
420
|
+
return (isObjectWithTruthyKeys(inputs, [
|
|
421
|
+
"authorizeUrl",
|
|
422
|
+
"tokenUrl",
|
|
423
|
+
"scopes",
|
|
424
|
+
"clientId",
|
|
425
|
+
"clientSecret",
|
|
426
|
+
]) ||
|
|
427
|
+
isObjectWithTruthyKeys(inputs, [
|
|
428
|
+
"tokenUrl",
|
|
429
|
+
"scopes",
|
|
430
|
+
"clientId",
|
|
431
|
+
"clientSecret",
|
|
432
|
+
]));
|
|
433
|
+
}
|
|
434
|
+
return (isObjectWithTruthyKeys(value, ["key", "label"]) &&
|
|
435
|
+
typeof inputs === "object");
|
|
436
|
+
}
|
|
437
|
+
return false;
|
|
438
|
+
};
|
|
408
439
|
/**
|
|
409
440
|
* This function returns true if `value` resembles the shape of JSON, and false otherwise.
|
|
410
441
|
*
|
|
@@ -478,6 +509,7 @@ exports.default = {
|
|
|
478
509
|
toJSONForm,
|
|
479
510
|
isPicklist,
|
|
480
511
|
isSchedule,
|
|
512
|
+
isConnection,
|
|
481
513
|
},
|
|
482
514
|
docs: {
|
|
483
515
|
formatJsonExample,
|