ropegeo-common 1.2.7 → 1.2.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../../src/types/cursors/cursor.ts"],"names":[],"mappings":"AAEA,oBAAY,UAAU;IAClB,MAAM,WAAW;IACjB,cAAc,oBAAoB;IAClC,YAAY,kBAAkB;CACjC;AAKD;;;GAGG;AACH,8BAAsB,MAAM;IACxB,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEzC,0EAA0E;IAC1E,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAEvD,YAAY,IAAI,MAAM;IAOtB;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAkB7F;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAC/B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,QAAQ,EAAE,UAAU,EACpB,UAAU,EAAE,MAAM,GACnB,IAAI;CAUV"}
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../../src/types/cursors/cursor.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IAClB,MAAM,WAAW;IACjB,cAAc,oBAAoB;IAClC,YAAY,kBAAkB;CACjC;AAuBD;;;GAGG;AACH,8BAAsB,MAAM;IACxB,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAEzC,0EAA0E;IAC1E,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAEvD,YAAY,IAAI,MAAM;IAMtB;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAkB7F;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAC/B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,QAAQ,EAAE,UAAU,EACpB,UAAU,EAAE,MAAM,GACnB,IAAI;CAUV"}
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /// <reference types="node" />
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.Cursor = exports.CursorType = void 0;
5
4
  var CursorType;
@@ -8,15 +7,32 @@ var CursorType;
8
7
  CursorType["RegionPreviews"] = "region_previews";
9
8
  CursorType["RegionImages"] = "region_images";
10
9
  })(CursorType || (exports.CursorType = CursorType = {}));
11
- const ENCODING = 'utf8';
12
- const BASE64URL = 'base64url';
10
+ /**
11
+ * Base64url encode/decode using only atob/btoa and TextEncoder/TextDecoder so it works in
12
+ * Node, React Native (Hermes), and browser without ever referencing Buffer (which is not
13
+ * available in RN and can cause "Property 'Buffer' doesn't exist" when bundlers inline code).
14
+ */
15
+ function base64UrlEncode(utf8) {
16
+ const bytes = new TextEncoder().encode(utf8);
17
+ let binary = '';
18
+ for (let i = 0; i < bytes.length; i++) {
19
+ binary += String.fromCharCode(bytes[i]);
20
+ }
21
+ const base64 = btoa(binary);
22
+ return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
23
+ }
24
+ function base64UrlDecode(encoded) {
25
+ const base64 = encoded.replace(/-/g, '+').replace(/_/g, '/') + '='.repeat((4 - (encoded.length % 4)) % 4);
26
+ const binary = atob(base64);
27
+ return new TextDecoder().decode(Uint8Array.from(binary, (c) => c.charCodeAt(0)));
28
+ }
13
29
  /**
14
30
  * Base class for pagination cursors. Each cursor encodes to base64url JSON
15
31
  * including cursorType so decoding can validate the correct cursor kind.
16
32
  */
17
33
  class Cursor {
18
34
  encodeBase64() {
19
- return Buffer.from(JSON.stringify({ cursorType: this.cursorType, ...this.toPayload() }), ENCODING).toString(BASE64URL);
35
+ return base64UrlEncode(JSON.stringify({ cursorType: this.cursorType, ...this.toPayload() }));
20
36
  }
21
37
  /**
22
38
  * Decodes a base64url-encoded cursor string to a plain object.
@@ -28,7 +44,7 @@ class Cursor {
28
44
  }
29
45
  let decoded;
30
46
  try {
31
- const json = Buffer.from(encoded, BASE64URL).toString(ENCODING);
47
+ const json = base64UrlDecode(encoded);
32
48
  decoded = JSON.parse(json);
33
49
  }
34
50
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ropegeo-common",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "Shared types and utilities for RopeGeo and WebScraper",
5
5
  "license": "ISC",
6
6
  "repository": {