@prismatic-io/spectral 10.3.0 → 10.3.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Prismatic LLC.
3
+ Copyright (c) 2024 Prismatic LLC.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
- # @prismatic-io/spectral
1
+ <div align="center">
2
+ <img src="https://prismatic.io/favicon-48x48.png" />
3
+ <h1>@prismatic-io/spectral</h1>
4
+ </div>
2
5
 
3
- This repository contains code for Prismatic's TypeScript library, `spectral`, which is used to build custom Prismatic components.
6
+ This repository contains code for Prismatic's TypeScript library, `spectral`, which is used to build custom Prismatic connectors and code-native integrations.
4
7
 
5
8
  ## Using Spectral
6
9
 
@@ -10,47 +13,41 @@ To install spectral, run:
10
13
  npm install @prismatic-io/spectral
11
14
  ```
12
15
 
13
- Please see our [documentation](https://prismatic.io/docs/custom-components/writing-custom-components) on writing and publishing custom components for Prismatic's platform.
16
+ Please see our [documentation](https://prismatic.io/docs/custom-connectors/) on writing and publishing custom connectors for Prismatic's platform.
14
17
 
15
18
  ## What is Prismatic?
16
19
 
17
- Prismatic is the integration platform for B2B software companies. It's the quickest way to build integrations to the other apps your customers use and to add a native integration marketplace to your product.
20
+ Prismatic is the leading embedded iPaaS, enabling B2B SaaS teams to ship product integrations faster and with less dev time. The only embedded iPaaS that empowers both developers and non-developers with tools for the complete integration lifecycle, Prismatic includes low-code and code-native building options, deployment and management tooling, and self-serve customer tools.
18
21
 
19
- Prismatic significantly reduces overall integration effort and enables non-dev teams to take on more of the integration workload, so that you can deliver integrations faster and spend more time on core product innovation.
22
+ Prismatic's unparalleled versatility lets teams deliver any integration from simple to complex in one powerful platform. SaaS companies worldwide, from startups to Fortune 500s, trust Prismatic to help connect their products to the other products their customers use.
20
23
 
21
24
  With Prismatic, you can:
22
25
 
23
- - Build reusable [integrations](https://prismatic.io/docs/integrations) in a low-code integration designer that's tailored for your product
24
- - Use [pre-built components](https://prismatic.io/docs/components/component-catalog) to handle most of your integrations' functionality, and write [custom components](https://prismatic.io/docs/custom-components/writing-custom-components) when needed
25
- - Quickly add an [integration marketplace](https://prismatic.io/docs/integration-marketplace) to your product so customers can explore, activate, and monitor integrations
26
- - Easily deploy customer-specific integration [instances](https://prismatic.io/docs/instances) with unique configurations and connections
27
- - Provide better support with tools like [logging](https://prismatic.io/docs/logging) and [alerting](https://prismatic.io/docs/monitoring-and-alerting)
28
- - Run your integrations in a purpose-built environment designed for security and scalability
29
- - Use powerful dev tools to mold the platform to your product, industry, and the way you build software
26
+ - Build [integrations](https://prismatic.io/docs/integrations/) using our [intuitive low-code designer](https://prismatic.io/docs/integrations/low-code-integration-designer/) or [code-native](https://prismatic.io/docs/integrations/code-native/) approach in your preferred IDE
27
+ - Leverage pre-built [connectors](https://prismatic.io/docs/components/) for common integration tasks, or develop custom connectors using our TypeScript SDK
28
+ - Embed a native [integration marketplace](https://prismatic.io/docs/embed/) in your product for customer self-service
29
+ - Configure and deploy customer-specific integration instances with powerful configuration tools
30
+ - Support customers efficiently with comprehensive [logging, monitoring, and alerting](https://prismatic.io/docs/monitor-instances/)
31
+ - Run integrations in a secure, scalable infrastructure designed for B2B SaaS
32
+ - Customize the platform to fit your product, industry, and development workflows
30
33
 
31
34
  ## Who uses Prismatic?
32
35
 
33
- 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 ranging from early-stage and growing SaaS startups to large, established software companies looking to improve the way they do integrations.
36
+ Prismatic is built for B2B software companies that need to provide integrations to their customers. Whether you're a growing SaaS startup or an established enterprise, Prismatic's platform scales with your integration needs.
34
37
 
35
- 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.
38
+ Our platform is particularly powerful for teams serving specialized vertical markets. We provide the flexibility and tools to build exactly the integrations your customers need, regardless of the systems you're connecting to or how unique your integration requirements may be.
36
39
 
37
40
  ## What kind of integrations can you build using Prismatic?
38
41
 
39
- Prismatic supports integrations ranging from simple and standard to complex, bespoke, and vertical-specific.
40
- 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.
41
- Here are some example use cases:
42
+ Prismatic supports integrations of any complexity - from simple data syncs to sophisticated, industry-specific solutions. Teams use it to build integrations between any type of system, whether modern SaaS or legacy with standard or custom protocols. Here are some example use cases:
42
43
 
43
- - Use job data from your system to create invoices in your customers' ERP.
44
- - Import and process data from third-party forms that vary significantly from customer to customer.
45
- - Email activity summary reports with parameters and intervals defined on a per-customer basis.
44
+ - Connect your product with customers' ERPs, CRMs, and other business systems
45
+ - Process data from multiple sources with customer-specific transformation requirements
46
+ - Automate workflows with customizable triggers, actions, and schedules
47
+ - Handle complex authentication flows and data mapping scenarios
46
48
 
47
- For information on the Prismatic platform, check out our [website](https://prismatic.io) and [docs](https://prismatic.io/docs).
48
-
49
- ## Building Spectral Locally
50
-
51
- To build spectral locally, you'll need `yarn` and `node` installed.
52
- 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.
49
+ For information on the Prismatic platform, check out our [website](https://prismatic.io/) and [docs](https://prismatic.io/docs/).
53
50
 
54
51
  ## License
55
52
 
56
- This repository is [MIT licensed](./LICENSE).
53
+ This repository is MIT licensed.
@@ -20,6 +20,7 @@ const types_1 = require("../types");
20
20
  const convertComponent_1 = require("./convertComponent");
21
21
  const integration_1 = require("./integration");
22
22
  const lodash_2 = require("lodash");
23
+ const perform_1 = require("./perform");
23
24
  const convertIntegration = (definition) => {
24
25
  var _a, _b, _c;
25
26
  // Generate a unique reference key that will be used to reference the
@@ -546,7 +547,7 @@ const convertOnExecution = (onExecution, componentRegistry) => (context, params)
546
547
  }, {});
547
548
  return Object.assign(Object.assign({}, accumulator), { [registryComponentKey]: componentActions });
548
549
  }, {});
549
- return onExecution(Object.assign(Object.assign({}, context), { components: componentMethods }), params);
550
+ return onExecution(Object.assign(Object.assign({}, context), { components: componentMethods, invokeFlow: (0, perform_1.createInvokeFlow)(context, { isCNI: true }) }), params);
550
551
  };
551
552
  /** Creates the structure necessary to import a Component as part of a
552
553
  * Code Native integration. */
@@ -1,4 +1,4 @@
1
- import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes, ConfigVarResultCollection, ComponentManifest } from "../types";
1
+ import { InstanceAttributes, CustomerAttributes, DataSourceType, DataSourceResultType, UserAttributes, TriggerEventFunctionReturn, IntegrationAttributes, FlowAttributes, ConfigVarResultCollection, ComponentManifest, FlowInvoker, ExecutionFrame } from "../types";
2
2
  interface DisplayDefinition {
3
3
  label: string;
4
4
  description: string;
@@ -47,7 +47,7 @@ export interface ActionLogger {
47
47
  warn: ActionLoggerFunction;
48
48
  error: ActionLoggerFunction;
49
49
  }
50
- export type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>> = {
50
+ export type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>, TFlows extends string[] = string[]> = {
51
51
  logger: ActionLogger;
52
52
  instanceState: Record<string, unknown>;
53
53
  crossFlowState: Record<string, unknown>;
@@ -70,6 +70,8 @@ export type ActionContext<TConfigVars extends ConfigVarResultCollection = Config
70
70
  integration: IntegrationAttributes;
71
71
  flow: FlowAttributes;
72
72
  startedAt: string;
73
+ invokeFlow: FlowInvoker<TFlows>;
74
+ executionFrame: ExecutionFrame;
73
75
  };
74
76
  type TriggerOptionChoice = "invalid" | "valid" | "required";
75
77
  export interface TriggerPayload {
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ /* Types used to describe the format the platform expects for
3
+ * component and integration definitions. */
2
4
  Object.defineProperty(exports, "__esModule", { value: true });
3
5
  exports.OAuth2Type = void 0;
4
6
  var OAuth2Type;
@@ -1,4 +1,4 @@
1
- import type { ErrorHandler, Inputs, PollingTriggerPerformFunction } from "../types";
1
+ import type { ActionContext, ErrorHandler, FlowInvoker, Inputs, PollingTriggerPerformFunction } from "../types";
2
2
  import { type PollingTriggerDefinition } from "../types/PollingTriggerDefinition";
3
3
  export type PerformFn = (...args: any[]) => Promise<any>;
4
4
  export type CleanFn = (...args: any[]) => any;
@@ -8,6 +8,9 @@ interface CreatePerformProps {
8
8
  errorHandler?: ErrorHandler;
9
9
  }
10
10
  export declare const cleanParams: (params: Record<string, unknown>, cleaners: InputCleaners) => Record<string, any>;
11
+ export declare const createInvokeFlow: <const TFlows extends Readonly<string[]>>(context: ActionContext, options?: {
12
+ isCNI?: boolean;
13
+ }) => FlowInvoker<TFlows>;
11
14
  export declare const createPerform: (performFn: PerformFn, { inputCleaners, errorHandler }: CreatePerformProps) => PerformFn;
12
15
  export declare const createPollingPerform: (trigger: PollingTriggerDefinition, { inputCleaners, errorHandler }: CreatePerformProps) => PollingTriggerPerformFunction<Inputs, Inputs>;
13
16
  export {};
@@ -19,8 +19,12 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
22
25
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.createPollingPerform = exports.createPerform = exports.cleanParams = void 0;
26
+ exports.createPollingPerform = exports.createPerform = exports.createInvokeFlow = exports.cleanParams = void 0;
27
+ const axios_1 = __importDefault(require("axios"));
24
28
  const lodash_1 = require("lodash");
25
29
  const cleanParams = (params, cleaners) => {
26
30
  const keys = (0, lodash_1.uniq)([...Object.keys(params), ...Object.keys(cleaners)]);
@@ -31,6 +35,21 @@ const cleanParams = (params, cleaners) => {
31
35
  }, {});
32
36
  };
33
37
  exports.cleanParams = cleanParams;
38
+ function formatExecutionFrameHeaders(frame, source) {
39
+ let frameToUse = frame;
40
+ if (source) {
41
+ frameToUse = Object.assign(Object.assign({}, frame), { customSource: source });
42
+ }
43
+ return JSON.stringify(frameToUse);
44
+ }
45
+ const createInvokeFlow = (context, options = {}) => {
46
+ return (flowName, data, config, source) => __awaiter(void 0, void 0, void 0, function* () {
47
+ var _a;
48
+ const sourceToUse = options.isCNI ? source : undefined;
49
+ return yield axios_1.default.post(context.webhookUrls[flowName], data, Object.assign(Object.assign({}, config), { headers: Object.assign(Object.assign({}, ((_a = config === null || config === void 0 ? void 0 : config.headers) !== null && _a !== void 0 ? _a : {})), { "prismatic-invoked-by": formatExecutionFrameHeaders(context.executionFrame, sourceToUse), "prismatic-invoke-type": "Cross Flow" }) }));
50
+ });
51
+ };
52
+ exports.createInvokeFlow = createInvokeFlow;
34
53
  const createPerform = (performFn, { inputCleaners, errorHandler }) => {
35
54
  return (...args) => __awaiter(void 0, void 0, void 0, function* () {
36
55
  try {
@@ -40,10 +59,10 @@ const createPerform = (performFn, { inputCleaners, errorHandler }) => {
40
59
  }
41
60
  if (args.length === 2) {
42
61
  const [context, params] = args;
43
- return yield performFn(context, (0, exports.cleanParams)(params, inputCleaners));
62
+ return yield performFn(Object.assign(Object.assign({}, context), { invokeFlow: (0, exports.createInvokeFlow)(context) }), (0, exports.cleanParams)(params, inputCleaners));
44
63
  }
45
64
  const [context, payload, params] = args;
46
- return yield performFn(context, payload, (0, exports.cleanParams)(params, inputCleaners));
65
+ return yield performFn(Object.assign(Object.assign({}, context), { invokeFlow: (0, exports.createInvokeFlow)(context) }), payload, (0, exports.cleanParams)(params, inputCleaners));
47
66
  }
48
67
  catch (error) {
49
68
  throw errorHandler ? errorHandler(error) : error;
@@ -69,6 +88,7 @@ const createPollingPerform = (trigger, { inputCleaners, errorHandler }) => {
69
88
  try {
70
89
  const { pollAction } = trigger;
71
90
  const pollingContext = {
91
+ invokeFlow: (0, exports.createInvokeFlow)(context),
72
92
  polling: {
73
93
  invokeAction: createInvokePollAction(context, pollAction, {
74
94
  inputCleaners,
package/dist/testing.d.ts CHANGED
@@ -4,8 +4,8 @@
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
- import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult, DataSourceContext } from "./serverTypes";
8
- import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceType, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection } from "./types";
7
+ import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionPerformReturn, DataSourceResult, DataSourceContext } from "./serverTypes";
8
+ import { ActionContext, ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceType, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection } from "./types";
9
9
  export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>, tokenValues?: Record<string, unknown>) => ConnectionValue;
10
10
  export declare const defaultConnectionValueEnvironmentVariable = "PRISMATIC_CONNECTION_VALUE";
11
11
  export declare const connectionValue: (envVarKey?: string) => ConnectionValue;
package/dist/testing.js CHANGED
@@ -48,6 +48,11 @@ const loggerMock = () => ({
48
48
  error: (0, jest_mock_1.spyOn)(console, "error"),
49
49
  });
50
50
  exports.loggerMock = loggerMock;
51
+ function invokeFlowTest(flowName, data, config) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ return Promise.resolve({});
54
+ });
55
+ }
51
56
  const createActionContext = (context) => {
52
57
  return Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, integrationState: {}, configVars: {}, components: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
53
58
  "Flow 1": "https://example.com",
@@ -73,7 +78,15 @@ const createActionContext = (context) => {
73
78
  }, flow: {
74
79
  id: "flowId",
75
80
  name: "Flow 1",
76
- }, startedAt: new Date().toISOString() }, context);
81
+ }, startedAt: new Date().toISOString(), invokeFlow: invokeFlowTest, executionFrame: {
82
+ invokedByExecutionJWT: "some-jwt",
83
+ invokedByExecutionStartedAt: "00-00-0000",
84
+ componentActionKey: "my-component-action-key",
85
+ executionId: "abc-123",
86
+ executionStartedAt: "",
87
+ stepName: "some-step",
88
+ loopPath: "",
89
+ } }, context);
77
90
  };
78
91
  const createDataSourceContext = (context) => {
79
92
  return Object.assign({ logger: (0, exports.loggerMock)(), configVars: {}, customer: {
@@ -1,8 +1,27 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from "axios";
1
2
  import { Inputs, ConfigVarResultCollection, ActionPerformReturn, ActionInputParameters, ActionLogger, InstanceAttributes, CustomerAttributes, UserAttributes, IntegrationAttributes, FlowAttributes, ComponentManifest } from ".";
3
+ interface StandardLineage {
4
+ componentActionKey: string;
5
+ executionId: string;
6
+ executionStartedAt: string;
7
+ stepName: string;
8
+ loopPath: string;
9
+ }
10
+ interface CustomLineage {
11
+ customSource: string;
12
+ }
13
+ export type ExecutionFrame = ({
14
+ invokedByExecutionJWT: string;
15
+ invokedByExecutionStartedAt: string;
16
+ } & StandardLineage) | ({
17
+ invokedByExecutionJWT: string;
18
+ invokedByExecutionStartedAt: string;
19
+ } & CustomLineage);
20
+ export type FlowInvoker<TFlows extends Readonly<string[]> | undefined> = (flowName: TFlows extends Readonly<string[]> ? TFlows[number] : string, data?: Record<string, unknown>, config?: AxiosRequestConfig<any>, source?: string) => Promise<AxiosResponse<any, any>>;
2
21
  /** Definition of the function to perform when an Action is invoked. */
3
22
  export type ActionPerformFunction<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]>, TAllowsBranching extends boolean | undefined, TReturn extends ActionPerformReturn<TAllowsBranching, unknown>> = (context: ActionContext<TConfigVars, TComponentActions>, params: ActionInputParameters<TInputs>) => Promise<TReturn>;
4
23
  /** Context provided to perform method containing helpers and contextual data */
5
- export type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>> = {
24
+ export type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>, TFlows extends string[] = string[]> = {
6
25
  /** Logger for permanent logging; console calls are also captured */
7
26
  logger: ActionLogger;
8
27
  /** A a flow-specific key/value store that may be used to store small amounts of data that is persisted between Instance executions */
@@ -43,4 +62,9 @@ export type ActionContext<TConfigVars extends ConfigVarResultCollection = Config
43
62
  flow: FlowAttributes;
44
63
  /** The time in UTC that execution started. */
45
64
  startedAt: string;
65
+ /** Function to invoke an execution of another flow.. */
66
+ invokeFlow: FlowInvoker<TFlows>;
67
+ /** Reference to the current execution and, when applicable, the current step. */
68
+ executionFrame: ExecutionFrame;
46
69
  };
70
+ export {};
@@ -1,4 +1,4 @@
1
- import type { ActionDisplayDefinition, TriggerEventFunction, Inputs, ConfigVarResultCollection, TriggerPayload, ActionDefinition, ActionContext, ActionInputParameters, ActionPerformReturn, TriggerResult } from ".";
1
+ import type { ActionDisplayDefinition, TriggerEventFunction, Inputs, ConfigVarResultCollection, TriggerPayload, ActionDefinition, ActionInputParameters, ActionPerformReturn, TriggerResult, ActionContext } from ".";
2
2
  export interface PollingContext<TInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection> extends ActionContext<TConfigVars> {
3
3
  polling: {
4
4
  invokeAction: (params: ActionInputParameters<TInputs>) => Promise<ActionPerformReturn<boolean, any>>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "10.3.0",
4
- "description": "Utility library for building Prismatic components and code-native integrations",
3
+ "version": "10.3.2",
4
+ "description": "Utility library for building Prismatic connectors and code-native integrations",
5
5
  "keywords": ["prismatic"],
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",