@constructor-io/constructorio-connect-cli 1.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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +184 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/dev.js +16 -0
  5. package/bin/run.cmd +3 -0
  6. package/bin/run.js +10 -0
  7. package/boilerplate-repo/.env.example +1 -0
  8. package/boilerplate-repo/.eslintrc.json +11 -0
  9. package/boilerplate-repo/.vscode/extensions.json +5 -0
  10. package/boilerplate-repo/.vscode/launch.json +13 -0
  11. package/boilerplate-repo/.vscode/tasks.json +20 -0
  12. package/boilerplate-repo/LICENSE +21 -0
  13. package/boilerplate-repo/README.md +650 -0
  14. package/boilerplate-repo/connectrc.js +7 -0
  15. package/boilerplate-repo/package.json +21 -0
  16. package/boilerplate-repo/src/fixtures/item/item.json +39 -0
  17. package/boilerplate-repo/src/fixtures/item_group/item_group.json +22 -0
  18. package/boilerplate-repo/src/fixtures/mapping/mapping.json +26 -0
  19. package/boilerplate-repo/src/fixtures/variation/variation.json +11 -0
  20. package/boilerplate-repo/src/templates/grouping/grouping.jsonata +37 -0
  21. package/boilerplate-repo/src/templates/helpers.jsonata +3 -0
  22. package/boilerplate-repo/src/templates/item/item.jsonata +26 -0
  23. package/boilerplate-repo/src/templates/item_group/item_group.jsonata +4 -0
  24. package/boilerplate-repo/src/templates/mapping/mapping.jsonata +34 -0
  25. package/boilerplate-repo/src/templates/variation/variation.jsonata +26 -0
  26. package/dist/commands/deploy.d.ts +10 -0
  27. package/dist/commands/deploy.d.ts.map +1 -0
  28. package/dist/commands/deploy.js +64 -0
  29. package/dist/commands/execute.d.ts +35 -0
  30. package/dist/commands/execute.d.ts.map +1 -0
  31. package/dist/commands/execute.js +145 -0
  32. package/dist/commands/init.d.ts +18 -0
  33. package/dist/commands/init.d.ts.map +1 -0
  34. package/dist/commands/init.js +172 -0
  35. package/dist/customer/config.d.ts +6 -0
  36. package/dist/customer/config.d.ts.map +1 -0
  37. package/dist/customer/config.js +40 -0
  38. package/dist/customer/get-connect-token.d.ts +15 -0
  39. package/dist/customer/get-connect-token.d.ts.map +1 -0
  40. package/dist/customer/get-connect-token.js +69 -0
  41. package/dist/customer/path.d.ts +26 -0
  42. package/dist/customer/path.d.ts.map +1 -0
  43. package/dist/customer/path.js +48 -0
  44. package/dist/customer/template-source-code.d.ts +12 -0
  45. package/dist/customer/template-source-code.d.ts.map +1 -0
  46. package/dist/customer/template-source-code.js +42 -0
  47. package/dist/helpers/build-config-file.d.ts +13 -0
  48. package/dist/helpers/build-config-file.d.ts.map +1 -0
  49. package/dist/helpers/build-config-file.js +62 -0
  50. package/dist/helpers/file-loaders.d.ts +19 -0
  51. package/dist/helpers/file-loaders.d.ts.map +1 -0
  52. package/dist/helpers/file-loaders.js +45 -0
  53. package/dist/helpers/find-deep-files.d.ts +7 -0
  54. package/dist/helpers/find-deep-files.d.ts.map +1 -0
  55. package/dist/helpers/find-deep-files.js +27 -0
  56. package/dist/helpers/generate-command-input.d.ts +19 -0
  57. package/dist/helpers/generate-command-input.d.ts.map +1 -0
  58. package/dist/helpers/generate-command-input.js +51 -0
  59. package/dist/helpers/is-git-repo-initialized.d.ts +5 -0
  60. package/dist/helpers/is-git-repo-initialized.d.ts.map +1 -0
  61. package/dist/helpers/is-git-repo-initialized.js +24 -0
  62. package/dist/helpers/ux-action.d.ts +2 -0
  63. package/dist/helpers/ux-action.d.ts.map +1 -0
  64. package/dist/helpers/ux-action.js +31 -0
  65. package/dist/http/deploy-request.d.ts +16 -0
  66. package/dist/http/deploy-request.d.ts.map +1 -0
  67. package/dist/http/deploy-request.js +45 -0
  68. package/dist/http/execute-templates-request.d.ts +10 -0
  69. package/dist/http/execute-templates-request.d.ts.map +1 -0
  70. package/dist/http/execute-templates-request.js +28 -0
  71. package/dist/http/get-connections-request.d.ts +18 -0
  72. package/dist/http/get-connections-request.d.ts.map +1 -0
  73. package/dist/http/get-connections-request.js +24 -0
  74. package/dist/http/http-client.d.ts +6 -0
  75. package/dist/http/http-client.d.ts.map +1 -0
  76. package/dist/http/http-client.js +57 -0
  77. package/dist/index.d.ts +2 -0
  78. package/dist/index.d.ts.map +1 -0
  79. package/dist/index.js +5 -0
  80. package/dist/prompt-data/filter-connections-by-template.d.ts +4 -0
  81. package/dist/prompt-data/filter-connections-by-template.d.ts.map +1 -0
  82. package/dist/prompt-data/filter-connections-by-template.js +30 -0
  83. package/dist/prompt-data/get-candidate-fixtures.d.ts +3 -0
  84. package/dist/prompt-data/get-candidate-fixtures.d.ts.map +1 -0
  85. package/dist/prompt-data/get-candidate-fixtures.js +49 -0
  86. package/dist/prompt-data/get-external-data-files.d.ts +3 -0
  87. package/dist/prompt-data/get-external-data-files.d.ts.map +1 -0
  88. package/dist/prompt-data/get-external-data-files.js +28 -0
  89. package/dist/prompt-data/get-template-files.d.ts +7 -0
  90. package/dist/prompt-data/get-template-files.d.ts.map +1 -0
  91. package/dist/prompt-data/get-template-files.js +50 -0
  92. package/dist/prompt-data/render-prompt.d.ts +9 -0
  93. package/dist/prompt-data/render-prompt.d.ts.map +1 -0
  94. package/dist/prompt-data/render-prompt.js +16 -0
  95. package/dist/rendering/render-repeat-input.d.ts +14 -0
  96. package/dist/rendering/render-repeat-input.d.ts.map +1 -0
  97. package/dist/rendering/render-repeat-input.js +25 -0
  98. package/dist/rendering/render-template-result.d.ts +2 -0
  99. package/dist/rendering/render-template-result.d.ts.map +1 -0
  100. package/dist/rendering/render-template-result.js +60 -0
  101. package/dist/rendering/render-tip.d.ts +6 -0
  102. package/dist/rendering/render-tip.d.ts.map +1 -0
  103. package/dist/rendering/render-tip.js +22 -0
  104. package/dist/types.d.ts +40 -0
  105. package/dist/types.d.ts.map +1 -0
  106. package/dist/types.js +2 -0
  107. package/oclif.manifest.json +129 -0
  108. package/package.json +98 -0
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Generates a string representing a command that can be directly pasted
3
+ * into the terminal from the provided inputs describing the command.
4
+ * This is useful for providing in-command suggestions to the user for what they may
5
+ * want to run next.
6
+ *
7
+ * @param commandName Name of the command that should be printed (e.g. "execute" or "init").
8
+ * @param args The positional arguments to be passed to the command. Must be in order.
9
+ * @param inputFlags A map of flag names to the values that should be printed in the command.
10
+ * @returns A string representing a ready to execute command.
11
+ */
12
+ export declare function generateCommandInput({ commandName, args, inputFlags }: Args): string;
13
+ interface Args {
14
+ commandName: string;
15
+ args?: string[];
16
+ inputFlags?: Record<string, string>;
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=generate-command-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-command-input.d.ts","sourceRoot":"","sources":["../../src/helpers/generate-command-input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,IAAI,UAW3E;AAgCD,UAAU,IAAI;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCommandInput = void 0;
4
+ /**
5
+ * Generates a string representing a command that can be directly pasted
6
+ * into the terminal from the provided inputs describing the command.
7
+ * This is useful for providing in-command suggestions to the user for what they may
8
+ * want to run next.
9
+ *
10
+ * @param commandName Name of the command that should be printed (e.g. "execute" or "init").
11
+ * @param args The positional arguments to be passed to the command. Must be in order.
12
+ * @param inputFlags A map of flag names to the values that should be printed in the command.
13
+ * @returns A string representing a ready to execute command.
14
+ */
15
+ function generateCommandInput({ commandName, args, inputFlags }) {
16
+ const flags = inputFlags ? renderInputFlags(inputFlags) : "";
17
+ return [
18
+ "npm run ", //
19
+ commandName,
20
+ renderDoubleDashes(commandName, !!flags),
21
+ renderArgs(args),
22
+ flags,
23
+ "\n",
24
+ ].join("");
25
+ }
26
+ exports.generateCommandInput = generateCommandInput;
27
+ /**
28
+ * Sometimes, when executing a command via npm it needs to have double dashes (--) in front of the flags.
29
+ * This function will add the double dashes, if needed, to the command.
30
+ */
31
+ function renderDoubleDashes(commandName, hasFlags) {
32
+ // If no flags are provided, we shouldn't add double dashes because there are no options to render.
33
+ if (!hasFlags) {
34
+ return "";
35
+ }
36
+ switch (commandName) {
37
+ case "execute":
38
+ return " --";
39
+ default:
40
+ return "";
41
+ }
42
+ }
43
+ function renderArgs(args) {
44
+ return args?.length ? ` ${args.join(" ")}` : "";
45
+ }
46
+ function renderInputFlags(input) {
47
+ return Object.keys(input).reduce((command, flag) => {
48
+ command += ` \\\n--${flag}=${input[flag]}`;
49
+ return command;
50
+ }, "");
51
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns true if a git repo is initialized in this folder and false otherwise.
3
+ */
4
+ export declare function isGitRepoInitialized(): boolean;
5
+ //# sourceMappingURL=is-git-repo-initialized.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-git-repo-initialized.d.ts","sourceRoot":"","sources":["../../src/helpers/is-git-repo-initialized.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAiB9C"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isGitRepoInitialized = void 0;
4
+ const child_process_1 = require("child_process");
5
+ /**
6
+ * Returns true if a git repo is initialized in this folder and false otherwise.
7
+ */
8
+ function isGitRepoInitialized() {
9
+ try {
10
+ const output = (0, child_process_1.execSync)(
11
+ //
12
+ "git rev-parse --is-inside-work-tree", {
13
+ // Don't print the result of this command to the console
14
+ stdio: "pipe",
15
+ })
16
+ .toString()
17
+ ?.trim();
18
+ return output === "true";
19
+ }
20
+ catch (_error) {
21
+ return false;
22
+ }
23
+ }
24
+ exports.isGitRepoInitialized = isGitRepoInitialized;
@@ -0,0 +1,2 @@
1
+ export declare function uxAction<T extends (...args: any[]) => any>(title: string, func: T): (...args: Parameters<T>) => ReturnType<T>;
2
+ //# sourceMappingURL=ux-action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ux-action.d.ts","sourceRoot":"","sources":["../../src/helpers/ux-action.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,CAAC,aAEmB,WAAW,CAAC,CAAC,KAAG,WAAW,CAAC,CAAC,CAwBxD"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uxAction = void 0;
4
+ const core_1 = require("@oclif/core");
5
+ function uxAction(title, func) {
6
+ return function (...args) {
7
+ core_1.ux.action.start(title);
8
+ let result;
9
+ try {
10
+ result = func(...args);
11
+ }
12
+ catch (e) {
13
+ core_1.ux.action.stop("❌");
14
+ throw e;
15
+ }
16
+ if (result?.then) {
17
+ result
18
+ .then(() => {
19
+ core_1.ux.action.stop("✅");
20
+ })
21
+ .catch(() => {
22
+ core_1.ux.action.stop("❌");
23
+ });
24
+ }
25
+ else {
26
+ core_1.ux.action.stop("✅");
27
+ }
28
+ return result;
29
+ };
30
+ }
31
+ exports.uxAction = uxAction;
@@ -0,0 +1,16 @@
1
+ import { type Config } from "../types";
2
+ /**
3
+ * Calls the /templates endpoint of the Constructor API to deploy templates.
4
+ */
5
+ export declare function performDeploy({ environment, config, templates, helpers, }: DeployArgs): Promise<void>;
6
+ interface DeployArgs {
7
+ environment: string;
8
+ config: Config;
9
+ templates: Array<{
10
+ connectionIds: string[];
11
+ sourceCode: Record<string, string | undefined>;
12
+ }>;
13
+ helpers?: string;
14
+ }
15
+ export {};
16
+ //# sourceMappingURL=deploy-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy-request.d.ts","sourceRoot":"","sources":["../../src/http/deploy-request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAIvC;;GAEG;AACH,wBAAsB,aAAa,CAAC,EAClC,WAAW,EACX,MAAM,EACN,SAAS,EACT,OAAO,GACR,EAAE,UAAU,iBAyCZ;AAED,UAAU,UAAU;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,KAAK,CAAC;QACf,aAAa,EAAE,MAAM,EAAE,CAAC;QACxB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;KAChD,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.performDeploy = void 0;
4
+ /* eslint-disable @typescript-eslint/no-base-to-string */
5
+ const axios_1 = require("axios");
6
+ const errors_1 = require("@oclif/core/lib/errors");
7
+ const core_1 = require("@oclif/core");
8
+ const http_client_1 = require("./http-client");
9
+ /**
10
+ * Calls the /templates endpoint of the Constructor API to deploy templates.
11
+ */
12
+ async function performDeploy({ environment, config, templates, helpers, }) {
13
+ const client = await (0, http_client_1.getHttpClient)();
14
+ try {
15
+ await client.post(`/templates`, {
16
+ environment,
17
+ config_file: config,
18
+ helpers,
19
+ templates: templates.map(({ connectionIds, sourceCode }) => {
20
+ return {
21
+ connection_ids: connectionIds,
22
+ source_code: sourceCode,
23
+ };
24
+ }),
25
+ });
26
+ }
27
+ catch (error) {
28
+ core_1.ux.action.stop("💥");
29
+ if (!(error instanceof axios_1.AxiosError)) {
30
+ throw error;
31
+ }
32
+ if (error.response?.status === 400 &&
33
+ Array.isArray(error.response?.data?.message)) {
34
+ throw new errors_1.CLIError(`💥 Some validations have failed :(`, {
35
+ suggestions: error.response?.data?.message,
36
+ });
37
+ }
38
+ const responseBody = error.response?.data;
39
+ const logData = responseBody
40
+ ? JSON.stringify(responseBody, null, 2)
41
+ : error;
42
+ throw new errors_1.CLIError(`💥 Received the following error from the Constructor API: \n${logData}}\n`);
43
+ }
44
+ }
45
+ exports.performDeploy = performDeploy;
@@ -0,0 +1,10 @@
1
+ export declare function executeTemplates({ template, helpers, targetData, externalData, connectionId, }: Args): Promise<any>;
2
+ interface Args {
3
+ template: string;
4
+ helpers: string;
5
+ targetData: any;
6
+ externalData: any;
7
+ connectionId: string;
8
+ }
9
+ export {};
10
+ //# sourceMappingURL=execute-templates-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-templates-request.d.ts","sourceRoot":"","sources":["../../src/http/execute-templates-request.ts"],"names":[],"mappings":"AAOA,wBAAsB,gBAAgB,CAAC,EACrC,QAAQ,EACR,OAAO,EACP,UAAU,EACV,YAAY,EACZ,YAAY,GACb,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAuBrB;AAED,UAAU,IAAI;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,GAAG,CAAC;IAChB,YAAY,EAAE,GAAG,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeTemplates = void 0;
4
+ const axios_1 = require("axios");
5
+ const errors_1 = require("@oclif/core/lib/errors");
6
+ const ux_action_1 = require("../helpers/ux-action");
7
+ const http_client_1 = require("./http-client");
8
+ async function executeTemplates({ template, helpers, targetData, externalData, connectionId, }) {
9
+ const client = await (0, http_client_1.getHttpClient)();
10
+ try {
11
+ return await (0, ux_action_1.uxAction)("📟 Executing your template", async () => {
12
+ return (await client.patch("templates/standalone/execute", {
13
+ raw_template: template,
14
+ helpers,
15
+ target_data: targetData,
16
+ external_data: externalData,
17
+ connection_id: connectionId,
18
+ })).data;
19
+ })();
20
+ }
21
+ catch (error) {
22
+ if ((0, axios_1.isAxiosError)(error) && error.response) {
23
+ throw new errors_1.CLIError(`Something went wrong while executing your template: ${JSON.stringify(error.response.data)}`);
24
+ }
25
+ throw error;
26
+ }
27
+ }
28
+ exports.executeTemplates = executeTemplates;
@@ -0,0 +1,18 @@
1
+ export declare function getConnectionsForCompany(): Promise<ConnectionResponseDto[]>;
2
+ export interface ConnectionResponseDto {
3
+ id: string;
4
+ name: string;
5
+ slug: string;
6
+ partner: string;
7
+ environment: string;
8
+ frequent_sync: boolean;
9
+ force: boolean;
10
+ notification_email?: string | null;
11
+ api_key?: string | null;
12
+ section: string;
13
+ ingestion_type?: string | null;
14
+ created_at: string;
15
+ updated_at: string;
16
+ active: boolean;
17
+ }
18
+ //# sourceMappingURL=get-connections-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-connections-request.d.ts","sourceRoot":"","sources":["../../src/http/get-connections-request.ts"],"names":[],"mappings":"AAOA,wBAAsB,wBAAwB,IAAI,OAAO,CACvD,qBAAqB,EAAE,CACxB,CAqBA;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CACjB"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConnectionsForCompany = void 0;
4
+ const axios_1 = require("axios");
5
+ const errors_1 = require("@oclif/core/lib/errors");
6
+ const ux_action_1 = require("../helpers/ux-action");
7
+ const http_client_1 = require("./http-client");
8
+ async function getConnectionsForCompany() {
9
+ const client = await (0, http_client_1.getHttpClient)();
10
+ try {
11
+ const response = await (0, ux_action_1.uxAction)("📡 Fetching your account details", async () => {
12
+ return await client.get("/connections");
13
+ })();
14
+ return response.data.connections;
15
+ }
16
+ catch (error) {
17
+ if ((0, axios_1.isAxiosError)(error) && error.response) {
18
+ throw new errors_1.CLIError("Something went wrong while fetching your company's connections: \n" +
19
+ error.message);
20
+ }
21
+ throw error;
22
+ }
23
+ }
24
+ exports.getConnectionsForCompany = getConnectionsForCompany;
@@ -0,0 +1,6 @@
1
+ import axios from "axios";
2
+ /**
3
+ * @returns An axios instance with the correct base URL and auth token.
4
+ */
5
+ export declare function getHttpClient(): Promise<axios.AxiosInstance>;
6
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/http/http-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAuB,MAAM,OAAO,CAAC;AAI5C;;GAEG;AACH,wBAAsB,aAAa,iCAiClC"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getHttpClient = void 0;
27
+ const errors_1 = require("@oclif/core/lib/errors");
28
+ const axios_1 = __importStar(require("axios"));
29
+ const get_connect_token_1 = require("../customer/get-connect-token");
30
+ /**
31
+ * @returns An axios instance with the correct base URL and auth token.
32
+ */
33
+ async function getHttpClient() {
34
+ const token = await (0, get_connect_token_1.getConnectToken)();
35
+ const baseURL = process.env.HOST ?? "https://connect.cnstrc.com";
36
+ const instance = axios_1.default.create({
37
+ baseURL,
38
+ headers: {
39
+ Authorization: `Bearer ${token}`,
40
+ },
41
+ });
42
+ instance.interceptors.response.use((response) => response, async (error) => {
43
+ if ((0, axios_1.isAxiosError)(error) && error.response) {
44
+ if (error.response.status === 403) {
45
+ throw new errors_1.CLIError("💥 Error while authenticating with the Constructor Connect API. Please check your CONNECT_AUTH_TOKEN environment variable.", {
46
+ suggestions: [
47
+ "Check the Connect Auth token you provided and try again",
48
+ "If you don't have one yet, please reach out over at partners@constructor.io",
49
+ ],
50
+ });
51
+ }
52
+ }
53
+ return await Promise.reject(error);
54
+ });
55
+ return instance;
56
+ }
57
+ exports.getHttpClient = getHttpClient;
@@ -0,0 +1,2 @@
1
+ export { run } from "@oclif/core";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.run = void 0;
4
+ var core_1 = require("@oclif/core");
5
+ Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
@@ -0,0 +1,4 @@
1
+ import { type ConnectionResponseDto } from "../http/get-connections-request";
2
+ import { type PromptChoices } from "../types";
3
+ export declare function filterConnectionsByTemplate(templatePath: string, connections: ConnectionResponseDto[]): Promise<PromptChoices<ConnectionResponseDto>>;
4
+ //# sourceMappingURL=filter-connections-by-template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter-connections-by-template.d.ts","sourceRoot":"","sources":["../../src/prompt-data/filter-connections-by-template.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAsB,2BAA2B,CAC/C,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,qBAAqB,EAAE,GACnC,OAAO,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC,CA4B/C"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.filterConnectionsByTemplate = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const config_1 = require("../customer/config");
9
+ async function filterConnectionsByTemplate(templatePath, connections) {
10
+ const config = await (0, config_1.getRepositoryConfigFile)();
11
+ const fullPath = path_1.default.join("src/templates", templatePath);
12
+ // Find the config mappings that have the template.
13
+ const connectionIds = config.environments.reduce((connectionIds, env) => {
14
+ env.templates.forEach((templateConfig) => {
15
+ const templatePaths = Object.values(templateConfig.paths);
16
+ if (templatePaths.includes(fullPath)) {
17
+ templateConfig.connection_ids.forEach((id) => connectionIds.add(id));
18
+ }
19
+ });
20
+ return connectionIds;
21
+ }, new Set());
22
+ const filteredConnections = connections.filter((c) => connectionIds.has(c.id));
23
+ return filteredConnections.map((c) => {
24
+ return {
25
+ name: c.name,
26
+ value: c,
27
+ };
28
+ });
29
+ }
30
+ exports.filterConnectionsByTemplate = filterConnectionsByTemplate;
@@ -0,0 +1,3 @@
1
+ import { type PromptChoices } from "../types";
2
+ export declare function getCandidateFixtures(templatePath: string): PromptChoices<string>;
3
+ //# sourceMappingURL=get-candidate-fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-candidate-fixtures.d.ts","sourceRoot":"","sources":["../../src/prompt-data/get-candidate-fixtures.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAI9C,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,GACnB,aAAa,CAAC,MAAM,CAAC,CA4CvB"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCandidateFixtures = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const errors_1 = require("@oclif/core/lib/errors");
9
+ const find_deep_files_1 = require("../helpers/find-deep-files");
10
+ const get_template_files_1 = require("./get-template-files");
11
+ function getCandidateFixtures(templatePath) {
12
+ const templateType = templatePath.split("/")[0];
13
+ if (!get_template_files_1.templateTypes.includes(templateType)) {
14
+ throw new errors_1.CLIError(`Invalid template type: ${templateType}`, {
15
+ suggestions: [
16
+ "Check that the template file path is correct",
17
+ "Check that your templates are in the correctly named directory for their type (e.g. 'item.jsonata' in the 'templates/item' directory",
18
+ "Check that you are using a valid template type: " +
19
+ get_template_files_1.templateTypes.join(", "),
20
+ ],
21
+ });
22
+ }
23
+ const fixtureType = templateType === "grouping" ? "variation" : templateType;
24
+ let fixtureFullPaths;
25
+ try {
26
+ fixtureFullPaths = (0, find_deep_files_1.findDeepFiles)(`src/fixtures/${fixtureType}`);
27
+ }
28
+ catch (error) {
29
+ if (error instanceof Error && error.message.includes("ENOENT")) {
30
+ throw new errors_1.CLIError(`Directory for ${fixtureType} fixtures (at src/fixtures/${fixtureType}) does not exist.`, {
31
+ suggestions: [
32
+ `If the ${fixtureType} directory has been deleted, recreate it and add fixtures to it.`,
33
+ `Ensure the ${fixtureType} directory is named correctly`,
34
+ ],
35
+ });
36
+ }
37
+ throw error;
38
+ }
39
+ return fixtureFullPaths
40
+ .filter((fixturePath) => path_1.default.extname(fixturePath) === ".json")
41
+ .map((fixturePath) => {
42
+ const fixtureRelativePath = path_1.default.relative("src/fixtures", fixturePath);
43
+ return {
44
+ name: fixtureRelativePath,
45
+ value: fixtureRelativePath,
46
+ };
47
+ });
48
+ }
49
+ exports.getCandidateFixtures = getCandidateFixtures;
@@ -0,0 +1,3 @@
1
+ import { type PromptChoices } from "../types";
2
+ export declare function getExternalDataFiles(): PromptChoices<string>;
3
+ //# sourceMappingURL=get-external-data-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-external-data-files.d.ts","sourceRoot":"","sources":["../../src/prompt-data/get-external-data-files.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,oBAAoB,IAAI,aAAa,CAAC,MAAM,CAAC,CAkB5D"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getExternalDataFiles = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const find_deep_files_1 = require("../helpers/find-deep-files");
9
+ function getExternalDataFiles() {
10
+ try {
11
+ return (0, find_deep_files_1.findDeepFiles)("src/fixtures/external_data")
12
+ .filter((file) => path_1.default.extname(file) === ".json")
13
+ .map((file) => {
14
+ const relativePath = path_1.default.relative("src/fixtures/external_data", file);
15
+ return {
16
+ name: relativePath,
17
+ value: relativePath,
18
+ };
19
+ });
20
+ }
21
+ catch (error) {
22
+ if (error instanceof Error && error.message.includes("ENOENT")) {
23
+ return [];
24
+ }
25
+ throw error;
26
+ }
27
+ }
28
+ exports.getExternalDataFiles = getExternalDataFiles;
@@ -0,0 +1,7 @@
1
+ import { type PromptChoices } from "../types";
2
+ export declare const templateTypes: string[];
3
+ /**
4
+ * Get a prompt-ready list of template files in the user repository
5
+ */
6
+ export declare function getTemplateFiles(): Promise<PromptChoices<string>>;
7
+ //# sourceMappingURL=get-template-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-template-files.d.ts","sourceRoot":"","sources":["../../src/prompt-data/get-template-files.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,eAAO,MAAM,aAAa,UAMzB,CAAC;AAEF;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAavE"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getTemplateFiles = exports.templateTypes = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const find_deep_files_1 = require("../helpers/find-deep-files");
9
+ exports.templateTypes = [
10
+ "item",
11
+ "variation",
12
+ "item_group",
13
+ "grouping",
14
+ "mapping",
15
+ ];
16
+ /**
17
+ * Get a prompt-ready list of template files in the user repository
18
+ */
19
+ async function getTemplateFiles() {
20
+ let files = [];
21
+ for (const type of exports.templateTypes) {
22
+ const typePath = path_1.default.join("src/templates", type);
23
+ files = files.concat(getTemplatePaths(typePath));
24
+ }
25
+ const filteredFiles = files.filter((file) => file.endsWith(".jsonata") && !file.includes("helpers"));
26
+ return filteredFiles.map((file) => ({
27
+ name: file.replace("src/templates/", ""),
28
+ value: file.replace("src/templates/", ""),
29
+ }));
30
+ }
31
+ exports.getTemplateFiles = getTemplateFiles;
32
+ /**
33
+ * @param typePath The full type path. E.g.
34
+ * - src/templates/item
35
+ * - src/templates/variation
36
+ * @returns A list of template paths for the given type. E.g.
37
+ * - src/templates/item/1.jsonata
38
+ * - src/templates/item/2.jsonata
39
+ */
40
+ function getTemplatePaths(typePath) {
41
+ try {
42
+ return (0, find_deep_files_1.findDeepFiles)(typePath);
43
+ }
44
+ catch (error) {
45
+ if (error instanceof Error && error.message.includes("ENOENT")) {
46
+ return [];
47
+ }
48
+ throw error;
49
+ }
50
+ }
@@ -0,0 +1,9 @@
1
+ import { type PromptChoices } from "../types";
2
+ export declare function renderPrompt<T>({ choices, promptMessage, emptyMessage, }: Args<T>): Promise<T>;
3
+ interface Args<T> {
4
+ choices: PromptChoices<T>;
5
+ promptMessage: string;
6
+ emptyMessage?: string;
7
+ }
8
+ export {};
9
+ //# sourceMappingURL=render-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-prompt.d.ts","sourceRoot":"","sources":["../../src/prompt-data/render-prompt.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAsB,YAAY,CAAC,CAAC,EAAE,EACpC,OAAO,EACP,aAAa,EACb,YAAY,GACb,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAWtB;AAED,UAAU,IAAI,CAAC,CAAC;IACd,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderPrompt = void 0;
4
+ const prompts_1 = require("@inquirer/prompts");
5
+ const errors_1 = require("@oclif/core/lib/errors");
6
+ async function renderPrompt({ choices, promptMessage, emptyMessage, }) {
7
+ switch (choices.length) {
8
+ case 0:
9
+ throw new errors_1.CLIError(emptyMessage ?? `No options found for: ${promptMessage}`);
10
+ case 1:
11
+ return choices[0].value;
12
+ default:
13
+ return await (0, prompts_1.select)({ message: promptMessage, choices });
14
+ }
15
+ }
16
+ exports.renderPrompt = renderPrompt;
@@ -0,0 +1,14 @@
1
+ import { type Command } from "@oclif/core";
2
+ /**
3
+ * Prints the text of the command you would need to put into the terminal in order to replicate
4
+ * the previously executed command, but with awareness of inputs provided during the execution
5
+ * of the command itself (through a select prompt for example).
6
+ *
7
+ * This extra awareness is provided through the `inputFlags` parameter which you can use
8
+ * to specify the specific values of each flag in order to replicate the current command.
9
+ *
10
+ * @param commandName Name of the command that should be printed.
11
+ * @param inputFlags A map of flag names to the values that should be printed in the command.
12
+ */
13
+ export declare function renderRepeatInput(command: Command, inputFlags: Record<string, string>): void;
14
+ //# sourceMappingURL=render-repeat-input.d.ts.map