@openfeature/server-sdk 1.20.0 → 1.20.2
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/LICENSE +1 -1
- package/README.md +63 -48
- package/dist/cjs/index.js +56 -269
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +46 -249
- package/dist/esm/index.js.map +4 -4
- package/dist/types.d.ts +44 -117
- package/package.json +3 -3
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,
|
|
@@ -73,9 +70,7 @@ __export(index_exports, {
|
|
|
73
70
|
OpenFeatureAPI: () => OpenFeatureAPI,
|
|
74
71
|
OpenFeatureEventEmitter: () => OpenFeatureEventEmitter,
|
|
75
72
|
ProviderEvents: () => import_core6.ServerProviderEvents,
|
|
76
|
-
ProviderStatus: () => import_core.ServerProviderStatus
|
|
77
|
-
constructAggregateError: () => constructAggregateError,
|
|
78
|
-
throwAggregateErrorFromPromiseResults: () => throwAggregateErrorFromPromiseResults
|
|
73
|
+
ProviderStatus: () => import_core.ServerProviderStatus
|
|
79
74
|
});
|
|
80
75
|
module.exports = __toCommonJS(index_exports);
|
|
81
76
|
|
|
@@ -204,12 +199,30 @@ var InMemoryProvider = class {
|
|
|
204
199
|
};
|
|
205
200
|
|
|
206
201
|
// src/provider/multi-provider/multi-provider.ts
|
|
207
|
-
var
|
|
202
|
+
var import_core7 = require("@openfeature/core");
|
|
208
203
|
|
|
209
|
-
// src/
|
|
204
|
+
// src/provider/multi-provider/strategies.ts
|
|
210
205
|
var import_core4 = require("@openfeature/core");
|
|
206
|
+
var FirstMatchStrategy = class extends import_core4.BaseFirstMatchStrategy {
|
|
207
|
+
constructor() {
|
|
208
|
+
super(import_core.ServerProviderStatus);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var FirstSuccessfulStrategy = class extends import_core4.BaseFirstSuccessfulStrategy {
|
|
212
|
+
constructor() {
|
|
213
|
+
super(import_core.ServerProviderStatus);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var ComparisonStrategy = class extends import_core4.BaseComparisonStrategy {
|
|
217
|
+
constructor(fallbackProvider, onMismatch) {
|
|
218
|
+
super(import_core.ServerProviderStatus, fallbackProvider, onMismatch);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// src/events/open-feature-event-emitter.ts
|
|
223
|
+
var import_core5 = require("@openfeature/core");
|
|
211
224
|
var import_node_events = require("node:events");
|
|
212
|
-
var OpenFeatureEventEmitter = class extends
|
|
225
|
+
var OpenFeatureEventEmitter = class extends import_core5.GenericEventEmitter {
|
|
213
226
|
constructor() {
|
|
214
227
|
super();
|
|
215
228
|
this.eventEmitter = new import_node_events.EventEmitter({ captureRejections: true });
|
|
@@ -220,40 +233,8 @@ var OpenFeatureEventEmitter = class extends import_core4.GenericEventEmitter {
|
|
|
220
233
|
}
|
|
221
234
|
};
|
|
222
235
|
|
|
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
|
-
};
|
|
236
|
+
// src/events/events.ts
|
|
237
|
+
var import_core6 = require("@openfeature/core");
|
|
257
238
|
|
|
258
239
|
// src/provider/multi-provider/hook-executor.ts
|
|
259
240
|
var HookExecutor = class {
|
|
@@ -312,196 +293,9 @@ var HookExecutor = class {
|
|
|
312
293
|
}
|
|
313
294
|
};
|
|
314
295
|
|
|
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
296
|
// src/provider/multi-provider/multi-provider.ts
|
|
503
297
|
var MultiProvider = class _MultiProvider {
|
|
504
|
-
constructor(constructorProviders, evaluationStrategy = new FirstMatchStrategy(), logger = new
|
|
298
|
+
constructor(constructorProviders, evaluationStrategy = new FirstMatchStrategy(), logger = new import_core7.DefaultLogger()) {
|
|
505
299
|
this.constructorProviders = constructorProviders;
|
|
506
300
|
this.evaluationStrategy = evaluationStrategy;
|
|
507
301
|
this.logger = logger;
|
|
@@ -511,7 +305,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
511
305
|
this.hookHints = /* @__PURE__ */ new WeakMap();
|
|
512
306
|
this.providerEntries = [];
|
|
513
307
|
this.providerEntriesByName = {};
|
|
514
|
-
this.statusTracker = new StatusTracker(this.events);
|
|
308
|
+
this.statusTracker = new import_core7.StatusTracker(this.events, import_core.ServerProviderStatus, import_core6.ServerProviderEvents);
|
|
515
309
|
this.hookExecutor = new HookExecutor(this.logger);
|
|
516
310
|
this.registerProviders(constructorProviders);
|
|
517
311
|
const aggregateMetadata = Object.keys(this.providerEntriesByName).reduce((acc, name) => {
|
|
@@ -553,7 +347,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
553
347
|
return (_b = (_a = provider.provider).initialize) == null ? void 0 : _b.call(_a, context);
|
|
554
348
|
})
|
|
555
349
|
);
|
|
556
|
-
throwAggregateErrorFromPromiseResults(result, this.providerEntries);
|
|
350
|
+
(0, import_core7.throwAggregateErrorFromPromiseResults)(result, this.providerEntries);
|
|
557
351
|
});
|
|
558
352
|
}
|
|
559
353
|
onClose() {
|
|
@@ -562,7 +356,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
562
356
|
var _a, _b;
|
|
563
357
|
return (_b = (_a = provider.provider).onClose) == null ? void 0 : _b.call(_a);
|
|
564
358
|
}));
|
|
565
|
-
throwAggregateErrorFromPromiseResults(result, this.providerEntries);
|
|
359
|
+
(0, import_core7.throwAggregateErrorFromPromiseResults)(result, this.providerEntries);
|
|
566
360
|
});
|
|
567
361
|
}
|
|
568
362
|
resolveBooleanEvaluation(flagKey, defaultValue, context) {
|
|
@@ -583,7 +377,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
583
377
|
const hookContext = this.hookContexts.get(context);
|
|
584
378
|
const hookHints = this.hookHints.get(context);
|
|
585
379
|
if (!hookContext || !hookHints) {
|
|
586
|
-
throw new
|
|
380
|
+
throw new import_core7.GeneralError("Hook context not available for evaluation");
|
|
587
381
|
}
|
|
588
382
|
const tasks = [];
|
|
589
383
|
for (const providerEntry of this.providerEntries) {
|
|
@@ -608,10 +402,10 @@ var MultiProvider = class _MultiProvider {
|
|
|
608
402
|
const resolutions = results.map(([, resolution]) => resolution).filter((r) => Boolean(r));
|
|
609
403
|
const finalResult = this.evaluationStrategy.determineFinalResult({ flagKey, flagType }, context, resolutions);
|
|
610
404
|
if ((_a = finalResult.errors) == null ? void 0 : _a.length) {
|
|
611
|
-
throw constructAggregateError(finalResult.errors);
|
|
405
|
+
throw (0, import_core7.constructAggregateError)(finalResult.errors);
|
|
612
406
|
}
|
|
613
407
|
if (!finalResult.details) {
|
|
614
|
-
throw new
|
|
408
|
+
throw new import_core7.GeneralError("No result was returned from any provider");
|
|
615
409
|
}
|
|
616
410
|
return finalResult.details;
|
|
617
411
|
});
|
|
@@ -690,7 +484,7 @@ var MultiProvider = class _MultiProvider {
|
|
|
690
484
|
case "boolean":
|
|
691
485
|
return yield provider.resolveBooleanEvaluation(flagKey, defaultValue, context, this.logger);
|
|
692
486
|
default:
|
|
693
|
-
throw new
|
|
487
|
+
throw new import_core7.GeneralError("Invalid flag evaluation type");
|
|
694
488
|
}
|
|
695
489
|
});
|
|
696
490
|
}
|
|
@@ -735,12 +529,12 @@ var MultiProvider = class _MultiProvider {
|
|
|
735
529
|
}
|
|
736
530
|
getErrorEvaluationDetails(flagKey, defaultValue, err, flagMetadata = {}) {
|
|
737
531
|
const errorMessage = err == null ? void 0 : err.message;
|
|
738
|
-
const errorCode = (err == null ? void 0 : err.code) ||
|
|
532
|
+
const errorCode = (err == null ? void 0 : err.code) || import_core7.ErrorCode.GENERAL;
|
|
739
533
|
return {
|
|
740
534
|
errorCode,
|
|
741
535
|
errorMessage,
|
|
742
536
|
value: defaultValue,
|
|
743
|
-
reason:
|
|
537
|
+
reason: import_core7.StandardResolutionReasons.ERROR,
|
|
744
538
|
flagMetadata: Object.freeze(flagMetadata),
|
|
745
539
|
flagKey
|
|
746
540
|
};
|
|
@@ -748,10 +542,10 @@ var MultiProvider = class _MultiProvider {
|
|
|
748
542
|
};
|
|
749
543
|
|
|
750
544
|
// src/open-feature.ts
|
|
751
|
-
var
|
|
545
|
+
var import_core9 = require("@openfeature/core");
|
|
752
546
|
|
|
753
547
|
// src/client/internal/open-feature-client.ts
|
|
754
|
-
var
|
|
548
|
+
var import_core8 = require("@openfeature/core");
|
|
755
549
|
var OpenFeatureClient = class {
|
|
756
550
|
constructor(providerAccessor, providerStatusAccessor, emitterAccessor, apiContextAccessor, apiHooksAccessor, transactionContextAccessor, globalLogger, options, context = {}) {
|
|
757
551
|
this.providerAccessor = providerAccessor;
|
|
@@ -781,7 +575,7 @@ var OpenFeatureClient = class {
|
|
|
781
575
|
addHandler(eventType, handler, options) {
|
|
782
576
|
var _a;
|
|
783
577
|
this.emitterAccessor().addHandler(eventType, handler);
|
|
784
|
-
const shouldRunNow = (0,
|
|
578
|
+
const shouldRunNow = (0, import_core8.statusMatchesEvent)(eventType, this._providerStatus);
|
|
785
579
|
if (shouldRunNow) {
|
|
786
580
|
try {
|
|
787
581
|
handler({
|
|
@@ -806,7 +600,7 @@ var OpenFeatureClient = class {
|
|
|
806
600
|
return this.emitterAccessor().getHandlers(eventType);
|
|
807
601
|
}
|
|
808
602
|
setLogger(logger) {
|
|
809
|
-
this._clientLogger = new
|
|
603
|
+
this._clientLogger = new import_core8.SafeLogger(logger);
|
|
810
604
|
return this;
|
|
811
605
|
}
|
|
812
606
|
setContext(context) {
|
|
@@ -916,7 +710,7 @@ var OpenFeatureClient = class {
|
|
|
916
710
|
providerMetadata: this._provider.metadata,
|
|
917
711
|
context: mergedContext,
|
|
918
712
|
logger: this._logger,
|
|
919
|
-
hookData: new
|
|
713
|
+
hookData: new import_core8.MapHookData()
|
|
920
714
|
})
|
|
921
715
|
);
|
|
922
716
|
let evaluationDetails;
|
|
@@ -929,7 +723,7 @@ var OpenFeatureClient = class {
|
|
|
929
723
|
flagKey
|
|
930
724
|
});
|
|
931
725
|
if (resolutionDetails.errorCode) {
|
|
932
|
-
const err = (0,
|
|
726
|
+
const err = (0, import_core8.instantiateErrorByErrorCode)(resolutionDetails.errorCode, resolutionDetails.errorMessage);
|
|
933
727
|
yield this.errorHooks(allHooksReversed, hookContexts, err, options);
|
|
934
728
|
evaluationDetails = this.getErrorEvaluationDetails(flagKey, defaultValue, err, resolutionDetails.flagMetadata);
|
|
935
729
|
} else {
|
|
@@ -947,17 +741,15 @@ var OpenFeatureClient = class {
|
|
|
947
741
|
beforeHooks(hooks, hookContexts, mergedContext, options) {
|
|
948
742
|
return __async(this, null, function* () {
|
|
949
743
|
var _a;
|
|
950
|
-
|
|
744
|
+
const accumulatedContext = mergedContext;
|
|
951
745
|
for (const [index, hook] of hooks.entries()) {
|
|
952
746
|
const hookContextIndex = hooks.length - 1 - index;
|
|
953
747
|
const hookContext = hookContexts[hookContextIndex];
|
|
954
748
|
Object.assign(hookContext.context, accumulatedContext);
|
|
955
749
|
const hookResult = yield (_a = hook == null ? void 0 : hook.before) == null ? void 0 : _a.call(hook, hookContext, Object.freeze(options.hookHints));
|
|
956
750
|
if (hookResult) {
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
Object.assign(hookContexts[hookContextIndex].context, accumulatedContext);
|
|
960
|
-
}
|
|
751
|
+
Object.assign(accumulatedContext, hookResult);
|
|
752
|
+
Object.assign(hookContext.context, accumulatedContext);
|
|
961
753
|
}
|
|
962
754
|
}
|
|
963
755
|
return Object.freeze(accumulatedContext);
|
|
@@ -1020,19 +812,19 @@ var OpenFeatureClient = class {
|
|
|
1020
812
|
}
|
|
1021
813
|
shortCircuitIfNotReady() {
|
|
1022
814
|
if (this.providerStatus === import_core.ServerProviderStatus.NOT_READY) {
|
|
1023
|
-
throw new
|
|
815
|
+
throw new import_core8.ProviderNotReadyError("provider has not yet initialized");
|
|
1024
816
|
} else if (this.providerStatus === import_core.ServerProviderStatus.FATAL) {
|
|
1025
|
-
throw new
|
|
817
|
+
throw new import_core8.ProviderFatalError("provider is in an irrecoverable error state");
|
|
1026
818
|
}
|
|
1027
819
|
}
|
|
1028
820
|
getErrorEvaluationDetails(flagKey, defaultValue, err, flagMetadata = {}) {
|
|
1029
821
|
const errorMessage = err == null ? void 0 : err.message;
|
|
1030
|
-
const errorCode = (err == null ? void 0 : err.code) ||
|
|
822
|
+
const errorCode = (err == null ? void 0 : err.code) || import_core8.ErrorCode.GENERAL;
|
|
1031
823
|
return {
|
|
1032
824
|
errorCode,
|
|
1033
825
|
errorMessage,
|
|
1034
826
|
value: defaultValue,
|
|
1035
|
-
reason:
|
|
827
|
+
reason: import_core8.StandardResolutionReasons.ERROR,
|
|
1036
828
|
flagMetadata: Object.freeze(flagMetadata),
|
|
1037
829
|
flagKey
|
|
1038
830
|
};
|
|
@@ -1068,12 +860,12 @@ var AsyncLocalStorageTransactionContextPropagator = class {
|
|
|
1068
860
|
// src/open-feature.ts
|
|
1069
861
|
var GLOBAL_OPENFEATURE_API_KEY = Symbol.for("@openfeature/js-sdk/api");
|
|
1070
862
|
var _globalThis = globalThis;
|
|
1071
|
-
var OpenFeatureAPI = class _OpenFeatureAPI extends
|
|
863
|
+
var OpenFeatureAPI = class _OpenFeatureAPI extends import_core9.OpenFeatureCommonAPI {
|
|
1072
864
|
constructor() {
|
|
1073
865
|
super("server");
|
|
1074
866
|
this._statusEnumType = import_core.ServerProviderStatus;
|
|
1075
867
|
this._apiEmitter = new OpenFeatureEventEmitter();
|
|
1076
|
-
this._defaultProvider = new
|
|
868
|
+
this._defaultProvider = new import_core9.ProviderWrapper(
|
|
1077
869
|
NOOP_PROVIDER,
|
|
1078
870
|
import_core.ServerProviderStatus.NOT_READY,
|
|
1079
871
|
this._statusEnumType
|
|
@@ -1105,14 +897,14 @@ var OpenFeatureAPI = class _OpenFeatureAPI extends import_core11.OpenFeatureComm
|
|
|
1105
897
|
}
|
|
1106
898
|
setProviderAndWait(domainOrProvider, providerOrUndefined) {
|
|
1107
899
|
return __async(this, null, function* () {
|
|
1108
|
-
const domain = (0,
|
|
1109
|
-
const provider = domain ? (0,
|
|
900
|
+
const domain = (0, import_core9.stringOrUndefined)(domainOrProvider);
|
|
901
|
+
const provider = domain ? (0, import_core9.objectOrUndefined)(providerOrUndefined) : (0, import_core9.objectOrUndefined)(domainOrProvider);
|
|
1110
902
|
yield this.setAwaitableProvider(domain, provider);
|
|
1111
903
|
});
|
|
1112
904
|
}
|
|
1113
905
|
setProvider(clientOrProvider, providerOrUndefined) {
|
|
1114
|
-
const domain = (0,
|
|
1115
|
-
const provider = domain ? (0,
|
|
906
|
+
const domain = (0, import_core9.stringOrUndefined)(clientOrProvider);
|
|
907
|
+
const provider = domain ? (0, import_core9.objectOrUndefined)(providerOrUndefined) : (0, import_core9.objectOrUndefined)(clientOrProvider);
|
|
1116
908
|
const maybePromise = this.setAwaitableProvider(domain, provider);
|
|
1117
909
|
Promise.resolve(maybePromise).catch((err) => {
|
|
1118
910
|
this._logger.error("Error during provider initialization:", err);
|
|
@@ -1131,9 +923,9 @@ var OpenFeatureAPI = class _OpenFeatureAPI extends import_core11.OpenFeatureComm
|
|
|
1131
923
|
}
|
|
1132
924
|
getClient(domainOrContext, versionOrContext, contextOrUndefined) {
|
|
1133
925
|
var _a, _b;
|
|
1134
|
-
const domain = (0,
|
|
1135
|
-
const version = (0,
|
|
1136
|
-
const context = (_b = (_a = (0,
|
|
926
|
+
const domain = (0, import_core9.stringOrUndefined)(domainOrContext);
|
|
927
|
+
const version = (0, import_core9.stringOrUndefined)(versionOrContext);
|
|
928
|
+
const context = (_b = (_a = (0, import_core9.objectOrUndefined)(domainOrContext)) != null ? _a : (0, import_core9.objectOrUndefined)(versionOrContext)) != null ? _b : (0, import_core9.objectOrUndefined)(contextOrUndefined);
|
|
1137
929
|
return new OpenFeatureClient(
|
|
1138
930
|
() => this.getProviderForClient(domain),
|
|
1139
931
|
() => this.getProviderStatus(domain),
|
|
@@ -1184,11 +976,8 @@ var OpenFeature = OpenFeatureAPI.getInstance();
|
|
|
1184
976
|
__reExport(index_exports, require("@openfeature/core"), module.exports);
|
|
1185
977
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1186
978
|
0 && (module.exports = {
|
|
1187
|
-
AggregateError,
|
|
1188
979
|
AsyncLocalStorageTransactionContextPropagator,
|
|
1189
|
-
BaseEvaluationStrategy,
|
|
1190
980
|
ComparisonStrategy,
|
|
1191
|
-
ErrorWithCode,
|
|
1192
981
|
FirstMatchStrategy,
|
|
1193
982
|
FirstSuccessfulStrategy,
|
|
1194
983
|
InMemoryProvider,
|
|
@@ -1200,8 +989,6 @@ __reExport(index_exports, require("@openfeature/core"), module.exports);
|
|
|
1200
989
|
OpenFeatureEventEmitter,
|
|
1201
990
|
ProviderEvents,
|
|
1202
991
|
ProviderStatus,
|
|
1203
|
-
constructAggregateError,
|
|
1204
|
-
throwAggregateErrorFromPromiseResults,
|
|
1205
992
|
...require("@openfeature/core")
|
|
1206
993
|
});
|
|
1207
994
|
//# sourceMappingURL=index.js.map
|