@constructor-io/constructorio-connect-cli 1.2.0 → 1.3.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.
package/README.md CHANGED
@@ -25,6 +25,7 @@ This package can be installed via npm: `npm i @constructor-io/constructorio-conn
25
25
  <!-- commands -->
26
26
  * [`constructorio-connect-cli deploy ENV`](#constructorio-connect-cli-deploy-env)
27
27
  * [`constructorio-connect-cli execute`](#constructorio-connect-cli-execute)
28
+ * [`constructorio-connect-cli generate-fixture`](#constructorio-connect-cli-generate-fixture)
28
29
  * [`constructorio-connect-cli help [COMMAND]`](#constructorio-connect-cli-help-command)
29
30
  * [`constructorio-connect-cli init NAME`](#constructorio-connect-cli-init-name)
30
31
 
@@ -90,6 +91,31 @@ EXAMPLES
90
91
  ```
91
92
 
92
93
 
94
+ ## `constructorio-connect-cli generate-fixture`
95
+
96
+ This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an example of how the data would be passed to the connector when executing the templates.
97
+
98
+ ```
99
+ USAGE
100
+ $ constructorio-connect-cli generate-fixture
101
+
102
+ DESCRIPTION
103
+
104
+ This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an
105
+ example of how the data would be passed to the connector when executing the templates.
106
+
107
+ You are expected to customize this file to match the data you expect to cover in a template execution (e.g. an item
108
+ with stock, a variation with missing data), etc. Note that you can have multiple fixtures of the same type to cover
109
+ different scenarios.
110
+
111
+ Finally, if the file already exists you'll be prompted to overwrite it.
112
+
113
+
114
+ EXAMPLES
115
+ $ constructorio-connect-cli generate-fixture
116
+ ```
117
+
118
+
93
119
  ## `constructorio-connect-cli help [COMMAND]`
94
120
 
95
121
  Display help for constructorio-connect-cli.
@@ -54,6 +54,35 @@ With that configured, visit the `connectrc.js` file. This is where you can descr
54
54
 
55
55
  An example with a single placeholder connection ID is provided in the `connectrc.js` by default. Replacing the example with your connection ID(s) and adjusting the example template source code according to your needs is the quickest way to get a set of working templates.
56
56
 
57
+ # Generate Fixture
58
+
59
+ Once you have written some templates and you would like to quickly test their output, you can use the `generate-fixture` command. This command will create a new fixture file based in your connection and the type.
60
+
61
+ This file serves as an example of how the data would be passed to the connector when executing the templates. You're expected to customize this file to match the data you expect to cover in a template execution. If the file already exists, you'll be prompted to overwrite it.
62
+
63
+ In summary, this command is a crucial part of testing your templates on the Constructor Connect platform. It allows you to generate test data, customize it to your needs, and see how your templates will handle it.
64
+
65
+
66
+ ## `npm run generate-fixture`
67
+
68
+ ```
69
+ USAGE
70
+ $ constructorio-connect-cli generate-fixture
71
+
72
+ DESCRIPTION
73
+
74
+ This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an example of how the data would be passed to the connector when executing the templates.
75
+
76
+ You are expected to customize this file to match the data you expect to cover in a template execution (e.g. an item with stock, a variation with missing data), etc. Note that you can have multiple fixtures of the same type to cover different
77
+ scenarios.
78
+
79
+ Finally, if the file already exists you'll be prompted to overwrite it.
80
+
81
+
82
+ EXAMPLES
83
+ $ constructorio-connect-cli generate-fixtures
84
+ ```
85
+
57
86
  # Executing Templates
58
87
 
59
88
  Once you have written some templates and you would like to quickly test their output, you can use the `execute` command. This command will allow you to see the result of executing your template against a specific fixture of JSON catalog data.
@@ -7,7 +7,8 @@
7
7
  "lint": "eslint . --ext .js",
8
8
  "lint:fix": "eslint . --ext .js --fix",
9
9
  "execute": "constructorio-connect-cli execute",
10
- "deploy": "constructorio-connect-cli deploy"
10
+ "deploy": "constructorio-connect-cli deploy",
11
+ "generate-fixture": "constructorio-connect-cli generate-fixture"
11
12
  },
12
13
  "devDependencies": {
13
14
  "eslint": "^8.47.0",
@@ -0,0 +1,9 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class GenerateFixture extends Command {
3
+ static args: {};
4
+ static description: string;
5
+ static examples: string[];
6
+ run(): Promise<any>;
7
+ getFixturePath(type: string, filename: string): string;
8
+ }
9
+ //# sourceMappingURL=generate-fixture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-fixture.d.ts","sourceRoot":"","sources":["../../src/commands/generate-fixture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAM,MAAM,aAAa,CAAC;AAa1C,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IAClD,MAAM,CAAC,IAAI,KAAM;IAEjB,MAAM,CAAC,WAAW,SAIhB;IAEF,MAAM,CAAC,QAAQ,WAA4C;IAErD,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IA6DzB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAK9C"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const fs_extra_1 = require("fs-extra");
5
+ const prompts_1 = require("@inquirer/prompts");
6
+ const ux_action_1 = require("../helpers/ux-action");
7
+ const render_tip_1 = require("../rendering/render-tip");
8
+ const render_prompt_1 = require("../prompt-data/render-prompt");
9
+ const types_1 = require("../types");
10
+ const get_fixture_1 = require("../http/get-fixture");
11
+ const get_connections_request_1 = require("../http/get-connections-request");
12
+ const file_exists_1 = require("../helpers/file-exists");
13
+ const path_1 = require("../customer/path");
14
+ class GenerateFixture extends core_1.Command {
15
+ static args = {};
16
+ static description = `
17
+ This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an example of how the data would be passed to the connector when executing the templates.\n
18
+ You are expected to customize this file to match the data you expect to cover in a template execution (e.g. an item with stock, a variation with missing data), etc. Note that you can have multiple fixtures of the same type to cover different scenarios.\n
19
+ Finally, if the file already exists you'll be prompted to overwrite it.
20
+ `;
21
+ static examples = ["$ <%= config.bin %> generate-fixture"];
22
+ async run() {
23
+ const connections = await (0, ux_action_1.uxAction)("📡 Reading your connections...", async () => {
24
+ return await (0, get_connections_request_1.getConnectionsForCompany)();
25
+ })();
26
+ const connectionId = await (0, render_prompt_1.renderPrompt)({
27
+ promptMessage: "Choose the connection to generate the fixture for",
28
+ choices: connections.map((connection) => ({
29
+ name: `[${connection.environment}] - ${connection.name} `,
30
+ value: connection.id,
31
+ })),
32
+ });
33
+ const type = await (0, render_prompt_1.renderPrompt)({
34
+ promptMessage: "Choose the type of fixture you want to generate",
35
+ choices: Object.keys(types_1.CatalogFixtureType).map((catalogFixtureType) => ({
36
+ name: catalogFixtureType,
37
+ value: Object(types_1.CatalogFixtureType)[catalogFixtureType],
38
+ })),
39
+ });
40
+ const filename = await (0, prompts_1.input)({
41
+ message: "Enter the filename",
42
+ default: `${type}.json`,
43
+ });
44
+ const filepath = this.getFixturePath(type, filename);
45
+ const shouldAskReplace = (0, file_exists_1.fileExists)(filepath, true);
46
+ if (shouldAskReplace) {
47
+ const shouldRefresh = await (0, prompts_1.confirm)({
48
+ message: `This fixture already exists. Do you want to refresh it?`,
49
+ default: false,
50
+ });
51
+ if (!shouldRefresh) {
52
+ (0, render_tip_1.renderTip)([
53
+ "Your file was not refreshed!",
54
+ "If you want to generate the fixture, please execute the command again",
55
+ ]);
56
+ return;
57
+ }
58
+ }
59
+ try {
60
+ await (0, ux_action_1.uxAction)("🧶 Generating fixtures...", async () => {
61
+ const response = await (0, get_fixture_1.getFixture)({
62
+ connectionId,
63
+ type: type,
64
+ });
65
+ await (0, fs_extra_1.outputFile)(filepath, JSON.stringify(response.data, null, 2));
66
+ })();
67
+ core_1.ux.info(`🎉 ${type} fixture generated at ${filepath}`);
68
+ }
69
+ catch (err) {
70
+ core_1.ux.error(`🙈 ${err.message}`);
71
+ }
72
+ }
73
+ getFixturePath(type, filename) {
74
+ return (0, path_1.getCustomerPath)(`src/fixtures/${type}/${filename.replace(/\.[^/.]+$/, "")}.json`);
75
+ }
76
+ }
77
+ exports.default = GenerateFixture;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns true if the file exists, false otherwise
3
+ * @param filepath The path of the file you want to check
4
+ * @returns boolean
5
+ */
6
+ export declare function fileExists(filepath: string, isCustomerPath?: boolean): boolean;
7
+ //# sourceMappingURL=file-exists.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-exists.d.ts","sourceRoot":"","sources":["../../src/helpers/file-exists.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,UAAQ,GAAG,OAAO,CAO5E"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fileExists = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const path_1 = require("../customer/path");
6
+ /**
7
+ * Returns true if the file exists, false otherwise
8
+ * @param filepath The path of the file you want to check
9
+ * @returns boolean
10
+ */
11
+ function fileExists(filepath, isCustomerPath = false) {
12
+ const fullpath = isCustomerPath ? filepath : (0, path_1.getCustomerPath)(filepath);
13
+ try {
14
+ return (0, fs_extra_1.existsSync)(fullpath);
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
20
+ exports.fileExists = fileExists;
@@ -0,0 +1,11 @@
1
+ import { type CatalogFixtureType } from "../types";
2
+ export declare function getFixture(args: GetFixturesArgs): Promise<GetFixtureResponseDto>;
3
+ interface GetFixturesArgs {
4
+ connectionId: string;
5
+ type: CatalogFixtureType;
6
+ }
7
+ export interface GetFixtureResponseDto {
8
+ data: any;
9
+ }
10
+ export {};
11
+ //# sourceMappingURL=get-fixture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-fixture.d.ts","sourceRoot":"","sources":["../../src/http/get-fixture.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAInD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,qBAAqB,CAAC,CAuBhC;AAED,UAAU,eAAe;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,kBAAkB,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,GAAG,CAAC;CACX"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFixture = 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 getFixture(args) {
9
+ const client = await (0, http_client_1.getHttpClient)();
10
+ try {
11
+ const response = await (0, ux_action_1.uxAction)("📡 Fetching fixtures", async () => {
12
+ return await client.get(`/templates/catalog_fixture`, {
13
+ params: {
14
+ connection_id: args.connectionId,
15
+ type: args.type,
16
+ },
17
+ });
18
+ })();
19
+ return response.data;
20
+ }
21
+ catch (error) {
22
+ if ((0, axios_1.isAxiosError)(error) && error.response) {
23
+ throw new errors_1.CLIError("Something went wrong while fetching fixtures: \n" +
24
+ error.response.data.message);
25
+ }
26
+ throw error;
27
+ }
28
+ }
29
+ exports.getFixture = getFixture;
package/dist/types.d.ts CHANGED
@@ -36,5 +36,12 @@ export interface TemplateExecutionErrorResponse {
36
36
  success: false;
37
37
  error: TemplateError;
38
38
  }
39
+ export declare enum CatalogFixtureType {
40
+ ITEM = "item",
41
+ VARIATION = "variation",
42
+ ITEM_GROUP = "item_group",
43
+ EXTERNAL_DATA = "external_data",
44
+ MAPPING = "mapping"
45
+ }
39
46
  export {};
40
47
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,2BAA2B,EAAE,OAAO,CAAC;IACrC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,YAAY,EAAE,KAAK,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,KAAK,CAAC;YACf,KAAK,EAAE;gBACL,IAAI,CAAC,EAAE,MAAM,CAAC;gBACd,SAAS,CAAC,EAAE,MAAM,CAAC;gBACnB,UAA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,CAAC;gBAClB,OAAO,CAAC,EAAE,MAAM,CAAC;aAClB,CAAC;YACF,cAAc,EAAE,MAAM,EAAE,CAAC;SAC1B,CAAC,CAAC;KACJ,CAAC,CAAC;CACJ;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,CACvC,MAAM,EACN;IACE,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CACF,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAEjE,UAAU,aAAa;IACrB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,UAAU,eAAe;IACzB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;CACpB"}
package/dist/types.js CHANGED
@@ -1,2 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CatalogFixtureType = void 0;
4
+ var CatalogFixtureType;
5
+ (function (CatalogFixtureType) {
6
+ CatalogFixtureType["ITEM"] = "item";
7
+ CatalogFixtureType["VARIATION"] = "variation";
8
+ CatalogFixtureType["ITEM_GROUP"] = "item_group";
9
+ CatalogFixtureType["EXTERNAL_DATA"] = "external_data";
10
+ CatalogFixtureType["MAPPING"] = "mapping";
11
+ })(CatalogFixtureType || (exports.CatalogFixtureType = CatalogFixtureType = {}));
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const _default: "1.2.0";
1
+ declare const _default: "1.3.0";
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.2.0';
3
+ exports.default = '1.3.0';
@@ -94,6 +94,29 @@
94
94
  "execute.js"
95
95
  ]
96
96
  },
97
+ "generate-fixture": {
98
+ "aliases": [],
99
+ "args": {},
100
+ "description": "\nThis command will fetch one fixture from the server and save it into a specified file. This fixture file will be an example of how the data would be passed to the connector when executing the templates.\n\nYou are expected to customize this file to match the data you expect to cover in a template execution (e.g. an item with stock, a variation with missing data), etc. Note that you can have multiple fixtures of the same type to cover different scenarios.\n\nFinally, if the file already exists you'll be prompted to overwrite it.\n ",
101
+ "examples": [
102
+ "$ <%= config.bin %> generate-fixture"
103
+ ],
104
+ "flags": {},
105
+ "hasDynamicHelp": false,
106
+ "hiddenAliases": [],
107
+ "id": "generate-fixture",
108
+ "pluginAlias": "@constructor-io/constructorio-connect-cli",
109
+ "pluginName": "@constructor-io/constructorio-connect-cli",
110
+ "pluginType": "core",
111
+ "strict": true,
112
+ "enableJsonFlag": false,
113
+ "isESM": false,
114
+ "relativePath": [
115
+ "dist",
116
+ "commands",
117
+ "generate-fixture.js"
118
+ ]
119
+ },
97
120
  "init": {
98
121
  "aliases": [],
99
122
  "args": {
@@ -125,5 +148,5 @@
125
148
  ]
126
149
  }
127
150
  },
128
- "version": "1.2.0"
151
+ "version": "1.3.0"
129
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-connect-cli",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
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",
@@ -23,7 +23,8 @@
23
23
  "build": "tsc --project tsconfig.production.json",
24
24
  "prebuild": "shx rm -rf dist",
25
25
  "type-check": "tsc --noemit",
26
- "test": "TZ=UTC jest",
26
+ "test": "TZ=UTC node --trace-warnings node_modules/.bin/jest",
27
+ "test:verbose": "TZ=UTC VERBOSE=true jest",
27
28
  "test:debug": "TZ=UTC node --inspect-brk -r ts-node/register node_modules/.bin/jest --runInBand",
28
29
  "test:watch": "TZ=UTC jest --watch",
29
30
  "test:cov": "TZ=UTC jest --coverage",