@mparticle/web-id5-kit 1.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.
@@ -0,0 +1,1892 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6
+
7
+ function commonjsRequire () {
8
+ throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
9
+ }
10
+
11
+ function createCommonjsModule(fn, module) {
12
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
13
+ }
14
+
15
+ function getCjsExportFromNamespace (n) {
16
+ return n && n['default'] || n;
17
+ }
18
+
19
+ var _nodeResolve_empty = {};
20
+
21
+ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
22
+ __proto__: null,
23
+ 'default': _nodeResolve_empty
24
+ });
25
+
26
+ var require$$0 = getCjsExportFromNamespace(_nodeResolve_empty$1);
27
+
28
+ var core = createCommonjsModule(function (module, exports) {
29
+ (function (root, factory) {
30
+ {
31
+ // CommonJS
32
+ module.exports = exports = factory();
33
+ }
34
+ }(commonjsGlobal, function () {
35
+
36
+ /*globals window, global, require*/
37
+
38
+ /**
39
+ * CryptoJS core components.
40
+ */
41
+ var CryptoJS = CryptoJS || (function (Math, undefined$1) {
42
+
43
+ var crypto;
44
+
45
+ // Native crypto from window (Browser)
46
+ if (typeof window !== 'undefined' && window.crypto) {
47
+ crypto = window.crypto;
48
+ }
49
+
50
+ // Native crypto in web worker (Browser)
51
+ if (typeof self !== 'undefined' && self.crypto) {
52
+ crypto = self.crypto;
53
+ }
54
+
55
+ // Native crypto from worker
56
+ if (typeof globalThis !== 'undefined' && globalThis.crypto) {
57
+ crypto = globalThis.crypto;
58
+ }
59
+
60
+ // Native (experimental IE 11) crypto from window (Browser)
61
+ if (!crypto && typeof window !== 'undefined' && window.msCrypto) {
62
+ crypto = window.msCrypto;
63
+ }
64
+
65
+ // Native crypto from global (NodeJS)
66
+ if (!crypto && typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto) {
67
+ crypto = commonjsGlobal.crypto;
68
+ }
69
+
70
+ // Native crypto import via require (NodeJS)
71
+ if (!crypto && typeof commonjsRequire === 'function') {
72
+ try {
73
+ crypto = require$$0;
74
+ } catch (err) {}
75
+ }
76
+
77
+ /*
78
+ * Cryptographically secure pseudorandom number generator
79
+ *
80
+ * As Math.random() is cryptographically not safe to use
81
+ */
82
+ var cryptoSecureRandomInt = function () {
83
+ if (crypto) {
84
+ // Use getRandomValues method (Browser)
85
+ if (typeof crypto.getRandomValues === 'function') {
86
+ try {
87
+ return crypto.getRandomValues(new Uint32Array(1))[0];
88
+ } catch (err) {}
89
+ }
90
+
91
+ // Use randomBytes method (NodeJS)
92
+ if (typeof crypto.randomBytes === 'function') {
93
+ try {
94
+ return crypto.randomBytes(4).readInt32LE();
95
+ } catch (err) {}
96
+ }
97
+ }
98
+
99
+ throw new Error('Native crypto module could not be used to get secure random number.');
100
+ };
101
+
102
+ /*
103
+ * Local polyfill of Object.create
104
+
105
+ */
106
+ var create = Object.create || (function () {
107
+ function F() {}
108
+
109
+ return function (obj) {
110
+ var subtype;
111
+
112
+ F.prototype = obj;
113
+
114
+ subtype = new F();
115
+
116
+ F.prototype = null;
117
+
118
+ return subtype;
119
+ };
120
+ }());
121
+
122
+ /**
123
+ * CryptoJS namespace.
124
+ */
125
+ var C = {};
126
+
127
+ /**
128
+ * Library namespace.
129
+ */
130
+ var C_lib = C.lib = {};
131
+
132
+ /**
133
+ * Base object for prototypal inheritance.
134
+ */
135
+ var Base = C_lib.Base = (function () {
136
+
137
+
138
+ return {
139
+ /**
140
+ * Creates a new object that inherits from this object.
141
+ *
142
+ * @param {Object} overrides Properties to copy into the new object.
143
+ *
144
+ * @return {Object} The new object.
145
+ *
146
+ * @static
147
+ *
148
+ * @example
149
+ *
150
+ * var MyType = CryptoJS.lib.Base.extend({
151
+ * field: 'value',
152
+ *
153
+ * method: function () {
154
+ * }
155
+ * });
156
+ */
157
+ extend: function (overrides) {
158
+ // Spawn
159
+ var subtype = create(this);
160
+
161
+ // Augment
162
+ if (overrides) {
163
+ subtype.mixIn(overrides);
164
+ }
165
+
166
+ // Create default initializer
167
+ if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
168
+ subtype.init = function () {
169
+ subtype.$super.init.apply(this, arguments);
170
+ };
171
+ }
172
+
173
+ // Initializer's prototype is the subtype object
174
+ subtype.init.prototype = subtype;
175
+
176
+ // Reference supertype
177
+ subtype.$super = this;
178
+
179
+ return subtype;
180
+ },
181
+
182
+ /**
183
+ * Extends this object and runs the init method.
184
+ * Arguments to create() will be passed to init().
185
+ *
186
+ * @return {Object} The new object.
187
+ *
188
+ * @static
189
+ *
190
+ * @example
191
+ *
192
+ * var instance = MyType.create();
193
+ */
194
+ create: function () {
195
+ var instance = this.extend();
196
+ instance.init.apply(instance, arguments);
197
+
198
+ return instance;
199
+ },
200
+
201
+ /**
202
+ * Initializes a newly created object.
203
+ * Override this method to add some logic when your objects are created.
204
+ *
205
+ * @example
206
+ *
207
+ * var MyType = CryptoJS.lib.Base.extend({
208
+ * init: function () {
209
+ * // ...
210
+ * }
211
+ * });
212
+ */
213
+ init: function () {
214
+ },
215
+
216
+ /**
217
+ * Copies properties into this object.
218
+ *
219
+ * @param {Object} properties The properties to mix in.
220
+ *
221
+ * @example
222
+ *
223
+ * MyType.mixIn({
224
+ * field: 'value'
225
+ * });
226
+ */
227
+ mixIn: function (properties) {
228
+ for (var propertyName in properties) {
229
+ if (properties.hasOwnProperty(propertyName)) {
230
+ this[propertyName] = properties[propertyName];
231
+ }
232
+ }
233
+
234
+ // IE won't copy toString using the loop above
235
+ if (properties.hasOwnProperty('toString')) {
236
+ this.toString = properties.toString;
237
+ }
238
+ },
239
+
240
+ /**
241
+ * Creates a copy of this object.
242
+ *
243
+ * @return {Object} The clone.
244
+ *
245
+ * @example
246
+ *
247
+ * var clone = instance.clone();
248
+ */
249
+ clone: function () {
250
+ return this.init.prototype.extend(this);
251
+ }
252
+ };
253
+ }());
254
+
255
+ /**
256
+ * An array of 32-bit words.
257
+ *
258
+ * @property {Array} words The array of 32-bit words.
259
+ * @property {number} sigBytes The number of significant bytes in this word array.
260
+ */
261
+ var WordArray = C_lib.WordArray = Base.extend({
262
+ /**
263
+ * Initializes a newly created word array.
264
+ *
265
+ * @param {Array} words (Optional) An array of 32-bit words.
266
+ * @param {number} sigBytes (Optional) The number of significant bytes in the words.
267
+ *
268
+ * @example
269
+ *
270
+ * var wordArray = CryptoJS.lib.WordArray.create();
271
+ * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
272
+ * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
273
+ */
274
+ init: function (words, sigBytes) {
275
+ words = this.words = words || [];
276
+
277
+ if (sigBytes != undefined$1) {
278
+ this.sigBytes = sigBytes;
279
+ } else {
280
+ this.sigBytes = words.length * 4;
281
+ }
282
+ },
283
+
284
+ /**
285
+ * Converts this word array to a string.
286
+ *
287
+ * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
288
+ *
289
+ * @return {string} The stringified word array.
290
+ *
291
+ * @example
292
+ *
293
+ * var string = wordArray + '';
294
+ * var string = wordArray.toString();
295
+ * var string = wordArray.toString(CryptoJS.enc.Utf8);
296
+ */
297
+ toString: function (encoder) {
298
+ return (encoder || Hex).stringify(this);
299
+ },
300
+
301
+ /**
302
+ * Concatenates a word array to this word array.
303
+ *
304
+ * @param {WordArray} wordArray The word array to append.
305
+ *
306
+ * @return {WordArray} This word array.
307
+ *
308
+ * @example
309
+ *
310
+ * wordArray1.concat(wordArray2);
311
+ */
312
+ concat: function (wordArray) {
313
+ // Shortcuts
314
+ var thisWords = this.words;
315
+ var thatWords = wordArray.words;
316
+ var thisSigBytes = this.sigBytes;
317
+ var thatSigBytes = wordArray.sigBytes;
318
+
319
+ // Clamp excess bits
320
+ this.clamp();
321
+
322
+ // Concat
323
+ if (thisSigBytes % 4) {
324
+ // Copy one byte at a time
325
+ for (var i = 0; i < thatSigBytes; i++) {
326
+ var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
327
+ thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
328
+ }
329
+ } else {
330
+ // Copy one word at a time
331
+ for (var j = 0; j < thatSigBytes; j += 4) {
332
+ thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2];
333
+ }
334
+ }
335
+ this.sigBytes += thatSigBytes;
336
+
337
+ // Chainable
338
+ return this;
339
+ },
340
+
341
+ /**
342
+ * Removes insignificant bits.
343
+ *
344
+ * @example
345
+ *
346
+ * wordArray.clamp();
347
+ */
348
+ clamp: function () {
349
+ // Shortcuts
350
+ var words = this.words;
351
+ var sigBytes = this.sigBytes;
352
+
353
+ // Clamp
354
+ words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
355
+ words.length = Math.ceil(sigBytes / 4);
356
+ },
357
+
358
+ /**
359
+ * Creates a copy of this word array.
360
+ *
361
+ * @return {WordArray} The clone.
362
+ *
363
+ * @example
364
+ *
365
+ * var clone = wordArray.clone();
366
+ */
367
+ clone: function () {
368
+ var clone = Base.clone.call(this);
369
+ clone.words = this.words.slice(0);
370
+
371
+ return clone;
372
+ },
373
+
374
+ /**
375
+ * Creates a word array filled with random bytes.
376
+ *
377
+ * @param {number} nBytes The number of random bytes to generate.
378
+ *
379
+ * @return {WordArray} The random word array.
380
+ *
381
+ * @static
382
+ *
383
+ * @example
384
+ *
385
+ * var wordArray = CryptoJS.lib.WordArray.random(16);
386
+ */
387
+ random: function (nBytes) {
388
+ var words = [];
389
+
390
+ for (var i = 0; i < nBytes; i += 4) {
391
+ words.push(cryptoSecureRandomInt());
392
+ }
393
+
394
+ return new WordArray.init(words, nBytes);
395
+ }
396
+ });
397
+
398
+ /**
399
+ * Encoder namespace.
400
+ */
401
+ var C_enc = C.enc = {};
402
+
403
+ /**
404
+ * Hex encoding strategy.
405
+ */
406
+ var Hex = C_enc.Hex = {
407
+ /**
408
+ * Converts a word array to a hex string.
409
+ *
410
+ * @param {WordArray} wordArray The word array.
411
+ *
412
+ * @return {string} The hex string.
413
+ *
414
+ * @static
415
+ *
416
+ * @example
417
+ *
418
+ * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
419
+ */
420
+ stringify: function (wordArray) {
421
+ // Shortcuts
422
+ var words = wordArray.words;
423
+ var sigBytes = wordArray.sigBytes;
424
+
425
+ // Convert
426
+ var hexChars = [];
427
+ for (var i = 0; i < sigBytes; i++) {
428
+ var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
429
+ hexChars.push((bite >>> 4).toString(16));
430
+ hexChars.push((bite & 0x0f).toString(16));
431
+ }
432
+
433
+ return hexChars.join('');
434
+ },
435
+
436
+ /**
437
+ * Converts a hex string to a word array.
438
+ *
439
+ * @param {string} hexStr The hex string.
440
+ *
441
+ * @return {WordArray} The word array.
442
+ *
443
+ * @static
444
+ *
445
+ * @example
446
+ *
447
+ * var wordArray = CryptoJS.enc.Hex.parse(hexString);
448
+ */
449
+ parse: function (hexStr) {
450
+ // Shortcut
451
+ var hexStrLength = hexStr.length;
452
+
453
+ // Convert
454
+ var words = [];
455
+ for (var i = 0; i < hexStrLength; i += 2) {
456
+ words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
457
+ }
458
+
459
+ return new WordArray.init(words, hexStrLength / 2);
460
+ }
461
+ };
462
+
463
+ /**
464
+ * Latin1 encoding strategy.
465
+ */
466
+ var Latin1 = C_enc.Latin1 = {
467
+ /**
468
+ * Converts a word array to a Latin1 string.
469
+ *
470
+ * @param {WordArray} wordArray The word array.
471
+ *
472
+ * @return {string} The Latin1 string.
473
+ *
474
+ * @static
475
+ *
476
+ * @example
477
+ *
478
+ * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
479
+ */
480
+ stringify: function (wordArray) {
481
+ // Shortcuts
482
+ var words = wordArray.words;
483
+ var sigBytes = wordArray.sigBytes;
484
+
485
+ // Convert
486
+ var latin1Chars = [];
487
+ for (var i = 0; i < sigBytes; i++) {
488
+ var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
489
+ latin1Chars.push(String.fromCharCode(bite));
490
+ }
491
+
492
+ return latin1Chars.join('');
493
+ },
494
+
495
+ /**
496
+ * Converts a Latin1 string to a word array.
497
+ *
498
+ * @param {string} latin1Str The Latin1 string.
499
+ *
500
+ * @return {WordArray} The word array.
501
+ *
502
+ * @static
503
+ *
504
+ * @example
505
+ *
506
+ * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
507
+ */
508
+ parse: function (latin1Str) {
509
+ // Shortcut
510
+ var latin1StrLength = latin1Str.length;
511
+
512
+ // Convert
513
+ var words = [];
514
+ for (var i = 0; i < latin1StrLength; i++) {
515
+ words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
516
+ }
517
+
518
+ return new WordArray.init(words, latin1StrLength);
519
+ }
520
+ };
521
+
522
+ /**
523
+ * UTF-8 encoding strategy.
524
+ */
525
+ var Utf8 = C_enc.Utf8 = {
526
+ /**
527
+ * Converts a word array to a UTF-8 string.
528
+ *
529
+ * @param {WordArray} wordArray The word array.
530
+ *
531
+ * @return {string} The UTF-8 string.
532
+ *
533
+ * @static
534
+ *
535
+ * @example
536
+ *
537
+ * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
538
+ */
539
+ stringify: function (wordArray) {
540
+ try {
541
+ return decodeURIComponent(escape(Latin1.stringify(wordArray)));
542
+ } catch (e) {
543
+ throw new Error('Malformed UTF-8 data');
544
+ }
545
+ },
546
+
547
+ /**
548
+ * Converts a UTF-8 string to a word array.
549
+ *
550
+ * @param {string} utf8Str The UTF-8 string.
551
+ *
552
+ * @return {WordArray} The word array.
553
+ *
554
+ * @static
555
+ *
556
+ * @example
557
+ *
558
+ * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
559
+ */
560
+ parse: function (utf8Str) {
561
+ return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
562
+ }
563
+ };
564
+
565
+ /**
566
+ * Abstract buffered block algorithm template.
567
+ *
568
+ * The property blockSize must be implemented in a concrete subtype.
569
+ *
570
+ * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
571
+ */
572
+ var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
573
+ /**
574
+ * Resets this block algorithm's data buffer to its initial state.
575
+ *
576
+ * @example
577
+ *
578
+ * bufferedBlockAlgorithm.reset();
579
+ */
580
+ reset: function () {
581
+ // Initial values
582
+ this._data = new WordArray.init();
583
+ this._nDataBytes = 0;
584
+ },
585
+
586
+ /**
587
+ * Adds new data to this block algorithm's buffer.
588
+ *
589
+ * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
590
+ *
591
+ * @example
592
+ *
593
+ * bufferedBlockAlgorithm._append('data');
594
+ * bufferedBlockAlgorithm._append(wordArray);
595
+ */
596
+ _append: function (data) {
597
+ // Convert string to WordArray, else assume WordArray already
598
+ if (typeof data == 'string') {
599
+ data = Utf8.parse(data);
600
+ }
601
+
602
+ // Append
603
+ this._data.concat(data);
604
+ this._nDataBytes += data.sigBytes;
605
+ },
606
+
607
+ /**
608
+ * Processes available data blocks.
609
+ *
610
+ * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
611
+ *
612
+ * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
613
+ *
614
+ * @return {WordArray} The processed data.
615
+ *
616
+ * @example
617
+ *
618
+ * var processedData = bufferedBlockAlgorithm._process();
619
+ * var processedData = bufferedBlockAlgorithm._process(!!'flush');
620
+ */
621
+ _process: function (doFlush) {
622
+ var processedWords;
623
+
624
+ // Shortcuts
625
+ var data = this._data;
626
+ var dataWords = data.words;
627
+ var dataSigBytes = data.sigBytes;
628
+ var blockSize = this.blockSize;
629
+ var blockSizeBytes = blockSize * 4;
630
+
631
+ // Count blocks ready
632
+ var nBlocksReady = dataSigBytes / blockSizeBytes;
633
+ if (doFlush) {
634
+ // Round up to include partial blocks
635
+ nBlocksReady = Math.ceil(nBlocksReady);
636
+ } else {
637
+ // Round down to include only full blocks,
638
+ // less the number of blocks that must remain in the buffer
639
+ nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
640
+ }
641
+
642
+ // Count words ready
643
+ var nWordsReady = nBlocksReady * blockSize;
644
+
645
+ // Count bytes ready
646
+ var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
647
+
648
+ // Process blocks
649
+ if (nWordsReady) {
650
+ for (var offset = 0; offset < nWordsReady; offset += blockSize) {
651
+ // Perform concrete-algorithm logic
652
+ this._doProcessBlock(dataWords, offset);
653
+ }
654
+
655
+ // Remove processed words
656
+ processedWords = dataWords.splice(0, nWordsReady);
657
+ data.sigBytes -= nBytesReady;
658
+ }
659
+
660
+ // Return processed words
661
+ return new WordArray.init(processedWords, nBytesReady);
662
+ },
663
+
664
+ /**
665
+ * Creates a copy of this object.
666
+ *
667
+ * @return {Object} The clone.
668
+ *
669
+ * @example
670
+ *
671
+ * var clone = bufferedBlockAlgorithm.clone();
672
+ */
673
+ clone: function () {
674
+ var clone = Base.clone.call(this);
675
+ clone._data = this._data.clone();
676
+
677
+ return clone;
678
+ },
679
+
680
+ _minBufferSize: 0
681
+ });
682
+
683
+ /**
684
+ * Abstract hasher template.
685
+ *
686
+ * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
687
+ */
688
+ var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
689
+ /**
690
+ * Configuration options.
691
+ */
692
+ cfg: Base.extend(),
693
+
694
+ /**
695
+ * Initializes a newly created hasher.
696
+ *
697
+ * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
698
+ *
699
+ * @example
700
+ *
701
+ * var hasher = CryptoJS.algo.SHA256.create();
702
+ */
703
+ init: function (cfg) {
704
+ // Apply config defaults
705
+ this.cfg = this.cfg.extend(cfg);
706
+
707
+ // Set initial values
708
+ this.reset();
709
+ },
710
+
711
+ /**
712
+ * Resets this hasher to its initial state.
713
+ *
714
+ * @example
715
+ *
716
+ * hasher.reset();
717
+ */
718
+ reset: function () {
719
+ // Reset data buffer
720
+ BufferedBlockAlgorithm.reset.call(this);
721
+
722
+ // Perform concrete-hasher logic
723
+ this._doReset();
724
+ },
725
+
726
+ /**
727
+ * Updates this hasher with a message.
728
+ *
729
+ * @param {WordArray|string} messageUpdate The message to append.
730
+ *
731
+ * @return {Hasher} This hasher.
732
+ *
733
+ * @example
734
+ *
735
+ * hasher.update('message');
736
+ * hasher.update(wordArray);
737
+ */
738
+ update: function (messageUpdate) {
739
+ // Append
740
+ this._append(messageUpdate);
741
+
742
+ // Update the hash
743
+ this._process();
744
+
745
+ // Chainable
746
+ return this;
747
+ },
748
+
749
+ /**
750
+ * Finalizes the hash computation.
751
+ * Note that the finalize operation is effectively a destructive, read-once operation.
752
+ *
753
+ * @param {WordArray|string} messageUpdate (Optional) A final message update.
754
+ *
755
+ * @return {WordArray} The hash.
756
+ *
757
+ * @example
758
+ *
759
+ * var hash = hasher.finalize();
760
+ * var hash = hasher.finalize('message');
761
+ * var hash = hasher.finalize(wordArray);
762
+ */
763
+ finalize: function (messageUpdate) {
764
+ // Final message update
765
+ if (messageUpdate) {
766
+ this._append(messageUpdate);
767
+ }
768
+
769
+ // Perform concrete-hasher logic
770
+ var hash = this._doFinalize();
771
+
772
+ return hash;
773
+ },
774
+
775
+ blockSize: 512/32,
776
+
777
+ /**
778
+ * Creates a shortcut function to a hasher's object interface.
779
+ *
780
+ * @param {Hasher} hasher The hasher to create a helper for.
781
+ *
782
+ * @return {Function} The shortcut function.
783
+ *
784
+ * @static
785
+ *
786
+ * @example
787
+ *
788
+ * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
789
+ */
790
+ _createHelper: function (hasher) {
791
+ return function (message, cfg) {
792
+ return new hasher.init(cfg).finalize(message);
793
+ };
794
+ },
795
+
796
+ /**
797
+ * Creates a shortcut function to the HMAC's object interface.
798
+ *
799
+ * @param {Hasher} hasher The hasher to use in this HMAC helper.
800
+ *
801
+ * @return {Function} The shortcut function.
802
+ *
803
+ * @static
804
+ *
805
+ * @example
806
+ *
807
+ * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
808
+ */
809
+ _createHmacHelper: function (hasher) {
810
+ return function (message, key) {
811
+ return new C_algo.HMAC.init(hasher, key).finalize(message);
812
+ };
813
+ }
814
+ });
815
+
816
+ /**
817
+ * Algorithm namespace.
818
+ */
819
+ var C_algo = C.algo = {};
820
+
821
+ return C;
822
+ }(Math));
823
+
824
+
825
+ return CryptoJS;
826
+
827
+ }));
828
+ });
829
+
830
+ var sha256 = createCommonjsModule(function (module, exports) {
831
+ (function (root, factory) {
832
+ {
833
+ // CommonJS
834
+ module.exports = exports = factory(core);
835
+ }
836
+ }(commonjsGlobal, function (CryptoJS) {
837
+
838
+ (function (Math) {
839
+ // Shortcuts
840
+ var C = CryptoJS;
841
+ var C_lib = C.lib;
842
+ var WordArray = C_lib.WordArray;
843
+ var Hasher = C_lib.Hasher;
844
+ var C_algo = C.algo;
845
+
846
+ // Initialization and round constants tables
847
+ var H = [];
848
+ var K = [];
849
+
850
+ // Compute constants
851
+ (function () {
852
+ function isPrime(n) {
853
+ var sqrtN = Math.sqrt(n);
854
+ for (var factor = 2; factor <= sqrtN; factor++) {
855
+ if (!(n % factor)) {
856
+ return false;
857
+ }
858
+ }
859
+
860
+ return true;
861
+ }
862
+
863
+ function getFractionalBits(n) {
864
+ return ((n - (n | 0)) * 0x100000000) | 0;
865
+ }
866
+
867
+ var n = 2;
868
+ var nPrime = 0;
869
+ while (nPrime < 64) {
870
+ if (isPrime(n)) {
871
+ if (nPrime < 8) {
872
+ H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
873
+ }
874
+ K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
875
+
876
+ nPrime++;
877
+ }
878
+
879
+ n++;
880
+ }
881
+ }());
882
+
883
+ // Reusable object
884
+ var W = [];
885
+
886
+ /**
887
+ * SHA-256 hash algorithm.
888
+ */
889
+ var SHA256 = C_algo.SHA256 = Hasher.extend({
890
+ _doReset: function () {
891
+ this._hash = new WordArray.init(H.slice(0));
892
+ },
893
+
894
+ _doProcessBlock: function (M, offset) {
895
+ // Shortcut
896
+ var H = this._hash.words;
897
+
898
+ // Working variables
899
+ var a = H[0];
900
+ var b = H[1];
901
+ var c = H[2];
902
+ var d = H[3];
903
+ var e = H[4];
904
+ var f = H[5];
905
+ var g = H[6];
906
+ var h = H[7];
907
+
908
+ // Computation
909
+ for (var i = 0; i < 64; i++) {
910
+ if (i < 16) {
911
+ W[i] = M[offset + i] | 0;
912
+ } else {
913
+ var gamma0x = W[i - 15];
914
+ var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
915
+ ((gamma0x << 14) | (gamma0x >>> 18)) ^
916
+ (gamma0x >>> 3);
917
+
918
+ var gamma1x = W[i - 2];
919
+ var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
920
+ ((gamma1x << 13) | (gamma1x >>> 19)) ^
921
+ (gamma1x >>> 10);
922
+
923
+ W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
924
+ }
925
+
926
+ var ch = (e & f) ^ (~e & g);
927
+ var maj = (a & b) ^ (a & c) ^ (b & c);
928
+
929
+ var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
930
+ var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
931
+
932
+ var t1 = h + sigma1 + ch + K[i] + W[i];
933
+ var t2 = sigma0 + maj;
934
+
935
+ h = g;
936
+ g = f;
937
+ f = e;
938
+ e = (d + t1) | 0;
939
+ d = c;
940
+ c = b;
941
+ b = a;
942
+ a = (t1 + t2) | 0;
943
+ }
944
+
945
+ // Intermediate hash value
946
+ H[0] = (H[0] + a) | 0;
947
+ H[1] = (H[1] + b) | 0;
948
+ H[2] = (H[2] + c) | 0;
949
+ H[3] = (H[3] + d) | 0;
950
+ H[4] = (H[4] + e) | 0;
951
+ H[5] = (H[5] + f) | 0;
952
+ H[6] = (H[6] + g) | 0;
953
+ H[7] = (H[7] + h) | 0;
954
+ },
955
+
956
+ _doFinalize: function () {
957
+ // Shortcuts
958
+ var data = this._data;
959
+ var dataWords = data.words;
960
+
961
+ var nBitsTotal = this._nDataBytes * 8;
962
+ var nBitsLeft = data.sigBytes * 8;
963
+
964
+ // Add padding
965
+ dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
966
+ dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
967
+ dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
968
+ data.sigBytes = dataWords.length * 4;
969
+
970
+ // Hash final blocks
971
+ this._process();
972
+
973
+ // Return final computed hash
974
+ return this._hash;
975
+ },
976
+
977
+ clone: function () {
978
+ var clone = Hasher.clone.call(this);
979
+ clone._hash = this._hash.clone();
980
+
981
+ return clone;
982
+ }
983
+ });
984
+
985
+ /**
986
+ * Shortcut function to the hasher's object interface.
987
+ *
988
+ * @param {WordArray|string} message The message to hash.
989
+ *
990
+ * @return {WordArray} The hash.
991
+ *
992
+ * @static
993
+ *
994
+ * @example
995
+ *
996
+ * var hash = CryptoJS.SHA256('message');
997
+ * var hash = CryptoJS.SHA256(wordArray);
998
+ */
999
+ C.SHA256 = Hasher._createHelper(SHA256);
1000
+
1001
+ /**
1002
+ * Shortcut function to the HMAC's object interface.
1003
+ *
1004
+ * @param {WordArray|string} message The message to hash.
1005
+ * @param {WordArray|string} key The secret key.
1006
+ *
1007
+ * @return {WordArray} The HMAC.
1008
+ *
1009
+ * @static
1010
+ *
1011
+ * @example
1012
+ *
1013
+ * var hmac = CryptoJS.HmacSHA256(message, key);
1014
+ */
1015
+ C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
1016
+ }(Math));
1017
+
1018
+
1019
+ return CryptoJS.SHA256;
1020
+
1021
+ }));
1022
+ });
1023
+
1024
+ function Common() {}
1025
+
1026
+ Common.prototype.exampleMethod = function () {
1027
+ return 'I am an example';
1028
+ };
1029
+
1030
+ Common.prototype.logId5Id = function (id5Id) {
1031
+ if (!id5Id) {
1032
+ return;
1033
+ }
1034
+
1035
+ var integrationAttributes = {
1036
+ encryptedId5Id: id5Id,
1037
+ id5IdType: this.id5IdType,
1038
+ };
1039
+
1040
+ window.mParticle.setIntegrationAttributes(this.moduleId, integrationAttributes);
1041
+ };
1042
+
1043
+ Common.prototype.buildPartnerData = function (mParticleUser) {
1044
+ var pdKeys = {};
1045
+ var userIdentities = mParticleUser.getUserIdentities();
1046
+
1047
+ var email = this.normalizeEmail(userIdentities.userIdentities['email']);
1048
+ var phone = this.normalizePhone(userIdentities.userIdentities['mobile_number']);
1049
+
1050
+ if (!email && !phone) {
1051
+ return null;
1052
+ }
1053
+
1054
+ if (email) {
1055
+ pdKeys[1] = sha256(email);
1056
+ }
1057
+
1058
+ if (phone) {
1059
+ pdKeys[2]= sha256(phone);
1060
+ }
1061
+
1062
+ var pdRaw = Object.keys(pdKeys).map(function(key){
1063
+ return key + '=' + pdKeys[key]
1064
+ }).join('&');
1065
+
1066
+ return btoa(pdRaw);
1067
+ };
1068
+
1069
+ Common.prototype.normalizeEmail = function(email) {
1070
+ if (!email || !this.validateEmail(email)) {
1071
+ return null;
1072
+ }
1073
+ var parts = email.split("@");
1074
+ var charactersToRemove = ['+', '.'];
1075
+
1076
+ if (parts[1] != 'gmail.com') {
1077
+ return email;
1078
+ }
1079
+
1080
+ parts[0]= this.replace(parts[0], charactersToRemove);
1081
+
1082
+ return parts.join('@');
1083
+ };
1084
+
1085
+ Common.prototype.normalizePhone = function(phone) {
1086
+ if (!phone) {
1087
+ return null;
1088
+ }
1089
+ var charactersToRemove = [' ', '-', '(', ')'];
1090
+ var normalizedPhone = this.replace(phone, charactersToRemove);
1091
+
1092
+ if (normalizedPhone[0] !== '+') {
1093
+ normalizedPhone = '+' + normalizedPhone;
1094
+ }
1095
+
1096
+ if (!this.validatePhone(normalizedPhone)) {
1097
+ return null;
1098
+ }
1099
+ return normalizedPhone;
1100
+ };
1101
+
1102
+ Common.prototype.replace = function(string, targets) {
1103
+ var newString = '';
1104
+ for(var i = 0; i < string.length; i++){
1105
+ var char = string[i];
1106
+ if (!targets.includes(char)){
1107
+ newString += char;
1108
+ }
1109
+ }
1110
+ return newString.toLowerCase();
1111
+ };
1112
+
1113
+ Common.prototype.validateEmail = function(email){
1114
+ if (!email) {
1115
+ return false;
1116
+ }
1117
+ var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1118
+ return emailRegex.test(email);
1119
+ };
1120
+
1121
+ Common.prototype.validatePhone = function(phone) {
1122
+ if (!phone){
1123
+ return false;
1124
+ }
1125
+ var e164Regex = /^\+?[1-9]\d{1,14}$/;
1126
+
1127
+ return e164Regex.test(phone);
1128
+ };
1129
+ var common = Common;
1130
+
1131
+ function CommerceHandler(common) {
1132
+ this.common = common || {};
1133
+ }
1134
+
1135
+ CommerceHandler.prototype.logCommerceEvent = function() {
1136
+ /*
1137
+ Sample ecommerce event schema:
1138
+ {
1139
+ CurrencyCode: 'USD',
1140
+ DeviceId:'a80eea1c-57f5-4f84-815e-06fe971b6ef2', // MP generated
1141
+ EventAttributes: { key1: 'value1', key2: 'value2' },
1142
+ EventType: 16,
1143
+ EventCategory: 10, // (This is an add product to cart event, see below for additional ecommerce EventCategories)
1144
+ EventName: "eCommerce - AddToCart",
1145
+ MPID: "8278431810143183490",
1146
+ ProductAction: {
1147
+ Affiliation: 'aff1',
1148
+ CouponCode: 'coupon',
1149
+ ProductActionType: 7,
1150
+ ProductList: [
1151
+ {
1152
+ Attributes: { prodKey1: 'prodValue1', prodKey2: 'prodValue2' },
1153
+ Brand: 'Apple',
1154
+ Category: 'phones',
1155
+ CouponCode: 'coupon1',
1156
+ Name: 'iPhone',
1157
+ Price: '600',
1158
+ Quantity: 2,
1159
+ Sku: "SKU123",
1160
+ TotalAmount: 1200,
1161
+ Variant: '64GB'
1162
+ }
1163
+ ],
1164
+ TransactionId: "tid1",
1165
+ ShippingAmount: 10,
1166
+ TaxAmount: 5,
1167
+ TotalAmount: 1215,
1168
+ },
1169
+ UserAttributes: { userKey1: 'userValue1', userKey2: 'userValue2' }
1170
+ UserIdentities: [
1171
+ {
1172
+ Identity: 'test@gmail.com', Type: 7
1173
+ }
1174
+ ]
1175
+ }
1176
+
1177
+ If your SDK has specific ways to log different eCommerce events, see below for
1178
+ mParticle's additional ecommerce EventCategory types:
1179
+
1180
+ 10: ProductAddToCart, (as shown above)
1181
+ 11: ProductRemoveFromCart,
1182
+ 12: ProductCheckout,
1183
+ 13: ProductCheckoutOption,
1184
+ 14: ProductClick,
1185
+ 15: ProductViewDetail,
1186
+ 16: ProductPurchase,
1187
+ 17: ProductRefund,
1188
+ 18: PromotionView,
1189
+ 19: PromotionClick,
1190
+ 20: ProductAddToWishlist,
1191
+ 21: ProductRemoveFromWishlist,
1192
+ 22: ProductImpression
1193
+ */
1194
+ };
1195
+
1196
+ var commerceHandler = CommerceHandler;
1197
+
1198
+ /*
1199
+ A non-ecommerce event has the following schema:
1200
+
1201
+ {
1202
+ DeviceId: "a80eea1c-57f5-4f84-815e-06fe971b6ef2",
1203
+ EventAttributes: {test: "Error", t: 'stack trace in string form'},
1204
+ EventName: "Error",
1205
+ MPID: "123123123123",
1206
+ UserAttributes: {userAttr1: 'value1', userAttr2: 'value2'},
1207
+ UserIdentities: [{Identity: 'email@gmail.com', Type: 7}]
1208
+ User Identity Types can be found here:
1209
+ }
1210
+
1211
+ */
1212
+
1213
+ function EventHandler(common) {
1214
+ this.common = common || {};
1215
+ }
1216
+ EventHandler.prototype.logEvent = function() {};
1217
+ EventHandler.prototype.logError = function() {
1218
+ // The schema for a logError event is the same, but noteworthy differences are as follows:
1219
+ // {
1220
+ // EventAttributes: {m: 'name of error passed into MP', s: "Error", t: 'stack trace in string form if applicable'},
1221
+ // EventName: "Error"
1222
+ // }
1223
+ };
1224
+ EventHandler.prototype.logPageView = function() {
1225
+ /* The schema for a logPagView event is the same, but noteworthy differences are as follows:
1226
+ {
1227
+ EventAttributes: {hostname: "www.google.com", title: 'Test Page'}, // These are event attributes only if no additional event attributes are explicitly provided to mParticle.logPageView(...)
1228
+ }
1229
+ */
1230
+ };
1231
+
1232
+ var eventHandler = EventHandler;
1233
+
1234
+ /*
1235
+ The 'mParticleUser' is an object with methods get user Identities and set/get user attributes
1236
+ Partners can determine what userIds are available to use in their SDK
1237
+ Call mParticleUser.getUserIdentities() to return an object of userIdentities --> { userIdentities: {customerid: '1234', email: 'email@gmail.com'} }
1238
+ For more identity types, see https://docs.mparticle.com/developers/sdk/web/idsync/#supported-identity-types
1239
+ Call mParticleUser.getMPID() to get mParticle ID
1240
+ For any additional methods, see https://docs.mparticle.com/developers/sdk/web/core-apidocs/classes/mParticle.Identity.getCurrentUser().html
1241
+ */
1242
+
1243
+ /*
1244
+ identityApiRequest has the schema:
1245
+ {
1246
+ userIdentities: {
1247
+ customerid: '123',
1248
+ email: 'abc'
1249
+ }
1250
+ }
1251
+ For more userIdentity types, see https://docs.mparticle.com/developers/sdk/web/idsync/#supported-identity-types
1252
+ */
1253
+
1254
+ function IdentityHandler(common) {
1255
+ this.common = common || {};
1256
+ }
1257
+ IdentityHandler.prototype.onUserIdentified = function() {};
1258
+ IdentityHandler.prototype.onIdentifyComplete = function() {};
1259
+
1260
+ //Must re-initialize ID5 with partner identities(pd) in the config to collect an updated ID5 ID
1261
+ IdentityHandler.prototype.onLoginComplete = function(
1262
+ mParticleUser
1263
+ ) {
1264
+ var partnerData = this.common.buildPartnerData(mParticleUser);
1265
+
1266
+ if (partnerData) {
1267
+ var id5Instance = window.ID5.init({partnerId: this.common.partnerId, pd: partnerData});
1268
+ var logId5Id = this.common.logId5Id;
1269
+
1270
+ id5Instance.onAvailable(function(status){
1271
+ logId5Id(status.getUserId());
1272
+ }.bind(logId5Id));
1273
+ }
1274
+ };
1275
+
1276
+ //Must re-initialize ID5 without partner identities (pd) in the config to revert to an anonymous ID5 ID
1277
+ IdentityHandler.prototype.onLogoutComplete = function(
1278
+ ) {
1279
+ var id5Instance = window.ID5.init({partnerId: this.common.partnerId});
1280
+ var logId5Id = this.common.logId5Id;
1281
+
1282
+ id5Instance.onAvailable(function(status){
1283
+ logId5Id(status.getUserId());
1284
+ }.bind(logId5Id));
1285
+ };
1286
+
1287
+ IdentityHandler.prototype.onModifyComplete = function() {};
1288
+
1289
+ /* In previous versions of the mParticle web SDK, setting user identities on
1290
+ kits is only reachable via the onSetUserIdentity method below. We recommend
1291
+ filling out `onSetUserIdentity` for maximum compatibility
1292
+ */
1293
+ IdentityHandler.prototype.onSetUserIdentity = function() {};
1294
+
1295
+ var identityHandler = IdentityHandler;
1296
+
1297
+ var initialization = {
1298
+ name: 'ID5',
1299
+ moduleId: '248',
1300
+ /* ****** Fill out initForwarder to load your SDK ******
1301
+ Note that not all arguments may apply to your SDK initialization.
1302
+ These are passed from mParticle, but leave them even if they are not being used.
1303
+ forwarderSettings contain settings that your SDK requires in order to initialize
1304
+ userAttributes example: {gender: 'male', age: 25}
1305
+ userIdentities example: { 1: 'customerId', 2: 'facebookId', 7: 'emailid@email.com' }
1306
+ additional identityTypes can be found at https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/src/types.js#L88-L101
1307
+ */
1308
+ initForwarder: function(forwarderSettings, testMode, userAttributes, userIdentities, processEvent, eventQueue, isInitialized, common) {
1309
+ /* `forwarderSettings` contains your SDK specific settings such as apiKey that your customer needs in order to initialize your SDK properly */
1310
+ common.partnerId = forwarderSettings.partnerId;
1311
+ common.id5IdType = forwarderSettings.id5IdType;
1312
+ common.moduleId = this.moduleId;
1313
+
1314
+ if (!testMode) {
1315
+ /* Load your Web SDK here using a variant of your snippet from your readme that your customers would generally put into their <head> tags
1316
+ Generally, our integrations create script tags and append them to the <head>. Please follow the following format as a guide:
1317
+ */
1318
+ //ID5 docs on initialization can be found here: https://github.com/id5io/id5-api.js/blob/master/README.md
1319
+ var id5Script = document.createElement('script');
1320
+ id5Script.src = 'https://cdn.id5-sync.com/api/1.0/id5-api.js';
1321
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(id5Script);
1322
+
1323
+ id5Script.onload = function() {
1324
+
1325
+ var id5Instance = window.ID5.init({partnerId: common.partnerId});
1326
+
1327
+ id5Instance.onAvailable(function(status){
1328
+ common.logId5Id(status.getUserId());
1329
+ }.bind(common));
1330
+ };
1331
+ } else {
1332
+
1333
+ var id5Instance = window.ID5.init({partnerId: common.partnerId});
1334
+
1335
+ id5Instance.onAvailable(function(status){
1336
+ common.logId5Id(status.getUserId());
1337
+ }.bind(common));
1338
+ }
1339
+ }
1340
+ };
1341
+
1342
+ var initialization_1 = initialization;
1343
+
1344
+ var sessionHandler = {
1345
+ onSessionStart: function() {
1346
+
1347
+ },
1348
+ onSessionEnd: function() {
1349
+
1350
+ }
1351
+ };
1352
+
1353
+ var sessionHandler_1 = sessionHandler;
1354
+
1355
+ /*
1356
+ The 'mParticleUser' is an object with methods on it to get user Identities and set/get user attributes
1357
+ Partners can determine what userIds are available to use in their SDK
1358
+ Call mParticleUser.getUserIdentities() to return an object of userIdentities --> { userIdentities: {customerid: '1234', email: 'email@gmail.com'} }
1359
+ For more identity types, see http://docs.mparticle.com/developers/sdk/javascript/identity#allowed-identity-types
1360
+ Call mParticleUser.getMPID() to get mParticle ID
1361
+ For any additional methods, see http://docs.mparticle.com/developers/sdk/javascript/apidocs/classes/mParticle.Identity.getCurrentUser().html
1362
+ */
1363
+
1364
+ function UserAttributeHandler(common) {
1365
+ this.common = common || {};
1366
+ }
1367
+ UserAttributeHandler.prototype.onRemoveUserAttribute = function() {};
1368
+ UserAttributeHandler.prototype.onSetUserAttribute = function() {};
1369
+ UserAttributeHandler.prototype.onConsentStateUpdated = function() {};
1370
+
1371
+ var userAttributeHandler = UserAttributeHandler;
1372
+
1373
+ // =============== REACH OUT TO MPARTICLE IF YOU HAVE ANY QUESTIONS ===============
1374
+ //
1375
+ // Copyright 2018 mParticle, Inc.
1376
+ //
1377
+ // Licensed under the Apache License, Version 2.0 (the "License");
1378
+ // you may not use this file except in compliance with the License.
1379
+ // You may obtain a copy of the License at
1380
+ //
1381
+ // http://www.apache.org/licenses/LICENSE-2.0
1382
+ //
1383
+ // Unless required by applicable law or agreed to in writing, software
1384
+ // distributed under the License is distributed on an "AS IS" BASIS,
1385
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1386
+ // See the License for the specific language governing permissions and
1387
+ // limitations under the License.
1388
+
1389
+
1390
+
1391
+
1392
+
1393
+
1394
+
1395
+
1396
+
1397
+ var name = initialization_1.name,
1398
+ moduleId = initialization_1.moduleId,
1399
+ MessageType = {
1400
+ SessionStart: 1,
1401
+ SessionEnd: 2,
1402
+ PageView: 3,
1403
+ PageEvent: 4,
1404
+ CrashReport: 5,
1405
+ OptOut: 6,
1406
+ Commerce: 16,
1407
+ Media: 20,
1408
+ };
1409
+
1410
+ var constructor = function() {
1411
+ var self = this,
1412
+ isInitialized = false,
1413
+ forwarderSettings,
1414
+ reportingService,
1415
+ eventQueue = [];
1416
+
1417
+ self.name = initialization_1.name;
1418
+ self.moduleId = initialization_1.moduleId;
1419
+ self.common = new common();
1420
+
1421
+ function initForwarder(
1422
+ settings,
1423
+ service,
1424
+ testMode,
1425
+ trackerId,
1426
+ userAttributes,
1427
+ userIdentities,
1428
+ appVersion,
1429
+ appName,
1430
+ customFlags,
1431
+ clientId
1432
+ ) {
1433
+ forwarderSettings = settings;
1434
+
1435
+ if (
1436
+ typeof window !== 'undefined' &&
1437
+ window.mParticle.isTestEnvironment
1438
+ ) {
1439
+ reportingService = function() {};
1440
+ } else {
1441
+ reportingService = service;
1442
+ }
1443
+
1444
+ try {
1445
+ initialization_1.initForwarder(
1446
+ settings,
1447
+ testMode,
1448
+ userAttributes,
1449
+ userIdentities,
1450
+ processEvent,
1451
+ eventQueue,
1452
+ isInitialized,
1453
+ self.common,
1454
+ appVersion,
1455
+ appName,
1456
+ customFlags,
1457
+ clientId
1458
+ );
1459
+ self.eventHandler = new eventHandler(self.common);
1460
+ self.identityHandler = new identityHandler(self.common);
1461
+ self.userAttributeHandler = new userAttributeHandler(self.common);
1462
+ self.commerceHandler = new commerceHandler(self.common);
1463
+
1464
+ isInitialized = true;
1465
+ } catch (e) {
1466
+ console.log('Failed to initialize ' + name + ' - ' + e);
1467
+ }
1468
+ }
1469
+
1470
+ function processEvent(event) {
1471
+ var reportEvent = false;
1472
+ if (isInitialized) {
1473
+ try {
1474
+ if (event.EventDataType === MessageType.SessionStart) {
1475
+ reportEvent = logSessionStart(event);
1476
+ } else if (event.EventDataType === MessageType.SessionEnd) {
1477
+ reportEvent = logSessionEnd(event);
1478
+ } else if (event.EventDataType === MessageType.CrashReport) {
1479
+ reportEvent = logError(event);
1480
+ } else if (event.EventDataType === MessageType.PageView) {
1481
+ reportEvent = logPageView(event);
1482
+ } else if (event.EventDataType === MessageType.Commerce) {
1483
+ reportEvent = logEcommerceEvent(event);
1484
+ } else if (event.EventDataType === MessageType.PageEvent) {
1485
+ reportEvent = logEvent(event);
1486
+ } else if (event.EventDataType === MessageType.Media) {
1487
+ // Kits should just treat Media Events as generic Events
1488
+ reportEvent = logEvent(event);
1489
+ }
1490
+ if (reportEvent === true && reportingService) {
1491
+ reportingService(self, event);
1492
+ return 'Successfully sent to ' + name;
1493
+ } else {
1494
+ return (
1495
+ 'Error logging event or event type not supported on forwarder ' +
1496
+ name
1497
+ );
1498
+ }
1499
+ } catch (e) {
1500
+ return 'Failed to send to ' + name + ' ' + e;
1501
+ }
1502
+ } else {
1503
+ eventQueue.push(event);
1504
+ return (
1505
+ "Can't send to forwarder " +
1506
+ name +
1507
+ ', not initialized. Event added to queue.'
1508
+ );
1509
+ }
1510
+ }
1511
+
1512
+ function logSessionStart(event) {
1513
+ try {
1514
+ return sessionHandler_1.onSessionStart(event);
1515
+ } catch (e) {
1516
+ return {
1517
+ error: 'Error starting session on forwarder ' + name + '; ' + e,
1518
+ };
1519
+ }
1520
+ }
1521
+
1522
+ function logSessionEnd(event) {
1523
+ try {
1524
+ return sessionHandler_1.onSessionEnd(event);
1525
+ } catch (e) {
1526
+ return {
1527
+ error: 'Error ending session on forwarder ' + name + '; ' + e,
1528
+ };
1529
+ }
1530
+ }
1531
+
1532
+ function logError(event) {
1533
+ try {
1534
+ return self.eventHandler.logError(event);
1535
+ } catch (e) {
1536
+ return {
1537
+ error: 'Error logging error on forwarder ' + name + '; ' + e,
1538
+ };
1539
+ }
1540
+ }
1541
+
1542
+ function logPageView(event) {
1543
+ try {
1544
+ return self.eventHandler.logPageView(event);
1545
+ } catch (e) {
1546
+ return {
1547
+ error:
1548
+ 'Error logging page view on forwarder ' + name + '; ' + e,
1549
+ };
1550
+ }
1551
+ }
1552
+
1553
+ function logEvent(event) {
1554
+ try {
1555
+ return self.eventHandler.logEvent(event);
1556
+ } catch (e) {
1557
+ return {
1558
+ error: 'Error logging event on forwarder ' + name + '; ' + e,
1559
+ };
1560
+ }
1561
+ }
1562
+
1563
+ function logEcommerceEvent(event) {
1564
+ try {
1565
+ return self.commerceHandler.logCommerceEvent(event);
1566
+ } catch (e) {
1567
+ return {
1568
+ error:
1569
+ 'Error logging purchase event on forwarder ' +
1570
+ name +
1571
+ '; ' +
1572
+ e,
1573
+ };
1574
+ }
1575
+ }
1576
+
1577
+ function setUserAttribute(key, value) {
1578
+ if (isInitialized) {
1579
+ try {
1580
+ self.userAttributeHandler.onSetUserAttribute(
1581
+ key,
1582
+ value,
1583
+ forwarderSettings
1584
+ );
1585
+ return 'Successfully set user attribute on forwarder ' + name;
1586
+ } catch (e) {
1587
+ return (
1588
+ 'Error setting user attribute on forwarder ' +
1589
+ name +
1590
+ '; ' +
1591
+ e
1592
+ );
1593
+ }
1594
+ } else {
1595
+ return (
1596
+ "Can't set user attribute on forwarder " +
1597
+ name +
1598
+ ', not initialized'
1599
+ );
1600
+ }
1601
+ }
1602
+
1603
+ function removeUserAttribute(key) {
1604
+ if (isInitialized) {
1605
+ try {
1606
+ self.userAttributeHandler.onRemoveUserAttribute(
1607
+ key,
1608
+ forwarderSettings
1609
+ );
1610
+ return (
1611
+ 'Successfully removed user attribute on forwarder ' + name
1612
+ );
1613
+ } catch (e) {
1614
+ return (
1615
+ 'Error removing user attribute on forwarder ' +
1616
+ name +
1617
+ '; ' +
1618
+ e
1619
+ );
1620
+ }
1621
+ } else {
1622
+ return (
1623
+ "Can't remove user attribute on forwarder " +
1624
+ name +
1625
+ ', not initialized'
1626
+ );
1627
+ }
1628
+ }
1629
+
1630
+ function setUserIdentity(id, type) {
1631
+ if (isInitialized) {
1632
+ try {
1633
+ self.identityHandler.onSetUserIdentity(
1634
+ forwarderSettings,
1635
+ id,
1636
+ type
1637
+ );
1638
+ return 'Successfully set user Identity on forwarder ' + name;
1639
+ } catch (e) {
1640
+ return (
1641
+ 'Error removing user attribute on forwarder ' +
1642
+ name +
1643
+ '; ' +
1644
+ e
1645
+ );
1646
+ }
1647
+ } else {
1648
+ return (
1649
+ "Can't call setUserIdentity on forwarder " +
1650
+ name +
1651
+ ', not initialized'
1652
+ );
1653
+ }
1654
+ }
1655
+
1656
+ function onUserIdentified(user) {
1657
+ if (isInitialized) {
1658
+ try {
1659
+ self.identityHandler.onUserIdentified(user);
1660
+
1661
+ return (
1662
+ 'Successfully called onUserIdentified on forwarder ' + name
1663
+ );
1664
+ } catch (e) {
1665
+ return {
1666
+ error:
1667
+ 'Error calling onUserIdentified on forwarder ' +
1668
+ name +
1669
+ '; ' +
1670
+ e,
1671
+ };
1672
+ }
1673
+ } else {
1674
+ return (
1675
+ "Can't set new user identities on forwader " +
1676
+ name +
1677
+ ', not initialized'
1678
+ );
1679
+ }
1680
+ }
1681
+
1682
+ function onIdentifyComplete(user, filteredIdentityRequest) {
1683
+ if (isInitialized) {
1684
+ try {
1685
+ self.identityHandler.onIdentifyComplete(
1686
+ user,
1687
+ filteredIdentityRequest
1688
+ );
1689
+
1690
+ return (
1691
+ 'Successfully called onIdentifyComplete on forwarder ' +
1692
+ name
1693
+ );
1694
+ } catch (e) {
1695
+ return {
1696
+ error:
1697
+ 'Error calling onIdentifyComplete on forwarder ' +
1698
+ name +
1699
+ '; ' +
1700
+ e,
1701
+ };
1702
+ }
1703
+ } else {
1704
+ return (
1705
+ "Can't call onIdentifyCompleted on forwader " +
1706
+ name +
1707
+ ', not initialized'
1708
+ );
1709
+ }
1710
+ }
1711
+
1712
+ function onLoginComplete(user, filteredIdentityRequest) {
1713
+ if (isInitialized) {
1714
+ try {
1715
+ self.identityHandler.onLoginComplete(
1716
+ user,
1717
+ filteredIdentityRequest
1718
+ );
1719
+
1720
+ return (
1721
+ 'Successfully called onLoginComplete on forwarder ' + name
1722
+ );
1723
+ } catch (e) {
1724
+ return {
1725
+ error:
1726
+ 'Error calling onLoginComplete on forwarder ' +
1727
+ name +
1728
+ '; ' +
1729
+ e,
1730
+ };
1731
+ }
1732
+ } else {
1733
+ return (
1734
+ "Can't call onLoginComplete on forwader " +
1735
+ name +
1736
+ ', not initialized'
1737
+ );
1738
+ }
1739
+ }
1740
+
1741
+ function onLogoutComplete(user, filteredIdentityRequest) {
1742
+ if (isInitialized) {
1743
+ try {
1744
+ self.identityHandler.onLogoutComplete(
1745
+ user,
1746
+ filteredIdentityRequest
1747
+ );
1748
+
1749
+ return (
1750
+ 'Successfully called onLogoutComplete on forwarder ' + name
1751
+ );
1752
+ } catch (e) {
1753
+ return {
1754
+ error:
1755
+ 'Error calling onLogoutComplete on forwarder ' +
1756
+ name +
1757
+ '; ' +
1758
+ e,
1759
+ };
1760
+ }
1761
+ } else {
1762
+ return (
1763
+ "Can't call onLogoutComplete on forwader " +
1764
+ name +
1765
+ ', not initialized'
1766
+ );
1767
+ }
1768
+ }
1769
+
1770
+ function onModifyComplete(user, filteredIdentityRequest) {
1771
+ if (isInitialized) {
1772
+ try {
1773
+ self.identityHandler.onModifyComplete(
1774
+ user,
1775
+ filteredIdentityRequest
1776
+ );
1777
+
1778
+ return (
1779
+ 'Successfully called onModifyComplete on forwarder ' + name
1780
+ );
1781
+ } catch (e) {
1782
+ return {
1783
+ error:
1784
+ 'Error calling onModifyComplete on forwarder ' +
1785
+ name +
1786
+ '; ' +
1787
+ e,
1788
+ };
1789
+ }
1790
+ } else {
1791
+ return (
1792
+ "Can't call onModifyComplete on forwader " +
1793
+ name +
1794
+ ', not initialized'
1795
+ );
1796
+ }
1797
+ }
1798
+
1799
+ function setOptOut(isOptingOutBoolean) {
1800
+ if (isInitialized) {
1801
+ try {
1802
+ self.initialization.setOptOut(isOptingOutBoolean);
1803
+
1804
+ return 'Successfully called setOptOut on forwarder ' + name;
1805
+ } catch (e) {
1806
+ return {
1807
+ error:
1808
+ 'Error calling setOptOut on forwarder ' +
1809
+ name +
1810
+ '; ' +
1811
+ e,
1812
+ };
1813
+ }
1814
+ } else {
1815
+ return (
1816
+ "Can't call setOptOut on forwader " +
1817
+ name +
1818
+ ', not initialized'
1819
+ );
1820
+ }
1821
+ }
1822
+
1823
+ this.init = initForwarder;
1824
+ this.process = processEvent;
1825
+ this.setUserAttribute = setUserAttribute;
1826
+ this.removeUserAttribute = removeUserAttribute;
1827
+ this.onUserIdentified = onUserIdentified;
1828
+ this.setUserIdentity = setUserIdentity;
1829
+ this.onIdentifyComplete = onIdentifyComplete;
1830
+ this.onLoginComplete = onLoginComplete;
1831
+ this.onLogoutComplete = onLogoutComplete;
1832
+ this.onModifyComplete = onModifyComplete;
1833
+ this.setOptOut = setOptOut;
1834
+ };
1835
+
1836
+ function getId() {
1837
+ return moduleId;
1838
+ }
1839
+
1840
+ function isObject(val) {
1841
+ return (
1842
+ val != null && typeof val === 'object' && Array.isArray(val) === false
1843
+ );
1844
+ }
1845
+
1846
+ function register(config) {
1847
+ if (!config) {
1848
+ console.log(
1849
+ 'You must pass a config object to register the kit ' + name
1850
+ );
1851
+ return;
1852
+ }
1853
+
1854
+ if (!isObject(config)) {
1855
+ console.log(
1856
+ "'config' must be an object. You passed in a " + typeof config
1857
+ );
1858
+ return;
1859
+ }
1860
+
1861
+ if (isObject(config.kits)) {
1862
+ config.kits[name] = {
1863
+ constructor: constructor,
1864
+ };
1865
+ } else {
1866
+ config.kits = {};
1867
+ config.kits[name] = {
1868
+ constructor: constructor,
1869
+ };
1870
+ }
1871
+ console.log(
1872
+ 'Successfully registered ' + name + ' to your mParticle configuration'
1873
+ );
1874
+ }
1875
+
1876
+ if (typeof window !== 'undefined') {
1877
+ if (window && window.mParticle && window.mParticle.addForwarder) {
1878
+ window.mParticle.addForwarder({
1879
+ name: name,
1880
+ constructor: constructor,
1881
+ getId: getId,
1882
+ });
1883
+ }
1884
+ }
1885
+
1886
+ var webKitWrapper = {
1887
+ register: register,
1888
+ };
1889
+ var webKitWrapper_1 = webKitWrapper.register;
1890
+
1891
+ exports.default = webKitWrapper;
1892
+ exports.register = webKitWrapper_1;