local-lite 2.0.4 → 2.0.6

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 (39) hide show
  1. package/README.md +2 -2
  2. package/bin/local-lite.mjs +215 -2
  3. package/dist/auth/apple.js +1 -1
  4. package/dist/auth/github.js +1 -1
  5. package/dist/auth/google.js +1 -12
  6. package/dist/auth/local.js +2 -25
  7. package/dist/auth/microsoft.js +1 -12
  8. package/dist/backups/cloud-storage.js +1 -12
  9. package/dist/core/client.d.ts +3 -3
  10. package/dist/core/client.js +6 -6
  11. package/dist/devtools/BenchmarkModal.js +16 -37
  12. package/dist/devtools/SyncInspector.js +11 -43
  13. package/dist/devtools/shared.d.ts +25 -0
  14. package/dist/devtools/shared.js +39 -0
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/kv-store/index.d.ts +3 -0
  18. package/dist/kv-store/index.js +19 -0
  19. package/dist/kv-store/manager.d.ts +52 -0
  20. package/dist/kv-store/manager.js +167 -0
  21. package/dist/kv-store/store.d.ts +13 -0
  22. package/dist/kv-store/store.js +85 -0
  23. package/dist/kv-store/types.d.ts +27 -0
  24. package/dist/kv-store/types.js +2 -0
  25. package/dist/react/index.d.ts +1 -1
  26. package/dist/react/index.js +1 -1
  27. package/dist/react/kv-store.d.ts +9 -0
  28. package/dist/react/kv-store.js +53 -0
  29. package/dist/schema/index.d.ts +0 -1
  30. package/dist/schema/index.js +0 -1
  31. package/dist/server/dashboard.d.ts +16 -0
  32. package/dist/server/dashboard.js +1364 -0
  33. package/dist/server/index.d.ts +1 -0
  34. package/dist/server/index.js +1 -0
  35. package/dist/utils/oauth.d.ts +9 -0
  36. package/dist/utils/oauth.js +18 -0
  37. package/package.json +10 -5
  38. package/skills/local-lite-offline-actions/SKILL.md +11 -11
  39. package/skills/local-lite-react/SKILL.md +7 -7
@@ -1,6 +1,7 @@
1
1
  export type ApiMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
2
2
  export * from './email.js';
3
3
  export * from './sync.js';
4
+ export * from './dashboard.js';
4
5
  export interface ApiRequestContext<TConfig = unknown> {
5
6
  request: Request;
6
7
  config: TConfig;
@@ -18,6 +18,7 @@ exports.defineServerConfig = defineServerConfig;
18
18
  exports.createServer = createServer;
19
19
  __exportStar(require("./email.js"), exports);
20
20
  __exportStar(require("./sync.js"), exports);
21
+ __exportStar(require("./dashboard.js"), exports);
21
22
  function normalizePath(path) {
22
23
  const normalized = `/${path.split('/').filter(Boolean).join('/')}`;
23
24
  return normalized === '/' ? normalized : normalized.replace(/\/$/, '');
@@ -18,3 +18,12 @@ export interface OAuthTokenErrorPayload {
18
18
  }
19
19
  export declare function parseOAuthTokenResponse<T extends OAuthTokenErrorPayload = Record<string, any>>(response: Response, providerLabel: string): Promise<T>;
20
20
  export declare function throwOAuthError(payload: OAuthTokenErrorPayload, status: number, providerLabel: string): never;
21
+ export interface PkceChallengePair {
22
+ codeVerifier: string;
23
+ codeChallenge: string;
24
+ state: string;
25
+ }
26
+ /**
27
+ * Generates a PKCE S256 verifier/challenge pair and an OAuth state token using a CSPRNG.
28
+ */
29
+ export declare function createPkceChallengePair(randomBytes?: (length: number) => Uint8Array): PkceChallengePair;
@@ -4,6 +4,10 @@ exports.createInMemoryOAuthTokenStore = createInMemoryOAuthTokenStore;
4
4
  exports.createOAuthTokenStore = createOAuthTokenStore;
5
5
  exports.parseOAuthTokenResponse = parseOAuthTokenResponse;
6
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");
7
11
  function createInMemoryOAuthTokenStore() {
8
12
  let storedTokens = null;
9
13
  let storedUser = null;
@@ -58,3 +62,17 @@ function throwOAuthError(payload, status, providerLabel) {
58
62
  payload.error ||
59
63
  `${providerLabel} OAuth request failed (${status}).`);
60
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "local-lite",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Never let a lost connection break a promise. Local-first sync that faithfully keeps data safe until you're back online.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -46,6 +46,11 @@
46
46
  "import": "./dist/schema/index.js",
47
47
  "default": "./dist/schema/index.js"
48
48
  },
49
+ "./schema/migrations": {
50
+ "types": "./dist/schema/sqlMigrations.d.ts",
51
+ "import": "./dist/schema/sqlMigrations.js",
52
+ "default": "./dist/schema/sqlMigrations.js"
53
+ },
49
54
  "./supabase": {
50
55
  "types": "./dist/adapters/remote/supabase.d.ts",
51
56
  "import": "./dist/adapters/remote/supabase.js",
@@ -131,10 +136,10 @@
131
136
  "import": "./dist/keys/index.js",
132
137
  "default": "./dist/keys/index.js"
133
138
  },
134
- "./kv": {
135
- "types": "./dist/kv/index.d.ts",
136
- "import": "./dist/kv/index.js",
137
- "default": "./dist/kv/index.js"
139
+ "./kv-store": {
140
+ "types": "./dist/kv-store/index.d.ts",
141
+ "import": "./dist/kv-store/index.js",
142
+ "default": "./dist/kv-store/index.js"
138
143
  },
139
144
  "./search": {
140
145
  "types": "./dist/search/index.d.ts",
@@ -1,9 +1,9 @@
1
1
  ---
2
2
  name: local-lite-offline-actions
3
- description: Queue offline actions, schedule background jobs, store key-value preferences, and track sync telemetry in local-lite. Use when using client.actions, client.scheduler, client.kv, client.getMetrics(), or handling offline mutation retries.
3
+ description: Queue offline actions, schedule background jobs, store key-value preferences, and track sync telemetry in local-lite. Use when using client.actions, client.scheduler, client.kvStore, client.getMetrics(), or handling offline mutation retries.
4
4
  ---
5
5
 
6
- # local-lite Offline Actions, KV & Scheduler
6
+ # local-lite Offline Actions, KV Store & Scheduler
7
7
 
8
8
  Guide for executing queued actions, running background jobs, persisting key-value pairs, and inspecting sync telemetry with `local-lite`.
9
9
 
@@ -95,20 +95,20 @@ client.actions.registerEmailHandler(
95
95
 
96
96
  ---
97
97
 
98
- ## 2. Key-Value Store & Secret Preferences (`client.kv`)
98
+ ## 2. Key-Value Store & Secret Preferences (`client.kvStore`)
99
99
 
100
- `client.kv` provides lightweight key-value storage directly within SQLite with optional TTL expiration and AES-256-GCM encryption.
100
+ `client.kvStore` provides lightweight key-value storage directly within SQLite with optional TTL expiration and AES-256-GCM encryption.
101
101
 
102
- ### Basic KV Usage
102
+ ### Basic KV Store Usage
103
103
  ```typescript
104
104
  // Store with optional TTL (expires in 24 hours)
105
- await client.kv.set('last_viewed_tab', 'dashboard', { ttlMs: 24 * 60 * 60 * 1000 });
105
+ await client.kvStore.set('last_viewed_tab', 'dashboard', { ttlMs: 24 * 60 * 60 * 1000 });
106
106
 
107
- // Read value (returns null if expired or missing)
108
- const tab = await client.kv.get('last_viewed_tab');
107
+ // Read value (returns undefined if expired or missing)
108
+ const tab = await client.kvStore.get('last_viewed_tab');
109
109
 
110
110
  // Delete value
111
- await client.kv.delete('last_viewed_tab');
111
+ await client.kvStore.delete('last_viewed_tab');
112
112
  ```
113
113
 
114
114
  ### Encrypted Secrets (AES-256-GCM)
@@ -116,10 +116,10 @@ Store sensitive API tokens or user secrets securely:
116
116
 
117
117
  ```typescript
118
118
  // Encrypt and persist
119
- await client.kv.setSecret('api_token', 'sk-live-secret-token-12345', 'PassphraseOrHardwareKey');
119
+ await client.kvStore.setSecret('api_token', 'sk-live-secret-token-12345', { passphrase: 'PassphraseOrHardwareKey' });
120
120
 
121
121
  // Decrypt
122
- const token = await client.kv.getSecret('api_token', 'PassphraseOrHardwareKey');
122
+ const token = await client.kvStore.getSecret('api_token', 'PassphraseOrHardwareKey');
123
123
  ```
124
124
 
125
125
  ---
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: local-lite-react
3
- description: Master reactive patterns, hooks, live queries, and optimistic state in React and React Native with local-lite. Use when writing useLiveQuery, useSyncStatus, useLocalAuth, useKV, useSearch, useQueryBuilder, or optimizing component re-renders.
3
+ description: Master reactive patterns, hooks, live queries, and optimistic state in React and React Native with local-lite. Use when writing useLiveQuery, useSyncStatus, useLocalAuth, useKVStore, useSearch, useQueryBuilder, or optimizing component re-renders.
4
4
  ---
5
5
 
6
6
  # local-lite React & React Native Integration
@@ -16,8 +16,8 @@ Comprehensive guide to building reactive, offline-first user interfaces using `l
16
16
  | `useLiveQuery(client, sql, params, deps)` | Reactive SQLite query. Auto-re-runs whenever relevant tables mutate. |
17
17
  | `useSyncStatus(client)` | Tracks online/offline status, sync worker state, and outbox changes. |
18
18
  | `useLocalAuth(client.auth)` | Manages zero-backend SQLite authentication, user profiles, and sessions. |
19
- | `useKV(client.kv, key, default)` | Reactive key-value store for preferences and application state. |
20
- | `useEncryptedKV(client.kv, key, pass)` | End-to-end encrypted secret preferences with AES-256-GCM. |
19
+ | `useKVStore(client, key, default)` | Reactive key-value store for preferences and application state. |
20
+ | `useEncryptedKV(client.kvStore, key, pass)` | End-to-end encrypted secret preferences with AES-256-GCM. |
21
21
  | `useSearch(client, ftsTable, query)` | Real-time full-text search powered by SQLite FTS5. |
22
22
  | `useQueryBuilder(client, table, filter)` | Declarative MongoDB-style query filters. |
23
23
  | `useCloudBackup(backupClient, db)` | Cloud backups (OneDrive / Google Drive) with live progress. |
@@ -93,17 +93,17 @@ async function addTodo(client: LocalFirstClient, title: string, projectId: strin
93
93
 
94
94
  ---
95
95
 
96
- ## 4. Reactive Preferences & Encrypted KV
96
+ ## 4. Reactive Preferences & Encrypted KV Store
97
97
 
98
98
  ```tsx
99
- import { useKV, useEncryptedKV } from 'local-lite/react';
99
+ import { useKVStore, useEncryptedKV } from 'local-lite/react';
100
100
 
101
101
  export function SettingsScreen({ client }) {
102
102
  // 1. Plain reactive setting
103
- const [theme, setTheme] = useKV<'light' | 'dark'>(client?.kv, 'app_theme', 'light');
103
+ const [theme, setTheme] = useKVStore<'light' | 'dark'>(client, 'app_theme', 'light');
104
104
 
105
105
  // 2. Encrypted setting (AES-256-GCM)
106
- const [apiKey, setApiKey] = useEncryptedKV(client?.kv, 'openai_key', 'UserPassphrase!');
106
+ const [apiKey, setApiKey] = useEncryptedKV(client?.kvStore, 'openai_key', 'UserPassphrase!');
107
107
 
108
108
  return (
109
109
  <View>