@centrali-io/centrali-sdk 9.12.0 → 9.13.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 +44 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -1
- package/package.json +1 -1
- package/src/managers/triggers.ts +8 -1
- package/src/types/triggers.ts +2 -0
package/README.md
CHANGED
|
@@ -1532,3 +1532,47 @@ ISC © Blueinit
|
|
|
1532
1532
|
---
|
|
1533
1533
|
|
|
1534
1534
|
**Built with ❤️ by the Centrali team**
|
|
1535
|
+
|
|
1536
|
+
## Endpoint idempotency (CEN-1555)
|
|
1537
|
+
|
|
1538
|
+
Synchronous endpoint triggers accept `Idempotency-Key` (1–255 printable ASCII
|
|
1539
|
+
characters, excluding spaces). Use one random key per logical operation and reuse
|
|
1540
|
+
that key with the same method, query and body when retrying. Every request still
|
|
1541
|
+
passes trigger validation and authentication before any stored result is read.
|
|
1542
|
+
Keys are scoped to workspace and trigger; the request fingerprint also includes
|
|
1543
|
+
the authenticated user. Raw keys are hashed before storage.
|
|
1544
|
+
|
|
1545
|
+
The first call claims the key using a PostgreSQL unique constraint. A repeat while
|
|
1546
|
+
it is running returns 409 with `Retry-After: 1`; a completed repeat returns the
|
|
1547
|
+
stored status, custom headers and JSON body with `Idempotent-Replayed: true`.
|
|
1548
|
+
A different request with the same key returns 422. Exact raw body bytes matter:
|
|
1549
|
+
changing JSON whitespace can count as a different request. Requests without a key
|
|
1550
|
+
retain the existing dispatch/retry behavior.
|
|
1551
|
+
|
|
1552
|
+
Keyed calls make one NATS dispatch attempt. Execution errors and transport errors
|
|
1553
|
+
returned by the dispatcher are stored and replayed, including uncertain failures;
|
|
1554
|
+
they do not release the key. An unexpected process or persistence failure can
|
|
1555
|
+
leave an in-progress claim until expiry. Do not use a new key merely to bypass an
|
|
1556
|
+
uncertain failure: reconcile external side effects first. Result persistence
|
|
1557
|
+
continues if the HTTP client disconnects while the data process stays alive.
|
|
1558
|
+
This does not recover a result after data-process death or a lost NATS reply.
|
|
1559
|
+
|
|
1560
|
+
Claims expire 24 hours after creation, including orphaned claims. Reuse after
|
|
1561
|
+
expiry can execute again. There is no exactly-once guarantee for external side
|
|
1562
|
+
effects. The stored response limit is 1 MiB including headers; an oversized result
|
|
1563
|
+
is replaced with a replayable 500 error. The existing daily trigger-health queue
|
|
1564
|
+
worker deletes expired rows using workspace-scoped, idempotent deletes. Cleanup
|
|
1565
|
+
may lag expiry; atomic claim replacement does not depend on cleanup timing.
|
|
1566
|
+
|
|
1567
|
+
Deploy the additive endpoint_idempotency migration before enabling this code.
|
|
1568
|
+
Rollback application code first; retain the table until all keyed calls have
|
|
1569
|
+
expired. Removing the feature or dropping the table removes retry protection.
|
|
1570
|
+
|
|
1571
|
+
SDK example:
|
|
1572
|
+
|
|
1573
|
+
```ts
|
|
1574
|
+
await client.triggers.invokeEndpoint('create-order', {
|
|
1575
|
+
payload: { product: 'widget', quantity: 1 },
|
|
1576
|
+
idempotencyKey: orderAttemptId,
|
|
1577
|
+
});
|
|
1578
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1433,6 +1433,8 @@ interface InvokeTriggerOptions {
|
|
|
1433
1433
|
* Options for invoking a synchronous compute endpoint.
|
|
1434
1434
|
*/
|
|
1435
1435
|
interface InvokeEndpointOptions {
|
|
1436
|
+
/** Reuse the same key and payload to retry a logical operation for up to 24 hours. */
|
|
1437
|
+
idempotencyKey?: string;
|
|
1436
1438
|
/** HTTP method (default: 'POST'). Must be in the trigger's allowedMethods. */
|
|
1437
1439
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
1438
1440
|
/** Request body payload (sent as JSON). Ignored for GET/DELETE. */
|
package/dist/index.js
CHANGED
|
@@ -1402,7 +1402,14 @@ var TriggersManager = class {
|
|
|
1402
1402
|
const method = (options == null ? void 0 : options.method) || "POST";
|
|
1403
1403
|
const data = ["GET", "DELETE"].includes(method) ? void 0 : (options == null ? void 0 : options.payload) || {};
|
|
1404
1404
|
const queryParams = options == null ? void 0 : options.query;
|
|
1405
|
-
|
|
1405
|
+
const headers = __spreadValues({}, options == null ? void 0 : options.headers);
|
|
1406
|
+
if ((options == null ? void 0 : options.idempotencyKey) !== void 0) {
|
|
1407
|
+
for (const name of Object.keys(headers)) {
|
|
1408
|
+
if (name.toLowerCase() === "idempotency-key") delete headers[name];
|
|
1409
|
+
}
|
|
1410
|
+
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
1411
|
+
}
|
|
1412
|
+
return this.requestFn(method, path, data, queryParams, { headers });
|
|
1406
1413
|
}
|
|
1407
1414
|
/**
|
|
1408
1415
|
* Invoke an asynchronous HTTP trigger by its stable path.
|
package/package.json
CHANGED
package/src/managers/triggers.ts
CHANGED
|
@@ -362,7 +362,14 @@ export class TriggersManager {
|
|
|
362
362
|
const method = (options?.method || 'POST') as Method;
|
|
363
363
|
const data = ['GET', 'DELETE'].includes(method) ? undefined : (options?.payload || {});
|
|
364
364
|
const queryParams = options?.query;
|
|
365
|
-
|
|
365
|
+
const headers = { ...options?.headers };
|
|
366
|
+
if (options?.idempotencyKey !== undefined) {
|
|
367
|
+
for (const name of Object.keys(headers)) {
|
|
368
|
+
if (name.toLowerCase() === 'idempotency-key') delete headers[name];
|
|
369
|
+
}
|
|
370
|
+
headers['Idempotency-Key'] = options.idempotencyKey;
|
|
371
|
+
}
|
|
372
|
+
return this.requestFn<T>(method, path, data, queryParams, { headers });
|
|
366
373
|
}
|
|
367
374
|
|
|
368
375
|
/**
|
package/src/types/triggers.ts
CHANGED
|
@@ -38,6 +38,8 @@ export interface InvokeTriggerOptions {
|
|
|
38
38
|
* Options for invoking a synchronous compute endpoint.
|
|
39
39
|
*/
|
|
40
40
|
export interface InvokeEndpointOptions {
|
|
41
|
+
/** Reuse the same key and payload to retry a logical operation for up to 24 hours. */
|
|
42
|
+
idempotencyKey?: string;
|
|
41
43
|
/** HTTP method (default: 'POST'). Must be in the trigger's allowedMethods. */
|
|
42
44
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
43
45
|
/** Request body payload (sent as JSON). Ignored for GET/DELETE. */
|