@prismatic-io/spectral 6.6.1 → 7.0.0-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/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 } from "./types";
6
+ import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, DataSourceResult } from "./types";
7
7
  import { convertComponent } from "./serverTypes/convert";
8
8
  /**
9
9
  * This function creates a component object that can be
@@ -34,6 +34,16 @@ export declare const action: <TInputs extends Inputs, TAllowsBranching extends b
34
34
  * @returns This function validates the shape of the `definition` object provided, and returns the same trigger object.
35
35
  */
36
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
+ /**
38
+ * This function creates a data source object that can be referenced
39
+ * by a custom component. It helps ensure that the shape of the
40
+ * data source object conforms to what the Prismatic API expects.
41
+ * For information on writing custom component data sources, see
42
+ * https://prismatic.io/docs/custom-components/writing-custom-components/#writing-data-sources.
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
+ * @returns This function validates the shape of the `definition` object provided, and returns the same data source object.
45
+ */
46
+ export declare const dataSource: <TInputs extends Inputs, TResult extends DataSourceResult<unknown>>(definition: DataSourceDefinition<TInputs, TResult>) => DataSourceDefinition<TInputs, TResult>;
37
47
  /**
38
48
  * For information and examples on how to write inputs
39
49
  * for custom component actions and triggers, see
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.testing = exports.util = exports.oauth2Connection = exports.connection = exports.input = exports.trigger = exports.action = exports.component = void 0;
25
+ exports.testing = exports.util = exports.oauth2Connection = exports.connection = exports.input = exports.dataSource = exports.trigger = exports.action = exports.component = void 0;
26
26
  const convert_1 = require("./serverTypes/convert");
27
27
  /**
28
28
  * This function creates a component object that can be
@@ -56,6 +56,17 @@ exports.action = action;
56
56
  */
57
57
  const trigger = (definition) => definition;
58
58
  exports.trigger = trigger;
59
+ /**
60
+ * This function creates a data source object that can be referenced
61
+ * by a custom component. It helps ensure that the shape of the
62
+ * data source object conforms to what the Prismatic API expects.
63
+ * For information on writing custom component data sources, see
64
+ * https://prismatic.io/docs/custom-components/writing-custom-components/#writing-data-sources.
65
+ * @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.
66
+ * @returns This function validates the shape of the `definition` object provided, and returns the same data source object.
67
+ */
68
+ const dataSource = (definition) => definition;
69
+ exports.dataSource = dataSource;
59
70
  /**
60
71
  * For information and examples on how to write inputs
61
72
  * for custom component actions and triggers, see
@@ -1,3 +1,3 @@
1
1
  import { ComponentDefinition } from "../types";
2
2
  import { Component as ServerComponent } from ".";
3
- export declare const convertComponent: <TPublic extends boolean>({ connections, actions, triggers, hooks, ...definition }: ComponentDefinition<TPublic>) => ServerComponent;
3
+ export declare const convertComponent: <TPublic extends boolean>({ connections, actions, triggers, dataSources, hooks, ...definition }: ComponentDefinition<TPublic>) => ServerComponent;
@@ -39,15 +39,24 @@ const convertTrigger = (triggerKey, _a, hooks) => {
39
39
  errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
40
40
  }) });
41
41
  };
42
+ const convertDataSource = (dataSourceKey, _a, hooks) => {
43
+ var { inputs = {}, perform } = _a, dataSource = __rest(_a, ["inputs", "perform"]);
44
+ const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
45
+ return Object.assign(Object.assign({}, dataSource), { key: dataSourceKey, inputs: convertedInputs, perform: (0, perform_1.createPerform)(perform, {
46
+ inputCleaners: {},
47
+ errorHandler: hooks === null || hooks === void 0 ? void 0 : hooks.error,
48
+ }) });
49
+ };
42
50
  const convertConnection = (_a) => {
43
51
  var { inputs = {} } = _a, connection = __rest(_a, ["inputs"]);
44
52
  const convertedInputs = Object.entries(inputs).map(([key, value]) => convertInput(key, value));
45
53
  return Object.assign(Object.assign({}, connection), { inputs: convertedInputs });
46
54
  };
47
55
  const convertComponent = (_a) => {
48
- var { connections = [], actions = {}, triggers = {}, hooks } = _a, definition = __rest(_a, ["connections", "actions", "triggers", "hooks"]);
56
+ var { connections = [], actions = {}, triggers = {}, dataSources = {}, hooks } = _a, definition = __rest(_a, ["connections", "actions", "triggers", "dataSources", "hooks"]);
49
57
  const convertedActions = Object.entries(actions).reduce((result, [actionKey, action]) => (Object.assign(Object.assign({}, result), { [actionKey]: convertAction(actionKey, action, hooks) })), {});
50
58
  const convertedTriggers = Object.entries(triggers).reduce((result, [triggerKey, trigger]) => (Object.assign(Object.assign({}, result), { [triggerKey]: convertTrigger(triggerKey, trigger, hooks) })), {});
51
- return Object.assign(Object.assign({}, definition), { connections: connections.map(convertConnection), actions: convertedActions, triggers: convertedTriggers });
59
+ const convertedDataSources = Object.entries(dataSources).reduce((result, [dataSourceKey, dataSource]) => (Object.assign(Object.assign({}, result), { [dataSourceKey]: convertDataSource(dataSourceKey, dataSource, hooks) })), {});
60
+ return Object.assign(Object.assign({}, definition), { connections: connections.map(convertConnection), actions: convertedActions, triggers: convertedTriggers, dataSources: convertedDataSources });
52
61
  };
53
62
  exports.convertComponent = convertComponent;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ import { DataSourceType } from "../types";
2
3
  interface DisplayDefinition {
3
4
  label: string;
4
5
  description: string;
@@ -13,6 +14,7 @@ export interface Component {
13
14
  };
14
15
  actions: Record<string, Action>;
15
16
  triggers: Record<string, Trigger>;
17
+ dataSources: Record<string, DataSource>;
16
18
  connections: Connection[];
17
19
  }
18
20
  export interface Action {
@@ -125,6 +127,24 @@ export interface Trigger {
125
127
  examplePayload?: unknown;
126
128
  isCommonTrigger?: boolean;
127
129
  }
130
+ export declare type DataSourceResult = {
131
+ content: DataSourceType;
132
+ supplementalData: {
133
+ data: unknown;
134
+ contentType: string;
135
+ };
136
+ };
137
+ export declare type DataSourcePerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<DataSourceResult>;
138
+ export interface DataSource {
139
+ key: string;
140
+ display: DisplayDefinition & {
141
+ directions?: string;
142
+ important?: boolean;
143
+ };
144
+ inputs: Input[];
145
+ perform: DataSourcePerformFunction;
146
+ examplePayload?: unknown;
147
+ }
128
148
  export declare enum OAuth2Type {
129
149
  ClientCredentials = "client_credentials",
130
150
  AuthorizationCode = "authorization_code"
package/dist/testing.d.ts CHANGED
@@ -4,8 +4,8 @@
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 } from "./serverTypes";
8
- import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult } from "./types";
7
+ import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult } from "./serverTypes";
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
  /**
11
11
  * Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
@@ -34,12 +34,20 @@ export declare const defaultTriggerPayload: () => TriggerPayload;
34
34
  * trigger result and a mock logger for asserting logging.
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
+ /**
38
+ * Invokes specified DataSourceDefinition perform function using supplied params
39
+ * and optional context. Accepts a generic type matching DataSourceResult as a convenience
40
+ * to avoid extra casting within test methods. Returns an InvokeResult containing both the
41
+ * action result and a mock logger for asserting logging.
42
+ */
43
+ export declare const invokeDataSource: <TInputs extends Inputs, TReturn extends InvokeDataSourceResult<unknown>>({ perform }: DataSourceDefinition<TInputs, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn>>;
37
44
  export declare class ComponentTestHarness<TComponent extends Component> {
38
45
  component: TComponent;
39
46
  constructor(component: TComponent);
40
47
  connectionValue({ key }: ConnectionDefinition): ConnectionValue;
41
48
  trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>;
42
49
  action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<ActionPerformReturn>;
50
+ dataSource(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<DataSourceResult>;
43
51
  }
44
52
  export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
45
53
  declare const _default: {
@@ -47,5 +55,6 @@ declare const _default: {
47
55
  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
56
  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
57
  createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
58
+ invokeDataSource: <TInputs_2 extends Inputs, TReturn_1 extends InvokeDataSourceResult<unknown>>({ perform }: DataSourceDefinition<TInputs_2, TReturn_1>, params: ActionInputParameters<TInputs_2>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn_1>>;
50
59
  };
51
60
  export default _default;
package/dist/testing.js CHANGED
@@ -15,7 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
15
  });
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.createHarness = exports.ComponentTestHarness = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.createConnection = void 0;
18
+ exports.createHarness = exports.ComponentTestHarness = exports.invokeDataSource = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.createConnection = void 0;
19
19
  const jest_mock_1 = require("jest-mock");
20
20
  const createConnection = ({ key }, values) => ({
21
21
  configVarKey: "",
@@ -37,6 +37,30 @@ const loggerMock = () => ({
37
37
  error: (0, jest_mock_1.spyOn)(console, "error"),
38
38
  });
39
39
  exports.loggerMock = loggerMock;
40
+ const baseContext = {
41
+ logger: (0, exports.loggerMock)(),
42
+ instanceState: {},
43
+ crossFlowState: {},
44
+ executionState: {},
45
+ stepId: "mockStepId",
46
+ executionId: "mockExecutionId",
47
+ webhookUrls: {
48
+ "Flow 1": "https://example.com",
49
+ },
50
+ webhookApiKeys: {
51
+ "Flow 1": ["example-123", "example-456"],
52
+ },
53
+ invokeUrl: "https://example.com",
54
+ customer: {
55
+ id: "customerId",
56
+ name: "Customer 1",
57
+ externalId: "1234",
58
+ },
59
+ instance: {
60
+ id: "instanceId",
61
+ name: "Instance 1",
62
+ },
63
+ };
40
64
  /**
41
65
  * Invokes specified ActionDefinition perform function using supplied params
42
66
  * and optional context. Accepts a generic type matching ActionPerformReturn as a convenience
@@ -44,18 +68,7 @@ exports.loggerMock = loggerMock;
44
68
  * action result and a mock logger for asserting logging.
45
69
  */
46
70
  const invoke = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
47
- const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
48
- "Flow 1": "https://example.com",
49
- }, webhookApiKeys: {
50
- "Flow 1": ["example-123", "example-456"],
51
- }, invokeUrl: "https://example.com", customer: {
52
- id: "customerId",
53
- name: "Customer 1",
54
- externalId: "1234",
55
- }, instance: {
56
- id: "instanceId",
57
- name: "Instance 1",
58
- } }, context);
71
+ const realizedContext = Object.assign(Object.assign({}, baseContext), context);
59
72
  const result = yield perform(realizedContext, params);
60
73
  return {
61
74
  result,
@@ -107,18 +120,7 @@ exports.defaultTriggerPayload = defaultTriggerPayload;
107
120
  * trigger result and a mock logger for asserting logging.
108
121
  */
109
122
  const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void 0, void 0, void 0, function* () {
110
- const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
111
- "Flow 1": "https://example.com",
112
- }, webhookApiKeys: {
113
- "Flow 1": ["example-123", "example-456"],
114
- }, invokeUrl: "https://example.com", customer: {
115
- id: "customerId",
116
- name: "Customer 1",
117
- externalId: "1234",
118
- }, instance: {
119
- id: "instanceId",
120
- name: "Instance 1",
121
- } }, context);
123
+ const realizedContext = Object.assign(Object.assign({}, baseContext), context);
122
124
  const realizedPayload = Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload);
123
125
  const realizedParams = params || {};
124
126
  const result = yield perform(realizedContext, realizedPayload, realizedParams);
@@ -128,6 +130,21 @@ const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void
128
130
  };
129
131
  });
130
132
  exports.invokeTrigger = invokeTrigger;
133
+ /**
134
+ * Invokes specified DataSourceDefinition perform function using supplied params
135
+ * and optional context. Accepts a generic type matching DataSourceResult as a convenience
136
+ * to avoid extra casting within test methods. Returns an InvokeResult containing both the
137
+ * action result and a mock logger for asserting logging.
138
+ */
139
+ const invokeDataSource = ({ perform }, params, context) => __awaiter(void 0, void 0, void 0, function* () {
140
+ const realizedContext = Object.assign(Object.assign({}, baseContext), context);
141
+ const result = yield perform(realizedContext, params);
142
+ return {
143
+ result,
144
+ loggerMock: realizedContext.logger,
145
+ };
146
+ });
147
+ exports.invokeDataSource = invokeDataSource;
131
148
  class ComponentTestHarness {
132
149
  constructor(component) {
133
150
  this.component = component;
@@ -142,40 +159,25 @@ class ComponentTestHarness {
142
159
  }
143
160
  trigger(key, payload, params, context) {
144
161
  return __awaiter(this, void 0, void 0, function* () {
145
- const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
146
- "Flow 1": "https://example.com",
147
- }, webhookApiKeys: {
148
- "Flow 1": ["example-123", "example-456"],
149
- }, invokeUrl: "https://example.com", customer: {
150
- id: "customerId",
151
- name: "Customer 1",
152
- externalId: "1234",
153
- }, instance: {
154
- id: "instanceId",
155
- name: "Instance 1",
156
- } }, context);
162
+ const realizedContext = Object.assign(Object.assign({}, baseContext), context);
157
163
  const trigger = this.component.triggers[key];
158
164
  return trigger.perform(realizedContext, Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), Object.assign({}, params));
159
165
  });
160
166
  }
161
167
  action(key, params, context) {
162
168
  return __awaiter(this, void 0, void 0, function* () {
163
- const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
164
- "Flow 1": "https://example.com",
165
- }, webhookApiKeys: {
166
- "Flow 1": ["example-123", "example-456"],
167
- }, invokeUrl: "https://example.com", customer: {
168
- id: "customerId",
169
- name: "Customer 1",
170
- externalId: "1234",
171
- }, instance: {
172
- id: "instanceId",
173
- name: "Instance 1",
174
- } }, context);
169
+ const realizedContext = Object.assign(Object.assign({}, baseContext), context);
175
170
  const action = this.component.actions[key];
176
171
  return action.perform(realizedContext, Object.assign({}, params));
177
172
  });
178
173
  }
174
+ dataSource(key, params, context) {
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ const realizedContext = Object.assign(Object.assign({}, baseContext), context);
177
+ const dataSource = this.component.dataSources[key];
178
+ return dataSource.perform(realizedContext, Object.assign({}, params));
179
+ });
180
+ }
179
181
  }
180
182
  exports.ComponentTestHarness = ComponentTestHarness;
181
183
  const createHarness = (component) => {
@@ -187,4 +189,5 @@ exports.default = {
187
189
  invoke: exports.invoke,
188
190
  invokeTrigger: exports.invokeTrigger,
189
191
  createHarness: exports.createHarness,
192
+ invokeDataSource: exports.invokeDataSource,
190
193
  };
@@ -12,7 +12,7 @@ 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. */
15
+ /** A field populated by the Prismatic platform which indicates whether the action failed with an error during execution. */
16
16
  failed?: boolean;
17
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
18
  error?: Record<string, unknown>;
@@ -1,4 +1,4 @@
1
- import { ActionDefinition, ConnectionDefinition, ComponentDisplayDefinition, TriggerDefinition } from ".";
1
+ import { ActionDefinition, ConnectionDefinition, ComponentDisplayDefinition, TriggerDefinition, DataSourceDefinition } from ".";
2
2
  export declare type ErrorHandler = (error: unknown) => unknown;
3
3
  export interface ComponentHooks {
4
4
  /** Defines a global error handler that automatically wraps the component's action/trigger perform functions. */
@@ -16,6 +16,8 @@ export declare type ComponentDefinition<TPublic extends boolean> = {
16
16
  actions?: Record<string, ActionDefinition<any, boolean, any>>;
17
17
  /** Specifies the supported Triggers of this Component. */
18
18
  triggers?: Record<string, TriggerDefinition<any, boolean, any>>;
19
+ /** Specifies the supported Data Sources of this Component. */
20
+ dataSources?: Record<string, DataSourceDefinition<any, any>>;
19
21
  /** Specifies the supported Connections of this Component. */
20
22
  connections?: ConnectionDefinition[];
21
23
  /** Hooks */
@@ -0,0 +1,15 @@
1
+ import { ActionDisplayDefinition, DataSourcePerformFunction, Inputs, DataSourceResult, DataSourceType } from ".";
2
+ /**
3
+ * DataSourceDefinition is the type of the object that is passed in to `dataSource` function to
4
+ * define a component Data Source.
5
+ */
6
+ export interface DataSourceDefinition<TInputs extends Inputs, TDataSourceResult extends DataSourceResult<DataSourceType>> {
7
+ /** Defines how the Data Source is displayed in the Prismatic interface. */
8
+ display: ActionDisplayDefinition;
9
+ /** Function to perform when this Data Source is invoked. */
10
+ perform: DataSourcePerformFunction<TInputs, TDataSourceResult>;
11
+ /** InputFields to present in the Prismatic interface for configuration of this Data Source. */
12
+ inputs: TInputs;
13
+ /** An example of the payload outputted by this Data Source. */
14
+ examplePayload?: Awaited<ReturnType<this["perform"]>>;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { Inputs, DataSourceResult, DataSourceType, ActionInputParameters, ActionContext } from ".";
2
+ /** Definition of the function to perform when a Data Source is invoked. */
3
+ export declare type DataSourcePerformFunction<T extends Inputs, TResult extends DataSourceResult<DataSourceType>> = (context: ActionContext, params: ActionInputParameters<T>) => Promise<TResult>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ /** Represents the result of a Data Source action. */
2
+ export declare type DataSourceResult<ContentData> = {
3
+ /** The data that will be used as content. */
4
+ content: ContentData;
5
+ /** Additional data that may be useful for out-of-band processing at a later time. */
6
+ supplementalData?: {
7
+ data: unknown;
8
+ contentType: string;
9
+ };
10
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
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;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
1
  import { ConditionalExpression } from "./conditional-logic";
2
+ import { ObjectSelection, ObjectFieldMap } from "./DataSourceType";
2
3
  /** InputField type enumeration. */
3
4
  export declare type InputFieldType = InputFieldDefinition["type"];
4
5
  export declare const InputFieldDefaultMap: Record<InputFieldType, string | undefined>;
@@ -6,7 +7,7 @@ export declare type Inputs = Record<string, InputFieldDefinition>;
6
7
  export declare type ConnectionInput = (StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField) & {
7
8
  shown?: boolean;
8
9
  };
9
- export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField;
10
+ export declare type InputFieldDefinition = StringInputField | DataInputField | TextInputField | PasswordInputField | BooleanInputField | CodeInputField | ConditionalInputField | ConnectionInputField | ObjectSelectionInputField | ObjectFieldMapInputField;
10
11
  export declare type InputCleanFunction<TValue, TResult = TValue> = (value: TValue) => TResult;
11
12
  interface BaseInputField {
12
13
  /** Interface label of the InputField. */
@@ -132,6 +133,28 @@ export interface Connection {
132
133
  token?: Record<string, unknown>;
133
134
  context?: Record<string, unknown>;
134
135
  }
136
+ /** Defines attributes of an ObjectSelectionInputField. */
137
+ export interface ObjectSelectionInputField extends BaseInputField {
138
+ /** Data type the InputField will collect. */
139
+ type: "objectselection";
140
+ /** Collection type of the InputField */
141
+ collection?: InputFieldCollection;
142
+ /** Default value for this field. */
143
+ default?: ObjectSelection;
144
+ /** Clean function */
145
+ clean?: InputCleanFunction<NonNullable<this["default"]>>;
146
+ }
147
+ /** Defines attributes of an ObjectFieldMapInputField. */
148
+ export interface ObjectFieldMapInputField extends BaseInputField {
149
+ /** Data type the InputField will collect. */
150
+ type: "objectfieldmap";
151
+ /** Collection type of the InputField */
152
+ collection?: InputFieldCollection;
153
+ /** Default value for this field. */
154
+ default?: ObjectFieldMap;
155
+ /** Clean function */
156
+ clean?: InputCleanFunction<NonNullable<this["default"]>>;
157
+ }
135
158
  /** Defines a single Choice option for a InputField. */
136
159
  export interface InputFieldChoice {
137
160
  /** Label to display for this Choice. */
@@ -10,4 +10,6 @@ exports.InputFieldDefaultMap = {
10
10
  code: "",
11
11
  conditional: undefined,
12
12
  connection: undefined,
13
+ objectselection: undefined,
14
+ objectfieldmap: undefined,
13
15
  };
@@ -18,3 +18,7 @@ export * from "./TriggerPerformFunction";
18
18
  export * from "./TriggerDefinition";
19
19
  export * from "./HttpResponse";
20
20
  export * from "./TriggerPayload";
21
+ export * from "./DataSourceDefinition";
22
+ export * from "./DataSourcePerformFunction";
23
+ export * from "./DataSourceResult";
24
+ export * from "./DataSourceType";
@@ -34,3 +34,7 @@ __exportStar(require("./TriggerPerformFunction"), exports);
34
34
  __exportStar(require("./TriggerDefinition"), exports);
35
35
  __exportStar(require("./HttpResponse"), exports);
36
36
  __exportStar(require("./TriggerPayload"), exports);
37
+ __exportStar(require("./DataSourceDefinition"), exports);
38
+ __exportStar(require("./DataSourcePerformFunction"), exports);
39
+ __exportStar(require("./DataSourceResult"), exports);
40
+ __exportStar(require("./DataSourceType"), exports);
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 } from "./types";
6
+ import { KeyValuePair, DataPayload, ObjectSelection, ObjectFieldMap } from "./types";
7
7
  /**
8
8
  * This function returns a lower cased version of the headers passed to it.
9
9
  *
@@ -36,6 +36,10 @@ declare const _default: {
36
36
  isJSON: (value: string) => boolean;
37
37
  toJSON: (value: unknown) => string;
38
38
  lowerCaseHeaders: (headers: Record<string, string>) => Record<string, string>;
39
+ isObjectSelection: (value: unknown) => value is ObjectSelection;
40
+ toObjectSelection: (value: unknown) => ObjectSelection;
41
+ isObjectFieldMap: (value: unknown) => value is ObjectFieldMap;
42
+ toObjectFieldMap: (value: unknown) => ObjectFieldMap;
39
43
  };
40
44
  docs: {
41
45
  formatJsonExample: (input: unknown) => string;
package/dist/util.js CHANGED
@@ -15,6 +15,81 @@ const isValid_1 = __importDefault(require("date-fns/isValid"));
15
15
  const isDate_1 = __importDefault(require("date-fns/isDate"));
16
16
  const safe_stable_stringify_1 = require("safe-stable-stringify");
17
17
  const valid_url_1 = require("valid-url");
18
+ const isObjectWithTruthyKeys = (value, keys) => {
19
+ return (value !== null &&
20
+ typeof value === "object" &&
21
+ keys.every((key) => key in value && Boolean(value === null || value === void 0 ? void 0 : value[key])));
22
+ };
23
+ /**
24
+ * @param value The value to test
25
+ * @returns This function returns true if the type of `value` is an ObjectSelection, or false otherwise.
26
+ */
27
+ const isObjectSelection = (value) => {
28
+ if (Array.isArray(value)) {
29
+ for (const selection of value) {
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;
45
+ }
46
+ return true;
47
+ };
48
+ /**
49
+ * This function coerces a provided value into an ObjectSelection if possible.
50
+ * @param value The value to coerce to ObjectSelection.
51
+ * @returns This function returns the the value as an ObjectSelection if possible.
52
+ */
53
+ const toObjectSelection = (value) => {
54
+ if (isObjectSelection(value)) {
55
+ return value;
56
+ }
57
+ throw new Error(`Value '${value}' cannot be coerced to ObjectSelection.`);
58
+ };
59
+ /**
60
+ * @param value The value to test
61
+ * @returns This function returns true if the type of `value` is an ObjectFieldMap, or false otherwise.
62
+ */
63
+ const isObjectFieldMap = (value) => {
64
+ if (Array.isArray(value)) {
65
+ for (const fieldMap of value) {
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
+ }
76
+ }
77
+ else {
78
+ return false;
79
+ }
80
+ return true;
81
+ };
82
+ /**
83
+ * This function coerces a provided value into an ObjectFieldMap if possible.
84
+ * @param value The value to coerce to ObjectFieldMap.
85
+ * @returns This function returns the the value as an ObjectFieldMap if possible.
86
+ */
87
+ const toObjectFieldMap = (value) => {
88
+ if (isObjectFieldMap(value)) {
89
+ return value;
90
+ }
91
+ throw new Error(`Value '${value}' cannot be coerced to ObjectFieldMap.`);
92
+ };
18
93
  /**
19
94
  * Determine if a variable is a boolean (true or false).
20
95
  *
@@ -357,6 +432,10 @@ exports.default = {
357
432
  isJSON,
358
433
  toJSON,
359
434
  lowerCaseHeaders: exports.lowerCaseHeaders,
435
+ isObjectSelection,
436
+ toObjectSelection,
437
+ isObjectFieldMap,
438
+ toObjectFieldMap,
360
439
  },
361
440
  docs: {
362
441
  formatJsonExample,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "6.6.1",
3
+ "version": "7.0.0-pre",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"