@tinycloud/sdk-services 3.0.0 → 3.1.0-beta.10
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-BhpVpA9b.d.cts → BaseService-B_UKhVht.d.ts} +74 -2
- package/dist/{BaseService-CuV-ZVPs.d.ts → BaseService-DWbPbov7.d.cts} +74 -2
- package/dist/encryption/index.cjs +199 -100
- 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 +199 -100
- package/dist/encryption/index.js.map +1 -1
- package/dist/index.cjs +832 -310
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -42
- package/dist/index.d.ts +84 -42
- package/dist/index.js +806 -292
- 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 +623 -125
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.d.cts +204 -14
- package/dist/kv/index.d.ts +204 -14
- package/dist/kv/index.js +623 -125
- package/dist/kv/index.js.map +1 -1
- package/dist/sql/index.cjs +191 -35
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.d.cts +6 -3
- package/dist/sql/index.d.ts +6 -3
- package/dist/sql/index.js +182 -26
- 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,9 +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-
|
|
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';
|
|
5
6
|
import { IKVService } from './kv/index.cjs';
|
|
6
|
-
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';
|
|
7
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';
|
|
8
9
|
import { IEncryptionService, DecryptCapabilityProof } from './encryption/index.cjs';
|
|
9
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';
|
|
@@ -1050,8 +1051,11 @@ declare function authExpiredError(service: string): ServiceError;
|
|
|
1050
1051
|
declare function networkError(service: string, message: string, cause?: Error): ServiceError;
|
|
1051
1052
|
/**
|
|
1052
1053
|
* Create a service error for timeouts.
|
|
1054
|
+
*
|
|
1055
|
+
* @param timeoutMs - The configured timeout that elapsed, when known
|
|
1056
|
+
* @param cause - The underlying timeout error, when known
|
|
1053
1057
|
*/
|
|
1054
|
-
declare function timeoutError(service: string): ServiceError;
|
|
1058
|
+
declare function timeoutError(service: string, timeoutMs?: number, cause?: Error): ServiceError;
|
|
1055
1059
|
/**
|
|
1056
1060
|
* Create a service error for aborted requests.
|
|
1057
1061
|
*/
|
|
@@ -1076,56 +1080,87 @@ declare function parseAuthError(responseText: string): {
|
|
|
1076
1080
|
*/
|
|
1077
1081
|
declare function authUnauthorizedError(service: string, message: string, meta?: Record<string, unknown>): ServiceError;
|
|
1078
1082
|
/**
|
|
1079
|
-
*
|
|
1083
|
+
* Authorization verdict read from an error's structure, never its message:
|
|
1084
|
+
* - `"unauthenticated"`: HTTP 401 — the session is missing or stale.
|
|
1085
|
+
* - `"forbidden"`: HTTP 403, or `AUTH_UNAUTHORIZED` without a status — the
|
|
1086
|
+
* session is valid but lacks the capability.
|
|
1087
|
+
* - `"other"`: a non-authorization HTTP error status (4xx/5xx).
|
|
1080
1088
|
*/
|
|
1081
|
-
|
|
1089
|
+
type AuthorizationVerdict = "unauthenticated" | "forbidden" | "other";
|
|
1082
1090
|
/**
|
|
1083
|
-
*
|
|
1091
|
+
* Parse a canonical TinyCloud resource, keeping nested space names intact.
|
|
1092
|
+
* The first registered service segment is authoritative: a later matching
|
|
1093
|
+
* segment in the path cannot turn a different service into grant advice.
|
|
1084
1094
|
*/
|
|
1085
|
-
declare function
|
|
1095
|
+
declare function parseCapabilityResource(resource: string, service: string): {
|
|
1096
|
+
space: string;
|
|
1097
|
+
path: string;
|
|
1098
|
+
} | undefined;
|
|
1086
1099
|
/**
|
|
1087
|
-
*
|
|
1100
|
+
* Return a grantable missing capability only when typed authorization evidence
|
|
1101
|
+
* and both safe, service-matched capability fields are present. Status alone,
|
|
1102
|
+
* message text, wildcard actions and unrecognized actions cannot grant scope.
|
|
1088
1103
|
*/
|
|
1089
|
-
declare function
|
|
1104
|
+
declare function validatedCapabilityOf(error: unknown): {
|
|
1105
|
+
resource: string;
|
|
1106
|
+
requiredAction: string;
|
|
1107
|
+
} | undefined;
|
|
1090
1108
|
/**
|
|
1091
|
-
*
|
|
1109
|
+
* Classify an error from its typed HTTP error status (`status`, `statusCode`,
|
|
1110
|
+
* or `meta.status`, 4xx/5xx only) and `AUTH_UNAUTHORIZED` code, following the
|
|
1111
|
+
* `cause` chain outer-first (at most {@link MAX_CAUSE_DEPTH} links, cycles
|
|
1112
|
+
* stop the walk) so wrappers that rethrow with `cause` keep the verdict. The
|
|
1113
|
+
* outermost error status decides, so an outer 5xx keeps its retry budget even
|
|
1114
|
+
* over an inner 401. Returns `undefined` for untyped errors; only then may
|
|
1115
|
+
* callers fall back to message heuristics.
|
|
1092
1116
|
*/
|
|
1093
|
-
declare function
|
|
1094
|
-
|
|
1117
|
+
declare function authorizationVerdictOf(error: unknown): AuthorizationVerdict | undefined;
|
|
1095
1118
|
/**
|
|
1096
|
-
*
|
|
1097
|
-
*
|
|
1098
|
-
* Types specific to the base service infrastructure.
|
|
1119
|
+
* Create a service error for storage quota exceeded (402 Payment Required).
|
|
1099
1120
|
*/
|
|
1100
|
-
|
|
1121
|
+
declare function storageQuotaExceededError(service: string, message: string, meta?: Record<string, unknown>): ServiceError;
|
|
1101
1122
|
/**
|
|
1102
|
-
*
|
|
1103
|
-
* Used by the SDK to instantiate services.
|
|
1123
|
+
* Create a service error for storage limit reached (413 Payload Too Large).
|
|
1104
1124
|
*/
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1125
|
+
declare function storageLimitReachedError(service: string, message: string, meta?: Record<string, unknown>): ServiceError;
|
|
1126
|
+
/** Shown when a write is rejected because the owner's storage is full. */
|
|
1127
|
+
declare const STORAGE_FULL_MESSAGE = "TinyCloud storage is full, so this change was not saved. Reading still works. Free up space or upgrade your plan to save again.";
|
|
1128
|
+
/** Shown when a write is larger than the storage the owner has left. */
|
|
1129
|
+
declare const STORAGE_WRITE_TOO_LARGE_MESSAGE = "This change is larger than the TinyCloud storage you have left, so it was not saved. Reading still works. Free up space or upgrade your plan to save it.";
|
|
1130
|
+
/**
|
|
1131
|
+
* Parse the byte counts from a node storage rejection
|
|
1132
|
+
* ("... Used: 155744 bytes, Limit: 0 bytes"). The limit is the share of the
|
|
1133
|
+
* owner's account-wide budget left for this space, so it is 0 when the
|
|
1134
|
+
* owner's other spaces already use the whole budget.
|
|
1135
|
+
*/
|
|
1136
|
+
declare function parseStorageQuotaBytes(responseText: string): {
|
|
1137
|
+
usedBytes: number;
|
|
1138
|
+
limitBytes: number;
|
|
1139
|
+
} | undefined;
|
|
1111
1140
|
/**
|
|
1112
|
-
*
|
|
1141
|
+
* Build the error for a write the node rejected for storage: 402 when storage
|
|
1142
|
+
* is already full, 413 when this write is larger than what is left. KV, SQL
|
|
1143
|
+
* and DuckDB all report it with the same codes and message so an app can
|
|
1144
|
+
* detect "storage full" in one place with {@link isStorageFullError}.
|
|
1113
1145
|
*/
|
|
1114
|
-
|
|
1115
|
-
/** The service class constructor */
|
|
1116
|
-
constructor: ServiceConstructor;
|
|
1117
|
-
/** Configuration for this service instance */
|
|
1118
|
-
config?: Record<string, unknown>;
|
|
1119
|
-
}
|
|
1146
|
+
declare function storageRejectionError(service: string, status: 402 | 413, meta: Record<string, unknown>, responseText: string): ServiceError;
|
|
1120
1147
|
/**
|
|
1121
|
-
*
|
|
1148
|
+
* True when a write failed for storage: the owner's TinyCloud storage is full
|
|
1149
|
+
* (`STORAGE_QUOTA_EXCEEDED`), or this write is larger than what is left
|
|
1150
|
+
* (`STORAGE_LIMIT_REACHED`). Reads keep working in both cases, so apps should
|
|
1151
|
+
* stay usable read-only and point the user at freeing up space or upgrading.
|
|
1122
1152
|
*/
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1153
|
+
declare function isStorageFullError(error: {
|
|
1154
|
+
code?: string;
|
|
1155
|
+
} | null | undefined): boolean;
|
|
1156
|
+
/**
|
|
1157
|
+
* Wrap an unknown error in a ServiceError.
|
|
1158
|
+
*/
|
|
1159
|
+
declare function wrapError(service: string, error: unknown, defaultCode?: string): ServiceError;
|
|
1160
|
+
/**
|
|
1161
|
+
* Create an error Result from a ServiceError.
|
|
1162
|
+
*/
|
|
1163
|
+
declare function errorResult(error: ServiceError): Result<never, ServiceError>;
|
|
1129
1164
|
|
|
1130
1165
|
/**
|
|
1131
1166
|
* DuckDB Service Types
|
|
@@ -1142,7 +1177,10 @@ interface DuckDbServiceConfig {
|
|
|
1142
1177
|
*/
|
|
1143
1178
|
defaultDatabase?: string;
|
|
1144
1179
|
/**
|
|
1145
|
-
*
|
|
1180
|
+
* Timeout in milliseconds for each DuckDB request, including reading the
|
|
1181
|
+
* response body. When it elapses the request is aborted and the operation
|
|
1182
|
+
* returns an `ErrorCodes.TIMEOUT` error. Unset (the default), `0`, or
|
|
1183
|
+
* `Infinity` means no timeout.
|
|
1146
1184
|
*/
|
|
1147
1185
|
timeout?: number;
|
|
1148
1186
|
/** Allow additional config properties */
|
|
@@ -1701,6 +1739,10 @@ type VaultErrorInput = {
|
|
|
1701
1739
|
code: "STORAGE_ERROR";
|
|
1702
1740
|
cause: Error;
|
|
1703
1741
|
message?: string;
|
|
1742
|
+
} | {
|
|
1743
|
+
code: "STORAGE_QUOTA_EXCEEDED" | "STORAGE_LIMIT_REACHED";
|
|
1744
|
+
message: string;
|
|
1745
|
+
meta?: Record<string, unknown>;
|
|
1704
1746
|
};
|
|
1705
1747
|
/**
|
|
1706
1748
|
* Vault error with service field (compatible with ServiceError).
|
|
@@ -2245,4 +2287,4 @@ declare class SecretsService implements ISecretsService {
|
|
|
2245
2287
|
listAll(): Promise<Result<SecretCatalogEntry[], SecretsError>>;
|
|
2246
2288
|
}
|
|
2247
2289
|
|
|
2248
|
-
export {
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +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-
|
|
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';
|
|
5
6
|
import { IKVService } from './kv/index.js';
|
|
6
|
-
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';
|
|
7
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';
|
|
8
9
|
import { IEncryptionService, DecryptCapabilityProof } from './encryption/index.js';
|
|
9
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';
|
|
@@ -1050,8 +1051,11 @@ declare function authExpiredError(service: string): ServiceError;
|
|
|
1050
1051
|
declare function networkError(service: string, message: string, cause?: Error): ServiceError;
|
|
1051
1052
|
/**
|
|
1052
1053
|
* Create a service error for timeouts.
|
|
1054
|
+
*
|
|
1055
|
+
* @param timeoutMs - The configured timeout that elapsed, when known
|
|
1056
|
+
* @param cause - The underlying timeout error, when known
|
|
1053
1057
|
*/
|
|
1054
|
-
declare function timeoutError(service: string): ServiceError;
|
|
1058
|
+
declare function timeoutError(service: string, timeoutMs?: number, cause?: Error): ServiceError;
|
|
1055
1059
|
/**
|
|
1056
1060
|
* Create a service error for aborted requests.
|
|
1057
1061
|
*/
|
|
@@ -1076,56 +1080,87 @@ declare function parseAuthError(responseText: string): {
|
|
|
1076
1080
|
*/
|
|
1077
1081
|
declare function authUnauthorizedError(service: string, message: string, meta?: Record<string, unknown>): ServiceError;
|
|
1078
1082
|
/**
|
|
1079
|
-
*
|
|
1083
|
+
* Authorization verdict read from an error's structure, never its message:
|
|
1084
|
+
* - `"unauthenticated"`: HTTP 401 — the session is missing or stale.
|
|
1085
|
+
* - `"forbidden"`: HTTP 403, or `AUTH_UNAUTHORIZED` without a status — the
|
|
1086
|
+
* session is valid but lacks the capability.
|
|
1087
|
+
* - `"other"`: a non-authorization HTTP error status (4xx/5xx).
|
|
1080
1088
|
*/
|
|
1081
|
-
|
|
1089
|
+
type AuthorizationVerdict = "unauthenticated" | "forbidden" | "other";
|
|
1082
1090
|
/**
|
|
1083
|
-
*
|
|
1091
|
+
* Parse a canonical TinyCloud resource, keeping nested space names intact.
|
|
1092
|
+
* The first registered service segment is authoritative: a later matching
|
|
1093
|
+
* segment in the path cannot turn a different service into grant advice.
|
|
1084
1094
|
*/
|
|
1085
|
-
declare function
|
|
1095
|
+
declare function parseCapabilityResource(resource: string, service: string): {
|
|
1096
|
+
space: string;
|
|
1097
|
+
path: string;
|
|
1098
|
+
} | undefined;
|
|
1086
1099
|
/**
|
|
1087
|
-
*
|
|
1100
|
+
* Return a grantable missing capability only when typed authorization evidence
|
|
1101
|
+
* and both safe, service-matched capability fields are present. Status alone,
|
|
1102
|
+
* message text, wildcard actions and unrecognized actions cannot grant scope.
|
|
1088
1103
|
*/
|
|
1089
|
-
declare function
|
|
1104
|
+
declare function validatedCapabilityOf(error: unknown): {
|
|
1105
|
+
resource: string;
|
|
1106
|
+
requiredAction: string;
|
|
1107
|
+
} | undefined;
|
|
1090
1108
|
/**
|
|
1091
|
-
*
|
|
1109
|
+
* Classify an error from its typed HTTP error status (`status`, `statusCode`,
|
|
1110
|
+
* or `meta.status`, 4xx/5xx only) and `AUTH_UNAUTHORIZED` code, following the
|
|
1111
|
+
* `cause` chain outer-first (at most {@link MAX_CAUSE_DEPTH} links, cycles
|
|
1112
|
+
* stop the walk) so wrappers that rethrow with `cause` keep the verdict. The
|
|
1113
|
+
* outermost error status decides, so an outer 5xx keeps its retry budget even
|
|
1114
|
+
* over an inner 401. Returns `undefined` for untyped errors; only then may
|
|
1115
|
+
* callers fall back to message heuristics.
|
|
1092
1116
|
*/
|
|
1093
|
-
declare function
|
|
1094
|
-
|
|
1117
|
+
declare function authorizationVerdictOf(error: unknown): AuthorizationVerdict | undefined;
|
|
1095
1118
|
/**
|
|
1096
|
-
*
|
|
1097
|
-
*
|
|
1098
|
-
* Types specific to the base service infrastructure.
|
|
1119
|
+
* Create a service error for storage quota exceeded (402 Payment Required).
|
|
1099
1120
|
*/
|
|
1100
|
-
|
|
1121
|
+
declare function storageQuotaExceededError(service: string, message: string, meta?: Record<string, unknown>): ServiceError;
|
|
1101
1122
|
/**
|
|
1102
|
-
*
|
|
1103
|
-
* Used by the SDK to instantiate services.
|
|
1123
|
+
* Create a service error for storage limit reached (413 Payload Too Large).
|
|
1104
1124
|
*/
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1125
|
+
declare function storageLimitReachedError(service: string, message: string, meta?: Record<string, unknown>): ServiceError;
|
|
1126
|
+
/** Shown when a write is rejected because the owner's storage is full. */
|
|
1127
|
+
declare const STORAGE_FULL_MESSAGE = "TinyCloud storage is full, so this change was not saved. Reading still works. Free up space or upgrade your plan to save again.";
|
|
1128
|
+
/** Shown when a write is larger than the storage the owner has left. */
|
|
1129
|
+
declare const STORAGE_WRITE_TOO_LARGE_MESSAGE = "This change is larger than the TinyCloud storage you have left, so it was not saved. Reading still works. Free up space or upgrade your plan to save it.";
|
|
1130
|
+
/**
|
|
1131
|
+
* Parse the byte counts from a node storage rejection
|
|
1132
|
+
* ("... Used: 155744 bytes, Limit: 0 bytes"). The limit is the share of the
|
|
1133
|
+
* owner's account-wide budget left for this space, so it is 0 when the
|
|
1134
|
+
* owner's other spaces already use the whole budget.
|
|
1135
|
+
*/
|
|
1136
|
+
declare function parseStorageQuotaBytes(responseText: string): {
|
|
1137
|
+
usedBytes: number;
|
|
1138
|
+
limitBytes: number;
|
|
1139
|
+
} | undefined;
|
|
1111
1140
|
/**
|
|
1112
|
-
*
|
|
1141
|
+
* Build the error for a write the node rejected for storage: 402 when storage
|
|
1142
|
+
* is already full, 413 when this write is larger than what is left. KV, SQL
|
|
1143
|
+
* and DuckDB all report it with the same codes and message so an app can
|
|
1144
|
+
* detect "storage full" in one place with {@link isStorageFullError}.
|
|
1113
1145
|
*/
|
|
1114
|
-
|
|
1115
|
-
/** The service class constructor */
|
|
1116
|
-
constructor: ServiceConstructor;
|
|
1117
|
-
/** Configuration for this service instance */
|
|
1118
|
-
config?: Record<string, unknown>;
|
|
1119
|
-
}
|
|
1146
|
+
declare function storageRejectionError(service: string, status: 402 | 413, meta: Record<string, unknown>, responseText: string): ServiceError;
|
|
1120
1147
|
/**
|
|
1121
|
-
*
|
|
1148
|
+
* True when a write failed for storage: the owner's TinyCloud storage is full
|
|
1149
|
+
* (`STORAGE_QUOTA_EXCEEDED`), or this write is larger than what is left
|
|
1150
|
+
* (`STORAGE_LIMIT_REACHED`). Reads keep working in both cases, so apps should
|
|
1151
|
+
* stay usable read-only and point the user at freeing up space or upgrading.
|
|
1122
1152
|
*/
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1153
|
+
declare function isStorageFullError(error: {
|
|
1154
|
+
code?: string;
|
|
1155
|
+
} | null | undefined): boolean;
|
|
1156
|
+
/**
|
|
1157
|
+
* Wrap an unknown error in a ServiceError.
|
|
1158
|
+
*/
|
|
1159
|
+
declare function wrapError(service: string, error: unknown, defaultCode?: string): ServiceError;
|
|
1160
|
+
/**
|
|
1161
|
+
* Create an error Result from a ServiceError.
|
|
1162
|
+
*/
|
|
1163
|
+
declare function errorResult(error: ServiceError): Result<never, ServiceError>;
|
|
1129
1164
|
|
|
1130
1165
|
/**
|
|
1131
1166
|
* DuckDB Service Types
|
|
@@ -1142,7 +1177,10 @@ interface DuckDbServiceConfig {
|
|
|
1142
1177
|
*/
|
|
1143
1178
|
defaultDatabase?: string;
|
|
1144
1179
|
/**
|
|
1145
|
-
*
|
|
1180
|
+
* Timeout in milliseconds for each DuckDB request, including reading the
|
|
1181
|
+
* response body. When it elapses the request is aborted and the operation
|
|
1182
|
+
* returns an `ErrorCodes.TIMEOUT` error. Unset (the default), `0`, or
|
|
1183
|
+
* `Infinity` means no timeout.
|
|
1146
1184
|
*/
|
|
1147
1185
|
timeout?: number;
|
|
1148
1186
|
/** Allow additional config properties */
|
|
@@ -1701,6 +1739,10 @@ type VaultErrorInput = {
|
|
|
1701
1739
|
code: "STORAGE_ERROR";
|
|
1702
1740
|
cause: Error;
|
|
1703
1741
|
message?: string;
|
|
1742
|
+
} | {
|
|
1743
|
+
code: "STORAGE_QUOTA_EXCEEDED" | "STORAGE_LIMIT_REACHED";
|
|
1744
|
+
message: string;
|
|
1745
|
+
meta?: Record<string, unknown>;
|
|
1704
1746
|
};
|
|
1705
1747
|
/**
|
|
1706
1748
|
* Vault error with service field (compatible with ServiceError).
|
|
@@ -2245,4 +2287,4 @@ declare class SecretsService implements ISecretsService {
|
|
|
2245
2287
|
listAll(): Promise<Result<SecretCatalogEntry[], SecretsError>>;
|
|
2246
2288
|
}
|
|
2247
2289
|
|
|
2248
|
-
export {
|
|
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 };
|