@prismatic-io/spectral 6.1.0 → 6.3.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/serverTypes/convert.d.ts +1 -1
- package/dist/serverTypes/index.d.ts +25 -15
- package/dist/serverTypes/index.js +2 -1
- package/dist/testing.d.ts +13 -4
- package/dist/testing.js +36 -2
- package/dist/types/ActionPerformReturn.d.ts +1 -1
- package/dist/types/ComponentDefinition.d.ts +4 -7
- package/dist/types/TriggerPayload.d.ts +2 -0
- package/dist/types/TriggerResult.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
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: {
|
|
@@ -60,6 +60,7 @@ interface TriggerPayload {
|
|
|
60
60
|
data: unknown;
|
|
61
61
|
contentType?: string;
|
|
62
62
|
};
|
|
63
|
+
pathFragment: string;
|
|
63
64
|
webhookUrls: Record<string, string>;
|
|
64
65
|
webhookApiKeys: Record<string, string[]>;
|
|
65
66
|
invokeUrl: string;
|
|
@@ -90,9 +91,9 @@ interface TriggerBaseResult {
|
|
|
90
91
|
interface TriggerBranchingResult extends TriggerBaseResult {
|
|
91
92
|
branch: string;
|
|
92
93
|
}
|
|
93
|
-
declare type TriggerResult = TriggerBranchingResult | TriggerBaseResult | undefined;
|
|
94
|
-
declare type TriggerPerformFunction = (context: ActionContext, payload: TriggerPayload, params: Record<string, unknown>) => Promise<TriggerResult>;
|
|
95
|
-
interface Trigger {
|
|
94
|
+
export declare type TriggerResult = TriggerBranchingResult | TriggerBaseResult | undefined;
|
|
95
|
+
export declare type TriggerPerformFunction = (context: ActionContext, payload: TriggerPayload, params: Record<string, unknown>) => Promise<TriggerResult>;
|
|
96
|
+
export interface Trigger {
|
|
96
97
|
key: string;
|
|
97
98
|
display: DisplayDefinition & {
|
|
98
99
|
directions?: string;
|
|
@@ -110,11 +111,11 @@ interface Trigger {
|
|
|
110
111
|
examplePayload?: unknown;
|
|
111
112
|
isCommonTrigger?: boolean;
|
|
112
113
|
}
|
|
113
|
-
declare enum OAuth2Type {
|
|
114
|
+
export declare enum OAuth2Type {
|
|
114
115
|
ClientCredentials = "client_credentials",
|
|
115
116
|
AuthorizationCode = "authorization_code"
|
|
116
117
|
}
|
|
117
|
-
interface Connection {
|
|
118
|
+
export interface Connection {
|
|
118
119
|
key: string;
|
|
119
120
|
label: string;
|
|
120
121
|
comments?: string;
|
|
@@ -124,6 +125,15 @@ interface Connection {
|
|
|
124
125
|
shown?: boolean;
|
|
125
126
|
})[];
|
|
126
127
|
}
|
|
128
|
+
export interface ConnectionValue {
|
|
129
|
+
key: string;
|
|
130
|
+
configVarKey: string;
|
|
131
|
+
fields: {
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
};
|
|
134
|
+
token?: Record<string, unknown>;
|
|
135
|
+
context?: Record<string, unknown>;
|
|
136
|
+
}
|
|
127
137
|
interface ServerPerformDataStructureReturn {
|
|
128
138
|
data: boolean | number | string | Record<string, unknown> | unknown[] | unknown;
|
|
129
139
|
contentType?: string;
|
|
@@ -146,13 +156,13 @@ interface ServerPerformBranchingDataStructureReturn extends ServerPerformDataStr
|
|
|
146
156
|
interface ServerPerformBranchingDataReturn extends ServerPerformDataReturn {
|
|
147
157
|
branch: string;
|
|
148
158
|
}
|
|
149
|
-
declare type ActionPerformReturn = ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn | ServerPerformDataReturn | ServerPerformBranchingDataReturn | undefined;
|
|
150
|
-
declare type ActionPerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<ActionPerformReturn>;
|
|
159
|
+
export declare type ActionPerformReturn = ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn | ServerPerformDataReturn | ServerPerformBranchingDataReturn | undefined;
|
|
160
|
+
export declare type ActionPerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<ActionPerformReturn>;
|
|
151
161
|
interface InputFieldChoice {
|
|
152
162
|
label: string;
|
|
153
163
|
value: string;
|
|
154
164
|
}
|
|
155
|
-
interface Input {
|
|
165
|
+
export interface Input {
|
|
156
166
|
key: string;
|
|
157
167
|
label: string;
|
|
158
168
|
keyLabel?: string;
|
|
@@ -166,4 +176,4 @@ interface Input {
|
|
|
166
176
|
model?: InputFieldChoice[];
|
|
167
177
|
language?: string;
|
|
168
178
|
}
|
|
169
|
-
export
|
|
179
|
+
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 {
|
|
9
|
-
export declare const createConnection: <T extends
|
|
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
|
-
|
|
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: "",
|
|
@@ -68,6 +68,7 @@ const defaultTriggerPayload = () => {
|
|
|
68
68
|
data: JSON.stringify(payloadData),
|
|
69
69
|
contentType,
|
|
70
70
|
},
|
|
71
|
+
pathFragment: "",
|
|
71
72
|
webhookUrls: {
|
|
72
73
|
"Flow 1": "https://example.com",
|
|
73
74
|
},
|
|
@@ -105,8 +106,41 @@ const invokeTrigger = ({ perform }, context, payload, params) => __awaiter(void
|
|
|
105
106
|
};
|
|
106
107
|
});
|
|
107
108
|
exports.invokeTrigger = invokeTrigger;
|
|
109
|
+
class ComponentTestHarness {
|
|
110
|
+
constructor(component) {
|
|
111
|
+
this.component = component;
|
|
112
|
+
}
|
|
113
|
+
connectionValue({ key }) {
|
|
114
|
+
const { PRISMATIC_CONNECTION_VALUE: value } = process.env;
|
|
115
|
+
if (!value) {
|
|
116
|
+
throw new Error("Unable to find connection value.");
|
|
117
|
+
}
|
|
118
|
+
const result = Object.assign(Object.assign({}, JSON.parse(value)), { key });
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
trigger(key, payload, params, context) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId" }, context);
|
|
124
|
+
const trigger = this.component.triggers[key];
|
|
125
|
+
return trigger.perform(realizedContext, Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload), Object.assign({}, params));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
action(key, params, context) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const realizedContext = Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, stepId: "mockStepId", executionId: "mockExecutionId" }, context);
|
|
131
|
+
const action = this.component.actions[key];
|
|
132
|
+
return action.perform(realizedContext, Object.assign({}, params));
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.ComponentTestHarness = ComponentTestHarness;
|
|
137
|
+
const createHarness = (component) => {
|
|
138
|
+
return new ComponentTestHarness(component);
|
|
139
|
+
};
|
|
140
|
+
exports.createHarness = createHarness;
|
|
108
141
|
exports.default = {
|
|
142
|
+
loggerMock: exports.loggerMock,
|
|
109
143
|
invoke: exports.invoke,
|
|
110
144
|
invokeTrigger: exports.invokeTrigger,
|
|
111
|
-
|
|
145
|
+
createHarness: exports.createHarness,
|
|
112
146
|
};
|
|
@@ -9,7 +9,7 @@ export interface ActionPerformDataReturn<ReturnData> {
|
|
|
9
9
|
/** An optional object, the keys and values of which will be persisted in the flow-specific instanceState and available for subsequent actions and executions */
|
|
10
10
|
instanceState?: Record<string, unknown>;
|
|
11
11
|
/** An optional object, the keys and values of which will be persisted in the crossFlowState and available in any flow for subsequent actions and executions */
|
|
12
|
-
crossFlowState
|
|
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
15
|
}
|
|
@@ -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
|
-
|
|
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
|
-
/**
|
|
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 {};
|
|
@@ -14,6 +14,8 @@ export interface TriggerPayload {
|
|
|
14
14
|
data: unknown;
|
|
15
15
|
contentType?: string;
|
|
16
16
|
};
|
|
17
|
+
/** Extended path information from the webhook trigger */
|
|
18
|
+
pathFragment: string;
|
|
17
19
|
/** The webhook URLs assigned to this integration's flows upon instance deploy */
|
|
18
20
|
webhookUrls: {
|
|
19
21
|
[key: string]: string;
|
|
@@ -9,7 +9,7 @@ export interface TriggerBaseResult {
|
|
|
9
9
|
/** An optional object, the keys and values of which will be persisted in the flow-specific instanceState and available for subsequent actions and executions */
|
|
10
10
|
instanceState?: Record<string, unknown>;
|
|
11
11
|
/** An optional object, the keys and values of which will be persisted in the crossFlowState and available in any flow for subsequent actions and executions */
|
|
12
|
-
crossFlowState
|
|
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
15
|
}
|