@prismatic-io/spectral 9.1.1 → 9.1.3

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;
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.convertIntegration = void 0;
26
+ exports.convertConfigVar = exports.convertIntegration = void 0;
27
27
  const yaml_1 = __importDefault(require("yaml"));
28
28
  const uuid_1 = require("uuid");
29
29
  const lodash_1 = require("lodash");
@@ -99,7 +99,7 @@ const codeNativeIntegrationYaml = ({ name, description, category, documentation,
99
99
  documentation,
100
100
  version,
101
101
  labels,
102
- requiredConfigVars: Object.entries(configVars || {}).map(([key, configVar]) => convertConfigVar(key, configVar, referenceKey, componentRegistry)),
102
+ requiredConfigVars: Object.entries(configVars || {}).map(([key, configVar]) => (0, exports.convertConfigVar)(key, configVar, referenceKey, componentRegistry)),
103
103
  endpointType,
104
104
  preprocessFlowName: hasPreprocessFlow ? preprocessFlows[0].name : undefined,
105
105
  externalCustomerIdField: fieldNameToReferenceInput(hasPreprocessFlow ? "onExecution" : "payload", preprocessFlowConfig === null || preprocessFlowConfig === void 0 ? void 0 : preprocessFlowConfig.externalCustomerIdField),
@@ -310,6 +310,7 @@ const convertInputValue = (value, collectionType) => {
310
310
  };
311
311
  /** Converts a Config Var into the structure necessary for YAML generation. */
312
312
  const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
313
+ var _a;
313
314
  const { orgOnly, meta } = convertConfigVarPermissionAndVisibility((0, lodash_1.pick)(configVar, ["permissionAndVisibilityType", "visibleToOrgDeployer"]));
314
315
  if ((0, types_1.isConnectionDefinitionConfigVar)(configVar)) {
315
316
  const { stableKey, description } = (0, lodash_1.pick)(configVar, ["stableKey", "description"]);
@@ -327,10 +328,24 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
327
328
  return result;
328
329
  }
329
330
  const meta = convertInputPermissionAndVisibility((0, lodash_1.pick)(input, ["permissionAndVisibilityType", "visibleToOrgDeployer"]));
330
- const defaultValue = input.collection ? [] : "";
331
+ const defaultValue = input.collection
332
+ ? (input.default || []).map((defaultValue) => {
333
+ if (typeof defaultValue === "string") {
334
+ return {
335
+ type: "value",
336
+ value: defaultValue,
337
+ };
338
+ }
339
+ return {
340
+ name: defaultValue.key,
341
+ type: "value",
342
+ value: defaultValue.value,
343
+ };
344
+ })
345
+ : input.default || "";
331
346
  return Object.assign(Object.assign({}, result), { [key]: {
332
347
  type: input.collection ? "complex" : "value",
333
- value: input.default || defaultValue,
348
+ value: defaultValue,
334
349
  meta,
335
350
  } });
336
351
  }, {}),
@@ -373,6 +388,9 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
373
388
  if ((0, types_1.isScheduleConfigVar)(configVar)) {
374
389
  result.scheduleType = "custom";
375
390
  }
391
+ if ((0, types_1.isJsonFormConfigVar)(configVar) || (0, types_1.isJsonFormDataSourceConfigVar)(configVar)) {
392
+ result.meta = Object.assign(Object.assign({}, result.meta), { validationMode: (_a = configVar === null || configVar === void 0 ? void 0 : configVar.validationMode) !== null && _a !== void 0 ? _a : "ValidateAndShow" });
393
+ }
376
394
  if ((0, types_1.isDataSourceDefinitionConfigVar)(configVar)) {
377
395
  result.dataType = configVar.dataSourceType;
378
396
  result.dataSource = {
@@ -385,9 +403,13 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
385
403
  result.dataType = componentRegistry[ref.component.key].dataSources[ref.key].dataSourceType;
386
404
  result.dataSource = ref;
387
405
  result.inputs = inputs;
406
+ if (configVar.validationMode) {
407
+ result.meta = Object.assign(Object.assign({}, result.meta), { validationMode: configVar.validationMode });
408
+ }
388
409
  }
389
410
  return result;
390
411
  };
412
+ exports.convertConfigVar = convertConfigVar;
391
413
  /** Maps the step name field to a fully qualified input. */
392
414
  const fieldNameToReferenceInput = (stepName, fieldName) => fieldName ? { type: "reference", value: `${stepName}.results.${fieldName}` } : undefined;
393
415
  /** Actions and Triggers will be scoped to their flow by combining the flow
@@ -1,3 +1,4 @@
1
+ import { ValidationMode } from "@jsonforms/core";
1
2
  import { type DataSourceDefinition, type ConnectionDefinition, type Inputs, type DataSourceType, type Connection, type JSONForm, type ObjectFieldMap, type ObjectSelection, type ConfigVarResultCollection, type Schedule, type CollectionDataSourceType, type DataSourceReference, type ConfigPage, type ConfigPages, type ConfigPageElement, type ComponentRegistryDataSource, type ComponentRegistryConnection, type UserLevelConfigPages } from ".";
2
3
  import type { Prettify, UnionToIntersection } from "./utils";
3
4
  /** Supported data types for Config Vars. */
@@ -105,12 +106,22 @@ type ScheduleConfigVar = CreateStandardConfigVar<"schedule"> & {
105
106
  };
106
107
  type ObjectSelectionConfigVar = CreateStandardConfigVar<"objectSelection">;
107
108
  type ObjectFieldMapConfigVar = CreateStandardConfigVar<"objectFieldMap">;
108
- type JsonFormConfigVar = CreateStandardConfigVar<"jsonForm">;
109
+ type JsonFormConfigVar = CreateStandardConfigVar<"jsonForm"> & {
110
+ validationMode?: ValidationMode;
111
+ };
112
+ type JsonFormDataSourceDefinitionConfigVar = DataSourceDefinitionConfigVar & {
113
+ validationMode?: ValidationMode;
114
+ };
109
115
  export type StandardConfigVar = StringConfigVar | DateConfigVar | TimestampConfigVar | PicklistConfigVar | CodeConfigVar | BooleanConfigVar | NumberConfigVar | ScheduleConfigVar | ObjectSelectionConfigVar | ObjectFieldMapConfigVar | JsonFormConfigVar;
110
116
  type BaseDataSourceConfigVar<TDataSourceType extends DataSourceType = DataSourceType> = TDataSourceType extends CollectionDataSourceType ? {
111
117
  dataSourceType: TDataSourceType;
112
118
  collectionType?: CollectionType | undefined;
113
- } & BaseConfigVar : TDataSourceType extends Exclude<DataSourceType, CollectionDataSourceType> ? BaseConfigVar & {
119
+ } & BaseConfigVar : TDataSourceType extends Exclude<DataSourceType, CollectionDataSourceType> ? TDataSourceType extends Extract<DataSourceType, "jsonForm"> ? BaseConfigVar & {
120
+ dataSourceType: Extract<DataSourceType, "jsonForm">;
121
+ dataSource?: never;
122
+ collectionType?: undefined;
123
+ validationMode?: ValidationMode;
124
+ } : BaseConfigVar & {
114
125
  dataSourceType: TDataSourceType;
115
126
  collectionType?: undefined;
116
127
  } : ({
@@ -123,6 +134,7 @@ type BaseDataSourceConfigVar<TDataSourceType extends DataSourceType = DataSource
123
134
  type DataSourceDefinitionConfigVar = DataSourceType extends infer TDataSourceType ? TDataSourceType extends DataSourceType ? BaseDataSourceConfigVar<TDataSourceType> & Omit<DataSourceDefinition<Inputs, ConfigVarResultCollection, TDataSourceType>, "display" | "inputs" | "examplePayload" | "detailDataSource"> : never : never;
124
135
  type DataSourceReferenceConfigVar = ComponentRegistryDataSource extends infer TDataSourceReference extends ComponentRegistryDataSource ? Omit<BaseDataSourceConfigVar<TDataSourceReference["dataSourceType"]>, "dataSourceType"> & {
125
136
  dataSource: TDataSourceReference["reference"];
137
+ validationMode?: ValidationMode;
126
138
  } : never;
127
139
  /** Defines attributes of a data source Config Var. */
128
140
  export type DataSourceConfigVar = DataSourceDefinitionConfigVar | DataSourceReferenceConfigVar;
@@ -165,6 +177,8 @@ type ExtractConfigVars<TConfigPages extends {
165
177
  export type ConfigVars = Prettify<UnionToIntersection<ExtractConfigVars<ConfigPages>>> & Prettify<UnionToIntersection<ExtractConfigVars<UserLevelConfigPages>>>;
166
178
  export declare const isCodeConfigVar: (cv: ConfigVar) => cv is CodeConfigVar;
167
179
  export declare const isScheduleConfigVar: (cv: ConfigVar) => cv is ScheduleConfigVar;
180
+ export declare const isJsonFormConfigVar: (cv: ConfigVar) => cv is JsonFormConfigVar;
181
+ export declare const isJsonFormDataSourceConfigVar: (cv: ConfigVar) => cv is JsonFormDataSourceDefinitionConfigVar;
168
182
  export declare const isDataSourceDefinitionConfigVar: (cv: ConfigVar) => cv is DataSourceDefinitionConfigVar;
169
183
  export declare const isDataSourceReferenceConfigVar: (cv: unknown) => cv is DataSourceReferenceConfigVar;
170
184
  export declare const isConnectionDefinitionConfigVar: (cv: ConfigVar) => cv is ConnectionDefinitionConfigVar;
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isConnectionReferenceConfigVar = exports.isConnectionDefinitionConfigVar = exports.isDataSourceReferenceConfigVar = exports.isDataSourceDefinitionConfigVar = exports.isScheduleConfigVar = exports.isCodeConfigVar = void 0;
3
+ exports.isConnectionReferenceConfigVar = exports.isConnectionDefinitionConfigVar = exports.isDataSourceReferenceConfigVar = exports.isDataSourceDefinitionConfigVar = exports.isJsonFormDataSourceConfigVar = exports.isJsonFormConfigVar = exports.isScheduleConfigVar = exports.isCodeConfigVar = void 0;
4
4
  const _1 = require(".");
5
5
  const isCodeConfigVar = (cv) => "dataType" in cv && cv.dataType === "code";
6
6
  exports.isCodeConfigVar = isCodeConfigVar;
7
7
  const isScheduleConfigVar = (cv) => "dataType" in cv && cv.dataType === "schedule";
8
8
  exports.isScheduleConfigVar = isScheduleConfigVar;
9
+ const isJsonFormConfigVar = (cv) => "dataType" in cv && cv.dataType === "jsonForm";
10
+ exports.isJsonFormConfigVar = isJsonFormConfigVar;
11
+ const isJsonFormDataSourceConfigVar = (cv) => "dataSourceType" in cv && cv.dataSourceType === "jsonForm";
12
+ exports.isJsonFormDataSourceConfigVar = isJsonFormDataSourceConfigVar;
9
13
  const isDataSourceDefinitionConfigVar = (cv) => "dataSourceType" in cv && "perform" in cv && typeof cv.perform === "function";
10
14
  exports.isDataSourceDefinitionConfigVar = isDataSourceDefinitionConfigVar;
11
15
  const isDataSourceReferenceConfigVar = (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "9.1.1",
3
+ "version": "9.1.3",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": ["prismatic"],
6
6
  "main": "dist/index.js",