@prismatic-io/spectral 9.0.0-rc.9 → 9.0.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.
Files changed (36) hide show
  1. package/dist/generators/componentManifest/cli.js +2 -1
  2. package/dist/generators/componentManifest/createActions.js +0 -15
  3. package/dist/generators/componentManifest/createConnections.js +0 -25
  4. package/dist/generators/componentManifest/createDataSources.js +1 -15
  5. package/dist/generators/componentManifest/createTriggers.js +0 -15
  6. package/dist/generators/componentManifest/docBlock.d.ts +10 -0
  7. package/dist/generators/componentManifest/docBlock.js +40 -0
  8. package/dist/generators/componentManifest/getInputs.d.ts +5 -7
  9. package/dist/generators/componentManifest/getInputs.js +23 -44
  10. package/dist/generators/componentManifest/templates/actions/action.ts.ejs +2 -2
  11. package/dist/generators/componentManifest/templates/connections/connection.ts.ejs +2 -2
  12. package/dist/generators/componentManifest/templates/dataSources/dataSource.ts.ejs +3 -2
  13. package/dist/generators/componentManifest/templates/index.ts.ejs +1 -1
  14. package/dist/generators/componentManifest/templates/partials/inputs.ejs +2 -3
  15. package/dist/generators/componentManifest/templates/partials/performArgs.ejs +1 -7
  16. package/dist/generators/componentManifest/templates/triggers/trigger.ts.ejs +2 -2
  17. package/dist/generators/utils/createTemplate.js +9 -3
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.js +2 -2
  20. package/dist/serverTypes/convertIntegration.js +39 -35
  21. package/dist/serverTypes/integration.d.ts +2 -0
  22. package/dist/types/ComponentManifest.d.ts +15 -15
  23. package/dist/types/ComponentRegistry.d.ts +89 -0
  24. package/dist/types/ComponentRegistry.js +5 -0
  25. package/dist/types/ConfigPages.d.ts +46 -0
  26. package/dist/types/ConfigPages.js +2 -0
  27. package/dist/types/ConfigVars.d.ts +241 -0
  28. package/dist/types/ConfigVars.js +30 -0
  29. package/dist/types/Inputs.d.ts +13 -13
  30. package/dist/types/IntegrationDefinition.d.ts +1 -220
  31. package/dist/types/IntegrationDefinition.js +0 -17
  32. package/dist/types/index.d.ts +3 -0
  33. package/dist/types/index.js +3 -0
  34. package/package.json +3 -2
  35. /package/dist/serverTypes/{convert.d.ts → convertComponent.d.ts} +0 -0
  36. /package/dist/serverTypes/{convert.js → convertComponent.js} +0 -0
@@ -17,6 +17,7 @@ exports.runMain = void 0;
17
17
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
18
18
  const path_1 = __importDefault(require("path"));
19
19
  const fs_extra_1 = require("fs-extra");
20
+ const lodash_1 = require("lodash");
20
21
  const index_1 = require("./index");
21
22
  const createFlagHelpText_1 = require("../utils/createFlagHelpText");
22
23
  const getFlagStringValue_1 = require("../utils/getFlagStringValue");
@@ -116,7 +117,7 @@ const runMain = (process) => __awaiter(void 0, void 0, void 0, function* () {
116
117
  component,
117
118
  dryRun: flags.dry_run.value,
118
119
  skipSignatureVerify: flags.skip_signature_verify.value,
119
- packageName: (_a = flags.name.value) !== null && _a !== void 0 ? _a : `@component-manifests/${component.key}`,
120
+ packageName: (_a = flags.name.value) !== null && _a !== void 0 ? _a : `@component-manifests/${(0, lodash_1.kebabCase)(component.key)}`,
120
121
  dependencies: {
121
122
  spectral: packageJson.version,
122
123
  dependencies: packageJson.dependencies,
@@ -18,20 +18,6 @@ const getInputs_1 = require("./getInputs");
18
18
  const getImports_1 = require("./getImports");
19
19
  const helpers_1 = require("./helpers");
20
20
  const createTemplate_1 = require("../utils/createTemplate");
21
- const DOC_BLOCK = [
22
- {
23
- propertyKey: "comments",
24
- },
25
- {
26
- propertyKey: "default",
27
- },
28
- {
29
- propertyKey: "example",
30
- },
31
- {
32
- propertyKey: "placeholder",
33
- },
34
- ];
35
21
  const createActions = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
36
22
  var _a, _b;
37
23
  if (verbose) {
@@ -51,7 +37,6 @@ const createActions = ({ component, dryRun, verbose, sourceDir, destinationDir,
51
37
  const actions = yield Promise.all(Object.entries((_b = component.actions) !== null && _b !== void 0 ? _b : {}).map(([actionKey, action]) => __awaiter(void 0, void 0, void 0, function* () {
52
38
  const inputs = (0, getInputs_1.getInputs)({
53
39
  inputs: action.inputs,
54
- docBlock: DOC_BLOCK,
55
40
  });
56
41
  const imports = (0, getImports_1.getImports)({ inputs });
57
42
  return yield renderAction({
@@ -18,30 +18,6 @@ const getInputs_1 = require("./getInputs");
18
18
  const getImports_1 = require("./getImports");
19
19
  const helpers_1 = require("./helpers");
20
20
  const createTemplate_1 = require("../utils/createTemplate");
21
- const DOC_BLOCK = [
22
- {
23
- propertyKey: "comments",
24
- },
25
- {
26
- propertyKey: "default",
27
- },
28
- {
29
- propertyKey: "example",
30
- },
31
- {
32
- propertyKey: "placeholder",
33
- },
34
- {
35
- propertyKey: "onPremControlled",
36
- propertyValue: true,
37
- output: "This input will be supplied when using an on prem resource.",
38
- },
39
- {
40
- propertyKey: "onPremiseControlled",
41
- propertyValue: true,
42
- output: "This input will be supplied when using an on prem resource.",
43
- },
44
- ];
45
21
  const createConnections = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
46
22
  var _a, _b;
47
23
  if (verbose) {
@@ -61,7 +37,6 @@ const createConnections = ({ component, dryRun, verbose, sourceDir, destinationD
61
37
  const connections = yield Promise.all(((_b = component.connections) !== null && _b !== void 0 ? _b : []).map((connection) => __awaiter(void 0, void 0, void 0, function* () {
62
38
  const inputs = (0, getInputs_1.getInputs)({
63
39
  inputs: connection.inputs,
64
- docBlock: DOC_BLOCK,
65
40
  });
66
41
  const imports = (0, getImports_1.getImports)({ inputs });
67
42
  const onPremAvailable = connection.inputs.some((input) => input.onPremControlled || input.onPremiseControlled);
@@ -18,20 +18,6 @@ const getInputs_1 = require("./getInputs");
18
18
  const getImports_1 = require("./getImports");
19
19
  const helpers_1 = require("./helpers");
20
20
  const createTemplate_1 = require("../utils/createTemplate");
21
- const DOC_BLOCK = [
22
- {
23
- propertyKey: "comments",
24
- },
25
- {
26
- propertyKey: "default",
27
- },
28
- {
29
- propertyKey: "example",
30
- },
31
- {
32
- propertyKey: "placeholder",
33
- },
34
- ];
35
21
  const createDataSources = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
36
22
  var _a, _b;
37
23
  if (verbose) {
@@ -51,7 +37,6 @@ const createDataSources = ({ component, dryRun, verbose, sourceDir, destinationD
51
37
  const dataSources = yield Promise.all(Object.entries((_b = component.dataSources) !== null && _b !== void 0 ? _b : {}).map(([dataSourceKey, dataSource]) => __awaiter(void 0, void 0, void 0, function* () {
52
38
  const inputs = (0, getInputs_1.getInputs)({
53
39
  inputs: dataSource.inputs,
54
- docBlock: DOC_BLOCK,
55
40
  });
56
41
  const imports = (0, getImports_1.getImports)({ inputs });
57
42
  return yield renderDataSource({
@@ -59,6 +44,7 @@ const createDataSources = ({ component, dryRun, verbose, sourceDir, destinationD
59
44
  key: dataSource.key || dataSourceKey,
60
45
  label: dataSource.display.label,
61
46
  description: dataSource.display.description,
47
+ dataSourceType: dataSource.dataSourceType,
62
48
  inputs,
63
49
  },
64
50
  imports,
@@ -18,20 +18,6 @@ const getInputs_1 = require("./getInputs");
18
18
  const getImports_1 = require("./getImports");
19
19
  const helpers_1 = require("./helpers");
20
20
  const createTemplate_1 = require("../utils/createTemplate");
21
- const DOC_BLOCK = [
22
- {
23
- propertyKey: "comments",
24
- },
25
- {
26
- propertyKey: "default",
27
- },
28
- {
29
- propertyKey: "example",
30
- },
31
- {
32
- propertyKey: "placeholder",
33
- },
34
- ];
35
21
  const createTriggers = ({ component, dryRun, verbose, sourceDir, destinationDir, }) => __awaiter(void 0, void 0, void 0, function* () {
36
22
  var _a, _b;
37
23
  if (verbose) {
@@ -51,7 +37,6 @@ const createTriggers = ({ component, dryRun, verbose, sourceDir, destinationDir,
51
37
  const triggers = yield Promise.all(Object.entries((_b = component.triggers) !== null && _b !== void 0 ? _b : {}).map(([triggerKey, trigger]) => __awaiter(void 0, void 0, void 0, function* () {
52
38
  const inputs = (0, getInputs_1.getInputs)({
53
39
  inputs: trigger.inputs,
54
- docBlock: DOC_BLOCK,
55
40
  });
56
41
  const imports = (0, getImports_1.getImports)({ inputs });
57
42
  return yield renderTrigger({
@@ -0,0 +1,10 @@
1
+ import { ServerTypeInput } from "./getInputs";
2
+ export declare const DOC_BLOCK_DEFAULT: (input: ServerTypeInput) => string;
3
+ interface AddLineProps {
4
+ key?: string;
5
+ value?: string | unknown | undefined | null;
6
+ raw?: string;
7
+ }
8
+ export declare const addLine: ({ key, value, raw }: AddLineProps) => string;
9
+ export declare const addPunctuation: (value: string | undefined) => string;
10
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addPunctuation = exports.addLine = exports.DOC_BLOCK_DEFAULT = void 0;
4
+ const DOC_BLOCK_DEFAULT = (input) => {
5
+ const comments = (0, exports.addPunctuation)(input.comments);
6
+ const onPrem = input.onPremControlled || input.onPremiseControlled
7
+ ? " This input will be supplied when using an on prem resource."
8
+ : "";
9
+ return ((0, exports.addLine)({ raw: "/**" }) +
10
+ (0, exports.addLine)({ value: input.label }) +
11
+ (0, exports.addLine)({ value: comments + onPrem }) +
12
+ (0, exports.addLine)({ raw: "*" }) +
13
+ (0, exports.addLine)({ key: "default", value: input.default }) +
14
+ (0, exports.addLine)({ key: "example", value: input.example }) +
15
+ (0, exports.addLine)({ key: "placeholder", value: input.placeholder }) +
16
+ (0, exports.addLine)({ raw: "*/" }));
17
+ };
18
+ exports.DOC_BLOCK_DEFAULT = DOC_BLOCK_DEFAULT;
19
+ const addLine = ({ key, value, raw }) => {
20
+ if (raw) {
21
+ return ` ${raw}\n`;
22
+ }
23
+ if (typeof value === "undefined" || value === null || value === "") {
24
+ return "";
25
+ }
26
+ const sanitizedValue = JSON.stringify(value)
27
+ .replace(/(^"|"$)|(^'|'$)/g, "")
28
+ .trim();
29
+ return ` * ${key ? `@${key} ${sanitizedValue}` : sanitizedValue}\n`;
30
+ };
31
+ exports.addLine = addLine;
32
+ const addPunctuation = (value) => {
33
+ if (typeof value === "undefined" || value === null || value === "") {
34
+ return "";
35
+ }
36
+ return value.endsWith(".") || value.endsWith("!") || value.endsWith("?")
37
+ ? value
38
+ : value + ".";
39
+ };
40
+ exports.addPunctuation = addPunctuation;
@@ -1,18 +1,16 @@
1
1
  import type { Input as InputBase } from "../../serverTypes";
2
2
  import type { InputFieldDefinition } from "../../types/Inputs";
3
- declare type ServerTypeInput = InputBase & {
3
+ export declare type ServerTypeInput = InputBase & {
4
4
  onPremControlled?: boolean;
5
+ shown?: boolean;
5
6
  };
6
7
  export interface Input {
7
8
  key: string;
8
9
  label: string;
9
10
  inputType: string;
10
11
  valueType: ValueType;
12
+ docBlock: string;
11
13
  required: boolean | undefined;
12
- properties: {
13
- key: keyof ServerTypeInput;
14
- value: string;
15
- }[];
16
14
  }
17
15
  export declare type ValueType = string | {
18
16
  type: string;
@@ -26,8 +24,8 @@ export declare type DocBlock = {
26
24
  }[];
27
25
  interface GetInputsProps {
28
26
  inputs: ServerTypeInput[];
29
- docBlock: DocBlock;
27
+ docBlock?: (input: ServerTypeInput) => string;
30
28
  }
31
- export declare const getInputs: ({ inputs, docBlock }: GetInputsProps) => Input[];
29
+ export declare const getInputs: ({ inputs, docBlock, }: GetInputsProps) => Input[];
32
30
  export declare const INPUT_TYPE_MAP: Record<InputFieldDefinition["type"], ValueType>;
33
31
  export {};
@@ -1,50 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.INPUT_TYPE_MAP = exports.getInputs = void 0;
4
- const getInputs = ({ inputs, docBlock }) => {
5
- return inputs.map((input) => {
6
- return {
7
- key: input.key,
8
- label: input.label,
9
- inputType: input.type,
10
- valueType: getInputValueType(input),
11
- required: input.required,
12
- collection: input.collection,
13
- onPremControlled: input.onPremiseControlled || input.onPremControlled,
14
- properties: docBlock.reduce((acc, { propertyKey, inputKey, propertyValue, output }) => {
15
- if (inputKey && inputKey !== input.key) {
16
- return acc;
17
- }
18
- if (output &&
19
- (input[propertyKey] === propertyValue ||
20
- typeof propertyValue === "undefined")) {
21
- return [
22
- ...acc,
23
- {
24
- key: propertyKey,
25
- value: output,
26
- },
27
- ];
28
- }
29
- if (typeof input[propertyKey] === "undefined" ||
30
- input[propertyKey] === null ||
31
- input[propertyKey] === "" ||
32
- (typeof propertyValue !== "undefined" &&
33
- input[propertyKey] !== propertyValue)) {
34
- return acc;
35
- }
36
- return [
37
- ...acc,
38
- {
39
- key: propertyKey,
40
- value: JSON.stringify(input[propertyKey])
41
- .replace(/(^"|"$)|(^'|'$)/g, "")
42
- .trim(),
43
- },
44
- ];
45
- }, []),
46
- };
47
- });
4
+ const docBlock_1 = require("./docBlock");
5
+ const getInputs = ({ inputs, docBlock = docBlock_1.DOC_BLOCK_DEFAULT, }) => {
6
+ return inputs.reduce((acc, input) => {
7
+ if ((typeof input.shown === "boolean" && input.shown === false) ||
8
+ input.type === "dynamicObjectSelection" ||
9
+ input.type === "dynamicFieldSelection") {
10
+ return acc;
11
+ }
12
+ return [
13
+ ...acc,
14
+ {
15
+ key: input.key,
16
+ label: input.label,
17
+ inputType: input.type,
18
+ valueType: getInputValueType(input),
19
+ required: input.required &&
20
+ (input.default === undefined || input.default === ""),
21
+ collection: input.collection,
22
+ onPremControlled: input.onPremiseControlled || input.onPremControlled,
23
+ docBlock: docBlock(input),
24
+ },
25
+ ];
26
+ }, []);
48
27
  };
49
28
  exports.getInputs = getInputs;
50
29
  exports.INPUT_TYPE_MAP = {
@@ -1,4 +1,4 @@
1
- <%- include('../partials/imports.ejs', { imports, helpers }) -%>
1
+ <%- include('../partials/imports.ejs', { imports, helpers }) %>
2
2
 
3
3
  export interface <%= helpers.capitalizeFirstLetter(action.key) %>Values {
4
4
  <%- include('../partials/performArgs.ejs', { inputs: action.inputs }) -%>
@@ -16,4 +16,4 @@ export const <%= action.key %> = {
16
16
  inputs: {
17
17
  <%- include('../partials/inputs.ejs', { inputs: action.inputs }) -%>
18
18
  }
19
- }
19
+ } as const;
@@ -1,4 +1,4 @@
1
- <%- include('../partials/imports.ejs', { imports, helpers }) -%>
1
+ <%- include('../partials/imports.ejs', { imports, helpers }) %>
2
2
 
3
3
  export interface <%= helpers.capitalizeFirstLetter(connection.key) %>Values {
4
4
  <%- include('../partials/performArgs.ejs', { inputs: connection.inputs }) -%>
@@ -19,4 +19,4 @@ export const <%= connection.key %> = {
19
19
  inputs: {
20
20
  <%- include('../partials/inputs.ejs', { inputs: connection.inputs }) -%>
21
21
  }
22
- };
22
+ } as const;
@@ -1,4 +1,4 @@
1
- <%- include('../partials/imports.ejs', { imports, helpers }) -%>
1
+ <%- include('../partials/imports.ejs', { imports, helpers }) %>
2
2
 
3
3
  export interface <%= helpers.capitalizeFirstLetter(dataSource.key) %>Values {
4
4
  <%- include('../partials/performArgs.ejs', { inputs: dataSource.inputs }) -%>
@@ -13,7 +13,8 @@ export const <%= dataSource.key %> = {
13
13
  perform: (
14
14
  _values: <%= helpers.capitalizeFirstLetter(dataSource.key) %>Values
15
15
  ): Promise<void> => Promise.resolve(),
16
+ dataSourceType: "<%= dataSource.dataSourceType %>",
16
17
  inputs: {
17
18
  <%- include('../partials/inputs.ejs', { inputs: dataSource.inputs }) -%>
18
19
  }
19
- }
20
+ } as const;
@@ -17,4 +17,4 @@ export default {
17
17
  dataSources,
18
18
  connections,
19
19
  triggers,
20
- };
20
+ } as const;
@@ -1,11 +1,10 @@
1
1
  <% inputs.forEach((input) => { -%>
2
2
  <%= input.key %>: {
3
- valueType: "<%- input.valueType.type ? input.valueType.type : input.valueType %>",
4
3
  inputType: "<%= input.inputType %>",
5
4
  <%_ if (input.collection) { -%>
6
- collection: "<%= input.collection %>" as const,
5
+ collection: "<%= input.collection %>",
7
6
  <%_ } else { -%>
8
- collection: null,
7
+ collection: undefined,
9
8
  <%_ } -%>
10
9
  <%_ if (input.default) { -%>
11
10
  default: <%= input.default %>,
@@ -1,10 +1,4 @@
1
1
  <% inputs.forEach((input) => { -%>
2
- /**
3
- * <%= input.label %>
4
- *
5
- <%_ input.properties.forEach((property) => { -%>
6
- * @<%= property.key %> <%- property.value %>
7
- <%_ }); -%>
8
- */
2
+ <%= input.docBlock -%>
9
3
  <%= input.key %><%= input.required ? "" : "?" %>: <%- input.valueType.type ? input.valueType.type : input.valueType %>;
10
4
  <% }); -%>
@@ -1,4 +1,4 @@
1
- <%- include('../partials/imports.ejs', { imports, helpers }) -%>
1
+ <%- include('../partials/imports.ejs', { imports, helpers }) %>
2
2
 
3
3
  export interface <%= helpers.capitalizeFirstLetter(trigger.key) %>Values {
4
4
  <%- include('../partials/performArgs.ejs', { inputs: trigger.inputs }) -%>
@@ -16,4 +16,4 @@ export const <%= trigger.key %> = {
16
16
  inputs: {
17
17
  <%- include('../partials/inputs.ejs', { inputs: trigger.inputs }) -%>
18
18
  }
19
- }
19
+ } as const;
@@ -16,19 +16,25 @@ exports.createTemplate = void 0;
16
16
  const ejs_1 = require("ejs");
17
17
  const fs_extra_1 = require("fs-extra");
18
18
  const path_1 = __importDefault(require("path"));
19
+ const prettier_1 = require("prettier");
19
20
  const createTemplate = ({ source, destination = source.replace(/\.ejs$/, ""), data = {}, dryRun, verbose, }) => __awaiter(void 0, void 0, void 0, function* () {
20
21
  if (!source) {
21
22
  throw new Error("Source is required");
22
23
  }
23
24
  try {
24
25
  if (path_1.default.extname(source) === ".ejs") {
25
- const rendered = yield (0, ejs_1.renderFile)(source, data);
26
+ const render = yield (0, ejs_1.renderFile)(source, data);
27
+ const formattedRender = [".ts", ".js"].includes(path_1.default.extname(destination))
28
+ ? (0, prettier_1.format)(render, {
29
+ parser: "typescript",
30
+ })
31
+ : render;
26
32
  if (dryRun) {
27
33
  console.info("");
28
34
  console.info("");
29
35
  console.info(`Rendering ${source} to ${destination}`);
30
36
  console.info("---------------------------- Start ----------------------------");
31
- console.info(rendered);
37
+ console.info(formattedRender);
32
38
  console.info("---------------------------- End ----------------------------");
33
39
  console.info("");
34
40
  return;
@@ -36,7 +42,7 @@ const createTemplate = ({ source, destination = source.replace(/\.ejs$/, ""), da
36
42
  if (verbose) {
37
43
  console.info(`Rendering ${source} to ${destination}`);
38
44
  }
39
- yield (0, fs_extra_1.outputFile)(destination, rendered, { encoding: "utf-8" });
45
+ yield (0, fs_extra_1.outputFile)(destination, formattedRender, { encoding: "utf-8" });
40
46
  }
41
47
  else {
42
48
  if (dryRun) {
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@
3
3
  * authors create inputs, actions, and components that can
4
4
  * be processed by the Prismatic API.
5
5
  */
6
- import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, IntegrationDefinition, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConfigVarResultCollection, TriggerPayload, DataSourceConfigVar, OnPremConnectionDefinition, ScheduleConfigVar, ComponentManifest } from "./types";
7
- import { convertComponent } from "./serverTypes/convert";
6
+ import { ActionDefinition, InputFieldDefinition, ComponentDefinition, DefaultConnectionDefinition, OAuth2ConnectionDefinition, Inputs, TriggerDefinition, ActionPerformReturn, TriggerResult, DataSourceDefinition, IntegrationDefinition, Flow, ConfigPage, StandardConfigVar, ConnectionConfigVar, ConfigVarResultCollection, TriggerPayload, DataSourceConfigVar, OnPremConnectionDefinition, ComponentManifest } from "./types";
7
+ import { convertComponent } from "./serverTypes/convertComponent";
8
8
  import { convertIntegration } from "./serverTypes/convertIntegration";
9
9
  /**
10
10
  * This function creates a Integration object that can be
@@ -35,7 +35,7 @@ export declare const configPage: <T extends ConfigPage = ConfigPage>(definition:
35
35
  * @param definition A Config Var type object.
36
36
  * @returns This function returns a standard config var object that has the shape the Prismatic API expects.
37
37
  */
38
- export declare const configVar: <T extends StandardConfigVar | ScheduleConfigVar>(definition: T) => T;
38
+ export declare const configVar: <T extends StandardConfigVar>(definition: T) => T;
39
39
  /**
40
40
  * For information on writing Code Native Integrations, see
41
41
  * https://prismatic.io/docs/code-native-integrations/#adding-config-vars.
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.testing = exports.util = exports.componentManifests = exports.oauth2Connection = exports.onPremConnection = exports.connection = exports.input = exports.dataSource = exports.trigger = exports.action = exports.component = exports.componentManifest = exports.connectionConfigVar = exports.dataSourceConfigVar = exports.configVar = exports.configPage = exports.flow = exports.integration = void 0;
26
- const convert_1 = require("./serverTypes/convert");
26
+ const convertComponent_1 = require("./serverTypes/convertComponent");
27
27
  const convertIntegration_1 = require("./serverTypes/convertIntegration");
28
28
  /**
29
29
  * This function creates a Integration object that can be
@@ -96,7 +96,7 @@ exports.componentManifest = componentManifest;
96
96
  * @param definition A ComponentDefinition type object, including display information, unique key, and a set of actions the component implements.
97
97
  * @returns This function returns a component object that has the shape the Prismatic API expects.
98
98
  */
99
- const component = (definition) => (0, convert_1.convertComponent)(definition);
99
+ const component = (definition) => (0, convertComponent_1.convertComponent)(definition);
100
100
  exports.component = component;
101
101
  /**
102
102
  * This function creates an action object that can be referenced
@@ -28,7 +28,7 @@ const yaml_1 = __importDefault(require("yaml"));
28
28
  const uuid_1 = require("uuid");
29
29
  const lodash_1 = require("lodash");
30
30
  const types_1 = require("../types");
31
- const convert_1 = require("./convert");
31
+ const convertComponent_1 = require("./convertComponent");
32
32
  const integration_1 = require("./integration");
33
33
  const convertIntegration = (definition) => {
34
34
  var _a, _b;
@@ -162,6 +162,9 @@ const convertConfigVarPermissionAndVisibility = ({ permissionAndVisibilityType,
162
162
  const convertComponentReference = (componentReference, componentRegistry) => {
163
163
  var _a, _b;
164
164
  const manifest = componentRegistry[componentReference.component];
165
+ if (!manifest) {
166
+ throw new Error(`Component with key "${componentReference.component}" not found in component registry.`);
167
+ }
165
168
  const ref = {
166
169
  component: {
167
170
  key: manifest.key,
@@ -282,6 +285,19 @@ const convertFlow = (flow, componentRegistry, referenceKey) => {
282
285
  result.supplementalComponents = convertComponentRegistry(componentRegistry);
283
286
  return result;
284
287
  };
288
+ /** Converts an input value to the expected server type by its collection type */
289
+ const convertInputValue = (value, collectionType) => {
290
+ if (collectionType !== "keyvaluelist") {
291
+ return value;
292
+ }
293
+ if (Array.isArray(value)) {
294
+ return value;
295
+ }
296
+ return Object.entries(value).map(([key, value]) => ({
297
+ key,
298
+ value,
299
+ }));
300
+ };
285
301
  /** Converts a Config Var into the structure necessary for YAML generation. */
286
302
  const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
287
303
  const { orgOnly, meta } = convertConfigVarPermissionAndVisibility((0, lodash_1.pick)(configVar, ["permissionAndVisibilityType", "visibleToOrgDeployer"]));
@@ -315,22 +331,30 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
315
331
  }
316
332
  if ((0, types_1.isConnectionReferenceConfigVar)(configVar)) {
317
333
  const { ref, inputs } = convertComponentReference(configVar.connection, componentRegistry);
318
- const { stableKey = "", description, connection: { template }, } = (0, lodash_1.pick)(configVar, ["stableKey", "description", "connection"]);
334
+ const { stableKey = "", description, connection: { template, onPremiseConnectionConfig }, } = (0, lodash_1.pick)(configVar, ["stableKey", "description", "connection"]);
319
335
  return {
320
336
  stableKey,
321
337
  description,
322
338
  key,
323
339
  dataType: "connection",
324
- connection: Object.assign(Object.assign({}, ref), { template }),
340
+ connection: Object.assign(Object.assign({}, ref), { template,
341
+ onPremiseConnectionConfig }),
325
342
  inputs,
326
343
  orgOnly,
327
344
  meta,
328
345
  };
329
346
  }
330
- const result = (0, lodash_1.assign)({ orgOnly, meta, key }, (0, lodash_1.pick)(configVar, [
347
+ const rawDefaultValue = "defaultValue" in configVar
348
+ ? convertInputValue(configVar.defaultValue, configVar.collectionType)
349
+ : undefined;
350
+ const defaultValue = typeof rawDefaultValue !== "undefined"
351
+ ? typeof rawDefaultValue === "string"
352
+ ? rawDefaultValue
353
+ : JSON.stringify(rawDefaultValue)
354
+ : undefined;
355
+ const result = (0, lodash_1.assign)({ orgOnly, meta, key, defaultValue }, (0, lodash_1.pick)(configVar, [
331
356
  "stableKey",
332
357
  "description",
333
- "defaultValue",
334
358
  "dataType",
335
359
  "pickList",
336
360
  "timeZone",
@@ -349,7 +373,8 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
349
373
  }
350
374
  if ((0, types_1.isDataSourceReferenceConfigVar)(configVar)) {
351
375
  const { ref, inputs } = convertComponentReference(configVar.dataSource, componentRegistry);
352
- result.dataType = configVar.dataSourceType;
376
+ result.dataType =
377
+ componentRegistry[ref.component.key]["dataSources"][ref.key]["dataSourceType"];
353
378
  result.dataSource = ref;
354
379
  result.inputs = inputs;
355
380
  }
@@ -374,39 +399,20 @@ const flowFunctionKey = (flowName, functionName) => {
374
399
  return `${flowKey}_${functionName}`;
375
400
  };
376
401
  const convertOnExecution = (onExecution, componentRegistry) => (context, params) => {
402
+ const {
377
403
  // @ts-expect-error _components isn't part of the public API
378
- const { _components } = context, remainingContext = __rest(context, ["_components"]);
404
+ _components } = context, remainingContext = __rest(context, ["_components"]);
379
405
  const invoke = _components
380
406
  .invoke;
381
407
  // Construct the component methods from the component registry
382
408
  const componentMethods = Object.entries(componentRegistry).reduce((accumulator, [registryComponentKey, { key: componentKey, actions, public: isPublic, signature },]) => {
383
- // Create an object to hold the methods for each action
384
- const methods = Object.keys(actions).reduce((methodsAccumulator, actionKey) => {
385
- const action = actions[actionKey];
409
+ const componentActions = Object.entries(actions).reduce((actionsAccumulator, [actionKey, action]) => {
386
410
  // Define the method to be called for the action
387
- methodsAccumulator[actionKey] = (values) => __awaiter(void 0, void 0, void 0, function* () {
411
+ const invokeAction = (values) => __awaiter(void 0, void 0, void 0, function* () {
388
412
  // Transform the input values based on the action's inputs
389
413
  const transformedValues = Object.entries(values).reduce((transformedAccumulator, [inputKey, inputValue]) => {
390
414
  const { collection } = action.inputs[inputKey];
391
- if (collection === "keyvaluelist" &&
392
- Array.isArray(inputValue)) {
393
- transformedAccumulator[inputKey] = inputValue.reduce((acc, { key, value }) => {
394
- return [...acc, { key, value }];
395
- }, []);
396
- return transformedAccumulator;
397
- }
398
- // Transform key-value list inputs
399
- if (collection === "keyvaluelist" &&
400
- Object.keys(inputValue).length) {
401
- transformedAccumulator[inputKey] = Object.entries(inputValue).map(([keyItem, valueItem]) => ({
402
- key: keyItem,
403
- value: valueItem,
404
- }));
405
- }
406
- else {
407
- transformedAccumulator[inputKey] = inputValue;
408
- }
409
- return transformedAccumulator;
415
+ return Object.assign(Object.assign({}, transformedAccumulator), { [inputKey]: convertInputValue(inputValue, collection) });
410
416
  }, {});
411
417
  // Invoke the action with the transformed values
412
418
  return invoke({
@@ -418,11 +424,9 @@ const convertOnExecution = (onExecution, componentRegistry) => (context, params)
418
424
  key: actionKey,
419
425
  }, context, transformedValues);
420
426
  });
421
- return methodsAccumulator;
427
+ return Object.assign(Object.assign({}, actionsAccumulator), { [actionKey]: invokeAction });
422
428
  }, {});
423
- // Add the methods to the accumulator under the registry component key
424
- accumulator[registryComponentKey] = methods;
425
- return accumulator;
429
+ return Object.assign(Object.assign({}, accumulator), { [registryComponentKey]: componentActions });
426
430
  }, {});
427
431
  return onExecution(Object.assign(Object.assign({}, remainingContext), { components: componentMethods }), params);
428
432
  };
@@ -477,7 +481,7 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
477
481
  if (!(0, types_1.isConnectionDefinitionConfigVar)(configVar)) {
478
482
  return result;
479
483
  }
480
- const convertedInputs = Object.entries(configVar.inputs).map(([key, value]) => (0, convert_1.convertInput)(key, value));
484
+ const convertedInputs = Object.entries(configVar.inputs).map(([key, value]) => (0, convertComponent_1.convertInput)(key, value));
481
485
  const connection = (0, lodash_1.pick)(configVar, ["oauth2Type", "iconPath"]);
482
486
  return [
483
487
  ...result,
@@ -7,6 +7,7 @@ export declare type ComponentReference = {
7
7
  };
8
8
  key: string;
9
9
  template?: string;
10
+ onPremiseConnectionConfig?: string;
10
11
  } | {
11
12
  component: {
12
13
  key: string;
@@ -15,6 +16,7 @@ export declare type ComponentReference = {
15
16
  };
16
17
  key: string;
17
18
  template?: string;
19
+ onPremiseConnectionConfig?: string;
18
20
  };
19
21
  export declare type Input = {
20
22
  name?: string | Input;