@prismatic-io/spectral 9.1.2 → 9.1.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.
@@ -48,7 +48,7 @@ const createActions = (_a) => __awaiter(void 0, [_a], void 0, function* ({ compo
48
48
  typeInterface: (0, createTypeInterface_1.createTypeInterface)((_b = action.key) !== null && _b !== void 0 ? _b : actionKey),
49
49
  import: (0, createImport_1.createImport)((_c = action.key) !== null && _c !== void 0 ? _c : actionKey),
50
50
  key: action.key || actionKey,
51
- label: action.display.description,
51
+ label: action.display.label,
52
52
  description: action.display.description,
53
53
  inputs,
54
54
  },
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addPunctuation = exports.addLine = exports.DOC_BLOCK_DEFAULT = void 0;
4
+ const escapeSpecialCharacters_1 = require("../utils/escapeSpecialCharacters");
4
5
  const DOC_BLOCK_DEFAULT = (input) => {
5
6
  const comments = (0, exports.addPunctuation)(input.comments);
6
7
  const onPrem = input.onPremControlled || input.onPremiseControlled
@@ -23,9 +24,9 @@ const addLine = ({ key, value, raw }) => {
23
24
  if (typeof value === "undefined" || value === null || value === "") {
24
25
  return "";
25
26
  }
26
- const sanitizedValue = JSON.stringify(value)
27
+ const sanitizedValue = (0, escapeSpecialCharacters_1.escapeSpecialCharacters)(JSON.stringify(value)
27
28
  .replace(/(^"|"$)|(^'|'$)/g, "")
28
- .trim();
29
+ .trim());
29
30
  return ` * ${key ? `@${key} ${sanitizedValue}` : sanitizedValue}\n`;
30
31
  };
31
32
  exports.addLine = addLine;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.INPUT_TYPE_MAP = exports.getInputs = void 0;
4
+ const escapeSpecialCharacters_1 = require("../utils/escapeSpecialCharacters");
4
5
  const docBlock_1 = require("./docBlock");
5
6
  const getDefaultValue = (value) => {
6
- if (value === undefined || value === "" || typeof value === "string") {
7
+ if (value === undefined || value === "") {
7
8
  return value;
8
9
  }
9
- return JSON.stringify(value);
10
+ const stringValue = typeof value === "string" ? value : JSON.stringify(value);
11
+ return (0, escapeSpecialCharacters_1.escapeSpecialCharacters)(stringValue);
10
12
  };
11
13
  const getInputs = ({ inputs, docBlock = docBlock_1.DOC_BLOCK_DEFAULT }) => {
12
14
  return inputs.reduce((acc, input) => {
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This regex targets common characters that may be included in default
3
+ * input values (code comment blocks, backticks, etc) and would cause
4
+ * component-manifest build issues. More characters may be added
5
+ * as discovered.
6
+ */
7
+ export declare const escapeSpecialCharacters: (value?: string) => string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ /**
3
+ * This regex targets common characters that may be included in default
4
+ * input values (code comment blocks, backticks, etc) and would cause
5
+ * component-manifest build issues. More characters may be added
6
+ * as discovered.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.escapeSpecialCharacters = void 0;
10
+ const escapeRegEx = /(\/|\\|\`|\$)/g;
11
+ const escapeSpecialCharacters = (value = "") => {
12
+ return value.replace(escapeRegEx, "\\$&");
13
+ };
14
+ exports.escapeSpecialCharacters = escapeSpecialCharacters;
@@ -1,3 +1,6 @@
1
- import { IntegrationDefinition } from "../types";
1
+ import { IntegrationDefinition, ConfigVar, ComponentRegistry } from "../types";
2
2
  import { Component as ServerComponent } from ".";
3
+ import { RequiredConfigVariable as ServerRequiredConfigVariable } from "./integration";
3
4
  export declare const convertIntegration: (definition: IntegrationDefinition) => ServerComponent;
5
+ /** Converts a Config Var into the structure necessary for YAML generation. */
6
+ export declare const convertConfigVar: (key: string, configVar: ConfigVar, referenceKey: string, componentRegistry: ComponentRegistry) => ServerRequiredConfigVariable;
@@ -8,22 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
13
  };
25
14
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.convertIntegration = void 0;
15
+ exports.convertConfigVar = exports.convertIntegration = void 0;
27
16
  const yaml_1 = __importDefault(require("yaml"));
28
17
  const uuid_1 = require("uuid");
29
18
  const lodash_1 = require("lodash");
@@ -99,7 +88,7 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
99
88
  documentation,
100
89
  version,
101
90
  labels,
102
- requiredConfigVars: Object.entries(configVars || {}).map(([key, configVar]) => convertConfigVar(key, configVar, referenceKey, componentRegistry)),
91
+ requiredConfigVars: Object.entries(configVars || {}).map(([key, configVar]) => (0, exports.convertConfigVar)(key, configVar, referenceKey, componentRegistry)),
103
92
  endpointType,
104
93
  preprocessFlowName: hasPreprocessFlow ? preprocessFlows[0].name : undefined,
105
94
  externalCustomerIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerIdField),
@@ -328,10 +317,24 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
328
317
  return result;
329
318
  }
330
319
  const meta = convertInputPermissionAndVisibility((0, lodash_1.pick)(input, ["permissionAndVisibilityType", "visibleToOrgDeployer"]));
331
- const defaultValue = input.collection ? [] : "";
320
+ const defaultValue = input.collection
321
+ ? (input.default || []).map((defaultValue) => {
322
+ if (typeof defaultValue === "string") {
323
+ return {
324
+ type: "value",
325
+ value: defaultValue,
326
+ };
327
+ }
328
+ return {
329
+ name: defaultValue.key,
330
+ type: "value",
331
+ value: defaultValue.value,
332
+ };
333
+ })
334
+ : input.default || "";
332
335
  return Object.assign(Object.assign({}, result), { [key]: {
333
336
  type: input.collection ? "complex" : "value",
334
- value: input.default || defaultValue,
337
+ value: defaultValue,
335
338
  meta,
336
339
  } });
337
340
  }, {}),
@@ -395,6 +398,7 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
395
398
  }
396
399
  return result;
397
400
  };
401
+ exports.convertConfigVar = convertConfigVar;
398
402
  /** Maps the step name field to a fully qualified input. */
399
403
  const fieldNameToReferenceInput = (stepName, fieldName) => fieldName ? { type: "reference", value: `${stepName}.results.${fieldName}` } : undefined;
400
404
  /** Actions and Triggers will be scoped to their flow by combining the flow
@@ -410,9 +414,8 @@ const flowFunctionKey = (flowName, functionName) => {
410
414
  return `${flowKey}_${functionName}`;
411
415
  };
412
416
  const convertOnExecution = (onExecution, componentRegistry) => (context, params) => {
413
- const {
414
417
  // @ts-expect-error _components isn't part of the public API
415
- _components } = context, remainingContext = __rest(context, ["_components"]);
418
+ const { _components } = context;
416
419
  const invoke = _components.invoke;
417
420
  // Construct the component methods from the component registry
418
421
  const componentMethods = Object.entries(componentRegistry).reduce((accumulator, [registryComponentKey, { key: componentKey, actions, public: isPublic, signature }]) => {
@@ -443,7 +446,7 @@ const convertOnExecution = (onExecution, componentRegistry) => (context, params)
443
446
  }, {});
444
447
  return Object.assign(Object.assign({}, accumulator), { [registryComponentKey]: componentActions });
445
448
  }, {});
446
- return onExecution(Object.assign(Object.assign({}, remainingContext), { components: componentMethods }), params);
449
+ return onExecution(Object.assign(Object.assign({}, context), { components: componentMethods }), params);
447
450
  };
448
451
  /** Creates the structure necessary to import a Component as part of a
449
452
  * Code Native integration. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "9.1.2",
3
+ "version": "9.1.4",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": ["prismatic"],
6
6
  "main": "dist/index.js",