@tinycloud/sdk-services 2.1.0 → 2.2.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/index.cjs +129 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -1
- package/dist/index.d.ts +52 -1
- package/dist/index.js +125 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1937,4 +1937,55 @@ interface WasmVaultFunctions {
|
|
|
1937
1937
|
}
|
|
1938
1938
|
declare function createVaultCrypto(wasm: WasmVaultFunctions): VaultCrypto;
|
|
1939
1939
|
|
|
1940
|
-
|
|
1940
|
+
declare const SECRET_NAME_RE: RegExp;
|
|
1941
|
+
interface SecretScopeOptions {
|
|
1942
|
+
/** Optional logical scope. Omit for the global secret namespace. */
|
|
1943
|
+
scope?: string;
|
|
1944
|
+
}
|
|
1945
|
+
interface ResolvedSecretPath {
|
|
1946
|
+
/** Canonical env-style secret name. */
|
|
1947
|
+
name: string;
|
|
1948
|
+
/** Canonical scope. Undefined means global. */
|
|
1949
|
+
scope?: string;
|
|
1950
|
+
/** Key passed to the data vault service. */
|
|
1951
|
+
vaultKey: string;
|
|
1952
|
+
/** KV permission paths that back the encrypted vault entry. */
|
|
1953
|
+
permissionPaths: {
|
|
1954
|
+
keys: string;
|
|
1955
|
+
vault: string;
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
declare function canonicalizeSecretScope(scope: string | undefined): string | undefined;
|
|
1959
|
+
declare function resolveSecretPath(name: string, options?: SecretScopeOptions): ResolvedSecretPath;
|
|
1960
|
+
|
|
1961
|
+
interface SecretPayload {
|
|
1962
|
+
value: string;
|
|
1963
|
+
createdAt: string;
|
|
1964
|
+
updatedAt: string;
|
|
1965
|
+
}
|
|
1966
|
+
type SecretsError = VaultError | ServiceError;
|
|
1967
|
+
interface ISecretsService {
|
|
1968
|
+
readonly vault: IDataVaultService;
|
|
1969
|
+
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
1970
|
+
lock(): void;
|
|
1971
|
+
readonly isUnlocked: boolean;
|
|
1972
|
+
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
1973
|
+
put(name: string, value: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
1974
|
+
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
1975
|
+
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
declare class SecretsService implements ISecretsService {
|
|
1979
|
+
private readonly getVault;
|
|
1980
|
+
constructor(vault: IDataVaultService | (() => IDataVaultService));
|
|
1981
|
+
get vault(): IDataVaultService;
|
|
1982
|
+
get isUnlocked(): boolean;
|
|
1983
|
+
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
1984
|
+
lock(): void;
|
|
1985
|
+
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
1986
|
+
put(name: string, value: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
1987
|
+
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
1988
|
+
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
export { BaseService, type BaseServiceOptions, type ColumnInfo, type DataVaultConfig, DataVaultService, 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, 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, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, type SchemaInfo, type SecretPayload, type SecretScopeOptions, type SecretsError, SecretsService, type ServiceConstructor, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, type ServiceRegistration, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, type TableInfo, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, authExpiredError, authRequiredError, authUnauthorizedError, canonicalizeSecretScope, createKVResponseSchema, createResultSchema, createVaultCrypto, errorResult, networkError, notFoundError, parseAuthError, permissionDeniedError, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, timeoutError, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, wrapError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1937,4 +1937,55 @@ interface WasmVaultFunctions {
|
|
|
1937
1937
|
}
|
|
1938
1938
|
declare function createVaultCrypto(wasm: WasmVaultFunctions): VaultCrypto;
|
|
1939
1939
|
|
|
1940
|
-
|
|
1940
|
+
declare const SECRET_NAME_RE: RegExp;
|
|
1941
|
+
interface SecretScopeOptions {
|
|
1942
|
+
/** Optional logical scope. Omit for the global secret namespace. */
|
|
1943
|
+
scope?: string;
|
|
1944
|
+
}
|
|
1945
|
+
interface ResolvedSecretPath {
|
|
1946
|
+
/** Canonical env-style secret name. */
|
|
1947
|
+
name: string;
|
|
1948
|
+
/** Canonical scope. Undefined means global. */
|
|
1949
|
+
scope?: string;
|
|
1950
|
+
/** Key passed to the data vault service. */
|
|
1951
|
+
vaultKey: string;
|
|
1952
|
+
/** KV permission paths that back the encrypted vault entry. */
|
|
1953
|
+
permissionPaths: {
|
|
1954
|
+
keys: string;
|
|
1955
|
+
vault: string;
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
declare function canonicalizeSecretScope(scope: string | undefined): string | undefined;
|
|
1959
|
+
declare function resolveSecretPath(name: string, options?: SecretScopeOptions): ResolvedSecretPath;
|
|
1960
|
+
|
|
1961
|
+
interface SecretPayload {
|
|
1962
|
+
value: string;
|
|
1963
|
+
createdAt: string;
|
|
1964
|
+
updatedAt: string;
|
|
1965
|
+
}
|
|
1966
|
+
type SecretsError = VaultError | ServiceError;
|
|
1967
|
+
interface ISecretsService {
|
|
1968
|
+
readonly vault: IDataVaultService;
|
|
1969
|
+
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
1970
|
+
lock(): void;
|
|
1971
|
+
readonly isUnlocked: boolean;
|
|
1972
|
+
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
1973
|
+
put(name: string, value: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
1974
|
+
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
1975
|
+
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
declare class SecretsService implements ISecretsService {
|
|
1979
|
+
private readonly getVault;
|
|
1980
|
+
constructor(vault: IDataVaultService | (() => IDataVaultService));
|
|
1981
|
+
get vault(): IDataVaultService;
|
|
1982
|
+
get isUnlocked(): boolean;
|
|
1983
|
+
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
1984
|
+
lock(): void;
|
|
1985
|
+
get(name: string, options?: SecretScopeOptions): Promise<Result<string, SecretsError>>;
|
|
1986
|
+
put(name: string, value: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
1987
|
+
delete(name: string, options?: SecretScopeOptions): Promise<Result<void, SecretsError>>;
|
|
1988
|
+
list(options?: SecretScopeOptions): Promise<Result<string[], SecretsError>>;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
export { BaseService, type BaseServiceOptions, type ColumnInfo, type DataVaultConfig, DataVaultService, 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, 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, type IHooksService, IKVService, type ISecretsService, IService, IServiceContext, InvokeAnyFunction, InvokeFunction, KVListResponseSchema, type KVListResponseType, KVListResultSchema, type KVListResultType, KVResponseHeadersSchema, type KVResponseHeadersType, type QuotaConfig, type QuotaStatus, type ResolvedSecretPath, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, SECRET_NAME_RE, type SchemaInfo, type SecretPayload, type SecretScopeOptions, type SecretsError, SecretsService, type ServiceConstructor, ServiceContext, type ServiceContextConfig, ServiceError, ServiceErrorEventSchema, type ServiceErrorEventType, ServiceErrorSchema, type ServiceErrorType, type ServiceRegistration, ServiceRequestEventSchema, type ServiceRequestEventType, ServiceResponseEventSchema, type ServiceResponseEventType, ServiceRetryEventSchema, type ServiceRetryEventType, ServiceSession, ServiceSessionSchema, type ServiceSessionType, StorageQuotaInfo, type SubscribeOptions, type TableInfo, TinyCloudQuota, type ValidationError, type VaultCrypto, type VaultEntry, type VaultError, type VaultGetOptions, type VaultGrantOptions, VaultHeaders, type VaultListOptions, VaultPublicSpaceKVActions, type VaultPutOptions, type ViewInfo, type WasmVaultFunctions, abortedError, authExpiredError, authRequiredError, authUnauthorizedError, canonicalizeSecretScope, createKVResponseSchema, createResultSchema, createVaultCrypto, errorResult, networkError, notFoundError, parseAuthError, permissionDeniedError, resolveSecretPath, storageLimitReachedError, storageQuotaExceededError, timeoutError, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, wrapError };
|
package/dist/index.js
CHANGED
|
@@ -3762,6 +3762,127 @@ function createVaultCrypto(wasm) {
|
|
|
3762
3762
|
sha256: (data) => wasm.vault_sha256(data)
|
|
3763
3763
|
};
|
|
3764
3764
|
}
|
|
3765
|
+
|
|
3766
|
+
// src/secrets/paths.ts
|
|
3767
|
+
var SECRET_NAME_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
3768
|
+
var SECRET_PREFIX = "secrets/";
|
|
3769
|
+
var SCOPED_SECRET_PREFIX = "secrets/scoped/";
|
|
3770
|
+
var RESERVED_SECRET_SCOPES = /* @__PURE__ */ new Set(["default", "global"]);
|
|
3771
|
+
function canonicalizeSecretScope(scope) {
|
|
3772
|
+
if (scope === void 0) {
|
|
3773
|
+
return void 0;
|
|
3774
|
+
}
|
|
3775
|
+
const trimmed = scope.trim();
|
|
3776
|
+
if (trimmed === "") {
|
|
3777
|
+
throw new Error("Secret scope must be non-empty; omit scope for global secrets.");
|
|
3778
|
+
}
|
|
3779
|
+
const canonical = trimmed.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
3780
|
+
if (canonical === "") {
|
|
3781
|
+
throw new Error("Secret scope must contain at least one letter or number.");
|
|
3782
|
+
}
|
|
3783
|
+
if (RESERVED_SECRET_SCOPES.has(canonical)) {
|
|
3784
|
+
throw new Error(
|
|
3785
|
+
`Secret scope ${JSON.stringify(scope)} is reserved; omit scope for global secrets.`
|
|
3786
|
+
);
|
|
3787
|
+
}
|
|
3788
|
+
return canonical;
|
|
3789
|
+
}
|
|
3790
|
+
function resolveSecretPath(name, options = {}) {
|
|
3791
|
+
const normalizedName = name.trim();
|
|
3792
|
+
if (!SECRET_NAME_RE.test(normalizedName)) {
|
|
3793
|
+
throw new Error(
|
|
3794
|
+
`Invalid secret name ${JSON.stringify(name)}. Secret names must match ${SECRET_NAME_RE.source}.`
|
|
3795
|
+
);
|
|
3796
|
+
}
|
|
3797
|
+
const scope = canonicalizeSecretScope(options.scope);
|
|
3798
|
+
const vaultKey = scope === void 0 ? `${SECRET_PREFIX}${normalizedName}` : `${SCOPED_SECRET_PREFIX}${scope}/${normalizedName}`;
|
|
3799
|
+
return {
|
|
3800
|
+
name: normalizedName,
|
|
3801
|
+
...scope !== void 0 ? { scope } : {},
|
|
3802
|
+
vaultKey,
|
|
3803
|
+
permissionPaths: {
|
|
3804
|
+
keys: `keys/${vaultKey}`,
|
|
3805
|
+
vault: `vault/${vaultKey}`
|
|
3806
|
+
}
|
|
3807
|
+
};
|
|
3808
|
+
}
|
|
3809
|
+
|
|
3810
|
+
// src/secrets/SecretsService.ts
|
|
3811
|
+
function invalidSecretInput(message) {
|
|
3812
|
+
return err({
|
|
3813
|
+
code: ErrorCodes.INVALID_INPUT,
|
|
3814
|
+
service: "secrets",
|
|
3815
|
+
message
|
|
3816
|
+
});
|
|
3817
|
+
}
|
|
3818
|
+
function resolveSecretPathResult(name, options) {
|
|
3819
|
+
try {
|
|
3820
|
+
return resolveSecretPath(name, options);
|
|
3821
|
+
} catch (error) {
|
|
3822
|
+
return invalidSecretInput(error instanceof Error ? error.message : String(error));
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
var SecretsService = class {
|
|
3826
|
+
constructor(vault) {
|
|
3827
|
+
this.getVault = typeof vault === "function" ? vault : () => vault;
|
|
3828
|
+
}
|
|
3829
|
+
get vault() {
|
|
3830
|
+
return this.getVault();
|
|
3831
|
+
}
|
|
3832
|
+
get isUnlocked() {
|
|
3833
|
+
return this.vault.isUnlocked;
|
|
3834
|
+
}
|
|
3835
|
+
unlock(signer) {
|
|
3836
|
+
return this.vault.unlock(signer);
|
|
3837
|
+
}
|
|
3838
|
+
lock() {
|
|
3839
|
+
this.vault.lock();
|
|
3840
|
+
}
|
|
3841
|
+
async get(name, options) {
|
|
3842
|
+
const secretPath = resolveSecretPathResult(name, options);
|
|
3843
|
+
if ("ok" in secretPath) return secretPath;
|
|
3844
|
+
const result = await this.vault.get(secretPath.vaultKey);
|
|
3845
|
+
if (!result.ok) {
|
|
3846
|
+
return result;
|
|
3847
|
+
}
|
|
3848
|
+
return { ok: true, data: result.data.value.value };
|
|
3849
|
+
}
|
|
3850
|
+
async put(name, value, options) {
|
|
3851
|
+
const secretPath = resolveSecretPathResult(name, options);
|
|
3852
|
+
if ("ok" in secretPath) return secretPath;
|
|
3853
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3854
|
+
return this.vault.put(secretPath.vaultKey, {
|
|
3855
|
+
value,
|
|
3856
|
+
createdAt: now,
|
|
3857
|
+
updatedAt: now
|
|
3858
|
+
});
|
|
3859
|
+
}
|
|
3860
|
+
async delete(name, options) {
|
|
3861
|
+
const secretPath = resolveSecretPathResult(name, options);
|
|
3862
|
+
if ("ok" in secretPath) return secretPath;
|
|
3863
|
+
return this.vault.delete(secretPath.vaultKey);
|
|
3864
|
+
}
|
|
3865
|
+
async list(options) {
|
|
3866
|
+
let prefix;
|
|
3867
|
+
try {
|
|
3868
|
+
const scope = canonicalizeSecretScope(options?.scope);
|
|
3869
|
+
prefix = scope === void 0 ? "secrets/" : `secrets/scoped/${scope}/`;
|
|
3870
|
+
} catch (error) {
|
|
3871
|
+
return invalidSecretInput(error instanceof Error ? error.message : String(error));
|
|
3872
|
+
}
|
|
3873
|
+
const result = await this.vault.list({
|
|
3874
|
+
prefix,
|
|
3875
|
+
removePrefix: true
|
|
3876
|
+
});
|
|
3877
|
+
if (!result.ok) {
|
|
3878
|
+
return result;
|
|
3879
|
+
}
|
|
3880
|
+
return {
|
|
3881
|
+
ok: true,
|
|
3882
|
+
data: result.data.filter((name) => SECRET_NAME_RE.test(name))
|
|
3883
|
+
};
|
|
3884
|
+
}
|
|
3885
|
+
};
|
|
3765
3886
|
export {
|
|
3766
3887
|
BaseService,
|
|
3767
3888
|
DataVaultService,
|
|
@@ -3780,8 +3901,10 @@ export {
|
|
|
3780
3901
|
KVService,
|
|
3781
3902
|
PrefixedKVService,
|
|
3782
3903
|
RetryPolicySchema,
|
|
3904
|
+
SECRET_NAME_RE,
|
|
3783
3905
|
SQLAction,
|
|
3784
3906
|
SQLService,
|
|
3907
|
+
SecretsService,
|
|
3785
3908
|
ServiceContext,
|
|
3786
3909
|
ServiceErrorEventSchema,
|
|
3787
3910
|
ServiceErrorSchema,
|
|
@@ -3797,6 +3920,7 @@ export {
|
|
|
3797
3920
|
authExpiredError,
|
|
3798
3921
|
authRequiredError,
|
|
3799
3922
|
authUnauthorizedError,
|
|
3923
|
+
canonicalizeSecretScope,
|
|
3800
3924
|
createKVResponseSchema,
|
|
3801
3925
|
createResultSchema,
|
|
3802
3926
|
createVaultCrypto,
|
|
@@ -3808,6 +3932,7 @@ export {
|
|
|
3808
3932
|
ok,
|
|
3809
3933
|
parseAuthError,
|
|
3810
3934
|
permissionDeniedError,
|
|
3935
|
+
resolveSecretPath,
|
|
3811
3936
|
serviceError,
|
|
3812
3937
|
storageLimitReachedError,
|
|
3813
3938
|
storageQuotaExceededError,
|