@naylence/runtime 0.3.5-test.6 → 0.3.5-test.8
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/browser/index.cjs +430 -6
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.mjs +431 -7
- package/dist/browser/index.mjs.map +1 -1
- package/dist/cjs/naylence/fame/storage/storage-profile-factory.js +23 -4
- package/dist/cjs/naylence/fame/storage/storage-profile-factory.js.map +1 -1
- package/dist/esm/naylence/fame/storage/storage-profile-factory.js +22 -4
- package/dist/esm/naylence/fame/storage/storage-profile-factory.js.map +1 -1
- package/dist/node/index.cjs +430 -6
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +431 -7
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.cjs +263 -6
- package/dist/node/node.cjs.map +1 -1
- package/dist/node/node.mjs +264 -7
- package/dist/node/node.mjs.map +1 -1
- package/dist/types/naylence/fame/storage/storage-profile-factory.d.ts +1 -0
- package/dist/types/naylence/fame/storage/storage-profile-factory.d.ts.map +1 -1
- package/package.json +7 -2
package/dist/browser/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@naylence/core');
|
|
4
|
+
var zod = require('zod');
|
|
4
5
|
var factory = require('@naylence/factory');
|
|
5
6
|
var fs = require('fs');
|
|
6
|
-
var zod = require('zod');
|
|
7
7
|
var yaml = require('yaml');
|
|
8
8
|
var sha2_js = require('@noble/hashes/sha2.js');
|
|
9
9
|
var utils_js = require('@noble/hashes/utils.js');
|
|
@@ -847,7 +847,7 @@ function coerceNumber(value) {
|
|
|
847
847
|
}
|
|
848
848
|
return undefined;
|
|
849
849
|
}
|
|
850
|
-
function coerceBoolean(value) {
|
|
850
|
+
function coerceBoolean$1(value) {
|
|
851
851
|
if (typeof value === 'boolean') {
|
|
852
852
|
return value;
|
|
853
853
|
}
|
|
@@ -871,7 +871,7 @@ function normalizeTaskSpawnerConfig(config = {}) {
|
|
|
871
871
|
0;
|
|
872
872
|
const defaultTimeout = coerceNumber(firstDefined(source, ['defaultTimeout', 'default_timeout'])) ??
|
|
873
873
|
0;
|
|
874
|
-
const autoCleanup = coerceBoolean(firstDefined(source, ['autoCleanup', 'auto_cleanup'])) ??
|
|
874
|
+
const autoCleanup = coerceBoolean$1(firstDefined(source, ['autoCleanup', 'auto_cleanup'])) ??
|
|
875
875
|
true;
|
|
876
876
|
return {
|
|
877
877
|
maxConcurrent,
|
|
@@ -894,7 +894,7 @@ function normalizeSpawnOptions(options = {}) {
|
|
|
894
894
|
function normalizeShutdownOptions(options = {}) {
|
|
895
895
|
const source = options;
|
|
896
896
|
const gracePeriod = coerceNumber(firstDefined(source, ['gracePeriod', 'grace_period'])) ?? 2000;
|
|
897
|
-
const cancelHanging = coerceBoolean(firstDefined(source, ['cancelHanging', 'cancel_hanging'])) ??
|
|
897
|
+
const cancelHanging = coerceBoolean$1(firstDefined(source, ['cancelHanging', 'cancel_hanging'])) ??
|
|
898
898
|
true;
|
|
899
899
|
const joinTimeout = coerceNumber(firstDefined(source, ['joinTimeout', 'join_timeout'])) ?? 1000;
|
|
900
900
|
return {
|
|
@@ -2946,6 +2946,211 @@ class StorageProviderFactory extends factory.AbstractResourceFactory {
|
|
|
2946
2946
|
return instance;
|
|
2947
2947
|
}
|
|
2948
2948
|
}
|
|
2949
|
+
function registerStorageProviderFactory(type, factory$1) {
|
|
2950
|
+
factory.registerFactory(STORAGE_PROVIDER_FACTORY_BASE_TYPE, type, factory$1);
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
const inMemoryStorageProviderConfigSchema = zod.z
|
|
2954
|
+
.object({
|
|
2955
|
+
type: zod.z
|
|
2956
|
+
.literal('InMemoryStorageProvider')
|
|
2957
|
+
.default('InMemoryStorageProvider'),
|
|
2958
|
+
})
|
|
2959
|
+
.passthrough();
|
|
2960
|
+
class InMemoryStorageProviderFactory extends StorageProviderFactory {
|
|
2961
|
+
constructor() {
|
|
2962
|
+
super(...arguments);
|
|
2963
|
+
this.type = 'InMemoryStorageProvider';
|
|
2964
|
+
}
|
|
2965
|
+
async create(config) {
|
|
2966
|
+
// Validate configuration and ensure correct type information
|
|
2967
|
+
const candidate = config ?? { type: 'InMemoryStorageProvider' };
|
|
2968
|
+
inMemoryStorageProviderConfigSchema.parse({
|
|
2969
|
+
type: candidate.type,
|
|
2970
|
+
...candidate,
|
|
2971
|
+
});
|
|
2972
|
+
return new InMemoryStorageProvider();
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
registerStorageProviderFactory('InMemoryStorageProvider', InMemoryStorageProviderFactory);
|
|
2976
|
+
|
|
2977
|
+
const CREDENTIAL_PROVIDER_FACTORY_BASE_TYPE = 'CredentialProviderFactory';
|
|
2978
|
+
class CredentialProviderFactory extends factory.AbstractResourceFactory {
|
|
2979
|
+
static async createCredentialProvider(config, options = {}) {
|
|
2980
|
+
const instance = config
|
|
2981
|
+
? await factory.createResource(CREDENTIAL_PROVIDER_FACTORY_BASE_TYPE, config, options)
|
|
2982
|
+
: await factory.createDefaultResource(CREDENTIAL_PROVIDER_FACTORY_BASE_TYPE, null, options);
|
|
2983
|
+
if (!instance) {
|
|
2984
|
+
throw new Error('Failed to create credential provider from configuration');
|
|
2985
|
+
}
|
|
2986
|
+
return instance;
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
function normalizeEnvConfig(config) {
|
|
2991
|
+
if (!config) {
|
|
2992
|
+
return {
|
|
2993
|
+
type: 'EnvCredentialProvider',
|
|
2994
|
+
varName: 'DEFAULT_VAR',
|
|
2995
|
+
};
|
|
2996
|
+
}
|
|
2997
|
+
if ('varName' in config &&
|
|
2998
|
+
typeof config.varName === 'string' &&
|
|
2999
|
+
config.varName.length > 0) {
|
|
3000
|
+
return {
|
|
3001
|
+
type: 'EnvCredentialProvider',
|
|
3002
|
+
varName: config.varName,
|
|
3003
|
+
};
|
|
3004
|
+
}
|
|
3005
|
+
const rawName = config.varName ??
|
|
3006
|
+
config.var_name;
|
|
3007
|
+
if (typeof rawName !== 'string' || rawName.length === 0) {
|
|
3008
|
+
throw new Error('EnvCredentialProvider requires a non-empty "varName"');
|
|
3009
|
+
}
|
|
3010
|
+
return {
|
|
3011
|
+
type: 'EnvCredentialProvider',
|
|
3012
|
+
varName: rawName,
|
|
3013
|
+
};
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
function normalizePromptConfig(config) {
|
|
3017
|
+
if (!config) {
|
|
3018
|
+
return {
|
|
3019
|
+
type: 'PromptCredentialProvider',
|
|
3020
|
+
credentialName: 'credential',
|
|
3021
|
+
};
|
|
3022
|
+
}
|
|
3023
|
+
const credentialName = config.credentialName ??
|
|
3024
|
+
config.credential_name ??
|
|
3025
|
+
'credential';
|
|
3026
|
+
if (typeof credentialName !== 'string' || credentialName.length === 0) {
|
|
3027
|
+
throw new Error('PromptCredentialProvider requires a non-empty "credentialName"');
|
|
3028
|
+
}
|
|
3029
|
+
return {
|
|
3030
|
+
type: 'PromptCredentialProvider',
|
|
3031
|
+
credentialName,
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
function normalizeSecretStoreConfig(config) {
|
|
3036
|
+
if (!config) {
|
|
3037
|
+
return {
|
|
3038
|
+
type: 'SecretStoreCredentialProvider',
|
|
3039
|
+
secretName: 'default',
|
|
3040
|
+
};
|
|
3041
|
+
}
|
|
3042
|
+
if ('secretName' in config &&
|
|
3043
|
+
typeof config.secretName === 'string' &&
|
|
3044
|
+
config.secretName.length > 0) {
|
|
3045
|
+
return {
|
|
3046
|
+
type: 'SecretStoreCredentialProvider',
|
|
3047
|
+
secretName: config.secretName,
|
|
3048
|
+
};
|
|
3049
|
+
}
|
|
3050
|
+
const rawName = config.secretName ??
|
|
3051
|
+
config.secret_name;
|
|
3052
|
+
if (typeof rawName !== 'string' || rawName.length === 0) {
|
|
3053
|
+
throw new Error('SecretStoreCredentialProvider requires a non-empty "secretName"');
|
|
3054
|
+
}
|
|
3055
|
+
return {
|
|
3056
|
+
type: 'SecretStoreCredentialProvider',
|
|
3057
|
+
secretName: rawName,
|
|
3058
|
+
};
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3061
|
+
function normalizeStaticConfig(config) {
|
|
3062
|
+
if (!config) {
|
|
3063
|
+
return {
|
|
3064
|
+
type: 'StaticCredentialProvider',
|
|
3065
|
+
credentialValue: '',
|
|
3066
|
+
};
|
|
3067
|
+
}
|
|
3068
|
+
if ('credentialValue' in config &&
|
|
3069
|
+
typeof config.credentialValue === 'string') {
|
|
3070
|
+
return {
|
|
3071
|
+
type: 'StaticCredentialProvider',
|
|
3072
|
+
credentialValue: config.credentialValue,
|
|
3073
|
+
};
|
|
3074
|
+
}
|
|
3075
|
+
const rawValue = config.credentialValue ??
|
|
3076
|
+
config.credential_value;
|
|
3077
|
+
if (typeof rawValue !== 'string') {
|
|
3078
|
+
throw new Error('StaticCredentialProvider requires a "credentialValue" string');
|
|
3079
|
+
}
|
|
3080
|
+
return {
|
|
3081
|
+
type: 'StaticCredentialProvider',
|
|
3082
|
+
credentialValue: rawValue,
|
|
3083
|
+
};
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
function isCredentialProviderConfig(value) {
|
|
3087
|
+
return Boolean(value &&
|
|
3088
|
+
typeof value === 'object' &&
|
|
3089
|
+
'type' in value);
|
|
3090
|
+
}
|
|
3091
|
+
class SecretSource {
|
|
3092
|
+
static normalize(value) {
|
|
3093
|
+
if (value === null || value === undefined) {
|
|
3094
|
+
throw new TypeError('Secret source cannot be null or undefined');
|
|
3095
|
+
}
|
|
3096
|
+
if (isCredentialProviderConfig(value)) {
|
|
3097
|
+
switch (value.type) {
|
|
3098
|
+
case 'EnvCredentialProvider':
|
|
3099
|
+
return normalizeEnvConfig(value);
|
|
3100
|
+
case 'SecretStoreCredentialProvider':
|
|
3101
|
+
return normalizeSecretStoreConfig(value);
|
|
3102
|
+
case 'StaticCredentialProvider':
|
|
3103
|
+
return normalizeStaticConfig(value);
|
|
3104
|
+
case 'PromptCredentialProvider':
|
|
3105
|
+
return normalizePromptConfig(value);
|
|
3106
|
+
default:
|
|
3107
|
+
return { ...value };
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
if (typeof value === 'string') {
|
|
3111
|
+
if (value.startsWith('env://')) {
|
|
3112
|
+
const varName = value.slice('env://'.length);
|
|
3113
|
+
if (!varName) {
|
|
3114
|
+
throw new Error("Environment variable name cannot be empty in 'env://' URI");
|
|
3115
|
+
}
|
|
3116
|
+
return normalizeEnvConfig({ type: 'EnvCredentialProvider', varName });
|
|
3117
|
+
}
|
|
3118
|
+
if (value.startsWith('secret://')) {
|
|
3119
|
+
const secretName = value.slice('secret://'.length);
|
|
3120
|
+
if (!secretName) {
|
|
3121
|
+
throw new Error("Secret name cannot be empty in 'secret://' URI");
|
|
3122
|
+
}
|
|
3123
|
+
return normalizeSecretStoreConfig({
|
|
3124
|
+
type: 'SecretStoreCredentialProvider',
|
|
3125
|
+
secretName,
|
|
3126
|
+
});
|
|
3127
|
+
}
|
|
3128
|
+
return normalizeStaticConfig({
|
|
3129
|
+
type: 'StaticCredentialProvider',
|
|
3130
|
+
credentialValue: value,
|
|
3131
|
+
});
|
|
3132
|
+
}
|
|
3133
|
+
if (typeof value === 'object') {
|
|
3134
|
+
const recordValue = value;
|
|
3135
|
+
if (!('type' in recordValue) || typeof recordValue.type !== 'string') {
|
|
3136
|
+
throw new TypeError("Secret source dict inputs must include a string 'type' field");
|
|
3137
|
+
}
|
|
3138
|
+
switch (recordValue.type) {
|
|
3139
|
+
case 'EnvCredentialProvider':
|
|
3140
|
+
return normalizeEnvConfig(recordValue);
|
|
3141
|
+
case 'SecretStoreCredentialProvider':
|
|
3142
|
+
return normalizeSecretStoreConfig(recordValue);
|
|
3143
|
+
case 'StaticCredentialProvider':
|
|
3144
|
+
return normalizeStaticConfig(recordValue);
|
|
3145
|
+
case 'PromptCredentialProvider':
|
|
3146
|
+
return normalizePromptConfig(recordValue);
|
|
3147
|
+
default:
|
|
3148
|
+
return { ...recordValue };
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
throw new TypeError(`Unsupported secret source type: ${typeof value}. Expected string, dict with 'type' field, or CredentialProviderConfig instance.`);
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
2949
3154
|
|
|
2950
3155
|
function isModuleNotFoundError(error) {
|
|
2951
3156
|
if (!(error instanceof Error)) {
|
|
@@ -2967,8 +3172,9 @@ function isModuleNotFoundError(error) {
|
|
|
2967
3172
|
* Wraps a dynamic import loader and enriches "module not found" failures with an actionable error message.
|
|
2968
3173
|
*/
|
|
2969
3174
|
async function safeImport(loader, dependencyNameOrOptions, maybeOptions) {
|
|
2970
|
-
const options =
|
|
2971
|
-
|
|
3175
|
+
const options = typeof dependencyNameOrOptions === 'string'
|
|
3176
|
+
? { dependencyName: dependencyNameOrOptions, ...(maybeOptions ?? {}) }
|
|
3177
|
+
: dependencyNameOrOptions;
|
|
2972
3178
|
const dependencyName = options.dependencyName;
|
|
2973
3179
|
try {
|
|
2974
3180
|
return await loader();
|
|
@@ -2990,6 +3196,219 @@ async function safeImport(loader, dependencyNameOrOptions, maybeOptions) {
|
|
|
2990
3196
|
}
|
|
2991
3197
|
}
|
|
2992
3198
|
|
|
3199
|
+
const indexedDBConfigSchema = zod.z
|
|
3200
|
+
.object({
|
|
3201
|
+
type: zod.z
|
|
3202
|
+
.literal('IndexedDBStorageProvider')
|
|
3203
|
+
.default('IndexedDBStorageProvider'),
|
|
3204
|
+
mode: zod.z
|
|
3205
|
+
.union([zod.z.literal('dx'), zod.z.literal('hardened'), zod.z.string()])
|
|
3206
|
+
.optional()
|
|
3207
|
+
.default('dx'),
|
|
3208
|
+
dbName: zod.z.string().min(1).default('naylence'),
|
|
3209
|
+
version: zod.z.union([zod.z.number().int().positive(), zod.z.string()]).default(1),
|
|
3210
|
+
namespacePrefix: zod.z.string().optional().default('kv'),
|
|
3211
|
+
enableCaching: zod.z.union([zod.z.boolean(), zod.z.string()]).optional(),
|
|
3212
|
+
isEncrypted: zod.z.union([zod.z.boolean(), zod.z.string()]).optional(),
|
|
3213
|
+
masterKey: zod.z
|
|
3214
|
+
.union([zod.z.string(), zod.z.record(zod.z.string(), zod.z.unknown()), zod.z.null()])
|
|
3215
|
+
.optional()
|
|
3216
|
+
.default(null),
|
|
3217
|
+
})
|
|
3218
|
+
.passthrough();
|
|
3219
|
+
const TRUE_VALUES = new Set(['true', '1', 'yes', 'on']);
|
|
3220
|
+
const FALSE_VALUES = new Set(['false', '0', 'no', 'off', '']);
|
|
3221
|
+
function coerceBoolean(value, fieldName, defaultValue) {
|
|
3222
|
+
if (value === undefined) {
|
|
3223
|
+
return defaultValue;
|
|
3224
|
+
}
|
|
3225
|
+
if (typeof value === 'boolean') {
|
|
3226
|
+
return value;
|
|
3227
|
+
}
|
|
3228
|
+
if (typeof value === 'string') {
|
|
3229
|
+
const normalized = value.trim().toLowerCase();
|
|
3230
|
+
if (TRUE_VALUES.has(normalized)) {
|
|
3231
|
+
return true;
|
|
3232
|
+
}
|
|
3233
|
+
if (FALSE_VALUES.has(normalized)) {
|
|
3234
|
+
return false;
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
throw new Error(`Expected a boolean-like value for '${fieldName}' but received '${String(value)}'`);
|
|
3238
|
+
}
|
|
3239
|
+
function normalizeIndexedDBConfig(config) {
|
|
3240
|
+
const candidate = {
|
|
3241
|
+
...config,
|
|
3242
|
+
};
|
|
3243
|
+
if (candidate.dbName === undefined && typeof candidate.db_name === 'string') {
|
|
3244
|
+
candidate.dbName = candidate.db_name;
|
|
3245
|
+
}
|
|
3246
|
+
if (candidate.namespacePrefix === undefined &&
|
|
3247
|
+
typeof candidate.namespace_prefix === 'string') {
|
|
3248
|
+
candidate.namespacePrefix = candidate.namespace_prefix;
|
|
3249
|
+
}
|
|
3250
|
+
if (candidate.enableCaching === undefined &&
|
|
3251
|
+
candidate.enable_caching !== undefined) {
|
|
3252
|
+
candidate.enableCaching = candidate.enable_caching;
|
|
3253
|
+
}
|
|
3254
|
+
if (candidate.isEncrypted === undefined &&
|
|
3255
|
+
candidate.is_encrypted !== undefined) {
|
|
3256
|
+
candidate.isEncrypted = candidate.is_encrypted;
|
|
3257
|
+
}
|
|
3258
|
+
if (candidate.masterKey === undefined && candidate.master_key !== undefined) {
|
|
3259
|
+
candidate.masterKey = candidate.master_key;
|
|
3260
|
+
}
|
|
3261
|
+
const parsed = indexedDBConfigSchema.parse({
|
|
3262
|
+
...candidate,
|
|
3263
|
+
type: 'IndexedDBStorageProvider',
|
|
3264
|
+
});
|
|
3265
|
+
const normalizedMode = (typeof parsed.mode === 'string' ? parsed.mode : 'dx').toLowerCase();
|
|
3266
|
+
if (normalizedMode !== 'dx' && normalizedMode !== 'hardened') {
|
|
3267
|
+
throw new Error("mode must be either 'dx' or 'hardened'");
|
|
3268
|
+
}
|
|
3269
|
+
const versionValue = typeof parsed.version === 'string'
|
|
3270
|
+
? parseInt(parsed.version, 10)
|
|
3271
|
+
: parsed.version;
|
|
3272
|
+
if (!Number.isInteger(versionValue) || versionValue <= 0) {
|
|
3273
|
+
throw new Error('version must be a positive integer');
|
|
3274
|
+
}
|
|
3275
|
+
const enableCaching = coerceBoolean(parsed.enableCaching, 'enableCaching', normalizedMode === 'dx');
|
|
3276
|
+
const isEncrypted = coerceBoolean(parsed.isEncrypted, 'isEncrypted', true);
|
|
3277
|
+
let masterKeyConfig = null;
|
|
3278
|
+
if (parsed.masterKey !== null && parsed.masterKey !== undefined) {
|
|
3279
|
+
masterKeyConfig = SecretSource.normalize(parsed.masterKey);
|
|
3280
|
+
}
|
|
3281
|
+
if (normalizedMode === 'hardened' && !masterKeyConfig) {
|
|
3282
|
+
throw new Error('hardened mode requires a masterKey configuration');
|
|
3283
|
+
}
|
|
3284
|
+
return {
|
|
3285
|
+
type: 'IndexedDBStorageProvider',
|
|
3286
|
+
mode: normalizedMode,
|
|
3287
|
+
dbName: parsed.dbName,
|
|
3288
|
+
version: versionValue,
|
|
3289
|
+
namespacePrefix: parsed.namespacePrefix ?? 'kv',
|
|
3290
|
+
enableCaching,
|
|
3291
|
+
isEncrypted,
|
|
3292
|
+
masterKey: masterKeyConfig,
|
|
3293
|
+
};
|
|
3294
|
+
}
|
|
3295
|
+
class IndexedDBStorageProviderFactory extends StorageProviderFactory {
|
|
3296
|
+
constructor() {
|
|
3297
|
+
super(...arguments);
|
|
3298
|
+
this.type = 'IndexedDBStorageProvider';
|
|
3299
|
+
this.isDefault = true;
|
|
3300
|
+
this.priority = 50;
|
|
3301
|
+
}
|
|
3302
|
+
async create(config) {
|
|
3303
|
+
const normalized = normalizeIndexedDBConfig(config);
|
|
3304
|
+
const { IndexedDBStorageProvider } = await getIndexedDbStorageProviderModule();
|
|
3305
|
+
let masterKeyProvider = null;
|
|
3306
|
+
if (normalized.masterKey) {
|
|
3307
|
+
masterKeyProvider =
|
|
3308
|
+
await CredentialProviderFactory.createCredentialProvider(normalized.masterKey);
|
|
3309
|
+
}
|
|
3310
|
+
return new IndexedDBStorageProvider({
|
|
3311
|
+
mode: normalized.mode,
|
|
3312
|
+
dbName: normalized.dbName,
|
|
3313
|
+
version: normalized.version,
|
|
3314
|
+
namespacePrefix: normalized.namespacePrefix,
|
|
3315
|
+
enableCaching: normalized.enableCaching,
|
|
3316
|
+
isEncrypted: normalized.isEncrypted,
|
|
3317
|
+
masterKeyProvider,
|
|
3318
|
+
});
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
let indexedDbStorageProviderModulePromise = null;
|
|
3322
|
+
function getIndexedDbStorageProviderModule() {
|
|
3323
|
+
if (!indexedDbStorageProviderModulePromise) {
|
|
3324
|
+
indexedDbStorageProviderModulePromise = safeImport(() => Promise.resolve().then(function () { return indexeddbStorageProvider; }), 'IndexedDBStorageProvider', {
|
|
3325
|
+
helpMessage: 'Failed to load the IndexedDB storage provider. Ensure IndexedDB is available or install the required polyfills.',
|
|
3326
|
+
});
|
|
3327
|
+
}
|
|
3328
|
+
return indexedDbStorageProviderModulePromise;
|
|
3329
|
+
}
|
|
3330
|
+
registerStorageProviderFactory('IndexedDBStorageProvider', IndexedDBStorageProviderFactory);
|
|
3331
|
+
|
|
3332
|
+
const ENV_VAR_STORAGE_DB_DIRECTORY = 'FAME_STORAGE_DB_DIRECTORY';
|
|
3333
|
+
const ENV_VAR_STORAGE_MASTER_KEY = 'FAME_STORAGE_MASTER_KEY';
|
|
3334
|
+
const ENV_VAR_STORAGE_ENCRYPTED = 'FAME_STORAGE_ENCRYPTED';
|
|
3335
|
+
const PROFILE_NAME_MEMORY = 'memory';
|
|
3336
|
+
const PROFILE_NAME_INDEXEDDB = 'indexeddb';
|
|
3337
|
+
const PROFILE_NAME_SQLITE = 'sqlite';
|
|
3338
|
+
const PROFILE_NAME_ENCRYPTED_SQLITE = 'encrypted-sqlite';
|
|
3339
|
+
const storageProfileSchema = zod.z
|
|
3340
|
+
.object({
|
|
3341
|
+
type: zod.z.literal('StorageProfile').default('StorageProfile'),
|
|
3342
|
+
profile: zod.z
|
|
3343
|
+
.string()
|
|
3344
|
+
.optional()
|
|
3345
|
+
.describe('Storage profile name (memory | indexeddb | sqlite | encrypted-sqlite)'),
|
|
3346
|
+
})
|
|
3347
|
+
.passthrough();
|
|
3348
|
+
const MEMORY_PROFILE_CONFIG = {
|
|
3349
|
+
type: 'InMemoryStorageProvider',
|
|
3350
|
+
};
|
|
3351
|
+
const INDEXEDDB_PROFILE_CONFIG = {
|
|
3352
|
+
type: 'IndexedDBStorageProvider',
|
|
3353
|
+
};
|
|
3354
|
+
const SQLITE_PROFILE_CONFIG = {
|
|
3355
|
+
type: 'SQLiteStorageProvider',
|
|
3356
|
+
dbDirectory: factory.Expressions.env(ENV_VAR_STORAGE_DB_DIRECTORY, './data/sqlite'),
|
|
3357
|
+
isEncrypted: factory.Expressions.env(ENV_VAR_STORAGE_ENCRYPTED, 'false'),
|
|
3358
|
+
masterKey: factory.Expressions.env(ENV_VAR_STORAGE_MASTER_KEY, ''),
|
|
3359
|
+
isCached: true,
|
|
3360
|
+
};
|
|
3361
|
+
const ENCRYPTED_SQLITE_PROFILE_CONFIG = {
|
|
3362
|
+
type: 'SQLiteStorageProvider',
|
|
3363
|
+
dbDirectory: factory.Expressions.env(ENV_VAR_STORAGE_DB_DIRECTORY, './data/sqlite'),
|
|
3364
|
+
isEncrypted: 'true',
|
|
3365
|
+
masterKey: factory.Expressions.env(ENV_VAR_STORAGE_MASTER_KEY),
|
|
3366
|
+
isCached: true,
|
|
3367
|
+
};
|
|
3368
|
+
// Base profile map with browser-safe options
|
|
3369
|
+
const BASE_PROFILE_MAP = {
|
|
3370
|
+
[PROFILE_NAME_MEMORY]: MEMORY_PROFILE_CONFIG,
|
|
3371
|
+
[PROFILE_NAME_INDEXEDDB]: INDEXEDDB_PROFILE_CONFIG,
|
|
3372
|
+
};
|
|
3373
|
+
// Extended profile map - can be augmented by Node.js environment
|
|
3374
|
+
const PROFILE_MAP$1 = {
|
|
3375
|
+
...BASE_PROFILE_MAP,
|
|
3376
|
+
};
|
|
3377
|
+
// Register SQLite profiles if we're in Node.js environment
|
|
3378
|
+
// This check allows the code to work in both browser and Node.js
|
|
3379
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
3380
|
+
PROFILE_MAP$1[PROFILE_NAME_SQLITE] = SQLITE_PROFILE_CONFIG;
|
|
3381
|
+
PROFILE_MAP$1[PROFILE_NAME_ENCRYPTED_SQLITE] = ENCRYPTED_SQLITE_PROFILE_CONFIG;
|
|
3382
|
+
}
|
|
3383
|
+
class StorageProfileFactory extends StorageProviderFactory {
|
|
3384
|
+
constructor() {
|
|
3385
|
+
super(...arguments);
|
|
3386
|
+
this.type = 'StorageProfile';
|
|
3387
|
+
}
|
|
3388
|
+
async create(config, options) {
|
|
3389
|
+
const candidate = config ?? { type: 'StorageProfile' };
|
|
3390
|
+
const parsed = storageProfileSchema.parse({
|
|
3391
|
+
...candidate,
|
|
3392
|
+
type: 'StorageProfile',
|
|
3393
|
+
});
|
|
3394
|
+
const profileName = (parsed.profile ?? PROFILE_NAME_MEMORY).toLowerCase();
|
|
3395
|
+
const profileConfig = PROFILE_MAP$1[profileName];
|
|
3396
|
+
if (!profileConfig) {
|
|
3397
|
+
throw new Error(`Unknown storage profile '${profileName}'. Supported profiles: ${Object.keys(PROFILE_MAP$1).join(', ')}`);
|
|
3398
|
+
}
|
|
3399
|
+
const createOptions = {
|
|
3400
|
+
...options,
|
|
3401
|
+
validate: options?.validate ?? true,
|
|
3402
|
+
};
|
|
3403
|
+
const provider = await factory.createResource(STORAGE_PROVIDER_FACTORY_BASE_TYPE, profileConfig, createOptions);
|
|
3404
|
+
if (!provider) {
|
|
3405
|
+
throw new Error(`Failed to create storage provider for profile '${profileName}'`);
|
|
3406
|
+
}
|
|
3407
|
+
return provider;
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
registerStorageProviderFactory('StorageProfile', StorageProfileFactory);
|
|
3411
|
+
|
|
2993
3412
|
const DEFAULT_DB_NAME$3 = 'naylence-secrets';
|
|
2994
3413
|
const DEFAULT_STORE_NAME$1 = 'auto-master-key';
|
|
2995
3414
|
const DEFAULT_KEY_ID$2 = 'master';
|
|
@@ -3738,6 +4157,11 @@ class IndexedDBStorageProvider extends EncryptedStorageProviderBase {
|
|
|
3738
4157
|
}
|
|
3739
4158
|
IndexedDBStorageProvider.supportedModes = new Set(['dx', 'hardened']);
|
|
3740
4159
|
|
|
4160
|
+
var indexeddbStorageProvider = /*#__PURE__*/Object.freeze({
|
|
4161
|
+
__proto__: null,
|
|
4162
|
+
IndexedDBStorageProvider: IndexedDBStorageProvider
|
|
4163
|
+
});
|
|
4164
|
+
|
|
3741
4165
|
const globalScope$1 = globalThis;
|
|
3742
4166
|
const nodeStack = globalScope$1.__naylenceNodeStack__ ?? (globalScope$1.__naylenceNodeStack__ = []);
|
|
3743
4167
|
function getCurrentNode() {
|