@contrail/cli 3.6.0-alpha-8-alpha.5ffe1e1 → 3.6.0-alpha-8-alpha.e2d1830

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
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
17
17
  $ contrail COMMAND
18
18
  running command...
19
19
  $ contrail (--version)
20
- @contrail/cli/3.6.0-alpha-8-alpha.5ffe1e1 linux-x64 node-v24.22.2
20
+ @contrail/cli/3.6.0-alpha-8-alpha.e2d1830 linux-x64 node-v24.22.2
21
21
  $ contrail --help [COMMAND]
22
22
  USAGE
23
23
  $ contrail COMMAND
@@ -583,17 +583,17 @@ EXAMPLES
583
583
 
584
584
  $ contrail entities create color -- name="Electric Blue" green=1 red=2 blue=3 # creates one color with specified properties only
585
585
 
586
- $ contrail entities create custom-entities:franchise
586
+ $ contrail entities create custom-entity:franchise
587
587
 
588
- $ contrail entities create project-item -n=1 -- projectId=abc # creates 10 project items within project ABC
588
+ $ contrail entities create project-item -n=10 -- projectId=abc # creates 10 project items within project ABC
589
589
 
590
590
  $ contrail entities create color -g -r # creates a random color with a human readable ID
591
591
 
592
592
  $ contrail entities create color -d -- name=test # simulates the creation of a color without actually creating it
593
593
 
594
- $ contrail entities create custom-entity:franchise -s # creates an entity and the response does not contain hydrating relationships
594
+ $ contrail entities create custom-entity:franchise -S # creates an entity and the response does not contain hydrated relationships
595
595
 
596
- $ contrail entities create color -g -- name=Electric Blue # creates a color with the name specified and other properties auto-generated
596
+ $ contrail entities create color -g -- name="Electric Blue" # creates a color with the name specified and other properties auto-generated
597
597
 
598
598
  $ contrail entities create color -o /tmp/colors.json -- name=Blue green=1 red=2 blue=3 # creates a color and saves the output to /tmp/colors.json
599
599
  ```
@@ -144,12 +144,12 @@ class CreateEntity extends basecommand_1.BaseCommand {
144
144
  static examples = [
145
145
  'contrail entities create color -g -n=10 # creates 10 random colors',
146
146
  'contrail entities create color -- name="Electric Blue" green=1 red=2 blue=3 # creates one color with specified properties only',
147
- 'contrail entities create custom-entities:franchise',
148
- 'contrail entities create project-item -n=1 -- projectId=abc # creates 10 project items within project ABC',
147
+ 'contrail entities create custom-entity:franchise',
148
+ 'contrail entities create project-item -n=10 -- projectId=abc # creates 10 project items within project ABC',
149
149
  'contrail entities create color -g -r # creates a random color with a human readable ID',
150
150
  'contrail entities create color -d -- name=test # simulates the creation of a color without actually creating it',
151
- 'contrail entities create custom-entity:franchise -s # creates an entity and the response does not contain hydrating relationships',
152
- 'contrail entities create color -g -- name=Electric Blue # creates a color with the name specified and other properties auto-generated',
151
+ 'contrail entities create custom-entity:franchise -S # creates an entity and the response does not contain hydrated relationships',
152
+ 'contrail entities create color -g -- name="Electric Blue" # creates a color with the name specified and other properties auto-generated',
153
153
  'contrail entities create color -o /tmp/colors.json -- name=Blue green=1 red=2 blue=3 # creates a color and saves the output to /tmp/colors.json',
154
154
  ];
155
155
  static flags = {
@@ -247,6 +247,10 @@ class CreateEntity extends basecommand_1.BaseCommand {
247
247
  if (count !== undefined && count <= 0) {
248
248
  this.error('Count must be a positive integer.');
249
249
  }
250
+ const unknownSubtype = await findUnknownSubtypeError(entityTypePath);
251
+ if (unknownSubtype) {
252
+ this.error(unknownSubtype);
253
+ }
250
254
  const partialEntities = inputFilename
251
255
  ? (0, file_helpers_1.parseFileAsJsonArray)(inputFilename)
252
256
  : Array.from({ length: count || 1 }).fill({});
@@ -314,14 +318,27 @@ async function createEntities(entityName, entities, routing = {}) {
314
318
  const settled = await Promise.allSettled(entities.map(async (e) => limit(() => createEntity(entityName, e, routing))));
315
319
  return summarizeSettledCreates(entities, settled);
316
320
  }
321
+ /**
322
+ * A subtype that does not exist under a type-managed root would otherwise be dropped,
323
+ * creating a root entity instead. The API cannot catch that, because the request it
324
+ * receives is a valid root create. A root that does not exist is left to the API.
325
+ */
326
+ async function findUnknownSubtypeError(entityTypePath) {
327
+ const { root } = (0, types_2.parseTypePath)(entityTypePath);
328
+ if (root === entityTypePath || (await (0, types_3.getTypeByPath)(entityTypePath))) {
329
+ return undefined;
330
+ }
331
+ return (await (0, types_3.getTypeByPath)(root))
332
+ ? `Type not found for path: ${entityTypePath}. The root ${root} exists, so this subtype is misspelled or missing.`
333
+ : undefined;
334
+ }
317
335
  async function buildEntitiesToCreate(entityTypePath, entities, propertySpecificationBySlug) {
318
336
  let type = await (0, types_3.getTypeByPath)(entityTypePath);
319
337
  if (!type) {
320
338
  console.warn(`Type not found for path: ${entityTypePath}`);
321
- type = {
322
- typePath: '',
323
- typeProperties: [],
324
- }; // Fallback to an empty type; This allows us to create entities that are not type-managed
339
+ // an untyped entity such as a webhook has no type record; keep the requested path
340
+ // so the root still resolves for the generated-value lookups
341
+ type = { typePath: entityTypePath, typeProperties: [] };
325
342
  }
326
343
  const [typesCache, objectReferencesCache] = await Promise.all([
327
344
  (0, types_2.buildLocalTypesCache)([...(0, types_2.getReferencedTypePaths)(type), entityTypePath]),
@@ -461,7 +478,7 @@ function pickRandomValueForProperty(property, objectReferencesCache, typeReferen
461
478
  case types_1.PropertyType.MultiSelect:
462
479
  if (!property.options)
463
480
  throw new Error('Option set is required for MultiSelect property');
464
- const randomSelection = pickRandomOptions(property.options, Math.max(2, property.options.length)); // Avoid picking more than the number of options
481
+ const randomSelection = pickRandomOptions(property.options, 1 + Math.floor(Math.random() * property.options.length));
465
482
  return randomSelection.map((option) => option.value);
466
483
  case types_1.PropertyType.Sequence:
467
484
  return generateRandomNumber();
@@ -493,7 +510,7 @@ function pickRandomValueForProperty(property, objectReferencesCache, typeReferen
493
510
  }
494
511
  exports.pickRandomValueForProperty = pickRandomValueForProperty;
495
512
  function pickRandomOptions(options, count) {
496
- const shuffled = options.sort(() => 0.5 - Math.random());
513
+ const shuffled = [...options].sort(() => 0.5 - Math.random());
497
514
  return shuffled.slice(0, count);
498
515
  }
499
516
  function generateRandomBooleanValue() {
@@ -550,3 +550,32 @@ describe('pickRandomPropertyValues', () => {
550
550
  expect((0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], undefined, new Set(['users']))).toEqual({});
551
551
  });
552
552
  });
553
+ describe('MultiSelect generation', () => {
554
+ const caches = [new Map(), new Map()];
555
+ const options = ['na', 'active', 'big', 'classic', 'custom', 'pro'].map((value) => ({ value }));
556
+ it('picks a real subset rather than every option', () => {
557
+ const property = {
558
+ slug: 'tags',
559
+ propertyType: types_1.PropertyType.MultiSelect,
560
+ propertyLevel: types_1.PropertyLevel.ALL,
561
+ options,
562
+ };
563
+ const counts = new Set(Array.from({ length: 40 }, () => (0, create_1.pickRandomValueForProperty)(property, caches[0], caches[1]).length));
564
+ expect(Math.max(...counts)).toBeLessThanOrEqual(options.length);
565
+ expect(Math.min(...counts)).toBeGreaterThan(0);
566
+ expect(counts.size).toBeGreaterThan(1);
567
+ });
568
+ it('does not reorder the option list it was given', () => {
569
+ const property = {
570
+ slug: 'tags',
571
+ propertyType: types_1.PropertyType.MultiSelect,
572
+ propertyLevel: types_1.PropertyLevel.ALL,
573
+ options,
574
+ };
575
+ const before = options.map((option) => option.value);
576
+ for (let i = 0; i < 20; i++) {
577
+ (0, create_1.pickRandomValueForProperty)(property, caches[0], caches[1]);
578
+ }
579
+ expect(options.map((option) => option.value)).toEqual(before);
580
+ });
581
+ });
@@ -250,7 +250,7 @@ async function find(entityName, options = {}) {
250
250
  // a suffix names a specific sub-route and an id names one entity; both always go
251
251
  // through the plain client (batch-fetch only understands criteria)
252
252
  if ((0, batchFetch_1.canBatchFetchEntity)(entityName) && !suffix && !id) {
253
- return (0, batchFetch_1.batchFetch)(entityName, payload);
253
+ return (0, batchFetch_1.batchFetch)(entityName, { ...payload, propertySlugs });
254
254
  }
255
255
  else {
256
256
  return client.get(payload);
@@ -6,7 +6,6 @@ const login_1 = require("../../auth/login");
6
6
  const webhooks_1 = require("../../api/webhooks");
7
7
  const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
8
8
  const basecommand_1 = require("../../basecommand");
9
- const logger_1 = tslib_1.__importDefault(require("../../logger"));
10
9
  class DeleteWebhooks extends basecommand_1.BaseCommand {
11
10
  static description = 'Delete an existing webhook. To delete a single webhook, pass its ID. To delete multiple webhooks, do not pass a value for the ID, and select multiple using the interactive selector';
12
11
  static examples = [
@@ -43,10 +42,10 @@ class DeleteWebhooks extends basecommand_1.BaseCommand {
43
42
  }
44
43
  }
45
44
  if (this.flags.json) {
46
- logger_1.default.info(JSON.stringify(deletedWebhooks, null, 2));
45
+ this.log(JSON.stringify(deletedWebhooks, null, 2));
47
46
  }
48
47
  else {
49
- logger_1.default.info(deletedWebhooks.map((x) => x.id).join('\n'));
48
+ this.log(deletedWebhooks.map((x) => x.id).join('\n'));
50
49
  }
51
50
  }
52
51
  }
@@ -39,7 +39,7 @@ async function cacheAssortmentItemsByAssortmentId(assortmentId) {
39
39
  }
40
40
  const assortmentItems = await (0, batchFetch_1.batchFetch)('assortment-item', {
41
41
  criteria: { assortmentId },
42
- customParams: { propertySlugs: 'id,assortmentId,itemId' },
42
+ propertySlugs: ['id', 'assortmentId', 'itemId'],
43
43
  });
44
44
  ASSORTMENT_ITEMS_CACHE_BY_ASSORTMENT_ID.set(assortmentId, assortmentItems);
45
45
  assortmentItems.forEach((item) => {
@@ -5,4 +5,7 @@ export interface BatchFetchableEntityMap {
5
5
  'project-item': ProjectItem;
6
6
  'assortment-item': AssortmentItem;
7
7
  }
8
- export declare function batchFetch<K extends keyof BatchFetchableEntityMap>(entityName: K, options: EntitiesClientGetOptions): Promise<BatchFetchableEntityMap[K][]>;
8
+ export type BatchFetchOptions = EntitiesClientGetOptions & {
9
+ propertySlugs?: string[];
10
+ };
11
+ export declare function batchFetch<K extends keyof BatchFetchableEntityMap>(entityName: K, options: BatchFetchOptions): Promise<BatchFetchableEntityMap[K][]>;
@@ -23,6 +23,7 @@ async function requestBatchFetch(entityName, options) {
23
23
  if (optionsClone.criteria) {
24
24
  optionsClone.where = optionsClone.criteria;
25
25
  }
26
+ delete optionsClone.customParams;
26
27
  return client.create({
27
28
  entityName: entityName,
28
29
  suffix: 'batch-fetch',
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Roles = exports.getItemFamilies = exports.getManyItems = void 0;
4
4
  const sdk_1 = require("@contrail/sdk");
5
- async function getManyItems(maxCount = 10000) {
5
+ const ITEM_FETCH_CEILING = 10000;
6
+ async function getManyItems(maxCount) {
6
7
  const client = new sdk_1.Entities();
8
+ const limit = maxCount ?? ITEM_FETCH_CEILING;
7
9
  const items = [];
8
10
  let nextPageKey = undefined;
9
11
  while (true) {
@@ -20,8 +22,10 @@ async function getManyItems(maxCount = 10000) {
20
22
  if (!nextPageKey) {
21
23
  break; // an absent cursor restarts pagination from page one
22
24
  }
23
- if (items.length >= maxCount) {
24
- console.warn(`Reached maximum item limit of ${maxCount}. Some items may not be included.`);
25
+ if (items.length >= limit) {
26
+ if (maxCount === undefined) {
27
+ console.warn(`Reached maximum item limit of ${limit}. Some items may not be included.`);
28
+ }
25
29
  break;
26
30
  }
27
31
  }
@@ -11,7 +11,7 @@ async function cacheProjectItemsByProjectId(projectId) {
11
11
  }
12
12
  const projectItems = await (0, batchFetch_1.batchFetch)('project-item', {
13
13
  criteria: { projectId },
14
- customParams: { propertySlugs: 'id,projectId,assortmentId' },
14
+ propertySlugs: ['id', 'projectId', 'itemId'],
15
15
  });
16
16
  PROJECT_ITEMS_CACHE_BY_PROJECT_ID.set(projectId, projectItems);
17
17
  projectItems.forEach((item) => {
@@ -14,9 +14,17 @@ exports.convertDateRangeToJSURL = exports.parseDate = exports.parseDateRange = e
14
14
  * Checks if a criteria value uses date range syntax (..)
15
15
  */
16
16
  function isDateRangeValue(value) {
17
- return typeof value === 'string' && value.includes('..');
17
+ if (typeof value !== 'string' || !value.includes('..')) {
18
+ return false;
19
+ }
20
+ const [start, end] = value.split('..');
21
+ const bounds = [start.trim(), end?.trim()].filter(Boolean);
22
+ return bounds.length > 0 && bounds.every((bound) => !isNaN(toBoundedDate(bound).getTime()));
18
23
  }
19
24
  exports.isDateRangeValue = isDateRangeValue;
25
+ function toBoundedDate(dateStr) {
26
+ return new Date(dateStr.includes('T') ? dateStr : `${dateStr}T00:00:00.000Z`);
27
+ }
20
28
  /**
21
29
  * Parses a date range value into its bounds
22
30
  * @param rangeValue - The value (e.g., "2025-09-15..2025-09-16")
@@ -15,6 +15,12 @@ describe('Date Range Specifications', () => {
15
15
  expect((0, dateRanges_1.isDateRangeValue)(42)).toBe(false);
16
16
  expect((0, dateRanges_1.isDateRangeValue)(undefined)).toBe(false);
17
17
  });
18
+ it('should reject dotted values whose bounds are not dates', () => {
19
+ expect((0, dateRanges_1.isDateRangeValue)('Loading...')).toBe(false);
20
+ expect((0, dateRanges_1.isDateRangeValue)('a..b')).toBe(false);
21
+ expect((0, dateRanges_1.isDateRangeValue)('v1..v2')).toBe(false);
22
+ expect((0, dateRanges_1.isDateRangeValue)('..')).toBe(false);
23
+ });
18
24
  });
19
25
  describe('parseDate', () => {
20
26
  it('should parse ISO timestamps correctly', () => {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.6.0-alpha-8-alpha.5ffe1e1",
2
+ "version": "3.6.0-alpha-8-alpha.e2d1830",
3
3
  "commands": {
4
4
  "app:create": {
5
5
  "id": "app:create",
@@ -683,12 +683,12 @@
683
683
  "examples": [
684
684
  "contrail entities create color -g -n=10 # creates 10 random colors",
685
685
  "contrail entities create color -- name=\"Electric Blue\" green=1 red=2 blue=3 # creates one color with specified properties only",
686
- "contrail entities create custom-entities:franchise",
687
- "contrail entities create project-item -n=1 -- projectId=abc # creates 10 project items within project ABC",
686
+ "contrail entities create custom-entity:franchise",
687
+ "contrail entities create project-item -n=10 -- projectId=abc # creates 10 project items within project ABC",
688
688
  "contrail entities create color -g -r # creates a random color with a human readable ID",
689
689
  "contrail entities create color -d -- name=test # simulates the creation of a color without actually creating it",
690
- "contrail entities create custom-entity:franchise -s # creates an entity and the response does not contain hydrating relationships",
691
- "contrail entities create color -g -- name=Electric Blue # creates a color with the name specified and other properties auto-generated",
690
+ "contrail entities create custom-entity:franchise -S # creates an entity and the response does not contain hydrated relationships",
691
+ "contrail entities create color -g -- name=\"Electric Blue\" # creates a color with the name specified and other properties auto-generated",
692
692
  "contrail entities create color -o /tmp/colors.json -- name=Blue green=1 red=2 blue=3 # creates a color and saves the output to /tmp/colors.json"
693
693
  ],
694
694
  "flags": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "3.6.0-alpha-8-alpha.5ffe1e1",
3
+ "version": "3.6.0-alpha-8-alpha.e2d1830",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",
@@ -57,6 +57,7 @@
57
57
  "listr": "^0.14.3",
58
58
  "lodash": "^4.17.21",
59
59
  "ncp": "^2.0.0",
60
+ "p-limit": "^3.1.0",
60
61
  "pkg-install": "^1.0.0",
61
62
  "semver": "^7.5.4",
62
63
  "unique-names-generator": "^4.7.1",