@constructor-io/constructorio-client-javascript 2.25.5 → 2.26.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.
@@ -18,6 +18,7 @@ var HumanityCheck = require('../utils/humanity-check');
18
18
  var helpers = require('../utils/helpers');
19
19
 
20
20
  var storageKey = '_constructorio_requests';
21
+ var requestTTL = 1800000; // 30 minutes in milliseconds
21
22
 
22
23
  var RequestQueue = /*#__PURE__*/function () {
23
24
  function RequestQueue(options, eventemitter) {
@@ -78,6 +79,7 @@ var RequestQueue = /*#__PURE__*/function () {
78
79
  var _nextInQueue = nextInQueue,
79
80
  networkParameters = _nextInQueue.networkParameters;
80
81
  var signal;
82
+ var instance = this;
81
83
  RequestQueue.set(queue);
82
84
 
83
85
  if (networkParameters) {
@@ -93,6 +95,22 @@ var RequestQueue = /*#__PURE__*/function () {
93
95
  url: nextInQueue,
94
96
  method: 'GET'
95
97
  };
98
+ } // If events older than `requestTTL` exist in queue, clear request queue
99
+ // - Prevents issue where stale items are sent in perputity
100
+ // - No request should go unsent for longer than `requestTTL`
101
+
102
+
103
+ if (nextInQueue.url) {
104
+ // Pull `dt` parameter from URL, indicating origin time of request
105
+ var dtMatch = nextInQueue.url.match(/\?.*_dt=([^&]+)/);
106
+ var requestOriginTime = parseInt(dtMatch && dtMatch[1], 10);
107
+ var now = +new Date();
108
+
109
+ if (requestOriginTime && Number.isInteger(requestOriginTime) && now - requestOriginTime > requestTTL) {
110
+ this.sendTrackingEvents = false;
111
+ RequestQueue.remove();
112
+ return;
113
+ }
96
114
  }
97
115
 
98
116
  if (nextInQueue.method === 'GET') {
@@ -115,37 +133,44 @@ var RequestQueue = /*#__PURE__*/function () {
115
133
 
116
134
  if (request) {
117
135
  this.requestPending = true;
118
- var instance = this;
119
136
  request.then(function (response) {
120
137
  // Request was successful, and returned a 2XX status code
121
138
  if (response.ok) {
122
- instance.eventemitter.emit('success', {
123
- url: nextInQueue.url,
124
- method: nextInQueue.method,
125
- message: 'ok'
126
- });
127
- } // Request was successful, but returned a non-2XX status code
128
- else {
129
- response.json().then(function (json) {
130
- instance.eventemitter.emit('error', {
139
+ if (instance.eventemitter) {
140
+ instance.eventemitter.emit('success', {
131
141
  url: nextInQueue.url,
132
142
  method: nextInQueue.method,
133
- message: json && json.message
143
+ message: 'ok'
134
144
  });
145
+ }
146
+ } // Request was successful, but returned a non-2XX status code
147
+ else {
148
+ response.json().then(function (json) {
149
+ if (instance.eventemitter) {
150
+ instance.eventemitter.emit('error', {
151
+ url: nextInQueue.url,
152
+ method: nextInQueue.method,
153
+ message: json && json.message
154
+ });
155
+ }
135
156
  })["catch"](function (error) {
136
- instance.eventemitter.emit('error', {
137
- url: nextInQueue.url,
138
- method: nextInQueue.method,
139
- message: error.type
140
- });
157
+ if (instance.eventemitter) {
158
+ instance.eventemitter.emit('error', {
159
+ url: nextInQueue.url,
160
+ method: nextInQueue.method,
161
+ message: error.type
162
+ });
163
+ }
141
164
  });
142
165
  }
143
166
  })["catch"](function (error) {
144
- instance.eventemitter.emit('error', {
145
- url: nextInQueue.url,
146
- method: nextInQueue.method,
147
- message: error.toString()
148
- });
167
+ if (instance.eventemitter) {
168
+ instance.eventemitter.emit('error', {
169
+ url: nextInQueue.url,
170
+ method: nextInQueue.method,
171
+ message: error.toString()
172
+ });
173
+ }
149
174
  })["finally"](function () {
150
175
  _this2.requestPending = false;
151
176
 
@@ -189,6 +214,7 @@ var RequestQueue = /*#__PURE__*/function () {
189
214
  // - Firefox seeing identical events being transmitted multiple times
190
215
 
191
216
  if (Array.isArray(localStorageQueue) && localStorageQueue.length !== queue.length) {
217
+ this.sendTrackingEvents = false;
192
218
  RequestQueue.remove();
193
219
  }
194
220
  } // Remove current request queue key
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-client-javascript",
3
- "version": "2.25.5",
3
+ "version": "2.26.3",
4
4
  "description": "Constructor.io JavaScript client",
5
5
  "main": "lib/constructorio.js",
6
6
  "scripts": {