@prismatic-io/spectral 10.17.2 → 10.18.2
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/clients/http/index.d.ts +84 -16
- package/dist/clients/http/index.js +85 -17
- package/dist/component.d.ts +3 -3
- package/dist/component.js +8 -8
- package/dist/conditionalLogic/index.js +3 -3
- package/dist/errors.d.ts +67 -0
- package/dist/errors.js +67 -0
- package/dist/generators/cniComponentManifest/cli.js +5 -5
- package/dist/generators/cniComponentManifest/index.d.ts +1 -1
- package/dist/generators/componentManifest/cli.js +6 -6
- package/dist/generators/componentManifest/createActions.d.ts +1 -1
- package/dist/generators/componentManifest/createActions.js +4 -4
- package/dist/generators/componentManifest/createConnections.d.ts +1 -1
- package/dist/generators/componentManifest/createConnections.js +4 -4
- package/dist/generators/componentManifest/createDataSources.d.ts +1 -1
- package/dist/generators/componentManifest/createDataSources.js +4 -4
- package/dist/generators/componentManifest/createStaticFiles.d.ts +1 -1
- package/dist/generators/componentManifest/createStaticFiles.js +1 -1
- package/dist/generators/componentManifest/createTriggers.d.ts +1 -1
- package/dist/generators/componentManifest/createTriggers.js +4 -4
- package/dist/generators/componentManifest/helpers.js +1 -1
- package/dist/generators/componentManifest/index.d.ts +2 -2
- package/dist/generators/componentManifest/index.js +1 -1
- package/dist/generators/utils/escapeSpecialCharacters.js +1 -1
- package/dist/index.d.ts +543 -53
- package/dist/index.js +545 -55
- package/dist/integration.d.ts +2 -2
- package/dist/integration.js +9 -9
- package/dist/serverTypes/asyncContext.d.ts +1 -1
- package/dist/serverTypes/context.d.ts +1 -1
- package/dist/serverTypes/context.js +2 -2
- package/dist/serverTypes/convertComponent.d.ts +2 -2
- package/dist/serverTypes/convertComponent.js +2 -2
- package/dist/serverTypes/convertIntegration.d.ts +3 -3
- package/dist/serverTypes/convertIntegration.js +13 -13
- package/dist/serverTypes/index.d.ts +2 -7
- package/dist/serverTypes/perform.d.ts +1 -1
- package/dist/serverTypes/perform.js +1 -1
- package/dist/testing.d.ts +195 -31
- package/dist/testing.js +199 -33
- package/dist/types/ActionPerformFunction.d.ts +6 -6
- package/dist/types/ConfigVars.d.ts +6 -6
- package/dist/types/ConnectionDefinition.d.ts +1 -1
- package/dist/types/FlowAttributes.d.ts +1 -1
- package/dist/types/index.d.ts +20 -20
- package/dist/types/index.js +20 -20
- package/dist/types/typeExportComponent.d.ts +15 -15
- package/dist/types/typeExportComponent.js +18 -18
- package/dist/types/typeExportIntegration.d.ts +17 -17
- package/dist/types/typeExportIntegration.js +17 -17
- package/dist/util.d.ts +29 -14
- package/dist/util.js +366 -108
- package/package.json +26 -28
package/dist/integration.d.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* This module contains functions to help developers create integrations
|
|
3
3
|
* that can run on the Prismatic platform.
|
|
4
4
|
*/
|
|
5
|
-
export { integration, flow, configVar, dataSourceConfigVar, connectionConfigVar, customerActivatedConnection, organizationActivatedConnection, componentManifest, componentManifests, onPremConnection, oauth2Connection, } from "./index";
|
|
6
|
-
export * from "./types/typeExportIntegration";
|
|
7
5
|
export * from "./errors";
|
|
6
|
+
export { componentManifest, componentManifests, configVar, connectionConfigVar, customerActivatedConnection, dataSourceConfigVar, flow, integration, oauth2Connection, onPremConnection, organizationActivatedConnection, } from "./index";
|
|
7
|
+
export * from "./types/typeExportIntegration";
|
package/dist/integration.js
CHANGED
|
@@ -18,18 +18,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.
|
|
21
|
+
exports.organizationActivatedConnection = exports.onPremConnection = exports.oauth2Connection = exports.integration = exports.flow = exports.dataSourceConfigVar = exports.customerActivatedConnection = exports.connectionConfigVar = exports.configVar = exports.componentManifests = exports.componentManifest = void 0;
|
|
22
|
+
__exportStar(require("./errors"), exports);
|
|
22
23
|
var index_1 = require("./index");
|
|
23
|
-
Object.defineProperty(exports, "
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "componentManifest", { enumerable: true, get: function () { return index_1.componentManifest; } });
|
|
25
|
+
Object.defineProperty(exports, "componentManifests", { enumerable: true, get: function () { return index_1.componentManifests; } });
|
|
25
26
|
Object.defineProperty(exports, "configVar", { enumerable: true, get: function () { return index_1.configVar; } });
|
|
26
|
-
Object.defineProperty(exports, "dataSourceConfigVar", { enumerable: true, get: function () { return index_1.dataSourceConfigVar; } });
|
|
27
27
|
Object.defineProperty(exports, "connectionConfigVar", { enumerable: true, get: function () { return index_1.connectionConfigVar; } });
|
|
28
28
|
Object.defineProperty(exports, "customerActivatedConnection", { enumerable: true, get: function () { return index_1.customerActivatedConnection; } });
|
|
29
|
-
Object.defineProperty(exports, "
|
|
30
|
-
Object.defineProperty(exports, "
|
|
31
|
-
Object.defineProperty(exports, "
|
|
32
|
-
Object.defineProperty(exports, "onPremConnection", { enumerable: true, get: function () { return index_1.onPremConnection; } });
|
|
29
|
+
Object.defineProperty(exports, "dataSourceConfigVar", { enumerable: true, get: function () { return index_1.dataSourceConfigVar; } });
|
|
30
|
+
Object.defineProperty(exports, "flow", { enumerable: true, get: function () { return index_1.flow; } });
|
|
31
|
+
Object.defineProperty(exports, "integration", { enumerable: true, get: function () { return index_1.integration; } });
|
|
33
32
|
Object.defineProperty(exports, "oauth2Connection", { enumerable: true, get: function () { return index_1.oauth2Connection; } });
|
|
33
|
+
Object.defineProperty(exports, "onPremConnection", { enumerable: true, get: function () { return index_1.onPremConnection; } });
|
|
34
|
+
Object.defineProperty(exports, "organizationActivatedConnection", { enumerable: true, get: function () { return index_1.organizationActivatedConnection; } });
|
|
34
35
|
__exportStar(require("./types/typeExportIntegration"), exports);
|
|
35
|
-
__exportStar(require("./errors"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentRegistry,
|
|
1
|
+
import { ComponentRegistry, Inputs, IntegrationDefinition, TriggerPayload, TriggerResult } from "../types";
|
|
2
2
|
import type { ActionContext } from "../types/ActionPerformFunction";
|
|
3
3
|
export declare function runWithContext<T>(context: ActionContext, fn: () => T | Promise<T>): T | Promise<T>;
|
|
4
4
|
export declare function requireContext(): ActionContext;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { ActionContext, ComponentManifest, ComponentRegistry, ConfigVarResultCollection, DebugContext, FlowInvoker } from "../types";
|
|
1
2
|
import { ActionContext as ServerActionContext } from ".";
|
|
2
|
-
import { ActionContext, ComponentRegistry, DebugContext, FlowInvoker, ConfigVarResultCollection, ComponentManifest } from "../types";
|
|
3
3
|
export declare function createCNIContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>, TFlows extends string[] = string[]>(context: ActionContext<TConfigVars, TComponentActions, TFlows>, componentRegistry: ComponentRegistry): ActionContext<TConfigVars, TComponentActions, TFlows>;
|
|
4
4
|
export declare function createDebugContext(context: ServerActionContext): DebugContext;
|
|
5
5
|
export declare function logDebugResults(context: ActionContext): void;
|
|
@@ -16,10 +16,10 @@ exports.createInvokeFlow = void 0;
|
|
|
16
16
|
exports.createCNIContext = createCNIContext;
|
|
17
17
|
exports.createDebugContext = createDebugContext;
|
|
18
18
|
exports.logDebugResults = logDebugResults;
|
|
19
|
-
const node_process_1 = require("node:process");
|
|
20
19
|
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
21
|
-
const
|
|
20
|
+
const node_process_1 = require("node:process");
|
|
22
21
|
const axios_1 = __importDefault(require("axios"));
|
|
22
|
+
const convertIntegration_1 = require("./convertIntegration");
|
|
23
23
|
const MEMORY_USAGE_CONVERSION = 1024 * 1024;
|
|
24
24
|
function createCNIContext(context, componentRegistry) {
|
|
25
25
|
// Component, debug, and invokeFlow methods are not provided as part of the server context.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Component as ServerComponent, Connection as ServerConnection, Trigger as ServerTrigger, Input as ServerInput } from ".";
|
|
1
|
+
import { ComponentDefinition, ComponentHooks, ConfigVarResultCollection, ConnectionDefinition, ConnectionInput, ConnectionTemplateInputField, InputFieldDefinition, Inputs, OnPremConnectionInput, TriggerDefinition, TriggerPayload, TriggerResult } from "../types";
|
|
3
2
|
import { PollingTriggerDefinition } from "../types/PollingTriggerDefinition";
|
|
3
|
+
import { Component as ServerComponent, Connection as ServerConnection, Input as ServerInput, Trigger as ServerTrigger } from ".";
|
|
4
4
|
export declare const convertInput: (key: string, { default: defaultValue, type, label, collection, ...rest }: InputFieldDefinition | OnPremConnectionInput | ConnectionInput) => ServerInput;
|
|
5
5
|
export declare const _isValidTemplateValue: (template: string, inputs: {
|
|
6
6
|
[key: string]: ConnectionInput | ConnectionTemplateInputField;
|
|
@@ -15,10 +15,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.convertComponent = exports.convertConnection = exports.convertTrigger = exports.convertTemplateInput = exports._isValidTemplateValue = exports.convertInput = void 0;
|
|
18
|
-
const types_1 = require("../types");
|
|
19
|
-
const perform_1 = require("./perform");
|
|
20
18
|
const omit_1 = __importDefault(require("lodash/omit"));
|
|
19
|
+
const types_1 = require("../types");
|
|
21
20
|
const PollingTriggerDefinition_1 = require("../types/PollingTriggerDefinition");
|
|
21
|
+
const perform_1 = require("./perform");
|
|
22
22
|
const convertInput = (key, _a) => {
|
|
23
23
|
var { default: defaultValue, type, label, collection } = _a, rest = __rest(_a, ["default", "type", "label", "collection"]);
|
|
24
24
|
const keyLabel = collection === "keyvaluelist" && typeof label === "object" ? label.key : undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Component as ServerComponent,
|
|
3
|
-
import {
|
|
1
|
+
import { CollectionType, ComponentRegistry, ConfigPages, ConfigVar, ConfigVarResultCollection, Flow, Inputs, IntegrationDefinition, QueueConfig, StandardQueueConfig, TriggerResult as TriggerPerformResult, TriggerReference } from "../types";
|
|
2
|
+
import { ActionContext, Component as ServerComponent, TriggerPayload, TriggerResult } from ".";
|
|
3
|
+
import { ComponentReference as ServerComponentReference, ConfigPage as ServerConfigPage, RequiredConfigVariable as ServerRequiredConfigVariable } from "./integration";
|
|
4
4
|
export declare const CONCURRENCY_LIMIT_MAX = 15;
|
|
5
5
|
export declare const CONCURRENCY_LIMIT_MIN = 2;
|
|
6
6
|
export declare const convertIntegration: <TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerPerformResult<TAllowsBranching, TPayload> = TriggerPerformResult<TAllowsBranching, TPayload>>(definition: IntegrationDefinition<TInputs, TActionInputs, TPayload, TAllowsBranching, TResult>) => ServerComponent<TInputs, TActionInputs, ConfigVarResultCollection, TPayload, TAllowsBranching, TResult>;
|
|
@@ -13,20 +13,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.invokeTriggerComponentInput = exports.convertConfigVar = exports.convertInputValue = exports.convertFlow = exports.convertQueueConfig = exports.convertConfigPages = exports.convertIntegration = exports.CONCURRENCY_LIMIT_MIN = exports.CONCURRENCY_LIMIT_MAX = void 0;
|
|
16
|
-
const
|
|
17
|
-
const uuid_1 = require("uuid");
|
|
16
|
+
const fs_1 = require("fs");
|
|
18
17
|
const assign_1 = __importDefault(require("lodash/assign"));
|
|
19
18
|
const camelCase_1 = __importDefault(require("lodash/camelCase"));
|
|
19
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
20
20
|
const pick_1 = __importDefault(require("lodash/pick"));
|
|
21
|
+
const path_1 = __importDefault(require("path"));
|
|
22
|
+
const uuid_1 = require("uuid");
|
|
23
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
21
24
|
const types_1 = require("../types");
|
|
25
|
+
const asyncContext_1 = require("./asyncContext");
|
|
26
|
+
const context_1 = require("./context");
|
|
22
27
|
const convertComponent_1 = require("./convertComponent");
|
|
23
|
-
const perform_1 = require("./perform");
|
|
24
28
|
const integration_1 = require("./integration");
|
|
25
|
-
const
|
|
26
|
-
const context_1 = require("./context");
|
|
27
|
-
const asyncContext_1 = require("./asyncContext");
|
|
28
|
-
const path_1 = __importDefault(require("path"));
|
|
29
|
-
const fs_1 = require("fs");
|
|
29
|
+
const perform_1 = require("./perform");
|
|
30
30
|
exports.CONCURRENCY_LIMIT_MAX = 15;
|
|
31
31
|
exports.CONCURRENCY_LIMIT_MIN = 2;
|
|
32
32
|
const convertIntegration = (definition) => {
|
|
@@ -55,7 +55,7 @@ const convertIntegration = (definition) => {
|
|
|
55
55
|
const file = (0, fs_1.readFileSync)(metaDataPath, { encoding: "utf-8" });
|
|
56
56
|
metadata = JSON.parse(file);
|
|
57
57
|
}
|
|
58
|
-
catch (
|
|
58
|
+
catch (_e) {
|
|
59
59
|
// No-op. If there's no metadata file then we move on.
|
|
60
60
|
}
|
|
61
61
|
const cniComponent = codeNativeIntegrationComponent(definition, referenceKey, configVars);
|
|
@@ -70,7 +70,7 @@ const convertConfigPages = (pages, userLevelConfigured) => {
|
|
|
70
70
|
}
|
|
71
71
|
return Object.entries(pages).map(([name, { tagline, elements }]) => (Object.assign(Object.assign({ name,
|
|
72
72
|
tagline }, (userLevelConfigured ? { userLevelConfigured } : {})), { elements: Object.entries(elements)
|
|
73
|
-
.filter(([
|
|
73
|
+
.filter(([_key, value]) => !(0, types_1.isConnectionScopedConfigVar)(value))
|
|
74
74
|
.map(([key, value]) => {
|
|
75
75
|
if (typeof value === "string") {
|
|
76
76
|
return {
|
|
@@ -210,7 +210,7 @@ const convertComponentReference = (componentReference, componentRegistry, refere
|
|
|
210
210
|
? manifestEntryInput.default === ""
|
|
211
211
|
? []
|
|
212
212
|
: manifestEntryInput.default
|
|
213
|
-
: (_c = manifestEntryInput.default) !== null && _c !== void 0 ? _c : "",
|
|
213
|
+
: ((_c = manifestEntryInput.default) !== null && _c !== void 0 ? _c : ""),
|
|
214
214
|
};
|
|
215
215
|
const type = isCollection ? "complex" : "value" in value ? "value" : "configVar";
|
|
216
216
|
if ("value" in value) {
|
|
@@ -505,7 +505,7 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
|
|
|
505
505
|
} });
|
|
506
506
|
}, {}),
|
|
507
507
|
orgOnly,
|
|
508
|
-
meta: Object.assign(Object.assign({}, meta), ("oauth2Config" in configVar ? (_a = configVar.oauth2Config) !== null && _a !== void 0 ? _a : {} : {})),
|
|
508
|
+
meta: Object.assign(Object.assign({}, meta), ("oauth2Config" in configVar ? ((_a = configVar.oauth2Config) !== null && _a !== void 0 ? _a : {}) : {})),
|
|
509
509
|
};
|
|
510
510
|
}
|
|
511
511
|
if ((0, types_1.isConnectionReferenceConfigVar)(configVar)) {
|
|
@@ -520,7 +520,7 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
|
|
|
520
520
|
connection: Object.assign(Object.assign({}, ref), { template }),
|
|
521
521
|
inputs,
|
|
522
522
|
orgOnly,
|
|
523
|
-
meta: Object.assign(Object.assign({}, meta), ("oauth2Config" in configVar ? (_b = configVar.oauth2Config) !== null && _b !== void 0 ? _b : {} : {})),
|
|
523
|
+
meta: Object.assign(Object.assign({}, meta), ("oauth2Config" in configVar ? ((_b = configVar.oauth2Config) !== null && _b !== void 0 ? _b : {}) : {})),
|
|
524
524
|
};
|
|
525
525
|
}
|
|
526
526
|
const rawDefaultValue = "defaultValue" in configVar
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentManifest, ConfigVarResultCollection, CustomerAttributes, DataSourceResultType, DataSourceType, DebugContext, ExecutionFrame, FlowAttributes, FlowInvoker, FlowSchemas, Inputs, InstanceAttributes, IntegrationAttributes, PollingTriggerPerformFunction, TriggerEventFunctionReturn, TriggerPerformFunction, TriggerResult as TriggerPerformResult, UserAttributes } from "../types";
|
|
2
2
|
import type { CNIPollingPerformFunction, ComponentRefTriggerPerformFunction } from "./triggerTypes";
|
|
3
3
|
interface DisplayDefinition {
|
|
4
4
|
label: string;
|
|
5
5
|
description: string;
|
|
6
6
|
}
|
|
7
|
-
export { InstanceAttributes } from "../types";
|
|
8
|
-
export { CustomerAttributes } from "../types";
|
|
9
|
-
export { UserAttributes } from "../types";
|
|
10
|
-
export { IntegrationAttributes } from "../types";
|
|
11
|
-
export { FlowAttributes } from "../types";
|
|
12
|
-
export { FlowSchemas } from "../types";
|
|
7
|
+
export { CustomerAttributes, FlowAttributes, FlowSchemas, InstanceAttributes, IntegrationAttributes, UserAttributes, } from "../types";
|
|
13
8
|
export interface PublishingMetadata {
|
|
14
9
|
flowsWithCustomerRequiredAPIKeys: {
|
|
15
10
|
name: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActionContext, ComponentRegistry, ConfigVarResultCollection, ErrorHandler, Inputs, PollingContext, PollingTriggerDefinition, PollingTriggerPerformFunction, TriggerPayload, TriggerReference, TriggerResult
|
|
1
|
+
import type { ActionContext, ComponentRegistry, ConfigVarResultCollection, ErrorHandler, Inputs, PollingContext, PollingTriggerDefinition, PollingTriggerPerformFunction, TriggerPayload, TriggerPerformFunction, TriggerReference, TriggerResult } from "../types";
|
|
2
2
|
import { ComponentReference as ServerComponentReference } from "./integration";
|
|
3
3
|
import type { CNIPollingPerformFunction, ComponentRefTriggerPerformFunction } from "./triggerTypes";
|
|
4
4
|
export type PerformFn = (...args: any[]) => Promise<any>;
|
|
@@ -24,9 +24,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.createCNIPerform = exports.createCNIComponentRefPerform = exports.createCNIPollingPerform = exports.createPollingPerform = exports.createPerform = exports.cleanParams = exports.createPollingContext = void 0;
|
|
27
|
-
const convertIntegration_1 = require("./convertIntegration");
|
|
28
27
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
29
28
|
const context_1 = require("./context");
|
|
29
|
+
const convertIntegration_1 = require("./convertIntegration");
|
|
30
30
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
31
|
const createPollingContext = ({ context, invokeAction, }) => {
|
|
32
32
|
return {
|
package/dist/testing.d.ts
CHANGED
|
@@ -4,34 +4,89 @@
|
|
|
4
4
|
* information on unit testing, check out our docs:
|
|
5
5
|
* https://prismatic.io/docs/custom-connectors/unit-testing/
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
import type { ActionContext,
|
|
7
|
+
import type { ActionLogger, Component, ConnectionValue, DataSourceContext, DataSourceResult, ActionPerformReturn as ServerActionPerformReturn, TriggerPayload, TriggerResult } from "./serverTypes";
|
|
8
|
+
import type { ActionContext, ActionDefinition, ActionInputParameters, ComponentManifest, ConfigVarResultCollection, ConnectionDefinition, DataSourceDefinition, DataSourceType, Flow, Inputs, ActionPerformReturn as InvokeActionPerformReturn, DataSourceResult as InvokeDataSourceResult, TriggerResult as InvokeTriggerResult, TriggerDefinition, TriggerEventFunctionReturn } from "./types";
|
|
9
9
|
/**
|
|
10
|
-
* Create a test connection to use when testing your custom component locally.
|
|
11
|
-
*
|
|
10
|
+
* Create a test connection to use when testing your custom component locally.
|
|
11
|
+
* This builds a `ConnectionValue` from your connection definition and
|
|
12
|
+
* test credential values.
|
|
13
|
+
*
|
|
14
|
+
* @param connectionDef The connection definition (only `key` is used).
|
|
15
|
+
* @param values A record of field values for the connection (e.g. `apiKey`, `baseUrl`).
|
|
16
|
+
* @param tokenValues Optional OAuth 2.0 token values (e.g. `access_token`, `refresh_token`).
|
|
17
|
+
* @param displayName Optional display name for the connection config variable.
|
|
18
|
+
* @returns A `ConnectionValue` object suitable for use in test invocations.
|
|
19
|
+
* @see {@link https://prismatic.io/docs/custom-connectors/unit-testing/#providing-test-connection-inputs-to-an-action-test | Test Connection Inputs}
|
|
20
|
+
* @example
|
|
21
|
+
* import { testing } from "@prismatic-io/spectral";
|
|
22
|
+
* import { apiKeyConnection } from "./connections";
|
|
23
|
+
*
|
|
24
|
+
* const testConnection = testing.createConnection(apiKeyConnection, {
|
|
25
|
+
* apiKey: "test-api-key-123",
|
|
26
|
+
* baseUrl: "https://api.acme.com/v2",
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Use with testing.invoke()
|
|
30
|
+
* const { result } = await testing.invoke(myAction, {
|
|
31
|
+
* connection: testConnection,
|
|
32
|
+
* });
|
|
12
33
|
*/
|
|
13
34
|
export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>, tokenValues?: Record<string, unknown>, displayName?: string) => ConnectionValue;
|
|
14
35
|
export declare const defaultConnectionValueEnvironmentVariable = "PRISMATIC_CONNECTION_VALUE";
|
|
15
36
|
/**
|
|
16
|
-
* Source a test connection from an environment variable for local testing.
|
|
17
|
-
*
|
|
37
|
+
* Source a test connection from an environment variable for local testing.
|
|
38
|
+
* The environment variable should contain a JSON-serialized connection value.
|
|
39
|
+
* Defaults to reading from `PRISMATIC_CONNECTION_VALUE`.
|
|
40
|
+
*
|
|
41
|
+
* @param envVarKey The name of the environment variable to read. Defaults to `"PRISMATIC_CONNECTION_VALUE"`.
|
|
42
|
+
* @returns A `ConnectionValue` parsed from the environment variable.
|
|
43
|
+
* @see {@link https://prismatic.io/docs/custom-connectors/unit-testing/#access-connections-for-local-testing | Access Connections for Local Testing}
|
|
44
|
+
* @example
|
|
45
|
+
* import { testing } from "@prismatic-io/spectral";
|
|
46
|
+
*
|
|
47
|
+
* // Reads from PRISMATIC_CONNECTION_VALUE env var (default)
|
|
48
|
+
* const conn = testing.connectionValue();
|
|
49
|
+
*
|
|
50
|
+
* // Or specify a custom env var
|
|
51
|
+
* const conn = testing.connectionValue("MY_ACME_CONNECTION");
|
|
18
52
|
*/
|
|
19
53
|
export declare const connectionValue: (envVarKey?: string) => ConnectionValue;
|
|
20
54
|
/**
|
|
21
|
-
* Pre-built mock of ActionLogger.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
55
|
+
* Pre-built mock of ActionLogger. All log methods (`info`, `warn`, `error`, etc.)
|
|
56
|
+
* are Jest spies, so you can assert that your actions log the expected messages.
|
|
57
|
+
*
|
|
58
|
+
* @returns A mock `ActionLogger` with Jest spy methods.
|
|
59
|
+
* @see {@link https://prismatic.io/docs/custom-connectors/unit-testing/#verifying-correct-logging-in-action-tests | Verifying Logging}
|
|
60
|
+
* @example
|
|
61
|
+
* import { testing } from "@prismatic-io/spectral";
|
|
62
|
+
*
|
|
63
|
+
* const logger = testing.loggerMock();
|
|
64
|
+
* // Pass logger in context, then assert:
|
|
65
|
+
* expect(logger.info).toHaveBeenCalledWith("Processing started");
|
|
24
66
|
*/
|
|
25
67
|
export declare const loggerMock: () => ActionLogger;
|
|
26
68
|
/**
|
|
27
|
-
* Creates basic component mocks based on
|
|
28
|
-
*
|
|
69
|
+
* Creates basic component action mocks based on a code-native integration's
|
|
70
|
+
* component registry. Each action mock returns the action's `examplePayload`
|
|
71
|
+
* by default. Pass overrides in the second argument to customize specific mocks.
|
|
72
|
+
*
|
|
73
|
+
* @param registry The component registry (or subset) to mock.
|
|
74
|
+
* @param mocks Optional overrides for specific component actions.
|
|
75
|
+
* @returns An object of mocked component actions, suitable for use in test context.
|
|
76
|
+
* @see {@link https://prismatic.io/docs/custom-connectors/unit-testing/ | Unit Testing}
|
|
77
|
+
* @example
|
|
78
|
+
* import { createMockContextComponents } from "@prismatic-io/spectral/dist/testing";
|
|
79
|
+
* import { componentRegistry } from "./componentRegistry";
|
|
80
|
+
*
|
|
81
|
+
* // Default mocks (uses examplePayload from the manifest)
|
|
82
|
+
* const components = createMockContextComponents(componentRegistry);
|
|
29
83
|
*
|
|
30
|
-
*
|
|
84
|
+
* // With custom overrides
|
|
85
|
+
* const components = createMockContextComponents(componentRegistry, {
|
|
31
86
|
* actions: {
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* }
|
|
87
|
+
* slack: {
|
|
88
|
+
* postMessage: () => Promise.resolve({ data: { ok: true } }),
|
|
89
|
+
* },
|
|
35
90
|
* },
|
|
36
91
|
* });
|
|
37
92
|
*/
|
|
@@ -48,24 +103,82 @@ interface InvokeReturn<ReturnData> {
|
|
|
48
103
|
loggerMock: ActionLogger;
|
|
49
104
|
}
|
|
50
105
|
/**
|
|
51
|
-
* Invokes
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* action
|
|
106
|
+
* Invokes a custom component action's `perform` function within a test harness.
|
|
107
|
+
* Returns both the action result and a mock logger for asserting logging behavior.
|
|
108
|
+
*
|
|
109
|
+
* @param actionDef The action definition to test (only `perform` is used).
|
|
110
|
+
* @param params Input parameter values to pass to the action's `perform` function.
|
|
111
|
+
* @param context Optional partial context overrides (e.g. custom `configVars` or `instanceState`).
|
|
112
|
+
* @returns An object with `result` (the action's return value) and `loggerMock` (for asserting logs).
|
|
113
|
+
* @see {@link https://prismatic.io/docs/custom-connectors/unit-testing/ | Unit Testing}
|
|
114
|
+
* @example
|
|
115
|
+
* import { testing } from "@prismatic-io/spectral";
|
|
116
|
+
* import { myAction } from "./actions";
|
|
117
|
+
*
|
|
118
|
+
* it("should return items", async () => {
|
|
119
|
+
* const { result, loggerMock } = await testing.invoke(myAction, {
|
|
120
|
+
* connection: testConnection,
|
|
121
|
+
* limit: "10",
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* expect(result.data).toHaveProperty("items");
|
|
125
|
+
* expect(loggerMock.info).toHaveBeenCalled();
|
|
126
|
+
* });
|
|
55
127
|
*/
|
|
56
128
|
export declare const invoke: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean, TReturn extends InvokeActionPerformReturn<TAllowsBranching, unknown>>({ perform }: ActionDefinition<TInputs, TConfigVars, TAllowsBranching, TReturn>, params: ActionInputParameters<TInputs>, context?: Partial<ActionContext<TConfigVars>>) => Promise<InvokeReturn<TReturn>>;
|
|
57
129
|
export declare const defaultTriggerPayload: () => TriggerPayload;
|
|
58
130
|
/**
|
|
59
|
-
* Invokes
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
131
|
+
* Invokes a custom component trigger's `perform` function within a test harness.
|
|
132
|
+
* Provides a default trigger payload that can be overridden. Returns both the
|
|
133
|
+
* trigger result and a mock logger for asserting logging behavior.
|
|
134
|
+
*
|
|
135
|
+
* @param triggerDef The trigger definition to test (only `perform` is used).
|
|
136
|
+
* @param context Optional partial context overrides.
|
|
137
|
+
* @param payload Optional partial trigger payload overrides (merged with defaults).
|
|
138
|
+
* @param params Optional input parameter values for the trigger.
|
|
139
|
+
* @returns An object with `result` (the trigger's return value) and `loggerMock`.
|
|
140
|
+
* @see {@link https://prismatic.io/docs/custom-connectors/unit-testing/ | Unit Testing}
|
|
141
|
+
* @example
|
|
142
|
+
* import { testing } from "@prismatic-io/spectral";
|
|
143
|
+
* import { webhookTrigger } from "./triggers";
|
|
144
|
+
*
|
|
145
|
+
* it("should process the webhook payload", async () => {
|
|
146
|
+
* const { result } = await testing.invokeTrigger(
|
|
147
|
+
* webhookTrigger,
|
|
148
|
+
* undefined, // use default context
|
|
149
|
+
* {
|
|
150
|
+
* body: { data: JSON.stringify({ event: "created" }) },
|
|
151
|
+
* headers: { "x-webhook-secret": "test-secret" },
|
|
152
|
+
* },
|
|
153
|
+
* { secret: "test-secret" },
|
|
154
|
+
* );
|
|
155
|
+
*
|
|
156
|
+
* expect(result.payload).toBeDefined();
|
|
157
|
+
* });
|
|
63
158
|
*/
|
|
64
159
|
export declare const invokeTrigger: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean, TResult extends InvokeTriggerResult<TAllowsBranching, TriggerPayload>>({ perform }: TriggerDefinition<TInputs, TConfigVars, TAllowsBranching, TResult>, context?: Partial<ActionContext<TConfigVars>>, payload?: TriggerPayload, params?: ActionInputParameters<TInputs>) => Promise<InvokeReturn<TResult>>;
|
|
65
160
|
/**
|
|
66
|
-
* Invokes
|
|
67
|
-
*
|
|
68
|
-
*
|
|
161
|
+
* Invokes a custom component data source's `perform` function within a test harness.
|
|
162
|
+
* Returns the data source result directly.
|
|
163
|
+
*
|
|
164
|
+
* @param dataSourceDef The data source definition to test (only `perform` is used).
|
|
165
|
+
* @param params Input parameter values to pass to the data source's `perform` function.
|
|
166
|
+
* @param context Optional partial context overrides.
|
|
167
|
+
* @returns The data source result (e.g. a picklist, JSON form, or other data source type).
|
|
168
|
+
* @see {@link https://prismatic.io/docs/custom-connectors/unit-testing/ | Unit Testing}
|
|
169
|
+
* @example
|
|
170
|
+
* import { testing } from "@prismatic-io/spectral";
|
|
171
|
+
* import { selectChannel } from "./dataSources";
|
|
172
|
+
*
|
|
173
|
+
* it("should return a list of channels", async () => {
|
|
174
|
+
* const result = await testing.invokeDataSource(selectChannel, {
|
|
175
|
+
* connection: testConnection,
|
|
176
|
+
* });
|
|
177
|
+
*
|
|
178
|
+
* expect(result.result).toContainEqual(
|
|
179
|
+
* expect.objectContaining({ label: "General" }),
|
|
180
|
+
* );
|
|
181
|
+
* });
|
|
69
182
|
*/
|
|
70
183
|
export declare const invokeDataSource: <TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TDataSourceType extends DataSourceType>({ perform }: DataSourceDefinition<TInputs, TConfigVars, TDataSourceType>, params: ActionInputParameters<TInputs>, context?: Partial<DataSourceContext<TConfigVars>>) => Promise<InvokeDataSourceResult<TDataSourceType>>;
|
|
71
184
|
type TestConnectionValue = Pick<ConnectionValue, "fields" | "context" | "token" | "key">;
|
|
@@ -74,9 +187,35 @@ type ToTestValues<TConfigVars extends ConfigVarResultCollection> = {
|
|
|
74
187
|
[K in keyof TConfigVars]: TConfigVars[K] extends ConnectionDefinition ? TestConnectionValue : string;
|
|
75
188
|
};
|
|
76
189
|
/**
|
|
77
|
-
* Invokes
|
|
78
|
-
*
|
|
79
|
-
*
|
|
190
|
+
* Invokes a code-native integration flow within a test harness. Runs the
|
|
191
|
+
* flow's `onTrigger` (if defined) followed by `onExecution`, and returns
|
|
192
|
+
* the execution result. Accepts optional config variables, context overrides,
|
|
193
|
+
* and a custom trigger payload.
|
|
194
|
+
*
|
|
195
|
+
* @param flow The flow definition to test.
|
|
196
|
+
* @param options Optional config variables, context overrides, and trigger payload.
|
|
197
|
+
* @returns An object with `result` (the flow execution return value) and `loggerMock`.
|
|
198
|
+
* @see {@link https://prismatic.io/docs/custom-connectors/unit-testing/ | Unit Testing}
|
|
199
|
+
* @example
|
|
200
|
+
* import { invokeFlow } from "@prismatic-io/spectral/dist/testing";
|
|
201
|
+
* import { myFlow } from "./flows";
|
|
202
|
+
*
|
|
203
|
+
* it("should execute the flow end-to-end", async () => {
|
|
204
|
+
* const { result } = await invokeFlow(myFlow, {
|
|
205
|
+
* configVars: {
|
|
206
|
+
* "Acme API Endpoint": "https://api.acme.com",
|
|
207
|
+
* "Acme Connection": {
|
|
208
|
+
* fields: { apiKey: "test-key" },
|
|
209
|
+
* key: "apiKey",
|
|
210
|
+
* },
|
|
211
|
+
* },
|
|
212
|
+
* payload: {
|
|
213
|
+
* body: { data: JSON.stringify({ event: "created" }) },
|
|
214
|
+
* },
|
|
215
|
+
* });
|
|
216
|
+
*
|
|
217
|
+
* expect(result.data).toBeDefined();
|
|
218
|
+
* });
|
|
80
219
|
*/
|
|
81
220
|
export declare const invokeFlow: <TInputs extends Inputs, TActionInputs extends Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TConfigVarValues extends TestConfigVarValues = ToTestValues<TConfigVars>, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends InvokeTriggerResult<TAllowsBranching, TPayload> = InvokeTriggerResult<TAllowsBranching, TPayload>>(flow: Flow<TInputs, TActionInputs, TPayload, TAllowsBranching, TResult>, { configVars, context, payload, }?: {
|
|
82
221
|
configVars?: TConfigVarValues;
|
|
@@ -119,8 +258,33 @@ export declare class ComponentTestHarness<TInputs extends Inputs, TActionInputs
|
|
|
119
258
|
dataSource<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<DataSourceContext<TConfigVars>>): Promise<DataSourceResult>;
|
|
120
259
|
}
|
|
121
260
|
/**
|
|
122
|
-
* Create a testing harness to test a custom component's actions, triggers
|
|
123
|
-
*
|
|
261
|
+
* Create a testing harness to test a custom component's actions, triggers
|
|
262
|
+
* and data sources by key. The harness automatically provides default input
|
|
263
|
+
* values and mock context.
|
|
264
|
+
*
|
|
265
|
+
* @param component The compiled component object (the result of calling `component()`).
|
|
266
|
+
* @returns A `ComponentTestHarness` instance with `.action()`, `.trigger()`, and `.dataSource()` methods.
|
|
267
|
+
* @see {@link https://prismatic.io/docs/custom-connectors/unit-testing/ | Unit Testing}
|
|
268
|
+
* @example
|
|
269
|
+
* import { testing } from "@prismatic-io/spectral";
|
|
270
|
+
* import myComponent from ".";
|
|
271
|
+
*
|
|
272
|
+
* const harness = testing.createHarness(myComponent);
|
|
273
|
+
*
|
|
274
|
+
* it("should list items", async () => {
|
|
275
|
+
* const result = await harness.action("listItems", {
|
|
276
|
+
* connection: testConnection,
|
|
277
|
+
* limit: "10",
|
|
278
|
+
* });
|
|
279
|
+
* expect(result.data).toHaveProperty("items");
|
|
280
|
+
* });
|
|
281
|
+
*
|
|
282
|
+
* it("should handle a webhook trigger", async () => {
|
|
283
|
+
* const result = await harness.trigger("webhook", {
|
|
284
|
+
* body: { data: '{"event":"created"}' },
|
|
285
|
+
* });
|
|
286
|
+
* expect(result.payload).toBeDefined();
|
|
287
|
+
* });
|
|
124
288
|
*/
|
|
125
289
|
export declare const createHarness: <TInputs extends Inputs, TActionInputs extends Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends InvokeTriggerResult<TAllowsBranching, TPayload> = InvokeTriggerResult<TAllowsBranching, TPayload>, TComponent extends Component<TInputs, TActionInputs, TConfigVars, TPayload, TAllowsBranching, TResult> = Component<TInputs, TActionInputs, TConfigVars, TPayload, TAllowsBranching, TResult>>(component: TComponent) => ComponentTestHarness<TInputs, TActionInputs, TConfigVars, TPayload, TAllowsBranching, TResult, TComponent>;
|
|
126
290
|
declare const _default: {
|