@prismatic-io/spectral 6.1.1 → 6.2.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.
@@ -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 = false>({ connections, actions, triggers, hooks, ...definition }: ComponentDefinition<TPublic>) => ServerComponent;
3
+ export declare const convertComponent: <TPublic extends boolean>({ connections, actions, triggers, hooks, ...definition }: ComponentDefinition<TPublic>) => ServerComponent;
@@ -3,7 +3,7 @@ interface DisplayDefinition {
3
3
  label: string;
4
4
  description: string;
5
5
  }
6
- interface Component {
6
+ export interface Component {
7
7
  key: string;
8
8
  public?: boolean;
9
9
  documentationUrl?: string;
@@ -15,7 +15,7 @@ interface Component {
15
15
  triggers: Record<string, Trigger>;
16
16
  connections: Connection[];
17
17
  }
18
- interface Action {
18
+ export interface Action {
19
19
  key: string;
20
20
  display: DisplayDefinition & {
21
21
  directions?: string;
@@ -30,8 +30,8 @@ interface Action {
30
30
  perform: ActionPerformFunction;
31
31
  examplePayload?: unknown;
32
32
  }
33
- declare type ActionLoggerFunction = (...args: unknown[]) => void;
34
- interface ActionLogger {
33
+ export declare type ActionLoggerFunction = (...args: unknown[]) => void;
34
+ export interface ActionLogger {
35
35
  metric: ActionLoggerFunction;
36
36
  trace: ActionLoggerFunction;
37
37
  debug: ActionLoggerFunction;
@@ -40,7 +40,7 @@ interface ActionLogger {
40
40
  warn: ActionLoggerFunction;
41
41
  error: ActionLoggerFunction;
42
42
  }
43
- interface ActionContext {
43
+ export interface ActionContext {
44
44
  logger: ActionLogger;
45
45
  instanceState: Record<string, unknown>;
46
46
  crossFlowState: Record<string, unknown>;
@@ -49,7 +49,7 @@ interface ActionContext {
49
49
  executionId: string;
50
50
  }
51
51
  declare type TriggerOptionChoice = "invalid" | "valid" | "required";
52
- interface TriggerPayload {
52
+ export interface TriggerPayload {
53
53
  headers: Record<string, string>;
54
54
  queryParameters: Record<string, string>;
55
55
  rawBody: {
@@ -90,9 +90,9 @@ interface TriggerBaseResult {
90
90
  interface TriggerBranchingResult extends TriggerBaseResult {
91
91
  branch: string;
92
92
  }
93
- declare type TriggerResult = TriggerBranchingResult | TriggerBaseResult | undefined;
94
- declare type TriggerPerformFunction = (context: ActionContext, payload: TriggerPayload, params: Record<string, unknown>) => Promise<TriggerResult>;
95
- interface Trigger {
93
+ export declare type TriggerResult = TriggerBranchingResult | TriggerBaseResult | undefined;
94
+ export declare type TriggerPerformFunction = (context: ActionContext, payload: TriggerPayload, params: Record<string, unknown>) => Promise<TriggerResult>;
95
+ export interface Trigger {
96
96
  key: string;
97
97
  display: DisplayDefinition & {
98
98
  directions?: string;
@@ -110,11 +110,11 @@ interface Trigger {
110
110
  examplePayload?: unknown;
111
111
  isCommonTrigger?: boolean;
112
112
  }
113
- declare enum OAuth2Type {
113
+ export declare enum OAuth2Type {
114
114
  ClientCredentials = "client_credentials",
115
115
  AuthorizationCode = "authorization_code"
116
116
  }
117
- interface Connection {
117
+ export interface Connection {
118
118
  key: string;
119
119
  label: string;
120
120
  comments?: string;
@@ -124,6 +124,15 @@ interface Connection {
124
124
  shown?: boolean;
125
125
  })[];
126
126
  }
127
+ export interface ConnectionValue {
128
+ key: string;
129
+ configVarKey: string;
130
+ fields: {
131
+ [key: string]: unknown;
132
+ };
133
+ token?: Record<string, unknown>;
134
+ context?: Record<string, unknown>;
135
+ }
127
136
  interface ServerPerformDataStructureReturn {
128
137
  data: boolean | number | string | Record<string, unknown> | unknown[] | unknown;
129
138
  contentType?: string;
@@ -146,13 +155,13 @@ interface ServerPerformBranchingDataStructureReturn extends ServerPerformDataStr
146
155
  interface ServerPerformBranchingDataReturn extends ServerPerformDataReturn {
147
156
  branch: string;
148
157
  }
149
- declare type ActionPerformReturn = ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn | ServerPerformDataReturn | ServerPerformBranchingDataReturn | undefined;
150
- declare type ActionPerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<ActionPerformReturn>;
158
+ export declare type ActionPerformReturn = ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn | ServerPerformDataReturn | ServerPerformBranchingDataReturn | undefined;
159
+ export declare type ActionPerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<ActionPerformReturn>;
151
160
  interface InputFieldChoice {
152
161
  label: string;
153
162
  value: string;
154
163
  }
155
- interface Input {
164
+ export interface Input {
156
165
  key: string;
157
166
  label: string;
158
167
  keyLabel?: string;
@@ -166,4 +175,4 @@ interface Input {
166
175
  model?: InputFieldChoice[];
167
176
  language?: string;
168
177
  }
169
- export type { Component, Trigger, Action, Connection, Input };
178
+ export {};
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuth2Type = void 0;
3
4
  var OAuth2Type;
4
5
  (function (OAuth2Type) {
5
6
  OAuth2Type["ClientCredentials"] = "client_credentials";
6
7
  OAuth2Type["AuthorizationCode"] = "authorization_code";
7
- })(OAuth2Type || (OAuth2Type = {}));
8
+ })(OAuth2Type = exports.OAuth2Type || (exports.OAuth2Type = {}));
package/dist/testing.d.ts CHANGED
@@ -4,9 +4,9 @@
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
- /** */
8
- import { ActionContext, ActionLogger, ActionDefinition, ActionInputParameters, ConnectionDefinition, Connection, Inputs, TriggerDefinition, TriggerPayload } from "./types";
9
- export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>) => Connection;
7
+ import { TriggerPayload, TriggerResult, Connection, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn } from "./serverTypes";
8
+ import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters } from "./types";
9
+ export declare const createConnection: <T extends Connection>({ key }: T, values: Record<string, unknown>) => ConnectionValue;
10
10
  /**
11
11
  * Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
12
12
  * See https://prismatic.io/docs/custom-components/writing-custom-components/#verifying-correct-logging-in-action-tests for information on testing correct logging behavior in your custom component.
@@ -34,9 +34,18 @@ export declare const defaultTriggerPayload: () => TriggerPayload;
34
34
  * trigger result and a mock logger for asserting logging.
35
35
  */
36
36
  export declare const invokeTrigger: <T extends Inputs>({ perform }: TriggerDefinition<T>, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<T> | undefined) => Promise<InvokeReturn<import("./types").TriggerResult<boolean | undefined>>>;
37
+ export declare class ComponentTestHarness<TComponent extends Component> {
38
+ component: TComponent;
39
+ constructor(component: TComponent);
40
+ connectionValue({ key }: ConnectionDefinition): ConnectionValue;
41
+ trigger(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<TriggerResult>;
42
+ action(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext>): Promise<ActionPerformReturn>;
43
+ }
44
+ export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
37
45
  declare const _default: {
46
+ loggerMock: () => ActionLogger;
38
47
  invoke: <T extends Inputs>({ perform }: ActionDefinition<T>, params: ActionInputParameters<T>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<import("./types").ActionPerformReturn<boolean | undefined, unknown>>>;
39
48
  invokeTrigger: <T_1 extends Inputs>({ perform }: TriggerDefinition<T_1>, context?: Partial<ActionContext> | undefined, payload?: TriggerPayload | undefined, params?: ActionInputParameters<T_1> | undefined) => Promise<InvokeReturn<import("./types").TriggerResult<boolean | undefined>>>;
40
- loggerMock: () => ActionLogger;
49
+ createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
41
50
  };
42
51
  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.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.createConnection = void 0;
18
+ exports.createHarness = exports.ComponentTestHarness = 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: "",
@@ -105,8 +105,41 @@ const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void
105
105
  };
106
106
  });
107
107
  exports.invokeTrigger = invokeTrigger;
108
+ class ComponentTestHarness {
109
+ constructor(component) {
110
+ this.component = component;
111
+ }
112
+ connectionValue({ key }) {
113
+ const { PRISMATIC_CONNECTION_VALUE: value } = process.env;
114
+ if (!value) {
115
+ throw new Error("Unable to find connection value.");
116
+ }
117
+ const result = Object.assign(Object.assign({}, JSON.parse(value)), { key });
118
+ return result;
119
+ }
120
+ trigger(key, payload, params, context) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId" }, context);
123
+ const trigger = this.component.triggers[key];
124
+ return trigger.perform(realizedContext, Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), Object.assign({}, params));
125
+ });
126
+ }
127
+ action(key, params, context) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId" }, context);
130
+ const action = this.component.actions[key];
131
+ return action.perform(realizedContext, Object.assign({}, params));
132
+ });
133
+ }
134
+ }
135
+ exports.ComponentTestHarness = ComponentTestHarness;
136
+ const createHarness = (component) => {
137
+ return new ComponentTestHarness(component);
138
+ };
139
+ exports.createHarness = createHarness;
108
140
  exports.default = {
141
+ loggerMock: exports.loggerMock,
109
142
  invoke: exports.invoke,
110
143
  invokeTrigger: exports.invokeTrigger,
111
- loggerMock: exports.loggerMock,
144
+ createHarness: exports.createHarness,
112
145
  };
@@ -4,13 +4,12 @@ export interface ComponentHooks {
4
4
  /** Defines a global error handler that automatically wraps the component's action/trigger perform functions. */
5
5
  error?: ErrorHandler;
6
6
  }
7
- interface BaseComponentDefinition<TPublic extends boolean = false> {
7
+ /** Defines attributes of a Component. */
8
+ export declare type ComponentDefinition<TPublic extends boolean> = {
8
9
  /** Specifies unique key for this Component. */
9
10
  key: string;
10
11
  /** Specifies if this Component is available for all Organizations or only your own @default false */
11
12
  public?: TPublic;
12
- /** Specified the URL for the Component Documentation. */
13
- documentationUrl?: string;
14
13
  /** Defines how the Component is displayed in the Prismatic interface. */
15
14
  display: ComponentDisplayDefinition<TPublic>;
16
15
  /** Specifies the supported Actions of this Component. */
@@ -21,9 +20,7 @@ interface BaseComponentDefinition<TPublic extends boolean = false> {
21
20
  connections?: ConnectionDefinition[];
22
21
  /** Hooks */
23
22
  hooks?: ComponentHooks;
24
- }
25
- /** Defines attributes of a Component. */
26
- export declare type ComponentDefinition<TPublic extends boolean = false> = BaseComponentDefinition<TPublic> & (TPublic extends true ? {
23
+ } & (TPublic extends true ? {
24
+ /** Specified the URL for the Component Documentation. */
27
25
  documentationUrl: string;
28
26
  } : unknown);
29
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "6.1.1",
3
+ "version": "6.2.0",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"