@splitsoftware/splitio-commons 1.17.0-rc.4 → 1.17.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.
@@ -63,14 +63,16 @@ var SSEClient = /** @class */ (function () {
63
63
  return encodeURIComponent(params + channel);
64
64
  }).join(',');
65
65
  var url = this.settings.urls.streaming + "/sse?channels=" + channelsQueryParam + "&accessToken=" + authToken.token + "&v=" + ABLY_API_VERSION + "&heartbeats=true"; // same results using `&heartbeats=false`
66
- // use headers in server-side or if getHeaderOverrides is defined
67
- var useHeaders = !this.settings.core.key || ((_a = this.settings.sync.requestOptions) === null || _a === void 0 ? void 0 : _a.getHeaderOverrides);
66
+ var isServerSide = !this.settings.core.key;
68
67
  this.connection = new this.eventSource(
69
- // For client-side SDKs, SplitSDKClientKey and SplitSDKClientKey metadata is passed as query params,
70
- // because native EventSource implementations for browser doesn't support headers.
71
- useHeaders ? url : url + ("&SplitSDKVersion=" + this.headers.SplitSDKVersion + "&SplitSDKClientKey=" + this.headers.SplitSDKClientKey),
72
- // For server-side SDKs, metadata is passed via headers. EventSource must support headers, like 'eventsource' package for Node.
73
- (0, objectAssign_1.objectAssign)(useHeaders ? { headers: (0, decorateHeaders_1.decorateHeaders)(this.settings, this.headers) } : {}, this.options));
68
+ // For client-side SDKs, metadata is passed as query param to avoid CORS issues and because native EventSource implementations in browsers do not support headers
69
+ isServerSide ? url : url + ("&SplitSDKVersion=" + this.headers.SplitSDKVersion + "&SplitSDKClientKey=" + this.headers.SplitSDKClientKey),
70
+ // For server-side SDKs, metadata is passed via headers
71
+ (0, objectAssign_1.objectAssign)(isServerSide ?
72
+ { headers: (0, decorateHeaders_1.decorateHeaders)(this.settings, this.headers) } :
73
+ ((_a = this.settings.sync.requestOptions) === null || _a === void 0 ? void 0 : _a.getHeaderOverrides) ?
74
+ { headers: (0, decorateHeaders_1.decorateHeaders)(this.settings, {}) } : // User must provide a window.EventSource polyfill that supports headers
75
+ {}, this.options));
74
76
  if (this.handler) { // no need to check if SSEClient is used only by PushManager
75
77
  this.connection.addEventListener('open', this.handler.handleOpen);
76
78
  this.connection.addEventListener('message', this.handler.handleMessage);
@@ -60,14 +60,16 @@ var SSEClient = /** @class */ (function () {
60
60
  return encodeURIComponent(params + channel);
61
61
  }).join(',');
62
62
  var url = this.settings.urls.streaming + "/sse?channels=" + channelsQueryParam + "&accessToken=" + authToken.token + "&v=" + ABLY_API_VERSION + "&heartbeats=true"; // same results using `&heartbeats=false`
63
- // use headers in server-side or if getHeaderOverrides is defined
64
- var useHeaders = !this.settings.core.key || ((_a = this.settings.sync.requestOptions) === null || _a === void 0 ? void 0 : _a.getHeaderOverrides);
63
+ var isServerSide = !this.settings.core.key;
65
64
  this.connection = new this.eventSource(
66
- // For client-side SDKs, SplitSDKClientKey and SplitSDKClientKey metadata is passed as query params,
67
- // because native EventSource implementations for browser doesn't support headers.
68
- useHeaders ? url : url + ("&SplitSDKVersion=" + this.headers.SplitSDKVersion + "&SplitSDKClientKey=" + this.headers.SplitSDKClientKey),
69
- // For server-side SDKs, metadata is passed via headers. EventSource must support headers, like 'eventsource' package for Node.
70
- objectAssign(useHeaders ? { headers: decorateHeaders(this.settings, this.headers) } : {}, this.options));
65
+ // For client-side SDKs, metadata is passed as query param to avoid CORS issues and because native EventSource implementations in browsers do not support headers
66
+ isServerSide ? url : url + ("&SplitSDKVersion=" + this.headers.SplitSDKVersion + "&SplitSDKClientKey=" + this.headers.SplitSDKClientKey),
67
+ // For server-side SDKs, metadata is passed via headers
68
+ objectAssign(isServerSide ?
69
+ { headers: decorateHeaders(this.settings, this.headers) } :
70
+ ((_a = this.settings.sync.requestOptions) === null || _a === void 0 ? void 0 : _a.getHeaderOverrides) ?
71
+ { headers: decorateHeaders(this.settings, {}) } : // User must provide a window.EventSource polyfill that supports headers
72
+ {}, this.options));
71
73
  if (this.handler) { // no need to check if SSEClient is used only by PushManager
72
74
  this.connection.addEventListener('open', this.handler.handleOpen);
73
75
  this.connection.addEventListener('message', this.handler.handleMessage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.17.0-rc.4",
3
+ "version": "1.17.0",
4
4
  "description": "Split JavaScript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -78,15 +78,20 @@ export class SSEClient implements ISSEClient {
78
78
  }
79
79
  ).join(',');
80
80
  const url = `${this.settings.urls.streaming}/sse?channels=${channelsQueryParam}&accessToken=${authToken.token}&v=${ABLY_API_VERSION}&heartbeats=true`; // same results using `&heartbeats=false`
81
- // use headers in server-side or if getHeaderOverrides is defined
82
- const useHeaders = !this.settings.core.key || this.settings.sync.requestOptions?.getHeaderOverrides;
81
+ const isServerSide = !this.settings.core.key;
83
82
 
84
83
  this.connection = new this.eventSource!(
85
- // For client-side SDKs, SplitSDKClientKey and SplitSDKClientKey metadata is passed as query params,
86
- // because native EventSource implementations for browser doesn't support headers.
87
- useHeaders ? url : url + `&SplitSDKVersion=${this.headers.SplitSDKVersion}&SplitSDKClientKey=${this.headers.SplitSDKClientKey}`,
88
- // For server-side SDKs, metadata is passed via headers. EventSource must support headers, like 'eventsource' package for Node.
89
- objectAssign(useHeaders ? { headers: decorateHeaders(this.settings, this.headers) } : {}, this.options)
84
+ // For client-side SDKs, metadata is passed as query param to avoid CORS issues and because native EventSource implementations in browsers do not support headers
85
+ isServerSide ? url : url + `&SplitSDKVersion=${this.headers.SplitSDKVersion}&SplitSDKClientKey=${this.headers.SplitSDKClientKey}`,
86
+ // For server-side SDKs, metadata is passed via headers
87
+ objectAssign(
88
+ isServerSide ?
89
+ { headers: decorateHeaders(this.settings, this.headers) } :
90
+ this.settings.sync.requestOptions?.getHeaderOverrides ?
91
+ { headers: decorateHeaders(this.settings, {}) } : // User must provide a window.EventSource polyfill that supports headers
92
+ {},
93
+ this.options
94
+ )
90
95
  );
91
96
 
92
97
  if (this.handler) { // no need to check if SSEClient is used only by PushManager