mezon-js 2.9.95 → 2.9.96

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/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export * from "./client";
18
18
  export * from "./session";
19
19
  export * from "./socket";
20
20
  export * from "./web_socket_adapter";
21
+ export * from "./utils";
21
22
  /**
22
23
  * Reexported due to duplicate definition of ChannelMessage in [Client]{@link ./client.ts} and [Session]{@link ./session.ts}
23
24
  */
@@ -61,7 +61,11 @@ __export(mezon_js_exports, {
61
61
  NotificationType: () => NotificationType,
62
62
  Session: () => Session,
63
63
  WebSocketAdapterText: () => WebSocketAdapterText,
64
- WebrtcSignalingType: () => WebrtcSignalingType
64
+ WebrtcSignalingType: () => WebrtcSignalingType,
65
+ b64DecodeUnicode: () => b64DecodeUnicode,
66
+ b64EncodeUnicode: () => b64EncodeUnicode,
67
+ buildFetchOptions: () => buildFetchOptions,
68
+ safeJSONParse: () => safeJSONParse
65
69
  });
66
70
  module.exports = __toCommonJS(mezon_js_exports);
67
71
 
@@ -640,6 +644,19 @@ var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
640
644
  var utob = (u) => u.replace(re_utob, cb_utob);
641
645
  var _encode = _hasBuffer ? (s) => Buffer.from(s, "utf8").toString("base64") : _TE ? (s) => _fromUint8Array(_TE.encode(s)) : (s) => _btoa(utob(s));
642
646
  var encode = (src, urlsafe = false) => urlsafe ? _mkUriSafe(_encode(src)) : _encode(src);
647
+ var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
648
+ var cb_btou = (cccc) => {
649
+ switch (cccc.length) {
650
+ case 4:
651
+ var cp = (7 & cccc.charCodeAt(0)) << 18 | (63 & cccc.charCodeAt(1)) << 12 | (63 & cccc.charCodeAt(2)) << 6 | 63 & cccc.charCodeAt(3), offset = cp - 65536;
652
+ return _fromCC((offset >>> 10) + 55296) + _fromCC((offset & 1023) + 56320);
653
+ case 3:
654
+ return _fromCC((15 & cccc.charCodeAt(0)) << 12 | (63 & cccc.charCodeAt(1)) << 6 | 63 & cccc.charCodeAt(2));
655
+ default:
656
+ return _fromCC((31 & cccc.charCodeAt(0)) << 6 | 63 & cccc.charCodeAt(1));
657
+ }
658
+ };
659
+ var btou = (b) => b.replace(re_btou, cb_btou);
643
660
  var atobPolyfill = (asc) => {
644
661
  asc = asc.replace(/\s+/g, "");
645
662
  if (!b64re.test(asc))
@@ -653,6 +670,10 @@ var atobPolyfill = (asc) => {
653
670
  return bin;
654
671
  };
655
672
  var _atob = typeof atob === "function" ? (asc) => atob(_tidyB64(asc)) : _hasBuffer ? (asc) => Buffer.from(asc, "base64").toString("binary") : atobPolyfill;
673
+ var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a).split("").map((c) => c.charCodeAt(0)));
674
+ var _decode = _hasBuffer ? (a) => Buffer.from(a, "base64").toString("utf8") : _TD ? (a) => _TD.decode(_toUint8Array(a)) : (a) => btou(_atob(a));
675
+ var _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == "-" ? "+" : "/"));
676
+ var decode2 = (src) => _decode(_unURI(src));
656
677
 
657
678
  // utils.ts
658
679
  function buildFetchOptions(method, options, bodyJson) {
@@ -680,6 +701,19 @@ function buildFetchOptions(method, options, bodyJson) {
680
701
  }
681
702
  return fetchOptions;
682
703
  }
704
+ function b64EncodeUnicode(str) {
705
+ return encode(encodeURIComponent(str).replace(
706
+ /%([0-9A-F]{2})/g,
707
+ function toSolidBytes(_match, p1) {
708
+ return String.fromCharCode(Number("0x" + p1));
709
+ }
710
+ ));
711
+ }
712
+ function b64DecodeUnicode(str) {
713
+ return decodeURIComponent(decode2(str).split("").map(function(c) {
714
+ return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
715
+ }).join(""));
716
+ }
683
717
  function safeJSONParse(jsonString) {
684
718
  try {
685
719
  const unescapedJSON = jsonString.replace(/\\./g, (match) => {
@@ -6863,7 +6897,7 @@ var encode2 = function(arraybuffer) {
6863
6897
  }
6864
6898
  return base64;
6865
6899
  };
6866
- var decode2 = function(base64) {
6900
+ var decode3 = function(base64) {
6867
6901
  var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
6868
6902
  if (base64[base64.length - 1] === "=") {
6869
6903
  bufferLength--;
@@ -6907,7 +6941,7 @@ var WebSocketAdapterText = class {
6907
6941
  const message = safeJSONParse(evt.data);
6908
6942
  if (message.party_data && message.party_data.data) {
6909
6943
  message.party_data.data = new Uint8Array(
6910
- decode2(message.party_data.data)
6944
+ decode3(message.party_data.data)
6911
6945
  );
6912
6946
  }
6913
6947
  value(message);
@@ -610,6 +610,19 @@ var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
610
610
  var utob = (u) => u.replace(re_utob, cb_utob);
611
611
  var _encode = _hasBuffer ? (s) => Buffer.from(s, "utf8").toString("base64") : _TE ? (s) => _fromUint8Array(_TE.encode(s)) : (s) => _btoa(utob(s));
612
612
  var encode = (src, urlsafe = false) => urlsafe ? _mkUriSafe(_encode(src)) : _encode(src);
613
+ var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
614
+ var cb_btou = (cccc) => {
615
+ switch (cccc.length) {
616
+ case 4:
617
+ var cp = (7 & cccc.charCodeAt(0)) << 18 | (63 & cccc.charCodeAt(1)) << 12 | (63 & cccc.charCodeAt(2)) << 6 | 63 & cccc.charCodeAt(3), offset = cp - 65536;
618
+ return _fromCC((offset >>> 10) + 55296) + _fromCC((offset & 1023) + 56320);
619
+ case 3:
620
+ return _fromCC((15 & cccc.charCodeAt(0)) << 12 | (63 & cccc.charCodeAt(1)) << 6 | 63 & cccc.charCodeAt(2));
621
+ default:
622
+ return _fromCC((31 & cccc.charCodeAt(0)) << 6 | 63 & cccc.charCodeAt(1));
623
+ }
624
+ };
625
+ var btou = (b) => b.replace(re_btou, cb_btou);
613
626
  var atobPolyfill = (asc) => {
614
627
  asc = asc.replace(/\s+/g, "");
615
628
  if (!b64re.test(asc))
@@ -623,6 +636,10 @@ var atobPolyfill = (asc) => {
623
636
  return bin;
624
637
  };
625
638
  var _atob = typeof atob === "function" ? (asc) => atob(_tidyB64(asc)) : _hasBuffer ? (asc) => Buffer.from(asc, "base64").toString("binary") : atobPolyfill;
639
+ var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a).split("").map((c) => c.charCodeAt(0)));
640
+ var _decode = _hasBuffer ? (a) => Buffer.from(a, "base64").toString("utf8") : _TD ? (a) => _TD.decode(_toUint8Array(a)) : (a) => btou(_atob(a));
641
+ var _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == "-" ? "+" : "/"));
642
+ var decode2 = (src) => _decode(_unURI(src));
626
643
 
627
644
  // utils.ts
628
645
  function buildFetchOptions(method, options, bodyJson) {
@@ -650,6 +667,19 @@ function buildFetchOptions(method, options, bodyJson) {
650
667
  }
651
668
  return fetchOptions;
652
669
  }
670
+ function b64EncodeUnicode(str) {
671
+ return encode(encodeURIComponent(str).replace(
672
+ /%([0-9A-F]{2})/g,
673
+ function toSolidBytes(_match, p1) {
674
+ return String.fromCharCode(Number("0x" + p1));
675
+ }
676
+ ));
677
+ }
678
+ function b64DecodeUnicode(str) {
679
+ return decodeURIComponent(decode2(str).split("").map(function(c) {
680
+ return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
681
+ }).join(""));
682
+ }
653
683
  function safeJSONParse(jsonString) {
654
684
  try {
655
685
  const unescapedJSON = jsonString.replace(/\\./g, (match) => {
@@ -6833,7 +6863,7 @@ var encode2 = function(arraybuffer) {
6833
6863
  }
6834
6864
  return base64;
6835
6865
  };
6836
- var decode2 = function(base64) {
6866
+ var decode3 = function(base64) {
6837
6867
  var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
6838
6868
  if (base64[base64.length - 1] === "=") {
6839
6869
  bufferLength--;
@@ -6877,7 +6907,7 @@ var WebSocketAdapterText = class {
6877
6907
  const message = safeJSONParse(evt.data);
6878
6908
  if (message.party_data && message.party_data.data) {
6879
6909
  message.party_data.data = new Uint8Array(
6880
- decode2(message.party_data.data)
6910
+ decode3(message.party_data.data)
6881
6911
  );
6882
6912
  }
6883
6913
  value(message);
@@ -10426,5 +10456,9 @@ export {
10426
10456
  NotificationType,
10427
10457
  Session,
10428
10458
  WebSocketAdapterText,
10429
- WebrtcSignalingType
10459
+ WebrtcSignalingType,
10460
+ b64DecodeUnicode,
10461
+ b64EncodeUnicode,
10462
+ buildFetchOptions,
10463
+ safeJSONParse
10430
10464
  };
package/index.ts CHANGED
@@ -20,6 +20,7 @@ export * from "./client";
20
20
  export * from "./session";
21
21
  export * from "./socket";
22
22
  export * from "./web_socket_adapter";
23
+ export * from "./utils"
23
24
 
24
25
  /**
25
26
  * Reexported due to duplicate definition of ChannelMessage in [Client]{@link ./client.ts} and [Session]{@link ./session.ts}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mezon-js",
3
3
 
4
- "version": "2.9.95",
4
+ "version": "2.9.96",
5
5
 
6
6
  "scripts": {
7
7
  "build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs"