@prismatic-io/spectral 7.0.3-pre → 7.0.4-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.
@@ -1,9 +1,11 @@
1
1
  /// <reference types="node" />
2
- import { DataSourceResultType, DataSourceResultFieldType } from "../types";
2
+ import { DataSourceResultType, DataSourceResultFieldType, Instance, Customer } 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
- id: string | null;
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
- id: string | null;
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;
@@ -129,12 +117,12 @@ export interface Trigger {
129
117
  }
130
118
  export declare type DataSourceResult = {
131
119
  result: DataSourceResultType;
132
- supplementalData: {
120
+ supplementalData?: {
133
121
  data: unknown;
134
122
  contentType: string;
135
123
  };
136
124
  };
137
- export declare type DataSourcePerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<DataSourceResult>;
125
+ export declare type DataSourcePerformFunction = (params: Record<string, unknown>) => Promise<DataSourceResult>;
138
126
  export interface DataSource {
139
127
  key: string;
140
128
  display: DisplayDefinition & {
@@ -215,4 +203,3 @@ export interface Input {
215
203
  model?: InputFieldChoice[];
216
204
  language?: string;
217
205
  }
218
- 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
@@ -5,7 +5,7 @@
5
5
  * https://prismatic.io/docs/custom-components/writing-custom-components/#testing-a-component
6
6
  */
7
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";
8
+ import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult } 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.
@@ -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,18 @@ 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
- * 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.
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, TReturn extends InvokeDataSourceResult<unknown>>({ perform }: DataSourceDefinition<TInputs, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<TReturn>>;
42
+ export declare const invokeDataSource: <TInputs extends Inputs, TReturn extends DataSourceResult>({ perform }: DataSourceDefinition<TInputs, TReturn>, params: ActionInputParameters<TInputs>) => Promise<TReturn>;
44
43
  export declare class ComponentTestHarness<TComponent extends Component> {
45
44
  component: TComponent;
46
45
  constructor(component: TComponent);
47
46
  connectionValue({ key }: ConnectionDefinition): ConnectionValue;
48
47
  trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>;
49
48
  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>;
49
+ dataSource(key: string, params?: Record<string, unknown>): Promise<DataSourceResult>;
51
50
  }
52
51
  export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
53
52
  declare const _default: {
@@ -55,6 +54,6 @@ declare const _default: {
55
54
  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
55
  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
56
  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>>;
57
+ invokeDataSource: <TInputs_2 extends Inputs, TReturn_1 extends DataSourceResult>({ perform }: DataSourceDefinition<TInputs_2, TReturn_1>, params: ActionInputParameters<TInputs_2>) => Promise<TReturn_1>;
59
58
  };
60
59
  export default _default;
package/dist/testing.js CHANGED
@@ -131,18 +131,13 @@ const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void
131
131
  });
132
132
  exports.invokeTrigger = invokeTrigger;
133
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.
134
+ * Invokes specified DataSourceDefinition perform function using supplied params.
135
+ * Accepts a generic type matching DataSourceResult as a convenience to avoid extra
136
+ * casting within test methods. Returns a DataSourceResult.
138
137
  */
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
- };
138
+ const invokeDataSource = ({ perform }, params) => __awaiter(void 0, void 0, void 0, function* () {
139
+ const result = yield perform(params);
140
+ return result;
146
141
  });
147
142
  exports.invokeDataSource = invokeDataSource;
148
143
  class ComponentTestHarness {
@@ -171,11 +166,10 @@ class ComponentTestHarness {
171
166
  return action.perform(realizedContext, Object.assign({}, params));
172
167
  });
173
168
  }
174
- dataSource(key, params, context) {
169
+ dataSource(key, params) {
175
170
  return __awaiter(this, void 0, void 0, function* () {
176
- const realizedContext = Object.assign(Object.assign({}, baseContext), context);
177
171
  const dataSource = this.component.dataSources[key];
178
- return dataSource.perform(realizedContext, Object.assign({}, params));
172
+ return dataSource.perform(Object.assign({}, params));
179
173
  });
180
174
  }
181
175
  }
@@ -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
- /** An object containing the ID, External ID and name of the customer the instance is deployed to */
25
- customer: {
26
- id: string | null;
27
- externalId: string | null;
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
  }
@@ -0,0 +1,6 @@
1
+ /** Contains attributes of the Customer for whom an Instance is being executed. */
2
+ export interface Customer {
3
+ id: string;
4
+ externalId: string;
5
+ name: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,3 @@
1
- import { Inputs, DataSourceResult, DataSourceResultType, ActionInputParameters, ActionContext } from ".";
1
+ import { Inputs, DataSourceResult, DataSourceResultType, ActionInputParameters } from ".";
2
2
  /** Definition of the function to perform when a Data Source is invoked. */
3
- export declare type DataSourcePerformFunction<T extends Inputs, TResult extends DataSourceResult<DataSourceResultType>> = (context: ActionContext, params: ActionInputParameters<T>) => Promise<TResult>;
3
+ export declare type DataSourcePerformFunction<T extends Inputs, TResult extends DataSourceResult<DataSourceResultType>> = (params: ActionInputParameters<T>) => Promise<TResult>;
@@ -0,0 +1,5 @@
1
+ /** Contains attributes of the Instance that is being executed. */
2
+ export interface Instance {
3
+ id: string;
4
+ name: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
- customer: {
31
- id: string | null;
32
- externalId: string | null;
33
- name: string | null;
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
  }
@@ -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 "./Instance";
25
+ export * from "./Customer";
24
26
  export * as serverTypes from "../serverTypes";
@@ -50,4 +50,6 @@ __exportStar(require("./TriggerPayload"), exports);
50
50
  __exportStar(require("./DataSourceDefinition"), exports);
51
51
  __exportStar(require("./DataSourcePerformFunction"), exports);
52
52
  __exportStar(require("./DataSourceResult"), exports);
53
+ __exportStar(require("./Instance"), exports);
54
+ __exportStar(require("./Customer"), exports);
53
55
  exports.serverTypes = __importStar(require("../serverTypes"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "7.0.3-pre",
3
+ "version": "7.0.4-pre",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"