@contrail/cli 3.6.0-alpha-8-alpha.ec1ef67 → 3.6.0-alpha-8-alpha.7830b8a

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.ec1ef67 linux-x64 node-v24.22.2
20
+ @contrail/cli/3.6.0-alpha-8-alpha.7830b8a 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 = {
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const fs_1 = tslib_1.__importDefault(require("fs"));
5
5
  const core_1 = require("@oclif/core");
6
- const types_1 = require("../../api/types");
6
+ const types_1 = require("@contrail/types");
7
+ const types_2 = require("../../api/types");
7
8
  const propertyValues_1 = require("../../helpers/propertySpecifications/propertyValues");
8
9
  const basecommand_1 = require("../../basecommand");
9
10
  const sdk_1 = require("@contrail/sdk");
@@ -205,10 +206,14 @@ async function getEntitiesByName(entityName, propertySpec, typePropertySets, opt
205
206
  });
206
207
  }
207
208
  function convertPropertySpecIntoCriteria(propertySpec, typePropertySets = []) {
209
+ const propertyTypeBySlug = (0, propertyValues_1.buildPropertyTypeMap)(typePropertySets);
208
210
  const ranges = new Map();
209
211
  const values = new Map();
210
212
  propertySpec.forEach((value, slug) => {
211
- ((0, dateRanges_1.isDateRangeValue)(value) ? ranges : values).set(slug, value);
213
+ const looksLikeRange = typeof value === 'string' && value.includes('..');
214
+ const isDateProperty = propertyTypeBySlug.get(slug) === types_1.PropertyType.Date;
215
+ const isRange = looksLikeRange && (isDateProperty || (0, dateRanges_1.isDateRangeValue)(value));
216
+ (isRange ? ranges : values).set(slug, value);
212
217
  });
213
218
  const criteria = (0, propertyValues_1.castCriteriaValues)(values, typePropertySets);
214
219
  ranges.forEach((value, slug) => {
@@ -224,7 +229,7 @@ function convertPropertySpecIntoCriteria(propertySpec, typePropertySets = []) {
224
229
  async function resolveQueryTypes(entityName, propertySpec) {
225
230
  const specified = propertySpec.get('typePath');
226
231
  const paths = specified === undefined ? [entityName] : [specified].flat().map(String);
227
- const types = await Promise.all(paths.map((path) => (0, types_1.getTypeByPath)(path).catch(() => {
232
+ const types = await Promise.all(paths.map((path) => (0, types_2.getTypeByPath)(path).catch(() => {
228
233
  console.error(`Could not resolve type ${path}; criteria on it are read as written.`);
229
234
  return undefined;
230
235
  })));
@@ -250,7 +255,7 @@ async function find(entityName, options = {}) {
250
255
  // a suffix names a specific sub-route and an id names one entity; both always go
251
256
  // through the plain client (batch-fetch only understands criteria)
252
257
  if ((0, batchFetch_1.canBatchFetchEntity)(entityName) && !suffix && !id) {
253
- return (0, batchFetch_1.batchFetch)(entityName, payload);
258
+ return (0, batchFetch_1.batchFetch)(entityName, { ...payload, propertySlugs });
254
259
  }
255
260
  else {
256
261
  return client.get(payload);
@@ -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', () => {
@@ -37,7 +37,11 @@ function castValueToPropertyType(value, propertyType, propertySlug) {
37
37
  }
38
38
  return numValue;
39
39
  case types_1.PropertyType.Date:
40
- return new Date(value.toString()).toISOString();
40
+ const date = new Date(value.toString());
41
+ if (isNaN(date.getTime())) {
42
+ throw new Error(`Invalid date value for ${propertySlug}: ${value}`);
43
+ }
44
+ return date.toISOString();
41
45
  case types_1.PropertyType.MultiSelect:
42
46
  if (Array.isArray(value)) {
43
47
  return value;
@@ -146,3 +146,11 @@ describe('castValuesToPropertyTypes never guesses', () => {
146
146
  });
147
147
  });
148
148
  });
149
+ describe('Date casting', () => {
150
+ it('names the slug and value for an unparseable date', () => {
151
+ expect(() => (0, propertyValues_1.castValueToPropertyType)('garbage', types_1.PropertyType.Date, 'createdOn')).toThrow('Invalid date value for createdOn: garbage');
152
+ });
153
+ it('still converts a parseable date', () => {
154
+ expect((0, propertyValues_1.castValueToPropertyType)('2025-09-15', types_1.PropertyType.Date, 'createdOn')).toBe('2025-09-15T00:00:00.000Z');
155
+ });
156
+ });
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.6.0-alpha-8-alpha.ec1ef67",
2
+ "version": "3.6.0-alpha-8-alpha.7830b8a",
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.ec1ef67",
3
+ "version": "3.6.0-alpha-8-alpha.7830b8a",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",