@tinycloud/sdk-services 3.1.0-beta.7 → 3.1.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/dist/{BaseService-DU-lE-Qx.d.ts → BaseService-B_UKhVht.d.ts} +1 -1
- package/dist/{BaseService-C8zRy0ww.d.cts → BaseService-DWbPbov7.d.cts} +1 -1
- package/dist/encryption/index.cjs +8 -0
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.d.cts +2 -2
- package/dist/encryption/index.d.ts +2 -2
- package/dist/encryption/index.js +8 -0
- package/dist/encryption/index.js.map +1 -1
- package/dist/index.cjs +760 -169
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +108 -17
- package/dist/index.d.ts +108 -17
- package/dist/index.js +760 -169
- package/dist/index.js.map +1 -1
- package/dist/internal/decrypt-transport-response-error.d.cts +1 -1
- package/dist/internal/decrypt-transport-response-error.d.ts +1 -1
- package/dist/kv/index.cjs +256 -9
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.d.cts +182 -3
- package/dist/kv/index.d.ts +182 -3
- package/dist/kv/index.js +256 -9
- package/dist/kv/index.js.map +1 -1
- package/dist/sql/index.cjs +8 -0
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.d.cts +2 -2
- package/dist/sql/index.d.ts +2 -2
- package/dist/sql/index.js +8 -0
- package/dist/sql/index.js.map +1 -1
- package/dist/{types-qwMmB7qB.d.cts → types-CVwwxqXF.d.cts} +8 -0
- package/dist/{types-qwMmB7qB.d.ts → types-CVwwxqXF.d.ts} +8 -0
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as IServiceContext, c as InvokeFunction, d as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, e as RetryPolicy, T as TelemetryConfig, I as IService, E as EventHandler, b as ServiceError, R as Result, P as PermissionHint, f as StorageQuotaInfo } from './types-
|
|
2
|
-
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './types-
|
|
1
|
+
import { a as IServiceContext, c as InvokeFunction, d as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, e as RetryPolicy, T as TelemetryConfig, I as IService, E as EventHandler, b as ServiceError, R as Result, P as PermissionHint, f as StorageQuotaInfo } from './types-CVwwxqXF.cjs';
|
|
2
|
+
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './types-CVwwxqXF.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { B as BaseService } from './BaseService-
|
|
5
|
-
export { a as BaseServiceOptions, R as RequestSignal, S as ServiceConstructor, b as ServiceRegistration } from './BaseService-
|
|
4
|
+
import { B as BaseService } from './BaseService-DWbPbov7.cjs';
|
|
5
|
+
export { a as BaseServiceOptions, R as RequestSignal, S as ServiceConstructor, b as ServiceRegistration } from './BaseService-DWbPbov7.cjs';
|
|
6
6
|
import { IKVService } from './kv/index.cjs';
|
|
7
|
-
export { DEFAULT_SIGNED_READ_URL_EXPIRY_MS, IPrefixedKVService, KVAction, KVActionType, KVBatchPutItem, KVBatchPutOptions, KVBatchPutResponse, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, PrefixedKVService } from './kv/index.cjs';
|
|
7
|
+
export { DEFAULT_SIGNED_READ_URL_EXPIRY_MS, IPrefixedKVService, KVAction, KVActionType, KVBatchPutItem, KVBatchPutOptions, KVBatchPutResponse, KVBatchReadResponse, KVChange, KVChangesAuthority, KVChangesOptions, KVChangesResponse, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, PrefixedKVService } from './kv/index.cjs';
|
|
8
8
|
export { BatchOptions, BatchResponse, DatabaseHandle, ExecuteOptions, ExecuteResponse, IDatabaseHandle, ISQLMigrations, ISQLService, QueryOptions, QueryResponse, SQLAction, SQLActionType, SQLMigrations, SQLService, SQLServiceConfig, SqlMigration, SqlMigrationApplyOptions, SqlMigrationApplyResponse, SqlStatement, SqlValue } from './sql/index.cjs';
|
|
9
9
|
import { IEncryptionService, DecryptCapabilityProof } from './encryption/index.cjs';
|
|
10
10
|
export { BuildCanonicalDecryptRequestInput, BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, CanonicalDecryptRequest, CanonicalJson, DECRYPT_ACTION, DECRYPT_FACT_TYPE, DECRYPT_RESULT_TYPE, DEFAULT_ENCRYPTION_ALG, DEFAULT_KEY_VERSION, DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, DecryptTransport, DiscoverNetworkInput, DiscoveredNetwork, DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, ENCRYPTION_SERVICE, ENCRYPTION_SERVICE_SHORT, ENVELOPE_VERSION, EncryptToNetworkInput, EncryptToNetworkOptions, EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionErrorInput, EncryptionService, EncryptionServiceConfig, InlineEncryptedEnvelope, Json, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, NodeDescriptorFetcher, ParsedNetworkId, RandomReceiverKeyInput, ReceiverKeyPair, ReceiverKeySigner, SignedReceiverKeyInput, VerifyDecryptResponseInput, WellKnownDescriptorFetcher, base64Decode, base64Encode, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalHashHex, canonicalSignedResponse, canonicalize as canonicalizeEncryptionJson, checkDecryptInvocationInput, decryptEnvelopeWithKey, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, encryptionError, ensureNetworkUsableForDecrypt, generateRandomReceiverKey, hexDecode, hexEncode, isNetworkId, networkDiscoveryKey, openWrappedKey, parseNetworkId, utf8Decode, utf8Encode, validateEnvelope, verifyDecryptResponse } from './encryption/index.cjs';
|
|
@@ -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
|
|
|
@@ -2287,4 +2378,4 @@ declare class SecretsService implements ISecretsService {
|
|
|
2287
2378
|
listAll(): Promise<Result<SecretCatalogEntry[], SecretsError>>;
|
|
2288
2379
|
}
|
|
2289
2380
|
|
|
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 };
|
|
2381
|
+
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, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as IServiceContext, c as InvokeFunction, d as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, e as RetryPolicy, T as TelemetryConfig, I as IService, E as EventHandler, b as ServiceError, R as Result, P as PermissionHint, f as StorageQuotaInfo } from './types-
|
|
2
|
-
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './types-
|
|
1
|
+
import { a as IServiceContext, c as InvokeFunction, d as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, e as RetryPolicy, T as TelemetryConfig, I as IService, E as EventHandler, b as ServiceError, R as Result, P as PermissionHint, f as StorageQuotaInfo } from './types-CVwwxqXF.js';
|
|
2
|
+
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './types-CVwwxqXF.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { B as BaseService } from './BaseService-
|
|
5
|
-
export { a as BaseServiceOptions, R as RequestSignal, S as ServiceConstructor, b as ServiceRegistration } from './BaseService-
|
|
4
|
+
import { B as BaseService } from './BaseService-B_UKhVht.js';
|
|
5
|
+
export { a as BaseServiceOptions, R as RequestSignal, S as ServiceConstructor, b as ServiceRegistration } from './BaseService-B_UKhVht.js';
|
|
6
6
|
import { IKVService } from './kv/index.js';
|
|
7
|
-
export { DEFAULT_SIGNED_READ_URL_EXPIRY_MS, IPrefixedKVService, KVAction, KVActionType, KVBatchPutItem, KVBatchPutOptions, KVBatchPutResponse, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, PrefixedKVService } from './kv/index.js';
|
|
7
|
+
export { DEFAULT_SIGNED_READ_URL_EXPIRY_MS, IPrefixedKVService, KVAction, KVActionType, KVBatchPutItem, KVBatchPutOptions, KVBatchPutResponse, KVBatchReadResponse, KVChange, KVChangesAuthority, KVChangesOptions, KVChangesResponse, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, PrefixedKVService } from './kv/index.js';
|
|
8
8
|
export { BatchOptions, BatchResponse, DatabaseHandle, ExecuteOptions, ExecuteResponse, IDatabaseHandle, ISQLMigrations, ISQLService, QueryOptions, QueryResponse, SQLAction, SQLActionType, SQLMigrations, SQLService, SQLServiceConfig, SqlMigration, SqlMigrationApplyOptions, SqlMigrationApplyResponse, SqlStatement, SqlValue } from './sql/index.js';
|
|
9
9
|
import { IEncryptionService, DecryptCapabilityProof } from './encryption/index.js';
|
|
10
10
|
export { BuildCanonicalDecryptRequestInput, BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, CanonicalDecryptRequest, CanonicalJson, DECRYPT_ACTION, DECRYPT_FACT_TYPE, DECRYPT_RESULT_TYPE, DEFAULT_ENCRYPTION_ALG, DEFAULT_KEY_VERSION, DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, DecryptTransport, DiscoverNetworkInput, DiscoveredNetwork, DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, ENCRYPTION_SERVICE, ENCRYPTION_SERVICE_SHORT, ENVELOPE_VERSION, EncryptToNetworkInput, EncryptToNetworkOptions, EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionErrorInput, EncryptionService, EncryptionServiceConfig, InlineEncryptedEnvelope, Json, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, NodeDescriptorFetcher, ParsedNetworkId, RandomReceiverKeyInput, ReceiverKeyPair, ReceiverKeySigner, SignedReceiverKeyInput, VerifyDecryptResponseInput, WellKnownDescriptorFetcher, base64Decode, base64Encode, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalHashHex, canonicalSignedResponse, canonicalize as canonicalizeEncryptionJson, checkDecryptInvocationInput, decryptEnvelopeWithKey, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, encryptionError, ensureNetworkUsableForDecrypt, generateRandomReceiverKey, hexDecode, hexEncode, isNetworkId, networkDiscoveryKey, openWrappedKey, parseNetworkId, utf8Decode, utf8Encode, validateEnvelope, verifyDecryptResponse } from './encryption/index.js';
|
|
@@ -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
|
|
|
@@ -2287,4 +2378,4 @@ declare class SecretsService implements ISecretsService {
|
|
|
2287
2378
|
listAll(): Promise<Result<SecretCatalogEntry[], SecretsError>>;
|
|
2288
2379
|
}
|
|
2289
2380
|
|
|
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 };
|
|
2381
|
+
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, 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 };
|