@tinycloud/sdk-services 2.11.0 → 3.0.0-beta.14
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/encryption/index.cjs +4 -1
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.js +4 -1
- package/dist/encryption/index.js.map +1 -1
- package/dist/index.cjs +80 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +79 -14
- package/dist/index.js.map +1 -1
- package/dist/kv/index.cjs +11 -10
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.js +11 -10
- package/dist/kv/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -115,6 +115,7 @@ __export(src_exports, {
|
|
|
115
115
|
parseNetworkId: () => parseNetworkId,
|
|
116
116
|
parsePermissionHint: () => parsePermissionHint,
|
|
117
117
|
parsePermissionHintFromErrorText: () => parsePermissionHintFromErrorText,
|
|
118
|
+
parseSecretCatalogKey: () => parseSecretCatalogKey,
|
|
118
119
|
permissionDeniedError: () => permissionDeniedError,
|
|
119
120
|
resolveSecretListPrefix: () => resolveSecretListPrefix,
|
|
120
121
|
resolveSecretPath: () => resolveSecretPath,
|
|
@@ -1619,7 +1620,7 @@ var KVService = class extends BaseService {
|
|
|
1619
1620
|
*/
|
|
1620
1621
|
getFullPath(key, prefixOverride) {
|
|
1621
1622
|
const prefix = prefixOverride ?? this._config.prefix ?? "";
|
|
1622
|
-
return prefix ? `${prefix}/${key}` : key;
|
|
1623
|
+
return prefix ? key === "" ? prefix : `${prefix}/${key}` : key;
|
|
1623
1624
|
}
|
|
1624
1625
|
/**
|
|
1625
1626
|
* Get the host URL.
|
|
@@ -2103,16 +2104,17 @@ var KVService = class extends BaseService {
|
|
|
2103
2104
|
...options?.ifNoneMatch === void 0 ? {} : { "if-none-match": options.ifNoneMatch }
|
|
2104
2105
|
}
|
|
2105
2106
|
);
|
|
2107
|
+
if (response.status === 401 || response.status === 403) {
|
|
2108
|
+
const errorText = await response.text();
|
|
2109
|
+
const message = errorText.trim().length > 0 ? errorText : `Failed to put key "${key}": ${response.status} - ${response.statusText || "authorization failed"}`;
|
|
2110
|
+
const { resource, action: requiredAction } = parseAuthError(errorText);
|
|
2111
|
+
return err(authUnauthorizedError("kv", message, {
|
|
2112
|
+
status: response.status,
|
|
2113
|
+
...requiredAction && { requiredAction },
|
|
2114
|
+
...resource && { resource }
|
|
2115
|
+
}));
|
|
2116
|
+
}
|
|
2106
2117
|
if (!response.ok) {
|
|
2107
|
-
if (response.status === 401) {
|
|
2108
|
-
const errorText2 = await response.text();
|
|
2109
|
-
const { resource, action } = parseAuthError(errorText2);
|
|
2110
|
-
return err(authUnauthorizedError("kv", errorText2, {
|
|
2111
|
-
status: response.status,
|
|
2112
|
-
...action && { requiredAction: action },
|
|
2113
|
-
...resource && { resource }
|
|
2114
|
-
}));
|
|
2115
|
-
}
|
|
2116
2118
|
const errorText = await response.text();
|
|
2117
2119
|
if (response.status === 412) {
|
|
2118
2120
|
return err(serviceError(
|
|
@@ -5752,7 +5754,9 @@ function canonicalizeSecretScope(scope) {
|
|
|
5752
5754
|
}
|
|
5753
5755
|
const trimmed = scope.trim();
|
|
5754
5756
|
if (trimmed === "") {
|
|
5755
|
-
throw new Error(
|
|
5757
|
+
throw new Error(
|
|
5758
|
+
"Secret scope must be non-empty; omit scope for global secrets."
|
|
5759
|
+
);
|
|
5756
5760
|
}
|
|
5757
5761
|
const canonical = trimmed.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
5758
5762
|
if (canonical === "") {
|
|
@@ -5787,6 +5791,28 @@ function resolveSecretListPrefix(options = {}) {
|
|
|
5787
5791
|
const scope = canonicalizeSecretScope(options.scope);
|
|
5788
5792
|
return scope === void 0 ? "vault/secrets/" : `vault/secrets/scoped/${scope}/`;
|
|
5789
5793
|
}
|
|
5794
|
+
function parseSecretCatalogKey(key) {
|
|
5795
|
+
if (SECRET_NAME_RE.test(key)) {
|
|
5796
|
+
return { name: key };
|
|
5797
|
+
}
|
|
5798
|
+
const parts = key.split("/");
|
|
5799
|
+
if (parts.length !== 3 || parts[0] !== "scoped") {
|
|
5800
|
+
return void 0;
|
|
5801
|
+
}
|
|
5802
|
+
const [, rawScope, name] = parts;
|
|
5803
|
+
if (!name || !SECRET_NAME_RE.test(name)) {
|
|
5804
|
+
return void 0;
|
|
5805
|
+
}
|
|
5806
|
+
try {
|
|
5807
|
+
const scope = canonicalizeSecretScope(rawScope);
|
|
5808
|
+
if (scope === void 0 || scope !== rawScope) {
|
|
5809
|
+
return void 0;
|
|
5810
|
+
}
|
|
5811
|
+
return { name, scope };
|
|
5812
|
+
} catch {
|
|
5813
|
+
return void 0;
|
|
5814
|
+
}
|
|
5815
|
+
}
|
|
5790
5816
|
|
|
5791
5817
|
// src/secrets/SecretsService.ts
|
|
5792
5818
|
function invalidSecretInput(message) {
|
|
@@ -5800,7 +5826,9 @@ function resolveSecretPathResult(name, options) {
|
|
|
5800
5826
|
try {
|
|
5801
5827
|
return resolveSecretPath(name, options);
|
|
5802
5828
|
} catch (error) {
|
|
5803
|
-
return invalidSecretInput(
|
|
5829
|
+
return invalidSecretInput(
|
|
5830
|
+
error instanceof Error ? error.message : String(error)
|
|
5831
|
+
);
|
|
5804
5832
|
}
|
|
5805
5833
|
}
|
|
5806
5834
|
var SecretsService = class {
|
|
@@ -5849,7 +5877,9 @@ var SecretsService = class {
|
|
|
5849
5877
|
const scope = canonicalizeSecretScope(options?.scope);
|
|
5850
5878
|
prefix = scope === void 0 ? "secrets/" : `secrets/scoped/${scope}/`;
|
|
5851
5879
|
} catch (error) {
|
|
5852
|
-
return invalidSecretInput(
|
|
5880
|
+
return invalidSecretInput(
|
|
5881
|
+
error instanceof Error ? error.message : String(error)
|
|
5882
|
+
);
|
|
5853
5883
|
}
|
|
5854
5884
|
const result = await this.vault.list({
|
|
5855
5885
|
prefix,
|
|
@@ -5863,6 +5893,38 @@ var SecretsService = class {
|
|
|
5863
5893
|
data: result.data.filter((name) => SECRET_NAME_RE.test(name))
|
|
5864
5894
|
};
|
|
5865
5895
|
}
|
|
5896
|
+
async listAll() {
|
|
5897
|
+
const entries = /* @__PURE__ */ new Map();
|
|
5898
|
+
let cursor;
|
|
5899
|
+
do {
|
|
5900
|
+
const result = await this.vault.listPage({
|
|
5901
|
+
prefix: "secrets/",
|
|
5902
|
+
removePrefix: true,
|
|
5903
|
+
limit: 1e3,
|
|
5904
|
+
...cursor === void 0 ? {} : { cursor }
|
|
5905
|
+
});
|
|
5906
|
+
if (!result.ok) {
|
|
5907
|
+
return result;
|
|
5908
|
+
}
|
|
5909
|
+
for (const key of result.data.keys) {
|
|
5910
|
+
const entry = parseSecretCatalogKey(key);
|
|
5911
|
+
if (!entry) continue;
|
|
5912
|
+
entries.set(`${entry.scope ?? ""}\0${entry.name}`, entry);
|
|
5913
|
+
}
|
|
5914
|
+
cursor = result.data.truncated ? result.data.nextCursor : void 0;
|
|
5915
|
+
if (result.data.truncated && cursor === void 0) {
|
|
5916
|
+
return invalidSecretInput(
|
|
5917
|
+
"Secret catalog listing was truncated without a continuation cursor."
|
|
5918
|
+
);
|
|
5919
|
+
}
|
|
5920
|
+
} while (cursor !== void 0);
|
|
5921
|
+
return {
|
|
5922
|
+
ok: true,
|
|
5923
|
+
data: [...entries.values()].sort(
|
|
5924
|
+
(a, b) => (a.scope ?? "").localeCompare(b.scope ?? "") || a.name.localeCompare(b.name)
|
|
5925
|
+
)
|
|
5926
|
+
};
|
|
5927
|
+
}
|
|
5866
5928
|
};
|
|
5867
5929
|
|
|
5868
5930
|
// src/encryption/canonical.ts
|
|
@@ -6752,7 +6814,10 @@ var EncryptionService = class extends BaseService {
|
|
|
6752
6814
|
const descriptor = usable.data;
|
|
6753
6815
|
const networkPublicKey = base64Decode2(descriptor.publicEncryptionKey);
|
|
6754
6816
|
const result = encryptToNetwork(this.crypto, {
|
|
6755
|
-
|
|
6817
|
+
// Discovery returns the node's canonical network identifier. Persist
|
|
6818
|
+
// that spelling in the envelope so a later response can be compared
|
|
6819
|
+
// byte-for-byte (notably for checksummed did:pkh principals).
|
|
6820
|
+
networkId: descriptor.networkId,
|
|
6756
6821
|
networkPublicKey,
|
|
6757
6822
|
plaintext,
|
|
6758
6823
|
...options?.aad !== void 0 ? { aad: options.aad } : {},
|
|
@@ -7011,6 +7076,7 @@ var import_decrypt_transport_response_error3 = require("@tinycloud/sdk-services/
|
|
|
7011
7076
|
parseNetworkId,
|
|
7012
7077
|
parsePermissionHint,
|
|
7013
7078
|
parsePermissionHintFromErrorText,
|
|
7079
|
+
parseSecretCatalogKey,
|
|
7014
7080
|
permissionDeniedError,
|
|
7015
7081
|
resolveSecretListPrefix,
|
|
7016
7082
|
resolveSecretPath,
|