@prismatic-io/spectral 7.0.0-pre → 7.0.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/dist/index.d.ts +18 -2
- package/dist/serverTypes/convert.js +4 -2
- package/dist/serverTypes/index.d.ts +16 -23
- package/dist/serverTypes/perform.js +4 -0
- package/dist/testing.d.ts +42 -9
- package/dist/testing.js +30 -18
- package/dist/types/ActionPerformFunction.d.ts +5 -12
- package/dist/types/Customer.d.ts +6 -0
- package/dist/types/{DataSourceType.js → Customer.js} +0 -0
- package/dist/types/DataSourceDefinition.d.ts +8 -4
- package/dist/types/DataSourcePerformFunction.d.ts +8 -2
- package/dist/types/DataSourceResult.d.ts +29 -4
- package/dist/types/Inputs.d.ts +65 -4
- package/dist/types/Inputs.js +5 -2
- package/dist/types/Instance.d.ts +5 -0
- package/dist/types/Instance.js +2 -0
- package/dist/types/TriggerPayload.d.ts +5 -9
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +16 -1
- package/dist/util.d.ts +7 -1
- package/dist/util.js +103 -35
- package/package.json +1 -1
- package/dist/types/DataSourceType.d.ts +0 -20
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, ActionPerformReturn, TriggerResult, DataSourceDefinition
|
|
6
|
+
import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition } from "./types";
|
|
7
7
|
import { convertComponent } from "./serverTypes/convert";
|
|
8
8
|
/**
|
|
9
9
|
* This function creates a component object that can be
|
|
@@ -43,7 +43,23 @@ export declare const trigger: <TInputs extends Inputs, TAllowsBranching extends
|
|
|
43
43
|
* @param definition A DataSourceDefinition type object that includes UI display information, a function to perform when the data source is invoked, and a an object containing inputs for the perform function.
|
|
44
44
|
* @returns This function validates the shape of the `definition` object provided, and returns the same data source object.
|
|
45
45
|
*/
|
|
46
|
-
export declare const dataSource: <TInputs extends Inputs,
|
|
46
|
+
export declare const dataSource: <TInputs extends Inputs, TDataSourceType extends keyof {
|
|
47
|
+
string: string;
|
|
48
|
+
date: string;
|
|
49
|
+
timestamp: string;
|
|
50
|
+
picklist: string[];
|
|
51
|
+
schedule: {
|
|
52
|
+
value: string;
|
|
53
|
+
};
|
|
54
|
+
code: string;
|
|
55
|
+
credential: unknown;
|
|
56
|
+
boolean: boolean;
|
|
57
|
+
number: number;
|
|
58
|
+
connection: import("./types").ConnectionDefinition;
|
|
59
|
+
objectSelection: import("./types").ObjectSelection;
|
|
60
|
+
objectFieldMap: import("./types").ObjectFieldMap;
|
|
61
|
+
jsonForm: import("./types").JSONForm;
|
|
62
|
+
}>(definition: DataSourceDefinition<TInputs, TDataSourceType>) => DataSourceDefinition<TInputs, TDataSourceType>;
|
|
47
63
|
/**
|
|
48
64
|
* For information and examples on how to write inputs
|
|
49
65
|
* for custom component actions and triggers, see
|
|
@@ -34,16 +34,18 @@ const convertAction = (actionKey, _a, hooks) => {
|
|
|
34
34
|
const convertTrigger = (triggerKey, _a, hooks) => {
|
|
35
35
|
var { inputs = {}, perform } = _a, trigger = __rest(_a, ["inputs", "perform"]);
|
|
36
36
|
const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
|
|
37
|
+
const inputCleaners = Object.entries(inputs).reduce((result, [key, { clean }]) => (Object.assign(Object.assign({}, result), { [key]: clean })), {});
|
|
37
38
|
return Object.assign(Object.assign({}, trigger), { key: triggerKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
|
|
38
|
-
inputCleaners
|
|
39
|
+
inputCleaners,
|
|
39
40
|
errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
|
|
40
41
|
}) });
|
|
41
42
|
};
|
|
42
43
|
const convertDataSource = (dataSourceKey, _a, hooks) => {
|
|
43
44
|
var { inputs = {}, perform } = _a, dataSource = __rest(_a, ["inputs", "perform"]);
|
|
44
45
|
const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
|
|
46
|
+
const inputCleaners = Object.entries(inputs).reduce((result, [key, { clean }]) => (Object.assign(Object.assign({}, result), { [key]: clean })), {});
|
|
45
47
|
return Object.assign(Object.assign({}, dataSource), { key: dataSourceKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
|
|
46
|
-
inputCleaners
|
|
48
|
+
inputCleaners,
|
|
47
49
|
errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
|
|
48
50
|
}) });
|
|
49
51
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { DataSourceType } from "../types";
|
|
2
|
+
import { Instance, Customer, DataSourceType, DataSourceResultType } from "../types";
|
|
3
3
|
interface DisplayDefinition {
|
|
4
4
|
label: string;
|
|
5
5
|
description: string;
|
|
6
6
|
}
|
|
7
|
+
export { Instance } from "../types";
|
|
8
|
+
export { Customer } from "../types";
|
|
7
9
|
export interface Component {
|
|
8
10
|
key: string;
|
|
9
11
|
public?: boolean;
|
|
@@ -52,15 +54,8 @@ export interface ActionContext {
|
|
|
52
54
|
webhookUrls: Record<string, string>;
|
|
53
55
|
webhookApiKeys: Record<string, string[]>;
|
|
54
56
|
invokeUrl: string;
|
|
55
|
-
customer:
|
|
56
|
-
|
|
57
|
-
externalId: string | null;
|
|
58
|
-
name: string | null;
|
|
59
|
-
};
|
|
60
|
-
instance: {
|
|
61
|
-
id: string | null;
|
|
62
|
-
name: string | null;
|
|
63
|
-
};
|
|
57
|
+
customer: Customer;
|
|
58
|
+
instance: Instance;
|
|
64
59
|
}
|
|
65
60
|
declare type TriggerOptionChoice = "invalid" | "valid" | "required";
|
|
66
61
|
export interface TriggerPayload {
|
|
@@ -79,15 +74,8 @@ export interface TriggerPayload {
|
|
|
79
74
|
webhookApiKeys: Record<string, string[]>;
|
|
80
75
|
invokeUrl: string;
|
|
81
76
|
executionId: string;
|
|
82
|
-
customer:
|
|
83
|
-
|
|
84
|
-
externalId: string | null;
|
|
85
|
-
name: string | null;
|
|
86
|
-
};
|
|
87
|
-
instance: {
|
|
88
|
-
id: string | null;
|
|
89
|
-
name: string | null;
|
|
90
|
-
};
|
|
77
|
+
customer: Customer;
|
|
78
|
+
instance: Instance;
|
|
91
79
|
}
|
|
92
80
|
interface HttpResponse {
|
|
93
81
|
statusCode: number;
|
|
@@ -127,14 +115,19 @@ export interface Trigger {
|
|
|
127
115
|
examplePayload?: unknown;
|
|
128
116
|
isCommonTrigger?: boolean;
|
|
129
117
|
}
|
|
118
|
+
export interface DataSourceContext {
|
|
119
|
+
logger: ActionLogger;
|
|
120
|
+
customer: Customer;
|
|
121
|
+
instance: Instance;
|
|
122
|
+
}
|
|
130
123
|
export declare type DataSourceResult = {
|
|
131
|
-
|
|
132
|
-
supplementalData
|
|
124
|
+
result: DataSourceResultType;
|
|
125
|
+
supplementalData?: {
|
|
133
126
|
data: unknown;
|
|
134
127
|
contentType: string;
|
|
135
128
|
};
|
|
136
129
|
};
|
|
137
|
-
export declare type DataSourcePerformFunction = (context:
|
|
130
|
+
export declare type DataSourcePerformFunction = (context: DataSourceContext, params: Record<string, unknown>) => Promise<DataSourceResult>;
|
|
138
131
|
export interface DataSource {
|
|
139
132
|
key: string;
|
|
140
133
|
display: DisplayDefinition & {
|
|
@@ -143,6 +136,7 @@ export interface DataSource {
|
|
|
143
136
|
};
|
|
144
137
|
inputs: Input[];
|
|
145
138
|
perform: DataSourcePerformFunction;
|
|
139
|
+
dataSourceType: DataSourceType;
|
|
146
140
|
examplePayload?: unknown;
|
|
147
141
|
}
|
|
148
142
|
export declare enum OAuth2Type {
|
|
@@ -214,4 +208,3 @@ export interface Input {
|
|
|
214
208
|
model?: InputFieldChoice[];
|
|
215
209
|
language?: string;
|
|
216
210
|
}
|
|
217
|
-
export {};
|
|
@@ -22,6 +22,10 @@ const cleanParams = (params, cleaners) => Object.entries(params).reduce((result,
|
|
|
22
22
|
const createPerform = (performFn, { inputCleaners, errorHandler }) => {
|
|
23
23
|
return (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
24
|
try {
|
|
25
|
+
if (args.length === 1) {
|
|
26
|
+
const [params] = args;
|
|
27
|
+
return yield performFn(cleanParams(params, inputCleaners));
|
|
28
|
+
}
|
|
25
29
|
if (args.length === 2) {
|
|
26
30
|
const [context, params] = args;
|
|
27
31
|
return yield performFn(context, cleanParams(params, inputCleaners));
|
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
|
/**
|
|
@@ -13,7 +13,7 @@ export declare const createConnection: <T extends ConnectionDefinition>({ key }:
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const loggerMock: () => ActionLogger;
|
|
15
15
|
/**
|
|
16
|
-
* The type of data returned by an `invoke()` function used for unit testing component actions.
|
|
16
|
+
* The type of data returned by an `invoke()` function used for unit testing component actions and triggers.
|
|
17
17
|
*/
|
|
18
18
|
interface InvokeReturn<ReturnData> {
|
|
19
19
|
result: ReturnData;
|
|
@@ -35,19 +35,36 @@ export declare const defaultTriggerPayload: () => TriggerPayload;
|
|
|
35
35
|
*/
|
|
36
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
|
/**
|
|
38
|
-
* Invokes specified DataSourceDefinition perform function using supplied params
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* action result and a mock logger for asserting logging.
|
|
38
|
+
* Invokes specified DataSourceDefinition perform function using supplied params.
|
|
39
|
+
* Accepts a generic type matching DataSourceResult as a convenience to avoid extra
|
|
40
|
+
* casting within test methods. Returns a DataSourceResult.
|
|
42
41
|
*/
|
|
43
|
-
export declare const invokeDataSource: <TInputs extends Inputs,
|
|
42
|
+
export declare const invokeDataSource: <TInputs extends Inputs, TDataSourceType extends keyof {
|
|
43
|
+
string: string;
|
|
44
|
+
date: string;
|
|
45
|
+
timestamp: string;
|
|
46
|
+
picklist: string[];
|
|
47
|
+
schedule: {
|
|
48
|
+
value: string;
|
|
49
|
+
};
|
|
50
|
+
code: string;
|
|
51
|
+
credential: unknown;
|
|
52
|
+
boolean: boolean;
|
|
53
|
+
number: number;
|
|
54
|
+
connection: ConnectionDefinition;
|
|
55
|
+
objectSelection: import("./types").ObjectSelection;
|
|
56
|
+
objectFieldMap: import("./types").ObjectFieldMap;
|
|
57
|
+
jsonForm: import("./types").JSONForm;
|
|
58
|
+
}>({ perform }: DataSourceDefinition<TInputs, TDataSourceType>, params: ActionInputParameters<TInputs>, context?: Partial<DataSourceContext> | undefined) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
44
59
|
export declare class ComponentTestHarness<TComponent extends Component> {
|
|
45
60
|
component: TComponent;
|
|
46
61
|
constructor(component: TComponent);
|
|
62
|
+
private buildContext;
|
|
63
|
+
private buildParams;
|
|
47
64
|
connectionValue({ key }: ConnectionDefinition): ConnectionValue;
|
|
48
65
|
trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>;
|
|
49
66
|
action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<ActionPerformReturn>;
|
|
50
|
-
dataSource(key: string, params?: Record<string, unknown>, context?: Partial<
|
|
67
|
+
dataSource(key: string, params?: Record<string, unknown>, context?: Partial<DataSourceContext>): Promise<DataSourceResult>;
|
|
51
68
|
}
|
|
52
69
|
export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
|
|
53
70
|
declare const _default: {
|
|
@@ -55,6 +72,22 @@ declare const _default: {
|
|
|
55
72
|
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>>;
|
|
56
73
|
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>>;
|
|
57
74
|
createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
|
|
58
|
-
invokeDataSource: <TInputs_2 extends Inputs,
|
|
75
|
+
invokeDataSource: <TInputs_2 extends Inputs, TDataSourceType extends keyof {
|
|
76
|
+
string: string;
|
|
77
|
+
date: string;
|
|
78
|
+
timestamp: string;
|
|
79
|
+
picklist: string[];
|
|
80
|
+
schedule: {
|
|
81
|
+
value: string;
|
|
82
|
+
};
|
|
83
|
+
code: string;
|
|
84
|
+
credential: unknown;
|
|
85
|
+
boolean: boolean;
|
|
86
|
+
number: number;
|
|
87
|
+
connection: ConnectionDefinition;
|
|
88
|
+
objectSelection: import("./types").ObjectSelection;
|
|
89
|
+
objectFieldMap: import("./types").ObjectFieldMap;
|
|
90
|
+
jsonForm: import("./types").JSONForm;
|
|
91
|
+
}>({ perform }: DataSourceDefinition<TInputs_2, TDataSourceType>, params: ActionInputParameters<TInputs_2>, context?: Partial<DataSourceContext> | undefined) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
59
92
|
};
|
|
60
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,25 +130,40 @@ 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
|
-
* Invokes specified DataSourceDefinition perform function using supplied params
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* action result and a mock logger for asserting logging.
|
|
146
|
+
* Invokes specified DataSourceDefinition perform function using supplied params.
|
|
147
|
+
* Accepts a generic type matching DataSourceResult as a convenience to avoid extra
|
|
148
|
+
* casting within test methods. Returns a DataSourceResult.
|
|
138
149
|
*/
|
|
139
150
|
const invokeDataSource = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
-
const realizedContext = Object.assign(Object.assign({},
|
|
151
|
+
const realizedContext = Object.assign(Object.assign({}, baseDataSourceContext), context);
|
|
141
152
|
const result = yield perform(realizedContext, params);
|
|
142
|
-
return
|
|
143
|
-
result,
|
|
144
|
-
loggerMock: realizedContext.logger,
|
|
145
|
-
};
|
|
153
|
+
return result;
|
|
146
154
|
});
|
|
147
155
|
exports.invokeDataSource = invokeDataSource;
|
|
148
156
|
class ComponentTestHarness {
|
|
149
157
|
constructor(component) {
|
|
150
158
|
this.component = component;
|
|
151
159
|
}
|
|
160
|
+
buildContext(baseContext, context) {
|
|
161
|
+
return Object.assign(Object.assign({}, baseContext), context);
|
|
162
|
+
}
|
|
163
|
+
buildParams(inputs, params) {
|
|
164
|
+
const defaults = inputs.reduce((result, { key, default: defaultValue }) => (Object.assign(Object.assign({}, result), { [key]: `${defaultValue !== null && defaultValue !== void 0 ? defaultValue : ""}` })), {});
|
|
165
|
+
return Object.assign(Object.assign({}, defaults), params);
|
|
166
|
+
}
|
|
152
167
|
connectionValue({ key }) {
|
|
153
168
|
const { PRISMATIC_CONNECTION_VALUE: value } = process.env;
|
|
154
169
|
if (!value) {
|
|
@@ -159,23 +174,20 @@ class ComponentTestHarness {
|
|
|
159
174
|
}
|
|
160
175
|
trigger(key, payload, params, context) {
|
|
161
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
|
|
163
177
|
const trigger = this.component.triggers[key];
|
|
164
|
-
return trigger.perform(
|
|
178
|
+
return trigger.perform(this.buildContext(baseActionContext, context), Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), this.buildParams(trigger.inputs, params));
|
|
165
179
|
});
|
|
166
180
|
}
|
|
167
181
|
action(key, params, context) {
|
|
168
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
|
|
170
183
|
const action = this.component.actions[key];
|
|
171
|
-
return action.perform(
|
|
184
|
+
return action.perform(this.buildContext(baseActionContext, context), this.buildParams(action.inputs, params));
|
|
172
185
|
});
|
|
173
186
|
}
|
|
174
187
|
dataSource(key, params, context) {
|
|
175
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
const realizedContext = Object.assign(Object.assign({}, baseContext), context);
|
|
177
189
|
const dataSource = this.component.dataSources[key];
|
|
178
|
-
return dataSource.perform(
|
|
190
|
+
return dataSource.perform(this.buildContext(baseDataSourceContext, context), this.buildParams(dataSource.inputs, params));
|
|
179
191
|
});
|
|
180
192
|
}
|
|
181
193
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Inputs, ActionPerformReturn, ActionInputParameters, ActionLogger } from ".";
|
|
1
|
+
import { Inputs, ActionPerformReturn, ActionInputParameters, ActionLogger, Instance, Customer } from ".";
|
|
2
2
|
/** Definition of the function to perform when an Action is invoked. */
|
|
3
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 */
|
|
@@ -21,15 +21,8 @@ export interface ActionContext {
|
|
|
21
21
|
webhookApiKeys: Record<string, string[]>;
|
|
22
22
|
/** The URL used to invoke the current execution */
|
|
23
23
|
invokeUrl: string;
|
|
24
|
-
/**
|
|
25
|
-
customer:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
name: string | null;
|
|
29
|
-
};
|
|
30
|
-
/** An object containing the ID ad name of the currently running instance */
|
|
31
|
-
instance: {
|
|
32
|
-
id: string | null;
|
|
33
|
-
name: string | null;
|
|
34
|
-
};
|
|
24
|
+
/** Contains attributes of the Customer for whom an Instance is being executed. */
|
|
25
|
+
customer: Customer;
|
|
26
|
+
/** Contains attributes of the Instance that is being executed. */
|
|
27
|
+
instance: Instance;
|
|
35
28
|
}
|
|
File without changes
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs,
|
|
1
|
+
import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs, DataSourceType } from ".";
|
|
2
2
|
/**
|
|
3
3
|
* DataSourceDefinition is the type of the object that is passed in to `dataSource` function to
|
|
4
4
|
* define a component Data Source.
|
|
5
5
|
*/
|
|
6
|
-
export interface DataSourceDefinition<TInputs extends Inputs,
|
|
6
|
+
export interface DataSourceDefinition<TInputs extends Inputs, TDataSourceType extends DataSourceType> {
|
|
7
7
|
/** Defines how the Data Source is displayed in the Prismatic interface. */
|
|
8
8
|
display: ActionDisplayDefinition;
|
|
9
|
-
/** Function to perform when this Data Source is invoked. */
|
|
10
|
-
perform: DataSourcePerformFunction<TInputs,
|
|
9
|
+
/** Function to perform when this Data Source is invoked; fetches data from the data source. */
|
|
10
|
+
perform: DataSourcePerformFunction<TInputs, TDataSourceType>;
|
|
11
|
+
/** The type of data that this Data Source represents. */
|
|
12
|
+
dataSourceType: TDataSourceType;
|
|
11
13
|
/** InputFields to present in the Prismatic interface for configuration of this Data Source. */
|
|
12
14
|
inputs: TInputs;
|
|
13
15
|
/** An example of the payload outputted by this Data Source. */
|
|
14
16
|
examplePayload?: Awaited<ReturnType<this["perform"]>>;
|
|
17
|
+
/** Specifies the name of a Data Source in this Component which can provide additional details about the content for this Data Source, such as example values when selecting particular API object fields. */
|
|
18
|
+
detailDataSource?: string;
|
|
15
19
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import { Inputs, DataSourceResult, DataSourceType, ActionInputParameters,
|
|
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<
|
|
9
|
+
export declare type DataSourcePerformFunction<TInputs extends Inputs, TDataSourceType extends DataSourceType> = (context: DataSourceContext, params: ActionInputParameters<TInputs>) => Promise<DataSourceResult<TDataSourceType>>;
|
|
@@ -1,10 +1,35 @@
|
|
|
1
|
+
import { ConnectionDefinition } from "./ConnectionDefinition";
|
|
2
|
+
import { ObjectSelection, ObjectFieldMap, JSONForm } from "./Inputs";
|
|
3
|
+
/** The type of field that is appropriate for rendering the data that is the result of the data source perform function. */
|
|
4
|
+
declare type DataSourceTypeMap = {
|
|
5
|
+
string: string;
|
|
6
|
+
date: string;
|
|
7
|
+
timestamp: string;
|
|
8
|
+
picklist: string[];
|
|
9
|
+
schedule: {
|
|
10
|
+
value: string;
|
|
11
|
+
};
|
|
12
|
+
code: string;
|
|
13
|
+
credential: unknown;
|
|
14
|
+
boolean: boolean;
|
|
15
|
+
number: number;
|
|
16
|
+
connection: ConnectionDefinition;
|
|
17
|
+
objectSelection: ObjectSelection;
|
|
18
|
+
objectFieldMap: ObjectFieldMap;
|
|
19
|
+
jsonForm: JSONForm;
|
|
20
|
+
};
|
|
21
|
+
export declare type DataSourceType = keyof DataSourceTypeMap;
|
|
22
|
+
export declare type DataSourceResultType = DataSourceTypeMap[DataSourceType];
|
|
1
23
|
/** Represents the result of a Data Source action. */
|
|
2
|
-
export declare type DataSourceResult<
|
|
3
|
-
/** The data that
|
|
4
|
-
|
|
5
|
-
/** Additional data that may be useful for out-of-band processing at a later time.
|
|
24
|
+
export declare type DataSourceResult<TDataSourceType extends DataSourceType> = {
|
|
25
|
+
/** The resulting data that is returned from the data source. */
|
|
26
|
+
result: DataSourceTypeMap[TDataSourceType];
|
|
27
|
+
/** Additional data that may be useful for out-of-band processing at a later time.
|
|
28
|
+
* NOTE: This is only available when the Data Source is called as part of fetching
|
|
29
|
+
* contents for a Configuration Wizard Page. */
|
|
6
30
|
supplementalData?: {
|
|
7
31
|
data: unknown;
|
|
8
32
|
contentType: string;
|
|
9
33
|
};
|
|
10
34
|
};
|
|
35
|
+
export {};
|
package/dist/types/Inputs.d.ts
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
import { ConditionalExpression } from "./conditional-logic";
|
|
2
|
-
|
|
2
|
+
export declare type Element = {
|
|
3
|
+
key: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare type ObjectSelection = {
|
|
7
|
+
object: Element;
|
|
8
|
+
fields?: Element[];
|
|
9
|
+
defaultSelected?: boolean;
|
|
10
|
+
}[];
|
|
11
|
+
export declare type ObjectFieldMap = {
|
|
12
|
+
fields: {
|
|
13
|
+
field: Element;
|
|
14
|
+
mappedObject?: Element;
|
|
15
|
+
mappedField?: Element;
|
|
16
|
+
defaultObject?: Element;
|
|
17
|
+
defaultField?: Element;
|
|
18
|
+
}[];
|
|
19
|
+
options?: {
|
|
20
|
+
object: Element;
|
|
21
|
+
fields: Element[];
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
export declare type JSONForm = {
|
|
25
|
+
schema: Record<string, unknown>;
|
|
26
|
+
uiSchema: Record<string, unknown>;
|
|
27
|
+
data: unknown;
|
|
28
|
+
};
|
|
29
|
+
export declare type DynamicObjectSelection = string;
|
|
30
|
+
export declare type DynamicFieldSelection = string;
|
|
3
31
|
/** InputField type enumeration. */
|
|
4
32
|
export declare type InputFieldType = InputFieldDefinition["type"];
|
|
5
33
|
export declare const InputFieldDefaultMap: Record<InputFieldType, string | undefined>;
|
|
@@ -7,7 +35,7 @@ export declare type Inputs = Record<string, InputFieldDefinition>;
|
|
|
7
35
|
export declare type ConnectionInput = (StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField) & {
|
|
8
36
|
shown?: boolean;
|
|
9
37
|
};
|
|
10
|
-
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField;
|
|
38
|
+
export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField | JSONFormInputField | DynamicObjectSelectionInputField | DynamicFieldSelectionInputField;
|
|
11
39
|
export declare type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult;
|
|
12
40
|
interface BaseInputField {
|
|
13
41
|
/** Interface label of the InputField. */
|
|
@@ -136,7 +164,7 @@ export interface Connection {
|
|
|
136
164
|
/** Defines attributes of an ObjectSelectionInputField. */
|
|
137
165
|
export interface ObjectSelectionInputField extends BaseInputField {
|
|
138
166
|
/** Data type the InputField will collect. */
|
|
139
|
-
type: "
|
|
167
|
+
type: "objectSelection";
|
|
140
168
|
/** Collection type of the InputField */
|
|
141
169
|
collection?: InputFieldCollection;
|
|
142
170
|
/** Default value for this field. */
|
|
@@ -147,7 +175,7 @@ export interface ObjectSelectionInputField extends BaseInputField {
|
|
|
147
175
|
/** Defines attributes of an ObjectFieldMapInputField. */
|
|
148
176
|
export interface ObjectFieldMapInputField extends BaseInputField {
|
|
149
177
|
/** Data type the InputField will collect. */
|
|
150
|
-
type: "
|
|
178
|
+
type: "objectFieldMap";
|
|
151
179
|
/** Collection type of the InputField */
|
|
152
180
|
collection?: InputFieldCollection;
|
|
153
181
|
/** Default value for this field. */
|
|
@@ -155,6 +183,39 @@ export interface ObjectFieldMapInputField extends BaseInputField {
|
|
|
155
183
|
/** Clean function */
|
|
156
184
|
clean?: InputCleanFunction<NonNullable<this["default"]>>;
|
|
157
185
|
}
|
|
186
|
+
/** Defines attributes of a JSONFormInputField. */
|
|
187
|
+
export interface JSONFormInputField extends BaseInputField {
|
|
188
|
+
/** Data type the InputField will collect. */
|
|
189
|
+
type: "jsonForm";
|
|
190
|
+
/** Collection type of the InputField */
|
|
191
|
+
collection?: InputFieldCollection;
|
|
192
|
+
/** Default value for this field. */
|
|
193
|
+
default?: JSONForm;
|
|
194
|
+
/** Clean function */
|
|
195
|
+
clean?: InputCleanFunction<NonNullable<this["default"]>>;
|
|
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
|
+
}
|
|
158
219
|
/** Defines a single Choice option for a InputField. */
|
|
159
220
|
export interface InputFieldChoice {
|
|
160
221
|
/** Label to display for this Choice. */
|
package/dist/types/Inputs.js
CHANGED
|
@@ -10,6 +10,9 @@ exports.InputFieldDefaultMap = {
|
|
|
10
10
|
code: "",
|
|
11
11
|
conditional: undefined,
|
|
12
12
|
connection: undefined,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
objectSelection: undefined,
|
|
14
|
+
objectFieldMap: undefined,
|
|
15
|
+
jsonForm: undefined,
|
|
16
|
+
dynamicObjectSelection: "",
|
|
17
|
+
dynamicFieldSelection: "",
|
|
15
18
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Instance, Customer } from ".";
|
|
1
2
|
/** Represents a Trigger Payload, which is data passed into a Trigger to invoke an Integration execution. */
|
|
2
3
|
export interface TriggerPayload {
|
|
3
4
|
headers: {
|
|
@@ -27,13 +28,8 @@ export interface TriggerPayload {
|
|
|
27
28
|
/** The URL that was used to invoke the execution. */
|
|
28
29
|
invokeUrl: string;
|
|
29
30
|
executionId: string;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
instance: {
|
|
36
|
-
id: string | null;
|
|
37
|
-
name: string | null;
|
|
38
|
-
};
|
|
31
|
+
/** Contains attributes of the Customer for whom an Instance is being executed. */
|
|
32
|
+
customer: Customer;
|
|
33
|
+
/** Contains attributes of the Instance that is being executed. */
|
|
34
|
+
instance: Instance;
|
|
39
35
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -21,4 +21,6 @@ export * from "./TriggerPayload";
|
|
|
21
21
|
export * from "./DataSourceDefinition";
|
|
22
22
|
export * from "./DataSourcePerformFunction";
|
|
23
23
|
export * from "./DataSourceResult";
|
|
24
|
-
export * from "./
|
|
24
|
+
export * from "./Instance";
|
|
25
|
+
export * from "./Customer";
|
|
26
|
+
export * as serverTypes from "../serverTypes";
|
package/dist/types/index.js
CHANGED
|
@@ -14,10 +14,23 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
14
14
|
if (k2 === undefined) k2 = k;
|
|
15
15
|
o[k2] = m[k];
|
|
16
16
|
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
17
22
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
23
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
24
|
};
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
20
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.serverTypes = void 0;
|
|
21
34
|
__exportStar(require("./ActionDefinition"), exports);
|
|
22
35
|
__exportStar(require("./ComponentDefinition"), exports);
|
|
23
36
|
__exportStar(require("./ConnectionDefinition"), exports);
|
|
@@ -37,4 +50,6 @@ __exportStar(require("./TriggerPayload"), exports);
|
|
|
37
50
|
__exportStar(require("./DataSourceDefinition"), exports);
|
|
38
51
|
__exportStar(require("./DataSourcePerformFunction"), exports);
|
|
39
52
|
__exportStar(require("./DataSourceResult"), exports);
|
|
40
|
-
__exportStar(require("./
|
|
53
|
+
__exportStar(require("./Instance"), exports);
|
|
54
|
+
__exportStar(require("./Customer"), exports);
|
|
55
|
+
exports.serverTypes = __importStar(require("../serverTypes"));
|
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 } 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
|
*
|
|
@@ -31,6 +31,7 @@ declare const _default: {
|
|
|
31
31
|
toBufferDataPayload: (value: unknown) => DataPayload;
|
|
32
32
|
isData: (value: unknown) => boolean;
|
|
33
33
|
toData: (value: unknown) => DataPayload;
|
|
34
|
+
isString: (value: unknown) => value is string;
|
|
34
35
|
toString: (value: unknown, defaultValue?: string) => string;
|
|
35
36
|
keyValPairListToObject: <TValue = unknown>(kvpList: KeyValuePair<unknown>[], valueConverter?: ((value: unknown) => TValue) | undefined) => Record<string, TValue>;
|
|
36
37
|
isJSON: (value: string) => boolean;
|
|
@@ -40,6 +41,11 @@ declare const _default: {
|
|
|
40
41
|
toObjectSelection: (value: unknown) => ObjectSelection;
|
|
41
42
|
isObjectFieldMap: (value: unknown) => value is ObjectFieldMap;
|
|
42
43
|
toObjectFieldMap: (value: unknown) => ObjectFieldMap;
|
|
44
|
+
isJSONForm: (value: unknown) => value is JSONForm;
|
|
45
|
+
toJSONForm: (value: unknown) => JSONForm;
|
|
46
|
+
isPicklist: (value: unknown) => boolean;
|
|
47
|
+
isSchedule: (value: unknown) => boolean;
|
|
48
|
+
isConnection: (value: unknown) => value is ConnectionDefinition;
|
|
43
49
|
};
|
|
44
50
|
docs: {
|
|
45
51
|
formatJsonExample: (input: unknown) => string;
|
package/dist/util.js
CHANGED
|
@@ -25,25 +25,11 @@ const isObjectWithTruthyKeys = (value, keys) => {
|
|
|
25
25
|
* @returns This function returns true if the type of `value` is an ObjectSelection, or false otherwise.
|
|
26
26
|
*/
|
|
27
27
|
const isObjectSelection = (value) => {
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
if (isObjectWithTruthyKeys(selection, ["key", "fields"])) {
|
|
31
|
-
const { fields } = selection;
|
|
32
|
-
if (!Array.isArray(fields) ||
|
|
33
|
-
fields.length === 0 ||
|
|
34
|
-
!fields.every((field) => isObjectWithTruthyKeys(field, ["key"]))) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
return false;
|
|
28
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
29
|
+
return isObjectSelection(JSON.parse(value));
|
|
45
30
|
}
|
|
46
|
-
return
|
|
31
|
+
return (Array.isArray(value) &&
|
|
32
|
+
value.every((item) => isObjectWithTruthyKeys(item, ["object"])));
|
|
47
33
|
};
|
|
48
34
|
/**
|
|
49
35
|
* This function coerces a provided value into an ObjectSelection if possible.
|
|
@@ -51,33 +37,31 @@ const isObjectSelection = (value) => {
|
|
|
51
37
|
* @returns This function returns the the value as an ObjectSelection if possible.
|
|
52
38
|
*/
|
|
53
39
|
const toObjectSelection = (value) => {
|
|
40
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
41
|
+
return toObjectSelection(JSON.parse(value));
|
|
42
|
+
}
|
|
54
43
|
if (isObjectSelection(value)) {
|
|
55
44
|
return value;
|
|
56
45
|
}
|
|
57
|
-
throw new Error(`Value '${value}' cannot be coerced to ObjectSelection.`);
|
|
46
|
+
throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to ObjectSelection.`);
|
|
58
47
|
};
|
|
59
48
|
/**
|
|
60
49
|
* @param value The value to test
|
|
61
50
|
* @returns This function returns true if the type of `value` is an ObjectFieldMap, or false otherwise.
|
|
62
51
|
*/
|
|
63
52
|
const isObjectFieldMap = (value) => {
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
if (isObjectWithTruthyKeys(fieldMap, ["key", "value"])) {
|
|
67
|
-
const { value: val } = fieldMap;
|
|
68
|
-
if (!isObjectWithTruthyKeys(val, ["objectKey", "fieldKey"])) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
53
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
54
|
+
return isObjectFieldMap(JSON.parse(value));
|
|
76
55
|
}
|
|
77
|
-
|
|
78
|
-
|
|
56
|
+
if (Boolean(value) && typeof value === "object") {
|
|
57
|
+
const { fields } = value;
|
|
58
|
+
return (Array.isArray(fields) &&
|
|
59
|
+
fields.every((item) => isObjectWithTruthyKeys(item, ["field"]) &&
|
|
60
|
+
isObjectWithTruthyKeys(item === null || item === void 0 ? void 0 : item.field, [
|
|
61
|
+
"key",
|
|
62
|
+
])));
|
|
79
63
|
}
|
|
80
|
-
return
|
|
64
|
+
return false;
|
|
81
65
|
};
|
|
82
66
|
/**
|
|
83
67
|
* This function coerces a provided value into an ObjectFieldMap if possible.
|
|
@@ -85,10 +69,37 @@ const isObjectFieldMap = (value) => {
|
|
|
85
69
|
* @returns This function returns the the value as an ObjectFieldMap if possible.
|
|
86
70
|
*/
|
|
87
71
|
const toObjectFieldMap = (value) => {
|
|
72
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
73
|
+
return toObjectFieldMap(JSON.parse(value));
|
|
74
|
+
}
|
|
88
75
|
if (isObjectFieldMap(value)) {
|
|
89
76
|
return value;
|
|
90
77
|
}
|
|
91
|
-
throw new Error(`Value '${value}' cannot be coerced to ObjectFieldMap.`);
|
|
78
|
+
throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to ObjectFieldMap.`);
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* @param value The value to test
|
|
82
|
+
* @returns This function returns true if the type of `value` is a JSONForm, or false otherwise.
|
|
83
|
+
*/
|
|
84
|
+
const isJSONForm = (value) => {
|
|
85
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
86
|
+
return isJSONForm(JSON.parse(value));
|
|
87
|
+
}
|
|
88
|
+
return isObjectWithTruthyKeys(value, ["schema", "uiSchema", "data"]);
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* This function coerces a provided value into a JSONForm if possible.
|
|
92
|
+
* @param value The value to coerce to JSONForm.
|
|
93
|
+
* @returns This function returns the the value as a JSONForm if possible.
|
|
94
|
+
*/
|
|
95
|
+
const toJSONForm = (value) => {
|
|
96
|
+
if (typeof value === "string" && isJSON(value)) {
|
|
97
|
+
return toJSONForm(JSON.parse(value));
|
|
98
|
+
}
|
|
99
|
+
if (isJSONForm(value)) {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
throw new Error(`Value '${typeof value === "string" ? value : JSON.stringify(value)}' cannot be coerced to JSONForm.`);
|
|
92
103
|
};
|
|
93
104
|
/**
|
|
94
105
|
* Determine if a variable is a boolean (true or false).
|
|
@@ -262,6 +273,25 @@ const toDate = (value) => {
|
|
|
262
273
|
* @returns This function returns true if `value` is a valid URL, and false otherwise.
|
|
263
274
|
*/
|
|
264
275
|
const isUrl = (value) => (0, valid_url_1.isWebUri)(value) !== undefined;
|
|
276
|
+
/**
|
|
277
|
+
* This function checks if value is a valid picklist.
|
|
278
|
+
*
|
|
279
|
+
* - `util.types.isPicklist(["value", new String("value")])` will return `true`.
|
|
280
|
+
*
|
|
281
|
+
* @param value The variable to test.
|
|
282
|
+
* @returns This function returns true if `value` is a valid picklist.
|
|
283
|
+
*/
|
|
284
|
+
const isPicklist = (value) => Array.isArray(value) && value.every(isString);
|
|
285
|
+
/**
|
|
286
|
+
* This function checks if value is a valid schedule.
|
|
287
|
+
*
|
|
288
|
+
* - `util.types.isSchedule({value: "00 00 * * 2,3"})` will return `true`.
|
|
289
|
+
* - `util.types.isSchedule({value: "00 00 * * 2,3", scheduleType: "week", timeZone: "America/Chicago"})` will return `true`.
|
|
290
|
+
*
|
|
291
|
+
* @param value The variable to test.
|
|
292
|
+
* @returns This function returns true if `value` is a valid schedule.
|
|
293
|
+
*/
|
|
294
|
+
const isSchedule = (value) => isObjectWithTruthyKeys(value, ["value"]);
|
|
265
295
|
/**
|
|
266
296
|
* This function helps to transform key-value lists to objects.
|
|
267
297
|
* This is useful for transforming inputs that are key-value collections into objects.
|
|
@@ -355,6 +385,13 @@ const toData = (value) => toBufferDataPayload(value);
|
|
|
355
385
|
* @returns This function returns a code block that can be used for documentation.
|
|
356
386
|
*/
|
|
357
387
|
const formatJsonExample = (input) => ["```json", JSON.stringify(input, undefined, 2), "```"].join("\n");
|
|
388
|
+
/**
|
|
389
|
+
* This function checks if value is a string.
|
|
390
|
+
* `util.types.isString("value")` and `util.types.isString(new String("value"))` return true.
|
|
391
|
+
* @param value The variable to test.
|
|
392
|
+
* @returns This function returns true or false, depending on if `value` is a string.
|
|
393
|
+
*/
|
|
394
|
+
const isString = (value) => typeof value === "string" || value instanceof String;
|
|
358
395
|
/**
|
|
359
396
|
* This function converts a `value` to a string.
|
|
360
397
|
* If `value` is undefined or an empty string, an optional `defaultValue` can be returned.
|
|
@@ -368,6 +405,31 @@ const formatJsonExample = (input) => ["```json", JSON.stringify(input, undefined
|
|
|
368
405
|
* @returns This function returns the stringified version fo `value`, or `defaultValue` in the case that `value` is undefined or an empty string.
|
|
369
406
|
*/
|
|
370
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
|
+
"clientId",
|
|
424
|
+
"clientSecret",
|
|
425
|
+
]) ||
|
|
426
|
+
isObjectWithTruthyKeys(inputs, ["tokenUrl", "clientId", "clientSecret"]));
|
|
427
|
+
}
|
|
428
|
+
return (isObjectWithTruthyKeys(value, ["key", "label"]) &&
|
|
429
|
+
typeof inputs === "object");
|
|
430
|
+
}
|
|
431
|
+
return false;
|
|
432
|
+
};
|
|
371
433
|
/**
|
|
372
434
|
* This function returns true if `value` resembles the shape of JSON, and false otherwise.
|
|
373
435
|
*
|
|
@@ -427,6 +489,7 @@ exports.default = {
|
|
|
427
489
|
toBufferDataPayload,
|
|
428
490
|
isData,
|
|
429
491
|
toData,
|
|
492
|
+
isString,
|
|
430
493
|
toString,
|
|
431
494
|
keyValPairListToObject,
|
|
432
495
|
isJSON,
|
|
@@ -436,6 +499,11 @@ exports.default = {
|
|
|
436
499
|
toObjectSelection,
|
|
437
500
|
isObjectFieldMap,
|
|
438
501
|
toObjectFieldMap,
|
|
502
|
+
isJSONForm,
|
|
503
|
+
toJSONForm,
|
|
504
|
+
isPicklist,
|
|
505
|
+
isSchedule,
|
|
506
|
+
isConnection,
|
|
439
507
|
},
|
|
440
508
|
docs: {
|
|
441
509
|
formatJsonExample,
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
export declare type ObjectSelection = {
|
|
3
|
-
key: string;
|
|
4
|
-
label?: string;
|
|
5
|
-
fields: {
|
|
6
|
-
key: string;
|
|
7
|
-
label?: string;
|
|
8
|
-
}[];
|
|
9
|
-
}[];
|
|
10
|
-
export declare type ObjectFieldMap = {
|
|
11
|
-
key: string;
|
|
12
|
-
label?: string;
|
|
13
|
-
value: {
|
|
14
|
-
objectKey: string;
|
|
15
|
-
objectLabel?: string;
|
|
16
|
-
fieldKey: string;
|
|
17
|
-
fieldLabel?: string;
|
|
18
|
-
};
|
|
19
|
-
}[];
|
|
20
|
-
export declare type DataSourceType = ObjectSelection | ObjectFieldMap | Buffer | boolean | number | string | Record<string, unknown> | unknown[] | unknown;
|