@mparticle/web-google-analytics-4-client-kit 1.0.2 → 1.0.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 +5 -2
- package/.eslintrc +0 -30
- package/dist/.keep +0 -0
- package/dist/GoogleAnalytics4EventForwarderClientSide-Kit.iife.js +0 -1318
- package/rollup.config.js +0 -52
- package/src/commerce-handler.js +0 -463
- package/src/common.js +0 -104
- package/src/event-handler.js +0 -36
- package/src/identity-handler.js +0 -68
- package/src/initialization.js +0 -75
- package/src/session-handler.js +0 -10
- package/src/user-attribute-handler.js +0 -27
- package/test/boilerplate/karma.config.js +0 -19
- package/test/boilerplate/mockhttprequest.js +0 -472
- package/test/boilerplate/test-index.js +0 -8
- package/test/boilerplate/test-karma.js +0 -8
- package/test/end-to-end-testapp/build/.keep +0 -0
- package/test/end-to-end-testapp/settings.js +0 -10
- package/test/index.html +0 -32
- package/test/settings.json +0 -12
- package/test/tests.js +0 -1433
package/src/identity-handler.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The 'mParticleUser' is an object with methods get user Identities and set/get user attributes
|
|
3
|
-
Partners can determine what userIds are available to use in their SDK
|
|
4
|
-
Call mParticleUser.getUserIdentities() to return an object of userIdentities --> { userIdentities: {customerid: '1234', email: 'email@gmail.com'} }
|
|
5
|
-
For more identity types, see http://docs.mparticle.com/developers/sdk/javascript/identity#allowed-identity-types
|
|
6
|
-
Call mParticleUser.getMPID() to get mParticle ID
|
|
7
|
-
For any additional methods, see http://docs.mparticle.com/developers/sdk/javascript/apidocs/classes/mParticle.Identity.getCurrentUser().html
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/*
|
|
11
|
-
identityApiRequest has the schema:
|
|
12
|
-
{
|
|
13
|
-
userIdentities: {
|
|
14
|
-
customerid: '123',
|
|
15
|
-
email: 'abc'
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
For more userIdentity types, see http://docs.mparticle.com/developers/sdk/javascript/identity#allowed-identity-types
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
function IdentityHandler(common) {
|
|
22
|
-
this.common = common || {};
|
|
23
|
-
}
|
|
24
|
-
IdentityHandler.prototype.onUserIdentified = function (mParticleUser) {
|
|
25
|
-
var configSettings = {};
|
|
26
|
-
var userId = this.common.getUserId(
|
|
27
|
-
mParticleUser,
|
|
28
|
-
this.common.forwarderSettings.externalUserIdentityType,
|
|
29
|
-
this.common.forwarderSettings.hashUserId
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
if (userId) {
|
|
33
|
-
configSettings.user_id = userId;
|
|
34
|
-
}
|
|
35
|
-
gtag('config', this.common.forwarderSettings.measurementId, {
|
|
36
|
-
// do not send a page view when updating the userid in an identity call
|
|
37
|
-
send_page_view: false,
|
|
38
|
-
user_id: userId,
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
IdentityHandler.prototype.onIdentifyComplete = function (
|
|
42
|
-
mParticleUser,
|
|
43
|
-
identityApiRequest
|
|
44
|
-
) {};
|
|
45
|
-
IdentityHandler.prototype.onLoginComplete = function (
|
|
46
|
-
mParticleUser,
|
|
47
|
-
identityApiRequest
|
|
48
|
-
) {};
|
|
49
|
-
IdentityHandler.prototype.onLogoutComplete = function (
|
|
50
|
-
mParticleUser,
|
|
51
|
-
identityApiRequest
|
|
52
|
-
) {};
|
|
53
|
-
IdentityHandler.prototype.onModifyComplete = function (
|
|
54
|
-
mParticleUser,
|
|
55
|
-
identityApiRequest
|
|
56
|
-
) {};
|
|
57
|
-
|
|
58
|
-
/* In previous versions of the mParticle web SDK, setting user identities on
|
|
59
|
-
kits is only reachable via the onSetUserIdentity method below. We recommend
|
|
60
|
-
filling out `onSetUserIdentity` for maximum compatibility
|
|
61
|
-
*/
|
|
62
|
-
IdentityHandler.prototype.onSetUserIdentity = function (
|
|
63
|
-
forwarderSettings,
|
|
64
|
-
id,
|
|
65
|
-
type
|
|
66
|
-
) {};
|
|
67
|
-
|
|
68
|
-
module.exports = IdentityHandler;
|
package/src/initialization.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
var initialization = {
|
|
2
|
-
name: 'GoogleAnalytics4',
|
|
3
|
-
/* ****** Fill out initForwarder to load your SDK ******
|
|
4
|
-
Note that not all arguments may apply to your SDK initialization.
|
|
5
|
-
These are passed from mParticle, but leave them even if they are not being used.
|
|
6
|
-
forwarderSettings contain settings that your SDK requires in order to initialize
|
|
7
|
-
userAttributes example: {gender: 'male', age: 25}
|
|
8
|
-
userIdentities example: { 1: 'customerId', 2: 'facebookId', 7: 'emailid@email.com' }
|
|
9
|
-
additional identityTypes can be found at https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/src/types.js#L88-L101
|
|
10
|
-
*/
|
|
11
|
-
initForwarder: function (
|
|
12
|
-
forwarderSettings,
|
|
13
|
-
testMode,
|
|
14
|
-
userAttributes,
|
|
15
|
-
userIdentities,
|
|
16
|
-
processEvent,
|
|
17
|
-
eventQueue,
|
|
18
|
-
isInitialized,
|
|
19
|
-
common
|
|
20
|
-
) {
|
|
21
|
-
common.forwarderSettings = forwarderSettings;
|
|
22
|
-
var measurementId = forwarderSettings.measurementId;
|
|
23
|
-
var userIdType = forwarderSettings.externalUserIdentityType;
|
|
24
|
-
var hashUserId = forwarderSettings.hashUserId;
|
|
25
|
-
var configSettings = {
|
|
26
|
-
send_page_view: forwarderSettings.enablePageView === 'True',
|
|
27
|
-
};
|
|
28
|
-
window.dataLayer = window.dataLayer || [];
|
|
29
|
-
|
|
30
|
-
window.gtag = function () {
|
|
31
|
-
window.dataLayer.push(arguments);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
if (!testMode) {
|
|
35
|
-
var clientScript = document.createElement('script');
|
|
36
|
-
clientScript.type = 'text/javascript';
|
|
37
|
-
clientScript.async = true;
|
|
38
|
-
clientScript.src =
|
|
39
|
-
'https://www.googletagmanager.com/gtag/js?id=' + measurementId;
|
|
40
|
-
(
|
|
41
|
-
document.getElementsByTagName('head')[0] ||
|
|
42
|
-
document.getElementsByTagName('body')[0]
|
|
43
|
-
).appendChild(clientScript);
|
|
44
|
-
|
|
45
|
-
clientScript.onload = function () {
|
|
46
|
-
gtag('js', new Date());
|
|
47
|
-
|
|
48
|
-
if (window.mParticle.getVersion().split('.')[0] === '2') {
|
|
49
|
-
var userId = common.getUserId(
|
|
50
|
-
mParticle.Identity.getCurrentUser(),
|
|
51
|
-
userIdType,
|
|
52
|
-
hashUserId
|
|
53
|
-
);
|
|
54
|
-
if (userId) {
|
|
55
|
-
configSettings.user_id = userId;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
gtag('config', measurementId, configSettings);
|
|
59
|
-
isInitialized = true;
|
|
60
|
-
|
|
61
|
-
if (window.dataLayer && gtag && eventQueue.length > 0) {
|
|
62
|
-
for (var i = 0; i < eventQueue.length; i++) {
|
|
63
|
-
processEvent(eventQueue[i]);
|
|
64
|
-
}
|
|
65
|
-
eventQueue = [];
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
} else {
|
|
69
|
-
isInitialized = true;
|
|
70
|
-
}
|
|
71
|
-
return isInitialized;
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
module.exports = initialization;
|
package/src/session-handler.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function UserAttributeHandler(common) {
|
|
2
|
-
this.common = common || {};
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
// `mParticleUser` was removed from the function signatures onRemoveUserAttribute, onSetUserAttribute, and onConsentStateUpload because they were not being used
|
|
6
|
-
// In the future if mParticleUser is ever required for an implementation of any of the below APIs, see https://github.com/mparticle-integrations/mparticle-javascript-integration-example/blob/master/src/user-attribute-handler.js
|
|
7
|
-
// for previous function signatures
|
|
8
|
-
|
|
9
|
-
UserAttributeHandler.prototype.onRemoveUserAttribute = function(key) {
|
|
10
|
-
var userAttributes = {};
|
|
11
|
-
userAttributes[key] = null;
|
|
12
|
-
gtag('set', 'user_properties', userAttributes);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
UserAttributeHandler.prototype.onSetUserAttribute = function(key, value) {
|
|
16
|
-
var userAttributes = {};
|
|
17
|
-
userAttributes[key] = value;
|
|
18
|
-
gtag('set', 'user_properties', userAttributes);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// TODO: Commenting this out for now because Integrations PM still determining if this is in scope or not
|
|
22
|
-
// UserAttributeHandler.prototype.onConsentStateUpdated = function() // oldState,
|
|
23
|
-
// newState,
|
|
24
|
-
// mParticleUser
|
|
25
|
-
// {};
|
|
26
|
-
|
|
27
|
-
module.exports = UserAttributeHandler;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module.exports = function(config) {
|
|
2
|
-
config.set({
|
|
3
|
-
frameworks: ['mocha', 'chai'],
|
|
4
|
-
files: ['../test-bundle.js'],
|
|
5
|
-
reporters: ['progress'],
|
|
6
|
-
port: 9876,
|
|
7
|
-
colors: true,
|
|
8
|
-
logLevel: config.LOG_INFO,
|
|
9
|
-
browsers: ['ChromeHeadless', 'Chrome', 'FirefoxHeadless', 'Safari', 'Edge', 'IE', 'Firefox'],
|
|
10
|
-
autoWatch: false,
|
|
11
|
-
concurrency: Infinity,
|
|
12
|
-
customLaunchers: {
|
|
13
|
-
FirefoxHeadless: {
|
|
14
|
-
base: 'Firefox',
|
|
15
|
-
flags: [ '-headless' ]
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
};
|
|
@@ -1,472 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undef*/
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Mock XMLHttpRequest (see http://www.w3.org/TR/XMLHttpRequest)
|
|
5
|
-
*
|
|
6
|
-
* Written by Philipp von Weitershausen <philipp@weitershausen.de>
|
|
7
|
-
* Released under the MIT license.
|
|
8
|
-
* http://www.opensource.org/licenses/mit-license.php
|
|
9
|
-
*
|
|
10
|
-
* For test interaction it exposes the following attributes:
|
|
11
|
-
*
|
|
12
|
-
* - method, url, urlParts, async, user, password
|
|
13
|
-
* - requestText
|
|
14
|
-
*
|
|
15
|
-
* as well as the following methods:
|
|
16
|
-
*
|
|
17
|
-
* - getRequestHeader(header)
|
|
18
|
-
* - setResponseHeader(header, value)
|
|
19
|
-
* - receive(status, data)
|
|
20
|
-
* - err(exception)
|
|
21
|
-
* - authenticate(user, password)
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
function MockHttpRequest () {
|
|
25
|
-
// These are internal flags and data structures
|
|
26
|
-
this.error = false;
|
|
27
|
-
this.sent = false;
|
|
28
|
-
this.requestHeaders = {};
|
|
29
|
-
this.responseHeaders = {};
|
|
30
|
-
}
|
|
31
|
-
MockHttpRequest.prototype = {
|
|
32
|
-
withCredentials: true,
|
|
33
|
-
|
|
34
|
-
statusReasons: {
|
|
35
|
-
100: 'Continue',
|
|
36
|
-
101: 'Switching Protocols',
|
|
37
|
-
102: 'Processing',
|
|
38
|
-
200: 'OK',
|
|
39
|
-
201: 'Created',
|
|
40
|
-
202: 'Accepted',
|
|
41
|
-
203: 'Non-Authoritative Information',
|
|
42
|
-
204: 'No Content',
|
|
43
|
-
205: 'Reset Content',
|
|
44
|
-
206: 'Partial Content',
|
|
45
|
-
207: 'Multi-Status',
|
|
46
|
-
300: 'Multiple Choices',
|
|
47
|
-
301: 'Moved Permanently',
|
|
48
|
-
302: 'Moved Temporarily',
|
|
49
|
-
303: 'See Other',
|
|
50
|
-
304: 'Not Modified',
|
|
51
|
-
305: 'Use Proxy',
|
|
52
|
-
307: 'Temporary Redirect',
|
|
53
|
-
400: 'Bad Request',
|
|
54
|
-
401: 'Unauthorized',
|
|
55
|
-
402: 'Payment Required',
|
|
56
|
-
403: 'Forbidden',
|
|
57
|
-
404: 'Not Found',
|
|
58
|
-
405: 'Method Not Allowed',
|
|
59
|
-
406: 'Not Acceptable',
|
|
60
|
-
407: 'Proxy Authentication Required',
|
|
61
|
-
408: 'Request Time-out',
|
|
62
|
-
409: 'Conflict',
|
|
63
|
-
410: 'Gone',
|
|
64
|
-
411: 'Length Required',
|
|
65
|
-
412: 'Precondition Failed',
|
|
66
|
-
413: 'Request Entity Too Large',
|
|
67
|
-
414: 'Request-URI Too Large',
|
|
68
|
-
415: 'Unsupported Media Type',
|
|
69
|
-
416: 'Requested range not satisfiable',
|
|
70
|
-
417: 'Expectation Failed',
|
|
71
|
-
422: 'Unprocessable Entity',
|
|
72
|
-
423: 'Locked',
|
|
73
|
-
424: 'Failed Dependency',
|
|
74
|
-
500: 'Internal Server Error',
|
|
75
|
-
501: 'Not Implemented',
|
|
76
|
-
502: 'Bad Gateway',
|
|
77
|
-
503: 'Service Unavailable',
|
|
78
|
-
504: 'Gateway Time-out',
|
|
79
|
-
505: 'HTTP Version not supported',
|
|
80
|
-
507: 'Insufficient Storage'
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
/*** State ***/
|
|
84
|
-
|
|
85
|
-
UNSENT: 0,
|
|
86
|
-
OPENED: 1,
|
|
87
|
-
HEADERS_RECEIVED: 2,
|
|
88
|
-
LOADING: 3,
|
|
89
|
-
DONE: 4,
|
|
90
|
-
readyState: 0,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
/*** Request ***/
|
|
94
|
-
|
|
95
|
-
open: function (method, url, async, user, password) {
|
|
96
|
-
if (typeof method !== 'string') {
|
|
97
|
-
throw 'INVALID_METHOD';
|
|
98
|
-
}
|
|
99
|
-
switch (method.toUpperCase()) {
|
|
100
|
-
case 'CONNECT':
|
|
101
|
-
case 'TRACE':
|
|
102
|
-
case 'TRACK':
|
|
103
|
-
throw 'SECURITY_ERR';
|
|
104
|
-
|
|
105
|
-
case 'DELETE':
|
|
106
|
-
case 'GET':
|
|
107
|
-
case 'HEAD':
|
|
108
|
-
case 'OPTIONS':
|
|
109
|
-
case 'POST':
|
|
110
|
-
case 'PUT':
|
|
111
|
-
method = method.toUpperCase();
|
|
112
|
-
}
|
|
113
|
-
this.method = method;
|
|
114
|
-
|
|
115
|
-
if (typeof url !== 'string') {
|
|
116
|
-
throw 'INVALID_URL';
|
|
117
|
-
}
|
|
118
|
-
this.url = url;
|
|
119
|
-
this.urlParts = this.parseUri(url);
|
|
120
|
-
|
|
121
|
-
if (async === undefined) {
|
|
122
|
-
async = true;
|
|
123
|
-
}
|
|
124
|
-
this.async = async;
|
|
125
|
-
this.user = user;
|
|
126
|
-
this.password = password;
|
|
127
|
-
|
|
128
|
-
this.readyState = this.OPENED;
|
|
129
|
-
this.onreadystatechange();
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
setRequestHeader: function (header, value) {
|
|
133
|
-
header = header.toLowerCase();
|
|
134
|
-
|
|
135
|
-
switch (header) {
|
|
136
|
-
case 'accept-charset':
|
|
137
|
-
case 'accept-encoding':
|
|
138
|
-
case 'connection':
|
|
139
|
-
case 'content-length':
|
|
140
|
-
case 'cookie':
|
|
141
|
-
case 'cookie2':
|
|
142
|
-
case 'content-transfer-encoding':
|
|
143
|
-
case 'date':
|
|
144
|
-
case 'expect':
|
|
145
|
-
case 'host':
|
|
146
|
-
case 'keep-alive':
|
|
147
|
-
case 'referer':
|
|
148
|
-
case 'te':
|
|
149
|
-
case 'trailer':
|
|
150
|
-
case 'transfer-encoding':
|
|
151
|
-
case 'upgrade':
|
|
152
|
-
case 'user-agent':
|
|
153
|
-
case 'via':
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if ((header.substr(0, 6) === 'proxy-')
|
|
157
|
-
|| (header.substr(0, 4) === 'sec-')) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// it's the first call on this header field
|
|
162
|
-
if (this.requestHeaders[header] === undefined)
|
|
163
|
-
{this.requestHeaders[header] = value;}
|
|
164
|
-
else {
|
|
165
|
-
var prev = this.requestHeaders[header];
|
|
166
|
-
this.requestHeaders[header] = prev + ', ' + value;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
send: function (data) {
|
|
172
|
-
if ((this.readyState !== this.OPENED)
|
|
173
|
-
|| this.sent) {
|
|
174
|
-
throw 'INVALID_STATE_ERR';
|
|
175
|
-
}
|
|
176
|
-
if ((this.method === 'GET') || (this.method === 'HEAD')) {
|
|
177
|
-
data = null;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
//TODO set Content-Type header?
|
|
181
|
-
this.error = false;
|
|
182
|
-
this.sent = true;
|
|
183
|
-
this.onreadystatechange();
|
|
184
|
-
|
|
185
|
-
// fake send
|
|
186
|
-
this.requestText = data;
|
|
187
|
-
this.onsend();
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
abort: function () {
|
|
191
|
-
this.responseText = null;
|
|
192
|
-
this.error = true;
|
|
193
|
-
for (var header in this.requestHeaders) {
|
|
194
|
-
delete this.requestHeaders[header];
|
|
195
|
-
}
|
|
196
|
-
delete this.requestText;
|
|
197
|
-
this.onreadystatechange();
|
|
198
|
-
this.onabort();
|
|
199
|
-
this.readyState = this.UNSENT;
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
/*** Response ***/
|
|
204
|
-
|
|
205
|
-
status: 0,
|
|
206
|
-
statusText: '',
|
|
207
|
-
|
|
208
|
-
getResponseHeader: function (header) {
|
|
209
|
-
if ((this.readyState === this.UNSENT)
|
|
210
|
-
|| (this.readyState === this.OPENED)
|
|
211
|
-
|| this.error) {
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
return this.responseHeaders[header.toLowerCase()];
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
getAllResponseHeaders: function () {
|
|
218
|
-
var r = '';
|
|
219
|
-
for (var header in this.responseHeaders) {
|
|
220
|
-
if ((header === 'set-cookie') || (header === 'set-cookie2')) {
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
//TODO title case header
|
|
224
|
-
r += header + ': ' + this.responseHeaders[header] + '\r\n';
|
|
225
|
-
}
|
|
226
|
-
return r;
|
|
227
|
-
},
|
|
228
|
-
|
|
229
|
-
responseText: '',
|
|
230
|
-
responseXML: undefined, //TODO
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
/*** See http://www.w3.org/TR/progress-events/ ***/
|
|
234
|
-
|
|
235
|
-
onload: function () {
|
|
236
|
-
// Instances should override this.
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
onprogress: function () {
|
|
240
|
-
// Instances should override this.
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
onerror: function () {
|
|
244
|
-
// Instances should override this.
|
|
245
|
-
},
|
|
246
|
-
|
|
247
|
-
onabort: function () {
|
|
248
|
-
// Instances should override this.
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
onreadystatechange: function () {
|
|
252
|
-
// Instances should override this.
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
/*** Properties and methods for test interaction ***/
|
|
257
|
-
|
|
258
|
-
onsend: function () {
|
|
259
|
-
// Instances should override this.
|
|
260
|
-
},
|
|
261
|
-
|
|
262
|
-
getRequestHeader: function (header) {
|
|
263
|
-
return this.requestHeaders[header.toLowerCase()];
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
setResponseHeader: function (header, value) {
|
|
267
|
-
this.responseHeaders[header.toLowerCase()] = value;
|
|
268
|
-
},
|
|
269
|
-
|
|
270
|
-
makeXMLResponse: function (data) {
|
|
271
|
-
var xmlDoc;
|
|
272
|
-
// according to specs from point 3.7.5:
|
|
273
|
-
// "1. If the response entity body is null terminate these steps
|
|
274
|
-
// and return null.
|
|
275
|
-
// 2. If final MIME type is not null, text/xml, application/xml,
|
|
276
|
-
// and does not end in +xml terminate these steps and return null.
|
|
277
|
-
var mimetype = this.getResponseHeader('Content-Type');
|
|
278
|
-
mimetype = mimetype && mimetype.split(';', 1)[0];
|
|
279
|
-
if ((mimetype == null) || (mimetype == 'text/xml') ||
|
|
280
|
-
(mimetype == 'application/xml') ||
|
|
281
|
-
(mimetype && mimetype.substring(mimetype.length - 4) == '+xml')) {
|
|
282
|
-
// Attempt to produce an xml response
|
|
283
|
-
// and it will fail if not a good xml
|
|
284
|
-
try {
|
|
285
|
-
if (window.DOMParser) {
|
|
286
|
-
var parser = new DOMParser();
|
|
287
|
-
xmlDoc = parser.parseFromString(data, 'text/xml');
|
|
288
|
-
} else { // Internet Explorer
|
|
289
|
-
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
|
|
290
|
-
xmlDoc.async = 'false';
|
|
291
|
-
xmlDoc.loadXML(data);
|
|
292
|
-
}
|
|
293
|
-
} catch (e) {
|
|
294
|
-
// according to specs from point 3.7.5:
|
|
295
|
-
// "3. Let document be a cookie-free Document object that
|
|
296
|
-
// represents the result of parsing the response entity body
|
|
297
|
-
// into a document tree following the rules from the XML
|
|
298
|
-
// specifications. If this fails (unsupported character
|
|
299
|
-
// encoding, namespace well-formedness error etc.), terminate
|
|
300
|
-
// these steps return null."
|
|
301
|
-
xmlDoc = null;
|
|
302
|
-
}
|
|
303
|
-
// parse errors also yield a null.
|
|
304
|
-
if ((xmlDoc && xmlDoc.parseError && xmlDoc.parseError.errorCode != 0)
|
|
305
|
-
|| (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.nodeName == 'parsererror')
|
|
306
|
-
|| (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.nodeName == 'html'
|
|
307
|
-
&& xmlDoc.documentElement.firstChild && xmlDoc.documentElement.firstChild.nodeName == 'body'
|
|
308
|
-
&& xmlDoc.documentElement.firstChild.firstChild && xmlDoc.documentElement.firstChild.firstChild.nodeName == 'parsererror')) {
|
|
309
|
-
xmlDoc = null;
|
|
310
|
-
}
|
|
311
|
-
} else {
|
|
312
|
-
// mimetype is specified, but not xml-ish
|
|
313
|
-
xmlDoc = null;
|
|
314
|
-
}
|
|
315
|
-
return xmlDoc;
|
|
316
|
-
},
|
|
317
|
-
|
|
318
|
-
// Call this to simulate a server response
|
|
319
|
-
receive: function (status, data) {
|
|
320
|
-
if ((this.readyState !== this.OPENED) || (!this.sent)) {
|
|
321
|
-
// Can't respond to unopened request.
|
|
322
|
-
throw 'INVALID_STATE_ERR';
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
this.status = status;
|
|
326
|
-
this.statusText = status + ' ' + this.statusReasons[status];
|
|
327
|
-
this.readyState = this.HEADERS_RECEIVED;
|
|
328
|
-
this.onprogress();
|
|
329
|
-
this.onreadystatechange();
|
|
330
|
-
|
|
331
|
-
this.responseText = data;
|
|
332
|
-
this.responseXML = this.makeXMLResponse(data);
|
|
333
|
-
|
|
334
|
-
this.readyState = this.LOADING;
|
|
335
|
-
this.onprogress();
|
|
336
|
-
this.onreadystatechange();
|
|
337
|
-
|
|
338
|
-
this.readyState = this.DONE;
|
|
339
|
-
this.onreadystatechange();
|
|
340
|
-
this.onprogress();
|
|
341
|
-
this.onload();
|
|
342
|
-
},
|
|
343
|
-
|
|
344
|
-
// Call this to simulate a request error (e.g. NETWORK_ERR)
|
|
345
|
-
err: function (exception) {
|
|
346
|
-
if ((this.readyState !== this.OPENED) || (!this.sent)) {
|
|
347
|
-
// Can't respond to unopened request.
|
|
348
|
-
throw 'INVALID_STATE_ERR';
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
this.responseText = null;
|
|
352
|
-
this.error = true;
|
|
353
|
-
for (var header in this.requestHeaders) {
|
|
354
|
-
delete this.requestHeaders[header];
|
|
355
|
-
}
|
|
356
|
-
this.readyState = this.DONE;
|
|
357
|
-
if (!this.async) {
|
|
358
|
-
throw exception;
|
|
359
|
-
}
|
|
360
|
-
this.onreadystatechange();
|
|
361
|
-
this.onerror();
|
|
362
|
-
},
|
|
363
|
-
|
|
364
|
-
// Convenience method to verify HTTP credentials
|
|
365
|
-
authenticate: function (user, password) {
|
|
366
|
-
if (this.user) {
|
|
367
|
-
return (user === this.user) && (password === this.password);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (this.urlParts.user) {
|
|
371
|
-
return ((user === this.urlParts.user)
|
|
372
|
-
&& (password === this.urlParts.password));
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// Basic auth. Requires existence of the 'atob' function.
|
|
376
|
-
var auth = this.getRequestHeader('Authorization');
|
|
377
|
-
if (auth === undefined) {
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
if (auth.substr(0, 6) !== 'Basic ') {
|
|
381
|
-
return false;
|
|
382
|
-
}
|
|
383
|
-
if (typeof atob !== 'function') {
|
|
384
|
-
return false;
|
|
385
|
-
}
|
|
386
|
-
auth = atob(auth.substr(6));
|
|
387
|
-
var pieces = auth.split(':');
|
|
388
|
-
var requser = pieces.shift();
|
|
389
|
-
var reqpass = pieces.join(':');
|
|
390
|
-
return (user === requser) && (password === reqpass);
|
|
391
|
-
},
|
|
392
|
-
|
|
393
|
-
// Parse RFC 3986 compliant URIs.
|
|
394
|
-
// Based on parseUri by Steven Levithan <stevenlevithan.com>
|
|
395
|
-
// See http://blog.stevenlevithan.com/archives/parseuri
|
|
396
|
-
parseUri: function (str) {
|
|
397
|
-
var pattern = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
398
|
-
var key = ['source', 'protocol', 'authority', 'userInfo', 'user',
|
|
399
|
-
'password', 'host', 'port', 'relative', 'path',
|
|
400
|
-
'directory', 'file', 'query', 'anchor'];
|
|
401
|
-
var querypattern = /(?:^|&)([^&=]*)=?([^&]*)/g;
|
|
402
|
-
|
|
403
|
-
var match = pattern.exec(str);
|
|
404
|
-
var uri = {};
|
|
405
|
-
var i = 14;
|
|
406
|
-
while (i--) {
|
|
407
|
-
uri[key[i]] = match[i] || '';
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
uri.queryKey = {};
|
|
411
|
-
uri[key[12]].replace(querypattern, function ($0, $1, $2) {
|
|
412
|
-
if ($1) {
|
|
413
|
-
uri.queryKey[$1] = $2;
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
return uri;
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
/*
|
|
423
|
-
* A small mock "server" that intercepts XMLHttpRequest calls and
|
|
424
|
-
* diverts them to your handler.
|
|
425
|
-
*
|
|
426
|
-
* Usage:
|
|
427
|
-
*
|
|
428
|
-
* 1. Initialize with either
|
|
429
|
-
* var server = new MockHttpServer(your_request_handler);
|
|
430
|
-
* or
|
|
431
|
-
* var server = new MockHttpServer();
|
|
432
|
-
* server.handle = function (request) { ... };
|
|
433
|
-
*
|
|
434
|
-
* 2. Call server.start() to start intercepting all XMLHttpRequests.
|
|
435
|
-
*
|
|
436
|
-
* 3. Do your tests.
|
|
437
|
-
*
|
|
438
|
-
* 4. Call server.stop() to tear down.
|
|
439
|
-
*
|
|
440
|
-
* 5. Profit!
|
|
441
|
-
*/
|
|
442
|
-
function MockHttpServer (handler) {
|
|
443
|
-
if (handler) {
|
|
444
|
-
this.handle = handler;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
MockHttpServer.prototype = {
|
|
448
|
-
requests: [],
|
|
449
|
-
start: function () {
|
|
450
|
-
var self = this;
|
|
451
|
-
|
|
452
|
-
function Request () {
|
|
453
|
-
this.onsend = function () {
|
|
454
|
-
self.requests.push(this);
|
|
455
|
-
self.handle(this);
|
|
456
|
-
};
|
|
457
|
-
MockHttpRequest.apply(this, arguments);
|
|
458
|
-
}
|
|
459
|
-
Request.prototype = MockHttpRequest.prototype;
|
|
460
|
-
|
|
461
|
-
window.OriginalHttpRequest = window.XMLHttpRequest;
|
|
462
|
-
window.XMLHttpRequest = Request;
|
|
463
|
-
},
|
|
464
|
-
|
|
465
|
-
stop: function () {
|
|
466
|
-
window.XMLHttpRequest = window.OriginalHttpRequest;
|
|
467
|
-
},
|
|
468
|
-
|
|
469
|
-
handle: function () {
|
|
470
|
-
// Instances should override this.
|
|
471
|
-
}
|
|
472
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
window.MockHttpServer = require('./mockhttprequest.js');
|
|
2
|
-
window.should = require('should');
|
|
3
|
-
require('@mparticle/web-sdk');
|
|
4
|
-
mParticle.addForwarder = function (forwarder) {
|
|
5
|
-
mParticle.forwarder = new forwarder.constructor();
|
|
6
|
-
};
|
|
7
|
-
require('../../node_modules/@mparticle/web-kit-wrapper/index.js');
|
|
8
|
-
require('../tests.js');
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
var shell = require('shelljs');
|
|
2
|
-
var util = require('util');
|
|
3
|
-
var defaultArgs = '--single-run --browsers=ChromeHeadless,FirefoxHeadless';
|
|
4
|
-
var args = process.argv.slice(2).join(' ') || defaultArgs;
|
|
5
|
-
|
|
6
|
-
var testCommand = util.format('browserify test/boilerplate/test-index.js -o test/test-bundle.js && karma start %s test/boilerplate/karma.config.js', args);
|
|
7
|
-
console.log('Running command: \n' + testCommand);
|
|
8
|
-
shell.exec(testCommand);
|
|
File without changes
|