launchdarkly-js-sdk-common 5.0.0-alpha.2 → 5.0.0-alpha.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "launchdarkly-js-sdk-common",
3
- "version": "5.0.0-alpha.2",
3
+ "version": "5.0.0-alpha.3",
4
4
  "description": "LaunchDarkly SDK for JavaScript - common code",
5
5
  "author": "LaunchDarkly <team@launchdarkly.com>",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@ function EventSender(platform, environmentId, options) {
31
31
  const headers = isDiagnostic
32
32
  ? baseHeaders
33
33
  : utils.extend({}, baseHeaders, {
34
- 'X-LaunchDarkly-Event-Schema': '3',
34
+ 'X-LaunchDarkly-Event-Schema': '4',
35
35
  'X-LaunchDarkly-Payload-ID': payloadId,
36
36
  });
37
37
  return platform
package/src/Requestor.js CHANGED
@@ -88,11 +88,11 @@ function Requestor(platform, options, environment) {
88
88
  let body;
89
89
 
90
90
  if (useReport) {
91
- endpoint = [baseUrl, '/sdk/evalx/', environment, '/user'].join('');
91
+ endpoint = [baseUrl, '/sdk/evalx/', environment, '/context'].join('');
92
92
  body = JSON.stringify(context);
93
93
  } else {
94
94
  data = utils.base64URLEncode(JSON.stringify(context));
95
- endpoint = [baseUrl, '/sdk/evalx/', environment, '/users/', data].join('');
95
+ endpoint = [baseUrl, '/sdk/evalx/', environment, '/contexts/', data].join('');
96
96
  }
97
97
  if (hash) {
98
98
  query = 'h=' + hash;
@@ -69,7 +69,7 @@ describe('Requestor', () => {
69
69
 
70
70
  expect(server.requests.length()).toEqual(1);
71
71
  const req = await server.requests.take();
72
- expect(req.path).toEqual(`/sdk/evalx/${env}/users/${encodedUser}`);
72
+ expect(req.path).toEqual(`/sdk/evalx/${env}/contexts/${encodedUser}`);
73
73
  });
74
74
  });
75
75
 
@@ -81,7 +81,7 @@ describe('Requestor', () => {
81
81
 
82
82
  expect(server.requests.length()).toEqual(1);
83
83
  const req = await server.requests.take();
84
- expect(req.path).toEqual(`/sdk/evalx/${env}/users/${encodedUser}?h=hash1`);
84
+ expect(req.path).toEqual(`/sdk/evalx/${env}/contexts/${encodedUser}?h=hash1`);
85
85
  });
86
86
  });
87
87
 
@@ -93,7 +93,7 @@ describe('Requestor', () => {
93
93
 
94
94
  expect(server.requests.length()).toEqual(1);
95
95
  const req = await server.requests.take();
96
- expect(req.path).toEqual(`/sdk/evalx/${env}/users/${encodedUser}?withReasons=true`);
96
+ expect(req.path).toEqual(`/sdk/evalx/${env}/contexts/${encodedUser}?withReasons=true`);
97
97
  });
98
98
  });
99
99
 
@@ -105,7 +105,7 @@ describe('Requestor', () => {
105
105
 
106
106
  expect(server.requests.length()).toEqual(1);
107
107
  const req = await server.requests.take();
108
- expect(req.path).toEqual(`/sdk/evalx/${env}/users/${encodedUser}?h=hash1&withReasons=true`);
108
+ expect(req.path).toEqual(`/sdk/evalx/${env}/contexts/${encodedUser}?h=hash1&withReasons=true`);
109
109
  });
110
110
  });
111
111
 
@@ -117,7 +117,7 @@ describe('Requestor', () => {
117
117
 
118
118
  expect(server.requests.length()).toEqual(1);
119
119
  const req = await server.requests.take();
120
- expect(req.path).toEqual(`/sdk/evalx/${env}/user`);
120
+ expect(req.path).toEqual(`/sdk/evalx/${env}/context`);
121
121
  });
122
122
  });
123
123
 
@@ -129,7 +129,7 @@ describe('Requestor', () => {
129
129
 
130
130
  expect(server.requests.length()).toEqual(1);
131
131
  const req = await server.requests.take();
132
- expect(req.path).toEqual(`/sdk/evalx/${env}/user?h=hash1`);
132
+ expect(req.path).toEqual(`/sdk/evalx/${env}/context?h=hash1`);
133
133
  });
134
134
  });
135
135
 
@@ -141,7 +141,7 @@ describe('Requestor', () => {
141
141
 
142
142
  expect(server.requests.length()).toEqual(1);
143
143
  const req = await server.requests.take();
144
- expect(req.path).toEqual(`/sdk/evalx/${env}/user?withReasons=true`);
144
+ expect(req.path).toEqual(`/sdk/evalx/${env}/context?withReasons=true`);
145
145
  });
146
146
  });
147
147
 
@@ -153,7 +153,7 @@ describe('Requestor', () => {
153
153
 
154
154
  expect(server.requests.length()).toEqual(1);
155
155
  const req = await server.requests.take();
156
- expect(req.path).toEqual(`/sdk/evalx/${env}/user?h=hash1&withReasons=true`);
156
+ expect(req.path).toEqual(`/sdk/evalx/${env}/context?h=hash1&withReasons=true`);
157
157
  });
158
158
  });
159
159
 
@@ -44,6 +44,10 @@ const baseOptionDefs = {
44
44
  */
45
45
  const allowedTagCharacters = /^(\w|\.|-)+$/;
46
46
 
47
+ function canonicalizeUrl(url) {
48
+ return url?.replace(/\/+$/, '');
49
+ }
50
+
47
51
  /**
48
52
  * Verify that a value meets the requirements for a tag value.
49
53
  * @param {string} tagValue
@@ -165,6 +169,11 @@ function validate(options, emitter, extraOptionDefs, logger) {
165
169
  }
166
170
  }
167
171
  });
172
+
173
+ ret.baseUrl = canonicalizeUrl(ret.baseUrl);
174
+ ret.streamUrl = canonicalizeUrl(ret.streamUrl);
175
+ ret.eventsUrl = canonicalizeUrl(ret.eventsUrl);
176
+
168
177
  return ret;
169
178
  }
170
179