@constructor-io/constructorio-connect-cli 1.15.1 → 1.15.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.
package/bin/dev.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  void (async () => {
4
4
  const { config } = await import("dotenv");
5
- config();
5
+ config({ quiet: true });
6
6
 
7
7
  const oclif = await import("@oclif/core");
8
8
 
package/bin/run.js CHANGED
@@ -5,6 +5,6 @@ void (async () => {
5
5
  const { config } = await import("dotenv");
6
6
  const path = await import("path");
7
7
 
8
- config({ path: path.join(process.cwd(), ".env") });
8
+ config({ quiet: true, path: path.join(process.cwd(), ".env") });
9
9
  await oclif.execute({ dir: __dirname });
10
10
  })();
@@ -53,7 +53,7 @@ jobs:
53
53
  - name: Setup node
54
54
  uses: actions/setup-node@v4
55
55
  with:
56
- node-version: "18.18.0"
56
+ node-version: "22.16.0"
57
57
 
58
58
  - name: Install dependencies
59
59
  run: npm ci
@@ -13,11 +13,6 @@ jobs:
13
13
  check:
14
14
  name: Run tests
15
15
  runs-on: ubuntu-latest
16
-
17
- strategy:
18
- matrix:
19
- node: ["20.18.0"]
20
-
21
16
  steps:
22
17
  - uses: actions/checkout@v3
23
18
 
@@ -28,9 +23,9 @@ jobs:
28
23
  run: echo "Missing CONNECT_AUTH_TOKEN secret" && exit 1
29
24
 
30
25
  - name: Setup node
31
- uses: actions/setup-node@v2
26
+ uses: actions/setup-node@v4
32
27
  with:
33
- node-version: ${{ matrix.node }}
28
+ node-version: "22.16.0"
34
29
 
35
30
  - name: Install dependencies
36
31
  run: npm ci
@@ -25,6 +25,8 @@ export default defineConfig([
25
25
  rules: {
26
26
  "@stylistic/indent": ["error", 2],
27
27
  "@stylistic/quotes": ["error", "double"],
28
+ "@stylistic/quote-props": ["error", "as-needed"],
29
+ "@stylistic/comma-dangle": ["error", "always-multiline"],
28
30
  },
29
31
  },
30
32
  ]);
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { config } from "dotenv";
6
- config();
6
+ config({ quiet: true });
7
7
 
8
8
  import { getConnections } from "@constructor-io/constructorio-connect-cli";
9
9
 
@@ -3,6 +3,6 @@
3
3
  */
4
4
 
5
5
  import { config } from "dotenv";
6
- config();
6
+ config({ quiet: true });
7
7
 
8
8
  process.env.TEST = "true";
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/customer/config.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAIlE;;;;;GAKG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAsC/D;AAED;;;GAGG;AACH,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAyCnF;AA8HD,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,oBAAoB,CAAC;CAC3C"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/customer/config.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAIlE;;;;;GAKG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAsC/D;AAED;;;GAGG;AACH,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,gBAAgB,CAAC,CA4CnF;AA+HD,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,oBAAoB,CAAC;CAC3C"}
@@ -100,22 +100,23 @@ async function getRepositoryConnectionsAndConfig() {
100
100
  };
101
101
  }
102
102
  catch (error) {
103
- if (hasUnexpectedToken(error)) {
104
- return handleUnexpectedTokenError(error, connectionsStr, fileContent);
105
- }
106
- else {
107
- (0, print_warnings_1.printExecutionWarnings)({
108
- warnings: [
109
- {
110
- type: "Config",
111
- critical: true,
112
- message: `Failed to parse the connections object in connectrc.js. Are you running a custom setup?`,
113
- },
114
- ],
115
- showDocsLink: false,
116
- });
117
- return { fileContent, existingConnections: {} };
103
+ // If the error is a parsing object error and the connections object does not use custom setups
104
+ // (ie: include process.env), it means that the connections object is not valid JSON, so we need to
105
+ // see whether the parse error is due to a quotation mark in the property names
106
+ if (hasParseObjectError(error) && !connectionsStr.includes("process.env")) {
107
+ return handleParseObjectError(error, connectionsStr, fileContent);
118
108
  }
109
+ (0, print_warnings_1.printExecutionWarnings)({
110
+ warnings: [
111
+ {
112
+ type: "Config",
113
+ critical: true,
114
+ message: `Failed to parse the connections object in connectrc.js. Are you running a custom setup?`,
115
+ },
116
+ ],
117
+ showDocsLink: false,
118
+ });
119
+ return { fileContent, existingConnections: {} };
119
120
  }
120
121
  }
121
122
  /**
@@ -161,29 +162,29 @@ function isEmptyFileContent(fileContent, configPath) {
161
162
  * @returns true if the connections object is found in the connectrc.js file
162
163
  */
163
164
  function hasConfigMatch(configMatch) {
164
- if (!configMatch) {
165
- (0, print_warnings_1.printExecutionWarnings)({
166
- warnings: [
167
- {
168
- type: "Config",
169
- critical: true,
170
- message: "Could not find the `connections` variable in connectrc.js to keep your connections up to date. Are you running a custom setup?",
171
- },
172
- ],
173
- showDocsLink: false,
174
- });
175
- return false;
165
+ if (configMatch) {
166
+ return true;
176
167
  }
177
- return true;
168
+ (0, print_warnings_1.printExecutionWarnings)({
169
+ warnings: [
170
+ {
171
+ type: "Config",
172
+ critical: true,
173
+ message: "Could not find the `connections` variable in connectrc.js to keep your connections up to date. Are you running a custom setup?",
174
+ },
175
+ ],
176
+ showDocsLink: false,
177
+ });
178
+ return false;
178
179
  }
179
180
  /**
180
- * Checks if the error is an unexpected token error
181
+ * Checks if the error is a parsing object error
181
182
  * @param error The error that is thrown when getting connections from connectrc.js
182
- * @returns true if the error is an unexpected token error
183
+ * @returns true if the error is a parsing object error
183
184
  */
184
- function hasUnexpectedToken(error) {
185
+ function hasParseObjectError(error) {
185
186
  return (error instanceof SyntaxError &&
186
- error.message.includes("Unexpected token") &&
187
+ error.message.includes("Expected property name") &&
187
188
  error.message.includes("in JSON at position"));
188
189
  }
189
190
  /**
@@ -194,7 +195,7 @@ function hasUnexpectedToken(error) {
194
195
  * @param fileContent The content of connectrc.js
195
196
  * @returns The connections object and the content of connectrc.js
196
197
  */
197
- function handleUnexpectedTokenError(_error, connectionsStr, fileContent) {
198
+ function handleParseObjectError(_error, connectionsStr, fileContent) {
198
199
  const QuotedConnectionStr = addQuotationMarksToProperties(connectionsStr);
199
200
  if (connectionsStr !== QuotedConnectionStr) {
200
201
  return {
@@ -202,21 +203,19 @@ function handleUnexpectedTokenError(_error, connectionsStr, fileContent) {
202
203
  existingConnections: JSON.parse(QuotedConnectionStr),
203
204
  };
204
205
  }
205
- else {
206
- (0, print_warnings_1.printExecutionWarnings)({
207
- warnings: [
208
- {
209
- type: "Config",
210
- critical: true,
211
- message: `Unable to parse the connections object. Please make sure that the config
206
+ (0, print_warnings_1.printExecutionWarnings)({
207
+ warnings: [
208
+ {
209
+ type: "Config",
210
+ critical: true,
211
+ message: `Unable to parse the connections object. Please make sure that the config
212
212
  file is defined as it was previously generated in the repo, as running custom setups to
213
213
  map your connections isn't supported when automatically updating those.`,
214
- },
215
- ],
216
- showDocsLink: false,
217
- });
218
- return { fileContent, existingConnections: {} };
219
- }
214
+ },
215
+ ],
216
+ showDocsLink: false,
217
+ });
218
+ return { fileContent, existingConnections: {} };
220
219
  }
221
220
  /**
222
221
  * Adds quotation marks to all properties in the {@link PartialConnection} make it JSON parsable
@@ -7,7 +7,7 @@
7
7
  * @param type string The type of fixture
8
8
  * @param name string The name/path of the fixture
9
9
  * @param dataOverride string The data to override in the fixture
10
- * @returns Record<string, unknown> The fixture data
10
+ * @returns Record<string, unknown> or Array<Record<string, unknown>> The fixture data
11
11
  */
12
- export declare const buildFixture: (type: string, name: string, dataOverride?: Record<string, unknown>) => never;
12
+ export declare const buildFixture: (type: string, name: string, dataOverride?: Record<string, unknown>) => never[];
13
13
  //# sourceMappingURL=build-fixture.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-fixture.d.ts","sourceRoot":"","sources":["../../src/functions/build-fixture.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,MAAM,EACZ,MAAM,MAAM,EACZ,eAAc,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,UAK3C,CAAC"}
1
+ {"version":3,"file":"build-fixture.d.ts","sourceRoot":"","sources":["../../src/functions/build-fixture.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,MAAM,EACZ,MAAM,MAAM,EACZ,eAAc,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,YAW3C,CAAC"}
@@ -16,10 +16,15 @@ const file_loaders_1 = require("../helpers/file-loaders");
16
16
  * @param type string The type of fixture
17
17
  * @param name string The name/path of the fixture
18
18
  * @param dataOverride string The data to override in the fixture
19
- * @returns Record<string, unknown> The fixture data
19
+ * @returns Record<string, unknown> or Array<Record<string, unknown>> The fixture data
20
20
  */
21
21
  const buildFixture = (type, name, dataOverride = {}) => {
22
22
  const data = (0, file_loaders_1.getCatalogFixture)(path_1.default.join(type, name));
23
+ if (Array.isArray(data)) {
24
+ return data.map((item) => {
25
+ return (0, remeda_1.mergeDeep)(item, dataOverride);
26
+ });
27
+ }
23
28
  return (0, remeda_1.mergeDeep)(data, dataOverride);
24
29
  };
25
30
  exports.buildFixture = buildFixture;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Adds rules to the eslint config file and then executes npm run lint
3
+ */
4
+ export declare function lintConfigFile(): Promise<void>;
5
+ /**
6
+ * Adds rules to eslint.config.js file
7
+ * @param rules Array of strings of rules, where the rule name within the string is in single quotes
8
+ * ie: [`'@stylistic/js/quote-props': ['error', 'as-needed']`],
9
+ * where '@stylistic/js/quote-props' is in single quotes
10
+ */
11
+ export declare function addRuleToConfig(rules: string[]): Promise<void>;
12
+ //# sourceMappingURL=lint-config-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint-config-file.d.ts","sourceRoot":"","sources":["../../src/helpers/lint-config-file.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAsB,cAAc,kBAQnC;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,iBA2BpD"}
@@ -0,0 +1,78 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.lintConfigFile = lintConfigFile;
37
+ exports.addRuleToConfig = addRuleToConfig;
38
+ const child_process_1 = require("child_process");
39
+ const fs = __importStar(require("fs/promises"));
40
+ const path_1 = require("../customer/path");
41
+ /**
42
+ * Adds rules to the eslint config file and then executes npm run lint
43
+ */
44
+ async function lintConfigFile() {
45
+ await addRuleToConfig([
46
+ `'@stylistic/js/quote-props': ['error', 'as-needed']`,
47
+ `'@stylistic/js/comma-dangle': ['error', 'always-multiline']`,
48
+ ]);
49
+ const repoPath = (0, path_1.getCustomerOSSpecificPath)("");
50
+ (0, child_process_1.execSync)(`(cd ${repoPath} && eslint . --fix)`);
51
+ }
52
+ /**
53
+ * Adds rules to eslint.config.js file
54
+ * @param rules Array of strings of rules, where the rule name within the string is in single quotes
55
+ * ie: [`'@stylistic/js/quote-props': ['error', 'as-needed']`],
56
+ * where '@stylistic/js/quote-props' is in single quotes
57
+ */
58
+ async function addRuleToConfig(rules) {
59
+ const eslintConfigPath = (0, path_1.getCustomerOSSpecificPath)("eslint.config.js");
60
+ const eslintConfig = await fs.readFile(eslintConfigPath, "utf-8");
61
+ const missingRules = rules.filter((rule) => {
62
+ // Extract rule names (part between single quotes, eg: "@stylistic/js/quote-props")
63
+ // to check for existence
64
+ const ruleNameMatch = rule.match(/^'([^']+)'/);
65
+ // If we can't extract rule name, don't add it to eslint
66
+ if (!ruleNameMatch)
67
+ return false;
68
+ const ruleName = ruleNameMatch[1];
69
+ return !eslintConfig.includes(ruleName);
70
+ });
71
+ if (missingRules.length === 0) {
72
+ return;
73
+ }
74
+ // Add all missing rules
75
+ const rulesString = missingRules.map((rule) => `${rule},`).join("\n ");
76
+ const updatedConfig = eslintConfig.replace(/(rules:\s*\{\s*)/, `$1${rulesString}\n `);
77
+ await fs.writeFile(eslintConfigPath, updatedConfig, "utf-8");
78
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"refresh-connections-list.d.ts","sourceRoot":"","sources":["../../src/helpers/refresh-connections-list.ts"],"names":[],"mappings":"AAcA,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAY5D"}
1
+ {"version":3,"file":"refresh-connections-list.d.ts","sourceRoot":"","sources":["../../src/helpers/refresh-connections-list.ts"],"names":[],"mappings":"AAeA,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAa5D"}
@@ -37,10 +37,11 @@ exports.refreshConnectionsList = refreshConnectionsList;
37
37
  const fs = __importStar(require("fs/promises"));
38
38
  const core_1 = require("@oclif/core");
39
39
  const config_1 = require("../customer/config");
40
+ const path_1 = require("../customer/path");
40
41
  const get_connections_request_1 = require("../http/get-connections-request");
41
42
  const render_prompt_1 = require("../prompt-data/render-prompt");
42
- const path_1 = require("../customer/path");
43
43
  const build_config_file_1 = require("./build-config-file");
44
+ const lint_config_file_1 = require("./lint-config-file");
44
45
  const should_update_connections_list_1 = require("./should-update-connections-list");
45
46
  const ux_action_1 = require("./ux-action");
46
47
  async function refreshConnectionsList() {
@@ -50,6 +51,7 @@ async function refreshConnectionsList() {
50
51
  return;
51
52
  }
52
53
  await updateConfigFile();
54
+ await (0, lint_config_file_1.lintConfigFile)();
53
55
  }
54
56
  catch (error) {
55
57
  core_1.ux.stdout(`Error refreshing connections list: ${error.message}`);
@@ -70,19 +72,15 @@ async function promptForUpdate() {
70
72
  });
71
73
  }
72
74
  async function checkConfigFileState() {
73
- const formattedConnections = await fetchNewConnections();
75
+ const newConnections = await fetchNewConnections();
74
76
  const { fileContent, existingConnections } = await (0, config_1.getRepositoryConnectionsAndConfig)();
75
77
  if (!fileContent) {
76
78
  return false;
77
79
  }
78
- if (!(0, should_update_connections_list_1.shouldUpdateConnectionList)(existingConnections, formattedConnections)) {
79
- return false;
80
- }
81
- const update = await promptForUpdate();
82
- if (!update) {
80
+ if (!(0, should_update_connections_list_1.shouldUpdateConnectionList)(existingConnections, newConnections)) {
83
81
  return false;
84
82
  }
85
- return true;
83
+ return await promptForUpdate();
86
84
  }
87
85
  async function updateConfigFile() {
88
86
  const formattedConnections = await fetchNewConnections();
@@ -94,9 +92,7 @@ async function updateConfigFile() {
94
92
  await (0, ux_action_1.uxAction)("Updating connectrc.js", async () => {
95
93
  const updatedContent = fileContent.replace(
96
94
  // Match the connections object in connectrc.js
97
- /const\s+connections\s*=\s*({[\s\S]*?});/,
98
- // Replace the connections object with the new formatted connections
99
- `const connections = ${JSON.stringify(formattedConnections, null, 2)};`);
95
+ /const\s+connections\s*=\s*({[\s\S]*?});/, `const connections = ${JSON.stringify(formattedConnections, null, 2)};`);
100
96
  await fs.writeFile(rcPath, updatedContent, "utf-8");
101
97
  })();
102
98
  core_1.ux.stdout("🎉 Successfully updated connections in connectrc.js");
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const _default: "1.15.1";
1
+ declare const _default: "1.15.3";
2
2
  export default _default;
3
3
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.15.1';
3
+ exports.default = '1.15.3';
@@ -199,5 +199,5 @@
199
199
  ]
200
200
  }
201
201
  },
202
- "version": "1.15.1"
202
+ "version": "1.15.3"
203
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-connect-cli",
3
- "version": "1.15.1",
3
+ "version": "1.15.3",
4
4
  "description": "CLI tool to enable users to interface with the Constructor Connect Ecosystem",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -67,7 +67,7 @@
67
67
  "axios": "^1.6.8",
68
68
  "axios-retry": "^4.4.1",
69
69
  "cli-highlight": "^2.1.11",
70
- "dotenv": "^16.4.5",
70
+ "dotenv": "^17.0.1",
71
71
  "fs-extra": "^11.2.0",
72
72
  "json-stringify-pretty-compact": "^3.0.0",
73
73
  "kleur": "^4.1.5",