@commercelayer/cli-plugin-provisioning 2.0.9 → 2.1.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.
Files changed (46) hide show
  1. package/bin/run.js +3 -3
  2. package/lib/base.d.ts +8 -8
  3. package/lib/base.js +224 -165
  4. package/lib/commands/provisioning/create.d.ts +2 -2
  5. package/lib/commands/provisioning/create.js +46 -34
  6. package/lib/commands/provisioning/delete.d.ts +2 -2
  7. package/lib/commands/provisioning/delete.js +25 -14
  8. package/lib/commands/provisioning/exec.d.ts +1 -1
  9. package/lib/commands/provisioning/exec.js +22 -13
  10. package/lib/commands/provisioning/fetch.d.ts +3 -3
  11. package/lib/commands/provisioning/fetch.js +25 -17
  12. package/lib/commands/provisioning/get.d.ts +3 -3
  13. package/lib/commands/provisioning/get.js +8 -8
  14. package/lib/commands/provisioning/list.d.ts +3 -3
  15. package/lib/commands/provisioning/list.js +42 -38
  16. package/lib/commands/provisioning/noc.d.ts +1 -1
  17. package/lib/commands/provisioning/noc.js +1 -1
  18. package/lib/commands/provisioning/relationship.d.ts +3 -3
  19. package/lib/commands/provisioning/relationship.js +39 -23
  20. package/lib/commands/provisioning/resources.d.ts +1 -1
  21. package/lib/commands/provisioning/resources.js +22 -12
  22. package/lib/commands/provisioning/retrieve.d.ts +2 -2
  23. package/lib/commands/provisioning/retrieve.js +36 -30
  24. package/lib/commands/provisioning/update.d.ts +3 -3
  25. package/lib/commands/provisioning/update.js +60 -41
  26. package/lib/csv.d.ts +1 -1
  27. package/lib/csv.js +30 -27
  28. package/lib/lang/curl.d.ts +2 -2
  29. package/lib/lang/curl.js +4 -2
  30. package/lib/lang/index.d.ts +5 -5
  31. package/lib/lang/index.js +26 -18
  32. package/lib/lang/node.d.ts +2 -2
  33. package/lib/lang/node.js +7 -7
  34. package/lib/lang/request.d.ts +3 -3
  35. package/lib/lang/request.js +37 -30
  36. package/lib/lang/ruby.d.ts +2 -2
  37. package/lib/lang/ruby.js +1 -1
  38. package/lib/output.d.ts +1 -1
  39. package/lib/output.js +3 -3
  40. package/lib/util/resources/available.js +33 -8
  41. package/lib/util/resources/build.js +35 -19
  42. package/lib/util/resources/index.d.ts +3 -3
  43. package/lib/util/resources/index.js +3 -3
  44. package/lib/util/timezones.js +127 -115
  45. package/oclif.manifest.json +1 -1
  46. package/package.json +85 -87
@@ -1,59 +1,69 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const base_1 = tslib_1.__importStar(require("../../base"));
5
4
  const cli_core_1 = require("@commercelayer/cli-core");
5
+ const base_1 = tslib_1.__importStar(require("../../base"));
6
6
  const lang_1 = require("../../lang");
7
- const OPERATION = 'update';
7
+ const OPERATION = "update";
8
8
  class ProvisioningUpdate extends base_1.default {
9
- static description = 'update an existing resource';
10
- static aliases = ['prov:update', 'pu', 'pupdate', 'pupd'];
9
+ static description = "update an existing resource";
10
+ static aliases = ["prov:update", "pu", "pupdate", "pupd"];
11
11
  static examples = [
12
- '$ commercelayer provisioning:update roles/<roleId> -a reference=referenceId',
12
+ "$ commercelayer provisioning:update roles/<roleId> -a reference=referenceId",
13
13
  '$ commercelayer prov:update roles <roleId> -a reference_origin="Ref Origin"',
14
14
  '$ cl prov:update roles/<roleId> -m meta_key="meta value"',
15
15
  '$ cl pu roles <roleId> -M meta_key="metadata overwrite',
16
- '$ clayer prov:update roles <roleId> -D /path/to/data/file/data.json',
16
+ "$ clayer prov:update roles <roleId> -D /path/to/data/file/data.json",
17
17
  ];
18
18
  static flags = {
19
19
  ...base_1.default.flags,
20
20
  attribute: base_1.Flags.string({
21
- char: 'a',
22
- description: 'define a resource attribute',
21
+ char: "a",
22
+ description: "define a resource attribute",
23
23
  multiple: true,
24
24
  }),
25
25
  object: base_1.Flags.string({
26
- char: 'O',
27
- description: 'define a resource object attribute',
26
+ char: "O",
27
+ description: "define a resource object attribute",
28
28
  multiple: true,
29
29
  }),
30
30
  relationship: base_1.Flags.string({
31
- char: 'r',
32
- description: 'define a relationship with another resource',
31
+ char: "r",
32
+ description: "define a relationship with another resource",
33
33
  multiple: true,
34
34
  }),
35
35
  metadata: base_1.Flags.string({
36
- char: 'm',
37
- description: 'define a metadata attribute and merge it with the metadata already present in the remote resource',
36
+ char: "m",
37
+ description: "define a metadata attribute and merge it with the metadata already present in the remote resource",
38
38
  multiple: true,
39
- exclusive: ['metadata-replace'],
39
+ exclusive: ["metadata-replace"],
40
40
  }),
41
- 'metadata-replace': base_1.Flags.string({
42
- char: 'M',
43
- description: 'define a metadata attribute and replace every item already present in the remote resource',
41
+ "metadata-replace": base_1.Flags.string({
42
+ char: "M",
43
+ description: "define a metadata attribute and replace every item already present in the remote resource",
44
44
  multiple: true,
45
- exclusive: ['metadata'],
45
+ exclusive: ["metadata"],
46
46
  }),
47
47
  data: base_1.Flags.string({
48
- char: 'D',
49
- description: 'the data file to use as request body',
48
+ char: "D",
49
+ description: "the data file to use as request body",
50
50
  multiple: false,
51
- exclusive: ['attribute', 'relationship', 'metadata', 'metadata-replace', 'doc' /*, FLAG_LOAD_PARAMS, FLAG_SAVE_PARAMS */],
52
- })
51
+ exclusive: [
52
+ "attribute",
53
+ "relationship",
54
+ "metadata",
55
+ "metadata-replace",
56
+ "doc" /*, FLAG_LOAD_PARAMS, FLAG_SAVE_PARAMS */,
57
+ ],
58
+ }),
53
59
  };
54
60
  static args = {
55
61
  ...base_1.default.args,
56
- id: base_1.Args.string({ name: 'id', description: 'id of the resource to update', required: false }),
62
+ id: base_1.Args.string({
63
+ name: "id",
64
+ description: "id of the resource to update",
65
+ required: false,
66
+ }),
57
67
  };
58
68
  async run() {
59
69
  const { args, flags } = await this.parse(ProvisioningUpdate);
@@ -62,16 +72,21 @@ class ProvisioningUpdate extends base_1.default {
62
72
  // const loadParams = flags[FLAG_LOAD_PARAMS]
63
73
  // const saveCmd = flags[FLAG_SAVE_PARAMS]
64
74
  // if (saveCmd) this.checkAlias(saveCmd, resource.api, OPERATION, this.config)
65
- const showHeaders = flags.headers || flags['headers-only'];
75
+ const showHeaders = flags.headers || flags["headers-only"];
66
76
  // Raw request
67
77
  if (flags.data) {
68
78
  try {
69
- const baseUrl = cli_core_1.clApi.baseURL('provisioning', undefined, flags.domain);
79
+ const baseUrl = cli_core_1.clApi.baseURL("provisioning", undefined, flags.domain);
70
80
  const accessToken = flags.accessToken;
71
- const rawRes = await cli_core_1.clApi.request.raw({ operation: cli_core_1.clApi.Operation.Update, baseUrl, accessToken, resource: resource.api }, cli_core_1.clApi.request.readDataFile(flags.data), id);
81
+ const rawRes = await cli_core_1.clApi.request.raw({
82
+ operation: cli_core_1.clApi.Operation.Update,
83
+ baseUrl,
84
+ accessToken,
85
+ resource: resource.api,
86
+ }, cli_core_1.clApi.request.readDataFile(flags.data), id);
72
87
  const out = flags.raw ? rawRes : cli_core_1.clApi.response.denormalize(rawRes);
73
88
  this.printOutput(out, flags);
74
- this.log(`\n${cli_core_1.clColor.style.success('Successfully')} updated resource of type ${cli_core_1.clColor.style.resource(resource.api)} with id ${cli_core_1.clColor.style.id(rawRes.id)}\n`);
89
+ this.log(`\n${cli_core_1.clColor.style.success("Successfully")} updated resource of type ${cli_core_1.clColor.style.resource(resource.api)} with id ${cli_core_1.clColor.style.id(rawRes.id)}\n`);
75
90
  return out;
76
91
  }
77
92
  catch (error) {
@@ -86,16 +101,16 @@ class ProvisioningUpdate extends base_1.default {
86
101
  // Relationships flags
87
102
  const relationships = this.relationshipFlag(flags.relationship);
88
103
  // Metadata flags
89
- const metadata = this.metadataFlag(flags.metadata || flags['metadata-replace']);
104
+ const metadata = this.metadataFlag(flags.metadata || flags["metadata-replace"]);
90
105
  // Relationships
91
106
  if (relationships && Object.keys(relationships).length > 0)
92
107
  Object.entries(relationships).forEach(([key, value]) => {
93
108
  const relSdk = cl[value.type];
94
- const rel = relSdk.relationship(((value.id === null) || (value.id === 'null')) ? null : value);
109
+ const rel = relSdk.relationship(value.id === null || value.id === "null" ? null : value);
95
110
  attributes[key] = rel;
96
111
  });
97
112
  // Objects
98
- if (objects && (Object.keys(objects).length > 0)) {
113
+ if (objects && Object.keys(objects).length > 0) {
99
114
  for (const o of Object.keys(objects)) {
100
115
  if (Object.keys(attributes).includes(o))
101
116
  this.warn(`Object ${o} will overwrite attribute ${o}`);
@@ -104,31 +119,35 @@ class ProvisioningUpdate extends base_1.default {
104
119
  }
105
120
  }
106
121
  // Metadata
107
- if (metadata && (Object.keys(metadata).length > 0)) {
122
+ if (metadata && Object.keys(metadata).length > 0) {
108
123
  if (attributes.metadata)
109
- this.warn(`Attribute ${cli_core_1.clColor.style.attribute('metadata')} will be overwritten by the content defined with the flags ${cli_core_1.clColor.style.flag('-m/-M')}`);
124
+ this.warn(`Attribute ${cli_core_1.clColor.style.attribute("metadata")} will be overwritten by the content defined with the flags ${cli_core_1.clColor.style.flag("-m/-M")}`);
110
125
  attributes.metadata = metadata;
111
126
  }
112
127
  // Include flags
113
128
  const include = this.includeFlag(flags.include, relationships);
114
129
  // Fields flags
115
130
  const fields = this.fieldsFlag(flags.fields, resource.type);
116
- const rawReader = flags.raw ? cl.addRawResponseReader({ headers: showHeaders }) : undefined;
131
+ const rawReader = flags.raw
132
+ ? cl.addRawResponseReader({ headers: showHeaders })
133
+ : undefined;
117
134
  const reqReader = flags.doc ? (0, lang_1.addRequestReader)(cl) : undefined;
118
135
  const params = {};
119
136
  try {
120
137
  const resSdk = cl[resource.api];
121
138
  this.checkOperation(resSdk, OPERATION, attributes);
122
- if (include && (include.length > 0))
139
+ if (include && include.length > 0)
123
140
  params.include = include;
124
- if (fields && (Object.keys(fields).length > 0))
141
+ if (fields && Object.keys(fields).length > 0)
125
142
  params.fields = fields;
126
143
  // Metadata attributes merge
127
144
  if (flags.metadata) {
128
- const params = { fields: { [resource.api]: ['metadata'] } };
145
+ const params = {
146
+ fields: { [resource.api]: ["metadata"] },
147
+ };
129
148
  const remRes = await resSdk.retrieve(id, params);
130
149
  const remMeta = remRes.metadata;
131
- if (remMeta && (Object.keys(remMeta).length > 0))
150
+ if (remMeta && Object.keys(remMeta).length > 0)
132
151
  attributes.metadata = { ...remMeta, ...metadata };
133
152
  }
134
153
  attributes.id = id;
@@ -138,10 +157,10 @@ class ProvisioningUpdate extends base_1.default {
138
157
  // if (savedParams) mergeCommandParams(params, savedParams)
139
158
  // }
140
159
  const res = await resSdk.update(attributes, params);
141
- const out = (flags.raw && rawReader) ? rawReader.rawResponse : res;
160
+ const out = flags.raw && rawReader ? rawReader.rawResponse : res;
142
161
  this.printHeaders(rawReader?.headers, flags);
143
162
  this.printOutput(out, flags);
144
- this.log(`\n${cli_core_1.clColor.style.success('Successfully')} updated resource of type ${cli_core_1.clColor.style.resource(resource.type)} with id ${cli_core_1.clColor.style.id(res.id)}\n`);
163
+ this.log(`\n${cli_core_1.clColor.style.success("Successfully")} updated resource of type ${cli_core_1.clColor.style.resource(resource.type)} with id ${cli_core_1.clColor.style.id(res.id)}\n`);
145
164
  // Save command arguments
146
165
  // if (saveCmd) this.saveParams(saveCmd, { type: resource.api }, OPERATION, params)
147
166
  return out;
@@ -149,7 +168,7 @@ class ProvisioningUpdate extends base_1.default {
149
168
  catch (error) {
150
169
  if ((0, lang_1.isRequestInterrupted)(error) && reqReader) {
151
170
  await this.showLiveDocumentation(reqReader.request, undefined, flags);
152
- cl.removeInterceptor('request', reqReader.id);
171
+ cl.removeInterceptor("request", reqReader.id);
153
172
  }
154
173
  else
155
174
  this.printError(error, flags, args);
package/lib/csv.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  declare const formatCsv: (obj: object[], flags?: any) => string;
2
2
  declare const exportCsv: (output: any, flags: any, path: string) => Promise<boolean>;
3
- export { formatCsv, exportCsv };
3
+ export { exportCsv, formatCsv };
package/lib/csv.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.exportCsv = exports.formatCsv = void 0;
5
- const json_2_csv_1 = require("json-2-csv");
6
- const fs_1 = require("fs");
4
+ exports.formatCsv = exports.exportCsv = void 0;
5
+ const node_fs_1 = require("node:fs");
7
6
  const cli_core_1 = require("@commercelayer/cli-core");
7
+ const json_2_csv_1 = require("json-2-csv");
8
8
  const formatCsv = (obj, flags) => {
9
9
  return cli_core_1.clOutput.printCSV(obj, flags);
10
10
  };
@@ -15,30 +15,30 @@ const analyzeItem = (name, item, flags) => {
15
15
  if (Array.isArray(item)) {
16
16
  for (const i of item) {
17
17
  const ks = analyzeItem(name, i, flags);
18
- ks.forEach(k => keys.add(k));
18
+ ks.forEach((k) => { keys.add(k); });
19
19
  }
20
20
  }
21
- else if (typeof item === 'object') {
21
+ else if (typeof item === "object") {
22
22
  const type = item.type;
23
23
  const fields = [];
24
24
  flags.fields.forEach((f) => {
25
- if (!name && (!f.includes('/')))
26
- fields.push(...f.split(','));
27
- else if (type && f.startsWith(type + '/'))
28
- fields.push(...f.substring(f.indexOf('/') + 1).split(','));
25
+ if (!name && !f.includes("/"))
26
+ fields.push(...f.split(","));
27
+ else if (type && f.startsWith(type + "/"))
28
+ fields.push(...f.substring(f.indexOf("/") + 1).split(","));
29
29
  });
30
30
  for (const [k, v] of Object.entries(item)) {
31
31
  // exclude 'type' fields
32
- if (k === 'type')
32
+ if (k === "type")
33
33
  continue;
34
34
  // exclude 'id' fields that are not explicitly included
35
- if ((k === 'id') && !fields.includes(k))
35
+ if (k === "id" && !fields.includes(k))
36
36
  continue;
37
- const ks = analyzeItem(`${name ? name + '.' : ''}${k}`, v, flags);
38
- ks.forEach(k => keys.add(k));
37
+ const ks = analyzeItem(`${name ? name + "." : ""}${k}`, v, flags);
38
+ ks.forEach((k) => { keys.add(k); });
39
39
  }
40
40
  }
41
- else if (name && (name !== 'type') && !name.endsWith('.type')) {
41
+ else if (name && name !== "type" && !name.endsWith(".type")) {
42
42
  // 'type' field can't be included in CLI filter but is always included in API response
43
43
  keys.add(name);
44
44
  }
@@ -48,36 +48,39 @@ const exportCsv = async (output, flags, path) => {
48
48
  // Rename header fields
49
49
  const header = {};
50
50
  if (flags.header) {
51
- flags.header.join(',').split(',').forEach((h) => {
52
- const ft = h.split(':');
51
+ flags.header
52
+ .join(",")
53
+ .split(",")
54
+ .forEach((h) => {
55
+ const ft = h.split(":");
53
56
  header[ft[0]] = ft[1];
54
57
  });
55
58
  }
56
59
  // Include fields
57
60
  const keys = analyzeItem(undefined, output, flags);
58
- const includeKeys = [...keys].map(k => {
61
+ const includeKeys = [...keys].map((k) => {
59
62
  return { field: k, title: header[k] || k };
60
63
  });
61
64
  // Exclude fields
62
65
  const excludeKeys = [];
63
66
  if (flags.fields) {
64
- if (!flags.fields.includes('id'))
65
- excludeKeys.push('id');
66
- if (!flags.fields.includes('type'))
67
- excludeKeys.push('type');
67
+ if (!flags.fields.includes("id"))
68
+ excludeKeys.push("id");
69
+ if (!flags.fields.includes("type"))
70
+ excludeKeys.push("type");
68
71
  }
69
72
  if (flags.include) {
70
73
  const include = [];
71
- flags.include.forEach((i) => include.push(...i.split(',')));
74
+ flags.include.forEach((i) => { include.push(...i.split(",")); });
72
75
  include.forEach((i) => {
73
76
  // excludeKeys.push(`${i}.id`)
74
77
  excludeKeys.push(`${i}.type`);
75
78
  });
76
79
  }
77
80
  // Delimiter
78
- let delimiter = flags.delimiter || ',';
79
- if (delimiter && (delimiter === 'TAB'))
80
- delimiter = '\t';
81
+ let delimiter = flags.delimiter || ",";
82
+ if (delimiter && delimiter === "TAB")
83
+ delimiter = "\t";
81
84
  const csv = (0, json_2_csv_1.json2csv)(output, {
82
85
  excelBOM: true,
83
86
  expandArrayObjects: true,
@@ -85,14 +88,14 @@ const exportCsv = async (output, flags, path) => {
85
88
  sortHeader: false,
86
89
  unwindArrays: true,
87
90
  useDateIso8601Format: true,
88
- emptyFieldValue: '',
91
+ emptyFieldValue: "",
89
92
  // excludeKeys,
90
93
  keys: includeKeys,
91
94
  delimiter: {
92
95
  field: delimiter,
93
96
  },
94
97
  });
95
- (0, fs_1.writeFileSync)(path, csv);
98
+ (0, node_fs_1.writeFileSync)(path, csv);
96
99
  return await Promise.resolve(true);
97
100
  };
98
101
  exports.exportCsv = exportCsv;
@@ -1,4 +1,4 @@
1
- import type { QueryParams } from '@commercelayer/provisioning-sdk';
2
- import { type RequestData } from './request';
1
+ import type { QueryParams } from "@commercelayer/provisioning-sdk";
2
+ import { type RequestData } from "./request";
3
3
  declare const buildCurl: (request: RequestData, _params?: QueryParams) => string;
4
4
  export { buildCurl };
package/lib/lang/curl.js CHANGED
@@ -4,9 +4,11 @@ exports.buildCurl = void 0;
4
4
  const _1 = require(".");
5
5
  const request_1 = require("./request");
6
6
  const headers = (request) => {
7
- return Object.entries((0, request_1.getHeaders)(request)).map(([h, v]) => {
7
+ return Object.entries((0, request_1.getHeaders)(request))
8
+ .map(([h, v]) => {
8
9
  return `-H '${h}: ${v}'`;
9
- }).join(' \\\n ');
10
+ })
11
+ .join(" \\\n ");
10
12
  };
11
13
  const buildCurl = (request, _params) => {
12
14
  let cmd = `curl -g -X ${(0, request_1.getMethod)(request)} \\\n '${(0, _1.getFullUrl)(request)}' \\\n ${headers(request)}`;
@@ -1,7 +1,7 @@
1
- import type { QueryParams } from '@commercelayer/provisioning-sdk';
2
- import type { RequestData } from './request';
3
- export { isRequestInterrupted } from './request';
4
- export * from './request';
1
+ import type { QueryParams } from "@commercelayer/provisioning-sdk";
2
+ import type { RequestData } from "./request";
3
+ export * from "./request";
4
+ export { isRequestInterrupted } from "./request";
5
5
  export declare const availableLanguages: string[];
6
6
  export declare const languageInfo: {
7
7
  curl: {
@@ -16,4 +16,4 @@ export declare const languageInfo: {
16
16
  declare const buildCommand: (lang: string, request: RequestData, params?: QueryParams, flags?: any) => string;
17
17
  declare const getLanguageArg: (flags: any) => string;
18
18
  declare const promptLanguage: () => Promise<string>;
19
- export { getLanguageArg, buildCommand, promptLanguage };
19
+ export { buildCommand, getLanguageArg, promptLanguage };
package/lib/lang/index.js CHANGED
@@ -1,29 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.promptLanguage = exports.buildCommand = exports.getLanguageArg = exports.languageInfo = exports.availableLanguages = exports.isRequestInterrupted = void 0;
3
+ exports.promptLanguage = exports.getLanguageArg = exports.buildCommand = exports.languageInfo = exports.availableLanguages = exports.isRequestInterrupted = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
5
6
  const curl_1 = require("./curl");
6
- const ruby_1 = require("./ruby");
7
7
  const node_1 = require("./node");
8
- const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
8
+ const ruby_1 = require("./ruby");
9
+ tslib_1.__exportStar(require("./request"), exports);
9
10
  var request_1 = require("./request");
10
11
  Object.defineProperty(exports, "isRequestInterrupted", { enumerable: true, get: function () { return request_1.isRequestInterrupted; } });
11
- tslib_1.__exportStar(require("./request"), exports);
12
- exports.availableLanguages = ['curl', 'node'];
12
+ exports.availableLanguages = ["curl", "node"];
13
13
  exports.languageInfo = {
14
- curl: { name: 'cURL', label: 'cURL command' },
15
- node: { name: 'Node', label: 'Node SDK source code' },
14
+ curl: { name: "cURL", label: "cURL command" },
15
+ node: { name: "Node", label: "Node SDK source code" },
16
16
  };
17
17
  const buildCommand = (lang, request, params, flags) => {
18
18
  if (lang)
19
19
  switch (lang.toLowerCase()) {
20
- case 'curl': return (0, curl_1.buildCurl)(request, params);
21
- case 'node': return (0, node_1.buildTypescript)(request, params, flags);
22
- case 'ruby': return (0, ruby_1.buildRuby)(request, params);
23
- default: return '';
20
+ case "curl":
21
+ return (0, curl_1.buildCurl)(request, params);
22
+ case "node":
23
+ return (0, node_1.buildTypescript)(request, params, flags);
24
+ case "ruby":
25
+ return (0, ruby_1.buildRuby)(request, params);
26
+ default:
27
+ return "";
24
28
  }
25
29
  else
26
- return '';
30
+ return "";
27
31
  };
28
32
  exports.buildCommand = buildCommand;
29
33
  const getLanguageArg = (flags) => {
@@ -38,14 +42,18 @@ const getLanguageArg = (flags) => {
38
42
  };
39
43
  exports.getLanguageArg = getLanguageArg;
40
44
  const promptLanguage = async () => {
41
- return await inquirer_1.default.prompt([{
42
- type: 'list',
43
- name: 'language',
44
- message: 'Select a format to show the command live documentation:',
45
- choices: exports.availableLanguages.map(l => {
45
+ return await inquirer_1.default
46
+ .prompt([
47
+ {
48
+ type: "list",
49
+ name: "language",
50
+ message: "Select a format to show the command live documentation:",
51
+ choices: exports.availableLanguages.map((l) => {
46
52
  const info = exports.languageInfo[l];
47
53
  return { name: info.label, value: l, short: info.name };
48
54
  }),
49
- }]).then(answers => answers.language);
55
+ },
56
+ ])
57
+ .then((answers) => answers.language);
50
58
  };
51
59
  exports.promptLanguage = promptLanguage;
@@ -1,4 +1,4 @@
1
- import type { QueryParams } from '@commercelayer/provisioning-sdk';
2
- import type { RequestData } from './request';
1
+ import type { QueryParams } from "@commercelayer/provisioning-sdk";
2
+ import type { RequestData } from "./request";
3
3
  declare const buildTypescript: (request: RequestData, params?: QueryParams, flags?: any) => string;
4
4
  export { buildTypescript };
package/lib/lang/node.js CHANGED
@@ -1,26 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildTypescript = void 0;
4
- const _1 = require(".");
5
4
  const cli_core_1 = require("@commercelayer/cli-core");
5
+ const _1 = require(".");
6
6
  const buildTypescript = (request, params, flags) => {
7
- const hasParams = params && (Object.keys(params).length > 0);
7
+ const hasParams = params && Object.keys(params).length > 0;
8
8
  const operation = (0, _1.getOperation)(request);
9
- const qpSuffix = (operation.name === 'list') ? 'List' : 'Retrieve';
10
- const paramsImport = hasParams ? `, { QueryParams${qpSuffix} }` : '';
9
+ const qpSuffix = operation.name === "list" ? "List" : "Retrieve";
10
+ const paramsImport = hasParams ? `, { QueryParams${qpSuffix} }` : "";
11
11
  let ts = `import commercelayer${paramsImport} from '@commercelayer/provisioning-sdk'`;
12
12
  ts += `\nconst accessToken = '${flags.accessToken}'`;
13
13
  if (flags.domain)
14
14
  ts += `\nconst domain = '${flags.domain}'`;
15
- ts += `\n\nconst cl = commercelayer({ accessToken${flags.domain ? ', domain' : ''} })`;
15
+ ts += `\n\nconst cl = commercelayer({ accessToken${flags.domain ? ", domain" : ""} })`;
16
16
  if (hasParams)
17
17
  ts += `\n\nconst params: QueryParams${qpSuffix} = ${cli_core_1.clOutput.printObject(params, { color: false })}`;
18
18
  const args = [];
19
19
  if (operation.id)
20
20
  args.push(`'${operation.id}'`);
21
21
  if (hasParams)
22
- args.push('params');
23
- ts += `\n\ncl.${operation.resource}.${operation.name}(${args.join(', ')}).then(console.log)`;
22
+ args.push("params");
23
+ ts += `\n\ncl.${operation.resource}.${operation.name}(${args.join(", ")}).then(console.log)`;
24
24
  return ts;
25
25
  };
26
26
  exports.buildTypescript = buildTypescript;
@@ -1,5 +1,5 @@
1
- import { type CommerceLayerProvisioningClient } from '@commercelayer/provisioning-sdk';
2
- import { type KeyValString } from '@commercelayer/cli-core';
1
+ import { type KeyValString } from "@commercelayer/cli-core";
2
+ import { type CommerceLayerProvisioningClient } from "@commercelayer/provisioning-sdk";
3
3
  type RequestData = {
4
4
  baseUrl: string;
5
5
  path: string;
@@ -22,8 +22,8 @@ type RequestReader = {
22
22
  };
23
23
  declare const addRequestReader: (cl: CommerceLayerProvisioningClient, interrupt?: boolean) => RequestReader;
24
24
  declare const isRequestInterrupted: (error: unknown) => boolean;
25
+ export type { OperationData, RequestData, RequestReader };
25
26
  export { addRequestReader, isRequestInterrupted };
26
- export type { RequestReader, RequestData, OperationData };
27
27
  export declare const getMethod: (request: RequestData) => string;
28
28
  export declare const getFullUrl: (request: RequestData) => string;
29
29
  export declare const getResource: (request: RequestData) => string;