@blotoutio/edgetag-sdk-browser 0.8.5 → 0.9.1

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.
Files changed (2) hide show
  1. package/index.js +27 -481
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -402,492 +402,38 @@
402
402
  }
403
403
  };
404
404
 
405
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
406
- // require the crypto API and do not support built-in fallback to lower quality random number
407
- // generators (like Math.random()).
408
- let getRandomValues;
409
- const rnds8 = new Uint8Array(16);
410
- function rng() {
411
- // lazy load so that environments that need to polyfill have a chance to do so
412
- if (!getRandomValues) {
413
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
414
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
415
-
416
- if (!getRandomValues) {
417
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
418
- }
419
- }
420
-
421
- return getRandomValues(rnds8);
422
- }
423
-
424
- var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
425
-
426
- function validate(uuid) {
427
- return typeof uuid === 'string' && REGEX.test(uuid);
428
- }
429
-
430
- /**
431
- * Convert array of 16 byte values to UUID string format of the form:
432
- * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
433
- */
434
-
435
- const byteToHex = [];
436
-
437
- for (let i = 0; i < 256; ++i) {
438
- byteToHex.push((i + 0x100).toString(16).slice(1));
439
- }
440
-
441
- function unsafeStringify(arr, offset = 0) {
442
- // Note: Be careful editing this code! It's been tuned for performance
443
- // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
444
- return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
445
- }
446
-
447
- function parse(uuid) {
448
- if (!validate(uuid)) {
449
- throw TypeError('Invalid UUID');
450
- }
451
-
452
- let v;
453
- const arr = new Uint8Array(16); // Parse ########-....-....-....-............
454
-
455
- arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
456
- arr[1] = v >>> 16 & 0xff;
457
- arr[2] = v >>> 8 & 0xff;
458
- arr[3] = v & 0xff; // Parse ........-####-....-....-............
459
-
460
- arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
461
- arr[5] = v & 0xff; // Parse ........-....-####-....-............
462
-
463
- arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
464
- arr[7] = v & 0xff; // Parse ........-....-....-####-............
465
-
466
- arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
467
- arr[9] = v & 0xff; // Parse ........-....-....-....-############
468
- // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
469
-
470
- arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
471
- arr[11] = v / 0x100000000 & 0xff;
472
- arr[12] = v >>> 24 & 0xff;
473
- arr[13] = v >>> 16 & 0xff;
474
- arr[14] = v >>> 8 & 0xff;
475
- arr[15] = v & 0xff;
476
- return arr;
477
- }
478
-
479
- function stringToBytes(str) {
480
- str = unescape(encodeURIComponent(str)); // UTF8 escape
481
-
482
- const bytes = [];
483
-
484
- for (let i = 0; i < str.length; ++i) {
485
- bytes.push(str.charCodeAt(i));
486
- }
487
-
488
- return bytes;
489
- }
490
-
491
- const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
492
- const URL$1 = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
493
- function v35(name, version, hashfunc) {
494
- function generateUUID(value, namespace, buf, offset) {
495
- var _namespace;
496
-
497
- if (typeof value === 'string') {
498
- value = stringToBytes(value);
499
- }
500
-
501
- if (typeof namespace === 'string') {
502
- namespace = parse(namespace);
503
- }
504
-
505
- if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
506
- throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
507
- } // Compute hash of namespace and value, Per 4.3
508
- // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
509
- // hashfunc([...namespace, ... value])`
510
-
511
-
512
- let bytes = new Uint8Array(16 + value.length);
513
- bytes.set(namespace);
514
- bytes.set(value, namespace.length);
515
- bytes = hashfunc(bytes);
516
- bytes[6] = bytes[6] & 0x0f | version;
517
- bytes[8] = bytes[8] & 0x3f | 0x80;
518
-
519
- if (buf) {
520
- offset = offset || 0;
521
-
522
- for (let i = 0; i < 16; ++i) {
523
- buf[offset + i] = bytes[i];
524
- }
525
-
526
- return buf;
527
- }
528
-
529
- return unsafeStringify(bytes);
530
- } // Function#name is not settable on some platforms (#270)
531
-
532
-
533
- try {
534
- generateUUID.name = name; // eslint-disable-next-line no-empty
535
- } catch (err) {} // For CommonJS default export support
536
-
537
-
538
- generateUUID.DNS = DNS;
539
- generateUUID.URL = URL$1;
540
- return generateUUID;
541
- }
542
-
543
- /*
544
- * Browser-compatible JavaScript MD5
545
- *
546
- * Modification of JavaScript MD5
547
- * https://github.com/blueimp/JavaScript-MD5
548
- *
549
- * Copyright 2011, Sebastian Tschan
550
- * https://blueimp.net
551
- *
552
- * Licensed under the MIT license:
553
- * https://opensource.org/licenses/MIT
554
- *
555
- * Based on
556
- * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
557
- * Digest Algorithm, as defined in RFC 1321.
558
- * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
559
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
560
- * Distributed under the BSD License
561
- * See http://pajhome.org.uk/crypt/md5 for more info.
562
- */
563
- function md5(bytes) {
564
- if (typeof bytes === 'string') {
565
- const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
566
-
567
- bytes = new Uint8Array(msg.length);
568
-
569
- for (let i = 0; i < msg.length; ++i) {
570
- bytes[i] = msg.charCodeAt(i);
571
- }
572
- }
573
-
574
- return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
575
- }
576
- /*
577
- * Convert an array of little-endian words to an array of bytes
578
- */
579
-
580
-
581
- function md5ToHexEncodedArray(input) {
582
- const output = [];
583
- const length32 = input.length * 32;
584
- const hexTab = '0123456789abcdef';
585
-
586
- for (let i = 0; i < length32; i += 8) {
587
- const x = input[i >> 5] >>> i % 32 & 0xff;
588
- const hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
589
- output.push(hex);
590
- }
591
-
592
- return output;
593
- }
594
- /**
595
- * Calculate output length with padding and bit length
596
- */
597
-
598
-
599
- function getOutputLength(inputLength8) {
600
- return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
601
- }
602
- /*
603
- * Calculate the MD5 of an array of little-endian words, and a bit length.
604
- */
605
-
606
-
607
- function wordsToMd5(x, len) {
608
- /* append padding */
609
- x[len >> 5] |= 0x80 << len % 32;
610
- x[getOutputLength(len) - 1] = len;
611
- let a = 1732584193;
612
- let b = -271733879;
613
- let c = -1732584194;
614
- let d = 271733878;
615
-
616
- for (let i = 0; i < x.length; i += 16) {
617
- const olda = a;
618
- const oldb = b;
619
- const oldc = c;
620
- const oldd = d;
621
- a = md5ff(a, b, c, d, x[i], 7, -680876936);
622
- d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
623
- c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
624
- b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
625
- a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
626
- d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
627
- c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
628
- b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
629
- a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
630
- d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
631
- c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
632
- b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
633
- a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
634
- d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
635
- c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
636
- b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
637
- a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
638
- d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
639
- c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
640
- b = md5gg(b, c, d, a, x[i], 20, -373897302);
641
- a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
642
- d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
643
- c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
644
- b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
645
- a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
646
- d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
647
- c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
648
- b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
649
- a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
650
- d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
651
- c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
652
- b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
653
- a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
654
- d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
655
- c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
656
- b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
657
- a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
658
- d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
659
- c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
660
- b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
661
- a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
662
- d = md5hh(d, a, b, c, x[i], 11, -358537222);
663
- c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
664
- b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
665
- a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
666
- d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
667
- c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
668
- b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
669
- a = md5ii(a, b, c, d, x[i], 6, -198630844);
670
- d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
671
- c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
672
- b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
673
- a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
674
- d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
675
- c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
676
- b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
677
- a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
678
- d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
679
- c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
680
- b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
681
- a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
682
- d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
683
- c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
684
- b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
685
- a = safeAdd(a, olda);
686
- b = safeAdd(b, oldb);
687
- c = safeAdd(c, oldc);
688
- d = safeAdd(d, oldd);
689
- }
690
-
691
- return [a, b, c, d];
692
- }
693
- /*
694
- * Convert an array bytes to an array of little-endian words
695
- * Characters >255 have their high-byte silently ignored.
696
- */
697
-
698
-
699
- function bytesToWords(input) {
700
- if (input.length === 0) {
701
- return [];
702
- }
703
-
704
- const length8 = input.length * 8;
705
- const output = new Uint32Array(getOutputLength(length8));
706
-
707
- for (let i = 0; i < length8; i += 8) {
708
- output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
709
- }
710
-
711
- return output;
712
- }
713
- /*
714
- * Add integers, wrapping at 2^32. This uses 16-bit operations internally
715
- * to work around bugs in some JS interpreters.
716
- */
717
-
718
-
719
- function safeAdd(x, y) {
720
- const lsw = (x & 0xffff) + (y & 0xffff);
721
- const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
722
- return msw << 16 | lsw & 0xffff;
723
- }
724
- /*
725
- * Bitwise rotate a 32-bit number to the left.
726
- */
727
-
728
-
729
- function bitRotateLeft(num, cnt) {
730
- return num << cnt | num >>> 32 - cnt;
731
- }
732
- /*
733
- * These functions implement the four basic operations the algorithm uses.
734
- */
735
-
736
-
737
- function md5cmn(q, a, b, x, s, t) {
738
- return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
739
- }
740
-
741
- function md5ff(a, b, c, d, x, s, t) {
742
- return md5cmn(b & c | ~b & d, a, b, x, s, t);
743
- }
744
-
745
- function md5gg(a, b, c, d, x, s, t) {
746
- return md5cmn(b & d | c & ~d, a, b, x, s, t);
747
- }
748
-
749
- function md5hh(a, b, c, d, x, s, t) {
750
- return md5cmn(b ^ c ^ d, a, b, x, s, t);
751
- }
752
-
753
- function md5ii(a, b, c, d, x, s, t) {
754
- return md5cmn(c ^ (b | ~d), a, b, x, s, t);
755
- }
756
-
757
- v35('v3', 0x30, md5);
758
-
759
- const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
760
- var native = {
761
- randomUUID
762
- };
763
-
764
- function v4(options, buf, offset) {
765
- if (native.randomUUID && !buf && !options) {
766
- return native.randomUUID();
767
- }
768
-
769
- options = options || {};
770
- const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
771
-
772
- rnds[6] = rnds[6] & 0x0f | 0x40;
773
- rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
774
-
775
- if (buf) {
776
- offset = offset || 0;
777
-
778
- for (let i = 0; i < 16; ++i) {
779
- buf[offset + i] = rnds[i];
780
- }
781
-
782
- return buf;
783
- }
784
-
785
- return unsafeStringify(rnds);
786
- }
787
-
788
- // Adapted from Chris Veness' SHA1 code at
789
- // http://www.movable-type.co.uk/scripts/sha1.html
790
- function f(s, x, y, z) {
791
- switch (s) {
792
- case 0:
793
- return x & y ^ ~x & z;
794
-
795
- case 1:
796
- return x ^ y ^ z;
797
-
798
- case 2:
799
- return x & y ^ x & z ^ y & z;
800
-
801
- case 3:
802
- return x ^ y ^ z;
803
- }
804
- }
805
-
806
- function ROTL(x, n) {
807
- return x << n | x >>> 32 - n;
808
- }
809
-
810
- function sha1(bytes) {
811
- const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
812
- const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
813
-
814
- if (typeof bytes === 'string') {
815
- const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
816
-
817
- bytes = [];
818
-
819
- for (let i = 0; i < msg.length; ++i) {
820
- bytes.push(msg.charCodeAt(i));
821
- }
822
- } else if (!Array.isArray(bytes)) {
823
- // Convert Array-like to Array
824
- bytes = Array.prototype.slice.call(bytes);
825
- }
826
-
827
- bytes.push(0x80);
828
- const l = bytes.length / 4 + 2;
829
- const N = Math.ceil(l / 16);
830
- const M = new Array(N);
831
-
832
- for (let i = 0; i < N; ++i) {
833
- const arr = new Uint32Array(16);
834
-
835
- for (let j = 0; j < 16; ++j) {
836
- arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
837
- }
838
-
839
- M[i] = arr;
840
- }
841
-
842
- M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
843
- M[N - 1][14] = Math.floor(M[N - 1][14]);
844
- M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
845
-
846
- for (let i = 0; i < N; ++i) {
847
- const W = new Uint32Array(80);
848
-
849
- for (let t = 0; t < 16; ++t) {
850
- W[t] = M[i][t];
851
- }
852
-
853
- for (let t = 16; t < 80; ++t) {
854
- W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
855
- }
856
-
857
- let a = H[0];
858
- let b = H[1];
859
- let c = H[2];
860
- let d = H[3];
861
- let e = H[4];
862
-
863
- for (let t = 0; t < 80; ++t) {
864
- const s = Math.floor(t / 20);
865
- const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
866
- e = d;
867
- d = c;
868
- c = ROTL(b, 30) >>> 0;
869
- b = a;
870
- a = T;
871
- }
872
-
873
- H[0] = H[0] + a >>> 0;
874
- H[1] = H[1] + b >>> 0;
875
- H[2] = H[2] + c >>> 0;
876
- H[3] = H[3] + d >>> 0;
877
- H[4] = H[4] + e >>> 0;
878
- }
879
-
880
- return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
881
- }
882
-
883
- v35('v5', 0x50, sha1);
884
-
885
405
  const encodeString = (name) => {
886
406
  if (typeof btoa === 'undefined') {
887
407
  return Buffer.from(name).toString('base64');
888
408
  }
889
409
  return btoa(name);
890
410
  };
411
+ const getBasicRandomNumber = () => {
412
+ return parseInt((Math.random() * 10000000000).toString(), 10);
413
+ };
414
+ const generateUUID = () => {
415
+ let id = '';
416
+ try {
417
+ id = crypto.randomUUID();
418
+ if (!id) {
419
+ const array = new Uint32Array(20);
420
+ const numbers = crypto.getRandomValues(array);
421
+ for (let i = 0; i < 5; i++) {
422
+ const y = i * 3;
423
+ if (i !== 0) {
424
+ id += '-';
425
+ }
426
+ const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3];
427
+ id += sum.toString();
428
+ }
429
+ }
430
+ }
431
+ catch (_a) {
432
+ id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
433
+ console.log('[EdgeTag] Crypto module not found');
434
+ }
435
+ return id;
436
+ };
891
437
  const generateEventId = (name) => {
892
438
  let time = Date.now().toString();
893
439
  if (typeof performance !== 'undefined' &&
@@ -897,7 +443,7 @@
897
443
  time = perf.toFixed(4);
898
444
  }
899
445
  }
900
- return `${encodeString(name)}-${v4()}-${time}`;
446
+ return `${encodeString(name)}-${generateUUID()}-${time}`;
901
447
  };
902
448
 
903
449
  const getCookieValue = (key) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.8.5",
3
+ "version": "0.9.1",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",