@prismatic-io/spectral 3.1.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/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +73 -0
- package/dist/testing.d.ts +72 -0
- package/dist/testing.js +130 -0
- package/dist/types/ActionDefinition.d.ts +25 -0
- package/dist/types/ActionDefinition.js +2 -0
- package/dist/types/ActionInputParameters.d.ts +24 -0
- package/dist/types/ActionInputParameters.js +2 -0
- package/dist/types/ActionLogger.d.ts +20 -0
- package/dist/types/ActionLogger.js +8 -0
- package/dist/types/ActionPerformFunction.d.ts +14 -0
- package/dist/types/ActionPerformFunction.js +2 -0
- package/dist/types/AuthorizationDefinition.d.ts +14 -0
- package/dist/types/AuthorizationDefinition.js +19 -0
- package/dist/types/Credential.d.ts +58 -0
- package/dist/types/Credential.js +8 -0
- package/dist/types/DisplayDefinition.d.ts +26 -0
- package/dist/types/DisplayDefinition.js +5 -0
- package/dist/types/InputFieldType.d.ts +12 -0
- package/dist/types/InputFieldType.js +2 -0
- package/dist/types/Inputs.d.ts +37 -0
- package/dist/types/Inputs.js +2 -0
- package/dist/types/PerformReturn.d.ts +19 -0
- package/dist/types/PerformReturn.js +2 -0
- package/dist/types/conditional-logic.d.ts +91 -0
- package/dist/types/conditional-logic.js +67 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.js +27 -0
- package/dist/types/server-types.d.ts +135 -0
- package/dist/types/server-types.js +8 -0
- package/dist/util.d.ts +33 -0
- package/dist/util.js +337 -0
- package/dist/util.test.d.ts +1 -0
- package/dist/util.test.js +286 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Prismatic LLC.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @prismatic-io/spectral
|
|
2
|
+
|
|
3
|
+
This repository contains code for Prismatic's TypeScript library, `spectral`, which is used to build custom Prismatic components.
|
|
4
|
+
|
|
5
|
+
## Using Spectral
|
|
6
|
+
|
|
7
|
+
To install spectral, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @prismatic-io/spectral
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Please see our [documentation](https://prismatic.io/docs/custom-components/writing-custom-components) on writing and publishing custom components for Prismatic's platform.
|
|
14
|
+
|
|
15
|
+
## What is Prismatic?
|
|
16
|
+
|
|
17
|
+
Prismatic is the embedded integration platform for B2B software companies. It's the easiest way to build integrations and provide a first-class integration experience to your customers.
|
|
18
|
+
|
|
19
|
+
Prismatic reduces integration effort and empowers every role with exactly what they need, so you can spend less time on integrations and more time on core product innovation.
|
|
20
|
+
|
|
21
|
+
With Prismatic, you can:
|
|
22
|
+
|
|
23
|
+
- Build reusable [integrations](https://prismatic.io/docs/integrations) in an intuitive low-code integration designer
|
|
24
|
+
- Easily deploy customer-specific integration [instances](https://prismatic.io/docs/instances) with unique configurations and credentials
|
|
25
|
+
- Run your integrations in a purpose-built environment
|
|
26
|
+
- Provide better support with built-in [logging](https://prismatic.io/docs/logging) and [alerting](https://prismatic.io/docs/monitoring-and-alerting)
|
|
27
|
+
- Embed a white-labeled customer integration portal with an [integration marketplace](https://prismatic.io/docs/integration-marketplace/) and customer self-service tools
|
|
28
|
+
- Mold the platform to your product, industry, and the way you build software
|
|
29
|
+
|
|
30
|
+
## Who uses Prismatic?
|
|
31
|
+
|
|
32
|
+
Prismatic is for B2B (business-to-business) software companies, meaning software companies that provide applications used by businesses. It's a good fit for products/teams at any stage, including early stage SaaS, established SaaS, and legacy or on-prem systems.
|
|
33
|
+
|
|
34
|
+
Many B2B software teams serve customers in niche vertical markets, and we designed Prismatic with that in mind. We provide powerful and flexible tools so you can build exactly the integrations your customers need, no matter who your customers are, no matter what systems you need to connect to, no matter how "non-standard" your integration scenario.
|
|
35
|
+
|
|
36
|
+
## What kind of integrations can you build using Prismatic?
|
|
37
|
+
|
|
38
|
+
Prismatic supports integrations ranging from simple and standard to complex, bespoke, and vertical-specific.
|
|
39
|
+
Teams use it to build integrations between applications of all kinds, SaaS or legacy, with or without a modern API, regardless of protocol or data format.
|
|
40
|
+
Here are some example use cases:
|
|
41
|
+
|
|
42
|
+
- Use job data from your system to create invoices in your customers' ERP.
|
|
43
|
+
- Import and process data from third-party forms that vary significantly from customer to customer.
|
|
44
|
+
- Email activity summary reports with parameters and intervals defined on a per-customer basis.
|
|
45
|
+
|
|
46
|
+
For information on the Prismatic platform, check out our [website](https://prismatic.io) and [docs](https://prismatic.io/docs).
|
|
47
|
+
|
|
48
|
+
## Building Spectral Locally
|
|
49
|
+
|
|
50
|
+
To build spectral locally, you'll need `yarn` and `node` installed.
|
|
51
|
+
Run `yarn build` to build the package, or `yarn pack` to build a tarball that can be used in custom components for testing changes to spectral.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
This repository is [MIT licensed](./LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module contains functions to help custom component
|
|
3
|
+
* authors create inputs, actions, and components that can
|
|
4
|
+
* be processed by the Prismatic API.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Both component author-facing types and server types that
|
|
8
|
+
* the Prismatic API expects are imported here.
|
|
9
|
+
*/
|
|
10
|
+
import { ActionDefinition, InputFieldDefinition, PerformReturn, Inputs } from "./types";
|
|
11
|
+
import { Component } from "./types/server-types";
|
|
12
|
+
/**
|
|
13
|
+
* This function creates a component object that can be
|
|
14
|
+
* imported into the Prismatic API. For information on using
|
|
15
|
+
* this function to write custom components, see
|
|
16
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#exporting-a-component.
|
|
17
|
+
* @param definition A ComponentDefinition type object, including display infromation, unique key, authorization information, and a set of actions the component implements.
|
|
18
|
+
* @returns This function returns a component object that has the shape the Prismatic API expects.
|
|
19
|
+
*/
|
|
20
|
+
export declare const component: <T extends boolean>(definition: Omit<Component<T>, "actions"> & {
|
|
21
|
+
actions: Record<string, ActionDefinition<any, boolean, PerformReturn<boolean, any>>>;
|
|
22
|
+
}) => Component<T>;
|
|
23
|
+
/**
|
|
24
|
+
* This function creates an action object that can be referenced
|
|
25
|
+
* by a custom component. It helps ensure that the shape of the
|
|
26
|
+
* action object conforms to what the Prismatic API expects.
|
|
27
|
+
* For information on writing custom component actions, see
|
|
28
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#writing-actions.
|
|
29
|
+
* @param definition An ActionDefinition type object that includes UI display information, a function to perform when the action is invoked, and a an object containing inputs for the perform function.
|
|
30
|
+
* @returns This function validates the shape of the `definition` object provided, and returns the same action object.
|
|
31
|
+
*/
|
|
32
|
+
export declare const action: <T extends Inputs, AllowsBranching extends boolean, ReturnData extends PerformReturn<AllowsBranching, unknown>>(definition: ActionDefinition<T, AllowsBranching, ReturnData>) => ActionDefinition<T, AllowsBranching, ReturnData>;
|
|
33
|
+
/**
|
|
34
|
+
* For information and examples on how to write inputs
|
|
35
|
+
* for custom component actions, see
|
|
36
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#adding-inputs.
|
|
37
|
+
* @param definition An InputFieldDefinition object that describes the type of an input for a custom component action, and information on how it should be displayed in the Prismatic WebApp.
|
|
38
|
+
* @returns This function validates the shape of the `definition` object provided, and returns the same input object.
|
|
39
|
+
*/
|
|
40
|
+
export declare const input: <T extends InputFieldDefinition>(definition: T) => T;
|
|
41
|
+
export { default as util } from "./util";
|
|
42
|
+
export * from "./types";
|
|
43
|
+
export { default as testing } from "./testing";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This module contains functions to help custom component
|
|
4
|
+
* authors create inputs, actions, and components that can
|
|
5
|
+
* be processed by the Prismatic API.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.testing = exports.util = exports.input = exports.action = exports.component = void 0;
|
|
22
|
+
/**
|
|
23
|
+
* This is a helper function for component() to convert an
|
|
24
|
+
* action defined in TypeScript into an action object that
|
|
25
|
+
* Prismatic's API can process.
|
|
26
|
+
* @param actionKey The unique identifier of an action.
|
|
27
|
+
* @param action The action definition, including its inputs, perform function, and app display information.
|
|
28
|
+
* @returns This function returns an action object that has the shape the Prismatic API expects.
|
|
29
|
+
*/
|
|
30
|
+
const convertAction = (actionKey, action) => {
|
|
31
|
+
var _a;
|
|
32
|
+
const items = Object.entries((_a = action.inputs) !== null && _a !== void 0 ? _a : {});
|
|
33
|
+
const inputDefinitions = items.map(([key, value]) => (Object.assign({ key }, (typeof value === "object" ? value : {}))));
|
|
34
|
+
return Object.assign(Object.assign({}, action), { key: actionKey, inputs: inputDefinitions, perform: action.perform, examplePayload: action.examplePayload });
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* This function creates a component object that can be
|
|
38
|
+
* imported into the Prismatic API. For information on using
|
|
39
|
+
* this function to write custom components, see
|
|
40
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#exporting-a-component.
|
|
41
|
+
* @param definition A ComponentDefinition type object, including display infromation, unique key, authorization information, and a set of actions the component implements.
|
|
42
|
+
* @returns This function returns a component object that has the shape the Prismatic API expects.
|
|
43
|
+
*/
|
|
44
|
+
const component = (definition) => (Object.assign(Object.assign({ version: "placeholder" }, definition), { documentationUrl: definition.documentationUrl || null, actions: Object.fromEntries(Object.entries(definition.actions).map(([actionKey, action]) => [
|
|
45
|
+
actionKey,
|
|
46
|
+
convertAction(actionKey, action),
|
|
47
|
+
])) }));
|
|
48
|
+
exports.component = component;
|
|
49
|
+
/**
|
|
50
|
+
* This function creates an action object that can be referenced
|
|
51
|
+
* by a custom component. It helps ensure that the shape of the
|
|
52
|
+
* action object conforms to what the Prismatic API expects.
|
|
53
|
+
* For information on writing custom component actions, see
|
|
54
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#writing-actions.
|
|
55
|
+
* @param definition An ActionDefinition type object that includes UI display information, a function to perform when the action is invoked, and a an object containing inputs for the perform function.
|
|
56
|
+
* @returns This function validates the shape of the `definition` object provided, and returns the same action object.
|
|
57
|
+
*/
|
|
58
|
+
const action = (definition) => definition;
|
|
59
|
+
exports.action = action;
|
|
60
|
+
/**
|
|
61
|
+
* For information and examples on how to write inputs
|
|
62
|
+
* for custom component actions, see
|
|
63
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#adding-inputs.
|
|
64
|
+
* @param definition An InputFieldDefinition object that describes the type of an input for a custom component action, and information on how it should be displayed in the Prismatic WebApp.
|
|
65
|
+
* @returns This function validates the shape of the `definition` object provided, and returns the same input object.
|
|
66
|
+
*/
|
|
67
|
+
const input = (definition) => definition;
|
|
68
|
+
exports.input = input;
|
|
69
|
+
var util_1 = require("./util");
|
|
70
|
+
Object.defineProperty(exports, "util", { enumerable: true, get: function () { return __importDefault(util_1).default; } });
|
|
71
|
+
__exportStar(require("./types"), exports);
|
|
72
|
+
var testing_1 = require("./testing");
|
|
73
|
+
Object.defineProperty(exports, "testing", { enumerable: true, get: function () { return __importDefault(testing_1).default; } });
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides functions to help developers unit
|
|
3
|
+
* test custom components prior to publishing them. For
|
|
4
|
+
* information on unit testing, check out our docs:
|
|
5
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#testing-a-component
|
|
6
|
+
*/
|
|
7
|
+
/** */
|
|
8
|
+
import { ActionContext, ActionLogger, ActionDefinition, ActionInputParameters, Credential, BasicCredential, ApiKeyCredential, ApiKeySecretCredential, PrivateKeyCredential, OAuth2Credential, PerformReturn, AuthorizationMethod, Inputs } from "./types";
|
|
9
|
+
/**
|
|
10
|
+
* Get an array of available authorization methods that a custom component can use.
|
|
11
|
+
* @param except Return authorization methods _except for_ those in this array.
|
|
12
|
+
* @returns This function returns an array of available authorization methods.
|
|
13
|
+
*/
|
|
14
|
+
export declare const getAuthorizationMethods: (except?: ("basic" | "api_key" | "api_key_secret" | "private_key" | "oauth2" | "oauth2_client_credentials")[] | undefined) => AuthorizationMethod[];
|
|
15
|
+
/** Utility functions to generate the different types of Credentials for testing. */
|
|
16
|
+
export declare const credentials: {
|
|
17
|
+
/** Return a BasicCredential assembled from provided username and password. */
|
|
18
|
+
basic: (username: string, password: string) => BasicCredential;
|
|
19
|
+
/** Return a ApiKeyCredential assembled from provided key. */
|
|
20
|
+
apiKey: (key: string) => ApiKeyCredential;
|
|
21
|
+
/** Return a ApiKeySecretCredential assembled from provided key and secret. */
|
|
22
|
+
apiKeySecret: (key: string, secret: string) => ApiKeySecretCredential;
|
|
23
|
+
/** Return a PrivateKeyCredential assembled from provided username and privateKey. */
|
|
24
|
+
privateKey: (username: string, privateKey: string) => PrivateKeyCredential;
|
|
25
|
+
/** Return a OAuth2Credential assembled from provided token and optional redirectUri. */
|
|
26
|
+
oauth2: (token: string, redirectUri?: string, tokenUri?: string, clientId?: string, clientSecret?: string, headers?: {}) => OAuth2Credential;
|
|
27
|
+
/** Return a OAuth2Credential assembled from provided token. */
|
|
28
|
+
oauth2ClientCredentials: (token: string, redirectUri?: string, tokenUri?: string, clientId?: string, clientSecret?: string, headers?: {}) => OAuth2Credential;
|
|
29
|
+
/** Returns an arbitrary Credential using method. Generally used for testing negative support cases. */
|
|
30
|
+
generate: (method: AuthorizationMethod) => Credential;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
|
|
34
|
+
* 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.
|
|
35
|
+
*/
|
|
36
|
+
export declare const loggerMock: () => ActionLogger;
|
|
37
|
+
/**
|
|
38
|
+
* The type of data returned by an `invoke()` function used for unit testing component actions.
|
|
39
|
+
*/
|
|
40
|
+
interface InvokeReturn<ReturnData> {
|
|
41
|
+
result: ReturnData;
|
|
42
|
+
loggerMock: ActionLogger;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Invokes specified ActionDefinition perform function using supplied params
|
|
46
|
+
* and optional context. Accepts a generic type matching PerformReturn as a convenience
|
|
47
|
+
* to avoid extra casting within test methods. Returns an InvokeResult containing both the
|
|
48
|
+
* action result and a mock logger for asserting logging.
|
|
49
|
+
*/
|
|
50
|
+
export declare const invoke: <T extends Inputs, AllowsBranching extends boolean, ReturnData extends PerformReturn<AllowsBranching, unknown>>(actionBase: ActionDefinition<T, AllowsBranching, ReturnData> | Record<string, ActionDefinition<T, AllowsBranching, ReturnData>>, params: ActionInputParameters<T>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<ReturnData>>;
|
|
51
|
+
declare const _default: {
|
|
52
|
+
invoke: <T extends Inputs, AllowsBranching extends boolean, ReturnData extends PerformReturn<AllowsBranching, unknown>>(actionBase: ActionDefinition<T, AllowsBranching, ReturnData> | Record<string, ActionDefinition<T, AllowsBranching, ReturnData>>, params: ActionInputParameters<T>, context?: Partial<ActionContext> | undefined) => Promise<InvokeReturn<ReturnData>>;
|
|
53
|
+
loggerMock: () => ActionLogger;
|
|
54
|
+
getAuthorizationMethods: (except?: ("basic" | "api_key" | "api_key_secret" | "private_key" | "oauth2" | "oauth2_client_credentials")[] | undefined) => ("basic" | "api_key" | "api_key_secret" | "private_key" | "oauth2" | "oauth2_client_credentials")[];
|
|
55
|
+
credentials: {
|
|
56
|
+
/** Return a BasicCredential assembled from provided username and password. */
|
|
57
|
+
basic: (username: string, password: string) => BasicCredential;
|
|
58
|
+
/** Return a ApiKeyCredential assembled from provided key. */
|
|
59
|
+
apiKey: (key: string) => ApiKeyCredential;
|
|
60
|
+
/** Return a ApiKeySecretCredential assembled from provided key and secret. */
|
|
61
|
+
apiKeySecret: (key: string, secret: string) => ApiKeySecretCredential;
|
|
62
|
+
/** Return a PrivateKeyCredential assembled from provided username and privateKey. */
|
|
63
|
+
privateKey: (username: string, privateKey: string) => PrivateKeyCredential;
|
|
64
|
+
/** Return a OAuth2Credential assembled from provided token and optional redirectUri. */
|
|
65
|
+
oauth2: (token: string, redirectUri?: string, tokenUri?: string, clientId?: string, clientSecret?: string, headers?: {}) => OAuth2Credential;
|
|
66
|
+
/** Return a OAuth2Credential assembled from provided token. */
|
|
67
|
+
oauth2ClientCredentials: (token: string, redirectUri?: string, tokenUri?: string, clientId?: string, clientSecret?: string, headers?: {}) => OAuth2Credential;
|
|
68
|
+
/** Returns an arbitrary Credential using method. Generally used for testing negative support cases. */
|
|
69
|
+
generate: (method: "basic" | "api_key" | "api_key_secret" | "private_key" | "oauth2" | "oauth2_client_credentials") => Credential;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export default _default;
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This module provides functions to help developers unit
|
|
4
|
+
* test custom components prior to publishing them. For
|
|
5
|
+
* information on unit testing, check out our docs:
|
|
6
|
+
* https://prismatic.io/docs/custom-components/writing-custom-components/#testing-a-component
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.invoke = exports.loggerMock = exports.credentials = exports.getAuthorizationMethods = void 0;
|
|
19
|
+
/** */
|
|
20
|
+
const types_1 = require("./types");
|
|
21
|
+
const jest_mock_1 = require("jest-mock");
|
|
22
|
+
/**
|
|
23
|
+
* Get an array of available authorization methods that a custom component can use.
|
|
24
|
+
* @param except Return authorization methods _except for_ those in this array.
|
|
25
|
+
* @returns This function returns an array of available authorization methods.
|
|
26
|
+
*/
|
|
27
|
+
const getAuthorizationMethods = (except) => {
|
|
28
|
+
if (except === undefined) {
|
|
29
|
+
return types_1.AvailableAuthorizationMethods;
|
|
30
|
+
}
|
|
31
|
+
return types_1.AvailableAuthorizationMethods.filter((m) => !except.includes(m));
|
|
32
|
+
};
|
|
33
|
+
exports.getAuthorizationMethods = getAuthorizationMethods;
|
|
34
|
+
/** Utility functions to generate the different types of Credentials for testing. */
|
|
35
|
+
exports.credentials = {
|
|
36
|
+
/** Return a BasicCredential assembled from provided username and password. */
|
|
37
|
+
basic: (username, password) => ({
|
|
38
|
+
authorizationMethod: "basic",
|
|
39
|
+
fields: {
|
|
40
|
+
username,
|
|
41
|
+
password,
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
/** Return a ApiKeyCredential assembled from provided key. */
|
|
45
|
+
apiKey: (key) => ({
|
|
46
|
+
authorizationMethod: "api_key",
|
|
47
|
+
fields: { api_key: key },
|
|
48
|
+
}),
|
|
49
|
+
/** Return a ApiKeySecretCredential assembled from provided key and secret. */
|
|
50
|
+
apiKeySecret: (key, secret) => ({
|
|
51
|
+
authorizationMethod: "api_key_secret",
|
|
52
|
+
fields: {
|
|
53
|
+
api_key: key,
|
|
54
|
+
api_secret: secret,
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
/** Return a PrivateKeyCredential assembled from provided username and privateKey. */
|
|
58
|
+
privateKey: (username, privateKey) => ({
|
|
59
|
+
authorizationMethod: "private_key",
|
|
60
|
+
fields: {
|
|
61
|
+
username,
|
|
62
|
+
private_key: privateKey,
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
/** Return a OAuth2Credential assembled from provided token and optional redirectUri. */
|
|
66
|
+
oauth2: (token, redirectUri = "", tokenUri = "", clientId = "", clientSecret = "", headers = {}) => ({
|
|
67
|
+
authorizationMethod: "oauth2",
|
|
68
|
+
redirectUri,
|
|
69
|
+
fields: {
|
|
70
|
+
client_id: clientId,
|
|
71
|
+
client_secret: clientSecret,
|
|
72
|
+
token_uri: tokenUri,
|
|
73
|
+
headers,
|
|
74
|
+
},
|
|
75
|
+
token: { access_token: token, token_type: "bearer" },
|
|
76
|
+
context: {},
|
|
77
|
+
}),
|
|
78
|
+
/** Return a OAuth2Credential assembled from provided token. */
|
|
79
|
+
oauth2ClientCredentials: (token, redirectUri = "", tokenUri = "", clientId = "", clientSecret = "", headers = {}) => ({
|
|
80
|
+
authorizationMethod: "oauth2_client_credentials",
|
|
81
|
+
redirectUri: redirectUri,
|
|
82
|
+
fields: {
|
|
83
|
+
client_id: clientId,
|
|
84
|
+
client_secret: clientSecret,
|
|
85
|
+
token_uri: tokenUri,
|
|
86
|
+
headers,
|
|
87
|
+
},
|
|
88
|
+
token: { access_token: token, token_type: "bearer" },
|
|
89
|
+
context: {},
|
|
90
|
+
}),
|
|
91
|
+
/** Returns an arbitrary Credential using method. Generally used for testing negative support cases. */
|
|
92
|
+
generate: (method) => ({
|
|
93
|
+
authorizationMethod: method,
|
|
94
|
+
fields: {},
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
|
|
99
|
+
* 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.
|
|
100
|
+
*/
|
|
101
|
+
const loggerMock = () => ({
|
|
102
|
+
debug: jest_mock_1.spyOn(console, "debug"),
|
|
103
|
+
info: jest_mock_1.spyOn(console, "info"),
|
|
104
|
+
log: jest_mock_1.spyOn(console, "log"),
|
|
105
|
+
warn: jest_mock_1.spyOn(console, "warn"),
|
|
106
|
+
error: jest_mock_1.spyOn(console, "error"),
|
|
107
|
+
});
|
|
108
|
+
exports.loggerMock = loggerMock;
|
|
109
|
+
/**
|
|
110
|
+
* Invokes specified ActionDefinition perform function using supplied params
|
|
111
|
+
* and optional context. Accepts a generic type matching PerformReturn as a convenience
|
|
112
|
+
* to avoid extra casting within test methods. Returns an InvokeResult containing both the
|
|
113
|
+
* action result and a mock logger for asserting logging.
|
|
114
|
+
*/
|
|
115
|
+
const invoke = (actionBase, params, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
const action = (actionBase.perform ? actionBase : Object.values(actionBase)[0]);
|
|
117
|
+
const realizedContext = Object.assign({ credential: undefined, logger: exports.loggerMock(), instanceState: {}, stepId: "mockStepId" }, context);
|
|
118
|
+
const result = yield action.perform(realizedContext, params);
|
|
119
|
+
return {
|
|
120
|
+
result,
|
|
121
|
+
loggerMock: realizedContext.logger,
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
exports.invoke = invoke;
|
|
125
|
+
exports.default = {
|
|
126
|
+
invoke: exports.invoke,
|
|
127
|
+
loggerMock: exports.loggerMock,
|
|
128
|
+
getAuthorizationMethods: exports.getAuthorizationMethods,
|
|
129
|
+
credentials: exports.credentials,
|
|
130
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PerformReturn, ActionDisplayDefinition, ActionPerformFunction, AuthorizationDefinition, Inputs } from ".";
|
|
2
|
+
/**
|
|
3
|
+
* ActionDefinition is the type of the object that is passed in to `action` function to
|
|
4
|
+
* define a component action.
|
|
5
|
+
*/
|
|
6
|
+
export interface ActionDefinition<T extends Inputs, AllowsBranching extends boolean, ReturnData extends PerformReturn<AllowsBranching, unknown>> {
|
|
7
|
+
/** Defines how the Action is displayed in the Prismatic interface. */
|
|
8
|
+
display: ActionDisplayDefinition;
|
|
9
|
+
/** Function to perform when this Action is invoked. */
|
|
10
|
+
perform: ActionPerformFunction<T, AllowsBranching, ReturnData>;
|
|
11
|
+
/** InputFields to present in the Prismatic interface for configuration of this Action. */
|
|
12
|
+
inputs: T;
|
|
13
|
+
/** Specifies Authorization settings, if applicable */
|
|
14
|
+
authorization?: AuthorizationDefinition;
|
|
15
|
+
/** Optional attribute that specifies whether an Action will terminate execution.*/
|
|
16
|
+
terminateExecution?: boolean;
|
|
17
|
+
/** Determines whether an Action will allow Conditional Branching.*/
|
|
18
|
+
allowsBranching?: AllowsBranching;
|
|
19
|
+
/** Static Branch names associated with an Action. */
|
|
20
|
+
staticBranchNames?: string[];
|
|
21
|
+
/** The Input associated with Dynamic Branching.*/
|
|
22
|
+
dynamicBranchInput?: string;
|
|
23
|
+
/** An example of the payload outputted by an Action*/
|
|
24
|
+
examplePayload?: ReturnData;
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InputFieldDefinition, Inputs, InputFieldTypeMap } from ".";
|
|
2
|
+
/**
|
|
3
|
+
* Collection of input parameters.
|
|
4
|
+
* Inputs can be static values, references to config variables, or
|
|
5
|
+
* references to previou steps' outputs.
|
|
6
|
+
*/
|
|
7
|
+
export declare type ActionInputParameters<T extends Inputs> = T extends Record<string, InputFieldDefinition> ? {
|
|
8
|
+
[K in keyof T]: ExtractValue<T[K]>;
|
|
9
|
+
} : never;
|
|
10
|
+
export declare type ExtractValue<TValue extends InputFieldDefinition> = MapCollectionValues<InputFieldTypeMap[TValue["type"]], TValue["collection"]>;
|
|
11
|
+
export declare type MapCollectionValues<TValue, TCollection extends InputFieldDefinition["collection"] | undefined> = TCollection extends "keyvaluelist" ? KeyValuePair<TValue>[] | undefined : TCollection extends "valuelist" ? TValue[] | undefined : TValue;
|
|
12
|
+
/**
|
|
13
|
+
* KeyValuePair input parameter type.
|
|
14
|
+
* This allows users to input multiple keys / values as an input.
|
|
15
|
+
* To see an example of how this can be used, see the `tagging` input
|
|
16
|
+
* of the `putObject` action of the AWS S3 component:
|
|
17
|
+
* https://github.com/prismatic-io/examples/blob/main/components/aws-s3/src/actions.ts
|
|
18
|
+
*/
|
|
19
|
+
export interface KeyValuePair<V = unknown> {
|
|
20
|
+
/** Key of the KeyValuePair */
|
|
21
|
+
key: string;
|
|
22
|
+
/** Value of the KeyValuePair */
|
|
23
|
+
value: V;
|
|
24
|
+
}
|