launchdarkly-js-sdk-common 5.0.0-alpha.7 → 5.0.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.
@@ -6,7 +6,8 @@ repo:
6
6
 
7
7
  branches:
8
8
  - name: main
9
- description: 4.x
9
+ description: 5.x
10
+ - name: 4.x
10
11
  - name: 3.x
11
12
 
12
13
  publications:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "launchdarkly-js-sdk-common",
3
- "version": "5.0.0-alpha.7",
3
+ "version": "5.0.0",
4
4
  "description": "LaunchDarkly SDK for JavaScript - common code",
5
5
  "author": "LaunchDarkly <team@launchdarkly.com>",
6
6
  "license": "Apache-2.0",
@@ -57,12 +57,12 @@ function InspectorManager(inspectors, logger) {
57
57
  *
58
58
  * @param {string} flagKey The key for the flag.
59
59
  * @param {Object} detail The LDEvaluationDetail for the flag.
60
- * @param {Object} user The LDUser for the flag.
60
+ * @param {Object} context The LDContext for the flag.
61
61
  */
62
- manager.onFlagUsed = (flagKey, detail, user) => {
62
+ manager.onFlagUsed = (flagKey, detail, context) => {
63
63
  if (inspectorsByType[InspectorTypes.flagUsed].length) {
64
64
  onNextTick(() => {
65
- inspectorsByType[InspectorTypes.flagUsed].forEach(inspector => inspector.method(flagKey, detail, user));
65
+ inspectorsByType[InspectorTypes.flagUsed].forEach(inspector => inspector.method(flagKey, detail, context));
66
66
  });
67
67
  }
68
68
  };
@@ -99,16 +99,16 @@ function InspectorManager(inspectors, logger) {
99
99
  };
100
100
 
101
101
  /**
102
- * Notify the registered inspectors that the user identity has changed.
102
+ * Notify the registered inspectors that the context identity has changed.
103
103
  *
104
104
  * The notification itself will be dispatched asynchronously.
105
105
  *
106
- * @param {Object} user The `LDUser` which is now identified.
106
+ * @param {Object} context The `LDContext` which is now identified.
107
107
  */
108
- manager.onIdentityChanged = user => {
108
+ manager.onIdentityChanged = context => {
109
109
  if (inspectorsByType[InspectorTypes.clientIdentityChanged].length) {
110
110
  onNextTick(() => {
111
- inspectorsByType[InspectorTypes.clientIdentityChanged].forEach(inspector => inspector.method(user));
111
+ inspectorsByType[InspectorTypes.clientIdentityChanged].forEach(inspector => inspector.method(context));
112
112
  });
113
113
  }
114
114
  };
@@ -39,16 +39,16 @@ describe('given an inspector with callbacks of every type', () => {
39
39
  {
40
40
  type: 'flag-used',
41
41
  name: 'my-flag-used-inspector',
42
- method: (flagKey, flagDetail, user) => {
43
- eventQueue.add({ type: 'flag-used', flagKey, flagDetail, user });
42
+ method: (flagKey, flagDetail, context) => {
43
+ eventQueue.add({ type: 'flag-used', flagKey, flagDetail, context });
44
44
  },
45
45
  },
46
46
  // 'flag-used registered twice.
47
47
  {
48
48
  type: 'flag-used',
49
49
  name: 'my-other-flag-used-inspector',
50
- method: (flagKey, flagDetail, user) => {
51
- eventQueue.add({ type: 'flag-used', flagKey, flagDetail, user });
50
+ method: (flagKey, flagDetail, context) => {
51
+ eventQueue.add({ type: 'flag-used', flagKey, flagDetail, context });
52
52
  },
53
53
  },
54
54
  {
@@ -75,10 +75,10 @@ describe('given an inspector with callbacks of every type', () => {
75
75
  {
76
76
  type: 'client-identity-changed',
77
77
  name: 'my-identity-inspector',
78
- method: user => {
78
+ method: context => {
79
79
  eventQueue.add({
80
80
  type: 'client-identity-changed',
81
- user,
81
+ context,
82
82
  });
83
83
  },
84
84
  },
@@ -137,7 +137,7 @@ describe('given an inspector with callbacks of every type', () => {
137
137
  kind: 'OFF',
138
138
  },
139
139
  },
140
- user: { key: 'test-key' },
140
+ context: { key: 'test-key' },
141
141
  };
142
142
  const event1 = await eventQueue.take();
143
143
  expect(event1).toMatchObject(expectedEvent);
@@ -180,7 +180,7 @@ describe('given an inspector with callbacks of every type', () => {
180
180
  const event = await eventQueue.take();
181
181
  expect(event).toMatchObject({
182
182
  type: 'client-identity-changed',
183
- user: { key: 'the-key' },
183
+ context: { key: 'the-key' },
184
184
  });
185
185
  });
186
186
  });
@@ -3,7 +3,7 @@ const { respondJson } = require('./mockHttp');
3
3
  const stubPlatform = require('./stubPlatform');
4
4
 
5
5
  const envName = 'UNKNOWN_ENVIRONMENT_ID';
6
- const user = { key: 'user' };
6
+ const context = { key: 'context-key' };
7
7
 
8
8
  describe('given a streaming client with registered inspectors', () => {
9
9
  const eventQueue = new AsyncQueue();
@@ -11,15 +11,15 @@ describe('given a streaming client with registered inspectors', () => {
11
11
  const inspectors = [
12
12
  {
13
13
  type: 'flag-used',
14
- method: (flagKey, flagDetail, user) => {
15
- eventQueue.add({ type: 'flag-used', flagKey, flagDetail, user });
14
+ method: (flagKey, flagDetail, context) => {
15
+ eventQueue.add({ type: 'flag-used', flagKey, flagDetail, context });
16
16
  },
17
17
  },
18
18
  // 'flag-used registered twice.
19
19
  {
20
20
  type: 'flag-used',
21
- method: (flagKey, flagDetail, user) => {
22
- eventQueue.add({ type: 'flag-used', flagKey, flagDetail, user });
21
+ method: (flagKey, flagDetail, context) => {
22
+ eventQueue.add({ type: 'flag-used', flagKey, flagDetail, context });
23
23
  },
24
24
  },
25
25
  {
@@ -43,10 +43,10 @@ describe('given a streaming client with registered inspectors', () => {
43
43
  },
44
44
  {
45
45
  type: 'client-identity-changed',
46
- method: user => {
46
+ method: context => {
47
47
  eventQueue.add({
48
48
  type: 'client-identity-changed',
49
- user,
49
+ context,
50
50
  });
51
51
  },
52
52
  },
@@ -60,7 +60,7 @@ describe('given a streaming client with registered inspectors', () => {
60
60
  const server = platform.testing.http.newServer();
61
61
  server.byDefault(respondJson({}));
62
62
  const config = { streaming: true, baseUrl: server.url, inspectors, sendEvents: false };
63
- client = platform.testing.makeClient(envName, user, config);
63
+ client = platform.testing.makeClient(envName, context, config);
64
64
  await client.waitUntilReady();
65
65
  });
66
66
 
@@ -81,7 +81,7 @@ describe('given a streaming client with registered inspectors', () => {
81
81
  const ident = await eventQueue.take();
82
82
  expect(ident).toMatchObject({
83
83
  type: 'client-identity-changed',
84
- user,
84
+ context,
85
85
  });
86
86
  const flagsEvent = await eventQueue.take();
87
87
  expect(flagsEvent).toMatchObject({
@@ -7,10 +7,10 @@ import PersistentStorage from '../PersistentStorage';
7
7
  import * as utils from '../utils';
8
8
 
9
9
  describe('PersistentFlagStore', () => {
10
- const user = { key: 'user' };
11
- const ident = Identity(user);
10
+ const context = { key: 'context-key', kind: 'user' };
11
+ const ident = Identity(context);
12
12
  const env = 'ENVIRONMENT';
13
- const lsKey = 'ld:' + env + ':' + utils.btoa(JSON.stringify(user));
13
+ const lsKey = 'ld:' + env + ':' + utils.btoa(JSON.stringify(context));
14
14
 
15
15
  it('stores flags', async () => {
16
16
  const platform = stubPlatform.defaults();
@@ -73,7 +73,7 @@ describe('PersistentFlagStore', () => {
73
73
  expect(platform.testing.getLocalStorageImmediately(lsKey)).toBe(undefined);
74
74
  });
75
75
 
76
- it('uses hash, if present, instead of user properties', async () => {
76
+ it('uses hash, if present, instead of context properties', async () => {
77
77
  const platform = stubPlatform.defaults();
78
78
  const storage = PersistentStorage(platform.localStorage, platform.testing.logger);
79
79
  const hash = '12345';
@@ -83,14 +83,14 @@ export function defaults() {
83
83
 
84
84
  eventSourcesCreated,
85
85
 
86
- makeClient: (env, user, options = {}) => {
86
+ makeClient: (env, context, options = {}) => {
87
87
  const config = { logger: p.testing.logger, ...options };
88
88
  // We want to simulate what the platform-specific SDKs will do in their own initialization functions.
89
89
  // They will call the common package's LDClient.initialize() and receive the clientVars object which
90
90
  // contains both the underlying client (in its "client" property) and some internal methods that the
91
91
  // platform-specific SDKs can use to do internal stuff. One of those is start(), which they will
92
92
  // call after doing any other initialization things they may need to do.
93
- const clientVars = LDClient.initialize(env, user, config, p);
93
+ const clientVars = LDClient.initialize(env, context, config, p);
94
94
  clientVars.start();
95
95
  return clientVars.client;
96
96
  },
@@ -66,8 +66,8 @@ describe('utils', () => {
66
66
 
67
67
  describe('chunkEventsForUrl', () => {
68
68
  it('should properly chunk the list of events', () => {
69
- const user = { key: 'foo' };
70
- const event = { kind: 'identify', key: user.key };
69
+ const context = { key: 'foo', kind: 'user' };
70
+ const event = { kind: 'identify', key: context.key };
71
71
  const eventLength = base64URLEncode(JSON.stringify(event)).length;
72
72
  const events = [event, event, event, event, event];
73
73
  const chunks = chunkEventsForUrl(eventLength * 2, events);
@@ -1,6 +1,6 @@
1
1
  const { v1: uuidv1 } = require('uuid');
2
2
  // Note that in the diagnostic events spec, these IDs are to be generated with UUID v4. However,
3
- // in JS we were already using v1 for unique user keys, so to avoid bringing in two packages we
3
+ // in JS we were already using v1 for unique context keys, so to avoid bringing in two packages we
4
4
  // will use v1 here as well.
5
5
 
6
6
  const { baseOptionDefs } = require('./configuration');
package/src/index.js CHANGED
@@ -189,8 +189,8 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) {
189
189
  }
190
190
  }
191
191
 
192
- function onIdentifyChange(user) {
193
- sendIdentifyEvent(user);
192
+ function onIdentifyChange(context) {
193
+ sendIdentifyEvent(context);
194
194
  notifyInspectionIdentityChanged();
195
195
  }
196
196
 
package/typings.d.ts CHANGED
@@ -327,8 +327,7 @@ declare module 'launchdarkly-js-sdk-common' {
327
327
  *
328
328
  * This is a metadata property, rather than an attribute that can be addressed in evaluations:
329
329
  * that is, a rule clause that references the attribute name "privateAttributes", will not use
330
- * this value, but instead will use whatever value (if any) you have set for that name with a
331
- * method such as SetString.
330
+ * this value, but would use a "privateAttributes" attribute set on the context.
332
331
  */
333
332
  privateAttributes?: string[];
334
333
  }