@centrali-io/centrali-sdk 2.9.4 → 2.9.6

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
@@ -122,6 +122,69 @@ const products = await centrali.queryRecords('Product', {
122
122
  });
123
123
  ```
124
124
 
125
+ ### Expanding References
126
+
127
+ When querying records with reference fields, use the `expand` parameter to include the full referenced record data:
128
+
129
+ ```typescript
130
+ // Expand a single reference field
131
+ const orders = await centrali.queryRecords('Order', {
132
+ expand: 'customer'
133
+ });
134
+
135
+ // Expand multiple reference fields
136
+ const orders = await centrali.queryRecords('Order', {
137
+ expand: 'customer,product'
138
+ });
139
+
140
+ // Nested expansion (up to 3 levels deep)
141
+ const orders = await centrali.queryRecords('Order', {
142
+ expand: 'customer,customer.address'
143
+ });
144
+
145
+ // Get a single record with expanded references
146
+ const order = await centrali.getRecord('Order', 'order-id', {
147
+ expand: 'customer,items'
148
+ });
149
+ ```
150
+
151
+ Expanded data is placed in the `_expanded` object within the record's data:
152
+
153
+ ```typescript
154
+ // Response structure
155
+ {
156
+ "id": "order-123",
157
+ "data": {
158
+ "customerId": "cust-456",
159
+ "total": 99.99,
160
+ "_expanded": {
161
+ "customerId": {
162
+ "id": "cust-456",
163
+ "data": {
164
+ "name": "John Doe",
165
+ "email": "john@example.com"
166
+ }
167
+ }
168
+ }
169
+ }
170
+ }
171
+
172
+ // Access expanded data
173
+ const customerName = order.data.data._expanded.customerId.data.name;
174
+ ```
175
+
176
+ For many-to-many relationships, the expanded field contains an array:
177
+
178
+ ```typescript
179
+ // Many-to-many expansion
180
+ const post = await centrali.getRecord('Post', 'post-id', {
181
+ expand: 'tags'
182
+ });
183
+
184
+ // _expanded.tags will be an array of tag records
185
+ const tagNames = post.data.data._expanded.tags.map(tag => tag.data.name);
186
+ ```
187
+
125
188
  ### Smart Queries
126
189
 
127
190
  Smart queries are reusable, predefined queries that are created in the Centrali console and can be executed programmatically via the SDK. Pagination (limit/skip) is defined in the query definition itself.
package/dist/index.js CHANGED
@@ -1801,15 +1801,51 @@ class CentraliSDK {
1801
1801
  getToken() {
1802
1802
  return this.token;
1803
1803
  }
1804
- /** Retrieve a record by ID. */
1805
- getRecord(recordSlug, id) {
1804
+ /**
1805
+ * Retrieve a record by ID.
1806
+ *
1807
+ * @param recordSlug - The structure's record slug
1808
+ * @param id - The record ID
1809
+ * @param options - Optional parameters including expand for reference fields
1810
+ *
1811
+ * @example
1812
+ * // Basic fetch
1813
+ * const order = await centrali.getRecord('Order', 'order-123');
1814
+ *
1815
+ * // With expanded references
1816
+ * const order = await centrali.getRecord('Order', 'order-123', {
1817
+ * expand: 'customer,items'
1818
+ * });
1819
+ * // Access expanded data: order.data.data._expanded.customer
1820
+ */
1821
+ getRecord(recordSlug, id, options) {
1806
1822
  const path = getRecordApiPath(this.options.workspaceId, recordSlug, id);
1807
- return this.request('GET', path);
1823
+ return this.request('GET', path, null, options);
1808
1824
  }
1809
- /** Query records with filters, pagination, etc. */
1825
+ /**
1826
+ * Query records with filters, pagination, sorting, and reference expansion.
1827
+ *
1828
+ * @param recordSlug - The structure's record slug
1829
+ * @param queryParams - Query parameters including filter, sort, pagination, and expand
1830
+ *
1831
+ * @example
1832
+ * // Basic query with filter and sort
1833
+ * const products = await centrali.queryRecords('Product', {
1834
+ * filter: 'inStock = true AND price < 100',
1835
+ * sort: '-createdAt',
1836
+ * limit: 10
1837
+ * });
1838
+ *
1839
+ * // Query with expanded references
1840
+ * const orders = await centrali.queryRecords('Order', {
1841
+ * filter: 'status = "pending"',
1842
+ * expand: 'customer,items'
1843
+ * });
1844
+ * // Access expanded data: orders.data[0].data._expanded.customer
1845
+ */
1810
1846
  queryRecords(recordSlug, queryParams) {
1811
1847
  const path = getRecordApiPath(this.options.workspaceId, recordSlug);
1812
- return this.request('GET', path, null, Object.assign({}, queryParams));
1848
+ return this.request('GET', path, null, queryParams);
1813
1849
  }
1814
1850
  /** Get records by Ids. */
1815
1851
  getRecordsByIds(recordSlug, ids) {
package/index.ts CHANGED
@@ -539,6 +539,53 @@ export interface DeleteRecordOptions {
539
539
  hard?: boolean;
540
540
  }
541
541
 
542
+ /**
543
+ * Options for expanding reference fields when fetching records.
544
+ * Expanded data is placed in the `_expanded` object within the record's data.
545
+ */
546
+ export interface ExpandOptions {
547
+ /**
548
+ * Comma-separated list of reference fields to expand.
549
+ * Supports nested expansion using dot notation (up to 3 levels deep).
550
+ *
551
+ * @example
552
+ * // Single field
553
+ * expand: 'customer'
554
+ *
555
+ * // Multiple fields
556
+ * expand: 'customer,product'
557
+ *
558
+ * // Nested expansion
559
+ * expand: 'customer,customer.address'
560
+ */
561
+ expand?: string;
562
+ }
563
+
564
+ /**
565
+ * Options for retrieving a single record.
566
+ */
567
+ export interface GetRecordOptions extends ExpandOptions {}
568
+
569
+ /**
570
+ * Options for querying records.
571
+ */
572
+ export interface QueryRecordOptions extends ExpandOptions {
573
+ /** CFL filter expression (e.g., 'status = "active" AND price > 100') */
574
+ filter?: string;
575
+ /** Sort field with optional direction prefix (e.g., '-createdAt' for descending) */
576
+ sort?: string;
577
+ /** Maximum number of records to return */
578
+ limit?: number;
579
+ /** Number of records to skip (for pagination) */
580
+ skip?: number;
581
+ /** Page number (alternative to skip) */
582
+ page?: number;
583
+ /** Include archived (soft-deleted) records */
584
+ includeArchived?: boolean;
585
+ /** Additional query parameters */
586
+ [key: string]: any;
587
+ }
588
+
542
589
  /**
543
590
  * Response from invoking a trigger.
544
591
  * Currently the API returns the queued job ID as a string.
@@ -3429,24 +3476,59 @@ export class CentraliSDK {
3429
3476
  }
3430
3477
 
3431
3478
 
3432
- /** Retrieve a record by ID. */
3479
+ /**
3480
+ * Retrieve a record by ID.
3481
+ *
3482
+ * @param recordSlug - The structure's record slug
3483
+ * @param id - The record ID
3484
+ * @param options - Optional parameters including expand for reference fields
3485
+ *
3486
+ * @example
3487
+ * // Basic fetch
3488
+ * const order = await centrali.getRecord('Order', 'order-123');
3489
+ *
3490
+ * // With expanded references
3491
+ * const order = await centrali.getRecord('Order', 'order-123', {
3492
+ * expand: 'customer,items'
3493
+ * });
3494
+ * // Access expanded data: order.data.data._expanded.customer
3495
+ */
3433
3496
  public getRecord<T = any>(
3434
3497
  recordSlug: string,
3435
- id: string
3498
+ id: string,
3499
+ options?: GetRecordOptions
3436
3500
  ): Promise<ApiResponse<T>> {
3437
3501
  const path = getRecordApiPath(this.options.workspaceId, recordSlug, id);
3438
- return this.request('GET', path);
3502
+ return this.request('GET', path, null, options);
3439
3503
  }
3440
3504
 
3441
- /** Query records with filters, pagination, etc. */
3505
+ /**
3506
+ * Query records with filters, pagination, sorting, and reference expansion.
3507
+ *
3508
+ * @param recordSlug - The structure's record slug
3509
+ * @param queryParams - Query parameters including filter, sort, pagination, and expand
3510
+ *
3511
+ * @example
3512
+ * // Basic query with filter and sort
3513
+ * const products = await centrali.queryRecords('Product', {
3514
+ * filter: 'inStock = true AND price < 100',
3515
+ * sort: '-createdAt',
3516
+ * limit: 10
3517
+ * });
3518
+ *
3519
+ * // Query with expanded references
3520
+ * const orders = await centrali.queryRecords('Order', {
3521
+ * filter: 'status = "pending"',
3522
+ * expand: 'customer,items'
3523
+ * });
3524
+ * // Access expanded data: orders.data[0].data._expanded.customer
3525
+ */
3442
3526
  public queryRecords<T = any>(
3443
3527
  recordSlug: string,
3444
- queryParams: Record<string, any>
3528
+ queryParams?: QueryRecordOptions
3445
3529
  ): Promise<ApiResponse<T>> {
3446
3530
  const path = getRecordApiPath(this.options.workspaceId, recordSlug);
3447
- return this.request('GET', path, null, {
3448
- ...queryParams,
3449
- });
3531
+ return this.request('GET', path, null, queryParams);
3450
3532
  }
3451
3533
 
3452
3534
  /** Get records by Ids. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centrali-io/centrali-sdk",
3
- "version": "2.9.4",
3
+ "version": "2.9.6",
4
4
  "description": "Centrali Node SDK",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",