@constructor-io/constructorio-connect-cli 1.16.1 → 1.18.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
@@ -124,7 +124,18 @@ This command will fetch one fixture from the server and save it into a specified
124
124
 
125
125
  ```
126
126
  USAGE
127
- $ constructorio-connect-cli generate-fixture
127
+ $ constructorio-connect-cli generate-fixture [--connection <value>] [--type
128
+ item|variation|item_group|external_data|mapping] [--filename <value>] [--item-id <value>] [--variation-id <value>]
129
+ [--replace-file]
130
+
131
+ FLAGS
132
+ --connection=<value> The connection to generate the fixture for
133
+ --filename=<value> The name of the fixture file to generate
134
+ --item-id=<value> The ID of the item to generate the fixture for
135
+ --replace-file Whether to replace the fixture file if it already exists without asking
136
+ --type=<option> The type of fixture to generate
137
+ <options: item|variation|item_group|external_data|mapping>
138
+ --variation-id=<value> The ID of the variation to generate the fixture for (only applicable when --type=variation)
128
139
 
129
140
  DESCRIPTION
130
141
  This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an
@@ -136,6 +147,16 @@ DESCRIPTION
136
147
 
137
148
  EXAMPLES
138
149
  $ constructorio-connect-cli generate-fixture
150
+
151
+ $ constructorio-connect-cli generate-fixture --connection=my-connection-id --type=item --filename=my-fixture.json
152
+
153
+ $ constructorio-connect-cli generate-fixture --connection=my-connection-id --type=variation --filename=my-fixture.json
154
+
155
+ $ constructorio-connect-cli generate-fixture --connection=my-connection-id --type=variation --item-id=123456789 --variation-id=987654321 --filename=my-fixture.json
156
+
157
+ $ constructorio-connect-cli generate-fixture --connection=my-connection-id --type=variation --item-id=123456789 --filename=my-fixture.json
158
+
159
+ $ constructorio-connect-cli generate-fixture --connection=my-connection-id --type=variation --filename=my-fixture.json --replace-file
139
160
  ```
140
161
 
141
162
 
@@ -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,6 +1,14 @@
1
1
  import { RefreshConnectionsCommand } from "./refresh-connections";
2
2
  export default class GenerateFixture extends RefreshConnectionsCommand {
3
3
  static args: {};
4
+ static flags: {
5
+ connection: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ filename: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ "item-id": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ "variation-id": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ "replace-file": import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ };
4
12
  static description: string;
5
13
  static examples: string[];
6
14
  runCommand(): Promise<any>;
@@ -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;AAiBlE,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,yBAAyB;IACpE,MAAM,CAAC,IAAI,KAAM;IAEjB,MAAM,CAAC,KAAK;;;;;;;MAyCV;IAEF,MAAM,CAAC,WAAW,SACsgB;IAExhB,MAAM,CAAC,QAAQ,WAOb;IAEI,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;IAuGhC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAU9C"}
@@ -11,18 +11,79 @@ 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 core_2 = require("@oclif/core");
23
+ const SUPPORTED_PARTNERS = [
24
+ "akeneo",
25
+ "commercetools",
26
+ "bigcommerce",
27
+ "shopify",
28
+ "vtex",
29
+ ];
30
+ const SUPPORTED_FIXTURE_TYPES = [
31
+ types_1.CatalogFixtureType.ITEM,
32
+ types_1.CatalogFixtureType.VARIATION,
33
+ ];
20
34
  class GenerateFixture extends refresh_connections_1.RefreshConnectionsCommand {
21
35
  static args = {};
36
+ static flags = {
37
+ connection: core_2.Flags.string({
38
+ description: "The connection to generate the fixture for",
39
+ required: false,
40
+ }),
41
+ type: core_2.Flags.string({
42
+ description: "The type of fixture to generate",
43
+ options: Object.values(types_1.CatalogFixtureType),
44
+ required: false,
45
+ }),
46
+ filename: core_2.Flags.string({
47
+ description: "The name of the fixture file to generate",
48
+ required: false,
49
+ }),
50
+ ["item-id"]: core_2.Flags.string({
51
+ description: "The ID of the item to generate the fixture for",
52
+ required: false,
53
+ }),
54
+ ["variation-id"]: core_2.Flags.string({
55
+ description: "The ID of the variation to generate the fixture for (only applicable when --type=variation)",
56
+ required: false,
57
+ relationships: [
58
+ {
59
+ type: "some",
60
+ flags: [
61
+ {
62
+ name: "type",
63
+ when: async (flags) => flags.type === "variation",
64
+ },
65
+ ],
66
+ },
67
+ ],
68
+ }),
69
+ ["replace-file"]: core_2.Flags.boolean({
70
+ description: "Whether to replace the fixture file if it already exists without asking",
71
+ required: false,
72
+ default: false,
73
+ }),
74
+ };
22
75
  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.";
23
- static examples = ["$ <%= config.bin %> generate-fixture"];
76
+ static examples = [
77
+ "$ <%= config.bin %> generate-fixture",
78
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=item --filename=my-fixture.json",
79
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=variation --filename=my-fixture.json",
80
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=variation --item-id=123456789 --variation-id=987654321 --filename=my-fixture.json",
81
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=variation --item-id=123456789 --filename=my-fixture.json",
82
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=variation --filename=my-fixture.json --replace-file",
83
+ ];
24
84
  async runCommand() {
25
- const connection = await (0, select_connections_1.selectConnections)("Choose the connection to generate the fixture for");
85
+ const { flags } = await this.parse(GenerateFixture);
86
+ const connection = await (0, select_connections_1.selectConnections)("Choose the connection to generate the fixture for", flags.connection);
26
87
  const choices = Object.keys(types_1.CatalogFixtureType).map((catalogFixtureType) => ({
27
88
  name: catalogFixtureType,
28
89
  value: Object(types_1.CatalogFixtureType)[catalogFixtureType],
@@ -31,36 +92,63 @@ class GenerateFixture extends refresh_connections_1.RefreshConnectionsCommand {
31
92
  const index = choices.findIndex((choice) => choice.value === "mapping");
32
93
  choices.splice(index, 1);
33
94
  }
34
- const type = await (0, render_prompt_1.renderPrompt)({
35
- promptMessage: "Choose the type of fixture you want to generate",
36
- choices,
37
- });
38
- const filename = await (0, prompts_1.input)({
39
- message: "Enter the filename",
40
- default: `${type}.json`,
41
- });
95
+ const type = flags.type ||
96
+ (await (0, render_prompt_1.renderPrompt)({
97
+ promptMessage: "Choose the type of fixture you want to generate",
98
+ choices,
99
+ }));
100
+ const filename = flags.filename ||
101
+ (await (0, prompts_1.input)({
102
+ message: "Enter the filename",
103
+ default: `${type}.json`,
104
+ }));
42
105
  const filepath = this.getFixturePath(type, filename);
43
106
  const shouldAskReplace = (0, file_exists_1.fileExists)(filepath, true);
44
107
  if (shouldAskReplace) {
45
- const shouldRefresh = await (0, prompts_1.confirm)({
46
- message: `This fixture already exists. Do you want to refresh it?`,
47
- default: false,
48
- });
49
- if (!shouldRefresh) {
50
- (0, render_tip_1.renderTip)([
51
- "Your file was not refreshed!",
52
- "If you want to generate the fixture, please execute the command again",
53
- ]);
108
+ if (flags["replace-file"]) {
109
+ core_1.ux.stdout(kleur_1.default.yellow("⚠️ WARNING!") +
110
+ kleur_1.default.gray(` The file ${filepath} already exists and will be replaced without asking because you provided the --replace-file flag.`));
111
+ }
112
+ else {
113
+ const shouldRefresh = await (0, prompts_1.confirm)({
114
+ message: `This fixture already exists. Do you want to refresh it?`,
115
+ default: false,
116
+ });
117
+ if (!shouldRefresh) {
118
+ (0, render_tip_1.renderTip)([
119
+ "Your file was not refreshed!",
120
+ "If you want to generate the fixture, please execute the command again",
121
+ ]);
122
+ return;
123
+ }
124
+ }
125
+ }
126
+ const canUseLiveFixture = SUPPORTED_PARTNERS.includes(connection.partner) &&
127
+ SUPPORTED_FIXTURE_TYPES.includes(type);
128
+ if (canUseLiveFixture) {
129
+ try {
130
+ const { data } = await getLiveFixtureData(connection, type, flags["item-id"], flags["variation-id"]);
131
+ await (0, fs_extra_1.outputFile)(filepath, JSON.stringify(data, null, 2));
132
+ core_1.ux.stdout(`🎉 ${type} live fixture generated at ${filepath}`);
54
133
  return;
55
134
  }
135
+ catch (_) {
136
+ const wantStaticFixture = await (0, prompts_1.confirm)({
137
+ message: `Do you want to generate a static fixture instead?`,
138
+ default: false,
139
+ });
140
+ if (!wantStaticFixture) {
141
+ return;
142
+ }
143
+ }
56
144
  }
57
145
  try {
58
146
  await (0, ux_action_1.uxAction)("🧶 Generating fixtures...", async () => {
59
- const response = await (0, get_fixture_1.getFixture)({
147
+ const { data } = await (0, get_fixture_1.getFixture)({
60
148
  connectionId: connection.id,
61
- type: type,
149
+ type,
62
150
  });
63
- await (0, fs_extra_1.outputFile)(filepath, JSON.stringify(response.data, null, 2));
151
+ await (0, fs_extra_1.outputFile)(filepath, JSON.stringify(data, null, 2));
64
152
  })();
65
153
  core_1.ux.stdout(`🎉 ${type} fixture generated at ${filepath}`);
66
154
  }
@@ -73,3 +161,68 @@ class GenerateFixture extends refresh_connections_1.RefreshConnectionsCommand {
73
161
  }
74
162
  }
75
163
  exports.default = GenerateFixture;
164
+ async function getLiveFixtureData(connection, type, argItemId, argVariationId) {
165
+ switch (connection.partner) {
166
+ case "shopify":
167
+ core_1.ux.stdout(kleur_1.default.yellow("TIP!") + kleur_1.default.gray(" Provide a sanitized Product ID"));
168
+ core_1.ux.stdout(kleur_1.default.gray(" 123456789"));
169
+ core_1.ux.stdout(kleur_1.default.gray(" (we also support full id strings: gid://shopify/Product/123456789)"));
170
+ break;
171
+ case "akeneo":
172
+ core_1.ux.stdout(kleur_1.default.yellow("TIP!") +
173
+ kleur_1.default.gray("Provide the Product UUID. If it belongs to a ProductModel, it'll be returned as the item"));
174
+ break;
175
+ case "commercetools":
176
+ core_1.ux.stdout(kleur_1.default.yellow("TIP!") +
177
+ kleur_1.default.gray(" Provide the standard Product ID, which can be found in the URL of the product in the Merchant Center"));
178
+ break;
179
+ }
180
+ const id = argItemId ||
181
+ (await (0, prompts_1.input)({
182
+ message: "Enter the ID of the item you want to generate the fixture for",
183
+ }));
184
+ try {
185
+ let data;
186
+ try {
187
+ const response = await (0, get_live_fixture_1.getLiveFixture)({
188
+ connectionId: connection.id,
189
+ id,
190
+ });
191
+ data = response.data;
192
+ }
193
+ catch (_) {
194
+ throw new Error(`Could not fetch live fixture for the provided ID. Is the ID correct?`);
195
+ }
196
+ if (type === types_1.CatalogFixtureType.ITEM) {
197
+ return {
198
+ data,
199
+ };
200
+ }
201
+ const possibleVariations = data.__variations || [];
202
+ if (possibleVariations.length === 0) {
203
+ throw new Error("The item you selected does not have variations, cannot generate variation fixture");
204
+ }
205
+ const variationsById = possibleVariations.reduce((acc, variation) => {
206
+ acc[variation.__id] = variation;
207
+ return acc;
208
+ }, {});
209
+ const variationId = argVariationId ||
210
+ (await (0, render_prompt_1.renderPrompt)({
211
+ promptMessage: "The item you selected has more than 1 variation. Please select the variation you want to generate the fixture for:",
212
+ choices: Object.keys(variationsById).map((variationId) => ({
213
+ name: variationId,
214
+ value: variationId,
215
+ })),
216
+ }));
217
+ const variationWithItem = Object.assign({}, variationsById[variationId], {
218
+ __item: data,
219
+ });
220
+ return {
221
+ data: variationWithItem,
222
+ };
223
+ }
224
+ catch (err) {
225
+ core_1.ux.stdout(`❌ ${err.message}`);
226
+ throw err;
227
+ }
228
+ }
@@ -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
  }
@@ -1,2 +1,2 @@
1
- export declare const selectConnections: (message?: string) => Promise<import("../types").Connection>;
1
+ export declare const selectConnections: (message?: string, selectedConnectionId?: string) => Promise<import("../types").Connection>;
2
2
  //# sourceMappingURL=select-connections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"select-connections.d.ts","sourceRoot":"","sources":["../../src/prompt-data/select-connections.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,GAC5B,UAAS,MAAgC,2CA0B1C,CAAC"}
1
+ {"version":3,"file":"select-connections.d.ts","sourceRoot":"","sources":["../../src/prompt-data/select-connections.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,GAC5B,UAAS,MAAgC,EACzC,uBAAuB,MAAM,2CAoC9B,CAAC"}
@@ -5,13 +5,19 @@ const get_connections_request_1 = require("../http/get-connections-request");
5
5
  const ux_action_1 = require("../helpers/ux-action");
6
6
  const get_connect_token_1 = require("../customer/get-connect-token");
7
7
  const render_prompt_1 = require("../prompt-data/render-prompt");
8
- const selectConnections = async (message = "Choose the connection") => {
8
+ const selectConnections = async (message = "Choose the connection", selectedConnectionId) => {
9
9
  const connections = await (0, ux_action_1.uxAction)("📡 Reading your connections...", async () => {
10
10
  return await (0, get_connections_request_1.getConnections)({ showLogs: true });
11
11
  })();
12
12
  // Load the connect token to ensure we can authenticate with Constructor.
13
13
  // We do this here because the terminal output gets weird when there is a prompt during a ux action.
14
14
  await (0, get_connect_token_1.getConnectToken)();
15
+ if (selectedConnectionId) {
16
+ const selectedConnection = connections.find((connection) => connection.id === selectedConnectionId);
17
+ if (selectedConnection) {
18
+ return selectedConnection;
19
+ }
20
+ }
15
21
  const connectionId = await (0, render_prompt_1.renderPrompt)({
16
22
  promptMessage: message,
17
23
  choices: connections.map((connection) => ({
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const _default: "1.16.1";
1
+ declare const _default: "1.18.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.1';
3
+ exports.default = '1.18.0';
@@ -115,9 +115,79 @@
115
115
  "args": {},
116
116
  "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.",
117
117
  "examples": [
118
- "$ <%= config.bin %> generate-fixture"
118
+ "$ <%= config.bin %> generate-fixture",
119
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=item --filename=my-fixture.json",
120
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=variation --filename=my-fixture.json",
121
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=variation --item-id=123456789 --variation-id=987654321 --filename=my-fixture.json",
122
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=variation --item-id=123456789 --filename=my-fixture.json",
123
+ "$ <%= config.bin %> generate-fixture --connection=my-connection-id --type=variation --filename=my-fixture.json --replace-file"
119
124
  ],
120
- "flags": {},
125
+ "flags": {
126
+ "connection": {
127
+ "description": "The connection to generate the fixture for",
128
+ "name": "connection",
129
+ "required": false,
130
+ "hasDynamicHelp": false,
131
+ "multiple": false,
132
+ "type": "option"
133
+ },
134
+ "type": {
135
+ "description": "The type of fixture to generate",
136
+ "name": "type",
137
+ "required": false,
138
+ "hasDynamicHelp": false,
139
+ "multiple": false,
140
+ "options": [
141
+ "item",
142
+ "variation",
143
+ "item_group",
144
+ "external_data",
145
+ "mapping"
146
+ ],
147
+ "type": "option"
148
+ },
149
+ "filename": {
150
+ "description": "The name of the fixture file to generate",
151
+ "name": "filename",
152
+ "required": false,
153
+ "hasDynamicHelp": false,
154
+ "multiple": false,
155
+ "type": "option"
156
+ },
157
+ "item-id": {
158
+ "description": "The ID of the item to generate the fixture for",
159
+ "name": "item-id",
160
+ "required": false,
161
+ "hasDynamicHelp": false,
162
+ "multiple": false,
163
+ "type": "option"
164
+ },
165
+ "variation-id": {
166
+ "description": "The ID of the variation to generate the fixture for (only applicable when --type=variation)",
167
+ "name": "variation-id",
168
+ "relationships": [
169
+ {
170
+ "type": "some",
171
+ "flags": [
172
+ {
173
+ "name": "type"
174
+ }
175
+ ]
176
+ }
177
+ ],
178
+ "required": false,
179
+ "hasDynamicHelp": false,
180
+ "multiple": false,
181
+ "type": "option"
182
+ },
183
+ "replace-file": {
184
+ "description": "Whether to replace the fixture file if it already exists without asking",
185
+ "name": "replace-file",
186
+ "required": false,
187
+ "allowNo": false,
188
+ "type": "boolean"
189
+ }
190
+ },
121
191
  "hasDynamicHelp": false,
122
192
  "hiddenAliases": [],
123
193
  "id": "generate-fixture",
@@ -207,5 +277,5 @@
207
277
  ]
208
278
  }
209
279
  },
210
- "version": "1.16.1"
280
+ "version": "1.18.0"
211
281
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-connect-cli",
3
- "version": "1.16.1",
3
+ "version": "1.18.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",