@tinycloud/sdk-services 3.1.0 → 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 +90 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -3
- package/dist/index.d.ts +45 -3
- package/dist/index.js +86 -11
- package/dist/index.js.map +1 -1
- package/dist/kv/index.cjs +4 -4
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.js +4 -4
- package/dist/kv/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1708,6 +1708,11 @@ interface VaultPutOptions {
|
|
|
1708
1708
|
contentType?: string;
|
|
1709
1709
|
/** Custom serializer (default: JSON.stringify for objects) */
|
|
1710
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?: "*";
|
|
1711
1716
|
}
|
|
1712
1717
|
/**
|
|
1713
1718
|
* Options for vault get operations.
|
|
@@ -1830,6 +1835,28 @@ type VaultErrorInput = {
|
|
|
1830
1835
|
code: "STORAGE_ERROR";
|
|
1831
1836
|
cause: Error;
|
|
1832
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;
|
|
1833
1860
|
} | {
|
|
1834
1861
|
code: "STORAGE_QUOTA_EXCEEDED" | "STORAGE_LIMIT_REACHED";
|
|
1835
1862
|
message: string;
|
|
@@ -2317,6 +2344,21 @@ interface SecretScopeOptions {
|
|
|
2317
2344
|
/** Optional logical scope. Omit for the global secret namespace. */
|
|
2318
2345
|
scope?: string;
|
|
2319
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;
|
|
2320
2362
|
interface ResolvedSecretPath {
|
|
2321
2363
|
/** Canonical env-style secret name. */
|
|
2322
2364
|
name: string;
|
|
@@ -2357,7 +2399,7 @@ interface ISecretsService {
|
|
|
2357
2399
|
lock(): void;
|
|
2358
2400
|
readonly isUnlocked: boolean;
|
|
2359
2401
|
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
2360
|
-
put(name: string, value: string, options?:
|
|
2402
|
+
put(name: string, value: string, options?: SecretPutOptions): Promise<Result<void, SecretsError>>;
|
|
2361
2403
|
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
2362
2404
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2363
2405
|
/** List global and scoped secrets without decrypting their values. */
|
|
@@ -2372,10 +2414,10 @@ declare class SecretsService implements ISecretsService {
|
|
|
2372
2414
|
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
2373
2415
|
lock(): void;
|
|
2374
2416
|
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
2375
|
-
put(name: string, value: string, options?:
|
|
2417
|
+
put(name: string, value: string, options?: SecretPutOptions): Promise<Result<void, SecretsError>>;
|
|
2376
2418
|
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
2377
2419
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2378
2420
|
listAll(): Promise<Result<SecretCatalogEntry[], SecretsError>>;
|
|
2379
2421
|
}
|
|
2380
2422
|
|
|
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 };
|
|
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
|
@@ -1708,6 +1708,11 @@ interface VaultPutOptions {
|
|
|
1708
1708
|
contentType?: string;
|
|
1709
1709
|
/** Custom serializer (default: JSON.stringify for objects) */
|
|
1710
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?: "*";
|
|
1711
1716
|
}
|
|
1712
1717
|
/**
|
|
1713
1718
|
* Options for vault get operations.
|
|
@@ -1830,6 +1835,28 @@ type VaultErrorInput = {
|
|
|
1830
1835
|
code: "STORAGE_ERROR";
|
|
1831
1836
|
cause: Error;
|
|
1832
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;
|
|
1833
1860
|
} | {
|
|
1834
1861
|
code: "STORAGE_QUOTA_EXCEEDED" | "STORAGE_LIMIT_REACHED";
|
|
1835
1862
|
message: string;
|
|
@@ -2317,6 +2344,21 @@ interface SecretScopeOptions {
|
|
|
2317
2344
|
/** Optional logical scope. Omit for the global secret namespace. */
|
|
2318
2345
|
scope?: string;
|
|
2319
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;
|
|
2320
2362
|
interface ResolvedSecretPath {
|
|
2321
2363
|
/** Canonical env-style secret name. */
|
|
2322
2364
|
name: string;
|
|
@@ -2357,7 +2399,7 @@ interface ISecretsService {
|
|
|
2357
2399
|
lock(): void;
|
|
2358
2400
|
readonly isUnlocked: boolean;
|
|
2359
2401
|
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
2360
|
-
put(name: string, value: string, options?:
|
|
2402
|
+
put(name: string, value: string, options?: SecretPutOptions): Promise<Result<void, SecretsError>>;
|
|
2361
2403
|
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
2362
2404
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2363
2405
|
/** List global and scoped secrets without decrypting their values. */
|
|
@@ -2372,10 +2414,10 @@ declare class SecretsService implements ISecretsService {
|
|
|
2372
2414
|
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
2373
2415
|
lock(): void;
|
|
2374
2416
|
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
2375
|
-
put(name: string, value: string, options?:
|
|
2417
|
+
put(name: string, value: string, options?: SecretPutOptions): Promise<Result<void, SecretsError>>;
|
|
2376
2418
|
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
2377
2419
|
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
2378
2420
|
listAll(): Promise<Result<SecretCatalogEntry[], SecretsError>>;
|
|
2379
2421
|
}
|
|
2380
2422
|
|
|
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 };
|
|
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.js
CHANGED
|
@@ -2299,7 +2299,7 @@ var KVService = class extends BaseService {
|
|
|
2299
2299
|
);
|
|
2300
2300
|
}
|
|
2301
2301
|
if (response.status === 404) {
|
|
2302
|
-
return this.classifyNotFound(response, key);
|
|
2302
|
+
return await this.classifyNotFound(response, key);
|
|
2303
2303
|
}
|
|
2304
2304
|
const errorText = await response.text();
|
|
2305
2305
|
if (response.status === 413) {
|
|
@@ -2868,7 +2868,7 @@ var KVService = class extends BaseService {
|
|
|
2868
2868
|
);
|
|
2869
2869
|
}
|
|
2870
2870
|
if (response.status === 404) {
|
|
2871
|
-
return this.classifyNotFound(response, key);
|
|
2871
|
+
return await this.classifyNotFound(response, key);
|
|
2872
2872
|
}
|
|
2873
2873
|
const errorText = await response.text();
|
|
2874
2874
|
if (response.status === 412) {
|
|
@@ -2935,7 +2935,7 @@ var KVService = class extends BaseService {
|
|
|
2935
2935
|
);
|
|
2936
2936
|
}
|
|
2937
2937
|
if (response.status === 404) {
|
|
2938
|
-
return this.classifyNotFound(response, key);
|
|
2938
|
+
return await this.classifyNotFound(response, key);
|
|
2939
2939
|
}
|
|
2940
2940
|
const errorText = await response.text();
|
|
2941
2941
|
return err(
|
|
@@ -3001,7 +3001,7 @@ var KVService = class extends BaseService {
|
|
|
3001
3001
|
signal: request.signal
|
|
3002
3002
|
});
|
|
3003
3003
|
if (!response.ok) {
|
|
3004
|
-
return this.createSignedReadUrlError(response, key, path);
|
|
3004
|
+
return await this.createSignedReadUrlError(response, key, path);
|
|
3005
3005
|
}
|
|
3006
3006
|
const signedUrl = this.normalizeSignedReadUrlResponse(
|
|
3007
3007
|
await response.json()
|
|
@@ -5292,6 +5292,12 @@ function defaultVaultMessage(input) {
|
|
|
5292
5292
|
return input.message ?? `Public key not found for ${input.did}`;
|
|
5293
5293
|
case "STORAGE_ERROR":
|
|
5294
5294
|
return input.message ?? input.cause.message;
|
|
5295
|
+
case "ALREADY_EXISTS":
|
|
5296
|
+
return input.message ?? `A value already exists at ${input.key}`;
|
|
5297
|
+
case "AUTH_UNAUTHORIZED":
|
|
5298
|
+
return input.message;
|
|
5299
|
+
case "PERMISSION_DENIED":
|
|
5300
|
+
return input.message;
|
|
5295
5301
|
case "STORAGE_QUOTA_EXCEEDED":
|
|
5296
5302
|
case "STORAGE_LIMIT_REACHED":
|
|
5297
5303
|
return input.message;
|
|
@@ -5305,13 +5311,33 @@ function vaultError(input) {
|
|
|
5305
5311
|
};
|
|
5306
5312
|
return { ok: false, error };
|
|
5307
5313
|
}
|
|
5314
|
+
function typedKvCause(error) {
|
|
5315
|
+
return Object.assign(new Error(error.message), {
|
|
5316
|
+
name: "ServiceError",
|
|
5317
|
+
code: error.code,
|
|
5318
|
+
service: error.service,
|
|
5319
|
+
...error.meta !== void 0 ? { meta: error.meta } : {},
|
|
5320
|
+
...error.cause !== void 0 ? { cause: error.cause } : {}
|
|
5321
|
+
});
|
|
5322
|
+
}
|
|
5308
5323
|
function kvWriteError(context, error) {
|
|
5309
5324
|
if (error.code === ErrorCodes.STORAGE_QUOTA_EXCEEDED || error.code === ErrorCodes.STORAGE_LIMIT_REACHED) {
|
|
5310
5325
|
return vaultError({ code: error.code, message: error.message, meta: error.meta });
|
|
5311
5326
|
}
|
|
5327
|
+
const message = `${context}: ${error.message}`;
|
|
5328
|
+
if (error.code === ErrorCodes.AUTH_UNAUTHORIZED) {
|
|
5329
|
+
const code = authorizationVerdictOf(error) === "unauthenticated" ? "AUTH_UNAUTHORIZED" : "PERMISSION_DENIED";
|
|
5330
|
+
return vaultError({
|
|
5331
|
+
code,
|
|
5332
|
+
message,
|
|
5333
|
+
...error.meta !== void 0 ? { meta: error.meta } : {},
|
|
5334
|
+
cause: typedKvCause(error)
|
|
5335
|
+
});
|
|
5336
|
+
}
|
|
5312
5337
|
return vaultError({
|
|
5313
5338
|
code: "STORAGE_ERROR",
|
|
5314
|
-
cause: new Error(
|
|
5339
|
+
cause: new Error(message, { cause: typedKvCause(error) }),
|
|
5340
|
+
...error.meta !== void 0 ? { meta: error.meta } : {}
|
|
5315
5341
|
});
|
|
5316
5342
|
}
|
|
5317
5343
|
var DataVaultService = class extends BaseService {
|
|
@@ -5591,11 +5617,18 @@ var DataVaultService = class extends BaseService {
|
|
|
5591
5617
|
cause: new Error(envelopeResult.error.message)
|
|
5592
5618
|
});
|
|
5593
5619
|
}
|
|
5594
|
-
const
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
);
|
|
5620
|
+
const valuePath = `vault/${key}`;
|
|
5621
|
+
const valueBody = JSON.stringify(envelopeResult.data);
|
|
5622
|
+
const valuePutResult = options?.ifNoneMatch !== void 0 ? await this.tc.kv.put(valuePath, valueBody, { ifNoneMatch: options.ifNoneMatch }) : await this.tc.kv.put(valuePath, valueBody);
|
|
5598
5623
|
if (!valuePutResult.ok) {
|
|
5624
|
+
if (options?.ifNoneMatch !== void 0 && valuePutResult.error.code === ErrorCodes.KV_PRECONDITION_FAILED) {
|
|
5625
|
+
return vaultError({
|
|
5626
|
+
code: "ALREADY_EXISTS",
|
|
5627
|
+
key,
|
|
5628
|
+
...valuePutResult.error.meta !== void 0 ? { meta: valuePutResult.error.meta } : {},
|
|
5629
|
+
cause: typedKvCause(valuePutResult.error)
|
|
5630
|
+
});
|
|
5631
|
+
}
|
|
5599
5632
|
return kvWriteError("Failed to store encrypted value", valuePutResult.error);
|
|
5600
5633
|
}
|
|
5601
5634
|
return { ok: true, data: void 0 };
|
|
@@ -5763,6 +5796,14 @@ var DataVaultService = class extends BaseService {
|
|
|
5763
5796
|
if (this.usesNetworkEncryption) {
|
|
5764
5797
|
return this.putNetworkEncrypted(key, value, options);
|
|
5765
5798
|
}
|
|
5799
|
+
if (options?.ifNoneMatch !== void 0) {
|
|
5800
|
+
return vaultError({
|
|
5801
|
+
code: "STORAGE_ERROR",
|
|
5802
|
+
cause: new Error(
|
|
5803
|
+
"ifNoneMatch is only supported by network-encrypted vaults"
|
|
5804
|
+
)
|
|
5805
|
+
});
|
|
5806
|
+
}
|
|
5766
5807
|
if (!this._isUnlocked || !this.masterKey) {
|
|
5767
5808
|
return vaultError({
|
|
5768
5809
|
code: "VAULT_LOCKED",
|
|
@@ -6574,6 +6615,35 @@ var SECRET_NAME_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
|
6574
6615
|
var SECRET_PREFIX = "secrets/";
|
|
6575
6616
|
var SCOPED_SECRET_PREFIX = "secrets/scoped/";
|
|
6576
6617
|
var RESERVED_SECRET_SCOPES = /* @__PURE__ */ new Set(["default", "global"]);
|
|
6618
|
+
var SECRET_SCOPE_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
6619
|
+
var MAX_SECRET_SCOPE_LENGTH = 64;
|
|
6620
|
+
var TC832_RESERVED_SCOPES = Object.freeze([
|
|
6621
|
+
"default",
|
|
6622
|
+
"global",
|
|
6623
|
+
"scoped"
|
|
6624
|
+
]);
|
|
6625
|
+
function appSecretScope(appId) {
|
|
6626
|
+
if (appId.trim() === "") {
|
|
6627
|
+
throw new Error("App id must be non-empty to derive a secret scope.");
|
|
6628
|
+
}
|
|
6629
|
+
const scope = appId.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
6630
|
+
if (scope === "") {
|
|
6631
|
+
throw new Error(
|
|
6632
|
+
`App id ${JSON.stringify(appId)} must contain at least one letter or number.`
|
|
6633
|
+
);
|
|
6634
|
+
}
|
|
6635
|
+
if (scope.length > MAX_SECRET_SCOPE_LENGTH) {
|
|
6636
|
+
throw new Error(
|
|
6637
|
+
`App id ${JSON.stringify(appId)} yields a secret scope longer than ${MAX_SECRET_SCOPE_LENGTH} characters.`
|
|
6638
|
+
);
|
|
6639
|
+
}
|
|
6640
|
+
if (TC832_RESERVED_SCOPES.includes(scope)) {
|
|
6641
|
+
throw new Error(
|
|
6642
|
+
`App id ${JSON.stringify(appId)} yields the reserved secret scope ${JSON.stringify(scope)}.`
|
|
6643
|
+
);
|
|
6644
|
+
}
|
|
6645
|
+
return scope;
|
|
6646
|
+
}
|
|
6577
6647
|
function canonicalizeSecretScope(scope) {
|
|
6578
6648
|
if (scope === void 0) {
|
|
6579
6649
|
return void 0;
|
|
@@ -6686,11 +6756,12 @@ var SecretsService = class {
|
|
|
6686
6756
|
const secretPath = resolveSecretPathResult(name, options);
|
|
6687
6757
|
if ("ok" in secretPath) return secretPath;
|
|
6688
6758
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
6689
|
-
|
|
6759
|
+
const payload = {
|
|
6690
6760
|
value,
|
|
6691
6761
|
createdAt: now,
|
|
6692
6762
|
updatedAt: now
|
|
6693
|
-
}
|
|
6763
|
+
};
|
|
6764
|
+
return options?.ifAbsent === true ? this.vault.put(secretPath.vaultKey, payload, { ifNoneMatch: "*" }) : this.vault.put(secretPath.vaultKey, payload);
|
|
6694
6765
|
}
|
|
6695
6766
|
async delete(name, options) {
|
|
6696
6767
|
const secretPath = resolveSecretPathResult(name, options);
|
|
@@ -7745,11 +7816,13 @@ export {
|
|
|
7745
7816
|
KVListResultSchema,
|
|
7746
7817
|
KVResponseHeadersSchema,
|
|
7747
7818
|
KVService,
|
|
7819
|
+
MAX_SECRET_SCOPE_LENGTH,
|
|
7748
7820
|
NETWORK_NAME_PATTERN,
|
|
7749
7821
|
NetworkIdError,
|
|
7750
7822
|
PrefixedKVService,
|
|
7751
7823
|
RetryPolicySchema,
|
|
7752
7824
|
SECRET_NAME_RE,
|
|
7825
|
+
SECRET_SCOPE_RE,
|
|
7753
7826
|
SQLAction,
|
|
7754
7827
|
SQLMigrations,
|
|
7755
7828
|
SQLService,
|
|
@@ -7763,6 +7836,7 @@ export {
|
|
|
7763
7836
|
ServiceResponseEventSchema,
|
|
7764
7837
|
ServiceRetryEventSchema,
|
|
7765
7838
|
ServiceSessionSchema,
|
|
7839
|
+
TC832_RESERVED_SCOPES,
|
|
7766
7840
|
TelemetryEvents,
|
|
7767
7841
|
TelemetrySpanEventSchema,
|
|
7768
7842
|
TinyCloudDebugLogger,
|
|
@@ -7770,6 +7844,7 @@ export {
|
|
|
7770
7844
|
VaultHeaders,
|
|
7771
7845
|
VaultPublicSpaceKVActions,
|
|
7772
7846
|
abortedError,
|
|
7847
|
+
appSecretScope,
|
|
7773
7848
|
authExpiredError,
|
|
7774
7849
|
authRequiredError,
|
|
7775
7850
|
authUnauthorizedError,
|