@centrali-io/centrali-sdk 9.5.1 → 9.6.0
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 +103 -7
- package/dist/index.d.ts +131 -20
- package/dist/index.js +205 -53
- package/package.json +1 -1
- package/src/client.ts +30 -26
- package/src/internal/auth.ts +13 -8
- package/src/internal/error.ts +2 -2
- package/src/internal/paths.ts +7 -0
- package/src/managers/triggers.ts +140 -8
- package/src/managers/validation.ts +39 -13
- package/src/types/triggers.ts +84 -0
- package/src/types/validation.ts +12 -1
package/dist/index.js
CHANGED
|
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
25
37
|
var __export = (target, all) => {
|
|
26
38
|
for (var name in all)
|
|
27
39
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -123,6 +135,7 @@ __export(index_exports, {
|
|
|
123
135
|
getFunctionTriggerPauseApiPath: () => getFunctionTriggerPauseApiPath,
|
|
124
136
|
getFunctionTriggerResumeApiPath: () => getFunctionTriggerResumeApiPath,
|
|
125
137
|
getFunctionTriggersApiPath: () => getFunctionTriggersApiPath,
|
|
138
|
+
getHttpTriggerApiPath: () => getHttpTriggerApiPath,
|
|
126
139
|
getOrchestrationRunStepsApiPath: () => getOrchestrationRunStepsApiPath,
|
|
127
140
|
getOrchestrationRunsApiPath: () => getOrchestrationRunsApiPath,
|
|
128
141
|
getOrchestrationRunsCanonicalApiPath: () => getOrchestrationRunsCanonicalApiPath,
|
|
@@ -186,7 +199,7 @@ function isCentraliError(err) {
|
|
|
186
199
|
function toCentraliError(err) {
|
|
187
200
|
var _a, _b, _c, _d;
|
|
188
201
|
if (err instanceof CentraliError) return err;
|
|
189
|
-
if (
|
|
202
|
+
if ((0, import_axios.isAxiosError)(err)) {
|
|
190
203
|
const status = (_a = err.response) == null ? void 0 : _a.status;
|
|
191
204
|
const statusText = (_b = err.response) == null ? void 0 : _b.statusText;
|
|
192
205
|
const body = (_c = err.response) == null ? void 0 : _c.data;
|
|
@@ -245,6 +258,9 @@ function getFunctionTriggerResumeApiPath(workspaceId, triggerId) {
|
|
|
245
258
|
function getEndpointApiPath(workspaceId, path) {
|
|
246
259
|
return `data/workspace/${workspaceId}/api/v1/endpoints/${path}`;
|
|
247
260
|
}
|
|
261
|
+
function getHttpTriggerApiPath(workspaceId, path) {
|
|
262
|
+
return `data/workspace/${workspaceId}/api/v1/http-trigger/${path}`;
|
|
263
|
+
}
|
|
248
264
|
function getSmartQueriesApiPath(workspaceId) {
|
|
249
265
|
return `data/workspace/${workspaceId}/api/v1/saved-queries`;
|
|
250
266
|
}
|
|
@@ -447,15 +463,19 @@ function fetchClientTokenForResource(clientId, clientSecret, baseUrl, resource)
|
|
|
447
463
|
client_secret: clientSecret,
|
|
448
464
|
resource
|
|
449
465
|
});
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
466
|
+
try {
|
|
467
|
+
const resp = yield import_axios2.default.post(
|
|
468
|
+
tokenEndpoint,
|
|
469
|
+
form,
|
|
470
|
+
{
|
|
471
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
472
|
+
proxy: false
|
|
473
|
+
}
|
|
474
|
+
);
|
|
475
|
+
return resp.data.access_token;
|
|
476
|
+
} catch (error) {
|
|
477
|
+
throw toCentraliError(error);
|
|
478
|
+
}
|
|
459
479
|
});
|
|
460
480
|
}
|
|
461
481
|
|
|
@@ -1094,11 +1114,28 @@ var OrchestrationsManager = class {
|
|
|
1094
1114
|
};
|
|
1095
1115
|
|
|
1096
1116
|
// src/managers/triggers.ts
|
|
1117
|
+
var import_crypto = __toESM(require("crypto"));
|
|
1097
1118
|
var TriggersManager = class {
|
|
1098
|
-
constructor(workspaceId, requestFn) {
|
|
1119
|
+
constructor(workspaceId, requestFn, requestBody) {
|
|
1120
|
+
this.requestBody = requestBody;
|
|
1099
1121
|
this.workspaceId = workspaceId;
|
|
1100
1122
|
this.requestFn = requestFn;
|
|
1101
1123
|
}
|
|
1124
|
+
/** Request acceptance and execution success are independent metrics. */
|
|
1125
|
+
health(period = 30) {
|
|
1126
|
+
return __async(this, null, function* () {
|
|
1127
|
+
if (!this.requestBody) throw new Error("Health reads require CentraliSDK.triggers");
|
|
1128
|
+
const body = yield this.requestBody("GET", `data/workspace/${this.workspaceId}/api/v1/triggers/health`, void 0, { period });
|
|
1129
|
+
return { data: body };
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
healthTrend(triggerId, period = 30) {
|
|
1133
|
+
return __async(this, null, function* () {
|
|
1134
|
+
if (!this.requestBody) throw new Error("Health reads require CentraliSDK.triggers");
|
|
1135
|
+
const body = yield this.requestBody("GET", `data/workspace/${this.workspaceId}/api/v1/triggers/${encodeURIComponent(triggerId)}/health/trend`, void 0, { period });
|
|
1136
|
+
return { data: body };
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1102
1139
|
/**
|
|
1103
1140
|
* Invoke an on-demand trigger by ID.
|
|
1104
1141
|
*
|
|
@@ -1367,7 +1404,91 @@ var TriggersManager = class {
|
|
|
1367
1404
|
const queryParams = options == null ? void 0 : options.query;
|
|
1368
1405
|
return this.requestFn(method, path, data, queryParams);
|
|
1369
1406
|
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Invoke an asynchronous HTTP trigger by its stable path.
|
|
1409
|
+
*
|
|
1410
|
+
* The JSON body is serialized before signing so the bytes transmitted by
|
|
1411
|
+
* Axios are exactly the bytes used to compute the HMAC. Signature options
|
|
1412
|
+
* mirror the server validator's trigger metadata. Omit `signingSecret` for
|
|
1413
|
+
* an unsigned trigger.
|
|
1414
|
+
*/
|
|
1415
|
+
invokeHttpTrigger(triggerPath, payload, options = {}) {
|
|
1416
|
+
const normalizedPath = triggerPath.replace(/^\/+|\/+$/g, "").replace(/\/+/g, "-");
|
|
1417
|
+
if (!normalizedPath) {
|
|
1418
|
+
throw new Error("HTTP trigger path must not be empty");
|
|
1419
|
+
}
|
|
1420
|
+
const path = getHttpTriggerApiPath(this.workspaceId, normalizedPath);
|
|
1421
|
+
const rawBody = JSON.stringify(payload != null ? payload : {});
|
|
1422
|
+
const headers = __spreadValues({
|
|
1423
|
+
"Content-Type": "application/json"
|
|
1424
|
+
}, options.headers);
|
|
1425
|
+
if (options.signingSecret !== void 0) {
|
|
1426
|
+
Object.assign(headers, createHttpTriggerSignatureHeaders(rawBody, options));
|
|
1427
|
+
}
|
|
1428
|
+
return this.requestFn("POST", path, rawBody, void 0, { headers });
|
|
1429
|
+
}
|
|
1370
1430
|
};
|
|
1431
|
+
function createHttpTriggerSignatureHeaders(rawBody, options) {
|
|
1432
|
+
var _a, _b;
|
|
1433
|
+
const {
|
|
1434
|
+
signingSecret,
|
|
1435
|
+
signatureHeaderName,
|
|
1436
|
+
signatureIdHeaderName,
|
|
1437
|
+
timestampHeaderName,
|
|
1438
|
+
timestampExtractionPattern,
|
|
1439
|
+
signatureHeaderTemplate = "{sig}",
|
|
1440
|
+
hmacAlgorithm = "sha256",
|
|
1441
|
+
hmacEncoding = "base64",
|
|
1442
|
+
encoding = "base64",
|
|
1443
|
+
secretEncoding = "raw",
|
|
1444
|
+
payloadFormat = "default"
|
|
1445
|
+
} = options;
|
|
1446
|
+
if (!signingSecret) {
|
|
1447
|
+
throw new Error("Signing secret must not be empty when signing an HTTP trigger request");
|
|
1448
|
+
}
|
|
1449
|
+
if (!signatureHeaderName) {
|
|
1450
|
+
throw new Error("signatureHeaderName is required when signing an HTTP trigger request");
|
|
1451
|
+
}
|
|
1452
|
+
const hasTimestamp = Boolean(timestampHeaderName || timestampExtractionPattern);
|
|
1453
|
+
const timestamp = hasTimestamp ? String((_a = options.timestamp) != null ? _a : Math.floor(Date.now() / 1e3)) : void 0;
|
|
1454
|
+
const sigId = signatureIdHeaderName ? (_b = options.sigId) != null ? _b : `msg_${import_crypto.default.randomBytes(12).toString("hex")}` : void 0;
|
|
1455
|
+
let signedPayload = rawBody;
|
|
1456
|
+
if (payloadFormat === "slack") {
|
|
1457
|
+
if (!timestamp) {
|
|
1458
|
+
throw new Error("Slack signatures require timestamp metadata");
|
|
1459
|
+
}
|
|
1460
|
+
signedPayload = `v0:${timestamp}:${rawBody}`;
|
|
1461
|
+
} else {
|
|
1462
|
+
if (timestamp) signedPayload = `${timestamp}.${signedPayload}`;
|
|
1463
|
+
if (sigId) signedPayload = `${sigId}.${signedPayload}`;
|
|
1464
|
+
}
|
|
1465
|
+
let secret;
|
|
1466
|
+
if (secretEncoding === "prefixed-base64") {
|
|
1467
|
+
const separator = signingSecret.indexOf("_");
|
|
1468
|
+
const encodedSecret = separator < 0 ? "" : signingSecret.slice(separator + 1);
|
|
1469
|
+
if (!encodedSecret) {
|
|
1470
|
+
throw new Error("Signing secret is malformed for prefixed-base64 encoding");
|
|
1471
|
+
}
|
|
1472
|
+
secret = Buffer.from(encodedSecret, encoding);
|
|
1473
|
+
} else {
|
|
1474
|
+
secret = Buffer.from(signingSecret, "utf8");
|
|
1475
|
+
}
|
|
1476
|
+
if (secret.length === 0) {
|
|
1477
|
+
throw new Error("Signing secret is malformed: decoded key must not be empty");
|
|
1478
|
+
}
|
|
1479
|
+
const digest = import_crypto.default.createHmac(hmacAlgorithm, secret).update(signedPayload).digest(hmacEncoding);
|
|
1480
|
+
const signatureValue = signatureHeaderTemplate.replace("{sig}", digest).replace("{ts}", timestamp != null ? timestamp : "");
|
|
1481
|
+
const headers = {
|
|
1482
|
+
[signatureHeaderName]: signatureValue
|
|
1483
|
+
};
|
|
1484
|
+
if (timestampHeaderName && timestamp && timestampHeaderName.toLowerCase() !== signatureHeaderName.toLowerCase()) {
|
|
1485
|
+
headers[timestampHeaderName] = timestamp;
|
|
1486
|
+
}
|
|
1487
|
+
if (signatureIdHeaderName && sigId) {
|
|
1488
|
+
headers[signatureIdHeaderName] = sigId;
|
|
1489
|
+
}
|
|
1490
|
+
return headers;
|
|
1491
|
+
}
|
|
1371
1492
|
|
|
1372
1493
|
// ../../backend/shared/query/dist/esm/types.js
|
|
1373
1494
|
var CANONICAL_OPERATORS2 = [
|
|
@@ -7069,6 +7190,12 @@ var AlertDefinitionsManager = class {
|
|
|
7069
7190
|
};
|
|
7070
7191
|
|
|
7071
7192
|
// src/managers/validation.ts
|
|
7193
|
+
function optionalCollectionSlug(value, name = "recordSlug") {
|
|
7194
|
+
if (value !== void 0 && typeof value !== "string") {
|
|
7195
|
+
throw new TypeError(`${name} must be a string`);
|
|
7196
|
+
}
|
|
7197
|
+
return value === "" ? void 0 : value;
|
|
7198
|
+
}
|
|
7072
7199
|
var ValidationManager = class {
|
|
7073
7200
|
constructor(workspaceId, requestFn) {
|
|
7074
7201
|
this.workspaceId = workspaceId;
|
|
@@ -7077,7 +7204,7 @@ var ValidationManager = class {
|
|
|
7077
7204
|
/**
|
|
7078
7205
|
* Trigger a batch validation scan on a structure.
|
|
7079
7206
|
*
|
|
7080
|
-
* @param
|
|
7207
|
+
* @param recordSlug - The collection slug to scan
|
|
7081
7208
|
* @param options - Optional scan configuration
|
|
7082
7209
|
* @returns The batch scan result with batchId for tracking
|
|
7083
7210
|
*
|
|
@@ -7088,11 +7215,16 @@ var ValidationManager = class {
|
|
|
7088
7215
|
* console.log('Records to scan:', batch.data.total);
|
|
7089
7216
|
* ```
|
|
7090
7217
|
*/
|
|
7091
|
-
triggerScan(
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7218
|
+
triggerScan(recordSlug, options) {
|
|
7219
|
+
return __async(this, null, function* () {
|
|
7220
|
+
const slug = optionalCollectionSlug(recordSlug);
|
|
7221
|
+
if (slug === void 0) throw new TypeError("recordSlug is required");
|
|
7222
|
+
const path = getValidationScanApiPath(this.workspaceId);
|
|
7223
|
+
return this.requestFn("POST", path, {
|
|
7224
|
+
recordSlug: slug,
|
|
7225
|
+
structureSlug: slug,
|
|
7226
|
+
validationTypes: options == null ? void 0 : options.validationTypes
|
|
7227
|
+
});
|
|
7096
7228
|
});
|
|
7097
7229
|
}
|
|
7098
7230
|
/**
|
|
@@ -7169,8 +7301,21 @@ var ValidationManager = class {
|
|
|
7169
7301
|
* ```
|
|
7170
7302
|
*/
|
|
7171
7303
|
listSuggestions(options) {
|
|
7172
|
-
|
|
7173
|
-
|
|
7304
|
+
return __async(this, null, function* () {
|
|
7305
|
+
const path = getValidationSuggestionsApiPath(this.workspaceId);
|
|
7306
|
+
if (!options) return this.requestFn("GET", path, null, options);
|
|
7307
|
+
const _a = options, { recordSlug, structureSlug } = _a, query = __objRest(_a, ["recordSlug", "structureSlug"]);
|
|
7308
|
+
const canonical = optionalCollectionSlug(recordSlug);
|
|
7309
|
+
const legacy = optionalCollectionSlug(structureSlug, "structureSlug");
|
|
7310
|
+
if (canonical !== void 0 && legacy !== void 0 && canonical !== legacy) {
|
|
7311
|
+
throw new Error("recordSlug and structureSlug must match");
|
|
7312
|
+
}
|
|
7313
|
+
const slug = canonical != null ? canonical : legacy;
|
|
7314
|
+
const params = __spreadValues({}, query);
|
|
7315
|
+
if (canonical !== void 0) params.recordSlug = canonical;
|
|
7316
|
+
if (slug !== void 0) params.structureSlug = slug;
|
|
7317
|
+
return this.requestFn("GET", path, null, params);
|
|
7318
|
+
});
|
|
7174
7319
|
}
|
|
7175
7320
|
/**
|
|
7176
7321
|
* Get a single validation suggestion by ID.
|
|
@@ -7251,7 +7396,7 @@ var ValidationManager = class {
|
|
|
7251
7396
|
/**
|
|
7252
7397
|
* Get validation summary statistics.
|
|
7253
7398
|
*
|
|
7254
|
-
* @param
|
|
7399
|
+
* @param recordSlug - Optional collection slug to filter summary
|
|
7255
7400
|
* @returns Summary of suggestions by status and type
|
|
7256
7401
|
*
|
|
7257
7402
|
* @example
|
|
@@ -7261,19 +7406,22 @@ var ValidationManager = class {
|
|
|
7261
7406
|
* console.log('By type:', summary.data.byIssueType);
|
|
7262
7407
|
* ```
|
|
7263
7408
|
*/
|
|
7264
|
-
getSummary(
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7409
|
+
getSummary(recordSlug) {
|
|
7410
|
+
return __async(this, null, function* () {
|
|
7411
|
+
const slug = optionalCollectionSlug(recordSlug);
|
|
7412
|
+
const path = getValidationSummaryApiPath(this.workspaceId);
|
|
7413
|
+
const params = slug !== void 0 ? { recordSlug: slug, structureSlug: slug } : void 0;
|
|
7414
|
+
return this.requestFn("GET", path, null, params);
|
|
7415
|
+
});
|
|
7268
7416
|
}
|
|
7269
7417
|
/**
|
|
7270
7418
|
* Get the count of pending suggestions for a structure.
|
|
7271
7419
|
*
|
|
7272
|
-
* @param
|
|
7420
|
+
* @param recordSlug - The collection slug
|
|
7273
7421
|
* @returns Object with pending count
|
|
7274
7422
|
*/
|
|
7275
|
-
getPendingCount(
|
|
7276
|
-
const path = getValidationPendingCountApiPath(this.workspaceId,
|
|
7423
|
+
getPendingCount(recordSlug) {
|
|
7424
|
+
const path = getValidationPendingCountApiPath(this.workspaceId, recordSlug);
|
|
7277
7425
|
return this.requestFn("GET", path);
|
|
7278
7426
|
}
|
|
7279
7427
|
};
|
|
@@ -8405,10 +8553,13 @@ var CentraliSDK = class {
|
|
|
8405
8553
|
this.axios.interceptors.response.use(
|
|
8406
8554
|
(response) => response,
|
|
8407
8555
|
(error) => __async(this, null, function* () {
|
|
8408
|
-
var _a, _b;
|
|
8409
|
-
const originalRequest = error.config;
|
|
8556
|
+
var _a, _b, _c, _d;
|
|
8557
|
+
const originalRequest = error == null ? void 0 : error.config;
|
|
8558
|
+
if (!originalRequest) {
|
|
8559
|
+
return Promise.reject(toCentraliError(error));
|
|
8560
|
+
}
|
|
8410
8561
|
if (this.options.publishableKey) {
|
|
8411
|
-
return Promise.reject(error);
|
|
8562
|
+
return Promise.reject(toCentraliError(error));
|
|
8412
8563
|
}
|
|
8413
8564
|
const isAuthError = ((_a = error.response) == null ? void 0 : _a.status) === 401 || ((_b = error.response) == null ? void 0 : _b.status) === 403;
|
|
8414
8565
|
const hasNotRetried = !originalRequest._hasRetried;
|
|
@@ -8416,10 +8567,10 @@ var CentraliSDK = class {
|
|
|
8416
8567
|
originalRequest._hasRetried = true;
|
|
8417
8568
|
try {
|
|
8418
8569
|
this.token = yield this.options.getToken();
|
|
8419
|
-
originalRequest.headers.Authorization = `Bearer ${this.token}`;
|
|
8570
|
+
((_c = originalRequest.headers) != null ? _c : originalRequest.headers = {}).Authorization = `Bearer ${this.token}`;
|
|
8420
8571
|
return this.axios(originalRequest);
|
|
8421
8572
|
} catch (refreshError) {
|
|
8422
|
-
return Promise.reject(error);
|
|
8573
|
+
return Promise.reject(toCentraliError(error));
|
|
8423
8574
|
}
|
|
8424
8575
|
}
|
|
8425
8576
|
const hasClientCredentials = this.options.clientId && this.options.clientSecret;
|
|
@@ -8439,13 +8590,13 @@ var CentraliSDK = class {
|
|
|
8439
8590
|
this.isRefreshingToken = false;
|
|
8440
8591
|
this.tokenRefreshPromise = null;
|
|
8441
8592
|
}
|
|
8442
|
-
originalRequest.headers.Authorization = `Bearer ${this.token}`;
|
|
8593
|
+
((_d = originalRequest.headers) != null ? _d : originalRequest.headers = {}).Authorization = `Bearer ${this.token}`;
|
|
8443
8594
|
return this.axios(originalRequest);
|
|
8444
8595
|
} catch (refreshError) {
|
|
8445
8596
|
this.isRefreshingToken = false;
|
|
8446
8597
|
this.tokenRefreshPromise = null;
|
|
8447
8598
|
this.token = null;
|
|
8448
|
-
return Promise.reject(toCentraliError(
|
|
8599
|
+
return Promise.reject(toCentraliError(error));
|
|
8449
8600
|
}
|
|
8450
8601
|
}
|
|
8451
8602
|
return Promise.reject(toCentraliError(error));
|
|
@@ -8525,7 +8676,8 @@ var CentraliSDK = class {
|
|
|
8525
8676
|
if (!this._triggers) {
|
|
8526
8677
|
this._triggers = new TriggersManager(
|
|
8527
8678
|
this.options.workspaceId,
|
|
8528
|
-
this.request.bind(this)
|
|
8679
|
+
this.request.bind(this),
|
|
8680
|
+
this.requestBody.bind(this)
|
|
8529
8681
|
);
|
|
8530
8682
|
}
|
|
8531
8683
|
return this._triggers;
|
|
@@ -9150,30 +9302,29 @@ var CentraliSDK = class {
|
|
|
9150
9302
|
});
|
|
9151
9303
|
};
|
|
9152
9304
|
}
|
|
9153
|
-
/**
|
|
9154
|
-
|
|
9155
|
-
|
|
9305
|
+
/** Return the typed HTTP body without applying legacy envelope normalization. */
|
|
9306
|
+
requestBody(method, path, data, queryParams, config) {
|
|
9307
|
+
return __async(this, null, function* () {
|
|
9308
|
+
const response = yield this.axios.request(__spreadValues({ method, url: path, data, params: queryParams }, config));
|
|
9309
|
+
return response.data;
|
|
9310
|
+
});
|
|
9311
|
+
}
|
|
9156
9312
|
request(method, path, data, queryParams, config) {
|
|
9157
9313
|
return __async(this, null, function* () {
|
|
9158
|
-
const
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
data,
|
|
9162
|
-
params: queryParams
|
|
9163
|
-
}, config));
|
|
9164
|
-
if (typeof resp.data !== "object" || resp.data === null) {
|
|
9165
|
-
return { data: resp.data };
|
|
9314
|
+
const body = yield this.requestBody(method, path, data, queryParams, config);
|
|
9315
|
+
if (typeof body !== "object" || body === null) {
|
|
9316
|
+
return { data: body };
|
|
9166
9317
|
}
|
|
9167
|
-
if (Array.isArray(
|
|
9168
|
-
return { data:
|
|
9318
|
+
if (Array.isArray(body)) {
|
|
9319
|
+
return { data: body };
|
|
9169
9320
|
}
|
|
9170
|
-
if ("result" in
|
|
9171
|
-
return { data:
|
|
9321
|
+
if ("result" in body && !("data" in body)) {
|
|
9322
|
+
return { data: body.result };
|
|
9172
9323
|
}
|
|
9173
|
-
if (!("data" in
|
|
9174
|
-
return { data:
|
|
9324
|
+
if (!("data" in body)) {
|
|
9325
|
+
return { data: body };
|
|
9175
9326
|
}
|
|
9176
|
-
return
|
|
9327
|
+
return body;
|
|
9177
9328
|
});
|
|
9178
9329
|
}
|
|
9179
9330
|
// ------------------ Data API Methods ------------------
|
|
@@ -9626,6 +9777,7 @@ var CentraliSDK = class {
|
|
|
9626
9777
|
getFunctionTriggerPauseApiPath,
|
|
9627
9778
|
getFunctionTriggerResumeApiPath,
|
|
9628
9779
|
getFunctionTriggersApiPath,
|
|
9780
|
+
getHttpTriggerApiPath,
|
|
9629
9781
|
getOrchestrationRunStepsApiPath,
|
|
9630
9782
|
getOrchestrationRunsApiPath,
|
|
9631
9783
|
getOrchestrationRunsCanonicalApiPath,
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -129,11 +129,16 @@ export class CentraliSDK {
|
|
|
129
129
|
this.axios.interceptors.response.use(
|
|
130
130
|
(response) => response,
|
|
131
131
|
async (error) => {
|
|
132
|
-
const originalRequest = error
|
|
132
|
+
const originalRequest = error?.config;
|
|
133
|
+
|
|
134
|
+
// Token failures and transport errors may have no request to retry.
|
|
135
|
+
if (!originalRequest) {
|
|
136
|
+
return Promise.reject(toCentraliError(error));
|
|
137
|
+
}
|
|
133
138
|
|
|
134
139
|
// Publishable keys: no retry — scope errors are permanent
|
|
135
140
|
if (this.options.publishableKey) {
|
|
136
|
-
return Promise.reject(error);
|
|
141
|
+
return Promise.reject(toCentraliError(error));
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
const isAuthError = error.response?.status === 401 || error.response?.status === 403;
|
|
@@ -144,10 +149,10 @@ export class CentraliSDK {
|
|
|
144
149
|
originalRequest._hasRetried = true;
|
|
145
150
|
try {
|
|
146
151
|
this.token = await this.options.getToken();
|
|
147
|
-
originalRequest.headers.Authorization = `Bearer ${this.token}`;
|
|
152
|
+
(originalRequest.headers ??= {}).Authorization = `Bearer ${this.token}`;
|
|
148
153
|
return this.axios(originalRequest);
|
|
149
154
|
} catch (refreshError) {
|
|
150
|
-
return Promise.reject(error);
|
|
155
|
+
return Promise.reject(toCentraliError(error));
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
158
|
|
|
@@ -176,14 +181,14 @@ export class CentraliSDK {
|
|
|
176
181
|
}
|
|
177
182
|
|
|
178
183
|
// Retry the original request with the new token
|
|
179
|
-
originalRequest.headers.Authorization = `Bearer ${this.token}`;
|
|
184
|
+
(originalRequest.headers ??= {}).Authorization = `Bearer ${this.token}`;
|
|
180
185
|
return this.axios(originalRequest);
|
|
181
186
|
} catch (refreshError) {
|
|
182
187
|
// Token refresh failed, clear state and reject
|
|
183
188
|
this.isRefreshingToken = false;
|
|
184
189
|
this.tokenRefreshPromise = null;
|
|
185
190
|
this.token = null;
|
|
186
|
-
return Promise.reject(toCentraliError(
|
|
191
|
+
return Promise.reject(toCentraliError(error));
|
|
187
192
|
}
|
|
188
193
|
}
|
|
189
194
|
|
|
@@ -268,7 +273,8 @@ export class CentraliSDK {
|
|
|
268
273
|
if (!this._triggers) {
|
|
269
274
|
this._triggers = new TriggersManager(
|
|
270
275
|
this.options.workspaceId,
|
|
271
|
-
this.request.bind(this)
|
|
276
|
+
this.request.bind(this),
|
|
277
|
+
this.requestBody.bind(this)
|
|
272
278
|
);
|
|
273
279
|
}
|
|
274
280
|
return this._triggers;
|
|
@@ -921,9 +927,13 @@ export class CentraliSDK {
|
|
|
921
927
|
};
|
|
922
928
|
}
|
|
923
929
|
|
|
924
|
-
/**
|
|
925
|
-
|
|
926
|
-
|
|
930
|
+
/** Return the typed HTTP body without applying legacy envelope normalization. */
|
|
931
|
+
private async requestBody<T>(method: Method, path: string, data?: any,
|
|
932
|
+
queryParams?: Record<string, any>, config?: AxiosRequestConfig): Promise<T> {
|
|
933
|
+
const response = await this.axios.request<T>({ method, url: path, data, params: queryParams, ...config });
|
|
934
|
+
return response.data;
|
|
935
|
+
}
|
|
936
|
+
|
|
927
937
|
private async request<T>(
|
|
928
938
|
method: Method,
|
|
929
939
|
path: string,
|
|
@@ -931,32 +941,26 @@ export class CentraliSDK {
|
|
|
931
941
|
queryParams?: Record<string, any>,
|
|
932
942
|
config?: AxiosRequestConfig
|
|
933
943
|
): Promise<ApiResponse<T>> {
|
|
934
|
-
const
|
|
935
|
-
method,
|
|
936
|
-
url: path,
|
|
937
|
-
data,
|
|
938
|
-
params: queryParams,
|
|
939
|
-
...config,
|
|
940
|
-
});
|
|
944
|
+
const body = await this.requestBody<ApiResponse<T>>(method, path, data, queryParams, config);
|
|
941
945
|
|
|
942
946
|
// 🔧 Normalize responses to always return { data: T, ... } format
|
|
943
947
|
// Handle primitives (strings, numbers, etc.)
|
|
944
|
-
if (typeof
|
|
945
|
-
return { data:
|
|
948
|
+
if (typeof body !== 'object' || body === null) {
|
|
949
|
+
return { data: body as T };
|
|
946
950
|
}
|
|
947
951
|
// Handle arrays (which are objects but should be wrapped in data property)
|
|
948
|
-
if (Array.isArray(
|
|
949
|
-
return { data:
|
|
952
|
+
if (Array.isArray(body)) {
|
|
953
|
+
return { data: body as T };
|
|
950
954
|
}
|
|
951
955
|
// Handle { result } responses (smart queries and some other endpoints)
|
|
952
|
-
if ('result' in
|
|
953
|
-
return { data: (
|
|
956
|
+
if ('result' in body && !('data' in body)) {
|
|
957
|
+
return { data: (body as any).result as T };
|
|
954
958
|
}
|
|
955
959
|
// Handle objects that don't have a data property (legacy endpoints)
|
|
956
|
-
if (!('data' in
|
|
957
|
-
return { data:
|
|
960
|
+
if (!('data' in body)) {
|
|
961
|
+
return { data: body as T };
|
|
958
962
|
}
|
|
959
|
-
return
|
|
963
|
+
return body;
|
|
960
964
|
}
|
|
961
965
|
|
|
962
966
|
// ------------------ Data API Methods ------------------
|
package/src/internal/auth.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
+
import { toCentraliError } from './error';
|
|
2
3
|
import { getApiUrl, getAuthUrl } from '../urls';
|
|
3
4
|
|
|
4
5
|
// Helper to encode form data
|
|
@@ -32,13 +33,17 @@ async function fetchClientTokenForResource(
|
|
|
32
33
|
client_secret: clientSecret,
|
|
33
34
|
resource,
|
|
34
35
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
try {
|
|
37
|
+
const resp = await axios.post(
|
|
38
|
+
tokenEndpoint,
|
|
39
|
+
form,
|
|
40
|
+
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
41
|
+
proxy: false
|
|
42
|
+
}
|
|
43
|
+
);
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
return resp.data.access_token;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw toCentraliError(error);
|
|
48
|
+
}
|
|
44
49
|
}
|
package/src/internal/error.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Error Types
|
|
3
3
|
// =====================================================
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { isAxiosError } from 'axios';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Error thrown by the Centrali SDK when an HTTP request fails.
|
|
@@ -74,7 +74,7 @@ export function isCentraliError(err: unknown): err is CentraliError {
|
|
|
74
74
|
|
|
75
75
|
export function toCentraliError(err: unknown): CentraliError {
|
|
76
76
|
if (err instanceof CentraliError) return err;
|
|
77
|
-
if (err
|
|
77
|
+
if (isAxiosError(err)) {
|
|
78
78
|
const status = err.response?.status;
|
|
79
79
|
const statusText = err.response?.statusText;
|
|
80
80
|
const body = err.response?.data as any;
|
package/src/internal/paths.ts
CHANGED
|
@@ -62,6 +62,13 @@ export function getEndpointApiPath(workspaceId: string, path: string): string {
|
|
|
62
62
|
return `data/workspace/${workspaceId}/api/v1/endpoints/${path}`;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Generate HTTP trigger invocation API URL PATH.
|
|
67
|
+
*/
|
|
68
|
+
export function getHttpTriggerApiPath(workspaceId: string, path: string): string {
|
|
69
|
+
return `data/workspace/${workspaceId}/api/v1/http-trigger/${path}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
65
72
|
/**
|
|
66
73
|
* Generate Saved Queries base API URL PATH for workspace-level operations.
|
|
67
74
|
*
|