@tinycloud/sdk-core 2.2.0-beta.7 → 2.2.0-beta.9
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 +103 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +100 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -75,6 +75,7 @@ __export(index_exports, {
|
|
|
75
75
|
SpaceService: () => SpaceService,
|
|
76
76
|
TinyCloud: () => TinyCloud,
|
|
77
77
|
UnsupportedFeatureError: () => UnsupportedFeatureError,
|
|
78
|
+
VAULT_PERMISSION_SERVICE: () => VAULT_PERMISSION_SERVICE,
|
|
78
79
|
VaultHeaders: () => import_sdk_services4.VaultHeaders,
|
|
79
80
|
VaultPublicSpaceKVActions: () => import_sdk_services4.VaultPublicSpaceKVActions,
|
|
80
81
|
VersionCheckError: () => VersionCheckError,
|
|
@@ -93,6 +94,8 @@ __export(index_exports, {
|
|
|
93
94
|
defaultSpaceCreationHandler: () => defaultSpaceCreationHandler,
|
|
94
95
|
err: () => import_sdk_services4.err,
|
|
95
96
|
expandActionShortNames: () => expandActionShortNames,
|
|
97
|
+
expandPermissionEntries: () => expandPermissionEntries,
|
|
98
|
+
expandPermissionEntry: () => expandPermissionEntry,
|
|
96
99
|
fetchLocationRecord: () => fetchLocationRecord,
|
|
97
100
|
fetchPeerId: () => fetchPeerId,
|
|
98
101
|
httpUrlToMultiaddr: () => httpUrlToMultiaddr,
|
|
@@ -2797,6 +2800,7 @@ var ACCOUNT_REGISTRY_SPACE = "account";
|
|
|
2797
2800
|
var ACCOUNT_REGISTRY_PATH = "applications/";
|
|
2798
2801
|
var SECRETS_SPACE = "secrets";
|
|
2799
2802
|
var SECRET_NAME_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
2803
|
+
var VAULT_PERMISSION_SERVICE = "tinycloud.vault";
|
|
2800
2804
|
var SERVICE_SHORT_TO_LONG = Object.freeze({
|
|
2801
2805
|
kv: "tinycloud.kv",
|
|
2802
2806
|
sql: "tinycloud.sql",
|
|
@@ -2879,6 +2883,20 @@ function expandActionShortNames(service, actions) {
|
|
|
2879
2883
|
return `${service}/${a}`;
|
|
2880
2884
|
});
|
|
2881
2885
|
}
|
|
2886
|
+
function expandPermissionEntry(entry) {
|
|
2887
|
+
if (entry.service !== VAULT_PERMISSION_SERVICE) {
|
|
2888
|
+
return [
|
|
2889
|
+
{
|
|
2890
|
+
...entry,
|
|
2891
|
+
actions: expandActionShortNames(entry.service, entry.actions)
|
|
2892
|
+
}
|
|
2893
|
+
];
|
|
2894
|
+
}
|
|
2895
|
+
return expandVaultPermissionEntry(entry);
|
|
2896
|
+
}
|
|
2897
|
+
function expandPermissionEntries(entries) {
|
|
2898
|
+
return entries.flatMap(expandPermissionEntry);
|
|
2899
|
+
}
|
|
2882
2900
|
function applyPrefix(prefix, path, skipPrefix) {
|
|
2883
2901
|
if (skipPrefix) {
|
|
2884
2902
|
return path;
|
|
@@ -3006,6 +3024,16 @@ function validatePermissionEntry(p, path) {
|
|
|
3006
3024
|
`${path}.actions must be a non-empty array`
|
|
3007
3025
|
);
|
|
3008
3026
|
}
|
|
3027
|
+
for (const action of entry.actions) {
|
|
3028
|
+
if (typeof action !== "string" || action.length === 0) {
|
|
3029
|
+
throw new ManifestValidationError(
|
|
3030
|
+
`${path}.actions must contain non-empty strings`
|
|
3031
|
+
);
|
|
3032
|
+
}
|
|
3033
|
+
if (entry.service === VAULT_PERMISSION_SERVICE) {
|
|
3034
|
+
vaultActionExpansion(action);
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3009
3037
|
if (entry.expiry !== void 0) {
|
|
3010
3038
|
parseExpiry(entry.expiry);
|
|
3011
3039
|
}
|
|
@@ -3055,7 +3083,7 @@ function resolveManifest(input) {
|
|
|
3055
3083
|
...secretEntries
|
|
3056
3084
|
];
|
|
3057
3085
|
const resources = withCapabilitiesReadForSpaces(
|
|
3058
|
-
allEntries.
|
|
3086
|
+
allEntries.flatMap((entry) => resolveEntry(entry, prefix, expiryMs, space))
|
|
3059
3087
|
);
|
|
3060
3088
|
const additionalDelegates = manifest.did === void 0 ? [] : [
|
|
3061
3089
|
{
|
|
@@ -3167,19 +3195,85 @@ function resolveEntry(entry, prefix, _inheritedExpiryMs, inheritedSpace) {
|
|
|
3167
3195
|
entry.path,
|
|
3168
3196
|
entry.skipPrefix === true
|
|
3169
3197
|
);
|
|
3170
|
-
const resolvedActions = expandActionShortNames(entry.service, entry.actions);
|
|
3171
3198
|
const entryExpiryMs = entry.expiry !== void 0 ? parseExpiry(entry.expiry) : void 0;
|
|
3172
|
-
return {
|
|
3173
|
-
|
|
3199
|
+
return expandPermissionEntry({
|
|
3200
|
+
...entry,
|
|
3174
3201
|
space: entry.space ?? inheritedSpace,
|
|
3175
3202
|
path: resolvedPath,
|
|
3176
|
-
|
|
3203
|
+
skipPrefix: true
|
|
3204
|
+
}).map((expanded) => ({
|
|
3205
|
+
service: expanded.service,
|
|
3206
|
+
space: expanded.space ?? inheritedSpace,
|
|
3207
|
+
path: expanded.path,
|
|
3208
|
+
actions: expanded.actions,
|
|
3177
3209
|
// Only populate `expiryMs` when the entry had its own expiry override.
|
|
3178
3210
|
// When absent, callers use the parent (delegation or manifest) expiry
|
|
3179
3211
|
// which is carried on ResolvedDelegate.expiryMs / ResolvedCapabilities.expiryMs.
|
|
3180
3212
|
...entryExpiryMs !== void 0 ? { expiryMs: entryExpiryMs } : {},
|
|
3181
3213
|
...entry.description !== void 0 ? { description: entry.description } : {}
|
|
3182
|
-
};
|
|
3214
|
+
}));
|
|
3215
|
+
}
|
|
3216
|
+
function expandVaultPermissionEntry(entry) {
|
|
3217
|
+
const byBase = /* @__PURE__ */ new Map();
|
|
3218
|
+
for (const action of entry.actions) {
|
|
3219
|
+
const expansion = vaultActionExpansion(action);
|
|
3220
|
+
for (const base of expansion.bases) {
|
|
3221
|
+
const actions = byBase.get(base) ?? [];
|
|
3222
|
+
if (!actions.includes(expansion.action)) {
|
|
3223
|
+
actions.push(expansion.action);
|
|
3224
|
+
}
|
|
3225
|
+
byBase.set(base, actions);
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
return [...byBase.entries()].map(([base, actions]) => ({
|
|
3229
|
+
...entry,
|
|
3230
|
+
service: "tinycloud.kv",
|
|
3231
|
+
path: vaultKVPath(base, entry.path),
|
|
3232
|
+
actions,
|
|
3233
|
+
skipPrefix: true
|
|
3234
|
+
}));
|
|
3235
|
+
}
|
|
3236
|
+
function vaultActionExpansion(action) {
|
|
3237
|
+
const normalized = normalizeVaultAction(action);
|
|
3238
|
+
if (normalized === "read" || normalized === "get") {
|
|
3239
|
+
return { bases: ["keys", "vault"], action: "tinycloud.kv/get" };
|
|
3240
|
+
}
|
|
3241
|
+
if (normalized === "write" || normalized === "put") {
|
|
3242
|
+
return { bases: ["keys", "vault"], action: "tinycloud.kv/put" };
|
|
3243
|
+
}
|
|
3244
|
+
if (normalized === "delete" || normalized === "del") {
|
|
3245
|
+
return { bases: ["keys", "vault"], action: "tinycloud.kv/del" };
|
|
3246
|
+
}
|
|
3247
|
+
if (normalized === "list") {
|
|
3248
|
+
return { bases: ["vault"], action: "tinycloud.kv/list" };
|
|
3249
|
+
}
|
|
3250
|
+
if (normalized === "head") {
|
|
3251
|
+
return { bases: ["vault"], action: "tinycloud.kv/get" };
|
|
3252
|
+
}
|
|
3253
|
+
if (normalized === "metadata") {
|
|
3254
|
+
return { bases: ["vault"], action: "tinycloud.kv/metadata" };
|
|
3255
|
+
}
|
|
3256
|
+
throw new ManifestValidationError(
|
|
3257
|
+
`unknown vault action ${JSON.stringify(action)}; expected read, write, delete, get, put, del, list, head, or metadata`
|
|
3258
|
+
);
|
|
3259
|
+
}
|
|
3260
|
+
function normalizeVaultAction(action) {
|
|
3261
|
+
if (action.startsWith(`${VAULT_PERMISSION_SERVICE}/`)) {
|
|
3262
|
+
return action.slice(`${VAULT_PERMISSION_SERVICE}/`.length);
|
|
3263
|
+
}
|
|
3264
|
+
if (action.startsWith("tinycloud.kv/")) {
|
|
3265
|
+
return action.slice("tinycloud.kv/".length);
|
|
3266
|
+
}
|
|
3267
|
+
if (action.includes("/")) {
|
|
3268
|
+
throw new ManifestValidationError(
|
|
3269
|
+
`unknown vault action ${JSON.stringify(action)}; expected a tinycloud.vault or tinycloud.kv action`
|
|
3270
|
+
);
|
|
3271
|
+
}
|
|
3272
|
+
return action;
|
|
3273
|
+
}
|
|
3274
|
+
function vaultKVPath(base, path) {
|
|
3275
|
+
const normalized = path.startsWith("/") ? path.slice(1) : path;
|
|
3276
|
+
return `${base}/${normalized}`;
|
|
3183
3277
|
}
|
|
3184
3278
|
function cloneResourceCapability(entry) {
|
|
3185
3279
|
return {
|
|
@@ -5049,6 +5143,7 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5049
5143
|
SpaceService,
|
|
5050
5144
|
TinyCloud,
|
|
5051
5145
|
UnsupportedFeatureError,
|
|
5146
|
+
VAULT_PERMISSION_SERVICE,
|
|
5052
5147
|
VaultHeaders,
|
|
5053
5148
|
VaultPublicSpaceKVActions,
|
|
5054
5149
|
VersionCheckError,
|
|
@@ -5067,6 +5162,8 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5067
5162
|
defaultSpaceCreationHandler,
|
|
5068
5163
|
err,
|
|
5069
5164
|
expandActionShortNames,
|
|
5165
|
+
expandPermissionEntries,
|
|
5166
|
+
expandPermissionEntry,
|
|
5070
5167
|
fetchLocationRecord,
|
|
5071
5168
|
fetchPeerId,
|
|
5072
5169
|
httpUrlToMultiaddr,
|