ropegeo-common 1.2.7 → 1.2.8
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":"
|
|
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;AA4BD;;;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,37 @@ var CursorType;
|
|
|
8
7
|
CursorType["RegionPreviews"] = "region_previews";
|
|
9
8
|
CursorType["RegionImages"] = "region_images";
|
|
10
9
|
})(CursorType || (exports.CursorType = CursorType = {}));
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Base64url encode/decode that works in Node (Buffer) and in React Native/browser (atob/btoa + TextEncoder/TextDecoder).
|
|
12
|
+
* Avoids relying on Node's Buffer so cursor parsing works in RN.
|
|
13
|
+
*/
|
|
14
|
+
function base64UrlEncode(utf8) {
|
|
15
|
+
if (typeof Buffer !== 'undefined') {
|
|
16
|
+
return Buffer.from(utf8, 'utf8').toString('base64url');
|
|
17
|
+
}
|
|
18
|
+
const bytes = new TextEncoder().encode(utf8);
|
|
19
|
+
let binary = '';
|
|
20
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
21
|
+
binary += String.fromCharCode(bytes[i]);
|
|
22
|
+
}
|
|
23
|
+
const base64 = btoa(binary);
|
|
24
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
25
|
+
}
|
|
26
|
+
function base64UrlDecode(encoded) {
|
|
27
|
+
const base64 = encoded.replace(/-/g, '+').replace(/_/g, '/') + '='.repeat((4 - (encoded.length % 4)) % 4);
|
|
28
|
+
if (typeof Buffer !== 'undefined') {
|
|
29
|
+
return Buffer.from(base64, 'base64').toString('utf8');
|
|
30
|
+
}
|
|
31
|
+
const binary = atob(base64);
|
|
32
|
+
return new TextDecoder().decode(Uint8Array.from(binary, (c) => c.charCodeAt(0)));
|
|
33
|
+
}
|
|
13
34
|
/**
|
|
14
35
|
* Base class for pagination cursors. Each cursor encodes to base64url JSON
|
|
15
36
|
* including cursorType so decoding can validate the correct cursor kind.
|
|
16
37
|
*/
|
|
17
38
|
class Cursor {
|
|
18
39
|
encodeBase64() {
|
|
19
|
-
return
|
|
40
|
+
return base64UrlEncode(JSON.stringify({ cursorType: this.cursorType, ...this.toPayload() }));
|
|
20
41
|
}
|
|
21
42
|
/**
|
|
22
43
|
* Decodes a base64url-encoded cursor string to a plain object.
|
|
@@ -28,7 +49,7 @@ class Cursor {
|
|
|
28
49
|
}
|
|
29
50
|
let decoded;
|
|
30
51
|
try {
|
|
31
|
-
const json =
|
|
52
|
+
const json = base64UrlDecode(encoded);
|
|
32
53
|
decoded = JSON.parse(json);
|
|
33
54
|
}
|
|
34
55
|
catch (err) {
|