@constructor-io/constructorio-connect-cli 1.15.2 → 1.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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";
@@ -10,7 +10,9 @@ export declare function getRepositoryConfigFile(): Promise<Config>;
10
10
  * Reads the content of the connectrc.js file and returns the connections object and the content of the file
11
11
  * @returns The connections object and the content of the connectrc.js file in {@link RawConfigContent}
12
12
  */
13
- export declare function getRepositoryConnectionsAndConfig(): Promise<RawConfigContent>;
13
+ export declare function getRepositoryConnectionsAndConfig({ shouldPrintExecutionWarnings, }?: {
14
+ shouldPrintExecutionWarnings?: boolean | undefined;
15
+ }): Promise<RawConfigContent>;
14
16
  interface RawConfigContent {
15
17
  fileContent: string;
16
18
  existingConnections: ConnectionConfigDict;
@@ -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,CAAC,EACtD,4BAAmC,GACpC;;CAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA+CjC;AA+HD,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,oBAAoB,CAAC;CAC3C"}
@@ -80,7 +80,7 @@ pointing to the correct connectrc.js directory.`,
80
80
  * Reads the content of the connectrc.js file and returns the connections object and the content of the file
81
81
  * @returns The connections object and the content of the connectrc.js file in {@link RawConfigContent}
82
82
  */
83
- async function getRepositoryConnectionsAndConfig() {
83
+ async function getRepositoryConnectionsAndConfig({ shouldPrintExecutionWarnings = true, } = {}) {
84
84
  const configPath = (0, path_1.getCustomerOSSpecificPath)("connectrc.js");
85
85
  const fileContent = await readRawConfigFile(configPath);
86
86
  // Get the connections object from the content of the connectrc.js file
@@ -100,10 +100,13 @@ async function getRepositoryConnectionsAndConfig() {
100
100
  };
101
101
  }
102
102
  catch (error) {
103
- if (hasUnexpectedToken(error)) {
104
- return handleUnexpectedTokenError(error, connectionsStr, fileContent);
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);
105
108
  }
106
- else {
109
+ if (shouldPrintExecutionWarnings) {
107
110
  (0, print_warnings_1.printExecutionWarnings)({
108
111
  warnings: [
109
112
  {
@@ -114,8 +117,8 @@ async function getRepositoryConnectionsAndConfig() {
114
117
  ],
115
118
  showDocsLink: false,
116
119
  });
117
- return { fileContent, existingConnections: {} };
118
120
  }
121
+ return { fileContent, existingConnections: {} };
119
122
  }
120
123
  }
121
124
  /**
@@ -161,29 +164,29 @@ function isEmptyFileContent(fileContent, configPath) {
161
164
  * @returns true if the connections object is found in the connectrc.js file
162
165
  */
163
166
  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;
167
+ if (configMatch) {
168
+ return true;
176
169
  }
177
- return true;
170
+ (0, print_warnings_1.printExecutionWarnings)({
171
+ warnings: [
172
+ {
173
+ type: "Config",
174
+ critical: true,
175
+ message: "Could not find the `connections` variable in connectrc.js to keep your connections up to date. Are you running a custom setup?",
176
+ },
177
+ ],
178
+ showDocsLink: false,
179
+ });
180
+ return false;
178
181
  }
179
182
  /**
180
- * Checks if the error is an unexpected token error
183
+ * Checks if the error is a parsing object error
181
184
  * @param error The error that is thrown when getting connections from connectrc.js
182
- * @returns true if the error is an unexpected token error
185
+ * @returns true if the error is a parsing object error
183
186
  */
184
- function hasUnexpectedToken(error) {
187
+ function hasParseObjectError(error) {
185
188
  return (error instanceof SyntaxError &&
186
- error.message.includes("Unexpected token") &&
189
+ error.message.includes("Expected property name") &&
187
190
  error.message.includes("in JSON at position"));
188
191
  }
189
192
  /**
@@ -194,7 +197,7 @@ function hasUnexpectedToken(error) {
194
197
  * @param fileContent The content of connectrc.js
195
198
  * @returns The connections object and the content of connectrc.js
196
199
  */
197
- function handleUnexpectedTokenError(_error, connectionsStr, fileContent) {
200
+ function handleParseObjectError(_error, connectionsStr, fileContent) {
198
201
  const QuotedConnectionStr = addQuotationMarksToProperties(connectionsStr);
199
202
  if (connectionsStr !== QuotedConnectionStr) {
200
203
  return {
@@ -202,21 +205,19 @@ function handleUnexpectedTokenError(_error, connectionsStr, fileContent) {
202
205
  existingConnections: JSON.parse(QuotedConnectionStr),
203
206
  };
204
207
  }
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
208
+ (0, print_warnings_1.printExecutionWarnings)({
209
+ warnings: [
210
+ {
211
+ type: "Config",
212
+ critical: true,
213
+ message: `Unable to parse the connections object. Please make sure that the config
212
214
  file is defined as it was previously generated in the repo, as running custom setups to
213
215
  map your connections isn't supported when automatically updating those.`,
214
- },
215
- ],
216
- showDocsLink: false,
217
- });
218
- return { fileContent, existingConnections: {} };
219
- }
216
+ },
217
+ ],
218
+ showDocsLink: false,
219
+ });
220
+ return { fileContent, existingConnections: {} };
220
221
  }
221
222
  /**
222
223
  * Adds quotation marks to all properties in the {@link PartialConnection} make it JSON parsable
@@ -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":"AAKA;;GAEG;AACH,wBAAsB,cAAc,kBAQnC;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,iBAgCpD"}
@@ -0,0 +1,83 @@
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_1 = require("fs");
40
+ const fs = __importStar(require("fs/promises"));
41
+ const path_1 = require("../customer/path");
42
+ /**
43
+ * Adds rules to the eslint config file and then executes npm run lint
44
+ */
45
+ async function lintConfigFile() {
46
+ await addRuleToConfig([
47
+ `'@stylistic/js/quote-props': ['error', 'as-needed']`,
48
+ `'@stylistic/js/comma-dangle': ['error', 'always-multiline']`,
49
+ ]);
50
+ const repoPath = (0, path_1.getCustomerOSSpecificPath)("");
51
+ (0, child_process_1.execSync)(`(cd ${repoPath} && eslint . --fix)`);
52
+ }
53
+ /**
54
+ * Adds rules to eslint.config.js file
55
+ * @param rules Array of strings of rules, where the rule name within the string is in single quotes
56
+ * ie: [`'@stylistic/js/quote-props': ['error', 'as-needed']`],
57
+ * where '@stylistic/js/quote-props' is in single quotes
58
+ */
59
+ async function addRuleToConfig(rules) {
60
+ // eslint config file should be present as checked in the refresh-connections-list.ts file
61
+ // It will either be eslint.config.js or eslint.config.mjs
62
+ const eslintConfigPath = (0, fs_1.existsSync)("eslint.config.js")
63
+ ? "eslint.config.js"
64
+ : "eslint.config.mjs";
65
+ const eslintConfig = await fs.readFile(eslintConfigPath, "utf-8");
66
+ const missingRules = rules.filter((rule) => {
67
+ // Extract rule names (part between single quotes, eg: "@stylistic/js/quote-props")
68
+ // to check for existence
69
+ const ruleNameMatch = rule.match(/^'([^']+)'/);
70
+ // If we can't extract rule name, don't add it to eslint
71
+ if (!ruleNameMatch)
72
+ return false;
73
+ const ruleName = ruleNameMatch[1];
74
+ return !eslintConfig.includes(ruleName);
75
+ });
76
+ if (missingRules.length === 0) {
77
+ return;
78
+ }
79
+ // Add all missing rules
80
+ const rulesString = missingRules.map((rule) => `${rule},`).join("\n ");
81
+ const updatedConfig = eslintConfig.replace(/(rules:\s*\{\s*)/, `$1${rulesString}\n `);
82
+ await fs.writeFile(eslintConfigPath, updatedConfig, "utf-8");
83
+ }
@@ -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":"AAgBA,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAgB5D"}
@@ -37,12 +37,14 @@ 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");
47
+ const fs_1 = require("fs");
46
48
  async function refreshConnectionsList() {
47
49
  try {
48
50
  const shouldUpdate = await checkConfigFileState();
@@ -50,6 +52,9 @@ async function refreshConnectionsList() {
50
52
  return;
51
53
  }
52
54
  await updateConfigFile();
55
+ if ((0, fs_1.existsSync)("eslint.config.js") || (0, fs_1.existsSync)("eslint.config.mjs")) {
56
+ await (0, lint_config_file_1.lintConfigFile)();
57
+ }
53
58
  }
54
59
  catch (error) {
55
60
  core_1.ux.stdout(`Error refreshing connections list: ${error.message}`);
@@ -70,33 +75,29 @@ async function promptForUpdate() {
70
75
  });
71
76
  }
72
77
  async function checkConfigFileState() {
73
- const formattedConnections = await fetchNewConnections();
78
+ const newConnections = await fetchNewConnections();
74
79
  const { fileContent, existingConnections } = await (0, config_1.getRepositoryConnectionsAndConfig)();
75
80
  if (!fileContent) {
76
81
  return false;
77
82
  }
78
- if (!(0, should_update_connections_list_1.shouldUpdateConnectionList)(existingConnections, formattedConnections)) {
83
+ if (!(0, should_update_connections_list_1.shouldUpdateConnectionList)(existingConnections, newConnections)) {
79
84
  return false;
80
85
  }
81
- const update = await promptForUpdate();
82
- if (!update) {
83
- return false;
84
- }
85
- return true;
86
+ return await promptForUpdate();
86
87
  }
87
88
  async function updateConfigFile() {
88
89
  const formattedConnections = await fetchNewConnections();
89
90
  const rcPath = (0, path_1.getCustomerOSSpecificPath)("connectrc.js");
90
- const { fileContent } = await (0, config_1.getRepositoryConnectionsAndConfig)();
91
+ const { fileContent } = await (0, config_1.getRepositoryConnectionsAndConfig)({
92
+ shouldPrintExecutionWarnings: false,
93
+ });
91
94
  if (!fileContent) {
92
95
  return;
93
96
  }
94
97
  await (0, ux_action_1.uxAction)("Updating connectrc.js", async () => {
95
98
  const updatedContent = fileContent.replace(
96
99
  // 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)};`);
100
+ /const\s+connections\s*=\s*({[\s\S]*?});/, `const connections = ${JSON.stringify(formattedConnections, null, 2)};`);
100
101
  await fs.writeFile(rcPath, updatedContent, "utf-8");
101
102
  })();
102
103
  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.2";
1
+ declare const _default: "1.15.4";
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.2';
3
+ exports.default = '1.15.4';
@@ -199,5 +199,5 @@
199
199
  ]
200
200
  }
201
201
  },
202
- "version": "1.15.2"
202
+ "version": "1.15.4"
203
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-connect-cli",
3
- "version": "1.15.2",
3
+ "version": "1.15.4",
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",