@datadog/openfeature-node-server 2.4.0 → 2.5.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/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Channel } from 'node:diagnostics_channel';
2
2
 
3
+ type Metadata = Record<string, string>;
4
+ type Paradigm = "server" | "client";
3
5
  type PrimitiveValue = null | boolean | string | number;
4
6
  type JsonObject = {
5
7
  [key: string]: JsonValue;
@@ -17,155 +19,8 @@ type EvaluationContext = {
17
19
  */
18
20
  targetingKey?: string;
19
21
  } & Record<string, EvaluationContextValue>;
20
- type FlagValue = boolean | string | number | JsonValue;
21
- interface ExposureEvent {
22
- allocation: {
23
- key: string;
24
- };
25
- flag: {
26
- key: string;
27
- };
28
- variant: {
29
- key: string;
30
- };
31
- serial_id?: number;
32
- subject: {
33
- id: string;
34
- attributes: EvaluationContext;
35
- };
36
- service?: string;
37
- rum?: {
38
- application?: {
39
- id?: string;
40
- };
41
- view?: {
42
- url?: string;
43
- };
44
- };
45
- }
46
- declare enum OperatorType {
47
- MATCHES = "MATCHES",
48
- NOT_MATCHES = "NOT_MATCHES",
49
- GTE = "GTE",
50
- GT = "GT",
51
- LTE = "LTE",
52
- LT = "LT",
53
- ONE_OF = "ONE_OF",
54
- NOT_ONE_OF = "NOT_ONE_OF",
55
- IS_NULL = "IS_NULL",
56
- SEMVER_EQ = "SEMVER_EQ",
57
- SEMVER_NEQ = "SEMVER_NEQ",
58
- SEMVER_LT = "SEMVER_LT",
59
- SEMVER_LTE = "SEMVER_LTE",
60
- SEMVER_GT = "SEMVER_GT",
61
- SEMVER_GTE = "SEMVER_GTE"
62
- }
63
- type NumericOperator = OperatorType.GTE | OperatorType.GT | OperatorType.LTE | OperatorType.LT;
64
- type SemVerOperator = OperatorType.SEMVER_EQ | OperatorType.SEMVER_NEQ | OperatorType.SEMVER_GTE | OperatorType.SEMVER_GT | OperatorType.SEMVER_LTE | OperatorType.SEMVER_LT;
65
- type MatchesCondition = {
66
- operator: OperatorType.MATCHES;
67
- attribute: string;
68
- value: string;
69
- };
70
- type NotMatchesCondition = {
71
- operator: OperatorType.NOT_MATCHES;
72
- attribute: string;
73
- value: string;
74
- };
75
- type OneOfCondition = {
76
- operator: OperatorType.ONE_OF;
77
- attribute: string;
78
- value: string[];
79
- };
80
- type NotOneOfCondition = {
81
- operator: OperatorType.NOT_ONE_OF;
82
- attribute: string;
83
- value: string[];
84
- };
85
- type NumericCondition = {
86
- operator: NumericOperator;
87
- attribute: string;
88
- value: number;
89
- };
90
- type NullCondition = {
91
- operator: OperatorType.IS_NULL;
92
- attribute: string;
93
- value: boolean;
94
- };
95
- type SemVerCondition = {
96
- operator: SemVerOperator;
97
- attribute: string;
98
- value: string;
99
- };
100
- type Condition = MatchesCondition | NotMatchesCondition | OneOfCondition | NotOneOfCondition | NumericCondition | NullCondition | SemVerCondition;
101
- interface Rule {
102
- conditions: Condition[];
103
- }
104
- type VariantType = "BOOLEAN" | "INTEGER" | "NUMERIC" | "STRING" | "JSON";
105
- interface VariantConfiguration {
106
- key: string;
107
- value: FlagValue;
108
- }
109
- interface ShardRange {
110
- start: number;
111
- end: number;
112
- }
113
- interface Shard {
114
- salt: string;
115
- ranges: ShardRange[];
116
- totalShards: number;
117
- }
118
- interface Split {
119
- variationKey: string;
120
- shards: Shard[];
121
- extraLogging?: Record<string, string>;
122
- serialId?: number;
123
- }
124
- interface Allocation {
125
- key: string;
126
- rules?: Rule[];
127
- startAt?: Date;
128
- endAt?: Date;
129
- splits: Split[];
130
- doLog?: boolean;
131
- }
132
- interface Flag {
133
- key: string;
134
- enabled: boolean;
135
- variationType: VariantType;
136
- variations: Record<string, VariantConfiguration>;
137
- allocations: Allocation[];
138
- }
139
- export interface UniversalFlagConfigurationV1 {
140
- createdAt: string;
141
- format: string;
142
- observeFullEvaluationData?: boolean;
143
- environment: {
144
- name: string;
145
- };
146
- flags: Record<string, Flag>;
147
- }
148
- type Metadata = Record<string, string>;
149
- type Paradigm = "server" | "client";
150
- type PrimitiveValue$1 = null | boolean | string | number;
151
- type JsonObject$1 = {
152
- [key: string]: JsonValue$1;
153
- };
154
- type JsonArray$1 = JsonValue$1[];
155
- type JsonValue$1 = PrimitiveValue$1 | JsonObject$1 | JsonArray$1;
156
- type EvaluationContextValue$1 = PrimitiveValue$1 | Date | {
157
- [key: string]: EvaluationContextValue$1;
158
- } | EvaluationContextValue$1[];
159
- type EvaluationContext$1 = {
160
- /**
161
- * A string uniquely identifying the subject (end-user, or client service) of a flag evaluation.
162
- * Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users.
163
- * Such providers may behave unpredictably if a targeting key is not specified at flag resolution.
164
- */
165
- targetingKey?: string;
166
- } & Record<string, EvaluationContextValue$1>;
167
22
  type FlagValueType = "boolean" | "string" | "number" | "object";
168
- type FlagValue$1 = boolean | string | number | JsonValue$1;
23
+ type FlagValue = boolean | string | number | JsonValue;
169
24
  type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>);
170
25
  type FlagMetadata = Record<string, string | number | boolean>;
171
26
  type ResolutionDetails<U> = {
@@ -176,7 +31,7 @@ type ResolutionDetails<U> = {
176
31
  errorCode?: ErrorCode;
177
32
  errorMessage?: string;
178
33
  };
179
- type EvaluationDetails<T extends FlagValue$1> = {
34
+ type EvaluationDetails<T extends FlagValue> = {
180
35
  flagKey: string;
181
36
  flagMetadata: Readonly<FlagMetadata>;
182
37
  } & ResolutionDetails<T>;
@@ -362,7 +217,7 @@ interface ProviderEventEmitter<E extends AnyProviderEvent, AdditionalContext ext
362
217
  removeAllHandlers(eventType?: AnyProviderEvent): void;
363
218
  getHandlers(eventType: AnyProviderEvent): EventHandler[];
364
219
  }
365
- type TrackingEventValue = PrimitiveValue$1 | Date | {
220
+ type TrackingEventValue = PrimitiveValue | Date | {
366
221
  [key: string]: TrackingEventValue;
367
222
  } | TrackingEventValue[];
368
223
  type TrackingEventDetails = {
@@ -454,14 +309,14 @@ interface CommonProvider<S extends ClientProviderStatus | ServerProviderStatus>
454
309
  * Use this function to perform any context-dependent setup within the provider.
455
310
  * @param context
456
311
  */
457
- initialize?(context?: EvaluationContext$1): Promise<void>;
312
+ initialize?(context?: EvaluationContext): Promise<void>;
458
313
  /**
459
314
  * Track a user action or application state, usually representing a business objective or outcome.
460
315
  * @param trackingEventName
461
316
  * @param context
462
317
  * @param trackingEventDetails
463
318
  */
464
- track?(trackingEventName: string, context: EvaluationContext$1, trackingEventDetails: TrackingEventDetails): void;
319
+ track?(trackingEventName: string, context: EvaluationContext, trackingEventDetails: TrackingEventDetails): void;
465
320
  }
466
321
  interface ClientMetadata {
467
322
  /**
@@ -521,20 +376,20 @@ interface HookData<TData = Record<string, unknown>> {
521
376
  clear(): void;
522
377
  }
523
378
  type HookHints = Readonly<Record<string, unknown>>;
524
- interface HookContext<T extends FlagValue$1 = FlagValue$1, TData = Record<string, unknown>> {
379
+ interface HookContext<T extends FlagValue = FlagValue, TData = Record<string, unknown>> {
525
380
  readonly flagKey: string;
526
381
  readonly defaultValue: T;
527
382
  readonly flagValueType: FlagValueType;
528
- readonly context: Readonly<EvaluationContext$1>;
383
+ readonly context: Readonly<EvaluationContext>;
529
384
  readonly clientMetadata: ClientMetadata;
530
385
  readonly providerMetadata: ProviderMetadata;
531
386
  readonly logger: Logger;
532
387
  readonly hookData: HookData<TData>;
533
388
  }
534
- interface BeforeHookContext<T extends FlagValue$1 = FlagValue$1, TData = Record<string, unknown>> extends HookContext<T, TData> {
535
- context: EvaluationContext$1;
389
+ interface BeforeHookContext<T extends FlagValue = FlagValue, TData = Record<string, unknown>> extends HookContext<T, TData> {
390
+ context: EvaluationContext;
536
391
  }
537
- interface BaseHook<T extends FlagValue$1 = FlagValue$1, TData = Record<string, unknown>, BeforeHookReturn = unknown, HooksReturn = unknown> {
392
+ interface BaseHook<T extends FlagValue = FlagValue, TData = Record<string, unknown>, BeforeHookReturn = unknown, HooksReturn = unknown> {
538
393
  /**
539
394
  * Runs before flag values are resolved from the provider.
540
395
  * If an EvaluationContext is returned, it will be merged with the pre-existing EvaluationContext.
@@ -564,7 +419,134 @@ interface BaseHook<T extends FlagValue$1 = FlagValue$1, TData = Record<string, u
564
419
  */
565
420
  finally?(hookContext: Readonly<HookContext<T, TData>>, evaluationDetails: EvaluationDetails<T>, hookHints?: HookHints): HooksReturn;
566
421
  }
567
- type Hook<TData = Record<string, unknown>> = BaseHook<FlagValue$1, TData, Promise<EvaluationContext$1 | void> | EvaluationContext$1 | void, Promise<void> | void>;
422
+ interface ExposureEvent {
423
+ allocation: {
424
+ key: string;
425
+ };
426
+ flag: {
427
+ key: string;
428
+ };
429
+ variant: {
430
+ key: string;
431
+ };
432
+ serial_id?: number;
433
+ subject: {
434
+ id: string;
435
+ attributes: EvaluationContext;
436
+ };
437
+ service?: string;
438
+ rum?: {
439
+ application?: {
440
+ id?: string;
441
+ };
442
+ view?: {
443
+ url?: string;
444
+ };
445
+ };
446
+ }
447
+ declare enum OperatorType {
448
+ MATCHES = "MATCHES",
449
+ NOT_MATCHES = "NOT_MATCHES",
450
+ GTE = "GTE",
451
+ GT = "GT",
452
+ LTE = "LTE",
453
+ LT = "LT",
454
+ ONE_OF = "ONE_OF",
455
+ NOT_ONE_OF = "NOT_ONE_OF",
456
+ IS_NULL = "IS_NULL",
457
+ SEMVER_EQ = "SEMVER_EQ",
458
+ SEMVER_NEQ = "SEMVER_NEQ",
459
+ SEMVER_LT = "SEMVER_LT",
460
+ SEMVER_LTE = "SEMVER_LTE",
461
+ SEMVER_GT = "SEMVER_GT",
462
+ SEMVER_GTE = "SEMVER_GTE"
463
+ }
464
+ type NumericOperator = OperatorType.GTE | OperatorType.GT | OperatorType.LTE | OperatorType.LT;
465
+ type SemVerOperator = OperatorType.SEMVER_EQ | OperatorType.SEMVER_NEQ | OperatorType.SEMVER_GTE | OperatorType.SEMVER_GT | OperatorType.SEMVER_LTE | OperatorType.SEMVER_LT;
466
+ type MatchesCondition = {
467
+ operator: OperatorType.MATCHES;
468
+ attribute: string;
469
+ value: string;
470
+ };
471
+ type NotMatchesCondition = {
472
+ operator: OperatorType.NOT_MATCHES;
473
+ attribute: string;
474
+ value: string;
475
+ };
476
+ type OneOfCondition = {
477
+ operator: OperatorType.ONE_OF;
478
+ attribute: string;
479
+ value: string[];
480
+ };
481
+ type NotOneOfCondition = {
482
+ operator: OperatorType.NOT_ONE_OF;
483
+ attribute: string;
484
+ value: string[];
485
+ };
486
+ type NumericCondition = {
487
+ operator: NumericOperator;
488
+ attribute: string;
489
+ value: number;
490
+ };
491
+ type NullCondition = {
492
+ operator: OperatorType.IS_NULL;
493
+ attribute: string;
494
+ value: boolean;
495
+ };
496
+ type SemVerCondition = {
497
+ operator: SemVerOperator;
498
+ attribute: string;
499
+ value: string;
500
+ };
501
+ type Condition = MatchesCondition | NotMatchesCondition | OneOfCondition | NotOneOfCondition | NumericCondition | NullCondition | SemVerCondition;
502
+ interface Rule {
503
+ conditions: Condition[];
504
+ }
505
+ type VariantType = "BOOLEAN" | "INTEGER" | "NUMERIC" | "STRING" | "JSON";
506
+ interface VariantConfiguration {
507
+ key: string;
508
+ value: FlagValue;
509
+ }
510
+ interface ShardRange {
511
+ start: number;
512
+ end: number;
513
+ }
514
+ interface Shard {
515
+ salt: string;
516
+ ranges: ShardRange[];
517
+ totalShards: number;
518
+ }
519
+ interface Split {
520
+ variationKey: string;
521
+ shards: Shard[];
522
+ extraLogging?: Record<string, string>;
523
+ serialId?: number;
524
+ }
525
+ interface Allocation {
526
+ key: string;
527
+ rules?: Rule[];
528
+ startAt?: Date;
529
+ endAt?: Date;
530
+ splits: Split[];
531
+ doLog?: boolean;
532
+ }
533
+ interface Flag {
534
+ key: string;
535
+ enabled: boolean;
536
+ variationType: VariantType;
537
+ variations: Record<string, VariantConfiguration>;
538
+ allocations: Allocation[];
539
+ }
540
+ export interface UniversalFlagConfigurationV1 {
541
+ createdAt: string;
542
+ format: string;
543
+ observeFullEvaluationData?: boolean;
544
+ environment: {
545
+ name: string;
546
+ };
547
+ flags: Record<string, Flag>;
548
+ }
549
+ type Hook<TData = Record<string, unknown>> = BaseHook<FlagValue, TData, Promise<EvaluationContext | void> | EvaluationContext | void, Promise<void> | void>;
568
550
  interface Provider extends CommonProvider<ServerProviderStatus> {
569
551
  /**
570
552
  * A provider hook exposes a mechanism for provider authors to register hooks
@@ -576,19 +558,19 @@ interface Provider extends CommonProvider<ServerProviderStatus> {
576
558
  /**
577
559
  * Resolve a boolean flag and its evaluation details.
578
560
  */
579
- resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext$1, logger: Logger): Promise<ResolutionDetails<boolean>>;
561
+ resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<boolean>>;
580
562
  /**
581
563
  * Resolve a string flag and its evaluation details.
582
564
  */
583
- resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext$1, logger: Logger): Promise<ResolutionDetails<string>>;
565
+ resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<string>>;
584
566
  /**
585
567
  * Resolve a numeric flag and its evaluation details.
586
568
  */
587
- resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext$1, logger: Logger): Promise<ResolutionDetails<number>>;
569
+ resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<number>>;
588
570
  /**
589
571
  * Resolve and parse an object flag and its evaluation details.
590
572
  */
591
- resolveObjectEvaluation<T extends JsonValue$1>(flagKey: string, defaultValue: T, context: EvaluationContext$1, logger: Logger): Promise<ResolutionDetails<T>>;
573
+ resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<T>>;
592
574
  }
593
575
  export interface DatadogNodeServerProviderOptions {
594
576
  /**
@@ -634,10 +616,10 @@ export declare class DatadogNodeServerProvider implements Provider {
634
616
  * See setConfiguration and setError for more details.
635
617
  */
636
618
  initialize(): Promise<void>;
637
- resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext$1, _logger: Logger): Promise<ResolutionDetails<boolean>>;
638
- resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext$1, _logger: Logger): Promise<ResolutionDetails<string>>;
639
- resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext$1, _logger: Logger): Promise<ResolutionDetails<number>>;
640
- resolveObjectEvaluation<T extends JsonValue$1>(flagKey: string, defaultValue: T, context: EvaluationContext$1, _logger: Logger): Promise<ResolutionDetails<T>>;
619
+ resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext, _logger: Logger): Promise<ResolutionDetails<boolean>>;
620
+ resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext, _logger: Logger): Promise<ResolutionDetails<string>>;
621
+ resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext, _logger: Logger): Promise<ResolutionDetails<number>>;
622
+ resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext, _logger: Logger): Promise<ResolutionDetails<T>>;
641
623
  private handleExposure;
642
624
  }
643
625
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/openfeature-node-server",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Node.js server bindings for OpenFeature (wraps @datadog/flagging-core)",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/DataDog/openfeature-js-client#readme",
@@ -15,6 +15,26 @@
15
15
  "main": "cjs/index.js",
16
16
  "module": "esm/index.js",
17
17
  "types": "index.d.ts",
18
+ "typesVersions": {
19
+ "*": {
20
+ "rules-based": [
21
+ "rules-based.d.ts"
22
+ ]
23
+ }
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "types": "./index.d.ts",
28
+ "module": "./esm/index.js",
29
+ "default": "./cjs/index.js"
30
+ },
31
+ "./rules-based": {
32
+ "types": "./rules-based.d.ts",
33
+ "module": "./esm/rules-based.js",
34
+ "default": "./cjs/rules-based.js"
35
+ },
36
+ "./package.json": "./package.json"
37
+ },
18
38
  "sideEffects": false,
19
39
  "files": [
20
40
  "cjs/",
@@ -30,15 +50,15 @@
30
50
  "build": "run-p build:cjs build:esm && yarn build:types",
31
51
  "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs",
32
52
  "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm",
33
- "//build:types": "Bundles @openfeature/* types into a self-contained index.d.ts with no external imports, required for SSI where dd-trace's node_modules can't reach the customer's @openfeature/server-sdk. See https://github.com/DataDog/dd-trace-js/pull/9570",
34
- "build:types": "trap 'rm -f src/.dts-entry.ts' EXIT; printf '/// <reference path=\"./global.d.ts\" />\\nexport * from \"./index\"\\n' > src/.dts-entry.ts && dts-bundle-generator -o index.d.ts src/.dts-entry.ts --external-inlines @openfeature/core @openfeature/server-sdk --no-banner --export-referenced-types false",
53
+ "//build:types": "Bundles self-contained declarations for each entrypoint, required for SSI where dd-trace's node_modules can't reach the customer's @openfeature/server-sdk. See https://github.com/DataDog/dd-trace-js/pull/9570",
54
+ "build:types": "node scripts/build-types.js",
35
55
  "replace-build-env": "node ../../scripts/build/replace-build-env.js",
36
- "clean": "rm -rf dist cjs esm index.d.ts",
56
+ "clean": "rm -rf dist cjs esm index.d.ts rules-based.d.ts",
37
57
  "test": "jest --passWithNoTests",
38
58
  "typecheck": "tsc --noEmit"
39
59
  },
40
60
  "dependencies": {
41
- "@datadog/flagging-core": "3.1.0"
61
+ "@datadog/flagging-core": "3.2.0"
42
62
  },
43
63
  "devDependencies": {
44
64
  "@openfeature/core": "1.11.0",