@centrali-io/centrali-sdk 3.0.4 → 3.0.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.
Files changed (3) hide show
  1. package/dist/index.js +123 -1
  2. package/index.ts +170 -0
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.CentraliSDK = exports.ValidationManager = exports.AnomalyInsightsManager = exports.SmartQueriesManager = exports.TriggersManager = exports.OrchestrationsManager = exports.RealtimeManager = void 0;
21
+ exports.CentraliSDK = exports.AllowedDomainsManager = exports.ValidationManager = exports.AnomalyInsightsManager = exports.SmartQueriesManager = exports.TriggersManager = exports.OrchestrationsManager = exports.RealtimeManager = void 0;
22
22
  exports.getApiUrl = getApiUrl;
23
23
  exports.getAuthUrl = getAuthUrl;
24
24
  exports.getRealtimeUrl = getRealtimeUrl;
@@ -53,6 +53,7 @@ exports.getValidationScanApiPath = getValidationScanApiPath;
53
53
  exports.getOrchestrationsApiPath = getOrchestrationsApiPath;
54
54
  exports.getOrchestrationRunsApiPath = getOrchestrationRunsApiPath;
55
55
  exports.getOrchestrationRunStepsApiPath = getOrchestrationRunStepsApiPath;
56
+ exports.getAllowedDomainsApiPath = getAllowedDomainsApiPath;
56
57
  const axios_1 = __importDefault(require("axios"));
57
58
  const qs_1 = __importDefault(require("qs"));
58
59
  const eventsource_1 = require("eventsource");
@@ -538,6 +539,13 @@ function getOrchestrationRunsApiPath(workspaceId, orchestrationId, runId) {
538
539
  function getOrchestrationRunStepsApiPath(workspaceId, orchestrationId, runId) {
539
540
  return `orchestration/ws/${workspaceId}/api/v1/orchestrations/${orchestrationId}/runs/${runId}/steps`;
540
541
  }
542
+ /**
543
+ * Generate Allowed Domains API URL PATH.
544
+ */
545
+ function getAllowedDomainsApiPath(workspaceId, domainId) {
546
+ const basePath = `data/workspace/${workspaceId}/api/v1/settings/allowed-domains`;
547
+ return domainId ? `${basePath}/${domainId}` : basePath;
548
+ }
541
549
  // =====================================================
542
550
  // Orchestrations Manager
543
551
  // =====================================================
@@ -1546,6 +1554,78 @@ class ValidationManager {
1546
1554
  }
1547
1555
  }
1548
1556
  exports.ValidationManager = ValidationManager;
1557
+ // =====================================================
1558
+ // Allowed Domains Manager
1559
+ // =====================================================
1560
+ /**
1561
+ * AllowedDomainsManager provides methods for managing allowed domains for compute function external calls.
1562
+ * Access via `client.allowedDomains`.
1563
+ *
1564
+ * Usage:
1565
+ * ```ts
1566
+ * // List all allowed domains
1567
+ * const domains = await client.allowedDomains.list();
1568
+ *
1569
+ * // Add a new domain
1570
+ * const domain = await client.allowedDomains.add({ domain: 'api.example.com' });
1571
+ *
1572
+ * // Remove a domain
1573
+ * await client.allowedDomains.remove('domain-id');
1574
+ * ```
1575
+ */
1576
+ class AllowedDomainsManager {
1577
+ constructor(workspaceId, requestFn) {
1578
+ this.workspaceId = workspaceId;
1579
+ this.requestFn = requestFn;
1580
+ }
1581
+ /**
1582
+ * List all allowed domains in the workspace.
1583
+ *
1584
+ * @returns List of allowed domains with total count
1585
+ *
1586
+ * @example
1587
+ * ```ts
1588
+ * const result = await client.allowedDomains.list();
1589
+ * console.log('Total domains:', result.meta.total);
1590
+ * result.data.forEach(d => console.log(d.domain));
1591
+ * ```
1592
+ */
1593
+ list() {
1594
+ const path = getAllowedDomainsApiPath(this.workspaceId);
1595
+ return this.requestFn('GET', path);
1596
+ }
1597
+ /**
1598
+ * Add a new allowed domain.
1599
+ *
1600
+ * @param options - The domain to add
1601
+ * @returns The created allowed domain entry
1602
+ *
1603
+ * @example
1604
+ * ```ts
1605
+ * const result = await client.allowedDomains.add({ domain: 'api.stripe.com' });
1606
+ * console.log('Added:', result.data.domain, result.data.id);
1607
+ * ```
1608
+ */
1609
+ add(options) {
1610
+ const path = getAllowedDomainsApiPath(this.workspaceId);
1611
+ return this.requestFn('POST', path, { domain: options.domain });
1612
+ }
1613
+ /**
1614
+ * Remove an allowed domain by ID.
1615
+ *
1616
+ * @param domainId - The ID of the domain to remove
1617
+ *
1618
+ * @example
1619
+ * ```ts
1620
+ * await client.allowedDomains.remove('domain-id-123');
1621
+ * ```
1622
+ */
1623
+ remove(domainId) {
1624
+ const path = getAllowedDomainsApiPath(this.workspaceId, domainId);
1625
+ return this.requestFn('DELETE', path);
1626
+ }
1627
+ }
1628
+ exports.AllowedDomainsManager = AllowedDomainsManager;
1549
1629
  /**
1550
1630
  * Main Centrali SDK client.
1551
1631
  */
@@ -1558,6 +1638,7 @@ class CentraliSDK {
1558
1638
  this._anomalyInsights = null;
1559
1639
  this._validation = null;
1560
1640
  this._orchestrations = null;
1641
+ this._allowedDomains = null;
1561
1642
  this.isRefreshingToken = false;
1562
1643
  this.tokenRefreshPromise = null;
1563
1644
  this.options = options;
@@ -1805,6 +1886,27 @@ class CentraliSDK {
1805
1886
  }
1806
1887
  return this._orchestrations;
1807
1888
  }
1889
+ /**
1890
+ * Allowed Domains namespace for managing compute function external call domains.
1891
+ *
1892
+ * Usage:
1893
+ * ```ts
1894
+ * // List all allowed domains
1895
+ * const domains = await client.allowedDomains.list();
1896
+ *
1897
+ * // Add a new domain
1898
+ * const domain = await client.allowedDomains.add({ domain: 'api.stripe.com' });
1899
+ *
1900
+ * // Remove a domain
1901
+ * await client.allowedDomains.remove('domain-id');
1902
+ * ```
1903
+ */
1904
+ get allowedDomains() {
1905
+ if (!this._allowedDomains) {
1906
+ this._allowedDomains = new AllowedDomainsManager(this.options.workspaceId, this.request.bind(this));
1907
+ }
1908
+ return this._allowedDomains;
1909
+ }
1808
1910
  /**
1809
1911
  * Manually set or update the bearer token for subsequent requests.
1810
1912
  */
@@ -1940,6 +2042,26 @@ class CentraliSDK {
1940
2042
  const path = getRecordApiPath(this.options.workspaceId, recordSlug, id);
1941
2043
  return this.request('PUT', path, Object.assign({}, updates));
1942
2044
  }
2045
+ /**
2046
+ * Upsert a record: find by match fields, update if exists, create if not.
2047
+ * Uses advisory locking for atomicity — safe for concurrent calls.
2048
+ *
2049
+ * @param recordSlug - The structure's record slug
2050
+ * @param options - { match: key-value pairs to find existing record, data: full record data }
2051
+ * @returns Response where result.data is the record and result.operation indicates create/update
2052
+ *
2053
+ * @example
2054
+ * const result = await client.upsertRecord('HourlyRollup', {
2055
+ * match: { metricKey: 'pageviews', bucketHour: '2025-01-01T10:00' },
2056
+ * data: { metricKey: 'pageviews', bucketHour: '2025-01-01T10:00', count: 42 },
2057
+ * });
2058
+ * // result.data → the record
2059
+ * // result.operation → 'created' or 'updated'
2060
+ */
2061
+ upsertRecord(recordSlug, options) {
2062
+ const path = getRecordApiPath(this.options.workspaceId, recordSlug) + '/upsert';
2063
+ return this.request('POST', path, { match: options.match, data: options.data });
2064
+ }
1943
2065
  /** Delete a record by ID (soft delete by default, can be restored). */
1944
2066
  deleteRecord(recordSlug, id, options) {
1945
2067
  const path = getRecordApiPath(this.options.workspaceId, recordSlug, id);
package/index.ts CHANGED
@@ -539,6 +539,36 @@ export interface DeleteRecordOptions {
539
539
  hard?: boolean;
540
540
  }
541
541
 
542
+ // =====================================================
543
+ // Allowed Domains Types
544
+ // =====================================================
545
+
546
+ /**
547
+ * An allowed domain entry for compute function external calls.
548
+ */
549
+ export interface AllowedDomain {
550
+ id: string;
551
+ domain: string;
552
+ createdAt: string;
553
+ createdBy: string;
554
+ }
555
+
556
+ /**
557
+ * Response from listing allowed domains.
558
+ */
559
+ export interface AllowedDomainsListResponse {
560
+ data: AllowedDomain[];
561
+ meta: { total: number };
562
+ }
563
+
564
+ /**
565
+ * Options for adding an allowed domain.
566
+ */
567
+ export interface AddAllowedDomainOptions {
568
+ /** The domain to allow (e.g., 'api.example.com'). No protocol prefix. */
569
+ domain: string;
570
+ }
571
+
542
572
  /**
543
573
  * Options for expanding reference fields when fetching records.
544
574
  * Expanded data is placed in the `_expanded` object within the record's data.
@@ -2154,6 +2184,14 @@ export function getOrchestrationRunStepsApiPath(workspaceId: string, orchestrati
2154
2184
  return `orchestration/ws/${workspaceId}/api/v1/orchestrations/${orchestrationId}/runs/${runId}/steps`;
2155
2185
  }
2156
2186
 
2187
+ /**
2188
+ * Generate Allowed Domains API URL PATH.
2189
+ */
2190
+ export function getAllowedDomainsApiPath(workspaceId: string, domainId?: string): string {
2191
+ const basePath = `data/workspace/${workspaceId}/api/v1/settings/allowed-domains`;
2192
+ return domainId ? `${basePath}/${domainId}` : basePath;
2193
+ }
2194
+
2157
2195
  // =====================================================
2158
2196
  // Orchestrations Manager
2159
2197
  // =====================================================
@@ -3262,6 +3300,88 @@ export class ValidationManager {
3262
3300
  }
3263
3301
  }
3264
3302
 
3303
+ // =====================================================
3304
+ // Allowed Domains Manager
3305
+ // =====================================================
3306
+
3307
+ /**
3308
+ * AllowedDomainsManager provides methods for managing allowed domains for compute function external calls.
3309
+ * Access via `client.allowedDomains`.
3310
+ *
3311
+ * Usage:
3312
+ * ```ts
3313
+ * // List all allowed domains
3314
+ * const domains = await client.allowedDomains.list();
3315
+ *
3316
+ * // Add a new domain
3317
+ * const domain = await client.allowedDomains.add({ domain: 'api.example.com' });
3318
+ *
3319
+ * // Remove a domain
3320
+ * await client.allowedDomains.remove('domain-id');
3321
+ * ```
3322
+ */
3323
+ export class AllowedDomainsManager {
3324
+ private requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>;
3325
+ private workspaceId: string;
3326
+
3327
+ constructor(
3328
+ workspaceId: string,
3329
+ requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>
3330
+ ) {
3331
+ this.workspaceId = workspaceId;
3332
+ this.requestFn = requestFn;
3333
+ }
3334
+
3335
+ /**
3336
+ * List all allowed domains in the workspace.
3337
+ *
3338
+ * @returns List of allowed domains with total count
3339
+ *
3340
+ * @example
3341
+ * ```ts
3342
+ * const result = await client.allowedDomains.list();
3343
+ * console.log('Total domains:', result.meta.total);
3344
+ * result.data.forEach(d => console.log(d.domain));
3345
+ * ```
3346
+ */
3347
+ public list(): Promise<ApiResponse<AllowedDomain[]>> {
3348
+ const path = getAllowedDomainsApiPath(this.workspaceId);
3349
+ return this.requestFn<AllowedDomain[]>('GET', path);
3350
+ }
3351
+
3352
+ /**
3353
+ * Add a new allowed domain.
3354
+ *
3355
+ * @param options - The domain to add
3356
+ * @returns The created allowed domain entry
3357
+ *
3358
+ * @example
3359
+ * ```ts
3360
+ * const result = await client.allowedDomains.add({ domain: 'api.stripe.com' });
3361
+ * console.log('Added:', result.data.domain, result.data.id);
3362
+ * ```
3363
+ */
3364
+ public add(options: AddAllowedDomainOptions): Promise<ApiResponse<AllowedDomain>> {
3365
+ const path = getAllowedDomainsApiPath(this.workspaceId);
3366
+ return this.requestFn<AllowedDomain>('POST', path, { domain: options.domain });
3367
+ }
3368
+
3369
+ /**
3370
+ * Remove an allowed domain by ID.
3371
+ *
3372
+ * @param domainId - The ID of the domain to remove
3373
+ *
3374
+ * @example
3375
+ * ```ts
3376
+ * await client.allowedDomains.remove('domain-id-123');
3377
+ * ```
3378
+ */
3379
+ public remove(domainId: string): Promise<ApiResponse<void>> {
3380
+ const path = getAllowedDomainsApiPath(this.workspaceId, domainId);
3381
+ return this.requestFn<void>('DELETE', path);
3382
+ }
3383
+ }
3384
+
3265
3385
  /**
3266
3386
  * Main Centrali SDK client.
3267
3387
  */
@@ -3275,6 +3395,7 @@ export class CentraliSDK {
3275
3395
  private _anomalyInsights: AnomalyInsightsManager | null = null;
3276
3396
  private _validation: ValidationManager | null = null;
3277
3397
  private _orchestrations: OrchestrationsManager | null = null;
3398
+ private _allowedDomains: AllowedDomainsManager | null = null;
3278
3399
  private isRefreshingToken: boolean = false;
3279
3400
  private tokenRefreshPromise: Promise<string> | null = null;
3280
3401
 
@@ -3577,6 +3698,31 @@ export class CentraliSDK {
3577
3698
  return this._orchestrations;
3578
3699
  }
3579
3700
 
3701
+ /**
3702
+ * Allowed Domains namespace for managing compute function external call domains.
3703
+ *
3704
+ * Usage:
3705
+ * ```ts
3706
+ * // List all allowed domains
3707
+ * const domains = await client.allowedDomains.list();
3708
+ *
3709
+ * // Add a new domain
3710
+ * const domain = await client.allowedDomains.add({ domain: 'api.stripe.com' });
3711
+ *
3712
+ * // Remove a domain
3713
+ * await client.allowedDomains.remove('domain-id');
3714
+ * ```
3715
+ */
3716
+ public get allowedDomains(): AllowedDomainsManager {
3717
+ if (!this._allowedDomains) {
3718
+ this._allowedDomains = new AllowedDomainsManager(
3719
+ this.options.workspaceId,
3720
+ this.request.bind(this)
3721
+ );
3722
+ }
3723
+ return this._allowedDomains;
3724
+ }
3725
+
3580
3726
  /**
3581
3727
  * Manually set or update the bearer token for subsequent requests.
3582
3728
  */
@@ -3753,6 +3899,30 @@ export class CentraliSDK {
3753
3899
  return this.request('PUT', path, { ...updates });
3754
3900
  }
3755
3901
 
3902
+ /**
3903
+ * Upsert a record: find by match fields, update if exists, create if not.
3904
+ * Uses advisory locking for atomicity — safe for concurrent calls.
3905
+ *
3906
+ * @param recordSlug - The structure's record slug
3907
+ * @param options - { match: key-value pairs to find existing record, data: full record data }
3908
+ * @returns Response where result.data is the record and result.operation indicates create/update
3909
+ *
3910
+ * @example
3911
+ * const result = await client.upsertRecord('HourlyRollup', {
3912
+ * match: { metricKey: 'pageviews', bucketHour: '2025-01-01T10:00' },
3913
+ * data: { metricKey: 'pageviews', bucketHour: '2025-01-01T10:00', count: 42 },
3914
+ * });
3915
+ * // result.data → the record
3916
+ * // result.operation → 'created' or 'updated'
3917
+ */
3918
+ public upsertRecord<T = any>(
3919
+ recordSlug: string,
3920
+ options: { match: Record<string, any>; data: Record<string, any> }
3921
+ ): Promise<ApiResponse<T> & { operation: 'created' | 'updated' }> {
3922
+ const path = getRecordApiPath(this.options.workspaceId, recordSlug) + '/upsert';
3923
+ return this.request('POST', path, { match: options.match, data: options.data }) as Promise<ApiResponse<T> & { operation: 'created' | 'updated' }>;
3924
+ }
3925
+
3756
3926
  /** Delete a record by ID (soft delete by default, can be restored). */
3757
3927
  public deleteRecord(
3758
3928
  recordSlug: string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centrali-io/centrali-sdk",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "Centrali Node SDK",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",