@openfeature/server-sdk 1.20.1 → 1.21.0
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/README.md +74 -52
- package/dist/cjs/index.js +88 -266
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +77 -246
- package/dist/esm/index.js.map +4 -4
- package/dist/types.d.ts +190 -145
- package/package.json +5 -4
package/dist/cjs/index.js
CHANGED
|
@@ -58,11 +58,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
58
58
|
// src/index.ts
|
|
59
59
|
var index_exports = {};
|
|
60
60
|
__export(index_exports, {
|
|
61
|
-
AggregateError: () => AggregateError,
|
|
62
61
|
AsyncLocalStorageTransactionContextPropagator: () => AsyncLocalStorageTransactionContextPropagator,
|
|
63
|
-
BaseEvaluationStrategy: () => BaseEvaluationStrategy,
|
|
64
62
|
ComparisonStrategy: () => ComparisonStrategy,
|
|
65
|
-
ErrorWithCode: () => ErrorWithCode,
|
|
66
63
|
FirstMatchStrategy: () => FirstMatchStrategy,
|
|
67
64
|
FirstSuccessfulStrategy: () => FirstSuccessfulStrategy,
|
|
68
65
|
InMemoryProvider: () => InMemoryProvider,
|
|
@@ -74,8 +71,7 @@ __export(index_exports, {
|
|
|
74
71
|
OpenFeatureEventEmitter: () => OpenFeatureEventEmitter,
|
|
75
72
|
ProviderEvents: () => import_core6.ServerProviderEvents,
|
|
76
73
|
ProviderStatus: () => import_core.ServerProviderStatus,
|
|
77
|
-
|
|
78
|
-
throwAggregateErrorFromPromiseResults: () => throwAggregateErrorFromPromiseResults
|
|
74
|
+
TypedInMemoryProvider: () => TypedInMemoryProvider
|
|
79
75
|
});
|
|
80
76
|
module.exports = __toCommonJS(index_exports);
|
|
81
77
|
|
|
@@ -202,14 +198,65 @@ var InMemoryProvider = class {
|
|
|
202
198
|
});
|
|
203
199
|
}
|
|
204
200
|
};
|
|
201
|
+
var TypedInMemoryProvider = class extends InMemoryProvider {
|
|
202
|
+
constructor(flagConfiguration = {}) {
|
|
203
|
+
super(flagConfiguration);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Overwrites the configured flags.
|
|
207
|
+
* @param { FlagConfiguration } flagConfiguration new flag configuration
|
|
208
|
+
* @example
|
|
209
|
+
* ```
|
|
210
|
+
* provider.putConfiguration({
|
|
211
|
+
* 'my-flag': {
|
|
212
|
+
* variants: { on: true, off: false },
|
|
213
|
+
* defaultVariant: 'on',
|
|
214
|
+
* contextEvaluator: (ctx) => ctx?.user?.id === '123' ? 'on' : 'off',
|
|
215
|
+
* disabled: false,
|
|
216
|
+
* },
|
|
217
|
+
* });
|
|
218
|
+
*
|
|
219
|
+
* const flags = {
|
|
220
|
+
* 'my-flag': {
|
|
221
|
+
* variants: { on: true, off: false },
|
|
222
|
+
* defaultVariant: 'on',
|
|
223
|
+
* contextEvaluator: (ctx) => ctx?.user?.id === '123' ? 'on' : 'off',
|
|
224
|
+
* disabled: false,
|
|
225
|
+
* },
|
|
226
|
+
* } as const; // 'as const' needed to preserve the `defaultVariant` narrow literal type rather than `string`
|
|
227
|
+
* provider.putConfiguration(flags);
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
putConfiguration(flagConfiguration) {
|
|
231
|
+
super.putConfiguration(flagConfiguration);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
205
234
|
|
|
206
235
|
// src/provider/multi-provider/multi-provider.ts
|
|
207
|
-
var
|
|
236
|
+
var import_core7 = require("@openfeature/core");
|
|
208
237
|
|
|
209
|
-
// src/
|
|
238
|
+
// src/provider/multi-provider/strategies.ts
|
|
210
239
|
var import_core4 = require("@openfeature/core");
|
|
240
|
+
var FirstMatchStrategy = class extends import_core4.BaseFirstMatchStrategy {
|
|
241
|
+
constructor() {
|
|
242
|
+
super(import_core.ServerProviderStatus);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
var FirstSuccessfulStrategy = class extends import_core4.BaseFirstSuccessfulStrategy {
|
|
246
|
+
constructor() {
|
|
247
|
+
super(import_core.ServerProviderStatus);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
var ComparisonStrategy = class extends import_core4.BaseComparisonStrategy {
|
|
251
|
+
constructor(fallbackProvider, onMismatch) {
|
|
252
|
+
super(import_core.ServerProviderStatus, fallbackProvider, onMismatch);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// src/events/open-feature-event-emitter.ts
|
|
257
|
+
var import_core5 = require("@openfeature/core");
|
|
211
258
|
var import_node_events = require("node:events");
|
|
212
|
-
var OpenFeatureEventEmitter = class extends
|
|
259
|
+
var OpenFeatureEventEmitter = class extends import_core5.GenericEventEmitter {
|
|
213
260
|
constructor() {
|
|
214
261
|
super();
|
|
215
262
|
this.eventEmitter = new import_node_events.EventEmitter({ captureRejections: true });
|
|
@@ -220,40 +267,8 @@ var OpenFeatureEventEmitter = class extends import_core4.GenericEventEmitter {
|
|
|
220
267
|
}
|
|
221
268
|
};
|
|
222
269
|
|
|
223
|
-
// src/
|
|
224
|
-
var
|
|
225
|
-
var ErrorWithCode = class extends import_core5.OpenFeatureError {
|
|
226
|
-
constructor(code, message) {
|
|
227
|
-
super(message);
|
|
228
|
-
this.code = code;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
var AggregateError = class extends import_core5.GeneralError {
|
|
232
|
-
constructor(message, originalErrors) {
|
|
233
|
-
super(message);
|
|
234
|
-
this.originalErrors = originalErrors;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
var constructAggregateError = (providerErrors) => {
|
|
238
|
-
const errorsWithSource = providerErrors.map(({ providerName, error }) => {
|
|
239
|
-
return { source: providerName, error };
|
|
240
|
-
}).flat();
|
|
241
|
-
return new AggregateError(
|
|
242
|
-
`Provider errors occurred: ${errorsWithSource[0].source}: ${errorsWithSource[0].error}`,
|
|
243
|
-
errorsWithSource
|
|
244
|
-
);
|
|
245
|
-
};
|
|
246
|
-
var throwAggregateErrorFromPromiseResults = (result, providerEntries) => {
|
|
247
|
-
const errors = result.map((r, i) => {
|
|
248
|
-
if (r.status === "rejected") {
|
|
249
|
-
return { error: r.reason, providerName: providerEntries[i].name };
|
|
250
|
-
}
|
|
251
|
-
return null;
|
|
252
|
-
}).filter((val) => Boolean(val));
|
|
253
|
-
if (errors.length) {
|
|
254
|
-
throw constructAggregateError(errors);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
270
|
+
// src/events/events.ts
|
|
271
|
+
var import_core6 = require("@openfeature/core");
|
|
257
272
|
|
|
258
273
|
// src/provider/multi-provider/hook-executor.ts
|
|
259
274
|
var HookExecutor = class {
|
|
@@ -312,196 +327,9 @@ var HookExecutor = class {
|
|
|
312
327
|
}
|
|
313
328
|
};
|
|
314
329
|
|
|
315
|
-
// src/events/events.ts
|
|
316
|
-
var import_core6 = require("@openfeature/core");
|
|
317
|
-
|
|
318
|
-
// src/provider/multi-provider/status-tracker.ts
|
|
319
|
-
var StatusTracker = class {
|
|
320
|
-
constructor(events) {
|
|
321
|
-
this.events = events;
|
|
322
|
-
this.providerStatuses = {};
|
|
323
|
-
}
|
|
324
|
-
wrapEventHandler(providerEntry) {
|
|
325
|
-
var _a, _b, _c, _d;
|
|
326
|
-
const provider = providerEntry.provider;
|
|
327
|
-
(_a = provider.events) == null ? void 0 : _a.addHandler(import_core6.ServerProviderEvents.Error, (details) => {
|
|
328
|
-
this.changeProviderStatus(providerEntry.name, import_core.ServerProviderStatus.ERROR, details);
|
|
329
|
-
});
|
|
330
|
-
(_b = provider.events) == null ? void 0 : _b.addHandler(import_core6.ServerProviderEvents.Stale, (details) => {
|
|
331
|
-
this.changeProviderStatus(providerEntry.name, import_core.ServerProviderStatus.STALE, details);
|
|
332
|
-
});
|
|
333
|
-
(_c = provider.events) == null ? void 0 : _c.addHandler(import_core6.ServerProviderEvents.ConfigurationChanged, (details) => {
|
|
334
|
-
this.events.emit(import_core6.ServerProviderEvents.ConfigurationChanged, details);
|
|
335
|
-
});
|
|
336
|
-
(_d = provider.events) == null ? void 0 : _d.addHandler(import_core6.ServerProviderEvents.Ready, (details) => {
|
|
337
|
-
this.changeProviderStatus(providerEntry.name, import_core.ServerProviderStatus.READY, details);
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
providerStatus(name) {
|
|
341
|
-
return this.providerStatuses[name];
|
|
342
|
-
}
|
|
343
|
-
getStatusFromProviderStatuses() {
|
|
344
|
-
const statuses = Object.values(this.providerStatuses);
|
|
345
|
-
if (statuses.includes(import_core.ServerProviderStatus.FATAL)) {
|
|
346
|
-
return import_core.ServerProviderStatus.FATAL;
|
|
347
|
-
} else if (statuses.includes(import_core.ServerProviderStatus.NOT_READY)) {
|
|
348
|
-
return import_core.ServerProviderStatus.NOT_READY;
|
|
349
|
-
} else if (statuses.includes(import_core.ServerProviderStatus.ERROR)) {
|
|
350
|
-
return import_core.ServerProviderStatus.ERROR;
|
|
351
|
-
} else if (statuses.includes(import_core.ServerProviderStatus.STALE)) {
|
|
352
|
-
return import_core.ServerProviderStatus.STALE;
|
|
353
|
-
}
|
|
354
|
-
return import_core.ServerProviderStatus.READY;
|
|
355
|
-
}
|
|
356
|
-
changeProviderStatus(name, status, details) {
|
|
357
|
-
const currentStatus = this.getStatusFromProviderStatuses();
|
|
358
|
-
this.providerStatuses[name] = status;
|
|
359
|
-
const newStatus = this.getStatusFromProviderStatuses();
|
|
360
|
-
if (currentStatus !== newStatus) {
|
|
361
|
-
if (newStatus === import_core.ServerProviderStatus.FATAL || newStatus === import_core.ServerProviderStatus.ERROR) {
|
|
362
|
-
this.events.emit(import_core6.ServerProviderEvents.Error, details);
|
|
363
|
-
} else if (newStatus === import_core.ServerProviderStatus.STALE) {
|
|
364
|
-
this.events.emit(import_core6.ServerProviderEvents.Stale, details);
|
|
365
|
-
} else if (newStatus === import_core.ServerProviderStatus.READY) {
|
|
366
|
-
this.events.emit(import_core6.ServerProviderEvents.Ready, details);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
// src/provider/multi-provider/strategies/base-evaluation-strategy.ts
|
|
373
|
-
var BaseEvaluationStrategy = class {
|
|
374
|
-
constructor() {
|
|
375
|
-
this.runMode = "sequential";
|
|
376
|
-
}
|
|
377
|
-
shouldEvaluateThisProvider(strategyContext, _evalContext) {
|
|
378
|
-
if (strategyContext.providerStatus === import_core.ServerProviderStatus.NOT_READY || strategyContext.providerStatus === import_core.ServerProviderStatus.FATAL) {
|
|
379
|
-
return false;
|
|
380
|
-
}
|
|
381
|
-
return true;
|
|
382
|
-
}
|
|
383
|
-
shouldEvaluateNextProvider(_strategyContext, _context, _result) {
|
|
384
|
-
return true;
|
|
385
|
-
}
|
|
386
|
-
shouldTrackWithThisProvider(strategyContext, _context, _trackingEventName, _trackingEventDetails) {
|
|
387
|
-
if (strategyContext.providerStatus === import_core.ServerProviderStatus.NOT_READY || strategyContext.providerStatus === import_core.ServerProviderStatus.FATAL) {
|
|
388
|
-
return false;
|
|
389
|
-
}
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
hasError(resolution) {
|
|
393
|
-
return "thrownError" in resolution || !!resolution.details.errorCode;
|
|
394
|
-
}
|
|
395
|
-
hasErrorWithCode(resolution, code) {
|
|
396
|
-
var _a;
|
|
397
|
-
return "thrownError" in resolution ? ((_a = resolution.thrownError) == null ? void 0 : _a.code) === code : resolution.details.errorCode === code;
|
|
398
|
-
}
|
|
399
|
-
collectProviderErrors(resolutions) {
|
|
400
|
-
var _a;
|
|
401
|
-
const errors = [];
|
|
402
|
-
for (const resolution of resolutions) {
|
|
403
|
-
if ("thrownError" in resolution) {
|
|
404
|
-
errors.push({ providerName: resolution.providerName, error: resolution.thrownError });
|
|
405
|
-
} else if (resolution.details.errorCode) {
|
|
406
|
-
errors.push({
|
|
407
|
-
providerName: resolution.providerName,
|
|
408
|
-
error: new ErrorWithCode(resolution.details.errorCode, (_a = resolution.details.errorMessage) != null ? _a : "unknown error")
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
return { errors };
|
|
413
|
-
}
|
|
414
|
-
resolutionToFinalResult(resolution) {
|
|
415
|
-
return { details: resolution.details, provider: resolution.provider, providerName: resolution.providerName };
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
// src/provider/multi-provider/strategies/first-match-strategy.ts
|
|
420
|
-
var import_core7 = require("@openfeature/core");
|
|
421
|
-
var FirstMatchStrategy = class extends BaseEvaluationStrategy {
|
|
422
|
-
shouldEvaluateNextProvider(strategyContext, context, result) {
|
|
423
|
-
if (this.hasErrorWithCode(result, import_core7.ErrorCode.FLAG_NOT_FOUND)) {
|
|
424
|
-
return true;
|
|
425
|
-
}
|
|
426
|
-
if (this.hasError(result)) {
|
|
427
|
-
return false;
|
|
428
|
-
}
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
determineFinalResult(strategyContext, context, resolutions) {
|
|
432
|
-
const finalResolution = resolutions[resolutions.length - 1];
|
|
433
|
-
if (this.hasError(finalResolution)) {
|
|
434
|
-
return this.collectProviderErrors(resolutions);
|
|
435
|
-
}
|
|
436
|
-
return this.resolutionToFinalResult(finalResolution);
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
// src/provider/multi-provider/strategies/first-successful-strategy.ts
|
|
441
|
-
var FirstSuccessfulStrategy = class extends BaseEvaluationStrategy {
|
|
442
|
-
shouldEvaluateNextProvider(strategyContext, context, result) {
|
|
443
|
-
return this.hasError(result);
|
|
444
|
-
}
|
|
445
|
-
determineFinalResult(strategyContext, context, resolutions) {
|
|
446
|
-
const finalResolution = resolutions[resolutions.length - 1];
|
|
447
|
-
if (this.hasError(finalResolution)) {
|
|
448
|
-
return this.collectProviderErrors(resolutions);
|
|
449
|
-
}
|
|
450
|
-
return this.resolutionToFinalResult(finalResolution);
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
// src/provider/multi-provider/strategies/comparison-strategy.ts
|
|
455
|
-
var import_core8 = require("@openfeature/core");
|
|
456
|
-
var ComparisonStrategy = class extends BaseEvaluationStrategy {
|
|
457
|
-
constructor(fallbackProvider, onMismatch) {
|
|
458
|
-
super();
|
|
459
|
-
this.fallbackProvider = fallbackProvider;
|
|
460
|
-
this.onMismatch = onMismatch;
|
|
461
|
-
this.runMode = "parallel";
|
|
462
|
-
}
|
|
463
|
-
determineFinalResult(strategyContext, context, resolutions) {
|
|
464
|
-
var _a;
|
|
465
|
-
let value;
|
|
466
|
-
let fallbackResolution;
|
|
467
|
-
let finalResolution;
|
|
468
|
-
let mismatch = false;
|
|
469
|
-
for (const [i, resolution] of resolutions.entries()) {
|
|
470
|
-
if (this.hasError(resolution)) {
|
|
471
|
-
return this.collectProviderErrors(resolutions);
|
|
472
|
-
}
|
|
473
|
-
if (resolution.provider === this.fallbackProvider) {
|
|
474
|
-
fallbackResolution = resolution;
|
|
475
|
-
}
|
|
476
|
-
if (i === 0) {
|
|
477
|
-
finalResolution = resolution;
|
|
478
|
-
}
|
|
479
|
-
if (typeof value !== "undefined" && value !== resolution.details.value) {
|
|
480
|
-
mismatch = true;
|
|
481
|
-
} else {
|
|
482
|
-
value = resolution.details.value;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
if (!fallbackResolution) {
|
|
486
|
-
throw new import_core8.GeneralError("Fallback provider not found in resolution results");
|
|
487
|
-
}
|
|
488
|
-
if (!finalResolution) {
|
|
489
|
-
throw new import_core8.GeneralError("Final resolution not found in resolution results");
|
|
490
|
-
}
|
|
491
|
-
if (mismatch) {
|
|
492
|
-
(_a = this.onMismatch) == null ? void 0 : _a.call(this, resolutions);
|
|
493
|
-
return {
|
|
494
|
-
details: fallbackResolution.details,
|
|
495
|
-
provider: fallbackResolution.provider
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
return this.resolutionToFinalResult(finalResolution);
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
|
|
502
330
|
// src/provider/multi-provider/multi-provider.ts
|
|
503
331
|
var MultiProvider = class _MultiProvider {
|
|
504
|
-
constructor(constructorProviders, evaluationStrategy = new FirstMatchStrategy(), logger = new
|
|
332
|
+
constructor(constructorProviders, evaluationStrategy = new FirstMatchStrategy(), logger = new import_core7.DefaultLogger()) {
|
|
505
333
|
this.constructorProviders = constructorProviders;
|
|
506
334
|
this.evaluationStrategy = evaluationStrategy;
|
|
507
335
|
this.logger = logger;
|
|
@@ -511,7 +339,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
511
339
|
this.hookHints = /* @__PURE__ */ new WeakMap();
|
|
512
340
|
this.providerEntries = [];
|
|
513
341
|
this.providerEntriesByName = {};
|
|
514
|
-
this.statusTracker = new StatusTracker(this.events);
|
|
342
|
+
this.statusTracker = new import_core7.StatusTracker(this.events, import_core.ServerProviderStatus, import_core6.ServerProviderEvents);
|
|
515
343
|
this.hookExecutor = new HookExecutor(this.logger);
|
|
516
344
|
this.registerProviders(constructorProviders);
|
|
517
345
|
const aggregateMetadata = Object.keys(this.providerEntriesByName).reduce((acc, name) => {
|
|
@@ -553,7 +381,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
553
381
|
return (_b = (_a = provider.provider).initialize) == null ? void 0 : _b.call(_a, context);
|
|
554
382
|
})
|
|
555
383
|
);
|
|
556
|
-
throwAggregateErrorFromPromiseResults(result, this.providerEntries);
|
|
384
|
+
(0, import_core7.throwAggregateErrorFromPromiseResults)(result, this.providerEntries);
|
|
557
385
|
});
|
|
558
386
|
}
|
|
559
387
|
onClose() {
|
|
@@ -562,7 +390,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
562
390
|
var _a, _b;
|
|
563
391
|
return (_b = (_a = provider.provider).onClose) == null ? void 0 : _b.call(_a);
|
|
564
392
|
}));
|
|
565
|
-
throwAggregateErrorFromPromiseResults(result, this.providerEntries);
|
|
393
|
+
(0, import_core7.throwAggregateErrorFromPromiseResults)(result, this.providerEntries);
|
|
566
394
|
});
|
|
567
395
|
}
|
|
568
396
|
resolveBooleanEvaluation(flagKey, defaultValue, context) {
|
|
@@ -583,7 +411,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
583
411
|
const hookContext = this.hookContexts.get(context);
|
|
584
412
|
const hookHints = this.hookHints.get(context);
|
|
585
413
|
if (!hookContext || !hookHints) {
|
|
586
|
-
throw new
|
|
414
|
+
throw new import_core7.GeneralError("Hook context not available for evaluation");
|
|
587
415
|
}
|
|
588
416
|
const tasks = [];
|
|
589
417
|
for (const providerEntry of this.providerEntries) {
|
|
@@ -608,10 +436,10 @@ var MultiProvider = class _MultiProvider {
|
|
|
608
436
|
const resolutions = results.map(([, resolution]) => resolution).filter((r) => Boolean(r));
|
|
609
437
|
const finalResult = this.evaluationStrategy.determineFinalResult({ flagKey, flagType }, context, resolutions);
|
|
610
438
|
if ((_a = finalResult.errors) == null ? void 0 : _a.length) {
|
|
611
|
-
throw constructAggregateError(finalResult.errors);
|
|
439
|
+
throw (0, import_core7.constructAggregateError)(finalResult.errors);
|
|
612
440
|
}
|
|
613
441
|
if (!finalResult.details) {
|
|
614
|
-
throw new
|
|
442
|
+
throw new import_core7.GeneralError("No result was returned from any provider");
|
|
615
443
|
}
|
|
616
444
|
return finalResult.details;
|
|
617
445
|
});
|
|
@@ -690,7 +518,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
690
518
|
case "boolean":
|
|
691
519
|
return yield provider.resolveBooleanEvaluation(flagKey, defaultValue, context, this.logger);
|
|
692
520
|
default:
|
|
693
|
-
throw new
|
|
521
|
+
throw new import_core7.GeneralError("Invalid flag evaluation type");
|
|
694
522
|
}
|
|
695
523
|
});
|
|
696
524
|
}
|
|
@@ -735,12 +563,12 @@ var MultiProvider = class _MultiProvider {
|
|
|
735
563
|
}
|
|
736
564
|
getErrorEvaluationDetails(flagKey, defaultValue, err, flagMetadata = {}) {
|
|
737
565
|
const errorMessage = err == null ? void 0 : err.message;
|
|
738
|
-
const errorCode = (err == null ? void 0 : err.code) ||
|
|
566
|
+
const errorCode = (err == null ? void 0 : err.code) || import_core7.ErrorCode.GENERAL;
|
|
739
567
|
return {
|
|
740
568
|
errorCode,
|
|
741
569
|
errorMessage,
|
|
742
570
|
value: defaultValue,
|
|
743
|
-
reason:
|
|
571
|
+
reason: import_core7.StandardResolutionReasons.ERROR,
|
|
744
572
|
flagMetadata: Object.freeze(flagMetadata),
|
|
745
573
|
flagKey
|
|
746
574
|
};
|
|
@@ -748,10 +576,10 @@ var MultiProvider = class _MultiProvider {
|
|
|
748
576
|
};
|
|
749
577
|
|
|
750
578
|
// src/open-feature.ts
|
|
751
|
-
var
|
|
579
|
+
var import_core9 = require("@openfeature/core");
|
|
752
580
|
|
|
753
581
|
// src/client/internal/open-feature-client.ts
|
|
754
|
-
var
|
|
582
|
+
var import_core8 = require("@openfeature/core");
|
|
755
583
|
var OpenFeatureClient = class {
|
|
756
584
|
constructor(providerAccessor, providerStatusAccessor, emitterAccessor, apiContextAccessor, apiHooksAccessor, transactionContextAccessor, globalLogger, options, context = {}) {
|
|
757
585
|
this.providerAccessor = providerAccessor;
|
|
@@ -781,7 +609,7 @@ var OpenFeatureClient = class {
|
|
|
781
609
|
addHandler(eventType, handler, options) {
|
|
782
610
|
var _a;
|
|
783
611
|
this.emitterAccessor().addHandler(eventType, handler);
|
|
784
|
-
const shouldRunNow = (0,
|
|
612
|
+
const shouldRunNow = (0, import_core8.statusMatchesEvent)(eventType, this._providerStatus);
|
|
785
613
|
if (shouldRunNow) {
|
|
786
614
|
try {
|
|
787
615
|
handler({
|
|
@@ -806,7 +634,7 @@ var OpenFeatureClient = class {
|
|
|
806
634
|
return this.emitterAccessor().getHandlers(eventType);
|
|
807
635
|
}
|
|
808
636
|
setLogger(logger) {
|
|
809
|
-
this._clientLogger = new
|
|
637
|
+
this._clientLogger = new import_core8.SafeLogger(logger);
|
|
810
638
|
return this;
|
|
811
639
|
}
|
|
812
640
|
setContext(context) {
|
|
@@ -916,7 +744,7 @@ var OpenFeatureClient = class {
|
|
|
916
744
|
providerMetadata: this._provider.metadata,
|
|
917
745
|
context: mergedContext,
|
|
918
746
|
logger: this._logger,
|
|
919
|
-
hookData: new
|
|
747
|
+
hookData: new import_core8.MapHookData()
|
|
920
748
|
})
|
|
921
749
|
);
|
|
922
750
|
let evaluationDetails;
|
|
@@ -929,7 +757,7 @@ var OpenFeatureClient = class {
|
|
|
929
757
|
flagKey
|
|
930
758
|
});
|
|
931
759
|
if (resolutionDetails.errorCode) {
|
|
932
|
-
const err = (0,
|
|
760
|
+
const err = (0, import_core8.instantiateErrorByErrorCode)(resolutionDetails.errorCode, resolutionDetails.errorMessage);
|
|
933
761
|
yield this.errorHooks(allHooksReversed, hookContexts, err, options);
|
|
934
762
|
evaluationDetails = this.getErrorEvaluationDetails(flagKey, defaultValue, err, resolutionDetails.flagMetadata);
|
|
935
763
|
} else {
|
|
@@ -955,9 +783,7 @@ var OpenFeatureClient = class {
|
|
|
955
783
|
const hookResult = yield (_a = hook == null ? void 0 : hook.before) == null ? void 0 : _a.call(hook, hookContext, Object.freeze(options.hookHints));
|
|
956
784
|
if (hookResult) {
|
|
957
785
|
Object.assign(accumulatedContext, hookResult);
|
|
958
|
-
|
|
959
|
-
Object.assign(hookContexts[hookContextIndex].context, accumulatedContext);
|
|
960
|
-
}
|
|
786
|
+
Object.assign(hookContext.context, accumulatedContext);
|
|
961
787
|
}
|
|
962
788
|
}
|
|
963
789
|
return Object.freeze(accumulatedContext);
|
|
@@ -1020,19 +846,19 @@ var OpenFeatureClient = class {
|
|
|
1020
846
|
}
|
|
1021
847
|
shortCircuitIfNotReady() {
|
|
1022
848
|
if (this.providerStatus === import_core.ServerProviderStatus.NOT_READY) {
|
|
1023
|
-
throw new
|
|
849
|
+
throw new import_core8.ProviderNotReadyError("provider has not yet initialized");
|
|
1024
850
|
} else if (this.providerStatus === import_core.ServerProviderStatus.FATAL) {
|
|
1025
|
-
throw new
|
|
851
|
+
throw new import_core8.ProviderFatalError("provider is in an irrecoverable error state");
|
|
1026
852
|
}
|
|
1027
853
|
}
|
|
1028
854
|
getErrorEvaluationDetails(flagKey, defaultValue, err, flagMetadata = {}) {
|
|
1029
855
|
const errorMessage = err == null ? void 0 : err.message;
|
|
1030
|
-
const errorCode = (err == null ? void 0 : err.code) ||
|
|
856
|
+
const errorCode = (err == null ? void 0 : err.code) || import_core8.ErrorCode.GENERAL;
|
|
1031
857
|
return {
|
|
1032
858
|
errorCode,
|
|
1033
859
|
errorMessage,
|
|
1034
860
|
value: defaultValue,
|
|
1035
|
-
reason:
|
|
861
|
+
reason: import_core8.StandardResolutionReasons.ERROR,
|
|
1036
862
|
flagMetadata: Object.freeze(flagMetadata),
|
|
1037
863
|
flagKey
|
|
1038
864
|
};
|
|
@@ -1068,12 +894,12 @@ var AsyncLocalStorageTransactionContextPropagator = class {
|
|
|
1068
894
|
// src/open-feature.ts
|
|
1069
895
|
var GLOBAL_OPENFEATURE_API_KEY = Symbol.for("@openfeature/js-sdk/api");
|
|
1070
896
|
var _globalThis = globalThis;
|
|
1071
|
-
var OpenFeatureAPI = class _OpenFeatureAPI extends
|
|
897
|
+
var OpenFeatureAPI = class _OpenFeatureAPI extends import_core9.OpenFeatureCommonAPI {
|
|
1072
898
|
constructor() {
|
|
1073
899
|
super("server");
|
|
1074
900
|
this._statusEnumType = import_core.ServerProviderStatus;
|
|
1075
901
|
this._apiEmitter = new OpenFeatureEventEmitter();
|
|
1076
|
-
this._defaultProvider = new
|
|
902
|
+
this._defaultProvider = new import_core9.ProviderWrapper(
|
|
1077
903
|
NOOP_PROVIDER,
|
|
1078
904
|
import_core.ServerProviderStatus.NOT_READY,
|
|
1079
905
|
this._statusEnumType
|
|
@@ -1105,14 +931,14 @@ var OpenFeatureAPI = class _OpenFeatureAPI extends import_core11.OpenFeatureComm
|
|
|
1105
931
|
}
|
|
1106
932
|
setProviderAndWait(domainOrProvider, providerOrUndefined) {
|
|
1107
933
|
return __async(this, null, function* () {
|
|
1108
|
-
const domain = (0,
|
|
1109
|
-
const provider = domain ? (0,
|
|
934
|
+
const domain = (0, import_core9.stringOrUndefined)(domainOrProvider);
|
|
935
|
+
const provider = domain ? (0, import_core9.objectOrUndefined)(providerOrUndefined) : (0, import_core9.objectOrUndefined)(domainOrProvider);
|
|
1110
936
|
yield this.setAwaitableProvider(domain, provider);
|
|
1111
937
|
});
|
|
1112
938
|
}
|
|
1113
939
|
setProvider(clientOrProvider, providerOrUndefined) {
|
|
1114
|
-
const domain = (0,
|
|
1115
|
-
const provider = domain ? (0,
|
|
940
|
+
const domain = (0, import_core9.stringOrUndefined)(clientOrProvider);
|
|
941
|
+
const provider = domain ? (0, import_core9.objectOrUndefined)(providerOrUndefined) : (0, import_core9.objectOrUndefined)(clientOrProvider);
|
|
1116
942
|
const maybePromise = this.setAwaitableProvider(domain, provider);
|
|
1117
943
|
Promise.resolve(maybePromise).catch((err) => {
|
|
1118
944
|
this._logger.error("Error during provider initialization:", err);
|
|
@@ -1131,9 +957,9 @@ var OpenFeatureAPI = class _OpenFeatureAPI extends import_core11.OpenFeatureComm
|
|
|
1131
957
|
}
|
|
1132
958
|
getClient(domainOrContext, versionOrContext, contextOrUndefined) {
|
|
1133
959
|
var _a, _b;
|
|
1134
|
-
const domain = (0,
|
|
1135
|
-
const version = (0,
|
|
1136
|
-
const context = (_b = (_a = (0,
|
|
960
|
+
const domain = (0, import_core9.stringOrUndefined)(domainOrContext);
|
|
961
|
+
const version = (0, import_core9.stringOrUndefined)(versionOrContext);
|
|
962
|
+
const context = (_b = (_a = (0, import_core9.objectOrUndefined)(domainOrContext)) != null ? _a : (0, import_core9.objectOrUndefined)(versionOrContext)) != null ? _b : (0, import_core9.objectOrUndefined)(contextOrUndefined);
|
|
1137
963
|
return new OpenFeatureClient(
|
|
1138
964
|
() => this.getProviderForClient(domain),
|
|
1139
965
|
() => this.getProviderStatus(domain),
|
|
@@ -1184,11 +1010,8 @@ var OpenFeature = OpenFeatureAPI.getInstance();
|
|
|
1184
1010
|
__reExport(index_exports, require("@openfeature/core"), module.exports);
|
|
1185
1011
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1186
1012
|
0 && (module.exports = {
|
|
1187
|
-
AggregateError,
|
|
1188
1013
|
AsyncLocalStorageTransactionContextPropagator,
|
|
1189
|
-
BaseEvaluationStrategy,
|
|
1190
1014
|
ComparisonStrategy,
|
|
1191
|
-
ErrorWithCode,
|
|
1192
1015
|
FirstMatchStrategy,
|
|
1193
1016
|
FirstSuccessfulStrategy,
|
|
1194
1017
|
InMemoryProvider,
|
|
@@ -1200,8 +1023,7 @@ __reExport(index_exports, require("@openfeature/core"), module.exports);
|
|
|
1200
1023
|
OpenFeatureEventEmitter,
|
|
1201
1024
|
ProviderEvents,
|
|
1202
1025
|
ProviderStatus,
|
|
1203
|
-
|
|
1204
|
-
throwAggregateErrorFromPromiseResults,
|
|
1026
|
+
TypedInMemoryProvider,
|
|
1205
1027
|
...require("@openfeature/core")
|
|
1206
1028
|
});
|
|
1207
1029
|
//# sourceMappingURL=index.js.map
|