@tinycloud/sdk-services 2.1.0 → 2.2.0-beta.7
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 +73 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -1
- package/dist/index.d.ts +31 -1
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1937,4 +1937,34 @@ interface WasmVaultFunctions {
|
|
|
1937
1937
|
}
|
|
1938
1938
|
declare function createVaultCrypto(wasm: WasmVaultFunctions): VaultCrypto;
|
|
1939
1939
|
|
|
1940
|
-
|
|
1940
|
+
interface SecretPayload {
|
|
1941
|
+
value: string;
|
|
1942
|
+
createdAt: string;
|
|
1943
|
+
updatedAt: string;
|
|
1944
|
+
}
|
|
1945
|
+
type SecretsError = VaultError | ServiceError;
|
|
1946
|
+
interface ISecretsService {
|
|
1947
|
+
readonly vault: IDataVaultService;
|
|
1948
|
+
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
1949
|
+
lock(): void;
|
|
1950
|
+
readonly isUnlocked: boolean;
|
|
1951
|
+
get(name: string): Promise<Result<string, SecretsError>>;
|
|
1952
|
+
put(name: string, value: string): Promise<Result<void, SecretsError>>;
|
|
1953
|
+
delete(name: string): Promise<Result<void, SecretsError>>;
|
|
1954
|
+
list(): Promise<Result<string[], SecretsError>>;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
declare class SecretsService implements ISecretsService {
|
|
1958
|
+
private readonly getVault;
|
|
1959
|
+
constructor(vault: IDataVaultService | (() => IDataVaultService));
|
|
1960
|
+
get vault(): IDataVaultService;
|
|
1961
|
+
get isUnlocked(): boolean;
|
|
1962
|
+
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
1963
|
+
lock(): void;
|
|
1964
|
+
get(name: string): Promise<Result<string, SecretsError>>;
|
|
1965
|
+
put(name: string, value: string): Promise<Result<void, SecretsError>>;
|
|
1966
|
+
delete(name: string): Promise<Result<void, SecretsError>>;
|
|
1967
|
+
list(): Promise<Result<string[], SecretsError>>;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
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, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, type SchemaInfo, type SecretPayload, 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, createKVResponseSchema, createResultSchema, createVaultCrypto, errorResult, networkError, notFoundError, parseAuthError, permissionDeniedError, storageLimitReachedError, storageQuotaExceededError, timeoutError, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, wrapError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1937,4 +1937,34 @@ interface WasmVaultFunctions {
|
|
|
1937
1937
|
}
|
|
1938
1938
|
declare function createVaultCrypto(wasm: WasmVaultFunctions): VaultCrypto;
|
|
1939
1939
|
|
|
1940
|
-
|
|
1940
|
+
interface SecretPayload {
|
|
1941
|
+
value: string;
|
|
1942
|
+
createdAt: string;
|
|
1943
|
+
updatedAt: string;
|
|
1944
|
+
}
|
|
1945
|
+
type SecretsError = VaultError | ServiceError;
|
|
1946
|
+
interface ISecretsService {
|
|
1947
|
+
readonly vault: IDataVaultService;
|
|
1948
|
+
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
1949
|
+
lock(): void;
|
|
1950
|
+
readonly isUnlocked: boolean;
|
|
1951
|
+
get(name: string): Promise<Result<string, SecretsError>>;
|
|
1952
|
+
put(name: string, value: string): Promise<Result<void, SecretsError>>;
|
|
1953
|
+
delete(name: string): Promise<Result<void, SecretsError>>;
|
|
1954
|
+
list(): Promise<Result<string[], SecretsError>>;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
declare class SecretsService implements ISecretsService {
|
|
1958
|
+
private readonly getVault;
|
|
1959
|
+
constructor(vault: IDataVaultService | (() => IDataVaultService));
|
|
1960
|
+
get vault(): IDataVaultService;
|
|
1961
|
+
get isUnlocked(): boolean;
|
|
1962
|
+
unlock(signer?: unknown): Promise<Result<void, VaultError>>;
|
|
1963
|
+
lock(): void;
|
|
1964
|
+
get(name: string): Promise<Result<string, SecretsError>>;
|
|
1965
|
+
put(name: string, value: string): Promise<Result<void, SecretsError>>;
|
|
1966
|
+
delete(name: string): Promise<Result<void, SecretsError>>;
|
|
1967
|
+
list(): Promise<Result<string[], SecretsError>>;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
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, Result, RetryPolicy, RetryPolicySchema, type RetryPolicyType, type SchemaInfo, type SecretPayload, 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, createKVResponseSchema, createResultSchema, createVaultCrypto, errorResult, networkError, notFoundError, parseAuthError, permissionDeniedError, storageLimitReachedError, storageQuotaExceededError, timeoutError, validateKVListResponse, validateKVResponseHeaders, validateRetryPolicy, validateServiceError, validateServiceRequestEvent, validateServiceResponseEvent, validateServiceSession, wrapError };
|
package/dist/index.js
CHANGED
|
@@ -3762,6 +3762,77 @@ function createVaultCrypto(wasm) {
|
|
|
3762
3762
|
sha256: (data) => wasm.vault_sha256(data)
|
|
3763
3763
|
};
|
|
3764
3764
|
}
|
|
3765
|
+
|
|
3766
|
+
// src/secrets/SecretsService.ts
|
|
3767
|
+
var SECRET_NAME_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
3768
|
+
var SECRET_PREFIX = "secrets/";
|
|
3769
|
+
function invalidSecretName(name) {
|
|
3770
|
+
return err({
|
|
3771
|
+
code: ErrorCodes.INVALID_INPUT,
|
|
3772
|
+
service: "secrets",
|
|
3773
|
+
message: `Invalid secret name ${JSON.stringify(name)}. Secret names must match ${SECRET_NAME_RE.source}.`
|
|
3774
|
+
});
|
|
3775
|
+
}
|
|
3776
|
+
function secretKey(name) {
|
|
3777
|
+
return `${SECRET_PREFIX}${name}`;
|
|
3778
|
+
}
|
|
3779
|
+
var SecretsService = class {
|
|
3780
|
+
constructor(vault) {
|
|
3781
|
+
this.getVault = typeof vault === "function" ? vault : () => vault;
|
|
3782
|
+
}
|
|
3783
|
+
get vault() {
|
|
3784
|
+
return this.getVault();
|
|
3785
|
+
}
|
|
3786
|
+
get isUnlocked() {
|
|
3787
|
+
return this.vault.isUnlocked;
|
|
3788
|
+
}
|
|
3789
|
+
unlock(signer) {
|
|
3790
|
+
return this.vault.unlock(signer);
|
|
3791
|
+
}
|
|
3792
|
+
lock() {
|
|
3793
|
+
this.vault.lock();
|
|
3794
|
+
}
|
|
3795
|
+
async get(name) {
|
|
3796
|
+
if (!SECRET_NAME_RE.test(name)) {
|
|
3797
|
+
return invalidSecretName(name);
|
|
3798
|
+
}
|
|
3799
|
+
const result = await this.vault.get(secretKey(name));
|
|
3800
|
+
if (!result.ok) {
|
|
3801
|
+
return result;
|
|
3802
|
+
}
|
|
3803
|
+
return { ok: true, data: result.data.value.value };
|
|
3804
|
+
}
|
|
3805
|
+
async put(name, value) {
|
|
3806
|
+
if (!SECRET_NAME_RE.test(name)) {
|
|
3807
|
+
return invalidSecretName(name);
|
|
3808
|
+
}
|
|
3809
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3810
|
+
return this.vault.put(secretKey(name), {
|
|
3811
|
+
value,
|
|
3812
|
+
createdAt: now,
|
|
3813
|
+
updatedAt: now
|
|
3814
|
+
});
|
|
3815
|
+
}
|
|
3816
|
+
async delete(name) {
|
|
3817
|
+
if (!SECRET_NAME_RE.test(name)) {
|
|
3818
|
+
return invalidSecretName(name);
|
|
3819
|
+
}
|
|
3820
|
+
return this.vault.delete(secretKey(name));
|
|
3821
|
+
}
|
|
3822
|
+
async list() {
|
|
3823
|
+
const result = await this.vault.list({
|
|
3824
|
+
prefix: SECRET_PREFIX,
|
|
3825
|
+
removePrefix: true
|
|
3826
|
+
});
|
|
3827
|
+
if (!result.ok) {
|
|
3828
|
+
return result;
|
|
3829
|
+
}
|
|
3830
|
+
return {
|
|
3831
|
+
ok: true,
|
|
3832
|
+
data: result.data.filter((name) => SECRET_NAME_RE.test(name))
|
|
3833
|
+
};
|
|
3834
|
+
}
|
|
3835
|
+
};
|
|
3765
3836
|
export {
|
|
3766
3837
|
BaseService,
|
|
3767
3838
|
DataVaultService,
|
|
@@ -3782,6 +3853,7 @@ export {
|
|
|
3782
3853
|
RetryPolicySchema,
|
|
3783
3854
|
SQLAction,
|
|
3784
3855
|
SQLService,
|
|
3856
|
+
SecretsService,
|
|
3785
3857
|
ServiceContext,
|
|
3786
3858
|
ServiceErrorEventSchema,
|
|
3787
3859
|
ServiceErrorSchema,
|