@prismatic-io/spectral 10.5.2 → 10.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,16 @@
1
- import { InputFieldDefinition, ComponentDefinition, ConnectionDefinition, TriggerDefinition, ComponentHooks, ConfigVarResultCollection, OnPremConnectionInput, TriggerPayload, ConnectionTemplateInputField } from "../types";
1
+ import { InputFieldDefinition, ComponentDefinition, ConnectionDefinition, TriggerDefinition, ComponentHooks, ConfigVarResultCollection, OnPremConnectionInput, TriggerPayload, ConnectionTemplateInputField, ConnectionInput } from "../types";
2
2
  import { Component as ServerComponent, Connection as ServerConnection, Trigger as ServerTrigger, Input as ServerInput } from ".";
3
3
  import { PollingTriggerDefinition } from "../types/PollingTriggerDefinition";
4
4
  export declare const convertInput: (key: string, { default: defaultValue, type, label, collection, ...rest }: InputFieldDefinition | OnPremConnectionInput) => ServerInput;
5
- export declare const convertTemplateInput: (key: string, { templateValue, label, ...rest }: ConnectionTemplateInputField) => ServerInput;
5
+ export declare const _isValidTemplateValue: (template: string, inputs: {
6
+ [key: string]: ConnectionInput | ConnectionTemplateInputField;
7
+ }) => {
8
+ isValid: boolean;
9
+ error?: string;
10
+ };
11
+ export declare const convertTemplateInput: (key: string, { templateValue, label, ...rest }: ConnectionTemplateInputField, inputs: {
12
+ [key: string]: ConnectionInput | ConnectionTemplateInputField;
13
+ }) => ServerInput;
6
14
  export declare const convertTrigger: (triggerKey: string, trigger: TriggerDefinition<any> | PollingTriggerDefinition<any, ConfigVarResultCollection, TriggerPayload, boolean, any, any>, hooks?: ComponentHooks) => ServerTrigger;
7
15
  export declare const convertConnection: ({ inputs, ...connection }: ConnectionDefinition) => ServerConnection;
8
16
  export declare const convertComponent: <TPublic extends boolean, TKey extends string>({ connections, actions, triggers, dataSources, hooks, ...definition }: ComponentDefinition<TPublic, TKey>) => ServerComponent;
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.convertComponent = exports.convertConnection = exports.convertTrigger = exports.convertTemplateInput = exports.convertInput = void 0;
17
+ exports.convertComponent = exports.convertConnection = exports.convertTrigger = exports.convertTemplateInput = exports._isValidTemplateValue = exports.convertInput = void 0;
18
18
  const types_1 = require("../types");
19
19
  const perform_1 = require("./perform");
20
20
  const omit_1 = __importDefault(require("lodash/omit"));
@@ -31,8 +31,42 @@ const convertInput = (key, _a) => {
31
31
  type, default: defaultValue !== null && defaultValue !== void 0 ? defaultValue : types_1.InputFieldDefaultMap[type], collection, label: typeof label === "string" ? label : label.value, keyLabel, onPremiseControlled: ("onPremControlled" in rest && rest.onPremControlled) || undefined });
32
32
  };
33
33
  exports.convertInput = convertInput;
34
- const convertTemplateInput = (key, _a) => {
34
+ const TEMPLATE_VALUE_REGEX = /{{#(\w+)}}/g;
35
+ const TEMPLATE_VALUE_ERRORS = {
36
+ NO_SLOTS: "No template slots were found. Declare a template slot with this notation: {{#someInputKey}}",
37
+ INVALID_KEYS: "Invalid keys were found in the template string. All referenced keys must be non-template inputs declared in the first argument:",
38
+ };
39
+ const _isValidTemplateValue = (template, inputs) => {
40
+ const matches = [...template.matchAll(TEMPLATE_VALUE_REGEX)];
41
+ if (matches.length === 0) {
42
+ return {
43
+ isValid: false,
44
+ error: TEMPLATE_VALUE_ERRORS.NO_SLOTS,
45
+ };
46
+ }
47
+ const invalidKeys = [];
48
+ for (const [_substr, key] of matches) {
49
+ if (!inputs[key] || inputs[key].type === "template") {
50
+ invalidKeys.push(key);
51
+ }
52
+ }
53
+ if (invalidKeys.length > 0) {
54
+ return {
55
+ isValid: false,
56
+ error: `${TEMPLATE_VALUE_ERRORS.INVALID_KEYS} ${invalidKeys}`,
57
+ };
58
+ }
59
+ return {
60
+ isValid: true,
61
+ };
62
+ };
63
+ exports._isValidTemplateValue = _isValidTemplateValue;
64
+ const convertTemplateInput = (key, _a, inputs) => {
35
65
  var { templateValue, label } = _a, rest = __rest(_a, ["templateValue", "label"]);
66
+ const validation = (0, exports._isValidTemplateValue)(templateValue, inputs);
67
+ if (!validation.isValid) {
68
+ throw `Template input "${key}": ${validation.error}`;
69
+ }
36
70
  return Object.assign(Object.assign({}, (0, omit_1.default)(rest, ["permissionAndVisibilityType", "visibleToOrgDeployer", "writeOnly"])), { key, type: "template", default: templateValue !== null && templateValue !== void 0 ? templateValue : "", label: typeof label === "string" ? label : label.value, shown: false });
37
71
  };
38
72
  exports.convertTemplateInput = convertTemplateInput;
@@ -122,7 +156,7 @@ const convertConnection = (_a) => {
122
156
  const { display: { label, icons, description: comments } } = connection, remaining = __rest(connection, ["display"]);
123
157
  const convertedInputs = Object.entries(inputs).map(([key, value]) => {
124
158
  if ("templateValue" in value) {
125
- return (0, exports.convertTemplateInput)(key, value);
159
+ return (0, exports.convertTemplateInput)(key, value, inputs);
126
160
  }
127
161
  return (0, exports.convertInput)(key, value);
128
162
  });
@@ -392,7 +392,8 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
392
392
  component: codeNativeIntegrationComponentReference(referenceKey),
393
393
  },
394
394
  inputs: Object.entries(configVar.inputs).reduce((result, [key, input]) => {
395
- if (input.shown === false) {
395
+ // Connection template inputs are never shown in the resulting YAML.
396
+ if (input.shown === false || "templateValue" in input) {
396
397
  return result;
397
398
  }
398
399
  const meta = convertInputPermissionAndVisibility((0, pick_1.default)(input, ["permissionAndVisibilityType", "visibleToOrgDeployer"]));
@@ -666,7 +667,12 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
666
667
  if (!(0, types_1.isConnectionDefinitionConfigVar)(configVar)) {
667
668
  return result;
668
669
  }
669
- const convertedInputs = Object.entries(configVar.inputs).map(([key, value]) => (0, convertComponent_1.convertInput)(key, value));
670
+ const convertedInputs = Object.entries(configVar.inputs).map(([key, value]) => {
671
+ if ("templateValue" in value) {
672
+ return (0, convertComponent_1.convertTemplateInput)(key, value, configVar.inputs);
673
+ }
674
+ return (0, convertComponent_1.convertInput)(key, value);
675
+ });
670
676
  const connection = (0, pick_1.default)(configVar, ["oauth2Type", "oauth2PkceMethod"]);
671
677
  const { avatarPath: avatarIconPath, oauth2ConnectionIconPath: iconPath } = (_a = configVar.icons) !== null && _a !== void 0 ? _a : {};
672
678
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "10.5.2",
3
+ "version": "10.5.4",
4
4
  "description": "Utility library for building Prismatic connectors and code-native integrations",
5
5
  "keywords": ["prismatic"],
6
6
  "main": "dist/index.js",