@tinycloud/sdk-services 2.1.0-beta.4 → 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.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
RetryPolicySchema: () => RetryPolicySchema,
|
|
40
40
|
SQLAction: () => SQLAction,
|
|
41
41
|
SQLService: () => SQLService,
|
|
42
|
+
SecretsService: () => SecretsService,
|
|
42
43
|
ServiceContext: () => ServiceContext,
|
|
43
44
|
ServiceErrorEventSchema: () => ServiceErrorEventSchema,
|
|
44
45
|
ServiceErrorSchema: () => ServiceErrorSchema,
|
|
@@ -3844,6 +3845,77 @@ function createVaultCrypto(wasm) {
|
|
|
3844
3845
|
sha256: (data) => wasm.vault_sha256(data)
|
|
3845
3846
|
};
|
|
3846
3847
|
}
|
|
3848
|
+
|
|
3849
|
+
// src/secrets/SecretsService.ts
|
|
3850
|
+
var SECRET_NAME_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
3851
|
+
var SECRET_PREFIX = "secrets/";
|
|
3852
|
+
function invalidSecretName(name) {
|
|
3853
|
+
return err({
|
|
3854
|
+
code: ErrorCodes.INVALID_INPUT,
|
|
3855
|
+
service: "secrets",
|
|
3856
|
+
message: `Invalid secret name ${JSON.stringify(name)}. Secret names must match ${SECRET_NAME_RE.source}.`
|
|
3857
|
+
});
|
|
3858
|
+
}
|
|
3859
|
+
function secretKey(name) {
|
|
3860
|
+
return `${SECRET_PREFIX}${name}`;
|
|
3861
|
+
}
|
|
3862
|
+
var SecretsService = class {
|
|
3863
|
+
constructor(vault) {
|
|
3864
|
+
this.getVault = typeof vault === "function" ? vault : () => vault;
|
|
3865
|
+
}
|
|
3866
|
+
get vault() {
|
|
3867
|
+
return this.getVault();
|
|
3868
|
+
}
|
|
3869
|
+
get isUnlocked() {
|
|
3870
|
+
return this.vault.isUnlocked;
|
|
3871
|
+
}
|
|
3872
|
+
unlock(signer) {
|
|
3873
|
+
return this.vault.unlock(signer);
|
|
3874
|
+
}
|
|
3875
|
+
lock() {
|
|
3876
|
+
this.vault.lock();
|
|
3877
|
+
}
|
|
3878
|
+
async get(name) {
|
|
3879
|
+
if (!SECRET_NAME_RE.test(name)) {
|
|
3880
|
+
return invalidSecretName(name);
|
|
3881
|
+
}
|
|
3882
|
+
const result = await this.vault.get(secretKey(name));
|
|
3883
|
+
if (!result.ok) {
|
|
3884
|
+
return result;
|
|
3885
|
+
}
|
|
3886
|
+
return { ok: true, data: result.data.value.value };
|
|
3887
|
+
}
|
|
3888
|
+
async put(name, value) {
|
|
3889
|
+
if (!SECRET_NAME_RE.test(name)) {
|
|
3890
|
+
return invalidSecretName(name);
|
|
3891
|
+
}
|
|
3892
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3893
|
+
return this.vault.put(secretKey(name), {
|
|
3894
|
+
value,
|
|
3895
|
+
createdAt: now,
|
|
3896
|
+
updatedAt: now
|
|
3897
|
+
});
|
|
3898
|
+
}
|
|
3899
|
+
async delete(name) {
|
|
3900
|
+
if (!SECRET_NAME_RE.test(name)) {
|
|
3901
|
+
return invalidSecretName(name);
|
|
3902
|
+
}
|
|
3903
|
+
return this.vault.delete(secretKey(name));
|
|
3904
|
+
}
|
|
3905
|
+
async list() {
|
|
3906
|
+
const result = await this.vault.list({
|
|
3907
|
+
prefix: SECRET_PREFIX,
|
|
3908
|
+
removePrefix: true
|
|
3909
|
+
});
|
|
3910
|
+
if (!result.ok) {
|
|
3911
|
+
return result;
|
|
3912
|
+
}
|
|
3913
|
+
return {
|
|
3914
|
+
ok: true,
|
|
3915
|
+
data: result.data.filter((name) => SECRET_NAME_RE.test(name))
|
|
3916
|
+
};
|
|
3917
|
+
}
|
|
3918
|
+
};
|
|
3847
3919
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3848
3920
|
0 && (module.exports = {
|
|
3849
3921
|
BaseService,
|
|
@@ -3865,6 +3937,7 @@ function createVaultCrypto(wasm) {
|
|
|
3865
3937
|
RetryPolicySchema,
|
|
3866
3938
|
SQLAction,
|
|
3867
3939
|
SQLService,
|
|
3940
|
+
SecretsService,
|
|
3868
3941
|
ServiceContext,
|
|
3869
3942
|
ServiceErrorEventSchema,
|
|
3870
3943
|
ServiceErrorSchema,
|