@tinycloud/sdk-services 3.1.0-beta.9 → 3.2.0-beta.2
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/dist/index.cjs +641 -182
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +147 -14
- package/dist/index.d.ts +147 -14
- package/dist/index.js +637 -182
- package/dist/index.js.map +1 -1
- package/dist/kv/index.cjs +60 -15
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.d.cts +12 -2
- package/dist/kv/index.d.ts +12 -2
- package/dist/kv/index.js +60 -15
- package/dist/kv/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1521,9 +1521,51 @@ interface SubscribeOptions {
|
|
|
1521
1521
|
}
|
|
1522
1522
|
interface HooksServiceConfig extends Record<string, unknown> {
|
|
1523
1523
|
host?: string;
|
|
1524
|
+
/** Shared-stream retry tuning; see {@link HookStreamRetryConfig}. */
|
|
1525
|
+
streamRetry?: HookStreamRetryConfig;
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Retry policy for the shared `/hooks/events` stream. When the stream fails
|
|
1529
|
+
* (network error, 5xx, or an expired/rotated ticket rejected with 401/403)
|
|
1530
|
+
* it is re-opened with exponential backoff: `HOOK_STREAM_RETRY_BASE_DELAY_MS`
|
|
1531
|
+
* (~250 ms) doubling to `HOOK_STREAM_RETRY_MAX_DELAY_MS` (~30 s) with jitter.
|
|
1532
|
+
* The retry streak resets after an event is received or a stream remains open
|
|
1533
|
+
* for at least 5 seconds. Retries stop when no subscribers remain, when the
|
|
1534
|
+
* service is aborted, or when minting the hook ticket is refused (the iterator
|
|
1535
|
+
* throws that typed error instead).
|
|
1536
|
+
*/
|
|
1537
|
+
interface HookStreamRetryConfig {
|
|
1538
|
+
/**
|
|
1539
|
+
* Delay before retry attempt `attempt` (1-based). Defaults to the jittered
|
|
1540
|
+
* exponential backoff described above. Must return milliseconds.
|
|
1541
|
+
*/
|
|
1542
|
+
delay?: (attempt: number) => number;
|
|
1543
|
+
/**
|
|
1544
|
+
* How a retry delay is awaited — the injectable clock. `delayMs` is the
|
|
1545
|
+
* resolved delay for `attempt`; `signal` aborts the wait early when the
|
|
1546
|
+
* subscription set changes or the service stops. Rejecting or throwing is
|
|
1547
|
+
* treated like a completed wait. After a custom wait returns — whether it
|
|
1548
|
+
* fulfilled, rejected or threw — the service still yields one event-loop
|
|
1549
|
+
* turn so a persistently failing stream can never starve the process.
|
|
1550
|
+
* Defaults to an abortable, unref'd `setTimeout`.
|
|
1551
|
+
*/
|
|
1552
|
+
wait?: (delayMs: number, attempt: number, signal: AbortSignal) => Promise<void>;
|
|
1524
1553
|
}
|
|
1525
1554
|
|
|
1526
1555
|
interface IHooksService {
|
|
1556
|
+
/**
|
|
1557
|
+
* Stream hook events until `options.signal` aborts, the SDK signs out or
|
|
1558
|
+
* the session ends, or the consumer stops iterating. Transient stream
|
|
1559
|
+
* failures — network errors, 5xx, and an expired or rotated ticket rejected
|
|
1560
|
+
* by `/hooks/events` (401/403) — are retried internally with backoff and
|
|
1561
|
+
* never reach the iterator.
|
|
1562
|
+
*
|
|
1563
|
+
* The iterator throws when minting the hook ticket is refused. The thrown
|
|
1564
|
+
* plain `ServiceError` carries `meta.status` with the refusing HTTP status,
|
|
1565
|
+
* so `for await` consumers can branch on it. Stream diagnostics contain only
|
|
1566
|
+
* SDK allow-listed identifiers; foreign error messages and causes are not
|
|
1567
|
+
* copied.
|
|
1568
|
+
*/
|
|
1527
1569
|
subscribe(subscriptions: HookSubscription[], options?: SubscribeOptions): AsyncIterable<HookEvent>;
|
|
1528
1570
|
register(webhook: HookWebhookRegistration): Promise<Result<HookWebhookRecord>>;
|
|
1529
1571
|
list(options?: HookWebhookListOptions): Promise<Result<HookWebhookRecord[]>>;
|
|
@@ -1534,10 +1576,13 @@ declare class HooksService extends BaseService implements IHooksService {
|
|
|
1534
1576
|
static readonly serviceName = "hooks";
|
|
1535
1577
|
protected _config: HooksServiceConfig;
|
|
1536
1578
|
private readonly _subscribers;
|
|
1537
|
-
|
|
1538
|
-
private
|
|
1539
|
-
|
|
1540
|
-
private
|
|
1579
|
+
/** True while the one supervisor loop runs. Set only by wake(), cleared only at loop exit. */
|
|
1580
|
+
private _supervising;
|
|
1581
|
+
/** The supervisor's current step, interruptible by wake(). */
|
|
1582
|
+
private _phase?;
|
|
1583
|
+
/** Bumped on every session change; part of the plan key. */
|
|
1584
|
+
private _sessionGeneration;
|
|
1585
|
+
private _lastContextSignal?;
|
|
1541
1586
|
constructor(config?: HooksServiceConfig);
|
|
1542
1587
|
get config(): HooksServiceConfig;
|
|
1543
1588
|
private get host();
|
|
@@ -1545,14 +1590,60 @@ declare class HooksService extends BaseService implements IHooksService {
|
|
|
1545
1590
|
register(webhook: HookWebhookRegistration): Promise<Result<HookWebhookRecord>>;
|
|
1546
1591
|
list(options?: HookWebhookListOptions): Promise<Result<HookWebhookRecord[]>>;
|
|
1547
1592
|
unregister(id: string, options?: HookWebhookUnregisterOptions): Promise<Result<void>>;
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1593
|
+
/**
|
|
1594
|
+
* Called after anything that may change what the supervisor should do:
|
|
1595
|
+
* subscribe, unsubscribe, session change, sign-out. Interrupts the running
|
|
1596
|
+
* step if the plan moved away from it, and starts the supervisor if none
|
|
1597
|
+
* runs. Touches only SDK-owned state, so it never throws into callers such
|
|
1598
|
+
* as `ServiceContext.setSession`.
|
|
1599
|
+
*/
|
|
1600
|
+
private wake;
|
|
1601
|
+
/**
|
|
1602
|
+
* The only owner of the shared stream. Each iteration is one attempt
|
|
1603
|
+
* (mint → open → drain), then a classification and, unless the attempt was
|
|
1604
|
+
* superseded or released its subscribers, a backoff. Every await is a
|
|
1605
|
+
* `phase` that wake() can interrupt; an interrupted phase yields
|
|
1606
|
+
* `undefined`, so a superseded mint can never act. Outside `attempt` and
|
|
1607
|
+
* `pause`, which each own one catch, the loop touches only SDK state.
|
|
1608
|
+
*/
|
|
1609
|
+
private supervise;
|
|
1610
|
+
/**
|
|
1611
|
+
* Run one step under an interrupt that wake() fires when the plan key moves
|
|
1612
|
+
* on. An interrupted step's result is discarded. The interrupt is also
|
|
1613
|
+
* fired when the step returns, which releases whatever it left open: the
|
|
1614
|
+
* request signal and its listeners, an unread response body, a timer.
|
|
1615
|
+
*/
|
|
1616
|
+
private phase;
|
|
1617
|
+
/**
|
|
1618
|
+
* One mint → open → drain. The single catch site for everything the
|
|
1619
|
+
* attempt touches that the SDK does not own: context accessors, invoke,
|
|
1620
|
+
* fetch, response bodies, the SSE parser. Never rejects.
|
|
1621
|
+
*/
|
|
1622
|
+
private attempt;
|
|
1623
|
+
/**
|
|
1624
|
+
* Back off before the next attempt. `config.streamRetry` overrides the
|
|
1625
|
+
* delay and the clock; whatever they do, the pause ends by the delay or the
|
|
1626
|
+
* interrupt, then yields one timer turn so an instant clock cannot starve
|
|
1627
|
+
* due timers or the process.
|
|
1628
|
+
*/
|
|
1629
|
+
private pause;
|
|
1630
|
+
/** The stream the current subscribers need, or undefined when none remain. */
|
|
1631
|
+
private plan;
|
|
1632
|
+
private dispatch;
|
|
1633
|
+
/**
|
|
1634
|
+
* Detach every subscriber. With `error`, their iterators throw it after
|
|
1635
|
+
* draining buffered events; without, they complete.
|
|
1636
|
+
*/
|
|
1637
|
+
private release;
|
|
1638
|
+
private report;
|
|
1639
|
+
/**
|
|
1640
|
+
* Unreachable by construction. If the loop ever rejects anyway, fail its
|
|
1641
|
+
* subscribers visibly instead of stranding them or crashing the process.
|
|
1642
|
+
*/
|
|
1643
|
+
private collapse;
|
|
1644
|
+
onSessionChange(session: ServiceSession | null): void;
|
|
1645
|
+
onSignOut(): void;
|
|
1553
1646
|
private createHookHeaders;
|
|
1554
|
-
private mintHookTicket;
|
|
1555
|
-
private openHookStream;
|
|
1556
1647
|
private createInvokeHeaders;
|
|
1557
1648
|
}
|
|
1558
1649
|
|
|
@@ -1617,6 +1708,11 @@ interface VaultPutOptions {
|
|
|
1617
1708
|
contentType?: string;
|
|
1618
1709
|
/** Custom serializer (default: JSON.stringify for objects) */
|
|
1619
1710
|
serialize?: (value: unknown) => Uint8Array;
|
|
1711
|
+
/**
|
|
1712
|
+
* `"*"` writes only when no value exists at the key. An existing value
|
|
1713
|
+
* fails with `ALREADY_EXISTS`; it is never overwritten.
|
|
1714
|
+
*/
|
|
1715
|
+
ifNoneMatch?: "*";
|
|
1620
1716
|
}
|
|
1621
1717
|
/**
|
|
1622
1718
|
* Options for vault get operations.
|
|
@@ -1739,6 +1835,28 @@ type VaultErrorInput = {
|
|
|
1739
1835
|
code: "STORAGE_ERROR";
|
|
1740
1836
|
cause: Error;
|
|
1741
1837
|
message?: string;
|
|
1838
|
+
meta?: Record<string, unknown>;
|
|
1839
|
+
} | {
|
|
1840
|
+
code: "ALREADY_EXISTS";
|
|
1841
|
+
key: string;
|
|
1842
|
+
message?: string;
|
|
1843
|
+
meta?: Record<string, unknown>;
|
|
1844
|
+
/** The typed KV error that refused the write (an `Error` carrying its `code`, `service` and `meta`). */
|
|
1845
|
+
cause: ServiceError & Error;
|
|
1846
|
+
} | {
|
|
1847
|
+
/** HTTP 401 only: the session must sign in again. */
|
|
1848
|
+
code: "AUTH_UNAUTHORIZED";
|
|
1849
|
+
message: string;
|
|
1850
|
+
meta?: Record<string, unknown>;
|
|
1851
|
+
/** The typed KV error that refused the write (an `Error` carrying its `code`, `service` and `meta`). */
|
|
1852
|
+
cause: ServiceError & Error;
|
|
1853
|
+
} | {
|
|
1854
|
+
/** A 403, or an authorization refusal without a status: signing in again does not help. */
|
|
1855
|
+
code: "PERMISSION_DENIED";
|
|
1856
|
+
message: string;
|
|
1857
|
+
meta?: Record<string, unknown>;
|
|
1858
|
+
/** The typed KV error that refused the write (an `Error` carrying its `code`, `service` and `meta`). */
|
|
1859
|
+
cause: ServiceError & Error;
|
|
1742
1860
|
} | {
|
|
1743
1861
|
code: "STORAGE_QUOTA_EXCEEDED" | "STORAGE_LIMIT_REACHED";
|
|
1744
1862
|
message: string;
|
|
@@ -2226,6 +2344,21 @@ interface SecretScopeOptions {
|
|
|
2226
2344
|
/** Optional logical scope. Omit for the global secret namespace. */
|
|
2227
2345
|
scope?: string;
|
|
2228
2346
|
}
|
|
2347
|
+
/** Canonical secret scope grammar shared with the TC-832 `/request` link. */
|
|
2348
|
+
declare const SECRET_SCOPE_RE: RegExp;
|
|
2349
|
+
/** Longest scope the TC-832 `/request` link accepts. */
|
|
2350
|
+
declare const MAX_SECRET_SCOPE_LENGTH = 64;
|
|
2351
|
+
/** Scopes the TC-832 `/request` link refuses. */
|
|
2352
|
+
declare const TC832_RESERVED_SCOPES: readonly string[];
|
|
2353
|
+
interface SecretPutOptions extends SecretScopeOptions {
|
|
2354
|
+
/** Write only when no secret exists under this name; never overwrite. */
|
|
2355
|
+
ifAbsent?: boolean;
|
|
2356
|
+
}
|
|
2357
|
+
/**
|
|
2358
|
+
* Derive the canonical secret scope for an app id such as
|
|
2359
|
+
* `xyz.tinycloud.feed-workflows` → `xyz-tinycloud-feed-workflows`.
|
|
2360
|
+
*/
|
|
2361
|
+
declare function appSecretScope(appId: string): string;
|
|
2229
2362
|
interface ResolvedSecretPath {
|
|
2230
2363
|
/** Canonical env-style secret name. */
|
|
2231
2364
|
name: string;
|
|
@@ -2266,7 +2399,7 @@ interface ISecretsService {
|
|
|
2266
2399
|
lock(): void;
|
|
2267
2400
|
readonly isUnlocked: boolean;
|
|
2268
2401
|
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
2269
|
-
put(name: string, value: string, options?:
|
|
2402
|
+
put(name: string, value: string, options?: SecretPutOptions): Promise<Result<void, SecretsError>>;
|
|
2270
2403
|
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
2271
2404
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2272
2405
|
/** List global and scoped secrets without decrypting their values. */
|
|
@@ -2281,10 +2414,10 @@ declare class SecretsService implements ISecretsService {
|
|
|
2281
2414
|
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
2282
2415
|
lock(): void;
|
|
2283
2416
|
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
2284
|
-
put(name: string, value: string, options?:
|
|
2417
|
+
put(name: string, value: string, options?: SecretPutOptions): Promise<Result<void, SecretsError>>;
|
|
2285
2418
|
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
2286
2419
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2287
2420
|
listAll(): Promise<Result<SecretCatalogEntry[], SecretsError>>;
|
|
2288
2421
|
}
|
|
2289
2422
|
|
|
2290
|
-
export { type AuthorizationVerdict, BaseService, type ColumnInfo, type DataVaultConfig, DataVaultService, DecryptCapabilityProof, DuckDbAction, type DuckDbActionType, type DuckDbBatchOptions, type BatchResponse as DuckDbBatchResponse, DuckDbDatabaseHandle, type DuckDbExecuteOptions, type ExecuteResponse as DuckDbExecuteResponse, type DuckDbOptions, type DuckDbQueryOptions, type QueryResponse as DuckDbQueryResponse, DuckDbService, type DuckDbServiceConfig, type DuckDbStatement, type DuckDbValue, EventHandler, FetchFunction, GenericKVResponseSchema, type GenericKVResponseType, GenericResultSchema, type HookEvent, type HookServiceName, type HookStreamEvent, type HookSubscription, type HookWebhookListOptions, type HookWebhookRecord, type HookWebhookRegistration, type HookWebhookScope, type HookWebhookUnregisterOptions, HooksService, type HooksServiceConfig, type IDataVaultService, type IDuckDbDatabaseHandle, type IDuckDbService, IEncryptionService, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, type ParsedSecretCatalogKey, PermissionHint, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, STORAGE_FULL_MESSAGE, STORAGE_WRITE_TOO_LARGE_MESSAGE, type SchemaInfo, type SecretCatalogEntry, type SecretPayload, type SecretScopeOptions, type SecretsError, SecretsService, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, type TableInfo, TelemetryConfig, TelemetrySpanEventSchema, type TelemetrySpanEventType, type TinyCloudDebugEnableOptions, type TinyCloudDebugEvent, type TinyCloudDebugLevel, TinyCloudDebugLogger, type TinyCloudDebugTimer, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, type VaultListPage, type VaultNetworkReadResult, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, authExpiredError, authRequiredError, authUnauthorizedError, authorizationVerdictOf, canonicalizeSecretScope, clearTinyCloudDebugLogs, createKVResponseSchema, createResultSchema, createVaultCrypto, disableTinyCloudDebug, enableTinyCloudDebug, errorResult, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isStorageFullError, networkError, notFoundError, parseAuthError, parseCapabilityResource, parsePermissionHint, parsePermissionHintFromErrorText, parseSecretCatalogKey, parseStorageQuotaBytes, permissionDeniedError, resolveSecretListPrefix, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, storageRejectionError, timeoutError, tinyCloudDebugLogger, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, validateTelemetrySpanEvent, validatedCapabilityOf, wrapError };
|
|
2423
|
+
export { type AuthorizationVerdict, BaseService, type ColumnInfo, type DataVaultConfig, DataVaultService, DecryptCapabilityProof, DuckDbAction, type DuckDbActionType, type DuckDbBatchOptions, type BatchResponse as DuckDbBatchResponse, DuckDbDatabaseHandle, type DuckDbExecuteOptions, type ExecuteResponse as DuckDbExecuteResponse, type DuckDbOptions, type DuckDbQueryOptions, type QueryResponse as DuckDbQueryResponse, DuckDbService, type DuckDbServiceConfig, type DuckDbStatement, type DuckDbValue, EventHandler, FetchFunction, GenericKVResponseSchema, type GenericKVResponseType, GenericResultSchema, type HookEvent, type HookServiceName, type HookStreamEvent, type HookStreamRetryConfig, type HookSubscription, type HookWebhookListOptions, type HookWebhookRecord, type HookWebhookRegistration, type HookWebhookScope, type HookWebhookUnregisterOptions, HooksService, type HooksServiceConfig, type IDataVaultService, type IDuckDbDatabaseHandle, type IDuckDbService, IEncryptionService, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, MAX_SECRET_SCOPE_LENGTH, type ParsedSecretCatalogKey, PermissionHint, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, SECRET_SCOPE_RE, STORAGE_FULL_MESSAGE, STORAGE_WRITE_TOO_LARGE_MESSAGE, type SchemaInfo, type SecretCatalogEntry, type SecretPayload, type SecretPutOptions, type SecretScopeOptions, type SecretsError, SecretsService, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, TC832_RESERVED_SCOPES, type TableInfo, TelemetryConfig, TelemetrySpanEventSchema, type TelemetrySpanEventType, type TinyCloudDebugEnableOptions, type TinyCloudDebugEvent, type TinyCloudDebugLevel, TinyCloudDebugLogger, type TinyCloudDebugTimer, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, type VaultListPage, type VaultNetworkReadResult, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, appSecretScope, authExpiredError, authRequiredError, authUnauthorizedError, authorizationVerdictOf, canonicalizeSecretScope, clearTinyCloudDebugLogs, createKVResponseSchema, createResultSchema, createVaultCrypto, disableTinyCloudDebug, enableTinyCloudDebug, errorResult, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isStorageFullError, networkError, notFoundError, parseAuthError, parseCapabilityResource, parsePermissionHint, parsePermissionHintFromErrorText, parseSecretCatalogKey, parseStorageQuotaBytes, permissionDeniedError, resolveSecretListPrefix, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, storageRejectionError, timeoutError, tinyCloudDebugLogger, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, validateTelemetrySpanEvent, validatedCapabilityOf, wrapError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1521,9 +1521,51 @@ interface SubscribeOptions {
|
|
|
1521
1521
|
}
|
|
1522
1522
|
interface HooksServiceConfig extends Record<string, unknown> {
|
|
1523
1523
|
host?: string;
|
|
1524
|
+
/** Shared-stream retry tuning; see {@link HookStreamRetryConfig}. */
|
|
1525
|
+
streamRetry?: HookStreamRetryConfig;
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Retry policy for the shared `/hooks/events` stream. When the stream fails
|
|
1529
|
+
* (network error, 5xx, or an expired/rotated ticket rejected with 401/403)
|
|
1530
|
+
* it is re-opened with exponential backoff: `HOOK_STREAM_RETRY_BASE_DELAY_MS`
|
|
1531
|
+
* (~250 ms) doubling to `HOOK_STREAM_RETRY_MAX_DELAY_MS` (~30 s) with jitter.
|
|
1532
|
+
* The retry streak resets after an event is received or a stream remains open
|
|
1533
|
+
* for at least 5 seconds. Retries stop when no subscribers remain, when the
|
|
1534
|
+
* service is aborted, or when minting the hook ticket is refused (the iterator
|
|
1535
|
+
* throws that typed error instead).
|
|
1536
|
+
*/
|
|
1537
|
+
interface HookStreamRetryConfig {
|
|
1538
|
+
/**
|
|
1539
|
+
* Delay before retry attempt `attempt` (1-based). Defaults to the jittered
|
|
1540
|
+
* exponential backoff described above. Must return milliseconds.
|
|
1541
|
+
*/
|
|
1542
|
+
delay?: (attempt: number) => number;
|
|
1543
|
+
/**
|
|
1544
|
+
* How a retry delay is awaited — the injectable clock. `delayMs` is the
|
|
1545
|
+
* resolved delay for `attempt`; `signal` aborts the wait early when the
|
|
1546
|
+
* subscription set changes or the service stops. Rejecting or throwing is
|
|
1547
|
+
* treated like a completed wait. After a custom wait returns — whether it
|
|
1548
|
+
* fulfilled, rejected or threw — the service still yields one event-loop
|
|
1549
|
+
* turn so a persistently failing stream can never starve the process.
|
|
1550
|
+
* Defaults to an abortable, unref'd `setTimeout`.
|
|
1551
|
+
*/
|
|
1552
|
+
wait?: (delayMs: number, attempt: number, signal: AbortSignal) => Promise<void>;
|
|
1524
1553
|
}
|
|
1525
1554
|
|
|
1526
1555
|
interface IHooksService {
|
|
1556
|
+
/**
|
|
1557
|
+
* Stream hook events until `options.signal` aborts, the SDK signs out or
|
|
1558
|
+
* the session ends, or the consumer stops iterating. Transient stream
|
|
1559
|
+
* failures — network errors, 5xx, and an expired or rotated ticket rejected
|
|
1560
|
+
* by `/hooks/events` (401/403) — are retried internally with backoff and
|
|
1561
|
+
* never reach the iterator.
|
|
1562
|
+
*
|
|
1563
|
+
* The iterator throws when minting the hook ticket is refused. The thrown
|
|
1564
|
+
* plain `ServiceError` carries `meta.status` with the refusing HTTP status,
|
|
1565
|
+
* so `for await` consumers can branch on it. Stream diagnostics contain only
|
|
1566
|
+
* SDK allow-listed identifiers; foreign error messages and causes are not
|
|
1567
|
+
* copied.
|
|
1568
|
+
*/
|
|
1527
1569
|
subscribe(subscriptions: HookSubscription[], options?: SubscribeOptions): AsyncIterable<HookEvent>;
|
|
1528
1570
|
register(webhook: HookWebhookRegistration): Promise<Result<HookWebhookRecord>>;
|
|
1529
1571
|
list(options?: HookWebhookListOptions): Promise<Result<HookWebhookRecord[]>>;
|
|
@@ -1534,10 +1576,13 @@ declare class HooksService extends BaseService implements IHooksService {
|
|
|
1534
1576
|
static readonly serviceName = "hooks";
|
|
1535
1577
|
protected _config: HooksServiceConfig;
|
|
1536
1578
|
private readonly _subscribers;
|
|
1537
|
-
|
|
1538
|
-
private
|
|
1539
|
-
|
|
1540
|
-
private
|
|
1579
|
+
/** True while the one supervisor loop runs. Set only by wake(), cleared only at loop exit. */
|
|
1580
|
+
private _supervising;
|
|
1581
|
+
/** The supervisor's current step, interruptible by wake(). */
|
|
1582
|
+
private _phase?;
|
|
1583
|
+
/** Bumped on every session change; part of the plan key. */
|
|
1584
|
+
private _sessionGeneration;
|
|
1585
|
+
private _lastContextSignal?;
|
|
1541
1586
|
constructor(config?: HooksServiceConfig);
|
|
1542
1587
|
get config(): HooksServiceConfig;
|
|
1543
1588
|
private get host();
|
|
@@ -1545,14 +1590,60 @@ declare class HooksService extends BaseService implements IHooksService {
|
|
|
1545
1590
|
register(webhook: HookWebhookRegistration): Promise<Result<HookWebhookRecord>>;
|
|
1546
1591
|
list(options?: HookWebhookListOptions): Promise<Result<HookWebhookRecord[]>>;
|
|
1547
1592
|
unregister(id: string, options?: HookWebhookUnregisterOptions): Promise<Result<void>>;
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1593
|
+
/**
|
|
1594
|
+
* Called after anything that may change what the supervisor should do:
|
|
1595
|
+
* subscribe, unsubscribe, session change, sign-out. Interrupts the running
|
|
1596
|
+
* step if the plan moved away from it, and starts the supervisor if none
|
|
1597
|
+
* runs. Touches only SDK-owned state, so it never throws into callers such
|
|
1598
|
+
* as `ServiceContext.setSession`.
|
|
1599
|
+
*/
|
|
1600
|
+
private wake;
|
|
1601
|
+
/**
|
|
1602
|
+
* The only owner of the shared stream. Each iteration is one attempt
|
|
1603
|
+
* (mint → open → drain), then a classification and, unless the attempt was
|
|
1604
|
+
* superseded or released its subscribers, a backoff. Every await is a
|
|
1605
|
+
* `phase` that wake() can interrupt; an interrupted phase yields
|
|
1606
|
+
* `undefined`, so a superseded mint can never act. Outside `attempt` and
|
|
1607
|
+
* `pause`, which each own one catch, the loop touches only SDK state.
|
|
1608
|
+
*/
|
|
1609
|
+
private supervise;
|
|
1610
|
+
/**
|
|
1611
|
+
* Run one step under an interrupt that wake() fires when the plan key moves
|
|
1612
|
+
* on. An interrupted step's result is discarded. The interrupt is also
|
|
1613
|
+
* fired when the step returns, which releases whatever it left open: the
|
|
1614
|
+
* request signal and its listeners, an unread response body, a timer.
|
|
1615
|
+
*/
|
|
1616
|
+
private phase;
|
|
1617
|
+
/**
|
|
1618
|
+
* One mint → open → drain. The single catch site for everything the
|
|
1619
|
+
* attempt touches that the SDK does not own: context accessors, invoke,
|
|
1620
|
+
* fetch, response bodies, the SSE parser. Never rejects.
|
|
1621
|
+
*/
|
|
1622
|
+
private attempt;
|
|
1623
|
+
/**
|
|
1624
|
+
* Back off before the next attempt. `config.streamRetry` overrides the
|
|
1625
|
+
* delay and the clock; whatever they do, the pause ends by the delay or the
|
|
1626
|
+
* interrupt, then yields one timer turn so an instant clock cannot starve
|
|
1627
|
+
* due timers or the process.
|
|
1628
|
+
*/
|
|
1629
|
+
private pause;
|
|
1630
|
+
/** The stream the current subscribers need, or undefined when none remain. */
|
|
1631
|
+
private plan;
|
|
1632
|
+
private dispatch;
|
|
1633
|
+
/**
|
|
1634
|
+
* Detach every subscriber. With `error`, their iterators throw it after
|
|
1635
|
+
* draining buffered events; without, they complete.
|
|
1636
|
+
*/
|
|
1637
|
+
private release;
|
|
1638
|
+
private report;
|
|
1639
|
+
/**
|
|
1640
|
+
* Unreachable by construction. If the loop ever rejects anyway, fail its
|
|
1641
|
+
* subscribers visibly instead of stranding them or crashing the process.
|
|
1642
|
+
*/
|
|
1643
|
+
private collapse;
|
|
1644
|
+
onSessionChange(session: ServiceSession | null): void;
|
|
1645
|
+
onSignOut(): void;
|
|
1553
1646
|
private createHookHeaders;
|
|
1554
|
-
private mintHookTicket;
|
|
1555
|
-
private openHookStream;
|
|
1556
1647
|
private createInvokeHeaders;
|
|
1557
1648
|
}
|
|
1558
1649
|
|
|
@@ -1617,6 +1708,11 @@ interface VaultPutOptions {
|
|
|
1617
1708
|
contentType?: string;
|
|
1618
1709
|
/** Custom serializer (default: JSON.stringify for objects) */
|
|
1619
1710
|
serialize?: (value: unknown) => Uint8Array;
|
|
1711
|
+
/**
|
|
1712
|
+
* `"*"` writes only when no value exists at the key. An existing value
|
|
1713
|
+
* fails with `ALREADY_EXISTS`; it is never overwritten.
|
|
1714
|
+
*/
|
|
1715
|
+
ifNoneMatch?: "*";
|
|
1620
1716
|
}
|
|
1621
1717
|
/**
|
|
1622
1718
|
* Options for vault get operations.
|
|
@@ -1739,6 +1835,28 @@ type VaultErrorInput = {
|
|
|
1739
1835
|
code: "STORAGE_ERROR";
|
|
1740
1836
|
cause: Error;
|
|
1741
1837
|
message?: string;
|
|
1838
|
+
meta?: Record<string, unknown>;
|
|
1839
|
+
} | {
|
|
1840
|
+
code: "ALREADY_EXISTS";
|
|
1841
|
+
key: string;
|
|
1842
|
+
message?: string;
|
|
1843
|
+
meta?: Record<string, unknown>;
|
|
1844
|
+
/** The typed KV error that refused the write (an `Error` carrying its `code`, `service` and `meta`). */
|
|
1845
|
+
cause: ServiceError & Error;
|
|
1846
|
+
} | {
|
|
1847
|
+
/** HTTP 401 only: the session must sign in again. */
|
|
1848
|
+
code: "AUTH_UNAUTHORIZED";
|
|
1849
|
+
message: string;
|
|
1850
|
+
meta?: Record<string, unknown>;
|
|
1851
|
+
/** The typed KV error that refused the write (an `Error` carrying its `code`, `service` and `meta`). */
|
|
1852
|
+
cause: ServiceError & Error;
|
|
1853
|
+
} | {
|
|
1854
|
+
/** A 403, or an authorization refusal without a status: signing in again does not help. */
|
|
1855
|
+
code: "PERMISSION_DENIED";
|
|
1856
|
+
message: string;
|
|
1857
|
+
meta?: Record<string, unknown>;
|
|
1858
|
+
/** The typed KV error that refused the write (an `Error` carrying its `code`, `service` and `meta`). */
|
|
1859
|
+
cause: ServiceError & Error;
|
|
1742
1860
|
} | {
|
|
1743
1861
|
code: "STORAGE_QUOTA_EXCEEDED" | "STORAGE_LIMIT_REACHED";
|
|
1744
1862
|
message: string;
|
|
@@ -2226,6 +2344,21 @@ interface SecretScopeOptions {
|
|
|
2226
2344
|
/** Optional logical scope. Omit for the global secret namespace. */
|
|
2227
2345
|
scope?: string;
|
|
2228
2346
|
}
|
|
2347
|
+
/** Canonical secret scope grammar shared with the TC-832 `/request` link. */
|
|
2348
|
+
declare const SECRET_SCOPE_RE: RegExp;
|
|
2349
|
+
/** Longest scope the TC-832 `/request` link accepts. */
|
|
2350
|
+
declare const MAX_SECRET_SCOPE_LENGTH = 64;
|
|
2351
|
+
/** Scopes the TC-832 `/request` link refuses. */
|
|
2352
|
+
declare const TC832_RESERVED_SCOPES: readonly string[];
|
|
2353
|
+
interface SecretPutOptions extends SecretScopeOptions {
|
|
2354
|
+
/** Write only when no secret exists under this name; never overwrite. */
|
|
2355
|
+
ifAbsent?: boolean;
|
|
2356
|
+
}
|
|
2357
|
+
/**
|
|
2358
|
+
* Derive the canonical secret scope for an app id such as
|
|
2359
|
+
* `xyz.tinycloud.feed-workflows` → `xyz-tinycloud-feed-workflows`.
|
|
2360
|
+
*/
|
|
2361
|
+
declare function appSecretScope(appId: string): string;
|
|
2229
2362
|
interface ResolvedSecretPath {
|
|
2230
2363
|
/** Canonical env-style secret name. */
|
|
2231
2364
|
name: string;
|
|
@@ -2266,7 +2399,7 @@ interface ISecretsService {
|
|
|
2266
2399
|
lock(): void;
|
|
2267
2400
|
readonly isUnlocked: boolean;
|
|
2268
2401
|
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
2269
|
-
put(name: string, value: string, options?:
|
|
2402
|
+
put(name: string, value: string, options?: SecretPutOptions): Promise<Result<void, SecretsError>>;
|
|
2270
2403
|
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
2271
2404
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2272
2405
|
/** List global and scoped secrets without decrypting their values. */
|
|
@@ -2281,10 +2414,10 @@ declare class SecretsService implements ISecretsService {
|
|
|
2281
2414
|
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
2282
2415
|
lock(): void;
|
|
2283
2416
|
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
2284
|
-
put(name: string, value: string, options?:
|
|
2417
|
+
put(name: string, value: string, options?: SecretPutOptions): Promise<Result<void, SecretsError>>;
|
|
2285
2418
|
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
2286
2419
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2287
2420
|
listAll(): Promise<Result<SecretCatalogEntry[], SecretsError>>;
|
|
2288
2421
|
}
|
|
2289
2422
|
|
|
2290
|
-
export { type AuthorizationVerdict, BaseService, type ColumnInfo, type DataVaultConfig, DataVaultService, DecryptCapabilityProof, DuckDbAction, type DuckDbActionType, type DuckDbBatchOptions, type BatchResponse as DuckDbBatchResponse, DuckDbDatabaseHandle, type DuckDbExecuteOptions, type ExecuteResponse as DuckDbExecuteResponse, type DuckDbOptions, type DuckDbQueryOptions, type QueryResponse as DuckDbQueryResponse, DuckDbService, type DuckDbServiceConfig, type DuckDbStatement, type DuckDbValue, EventHandler, FetchFunction, GenericKVResponseSchema, type GenericKVResponseType, GenericResultSchema, type HookEvent, type HookServiceName, type HookStreamEvent, type HookSubscription, type HookWebhookListOptions, type HookWebhookRecord, type HookWebhookRegistration, type HookWebhookScope, type HookWebhookUnregisterOptions, HooksService, type HooksServiceConfig, type IDataVaultService, type IDuckDbDatabaseHandle, type IDuckDbService, IEncryptionService, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, type ParsedSecretCatalogKey, PermissionHint, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, STORAGE_FULL_MESSAGE, STORAGE_WRITE_TOO_LARGE_MESSAGE, type SchemaInfo, type SecretCatalogEntry, type SecretPayload, type SecretScopeOptions, type SecretsError, SecretsService, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, type TableInfo, TelemetryConfig, TelemetrySpanEventSchema, type TelemetrySpanEventType, type TinyCloudDebugEnableOptions, type TinyCloudDebugEvent, type TinyCloudDebugLevel, TinyCloudDebugLogger, type TinyCloudDebugTimer, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, type VaultListPage, type VaultNetworkReadResult, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, authExpiredError, authRequiredError, authUnauthorizedError, authorizationVerdictOf, canonicalizeSecretScope, clearTinyCloudDebugLogs, createKVResponseSchema, createResultSchema, createVaultCrypto, disableTinyCloudDebug, enableTinyCloudDebug, errorResult, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isStorageFullError, networkError, notFoundError, parseAuthError, parseCapabilityResource, parsePermissionHint, parsePermissionHintFromErrorText, parseSecretCatalogKey, parseStorageQuotaBytes, permissionDeniedError, resolveSecretListPrefix, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, storageRejectionError, timeoutError, tinyCloudDebugLogger, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, validateTelemetrySpanEvent, validatedCapabilityOf, wrapError };
|
|
2423
|
+
export { type AuthorizationVerdict, BaseService, type ColumnInfo, type DataVaultConfig, DataVaultService, DecryptCapabilityProof, DuckDbAction, type DuckDbActionType, type DuckDbBatchOptions, type BatchResponse as DuckDbBatchResponse, DuckDbDatabaseHandle, type DuckDbExecuteOptions, type ExecuteResponse as DuckDbExecuteResponse, type DuckDbOptions, type DuckDbQueryOptions, type QueryResponse as DuckDbQueryResponse, DuckDbService, type DuckDbServiceConfig, type DuckDbStatement, type DuckDbValue, EventHandler, FetchFunction, GenericKVResponseSchema, type GenericKVResponseType, GenericResultSchema, type HookEvent, type HookServiceName, type HookStreamEvent, type HookStreamRetryConfig, type HookSubscription, type HookWebhookListOptions, type HookWebhookRecord, type HookWebhookRegistration, type HookWebhookScope, type HookWebhookUnregisterOptions, HooksService, type HooksServiceConfig, type IDataVaultService, type IDuckDbDatabaseHandle, type IDuckDbService, IEncryptionService, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, MAX_SECRET_SCOPE_LENGTH, type ParsedSecretCatalogKey, PermissionHint, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, SECRET_SCOPE_RE, STORAGE_FULL_MESSAGE, STORAGE_WRITE_TOO_LARGE_MESSAGE, type SchemaInfo, type SecretCatalogEntry, type SecretPayload, type SecretPutOptions, type SecretScopeOptions, type SecretsError, SecretsService, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, TC832_RESERVED_SCOPES, type TableInfo, TelemetryConfig, TelemetrySpanEventSchema, type TelemetrySpanEventType, type TinyCloudDebugEnableOptions, type TinyCloudDebugEvent, type TinyCloudDebugLevel, TinyCloudDebugLogger, type TinyCloudDebugTimer, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, type VaultListPage, type VaultNetworkReadResult, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, appSecretScope, authExpiredError, authRequiredError, authUnauthorizedError, authorizationVerdictOf, canonicalizeSecretScope, clearTinyCloudDebugLogs, createKVResponseSchema, createResultSchema, createVaultCrypto, disableTinyCloudDebug, enableTinyCloudDebug, errorResult, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isStorageFullError, networkError, notFoundError, parseAuthError, parseCapabilityResource, parsePermissionHint, parsePermissionHintFromErrorText, parseSecretCatalogKey, parseStorageQuotaBytes, permissionDeniedError, resolveSecretListPrefix, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, storageRejectionError, timeoutError, tinyCloudDebugLogger, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, validateTelemetrySpanEvent, validatedCapabilityOf, wrapError };
|