local-lite 2.0.3 → 2.0.5
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/adapters/local/better-sqlite3.js +3 -10
- package/dist/adapters/local/node-sqlite.js +3 -10
- package/dist/adapters/remote/convex.js +2 -5
- package/dist/adapters/remote/firestore.js +2 -5
- package/dist/auth/apple.js +7 -70
- package/dist/auth/github.js +6 -69
- package/dist/auth/google.js +6 -87
- package/dist/auth/local.js +2 -25
- package/dist/auth/microsoft.js +4 -78
- package/dist/backups/cloud-storage.d.ts +2 -2
- package/dist/backups/cloud-storage.js +4 -46
- package/dist/backups/encryption.js +2 -5
- package/dist/devtools/BenchmarkModal.js +16 -37
- package/dist/devtools/SyncInspector.js +11 -43
- package/dist/devtools/shared.d.ts +25 -0
- package/dist/devtools/shared.js +39 -0
- package/dist/keys/generator.d.ts +2 -4
- package/dist/keys/generator.js +4 -33
- package/dist/keys/signed-token.d.ts +2 -1
- package/dist/keys/signed-token.js +6 -23
- package/dist/utils/crypto.d.ts +13 -0
- package/dist/utils/crypto.js +70 -0
- package/dist/utils/oauth.d.ts +29 -0
- package/dist/utils/oauth.js +78 -0
- package/dist/utils/sql.d.ts +8 -0
- package/dist/utils/sql.js +23 -0
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInMemoryOAuthTokenStore = createInMemoryOAuthTokenStore;
|
|
4
|
+
exports.createOAuthTokenStore = createOAuthTokenStore;
|
|
5
|
+
exports.parseOAuthTokenResponse = parseOAuthTokenResponse;
|
|
6
|
+
exports.throwOAuthError = throwOAuthError;
|
|
7
|
+
exports.createPkceChallengePair = createPkceChallengePair;
|
|
8
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
9
|
+
const utils_js_1 = require("@noble/hashes/utils.js");
|
|
10
|
+
const crypto_js_1 = require("./crypto.js");
|
|
11
|
+
function createInMemoryOAuthTokenStore() {
|
|
12
|
+
let storedTokens = null;
|
|
13
|
+
let storedUser = null;
|
|
14
|
+
return {
|
|
15
|
+
getTokens: async () => storedTokens,
|
|
16
|
+
setTokens: async (tokens) => {
|
|
17
|
+
storedTokens = tokens;
|
|
18
|
+
},
|
|
19
|
+
removeTokens: async () => {
|
|
20
|
+
storedTokens = null;
|
|
21
|
+
},
|
|
22
|
+
getUser: async () => storedUser,
|
|
23
|
+
setUser: async (user) => {
|
|
24
|
+
storedUser = user;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function createOAuthTokenStore(storage, prefix, validateTokens, validateUser) {
|
|
29
|
+
const tokensKey = `${prefix}-tokens`;
|
|
30
|
+
const userKey = `${prefix}-user`;
|
|
31
|
+
return {
|
|
32
|
+
getTokens: async () => {
|
|
33
|
+
const raw = await storage.getItem(tokensKey);
|
|
34
|
+
return validateTokens(raw) ? raw : null;
|
|
35
|
+
},
|
|
36
|
+
setTokens: (tokens) => storage.setItem(tokensKey, tokens),
|
|
37
|
+
removeTokens: () => storage.removeItem(tokensKey),
|
|
38
|
+
getUser: async () => {
|
|
39
|
+
const raw = await storage.getItem(userKey);
|
|
40
|
+
return validateUser(raw) ? raw : null;
|
|
41
|
+
},
|
|
42
|
+
setUser: async (user) => {
|
|
43
|
+
if (user) {
|
|
44
|
+
await storage.setItem(userKey, user);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
await storage.removeItem(userKey);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async function parseOAuthTokenResponse(response, providerLabel) {
|
|
53
|
+
try {
|
|
54
|
+
return (await response.json());
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw new Error(`${providerLabel} OAuth request failed (${response.status}).`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function throwOAuthError(payload, status, providerLabel) {
|
|
61
|
+
throw new Error(payload.error_description ||
|
|
62
|
+
payload.error ||
|
|
63
|
+
`${providerLabel} OAuth request failed (${status}).`);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Generates a PKCE S256 verifier/challenge pair and an OAuth state token using a CSPRNG.
|
|
67
|
+
*/
|
|
68
|
+
function createPkceChallengePair(randomBytes = crypto_js_1.requireSecureRandomBytes) {
|
|
69
|
+
const verifierBytes = randomBytes(32);
|
|
70
|
+
const stateBytes = randomBytes(32);
|
|
71
|
+
if (verifierBytes.length !== 32 || stateBytes.length !== 32) {
|
|
72
|
+
throw new Error('The randomBytes provider returned an invalid number of bytes.');
|
|
73
|
+
}
|
|
74
|
+
const codeVerifier = (0, crypto_js_1.base64UrlEncode)(verifierBytes);
|
|
75
|
+
const codeChallenge = (0, crypto_js_1.base64UrlEncode)((0, sha2_js_1.sha256)((0, utils_js_1.utf8ToBytes)(codeVerifier)));
|
|
76
|
+
const state = (0, crypto_js_1.base64UrlEncode)(stateBytes);
|
|
77
|
+
return { codeVerifier, codeChallenge, state };
|
|
78
|
+
}
|
package/dist/utils/sql.d.ts
CHANGED
|
@@ -7,3 +7,11 @@ export declare function escapeIdentifier(identifier: string): string;
|
|
|
7
7
|
* (e.g. FTS5 index and shadow tables, sync outbox, local session/key stores, sqlite/android internals).
|
|
8
8
|
*/
|
|
9
9
|
export declare function isInternalTable(tableName: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Determines whether a SQLite statement is a read-only query (SELECT/WITH/EXPLAIN or non-mutating PRAGMA).
|
|
12
|
+
*/
|
|
13
|
+
export declare function isReadQuery(sql: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Extracts a required document/row ID from a record using primaryKey, an optional fallback ID, or `id`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractDocumentId(row: any, primaryKey: string, fallbackId?: unknown, providerLabel?: string): string;
|
package/dist/utils/sql.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.escapeIdentifier = escapeIdentifier;
|
|
4
4
|
exports.isInternalTable = isInternalTable;
|
|
5
|
+
exports.isReadQuery = isReadQuery;
|
|
6
|
+
exports.extractDocumentId = extractDocumentId;
|
|
5
7
|
/**
|
|
6
8
|
* Safely escape a SQL identifier (table name or column name) with double quotes.
|
|
7
9
|
*/
|
|
@@ -28,3 +30,24 @@ function isInternalTable(tableName) {
|
|
|
28
30
|
return true;
|
|
29
31
|
return false;
|
|
30
32
|
}
|
|
33
|
+
const READ_QUERY_REGEX = /^(?:SELECT|WITH|EXPLAIN)\b/i;
|
|
34
|
+
const READ_ONLY_PRAGMA_REGEX = /^PRAGMA\b/i;
|
|
35
|
+
const MUTATING_PRAGMA_REGEX = /=|wal_checkpoint|shrink_memory|optimize/i;
|
|
36
|
+
/**
|
|
37
|
+
* Determines whether a SQLite statement is a read-only query (SELECT/WITH/EXPLAIN or non-mutating PRAGMA).
|
|
38
|
+
*/
|
|
39
|
+
function isReadQuery(sql) {
|
|
40
|
+
if (READ_QUERY_REGEX.test(sql))
|
|
41
|
+
return true;
|
|
42
|
+
return READ_ONLY_PRAGMA_REGEX.test(sql) && !MUTATING_PRAGMA_REGEX.test(sql);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Extracts a required document/row ID from a record using primaryKey, an optional fallback ID, or `id`.
|
|
46
|
+
*/
|
|
47
|
+
function extractDocumentId(row, primaryKey, fallbackId, providerLabel = 'Remote') {
|
|
48
|
+
const id = row?.[primaryKey] ?? fallbackId ?? row?.id;
|
|
49
|
+
if (id === undefined || id === null || String(id).length === 0) {
|
|
50
|
+
throw new Error(`${providerLabel} change is missing its document ID.`);
|
|
51
|
+
}
|
|
52
|
+
return String(id);
|
|
53
|
+
}
|
package/package.json
CHANGED