@constructor-io/constructorio-connect-cli 1.16.0 → 1.17.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.
@@ -3,7 +3,10 @@
3
3
  * @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-development-flow#step-3-test-your-templates
4
4
  */
5
5
 
6
- import { executeTemplate, buildFixture } from "@constructor-io/constructorio-connect-cli";
6
+ import {
7
+ executeTemplate,
8
+ buildFixture,
9
+ } from "@constructor-io/constructorio-connect-cli";
7
10
 
8
11
  describe("item", () => {
9
12
  it("should match snapshot", async () => {
@@ -3,7 +3,10 @@
3
3
  * @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-development-flow#step-3-test-your-templates
4
4
  */
5
5
 
6
- import { executeTemplate, buildFixture } from "@constructor-io/constructorio-connect-cli";
6
+ import {
7
+ executeTemplate,
8
+ buildFixture,
9
+ } from "@constructor-io/constructorio-connect-cli";
7
10
 
8
11
  describe("item_group", () => {
9
12
  it("should match snapshot", async () => {
@@ -3,7 +3,10 @@
3
3
  * @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-development-flow#step-3-test-your-templates
4
4
  */
5
5
 
6
- import { executeTemplate, buildFixture } from "@constructor-io/constructorio-connect-cli";
6
+ import {
7
+ executeTemplate,
8
+ buildFixture,
9
+ } from "@constructor-io/constructorio-connect-cli";
7
10
 
8
11
  describe("mapping", () => {
9
12
  it("should map item groups", async () => {
@@ -3,7 +3,10 @@
3
3
  * @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-development-flow#step-3-test-your-templates
4
4
  */
5
5
 
6
- import { executeTemplate, buildFixture } from "@constructor-io/constructorio-connect-cli";
6
+ import {
7
+ executeTemplate,
8
+ buildFixture,
9
+ } from "@constructor-io/constructorio-connect-cli";
7
10
 
8
11
  describe("variation", () => {
9
12
  it("should match snapshot", async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"generate-fixture.d.ts","sourceRoot":"","sources":["../../src/commands/generate-fixture.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,yBAAyB;IACpE,MAAM,CAAC,IAAI,KAAM;IAEjB,MAAM,CAAC,WAAW,SACsgB;IAExhB,MAAM,CAAC,QAAQ,WAA4C;IAErD,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;IA2DhC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAU9C"}
1
+ {"version":3,"file":"generate-fixture.d.ts","sourceRoot":"","sources":["../../src/commands/generate-fixture.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAgBlE,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,yBAAyB;IACpE,MAAM,CAAC,IAAI,KAAM;IAEjB,MAAM,CAAC,WAAW,SACsgB;IAExhB,MAAM,CAAC,QAAQ,WAA4C;IAErD,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;IAkFhC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAU9C"}
@@ -11,12 +11,25 @@ const path_2 = require("../customer/path");
11
11
  const file_exists_1 = require("../helpers/file-exists");
12
12
  const ux_action_1 = require("../helpers/ux-action");
13
13
  const get_fixture_1 = require("../http/get-fixture");
14
+ const get_live_fixture_1 = require("../http/get-live-fixture");
14
15
  const render_prompt_1 = require("../prompt-data/render-prompt");
15
16
  const render_tip_1 = require("../rendering/render-tip");
16
17
  const types_1 = require("../types");
17
18
  const check_if_connection_needs_mapping_1 = require("../helpers/check-if-connection-needs-mapping");
18
19
  const select_connections_1 = require("../prompt-data/select-connections");
19
20
  const refresh_connections_1 = require("./refresh-connections");
21
+ const kleur_1 = __importDefault(require("kleur"));
22
+ const SUPPORTED_PARTNERS = [
23
+ "akeneo",
24
+ "commercetools",
25
+ "bigcommerce",
26
+ "shopify",
27
+ "vtex",
28
+ ];
29
+ const SUPPORTED_FIXTURE_TYPES = [
30
+ types_1.CatalogFixtureType.ITEM,
31
+ types_1.CatalogFixtureType.VARIATION,
32
+ ];
20
33
  class GenerateFixture extends refresh_connections_1.RefreshConnectionsCommand {
21
34
  static args = {};
22
35
  static description = "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 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 Finally, if the file already exists you'll be prompted to overwrite it.";
@@ -54,13 +67,32 @@ class GenerateFixture extends refresh_connections_1.RefreshConnectionsCommand {
54
67
  return;
55
68
  }
56
69
  }
70
+ const canUseLiveFixture = SUPPORTED_PARTNERS.includes(connection.partner) &&
71
+ SUPPORTED_FIXTURE_TYPES.includes(type);
72
+ if (canUseLiveFixture) {
73
+ try {
74
+ const { data } = await getLiveFixtureData(connection, type);
75
+ await (0, fs_extra_1.outputFile)(filepath, JSON.stringify(data, null, 2));
76
+ core_1.ux.stdout(`🎉 ${type} live fixture generated at ${filepath}`);
77
+ return;
78
+ }
79
+ catch (_) {
80
+ const wantStaticFixture = await (0, prompts_1.confirm)({
81
+ message: `Do you want to generate a static fixture instead?`,
82
+ default: false,
83
+ });
84
+ if (!wantStaticFixture) {
85
+ return;
86
+ }
87
+ }
88
+ }
57
89
  try {
58
90
  await (0, ux_action_1.uxAction)("🧶 Generating fixtures...", async () => {
59
- const response = await (0, get_fixture_1.getFixture)({
91
+ const { data } = await (0, get_fixture_1.getFixture)({
60
92
  connectionId: connection.id,
61
- type: type,
93
+ type,
62
94
  });
63
- await (0, fs_extra_1.outputFile)(filepath, JSON.stringify(response.data, null, 2));
95
+ await (0, fs_extra_1.outputFile)(filepath, JSON.stringify(data, null, 2));
64
96
  })();
65
97
  core_1.ux.stdout(`🎉 ${type} fixture generated at ${filepath}`);
66
98
  }
@@ -73,3 +105,66 @@ class GenerateFixture extends refresh_connections_1.RefreshConnectionsCommand {
73
105
  }
74
106
  }
75
107
  exports.default = GenerateFixture;
108
+ async function getLiveFixtureData(connection, type) {
109
+ switch (connection.partner) {
110
+ case "shopify":
111
+ core_1.ux.stdout(kleur_1.default.yellow("TIP!") + kleur_1.default.gray(" Provide a sanitized Product ID"));
112
+ core_1.ux.stdout(kleur_1.default.gray(" ✅ 123456789"));
113
+ core_1.ux.stdout(kleur_1.default.gray(" ❌ gid://shopify/Product/123456789"));
114
+ break;
115
+ case "akeneo":
116
+ core_1.ux.stdout(kleur_1.default.yellow("TIP!") +
117
+ kleur_1.default.gray("Provide the Product UUID. If it belongs to a ProductModel, it'll be returned as the item"));
118
+ break;
119
+ case "commercetools":
120
+ core_1.ux.stdout(kleur_1.default.yellow("TIP!") +
121
+ kleur_1.default.gray(" Provide the standard Product ID, which can be found in the URL of the product in the Merchant Center"));
122
+ break;
123
+ }
124
+ const id = await (0, prompts_1.input)({
125
+ message: "Enter the ID of the item you want to generate the fixture for",
126
+ });
127
+ try {
128
+ let data;
129
+ try {
130
+ const response = await (0, get_live_fixture_1.getLiveFixture)({
131
+ connectionId: connection.id,
132
+ id,
133
+ });
134
+ data = response.data;
135
+ }
136
+ catch (_) {
137
+ throw new Error(`Could not fetch live fixture for the provided ID. Is the ID correct?`);
138
+ }
139
+ if (type === types_1.CatalogFixtureType.ITEM) {
140
+ return {
141
+ data,
142
+ };
143
+ }
144
+ const possibleVariations = data.__variations || [];
145
+ if (possibleVariations.length === 0) {
146
+ throw new Error("The item you selected does not have variations, cannot generate variation fixture");
147
+ }
148
+ const variationsById = possibleVariations.reduce((acc, variation) => {
149
+ acc[variation.__id] = variation;
150
+ return acc;
151
+ }, {});
152
+ const variationId = await (0, render_prompt_1.renderPrompt)({
153
+ promptMessage: "The item you selected has more than 1 variation. Please select the variation you want to generate the fixture for:",
154
+ choices: Object.keys(variationsById).map((variationId) => ({
155
+ name: variationId,
156
+ value: variationId,
157
+ })),
158
+ });
159
+ const variationWithItem = Object.assign({}, variationsById[variationId], {
160
+ __item: data,
161
+ });
162
+ return {
163
+ data: variationWithItem,
164
+ };
165
+ }
166
+ catch (err) {
167
+ core_1.ux.stdout(`❌ ${err.message}`);
168
+ throw err;
169
+ }
170
+ }
@@ -0,0 +1,10 @@
1
+ export declare function getLiveFixture(args: GetLiveFixtureArgs): Promise<GetLiveFixtureResponseDto>;
2
+ interface GetLiveFixtureArgs {
3
+ connectionId: string;
4
+ id: string;
5
+ }
6
+ export interface GetLiveFixtureResponseDto {
7
+ data: any;
8
+ }
9
+ export {};
10
+ //# sourceMappingURL=get-live-fixture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-live-fixture.d.ts","sourceRoot":"","sources":["../../src/http/get-live-fixture.ts"],"names":[],"mappings":"AAOA,wBAAsB,cAAc,CAClC,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,yBAAyB,CAAC,CA0BpC;AAED,UAAU,kBAAkB;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,GAAG,CAAC;CACX"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLiveFixture = getLiveFixture;
4
+ const axios_1 = require("axios");
5
+ const errors_1 = require("@oclif/core/errors");
6
+ const ux_action_1 = require("../helpers/ux-action");
7
+ const http_client_1 = require("./http-client");
8
+ async function getLiveFixture(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(`/live_fixtures/item`, {
13
+ params: {
14
+ connection_id: args.connectionId,
15
+ id: args.id,
16
+ },
17
+ headers: {
18
+ Authorization: `Bearer ${process.env.CONNECT_AUTH_TOKEN}`,
19
+ },
20
+ });
21
+ })();
22
+ return response;
23
+ }
24
+ catch (error) {
25
+ if ((0, axios_1.isAxiosError)(error) && error.response) {
26
+ throw new errors_1.CLIError("Something went wrong while fetching fixtures: \n" +
27
+ error.response.data.message);
28
+ }
29
+ throw error;
30
+ }
31
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/http/http-client.ts"],"names":[],"mappings":"AACA,OAAO,KAA6C,MAAM,OAAO,CAAC;AA6BlE,UAAU,iBAAiB;IACzB,YAAY,EAAE,OAAO,CAAC;CACvB;AAOD;;GAEG;AACH,wBAAsB,aAAa,CACjC,EAAE,YAAY,EAAE,GAAE,iBAEjB,gCA8DF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,GAAG,WAK7C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,cAcjE"}
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/http/http-client.ts"],"names":[],"mappings":"AACA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAmClE,UAAU,iBAAiB;IACzB,YAAY,EAAE,OAAO,CAAC;CACvB;AAOD;;GAEG;AACH,wBAAsB,aAAa,CACjC,EAAE,YAAY,EAAE,GAAE,iBAEjB,gCA8DF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,GAAG,WAK7C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,cAcjE"}
@@ -61,6 +61,11 @@ const RETRY_IGNORED_HTTP_STATUS_CODES = [
61
61
  * This error is thrown whenever a user has no permissions to access a resource.
62
62
  */
63
63
  403,
64
+ /**
65
+ * HTTP 404: Not Found
66
+ * This error is thrown whenever a resource cannot be found.
67
+ */
68
+ 404,
64
69
  ];
65
70
  const MAX_RETRIES = 3;
66
71
  /**
@@ -1 +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"}
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,CAuBtB;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"}
@@ -10,6 +10,16 @@ async function renderPrompt({ choices, promptMessage, emptyMessage, }) {
10
10
  case 1:
11
11
  return choices[0].value;
12
12
  default:
13
- return await (0, prompts_1.select)({ message: promptMessage, choices });
13
+ return await (0, prompts_1.search)({
14
+ message: promptMessage,
15
+ source(term) {
16
+ if (!term)
17
+ return choices;
18
+ return choices.filter((choice) => choice.name
19
+ .toLowerCase()
20
+ .trim()
21
+ .includes(term.toLowerCase().trim()));
22
+ },
23
+ });
14
24
  }
15
25
  }
@@ -46,6 +46,7 @@ function renderTemplateError(result) {
46
46
  highlightedSnippet = highlightedSnippet
47
47
  .split("\n")
48
48
  .map((line, i) => kleur_1.default.gray(`${i + 1 + startLine} `) + line)
49
+ .filter((_, i) => i + 1 + startLine > 0)
49
50
  .join("\n");
50
51
  core_1.ux.stdout(highlightedSnippet);
51
52
  core_1.ux.stdout("\n");
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const _default: "1.16.0";
1
+ declare const _default: "1.17.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.16.0';
3
+ exports.default = '1.17.0';
@@ -207,5 +207,5 @@
207
207
  ]
208
208
  }
209
209
  },
210
- "version": "1.16.0"
210
+ "version": "1.17.0"
211
211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-connect-cli",
3
- "version": "1.16.0",
3
+ "version": "1.17.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",
@@ -92,9 +92,9 @@
92
92
  "globals": "^16.0.0",
93
93
  "jest": "^29.7.0",
94
94
  "license-checker": "^25.0.1",
95
- "markdownlint-cli2": "^0.20.0",
95
+ "markdownlint-cli2": "^0.21.0",
96
96
  "mock-fs": "^5.2.0",
97
- "nock": "14.0.10",
97
+ "nock": "14.0.11",
98
98
  "oclif": "^4.17.42",
99
99
  "prettier": "^3.2.5",
100
100
  "prettier-2": "npm:prettier@^2.8.8",