@datadog/mobile-react-native 3.7.0 → 3.8.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.
Files changed (35) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  2. package/ios/Sources/DdFlagsImplementation.swift +3 -4
  3. package/ios/Sources/DdLogsImplementation.swift +8 -8
  4. package/ios/Sources/DdRumImplementation.swift +23 -23
  5. package/ios/Sources/DdSdkImplementation.swift +20 -21
  6. package/ios/Sources/DdTraceImplementation.swift +2 -2
  7. package/ios/Sources/RCTPromiseTypes.swift +18 -0
  8. package/ios/Sources/SdkVersion.swift +1 -1
  9. package/lib/commonjs/flags/internal.js +9 -1
  10. package/lib/commonjs/flags/internal.js.map +1 -1
  11. package/lib/commonjs/flags/rumIntegration.js +104 -0
  12. package/lib/commonjs/flags/rumIntegration.js.map +1 -0
  13. package/lib/commonjs/index.js +7 -0
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/version.js +1 -1
  16. package/lib/module/flags/internal.js +9 -1
  17. package/lib/module/flags/internal.js.map +1 -1
  18. package/lib/module/flags/rumIntegration.js +97 -0
  19. package/lib/module/flags/rumIntegration.js.map +1 -0
  20. package/lib/module/index.js +2 -1
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/version.js +1 -1
  23. package/lib/typescript/flags/internal.d.ts.map +1 -1
  24. package/lib/typescript/flags/rumIntegration.d.ts +14 -0
  25. package/lib/typescript/flags/rumIntegration.d.ts.map +1 -0
  26. package/lib/typescript/index.d.ts +2 -1
  27. package/lib/typescript/index.d.ts.map +1 -1
  28. package/lib/typescript/version.d.ts +1 -1
  29. package/package.json +2 -2
  30. package/src/flags/__tests__/internal.test.ts +39 -0
  31. package/src/flags/__tests__/rumIntegration.test.ts +493 -0
  32. package/src/flags/internal.ts +12 -1
  33. package/src/flags/rumIntegration.ts +140 -0
  34. package/src/index.tsx +3 -1
  35. package/src/version.ts +1 -1
@@ -0,0 +1,493 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import { InternalLog } from '../../InternalLog';
8
+ import { SdkVerbosity } from '../../config/types/SdkVerbosity';
9
+ import { UserInfoSingleton } from '../../sdk/UserInfoSingleton/UserInfoSingleton';
10
+ import { __ddEnrichEvaluationContextWithRumUser } from '../rumIntegration';
11
+
12
+ describe('__ddEnrichEvaluationContextWithRumUser', () => {
13
+ beforeEach(() => {
14
+ UserInfoSingleton.reset();
15
+ jest.spyOn(InternalLog, 'log').mockImplementation(() => {});
16
+ });
17
+
18
+ afterEach(() => {
19
+ jest.restoreAllMocks();
20
+ });
21
+
22
+ it('normalizes the application context when no RUM user is available', () => {
23
+ const context = {
24
+ targetingKey: 'explicit-user',
25
+ email: undefined
26
+ };
27
+
28
+ expect(__ddEnrichEvaluationContextWithRumUser(context)).toStrictEqual({
29
+ targetingKey: 'explicit-user'
30
+ });
31
+ expect(context).toStrictEqual({
32
+ targetingKey: 'explicit-user',
33
+ email: undefined
34
+ });
35
+ expect(InternalLog.log).not.toHaveBeenCalled();
36
+ });
37
+
38
+ it('silently removes RUM defaults after clearing the user', () => {
39
+ const applicationContext = { region: 'us', email: undefined };
40
+ UserInfoSingleton.getInstance().setUserInfo({
41
+ id: 'rum-user',
42
+ extraInfo: { plan: 'pro' }
43
+ });
44
+ expect(
45
+ __ddEnrichEvaluationContextWithRumUser(applicationContext)
46
+ ).toStrictEqual({
47
+ targetingKey: 'rum-user',
48
+ plan: 'pro',
49
+ region: 'us'
50
+ });
51
+
52
+ UserInfoSingleton.getInstance().clearUserInfo();
53
+
54
+ expect(
55
+ __ddEnrichEvaluationContextWithRumUser(applicationContext)
56
+ ).toStrictEqual({ region: 'us' });
57
+ expect(InternalLog.log).not.toHaveBeenCalled();
58
+ });
59
+
60
+ it('adds flat primitive RUM user properties and lets explicit context win', () => {
61
+ UserInfoSingleton.getInstance().setUserInfo({
62
+ id: 'rum-user',
63
+ name: 'RUM Name',
64
+ email: 'rum@example.com',
65
+ extraInfo: {
66
+ company_name: 'Example, Inc.',
67
+ age: 42,
68
+ active: true,
69
+ nullable: null,
70
+ missing: undefined,
71
+ profile: { plan: 'enterprise' },
72
+ roles: ['admin']
73
+ }
74
+ });
75
+
76
+ expect(
77
+ __ddEnrichEvaluationContextWithRumUser({
78
+ targetingKey: 'explicit-user',
79
+ email: 'explicit@example.com',
80
+ request_attribute: 'request-value'
81
+ })
82
+ ).toEqual({
83
+ targetingKey: 'explicit-user',
84
+ name: 'RUM Name',
85
+ email: 'explicit@example.com',
86
+ company_name: 'Example, Inc.',
87
+ age: 42,
88
+ active: true,
89
+ request_attribute: 'request-value'
90
+ });
91
+ expect(InternalLog.log).toHaveBeenCalledTimes(4);
92
+ for (const key of ['nullable', 'missing', 'profile', 'roles']) {
93
+ expect(InternalLog.log).toHaveBeenCalledWith(
94
+ expect.stringContaining(
95
+ `RUM user property "${key}" is not a string, number, or boolean`
96
+ ),
97
+ SdkVerbosity.WARN
98
+ );
99
+ }
100
+ });
101
+
102
+ it('omits null RUM attributes without changing application values', () => {
103
+ const extraInfo = {
104
+ nullable: null,
105
+ overridden: null,
106
+ removed: null,
107
+ plan: 'pro'
108
+ };
109
+ UserInfoSingleton.getInstance().setUserInfo({
110
+ id: 'rum-user',
111
+ extraInfo
112
+ });
113
+ const context = {
114
+ overridden: 'application-value',
115
+ removed: undefined,
116
+ plan: null
117
+ };
118
+
119
+ expect(__ddEnrichEvaluationContextWithRumUser(context)).toStrictEqual({
120
+ targetingKey: 'rum-user',
121
+ overridden: 'application-value',
122
+ plan: null
123
+ });
124
+ expect(context).toStrictEqual({
125
+ overridden: 'application-value',
126
+ removed: undefined,
127
+ plan: null
128
+ });
129
+ expect(extraInfo).toStrictEqual({
130
+ nullable: null,
131
+ overridden: null,
132
+ removed: null,
133
+ plan: 'pro'
134
+ });
135
+ expect(InternalLog.log).toHaveBeenCalledTimes(3);
136
+ for (const key of ['nullable', 'overridden', 'removed']) {
137
+ expect(InternalLog.log).toHaveBeenCalledWith(
138
+ expect.stringContaining(
139
+ `RUM user property "${key}" is not a string, number, or boolean`
140
+ ),
141
+ SdkVerbosity.WARN
142
+ );
143
+ }
144
+ });
145
+
146
+ it('preserves an explicitly empty targeting key', () => {
147
+ UserInfoSingleton.getInstance().setUserInfo({ id: 'rum-user' });
148
+
149
+ expect(
150
+ __ddEnrichEvaluationContextWithRumUser({ targetingKey: '' })
151
+ ).toEqual({ targetingKey: '' });
152
+ });
153
+
154
+ it('uses explicitly undefined fields to remove RUM defaults', () => {
155
+ UserInfoSingleton.getInstance().setUserInfo({
156
+ id: 'rum-user',
157
+ email: 'rum@example.com',
158
+ extraInfo: { plan: 'pro' }
159
+ });
160
+
161
+ expect(
162
+ __ddEnrichEvaluationContextWithRumUser({
163
+ targetingKey: undefined,
164
+ email: undefined,
165
+ plan: undefined,
166
+ request_attribute: 'request-value'
167
+ })
168
+ ).toStrictEqual({ request_attribute: 'request-value' });
169
+ });
170
+
171
+ it('uses the latest RUM user each time it is called', () => {
172
+ UserInfoSingleton.getInstance().setUserInfo({ id: 'rum-user-a' });
173
+ expect(__ddEnrichEvaluationContextWithRumUser({})).toEqual({
174
+ targetingKey: 'rum-user-a'
175
+ });
176
+
177
+ UserInfoSingleton.getInstance().setUserInfo({
178
+ id: 'rum-user-b',
179
+ extraInfo: { plan: 'pro' }
180
+ });
181
+ expect(__ddEnrichEvaluationContextWithRumUser({})).toEqual({
182
+ targetingKey: 'rum-user-b',
183
+ plan: 'pro'
184
+ });
185
+ });
186
+
187
+ it.each(['extraInfo', 'custom property'])(
188
+ 'keeps the RUM user fields when %s cannot be read',
189
+ unreadable => {
190
+ const user = {
191
+ id: 'rum-user',
192
+ name: 'RUM Name',
193
+ email: 'rum@example.com',
194
+ extraInfo: { plan: 'pro' }
195
+ };
196
+ Object.defineProperty(
197
+ unreadable === 'extraInfo' ? user : user.extraInfo,
198
+ unreadable === 'extraInfo' ? 'extraInfo' : 'broken',
199
+ {
200
+ enumerable: true,
201
+ get: () => {
202
+ throw new Error('cannot read user property');
203
+ }
204
+ }
205
+ );
206
+ UserInfoSingleton.getInstance().setUserInfo(user);
207
+
208
+ expect(
209
+ __ddEnrichEvaluationContextWithRumUser({ region: 'us' })
210
+ ).toStrictEqual({
211
+ targetingKey: 'rum-user',
212
+ name: 'RUM Name',
213
+ email: 'rum@example.com',
214
+ region: 'us'
215
+ });
216
+ expect(InternalLog.log).toHaveBeenCalledTimes(1);
217
+ expect(InternalLog.log).toHaveBeenCalledWith(
218
+ 'Some RUM user properties could not be read (cannot read user property) and were not added to the evaluation context.',
219
+ SdkVerbosity.WARN
220
+ );
221
+ }
222
+ );
223
+
224
+ it('preserves application overrides and tombstones when extraInfo cannot be read', () => {
225
+ UserInfoSingleton.getInstance().setUserInfo({
226
+ id: 'rum-user',
227
+ name: 'RUM Name',
228
+ email: 'rum@example.com',
229
+ get extraInfo() {
230
+ throw new Error('cannot read extraInfo');
231
+ }
232
+ });
233
+ const context = {
234
+ targetingKey: 'explicit-user',
235
+ name: undefined,
236
+ email: 'application@example.com'
237
+ };
238
+
239
+ expect(__ddEnrichEvaluationContextWithRumUser(context)).toStrictEqual({
240
+ targetingKey: 'explicit-user',
241
+ email: 'application@example.com'
242
+ });
243
+ expect(context).toHaveProperty('name', undefined);
244
+ });
245
+
246
+ it.each(['name', 'email', 'id'])(
247
+ 'keeps custom properties when the RUM user %s cannot be read',
248
+ field => {
249
+ const user = {
250
+ id: 'rum-user',
251
+ name: 'RUM Name',
252
+ email: 'rum@example.com',
253
+ extraInfo: {
254
+ plan: 'pro',
255
+ targetingKey: 'custom-user',
256
+ name: 'custom-name',
257
+ email: 'custom@example.com'
258
+ }
259
+ };
260
+ UserInfoSingleton.getInstance().setUserInfo(user);
261
+ Object.defineProperty(user, field, {
262
+ get: () => {
263
+ throw new Error(`cannot read ${field}`);
264
+ }
265
+ });
266
+
267
+ expect(
268
+ __ddEnrichEvaluationContextWithRumUser({ region: 'us' })
269
+ ).toStrictEqual({
270
+ plan: 'pro',
271
+ targetingKey: 'custom-user',
272
+ name: 'custom-name',
273
+ email: 'custom@example.com',
274
+ region: 'us'
275
+ });
276
+ expect(InternalLog.log).toHaveBeenCalledTimes(1);
277
+ expect(InternalLog.log).toHaveBeenCalledWith(
278
+ `Some RUM user fields could not be read (cannot read ${field}) and were not added to the evaluation context.`,
279
+ SdkVerbosity.WARN
280
+ );
281
+ }
282
+ );
283
+
284
+ it.each(['custom-value', '', 42, true, false])(
285
+ 'merges custom identity attributes with value %p when RUM identity fields are absent',
286
+ value => {
287
+ const extraInfo = {
288
+ targetingKey: value,
289
+ name: value,
290
+ email: value,
291
+ plan: 'pro'
292
+ };
293
+ UserInfoSingleton.getInstance().addUserExtraInfo(extraInfo);
294
+
295
+ expect(__ddEnrichEvaluationContextWithRumUser({})).toStrictEqual(
296
+ extraInfo
297
+ );
298
+ expect(InternalLog.log).not.toHaveBeenCalled();
299
+ }
300
+ );
301
+
302
+ it('keeps RUM and application targeting keys when the custom targeting key is invalid', () => {
303
+ UserInfoSingleton.getInstance().setUserInfo({
304
+ id: 'rum-user',
305
+ extraInfo: { targetingKey: 42 }
306
+ });
307
+
308
+ expect(__ddEnrichEvaluationContextWithRumUser({})).toStrictEqual({
309
+ targetingKey: 'rum-user'
310
+ });
311
+ expect(
312
+ __ddEnrichEvaluationContextWithRumUser({
313
+ targetingKey: 'application-user'
314
+ })
315
+ ).toStrictEqual({ targetingKey: 'application-user' });
316
+ expect(
317
+ __ddEnrichEvaluationContextWithRumUser({ targetingKey: undefined })
318
+ ).toStrictEqual({});
319
+ expect(InternalLog.log).not.toHaveBeenCalled();
320
+ });
321
+
322
+ it.each([42, true, false])(
323
+ 'preserves an application targeting key of %p over RUM defaults without validating it',
324
+ targetingKey => {
325
+ UserInfoSingleton.getInstance().setUserInfo({
326
+ id: 'rum-user',
327
+ extraInfo: { targetingKey: 'custom-user' }
328
+ });
329
+ // JavaScript callers can provide values outside the TypeScript contract.
330
+ const context = { targetingKey: targetingKey as never };
331
+
332
+ expect(
333
+ __ddEnrichEvaluationContextWithRumUser(context)
334
+ ).toStrictEqual(context);
335
+ expect(InternalLog.log).not.toHaveBeenCalled();
336
+ }
337
+ );
338
+
339
+ it('merges extraInfo, then RUM identity fields, then application context', () => {
340
+ UserInfoSingleton.getInstance().setUserInfo({
341
+ id: 'rum-user',
342
+ name: 'RUM Name',
343
+ email: 'rum@example.com',
344
+ extraInfo: {
345
+ targetingKey: 'custom-user',
346
+ name: 'custom-name',
347
+ email: 'custom@example.com',
348
+ plan: 'pro'
349
+ }
350
+ });
351
+
352
+ expect(__ddEnrichEvaluationContextWithRumUser({})).toStrictEqual({
353
+ targetingKey: 'rum-user',
354
+ name: 'RUM Name',
355
+ email: 'rum@example.com',
356
+ plan: 'pro'
357
+ });
358
+ expect(
359
+ __ddEnrichEvaluationContextWithRumUser({
360
+ targetingKey: 'application-user',
361
+ name: 'Application Name',
362
+ email: 'application@example.com'
363
+ })
364
+ ).toStrictEqual({
365
+ targetingKey: 'application-user',
366
+ name: 'Application Name',
367
+ email: 'application@example.com',
368
+ plan: 'pro'
369
+ });
370
+ expect(
371
+ __ddEnrichEvaluationContextWithRumUser({
372
+ targetingKey: undefined,
373
+ name: undefined,
374
+ email: undefined
375
+ })
376
+ ).toStrictEqual({ plan: 'pro' });
377
+ expect(InternalLog.log).not.toHaveBeenCalled();
378
+ });
379
+
380
+ it('reads each RUM user field once and uses the validated value', () => {
381
+ const getters = {
382
+ id: jest.fn().mockReturnValueOnce('rum-user').mockReturnValue(42),
383
+ name: jest.fn().mockReturnValueOnce('RUM Name').mockReturnValue(42),
384
+ email: jest
385
+ .fn()
386
+ .mockReturnValueOnce('rum@example.com')
387
+ .mockReturnValue(42)
388
+ };
389
+ const user = {};
390
+ for (const [key, get] of Object.entries(getters)) {
391
+ Object.defineProperty(user, key, { get });
392
+ }
393
+ jest.spyOn(
394
+ UserInfoSingleton.getInstance(),
395
+ 'getUserInfo'
396
+ ).mockReturnValue(user);
397
+
398
+ expect(__ddEnrichEvaluationContextWithRumUser({})).toStrictEqual({
399
+ targetingKey: 'rum-user',
400
+ name: 'RUM Name',
401
+ email: 'rum@example.com'
402
+ });
403
+ for (const get of Object.values(getters)) {
404
+ expect(get).toHaveBeenCalledTimes(1);
405
+ }
406
+ expect(InternalLog.log).not.toHaveBeenCalled();
407
+ });
408
+
409
+ it('normalizes application context and logs once when reading the RUM user fails', () => {
410
+ jest.spyOn(
411
+ UserInfoSingleton.getInstance(),
412
+ 'getUserInfo'
413
+ ).mockImplementation(() => {
414
+ throw new Error('cannot read user');
415
+ });
416
+
417
+ expect(
418
+ __ddEnrichEvaluationContextWithRumUser({
419
+ targetingKey: 'explicit-user',
420
+ email: undefined
421
+ })
422
+ ).toStrictEqual({ targetingKey: 'explicit-user' });
423
+ expect(InternalLog.log).toHaveBeenCalledTimes(1);
424
+ expect(InternalLog.log).toHaveBeenCalledWith(
425
+ 'Could not read the RUM user (cannot read user). No RUM values were added to the evaluation context.',
426
+ SdkVerbosity.WARN
427
+ );
428
+ });
429
+
430
+ it('returns unreadable application context unchanged and logs the fallback', () => {
431
+ UserInfoSingleton.getInstance().setUserInfo({ id: 'rum-user' });
432
+ const context = {
433
+ region: 'us',
434
+ email: undefined,
435
+ get broken() {
436
+ throw new Error('cannot read application context');
437
+ }
438
+ };
439
+
440
+ expect(__ddEnrichEvaluationContextWithRumUser(context)).toBe(context);
441
+ expect(InternalLog.log).toHaveBeenCalledTimes(1);
442
+ expect(InternalLog.log).toHaveBeenCalledWith(
443
+ 'Could not read the application evaluation context (cannot read application context). Returning it unchanged, without the RUM user.',
444
+ SdkVerbosity.WARN
445
+ );
446
+ });
447
+
448
+ it.each([
449
+ ['non-Error value', 'failure'],
450
+ [
451
+ 'unreadable message',
452
+ Object.defineProperty(new Error(), 'message', {
453
+ get: () => {
454
+ throw new Error('cannot read message');
455
+ }
456
+ })
457
+ ],
458
+ [
459
+ 'uncoercible message',
460
+ Object.defineProperty(new Error(), 'message', {
461
+ value: {
462
+ toString: () => {
463
+ throw new Error('cannot coerce message');
464
+ }
465
+ }
466
+ })
467
+ ],
468
+ [
469
+ 'unreadable prototype',
470
+ new Proxy(new Error(), {
471
+ getPrototypeOf: () => {
472
+ throw new Error('cannot read prototype');
473
+ }
474
+ })
475
+ ]
476
+ ])('safely logs a %s thrown by a user getter', (_description, error) => {
477
+ UserInfoSingleton.getInstance().setUserInfo({
478
+ id: 'rum-user',
479
+ get extraInfo() {
480
+ throw error;
481
+ }
482
+ });
483
+
484
+ expect(__ddEnrichEvaluationContextWithRumUser({})).toStrictEqual({
485
+ targetingKey: 'rum-user'
486
+ });
487
+ expect(InternalLog.log).toHaveBeenCalledTimes(1);
488
+ expect(InternalLog.log).toHaveBeenCalledWith(
489
+ 'Some RUM user properties could not be read (unknown error) and were not added to the evaluation context.',
490
+ SdkVerbosity.WARN
491
+ );
492
+ });
493
+ });
@@ -24,7 +24,18 @@ export interface FlagCacheEntry {
24
24
  export const processEvaluationContext = (
25
25
  context: EvaluationContext
26
26
  ): EvaluationContext => {
27
- const { targetingKey } = context;
27
+ let { targetingKey } = context;
28
+
29
+ // Validate only the final targeting key, after any RUM/application merge. Its source must
30
+ // not affect validation or cause a fallback to a lower-precedence user's identity.
31
+ // Both online and offline clients share this boundary; native calls require a string.
32
+ if (typeof targetingKey !== 'string') {
33
+ InternalLog.log(
34
+ "The evaluation context targetingKey is not a string. Using the anonymous subject ('') instead.",
35
+ SdkVerbosity.WARN
36
+ );
37
+ targetingKey = '';
38
+ }
28
39
 
29
40
  // We should ignore non-primitive values in the context as per FFE SDK requirements OF.3.
30
41
  const providedAttributes: Record<string, unknown> =
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import { InternalLog } from '../InternalLog';
8
+ import { SdkVerbosity } from '../config/types/SdkVerbosity';
9
+ import { UserInfoSingleton } from '../sdk/UserInfoSingleton/UserInfoSingleton';
10
+ import type { UserInfo } from '../sdk/UserInfoSingleton/types';
11
+
12
+ type FlatEvaluationContext = Record<string, unknown> & {
13
+ targetingKey?: string | undefined;
14
+ };
15
+
16
+ /**
17
+ * Add the current RUM user to an OpenFeature-shaped evaluation context.
18
+ *
19
+ * @internal Used by the explicit helper in the Datadog OpenFeature package. This is a point-in-time
20
+ * read; it does not synchronize OpenFeature when the RUM user changes. RUM values provide defaults;
21
+ * fields explicitly supplied by the application remain authoritative. An explicitly undefined
22
+ * field removes the corresponding RUM default and is omitted from the effective context.
23
+ */
24
+ export const __ddEnrichEvaluationContextWithRumUser = (
25
+ context: FlatEvaluationContext
26
+ ): FlatEvaluationContext => {
27
+ const effectiveContext = new Map(getRumContextEntries());
28
+
29
+ try {
30
+ for (const [key, value] of Object.entries(context)) {
31
+ if (value === undefined) {
32
+ effectiveContext.delete(key);
33
+ } else {
34
+ effectiveContext.set(key, value);
35
+ }
36
+ }
37
+
38
+ return Object.fromEntries(effectiveContext);
39
+ } catch (error) {
40
+ InternalLog.log(
41
+ `Could not read the application evaluation context (${errorMessage(
42
+ error
43
+ )}). Returning it unchanged, without the RUM user.`,
44
+ SdkVerbosity.WARN
45
+ );
46
+
47
+ return context;
48
+ }
49
+ };
50
+
51
+ const getRumContextEntries = (): Array<[string, unknown]> => {
52
+ const user = readRumUser();
53
+ if (!user) {
54
+ return [];
55
+ }
56
+
57
+ const entries: Array<[string, unknown]> = [];
58
+
59
+ // Do not add identity-key-specific filtering here: targetingKey, name, and email follow
60
+ // the same merge precedence as other attributes (extraInfo -> RUM fields -> application).
61
+ // Merge precedence and validation are separate: processEvaluationContext validates the final
62
+ // targetingKey regardless of its source, without warning about values overwritten in the merge.
63
+ // Isolate custom properties from the user's own fields: either group may invoke getters.
64
+ try {
65
+ for (const [key, value] of Object.entries(user.extraInfo ?? {})) {
66
+ if (!isSupportedAttribute(value)) {
67
+ InternalLog.log(
68
+ `RUM user property "${key}" is not a string, number, or boolean. Omitting it from the evaluation context.`,
69
+ SdkVerbosity.WARN
70
+ );
71
+ continue;
72
+ }
73
+ entries.push([key, value]);
74
+ }
75
+ } catch (error) {
76
+ InternalLog.log(
77
+ `Some RUM user properties could not be read (${errorMessage(
78
+ error
79
+ )}) and were not added to the evaluation context.`,
80
+ SdkVerbosity.WARN
81
+ );
82
+ }
83
+
84
+ try {
85
+ // Read once so a getter cannot change the value between validation and insertion.
86
+ const { name, email, id } = user;
87
+ if (typeof name === 'string') {
88
+ entries.push(['name', name]);
89
+ }
90
+ if (typeof email === 'string') {
91
+ entries.push(['email', email]);
92
+ }
93
+ if (typeof id === 'string') {
94
+ entries.push(['targetingKey', id]);
95
+ }
96
+ } catch (error) {
97
+ InternalLog.log(
98
+ `Some RUM user fields could not be read (${errorMessage(
99
+ error
100
+ )}) and were not added to the evaluation context.`,
101
+ SdkVerbosity.WARN
102
+ );
103
+ }
104
+
105
+ return entries;
106
+ };
107
+
108
+ const readRumUser = (): UserInfo | undefined => {
109
+ try {
110
+ return UserInfoSingleton.getInstance().getUserInfo();
111
+ } catch (error) {
112
+ InternalLog.log(
113
+ `Could not read the RUM user (${errorMessage(
114
+ error
115
+ )}). No RUM values were added to the evaluation context.`,
116
+ SdkVerbosity.WARN
117
+ );
118
+
119
+ return undefined;
120
+ }
121
+ };
122
+
123
+ const errorMessage = (error: unknown): string => {
124
+ try {
125
+ // Both reading and coercing an application's error message can throw.
126
+ return error instanceof Error ? String(error.message) : 'unknown error';
127
+ } catch {
128
+ return 'unknown error';
129
+ }
130
+ };
131
+
132
+ const isSupportedAttribute = (
133
+ value: unknown
134
+ ): value is string | number | boolean => {
135
+ return (
136
+ typeof value === 'string' ||
137
+ typeof value === 'number' ||
138
+ typeof value === 'boolean'
139
+ );
140
+ };
package/src/index.tsx CHANGED
@@ -37,6 +37,7 @@ import {
37
37
  configurationToString
38
38
  } from './flags/configuration';
39
39
  import type { ParsedFlagsConfiguration } from './flags/configuration';
40
+ import { __ddEnrichEvaluationContextWithRumUser } from './flags/rumIntegration';
40
41
  import type {
41
42
  FlagsConfiguration,
42
43
  FlagDetails,
@@ -112,7 +113,8 @@ export {
112
113
  DatadogTracingIdentifier,
113
114
  DatadogTracingContext,
114
115
  DdBabelInteractionTracking,
115
- __ddExtractText
116
+ __ddExtractText,
117
+ __ddEnrichEvaluationContextWithRumUser
116
118
  };
117
119
  export type {
118
120
  Timestamp,
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '3.7.0';
2
+ export const version = '3.8.0';