@contrail/cli 3.6.0-alpha-8-alpha.c613d8e → 3.6.0-alpha-8-alpha.2ba81bf

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.
@@ -4,13 +4,17 @@ export default class DeleteEntity extends BaseCommand {
4
4
  static examples: string[];
5
5
  static flags: {
6
6
  dryRun: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
- input: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
- id: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ inputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ suffix: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
10
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
11
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
12
  };
12
13
  static args: {
13
14
  entityName: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
15
+ ids: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
14
16
  };
17
+ static strict: boolean;
18
+ init(): Promise<void>;
15
19
  run(): Promise<void>;
16
20
  }
@@ -6,27 +6,37 @@ const p_limit_1 = tslib_1.__importDefault(require("p-limit"));
6
6
  const basecommand_1 = require("../../basecommand");
7
7
  const sdk_1 = require("@contrail/sdk");
8
8
  const login_1 = require("../../auth/login");
9
+ const common_1 = require("../../common");
9
10
  const file_helpers_1 = require("../../helpers/file-helpers");
10
11
  let IS_DRY_RUN = false;
11
12
  class DeleteEntity extends basecommand_1.BaseCommand {
12
- static description = '(BETA) Delete an entity';
13
- static examples = ['contrail entities delete color 123'];
13
+ static description = 'Delete entities by id';
14
+ static examples = [
15
+ 'contrail entities delete color 123',
16
+ 'contrail entities delete color id1 id2 id3',
17
+ 'contrail entities delete item -i ids.json',
18
+ ];
14
19
  static flags = {
15
20
  ...basecommand_1.BaseCommand.baseFlags,
16
21
  dryRun: core_1.Flags.boolean({
17
22
  char: 'd',
18
- description: 'If true, does not delete the entity but simulates the deletion',
23
+ description: 'If true, does not delete the entities but simulates the deletion',
19
24
  required: false,
20
25
  default: false,
21
26
  }),
22
- input: core_1.Flags.string({
27
+ inputFile: core_1.Flags.string({
23
28
  char: 'i',
24
- description: 'A JSON array of objects where each object is one entity to create. Cannot be used with --count. Unless --precise is specified, any missing values will be populated with random values.',
29
+ description: "A file with a JSON array of objects; only each object's id is used. Deletes every entity in the file.",
25
30
  required: false,
26
31
  multiple: false,
27
32
  }),
28
- id: core_1.Flags.string({
29
- description: 'The unique identifier of the entity',
33
+ suffix: core_1.Flags.string({
34
+ description: 'Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets /<entities>/synchronous)',
35
+ required: false,
36
+ }),
37
+ apiVersion: core_1.Flags.string({
38
+ description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
39
+ options: ['1', '2'],
30
40
  required: false,
31
41
  }),
32
42
  };
@@ -35,84 +45,93 @@ class DeleteEntity extends basecommand_1.BaseCommand {
35
45
  description: 'The name of the entity type to delete',
36
46
  required: true,
37
47
  }),
48
+ ids: core_1.Args.string({
49
+ description: 'One or more entity ids to delete',
50
+ required: false,
51
+ }),
38
52
  };
53
+ static strict = false;
54
+ async init() {
55
+ (0, common_1.routeConsoleLogToStderr)();
56
+ await super.init();
57
+ }
39
58
  async run() {
40
- this.log('🚨 This command is in BETA and may change or be removed at any time.');
41
59
  await (0, login_1.authUser)();
42
- const { args, flags } = await this.parse(DeleteEntity);
60
+ const { args, flags, argv } = await this.parse(DeleteEntity);
43
61
  const { entityName } = args;
44
- const { id, input: inputFilename } = flags;
62
+ const { inputFile: inputFilename, suffix, apiVersion } = flags;
45
63
  if (flags.dryRun) {
46
64
  IS_DRY_RUN = true;
47
- this.log('Running in dry run mode. No entities will be deleted.');
65
+ console.error('Running in dry run mode. No entities will be deleted.');
66
+ }
67
+ const tokens = argv.slice(1);
68
+ const valueTokens = tokens.filter((token) => token.includes('='));
69
+ if (valueTokens.length > 0) {
70
+ this.error(`delete takes no -- values (got: ${valueTokens.join(' ')}); pass ids positionally or use an input file (-i).`);
71
+ }
72
+ const positionalIds = tokens;
73
+ if (inputFilename && positionalIds.length > 0) {
74
+ this.error('You cannot use --inputFile and positional ids together. Please specify one or the other.');
75
+ }
76
+ if (!inputFilename && positionalIds.length === 0) {
77
+ this.error('You must provide one or more ids or an input file (-i) of entities to delete.');
48
78
  }
49
79
  const jsonInput = inputFilename ? (0, file_helpers_1.parseFileAsJsonArray)(inputFilename) : undefined;
50
- if (!jsonInput && !id) {
51
- this.error('You must provide either an ID or a JSON input file with entities to delete.');
80
+ const rowsWithId = jsonInput?.filter((item) => item.id);
81
+ if (jsonInput && rowsWithId.length < jsonInput.length) {
82
+ console.error(`${jsonInput.length - rowsWithId.length} row(s) without an id were skipped.`);
52
83
  }
53
- const ids = jsonInput ? jsonInput.map((item) => item.id) : [id];
84
+ const ids = rowsWithId ? rowsWithId.map((item) => item.id) : positionalIds;
54
85
  try {
55
- const response = await deleteEntityByIds(entityName, ids);
86
+ const response = await deleteEntityByIds(entityName, ids, {
87
+ suffix,
88
+ apiVersion: apiVersion,
89
+ });
56
90
  if (IS_DRY_RUN) {
57
- this.log('simulated deletion of entities:');
91
+ console.error('simulated deletion of entities:');
58
92
  }
59
93
  else {
60
- this.log('deleted entities:');
94
+ console.error('deleted entities:');
61
95
  }
62
96
  this.log(JSON.stringify(response, null, 2));
97
+ if (response.failed.length > 0) {
98
+ console.error(`${response.failed.length} of ${ids.length} deletes failed.`);
99
+ process.exitCode = 1;
100
+ }
63
101
  }
64
102
  catch (e) {
65
- this.error(`Error fetching entity: ${e.message}`);
103
+ this.error(`Error deleting entities: ${e.message}`);
66
104
  }
67
105
  }
68
106
  }
69
107
  exports.default = DeleteEntity;
70
- async function deleteEntityByIds(entityName, ids) {
71
- const idsDeleted = new Set();
72
- const idsNotFound = new Set();
73
- const idsErrored = new Set();
108
+ async function deleteEntityByIds(entityName, ids, routing = {}) {
109
+ const deletedIds = [];
110
+ const notFoundIds = [];
111
+ const failed = [];
74
112
  const limit = (0, p_limit_1.default)(10);
75
- const deletePromises = ids.map((id) => limit(() => deleteEntityById(entityName, id).then((entity) => {
113
+ const deletePromises = ids.map((id) => limit(() => deleteEntityById(entityName, id, routing).then((entity) => {
76
114
  if (!entity) {
77
- idsNotFound.add(id);
78
- return null;
115
+ notFoundIds.push(id);
116
+ return;
79
117
  }
80
- idsDeleted.add(id);
81
- return entity;
118
+ deletedIds.push(id);
82
119
  }, (error) => {
83
- if (error.message.includes('not found')) {
84
- idsNotFound.add(id);
120
+ if (error.message?.includes('not found')) {
121
+ notFoundIds.push(id);
85
122
  }
86
123
  else {
87
- idsErrored.add(id);
124
+ failed.push({ id, error: (0, common_1.sdkErrorMessage)(error) });
88
125
  }
89
- return null;
90
126
  })));
91
127
  await Promise.all(deletePromises);
92
- return {
93
- idsDeleted: Array.from(idsDeleted),
94
- idsNotFound: Array.from(idsNotFound),
95
- idsErrored: Array.from(idsErrored),
96
- };
128
+ return { deletedIds, notFoundIds, failed };
97
129
  }
98
- async function deleteEntityById(entityName, id) {
130
+ async function deleteEntityById(entityName, id, routing = {}) {
99
131
  const client = new sdk_1.Entities();
100
132
  if (IS_DRY_RUN) {
101
- return client.get({ entityName, id, ignore404: true }).catch(throwIfNot404);
133
+ return client.get({ entityName, id, ignore404: true });
102
134
  }
103
- return client.delete({ entityName, id, ignore404: true }).catch(throwIfNot404);
104
- }
105
- function throwIfNot404(e) {
106
- const { statusCode } = parseSDKErrorMessage(e);
107
- if (statusCode === 404) {
108
- return null;
109
- }
110
- throw e;
111
- }
112
- function parseSDKErrorMessage(e) {
113
- const parsed = JSON.parse(e.details);
114
- return {
115
- statusCode: parsed.statusCode,
116
- message: parsed.message,
117
- };
135
+ const { suffix, apiVersion } = routing;
136
+ return client.delete({ entityName, id, ignore404: true, suffix, apiVersion });
118
137
  }
@@ -10,12 +10,16 @@ export default class GetEntity extends BaseCommand {
10
10
  skipHydrateRelationships: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
11
  take: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
12
  relations: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
+ suffix: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
14
+ apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
15
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
14
16
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
15
17
  };
16
18
  static args: {
17
19
  typePath: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
20
+ ids: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
18
21
  };
19
22
  static strict: boolean;
23
+ init(): Promise<void>;
20
24
  run(): Promise<void>;
21
25
  }
@@ -6,14 +6,17 @@ const core_1 = require("@oclif/core");
6
6
  const basecommand_1 = require("../../basecommand");
7
7
  const sdk_1 = require("@contrail/sdk");
8
8
  const login_1 = require("../../auth/login");
9
+ const common_1 = require("../../common");
9
10
  const types_1 = require("../../api/types");
10
11
  const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
11
12
  const batchFetch_1 = require("../../helpers/entities/batchFetch");
12
13
  let SHOULD_USE_PAGINATED_FIND = false;
13
14
  let MAX_NUMBER_OF_ENTITIES_TO_FETCH = undefined;
14
15
  class GetEntity extends basecommand_1.BaseCommand {
15
- static description = '(BETA) Get an entity';
16
+ static description = 'Get an entity';
16
17
  static examples = [
18
+ 'contrail entities get color 123',
19
+ 'contrail entities get color id1 id2 id3',
17
20
  'contrail entities get color -- id=123',
18
21
  'contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16',
19
22
  'contrail entities get orders -- updatedAt=2025-09-15T04:00:00Z..',
@@ -59,28 +62,56 @@ class GetEntity extends basecommand_1.BaseCommand {
59
62
  description: 'Comma-separated list of relations to include in the output',
60
63
  required: false,
61
64
  }),
65
+ suffix: core_1.Flags.string({
66
+ description: 'Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets /<entities>/synchronous)',
67
+ required: false,
68
+ }),
69
+ apiVersion: core_1.Flags.string({
70
+ description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
71
+ options: ['1', '2'],
72
+ required: false,
73
+ }),
62
74
  };
63
75
  static args = {
64
76
  typePath: core_1.Args.string({
65
77
  description: 'The name of the entity type to fetch',
66
78
  required: true,
67
79
  }),
80
+ ids: core_1.Args.string({
81
+ description: 'One or more entity ids; shorthand for the id/ids criteria',
82
+ required: false,
83
+ }),
68
84
  };
69
85
  static strict = false;
86
+ async init() {
87
+ (0, common_1.routeConsoleLogToStderr)();
88
+ await super.init();
89
+ }
70
90
  async run() {
71
- this.log('🚨 This command is in BETA and may change or be removed at any time.');
72
91
  await (0, login_1.authUser)();
73
92
  const { args, flags, argv } = await this.parse(GetEntity);
74
93
  const { typePath } = args;
75
- const { outputFile, paginated: shouldUsePaginatedFind, propertySlugs, relations: relationString, skip, skipHydrateRelationships, take, } = flags;
94
+ const { outputFile, paginated: shouldUsePaginatedFind, propertySlugs, relations: relationString, skip, skipHydrateRelationships, suffix, apiVersion, take, } = flags;
76
95
  SHOULD_USE_PAGINATED_FIND = shouldUsePaginatedFind;
77
96
  MAX_NUMBER_OF_ENTITIES_TO_FETCH = take;
78
97
  if (MAX_NUMBER_OF_ENTITIES_TO_FETCH)
79
- console.log(`Will limit output to ${MAX_NUMBER_OF_ENTITIES_TO_FETCH} entities.`);
80
- const propertySpecificationArgs = argv
81
- .slice(1, argv.length)
82
- .filter(propertySpecifications_1.isValidPropertySpecification);
83
- const propertySpecBySlug = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(propertySpecificationArgs);
98
+ console.error(`Will limit output to ${MAX_NUMBER_OF_ENTITIES_TO_FETCH} entities.`);
99
+ const { ids: positionalIds, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(argv.slice(1));
100
+ const propertySpecBySlug = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
101
+ if (positionalIds.length > 0) {
102
+ if (propertySpecBySlug.has('id') || propertySpecBySlug.has('ids')) {
103
+ this.error('Pass ids positionally or as -- id=/ids= criteria, not both.');
104
+ }
105
+ if (propertySpecBySlug.size > 0) {
106
+ this.error('Positional ids cannot be combined with other -- criteria. Use -- ids= alongside the other criteria instead.');
107
+ }
108
+ if (positionalIds.length === 1) {
109
+ propertySpecBySlug.set('id', positionalIds[0]);
110
+ }
111
+ else {
112
+ propertySpecBySlug.set('ids', positionalIds);
113
+ }
114
+ }
84
115
  const relations = relationString
85
116
  ? relationString
86
117
  .split(',')
@@ -101,6 +132,8 @@ class GetEntity extends basecommand_1.BaseCommand {
101
132
  criteria: convertPropertySpecIntoCriteria(propertySpecBySlug),
102
133
  skipHydrateRelationships,
103
134
  skip,
135
+ suffix,
136
+ apiVersion: apiVersion,
104
137
  relations,
105
138
  propertySlugs: propertySlugsArray,
106
139
  });
@@ -115,7 +148,7 @@ class GetEntity extends basecommand_1.BaseCommand {
115
148
  }
116
149
  writer.write('\n]\n');
117
150
  if (outputFile)
118
- this.log(`Output saved to ${outputFile}`);
151
+ console.error(`Output saved to ${outputFile}`);
119
152
  }
120
153
  else {
121
154
  const response = await getEntityByTypePath(typePath, propertySpecBySlug, {
@@ -123,11 +156,16 @@ class GetEntity extends basecommand_1.BaseCommand {
123
156
  relations,
124
157
  propertySlugs: propertySlugsArray,
125
158
  skip,
159
+ suffix,
160
+ apiVersion: apiVersion,
126
161
  take,
127
162
  });
163
+ if (response === null) {
164
+ this.error(`Entity not found: ${propertySpecBySlug.get('id')}`, { exit: 1 });
165
+ }
128
166
  if (outputFile) {
129
167
  fs_1.default.writeFileSync(outputFile, JSON.stringify(response, null, 2));
130
- this.log(`Output saved to ${outputFile}`);
168
+ console.error(`Output saved to ${outputFile}`);
131
169
  }
132
170
  else {
133
171
  this.log(JSON.stringify(response, null, 2));
@@ -135,13 +173,16 @@ class GetEntity extends basecommand_1.BaseCommand {
135
173
  }
136
174
  }
137
175
  catch (e) {
176
+ if (e.message?.startsWith('Entity not found:')) {
177
+ throw e;
178
+ }
138
179
  this.error(`Error fetching entity: ${e.message}`);
139
180
  }
140
181
  }
141
182
  }
142
183
  exports.default = GetEntity;
143
184
  async function getEntityByTypePath(typePath, propertySpec, options = {}) {
144
- const { propertySlugs, relations, skipHydrateRelationships, skip, take } = options;
185
+ const { propertySlugs, relations, skipHydrateRelationships, skip, suffix, apiVersion, take } = options;
145
186
  const id = propertySpec?.get('id')?.toString() || undefined;
146
187
  const criteria = convertPropertySpecIntoCriteria(propertySpec || new Map());
147
188
  const { root: entityName } = (0, types_1.parseTypePath)(typePath);
@@ -150,11 +191,15 @@ async function getEntityByTypePath(typePath, propertySpec, options = {}) {
150
191
  }
151
192
  return find(entityName, {
152
193
  id,
194
+ // a missing id returns null (no retries); the command turns it into a clean not-found error
195
+ ignore404: id !== undefined,
153
196
  skipHydrateRelationships,
154
197
  relations,
155
198
  propertySlugs,
156
199
  criteria,
157
200
  skip,
201
+ suffix,
202
+ apiVersion,
158
203
  take,
159
204
  });
160
205
  }
@@ -167,19 +212,24 @@ function convertPropertySpecIntoCriteria(propertySpec) {
167
212
  }
168
213
  async function find(entityName, options = {}) {
169
214
  const client = new sdk_1.Entities();
170
- const { criteria, id, propertySlugs, skipHydrateRelationships, relations, skip, take } = options;
215
+ const { criteria, id, ignore404, propertySlugs, skipHydrateRelationships, relations, skip, suffix, apiVersion, take, } = options;
171
216
  const queryOptions = {
172
217
  entityName,
218
+ ignore404,
173
219
  skipHydrateRelationships,
174
220
  relations,
175
221
  skip,
222
+ suffix,
223
+ apiVersion,
176
224
  take,
177
225
  };
178
226
  if (propertySlugs && propertySlugs.length > 0) {
179
227
  queryOptions.customParams = { propertySlugs: propertySlugs.join(',') };
180
228
  }
181
229
  const payload = id ? { id, ...queryOptions } : { criteria, ...queryOptions };
182
- if ((0, batchFetch_1.canBatchFetchEntity)(entityName)) {
230
+ // a suffix names a specific sub-route and an id names one entity; both always go
231
+ // through the plain client (batch-fetch only understands criteria)
232
+ if ((0, batchFetch_1.canBatchFetchEntity)(entityName) && !suffix && !id) {
183
233
  return (0, batchFetch_1.batchFetch)(entityName, payload);
184
234
  }
185
235
  else {
@@ -195,7 +245,8 @@ async function* streamPaginatedFind(typePath, options = {}) {
195
245
  const opts = {
196
246
  ...options,
197
247
  entityName,
198
- apiVersion: sdk_1.API_VERSION.V2,
248
+ // paginated reads require the V2 response shape unless overridden
249
+ apiVersion: options.apiVersion ?? sdk_1.API_VERSION.V2,
199
250
  nextPageKey,
200
251
  };
201
252
  if (options.propertySlugs?.length > 0) {
@@ -212,7 +263,7 @@ async function* streamPaginatedFind(typePath, options = {}) {
212
263
  if (MAX_NUMBER_OF_ENTITIES_TO_FETCH && count >= MAX_NUMBER_OF_ENTITIES_TO_FETCH)
213
264
  return;
214
265
  }
215
- console.log(`Fetched ${count} entities`);
266
+ console.error(`Fetched ${count} entities`);
216
267
  if (!nextPageKey || results.length === 0)
217
268
  return;
218
269
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const create_1 = tslib_1.__importDefault(require("./create"));
5
+ const get_1 = tslib_1.__importDefault(require("./get"));
6
+ const update_1 = tslib_1.__importDefault(require("./update"));
7
+ const delete_1 = tslib_1.__importDefault(require("./delete"));
8
+ const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
9
+ describe('entities command grammar: entities <verb> <typePath> [ID...]', () => {
10
+ describe('partitionIdsAndSpecs', () => {
11
+ it('should treat tokens without an equals sign as ids', () => {
12
+ const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(['id1', 'id2', 'id3']);
13
+ expect(ids).toEqual(['id1', 'id2', 'id3']);
14
+ expect(specs).toEqual([]);
15
+ });
16
+ it('should treat slug=value tokens as property specifications', () => {
17
+ const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(['name=jet', 'hex=000000']);
18
+ expect(ids).toEqual([]);
19
+ expect(specs).toEqual(['name=jet', 'hex=000000']);
20
+ });
21
+ it('should split mixed tokens preserving order within each group', () => {
22
+ const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(['id1', 'name=jet', 'id2', 'status=archived']);
23
+ expect(ids).toEqual(['id1', 'id2']);
24
+ expect(specs).toEqual(['name=jet', 'status=archived']);
25
+ });
26
+ it('should not classify malformed specs as ids', () => {
27
+ const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(['=value']);
28
+ expect(ids).toEqual([]);
29
+ expect(specs).toEqual([]);
30
+ });
31
+ it('should handle empty input', () => {
32
+ const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)([]);
33
+ expect(ids).toEqual([]);
34
+ expect(specs).toEqual([]);
35
+ });
36
+ });
37
+ describe('positional id arguments', () => {
38
+ it('should accept variadic positional ids on get', () => {
39
+ expect(get_1.default.strict).toBe(false);
40
+ expect(get_1.default.args.ids).toBeDefined();
41
+ });
42
+ it('should accept variadic positional ids on update with no single id arg', () => {
43
+ expect(update_1.default.strict).toBe(false);
44
+ expect(update_1.default.args.ids).toBeDefined();
45
+ expect(update_1.default.args.id).toBeUndefined();
46
+ });
47
+ it('should accept variadic positional ids on delete with no --id flag', () => {
48
+ expect(delete_1.default.strict).toBe(false);
49
+ expect(delete_1.default.args.ids).toBeDefined();
50
+ expect(delete_1.default.flags.id).toBeUndefined();
51
+ });
52
+ });
53
+ describe('flag alignment across verbs', () => {
54
+ it('should name the input file -i, --inputFile on every verb that accepts one', () => {
55
+ expect(create_1.default.flags.inputFile.char).toBe('i');
56
+ expect(update_1.default.flags.inputFile.char).toBe('i');
57
+ expect(delete_1.default.flags.inputFile.char).toBe('i');
58
+ expect(delete_1.default.flags.input).toBeUndefined();
59
+ });
60
+ it('should map skipHydrateRelationships to -S on every verb', () => {
61
+ expect(create_1.default.flags.skipHydrateRelationships.char).toBe('S');
62
+ expect(get_1.default.flags.skipHydrateRelationships.char).toBe('S');
63
+ expect(update_1.default.flags.skipHydrateRelationships.char).toBe('S');
64
+ });
65
+ it('should keep -s for --skip on get', () => {
66
+ expect(get_1.default.flags.skip.char).toBe('s');
67
+ });
68
+ it('should expose --suffix on every verb to reach entity sub-routes', () => {
69
+ expect(create_1.default.flags.suffix).toBeDefined();
70
+ expect(get_1.default.flags.suffix).toBeDefined();
71
+ expect(update_1.default.flags.suffix).toBeDefined();
72
+ expect(delete_1.default.flags.suffix).toBeDefined();
73
+ });
74
+ it('should expose --apiVersion on every verb, constrained to 1 or 2', () => {
75
+ for (const command of [create_1.default, get_1.default, update_1.default, delete_1.default]) {
76
+ expect(command.flags.apiVersion.options).toEqual(['1', '2']);
77
+ }
78
+ });
79
+ });
80
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const create_1 = require("./create");
4
+ const update_1 = require("./update");
5
+ const fulfilled = (value) => ({ status: 'fulfilled', value });
6
+ const rejected = (message) => ({
7
+ status: 'rejected',
8
+ reason: new Error(message),
9
+ });
10
+ describe('mutation output summaries', () => {
11
+ describe('summarizeSettledCreates', () => {
12
+ it('should put every fulfilled result under created', () => {
13
+ const inputs = [{ name: 'a' }, { name: 'b' }];
14
+ const summary = (0, create_1.summarizeSettledCreates)(inputs, [
15
+ fulfilled({ id: '1', name: 'a' }),
16
+ fulfilled({ id: '2', name: 'b' }),
17
+ ]);
18
+ expect(summary.created).toEqual([
19
+ { id: '1', name: 'a' },
20
+ { id: '2', name: 'b' },
21
+ ]);
22
+ expect(summary.failed).toEqual([]);
23
+ });
24
+ it('should pair each failed input with its error so it can be retried as-is', () => {
25
+ const inputs = [{ itemId: 'itm-1' }, { itemId: 'itm-41x' }, { itemId: 'itm-3' }];
26
+ const summary = (0, create_1.summarizeSettledCreates)(inputs, [
27
+ fulfilled({ id: 'ai-1' }),
28
+ rejected('Item with ID itm-41x does not exist'),
29
+ fulfilled({ id: 'ai-3' }),
30
+ ]);
31
+ expect(summary.created).toEqual([{ id: 'ai-1' }, { id: 'ai-3' }]);
32
+ expect(summary.failed).toEqual([
33
+ { input: { itemId: 'itm-41x' }, error: 'Item with ID itm-41x does not exist' },
34
+ ]);
35
+ });
36
+ it('should fall back to details when the SDK error message is empty', () => {
37
+ const sdkError = Object.assign(new Error(''), {
38
+ details: '{"message":"Assortment not found.","statusCode":404}',
39
+ });
40
+ const summary = (0, create_1.summarizeSettledCreates)([{ assortmentId: 'bogus' }], [{ status: 'rejected', reason: sdkError }]);
41
+ expect(summary.failed[0].error).toBe('{"message":"Assortment not found.","statusCode":404}');
42
+ });
43
+ it('should stringify reasons that are not Errors', () => {
44
+ const summary = (0, create_1.summarizeSettledCreates)([{ name: 'a' }], [{ status: 'rejected', reason: 'boom' }]);
45
+ expect(summary.failed).toEqual([{ input: { name: 'a' }, error: 'boom' }]);
46
+ });
47
+ it('should handle empty input', () => {
48
+ expect((0, create_1.summarizeSettledCreates)([], [])).toEqual({ created: [], failed: [] });
49
+ });
50
+ });
51
+ describe('summarizeSettledUpdates', () => {
52
+ it('should report updated, failed, and skipped without stopping on failures', () => {
53
+ const inputs = [{ id: 'id1' }, { id: 'id2' }, { id: 'id3' }];
54
+ const summary = (0, update_1.summarizeSettledUpdates)(inputs, [
55
+ fulfilled({ id: 'id1', status: 'archived' }),
56
+ rejected('Entity not found.'),
57
+ fulfilled({ id: 'id3', status: 'archived' }),
58
+ ], 2);
59
+ expect(summary.updated).toEqual([
60
+ { id: 'id1', status: 'archived' },
61
+ { id: 'id3', status: 'archived' },
62
+ ]);
63
+ expect(summary.failed).toEqual([{ id: 'id2', error: 'Entity not found.' }]);
64
+ expect(summary.skipped).toBe(2);
65
+ });
66
+ it('should not report a failed id as updated', () => {
67
+ const summary = (0, update_1.summarizeSettledUpdates)([{ id: 'id1' }], [rejected('boom')], 0);
68
+ expect(summary.updated).toEqual([]);
69
+ expect(summary.failed).toEqual([{ id: 'id1', error: 'boom' }]);
70
+ });
71
+ });
72
+ });
@@ -6,14 +6,27 @@ export default class UpdateEntity extends BaseCommand {
6
6
  skipHydrateRelationships: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
7
  dryRun: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
8
  inputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
- force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
+ suffix: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
11
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
12
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
13
  };
13
14
  static args: {
14
15
  entityName: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
15
- id: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
16
+ ids: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
16
17
  };
17
18
  static strict: boolean;
19
+ init(): Promise<void>;
18
20
  run(): Promise<void>;
19
21
  }
22
+ export type UpdateSummary = {
23
+ updated: any[];
24
+ failed: {
25
+ id: string;
26
+ error: string;
27
+ }[];
28
+ skipped: number;
29
+ };
30
+ export declare function summarizeSettledUpdates(inputs: {
31
+ id: string;
32
+ }[], settled: PromiseSettledResult<any>[], skipped: number): UpdateSummary;