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