local-lite 0.1.4 → 0.2.2
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/README.md +5 -2
- package/bin/local-lite.mjs +65 -61
- package/dist/auth/apple.d.ts +3 -4
- package/dist/auth/apple.js +26 -3
- package/dist/auth/github.d.ts +3 -5
- package/dist/auth/github.js +18 -4
- package/dist/auth/google.d.ts +3 -6
- package/dist/auth/google.js +19 -5
- package/dist/auth/identity.d.ts +42 -0
- package/dist/auth/identity.js +63 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/local.d.ts +33 -1
- package/dist/auth/local.js +94 -13
- package/dist/auth/microsoft.d.ts +3 -5
- package/dist/auth/microsoft.js +16 -3
- package/dist/auth/session.d.ts +4 -0
- package/dist/auth/session.js +19 -1
- package/dist/auth/unified.d.ts +73 -0
- package/dist/auth/unified.js +188 -0
- package/package.json +1 -2
- package/skills/local-lite-auth/SKILL.md +67 -27
- package/skills/local-lite-server/SKILL.md +127 -0
- package/docs/.nojekyll +0 -1
- package/docs/README.md +0 -108
- package/docs/_sidebar.md +0 -22
- package/docs/actions-email.md +0 -222
- package/docs/adapters-local.md +0 -272
- package/docs/adapters-remote.md +0 -291
- package/docs/api-keys.md +0 -114
- package/docs/architecture.md +0 -106
- package/docs/auth.md +0 -342
- package/docs/backups.md +0 -214
- package/docs/breaking-changes.md +0 -147
- package/docs/client-api.md +0 -412
- package/docs/configuration.md +0 -228
- package/docs/conflict-resolution.md +0 -78
- package/docs/getting-started.md +0 -190
- package/docs/google-auth.md +0 -234
- package/docs/index.html +0 -166
- package/docs/kv.md +0 -89
- package/docs/maintenance-portability.md +0 -133
- package/docs/react-hooks.md +0 -457
- package/docs/scheduler.md +0 -81
- package/docs/search.md +0 -71
- package/docs/server.md +0 -101
- package/docs/session.md +0 -129
- package/docs/storage.md +0 -265
package/README.md
CHANGED
|
@@ -95,6 +95,7 @@ For an application-level upgrade checklist or AI-assisted code review, see the
|
|
|
95
95
|
The package ships [Agent Skills](./skills) that AI coding assistants can load:
|
|
96
96
|
* `local-lite-setup`: Multi-platform setup (Expo, Web, Node) and client initialization.
|
|
97
97
|
* `local-lite-auth`: Zero-backend SQLite authentication, PBKDF2 crypto, lockout, reset tokens, and OAuth.
|
|
98
|
+
* `local-lite-server`: Framework-neutral REST API routing, route params, middleware pipelines, and single fetch() dispatcher.
|
|
98
99
|
* `local-lite-backups`: Cloud backups (OneDrive, Google Drive), AES-256-GCM database encryption, and restore.
|
|
99
100
|
* `local-lite-schema`: Declarative cascading deletions (`onDelete`), append-only migrations, and FTS5 search.
|
|
100
101
|
* `local-lite-storage`: Blob and file management, ExpoFileDriver, and cloud storage bucket sync.
|
|
@@ -104,8 +105,10 @@ The package ships [Agent Skills](./skills) that AI coding assistants can load:
|
|
|
104
105
|
* `local-lite-upgrade`: Migration checklist and breaking change reviews across version upgrades.
|
|
105
106
|
|
|
106
107
|
```bash
|
|
107
|
-
npx local-lite install-skills
|
|
108
|
-
npx local-lite install-skills --target claude
|
|
108
|
+
npx local-lite install-skills # Copilot: .github/skills
|
|
109
|
+
npx local-lite install-skills --target claude # Claude Code: .claude/skills
|
|
110
|
+
npx local-lite install-skills --target antigravity # Antigravity / Gemini: .gemini/skills
|
|
111
|
+
npx local-lite install-skills --target cursor # Cursor: .cursor/skills
|
|
109
112
|
npx local-lite install-skills --dir path/to/dir --force
|
|
110
113
|
```
|
|
111
114
|
|
package/bin/local-lite.mjs
CHANGED
|
@@ -1,62 +1,66 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { cp, mkdir, readdir } from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
|
|
6
|
-
const skillsRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'skills');
|
|
7
|
-
const targets = {
|
|
8
|
-
copilot: '.github/skills',
|
|
9
|
-
claude: '.claude/skills',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
2
|
+
import { cp, mkdir, readdir } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const skillsRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'skills');
|
|
7
|
+
const targets = {
|
|
8
|
+
copilot: '.github/skills',
|
|
9
|
+
claude: '.claude/skills',
|
|
10
|
+
antigravity: '.gemini/skills',
|
|
11
|
+
gemini: '.gemini/skills',
|
|
12
|
+
cursor: '.cursor/skills',
|
|
13
|
+
agent: '.agent/skills',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const usage = `Usage: local-lite install-skills [--target copilot|claude|antigravity|cursor|agent] [--dir <path>] [--force]
|
|
17
|
+
|
|
18
|
+
Copies the bundled AI skills into your project.
|
|
19
|
+
--target copilot (default, .github/skills), claude (.claude/skills), antigravity (.gemini/skills), cursor (.cursor/skills), agent (.agent/skills)
|
|
20
|
+
--dir custom destination directory (overrides --target)
|
|
21
|
+
--force overwrite existing skill files`;
|
|
22
|
+
|
|
23
|
+
function parseArgs(argv) {
|
|
24
|
+
const options = { target: 'copilot', dir: undefined, force: false };
|
|
25
|
+
for (let i = 0; i < argv.length; i++) {
|
|
26
|
+
const arg = argv[i];
|
|
27
|
+
if (arg === '--force') options.force = true;
|
|
28
|
+
else if (arg === '--target') options.target = argv[++i];
|
|
29
|
+
else if (arg === '--dir') {
|
|
30
|
+
options.dir = argv[++i];
|
|
31
|
+
if (!options.dir) throw new Error('--dir requires a path.');
|
|
32
|
+
} else throw new Error(`Unknown option: ${arg}`);
|
|
33
|
+
}
|
|
34
|
+
if (!options.dir && !targets[options.target]) {
|
|
35
|
+
throw new Error(`Unknown target "${options.target}". Supported: ${Object.keys(targets).join(', ')}.`);
|
|
36
|
+
}
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function installSkills(options) {
|
|
41
|
+
const destination = path.resolve(process.cwd(), options.dir ?? targets[options.target]);
|
|
42
|
+
await mkdir(destination, { recursive: true });
|
|
43
|
+
const entries = await readdir(skillsRoot, { withFileTypes: true });
|
|
44
|
+
for (const entry of entries.filter((item) => item.isDirectory())) {
|
|
45
|
+
await cp(path.join(skillsRoot, entry.name), path.join(destination, entry.name), {
|
|
46
|
+
recursive: true,
|
|
47
|
+
force: options.force,
|
|
48
|
+
errorOnExist: false,
|
|
49
|
+
});
|
|
50
|
+
console.log(`Installed ${entry.name} -> ${path.join(destination, entry.name)}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
55
|
+
try {
|
|
56
|
+
if (command === 'install-skills') {
|
|
57
|
+
await installSkills(parseArgs(rest));
|
|
58
|
+
} else {
|
|
59
|
+
console.log(usage);
|
|
60
|
+
process.exitCode = command && command !== '--help' && command !== '-h' ? 1 : 0;
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(error instanceof Error ? error.message : error);
|
|
64
|
+
console.error(usage);
|
|
65
|
+
process.exitCode = 1;
|
|
66
|
+
}
|
package/dist/auth/apple.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { type AuthUser } from './identity.js';
|
|
1
2
|
export declare const APPLE_AUTHORIZATION_ENDPOINT = "https://appleid.apple.com/auth/authorize";
|
|
2
3
|
export declare const APPLE_TOKEN_ENDPOINT = "https://appleid.apple.com/auth/token";
|
|
3
4
|
export declare const DEFAULT_APPLE_AUTH_SCOPES: string[];
|
|
4
|
-
export interface AppleUser {
|
|
5
|
-
|
|
6
|
-
email: string;
|
|
7
|
-
name: string;
|
|
5
|
+
export interface AppleUser extends AuthUser {
|
|
6
|
+
provider: 'apple';
|
|
8
7
|
givenName?: string;
|
|
9
8
|
familyName?: string;
|
|
10
9
|
identityToken?: string;
|
package/dist/auth/apple.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AppleAuthClient = exports.DEFAULT_APPLE_AUTH_SCOPES = exports.APPLE_TOKEN_ENDPOINT = exports.APPLE_AUTHORIZATION_ENDPOINT = void 0;
|
|
4
4
|
exports.createInMemoryAppleTokenStore = createInMemoryAppleTokenStore;
|
|
5
5
|
exports.createAppleAuthTokenStore = createAppleAuthTokenStore;
|
|
6
|
+
const identity_js_1 = require("./identity.js");
|
|
6
7
|
exports.APPLE_AUTHORIZATION_ENDPOINT = 'https://appleid.apple.com/auth/authorize';
|
|
7
8
|
exports.APPLE_TOKEN_ENDPOINT = 'https://appleid.apple.com/auth/token';
|
|
8
9
|
exports.DEFAULT_APPLE_AUTH_SCOPES = ['name', 'email'];
|
|
@@ -200,14 +201,24 @@ class AppleAuthClient {
|
|
|
200
201
|
expiresAt: claims.exp ? claims.exp * 1000 : undefined,
|
|
201
202
|
};
|
|
202
203
|
await this.tokenStore.setTokens(tokens);
|
|
204
|
+
const canonicalId = (0, identity_js_1.resolveUnifiedUserId)({ id, email, emailVerified: Boolean(claims.email_verified ?? true) }, 'apple');
|
|
203
205
|
const user = {
|
|
204
|
-
id,
|
|
206
|
+
id: canonicalId,
|
|
207
|
+
userId: canonicalId,
|
|
205
208
|
email,
|
|
209
|
+
emailVerified: Boolean(claims.email_verified ?? true),
|
|
206
210
|
name,
|
|
211
|
+
displayName: name,
|
|
212
|
+
avatarUrl: null,
|
|
213
|
+
picture: null,
|
|
214
|
+
provider: 'apple',
|
|
215
|
+
providerAccountId: id,
|
|
207
216
|
givenName,
|
|
208
217
|
familyName,
|
|
209
218
|
identityToken: authorization.id_token,
|
|
210
219
|
authorizationCode: authorization.code,
|
|
220
|
+
rawProfile: claims,
|
|
221
|
+
createdAt: Date.now(),
|
|
211
222
|
};
|
|
212
223
|
await this.tokenStore.setUser(user);
|
|
213
224
|
this.notify(user);
|
|
@@ -226,14 +237,26 @@ class AppleAuthClient {
|
|
|
226
237
|
const resolvedGivenName = givenName || priorUser?.givenName;
|
|
227
238
|
const resolvedFamilyName = familyName || priorUser?.familyName;
|
|
228
239
|
const resolvedName = name !== email.split('@')[0] ? name : priorUser?.name || name;
|
|
240
|
+
const rawId = String(cred.user || claims.sub || 'apple_user');
|
|
241
|
+
const finalEmail = cred.email || priorUser?.email || email;
|
|
242
|
+
const canonicalId = (0, identity_js_1.resolveUnifiedUserId)({ id: rawId, email: finalEmail, emailVerified: true }, 'apple');
|
|
229
243
|
const user = {
|
|
230
|
-
id,
|
|
231
|
-
|
|
244
|
+
id: canonicalId,
|
|
245
|
+
userId: canonicalId,
|
|
246
|
+
email: finalEmail,
|
|
247
|
+
emailVerified: true,
|
|
232
248
|
name: resolvedName,
|
|
249
|
+
displayName: resolvedName,
|
|
250
|
+
avatarUrl: null,
|
|
251
|
+
picture: null,
|
|
252
|
+
provider: 'apple',
|
|
253
|
+
providerAccountId: rawId,
|
|
233
254
|
givenName: resolvedGivenName,
|
|
234
255
|
familyName: resolvedFamilyName,
|
|
235
256
|
identityToken: cred.identityToken || undefined,
|
|
236
257
|
authorizationCode: cred.authorizationCode || undefined,
|
|
258
|
+
rawProfile: claims,
|
|
259
|
+
createdAt: Date.now(),
|
|
237
260
|
};
|
|
238
261
|
if (cred.identityToken) {
|
|
239
262
|
await this.tokenStore.setTokens({
|
package/dist/auth/github.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import { type AuthUser } from './identity.js';
|
|
1
2
|
export declare const GITHUB_AUTHORIZATION_ENDPOINT = "https://github.com/login/oauth/authorize";
|
|
2
3
|
export declare const GITHUB_TOKEN_ENDPOINT = "https://github.com/login/oauth/access_token";
|
|
3
4
|
export declare const GITHUB_API_ENDPOINT = "https://api.github.com";
|
|
4
5
|
export declare const DEFAULT_GITHUB_AUTH_SCOPES: string[];
|
|
5
|
-
export interface GitHubUser {
|
|
6
|
-
|
|
6
|
+
export interface GitHubUser extends AuthUser {
|
|
7
|
+
provider: 'github';
|
|
7
8
|
login: string;
|
|
8
|
-
name: string;
|
|
9
|
-
email: string;
|
|
10
|
-
avatarUrl?: string;
|
|
11
9
|
bio?: string;
|
|
12
10
|
company?: string;
|
|
13
11
|
location?: string;
|
package/dist/auth/github.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GitHubAuthClient = exports.DEFAULT_GITHUB_AUTH_SCOPES = exports.GITHUB_API_ENDPOINT = exports.GITHUB_TOKEN_ENDPOINT = exports.GITHUB_AUTHORIZATION_ENDPOINT = void 0;
|
|
4
4
|
exports.createInMemoryGitHubTokenStore = createInMemoryGitHubTokenStore;
|
|
5
5
|
exports.createGitHubAuthTokenStore = createGitHubAuthTokenStore;
|
|
6
|
+
const identity_js_1 = require("./identity.js");
|
|
6
7
|
exports.GITHUB_AUTHORIZATION_ENDPOINT = 'https://github.com/login/oauth/authorize';
|
|
7
8
|
exports.GITHUB_TOKEN_ENDPOINT = 'https://github.com/login/oauth/access_token';
|
|
8
9
|
exports.GITHUB_API_ENDPOINT = 'https://api.github.com';
|
|
@@ -273,15 +274,28 @@ class GitHubAuthClient {
|
|
|
273
274
|
// Fallback to username generated placeholder if emails restricted
|
|
274
275
|
}
|
|
275
276
|
}
|
|
277
|
+
const rawId = String(raw.id ?? raw.sub ?? 'github_user');
|
|
278
|
+
const normalizedEmail = email ? email.trim().toLowerCase() : `${raw.login}@users.noreply.github.com`;
|
|
279
|
+
const id = (0, identity_js_1.resolveUnifiedUserId)({ id: rawId, email: normalizedEmail, emailVerified: true }, 'github');
|
|
280
|
+
const name = raw.name || raw.login || 'GitHub User';
|
|
281
|
+
const avatarUrl = raw.avatar_url || null;
|
|
276
282
|
return {
|
|
277
|
-
id
|
|
283
|
+
id,
|
|
284
|
+
userId: id,
|
|
278
285
|
login: raw.login,
|
|
279
|
-
name
|
|
280
|
-
|
|
281
|
-
|
|
286
|
+
name,
|
|
287
|
+
displayName: name,
|
|
288
|
+
email: normalizedEmail,
|
|
289
|
+
emailVerified: true,
|
|
290
|
+
provider: 'github',
|
|
291
|
+
providerAccountId: rawId,
|
|
292
|
+
avatarUrl,
|
|
293
|
+
picture: avatarUrl,
|
|
282
294
|
bio: raw.bio,
|
|
283
295
|
company: raw.company,
|
|
284
296
|
location: raw.location,
|
|
297
|
+
rawProfile: raw,
|
|
298
|
+
createdAt: Date.now(),
|
|
285
299
|
};
|
|
286
300
|
}
|
|
287
301
|
}
|
package/dist/auth/google.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
+
import { type AuthUser } from './identity.js';
|
|
1
2
|
import { GoogleDriveBackupStorage, GoogleDriveBackupClient, type GoogleDriveBackupClientOptions } from '../backups/cloud-storage.js';
|
|
2
3
|
export declare const GOOGLE_AUTHORIZATION_ENDPOINT = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
3
4
|
export declare const GOOGLE_TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
|
|
4
5
|
export declare const GOOGLE_USERINFO_ENDPOINT = "https://www.googleapis.com/oauth2/v3/userinfo";
|
|
5
6
|
export declare const DEFAULT_GOOGLE_AUTH_SCOPES: string[];
|
|
6
|
-
export interface GoogleUser {
|
|
7
|
-
|
|
8
|
-
email: string;
|
|
9
|
-
emailVerified: boolean;
|
|
10
|
-
name: string;
|
|
7
|
+
export interface GoogleUser extends AuthUser {
|
|
8
|
+
provider: 'google';
|
|
11
9
|
givenName?: string;
|
|
12
10
|
familyName?: string;
|
|
13
|
-
picture?: string;
|
|
14
11
|
locale?: string;
|
|
15
12
|
}
|
|
16
13
|
export interface GoogleAuthTokens {
|
package/dist/auth/google.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GoogleAuthClient = exports.DEFAULT_GOOGLE_AUTH_SCOPES = exports.GOOGLE_USERINFO_ENDPOINT = exports.GOOGLE_TOKEN_ENDPOINT = exports.GOOGLE_AUTHORIZATION_ENDPOINT = void 0;
|
|
4
4
|
exports.createInMemoryGoogleTokenStore = createInMemoryGoogleTokenStore;
|
|
5
5
|
exports.createGoogleAuthTokenStore = createGoogleAuthTokenStore;
|
|
6
|
+
const identity_js_1 = require("./identity.js");
|
|
6
7
|
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
7
8
|
const utils_js_1 = require("@noble/hashes/utils.js");
|
|
8
9
|
const cloud_storage_js_1 = require("../backups/cloud-storage.js");
|
|
@@ -309,15 +310,28 @@ class GoogleAuthClient {
|
|
|
309
310
|
throw new Error(`Failed to fetch Google user profile (${res.status}).`);
|
|
310
311
|
}
|
|
311
312
|
const raw = (await res.json());
|
|
313
|
+
const email = raw.email ? String(raw.email).trim().toLowerCase() : '';
|
|
314
|
+
const emailVerified = Boolean(raw.email_verified ?? true);
|
|
315
|
+
const sub = String(raw.sub || raw.id || 'google_user');
|
|
316
|
+
const id = (0, identity_js_1.resolveUnifiedUserId)({ id: sub, email, emailVerified }, 'google');
|
|
317
|
+
const name = raw.name || raw.email || 'Google User';
|
|
318
|
+
const avatarUrl = raw.picture || null;
|
|
312
319
|
return {
|
|
313
|
-
id
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
320
|
+
id,
|
|
321
|
+
userId: id,
|
|
322
|
+
email,
|
|
323
|
+
emailVerified,
|
|
324
|
+
name,
|
|
325
|
+
displayName: name,
|
|
326
|
+
avatarUrl,
|
|
327
|
+
picture: avatarUrl,
|
|
328
|
+
provider: 'google',
|
|
329
|
+
providerAccountId: sub,
|
|
317
330
|
givenName: raw.given_name,
|
|
318
331
|
familyName: raw.family_name,
|
|
319
|
-
picture: raw.picture,
|
|
320
332
|
locale: raw.locale,
|
|
333
|
+
rawProfile: raw,
|
|
334
|
+
createdAt: Date.now(),
|
|
321
335
|
};
|
|
322
336
|
}
|
|
323
337
|
createDriveBackupStorage() {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const DEFAULT_UNIFIED_EMAIL_NAMESPACE = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
|
2
|
+
export type SupportedAuthProvider = 'google' | 'github' | 'microsoft' | 'apple' | 'local';
|
|
3
|
+
/**
|
|
4
|
+
* Standardized first-class user identity across all auth providers in local-lite.
|
|
5
|
+
* Every provider client natively resolves and returns this canonical model.
|
|
6
|
+
*/
|
|
7
|
+
export interface AuthUser {
|
|
8
|
+
/** Canonical deterministic UUID across all providers with the same verified email */
|
|
9
|
+
id: string;
|
|
10
|
+
/** Alias for id to ensure compatibility with session records and sync workers */
|
|
11
|
+
userId: string;
|
|
12
|
+
email: string;
|
|
13
|
+
emailVerified: boolean;
|
|
14
|
+
name: string;
|
|
15
|
+
displayName: string;
|
|
16
|
+
avatarUrl?: string | null;
|
|
17
|
+
picture?: string | null;
|
|
18
|
+
provider: SupportedAuthProvider;
|
|
19
|
+
providerAccountId: string;
|
|
20
|
+
rawProfile?: Record<string, any>;
|
|
21
|
+
createdAt?: number;
|
|
22
|
+
}
|
|
23
|
+
export type UnifiedAuthUser = AuthUser;
|
|
24
|
+
export interface IdentityResolverOptions {
|
|
25
|
+
namespace?: string;
|
|
26
|
+
requireVerifiedEmail?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolves a canonical UUID for an incoming profile.
|
|
30
|
+
* If email is verified, hashes the normalized email against the UUIDv5 namespace.
|
|
31
|
+
* Falls back to provider-scoped deterministic ID if unverified or email is missing.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveUnifiedUserId(profile: {
|
|
34
|
+
id: string | number;
|
|
35
|
+
email?: string | null;
|
|
36
|
+
emailVerified?: boolean;
|
|
37
|
+
}, provider: SupportedAuthProvider, options?: IdentityResolverOptions): string;
|
|
38
|
+
/**
|
|
39
|
+
* Standardizes raw user records from Google, GitHub, Microsoft, Apple, or local auth
|
|
40
|
+
* into a single unified user object with a canonical `id` / `userId`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createUnifiedAuthUser(rawUser: Record<string, any>, provider: SupportedAuthProvider, options?: IdentityResolverOptions): AuthUser;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_UNIFIED_EMAIL_NAMESPACE = void 0;
|
|
4
|
+
exports.resolveUnifiedUserId = resolveUnifiedUserId;
|
|
5
|
+
exports.createUnifiedAuthUser = createUnifiedAuthUser;
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
exports.DEFAULT_UNIFIED_EMAIL_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a canonical UUID for an incoming profile.
|
|
10
|
+
* If email is verified, hashes the normalized email against the UUIDv5 namespace.
|
|
11
|
+
* Falls back to provider-scoped deterministic ID if unverified or email is missing.
|
|
12
|
+
*/
|
|
13
|
+
function resolveUnifiedUserId(profile, provider, options) {
|
|
14
|
+
const ns = options?.namespace || exports.DEFAULT_UNIFIED_EMAIL_NAMESPACE;
|
|
15
|
+
const requireVerified = options?.requireVerifiedEmail ?? true;
|
|
16
|
+
const isVerified = !requireVerified || profile.emailVerified === true;
|
|
17
|
+
if (isVerified && profile.email && profile.email.trim().length > 0) {
|
|
18
|
+
return (0, uuid_1.v5)(profile.email.trim().toLowerCase(), ns);
|
|
19
|
+
}
|
|
20
|
+
return (0, uuid_1.v5)(`${provider}:${profile.id}`, ns);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Standardizes raw user records from Google, GitHub, Microsoft, Apple, or local auth
|
|
24
|
+
* into a single unified user object with a canonical `id` / `userId`.
|
|
25
|
+
*/
|
|
26
|
+
function createUnifiedAuthUser(rawUser, provider, options) {
|
|
27
|
+
const emailRaw = typeof rawUser.email === 'string' ? rawUser.email : undefined;
|
|
28
|
+
const email = emailRaw ? emailRaw.trim().toLowerCase() : '';
|
|
29
|
+
const emailVerified = rawUser.emailVerified === true ||
|
|
30
|
+
rawUser.email_verified === true ||
|
|
31
|
+
provider === 'microsoft' ||
|
|
32
|
+
provider === 'github';
|
|
33
|
+
const providerAccountId = String(rawUser.providerAccountId ?? rawUser.id ?? rawUser.sub ?? rawUser.userId ?? '');
|
|
34
|
+
const id = resolveUnifiedUserId({ id: providerAccountId, email, emailVerified }, provider, options);
|
|
35
|
+
const name = typeof rawUser.name === 'string' && rawUser.name.trim()
|
|
36
|
+
? rawUser.name.trim()
|
|
37
|
+
: typeof rawUser.displayName === 'string' && rawUser.displayName.trim()
|
|
38
|
+
? rawUser.displayName.trim()
|
|
39
|
+
: typeof rawUser.login === 'string'
|
|
40
|
+
? rawUser.login
|
|
41
|
+
: email.split('@')[0] || 'User';
|
|
42
|
+
const avatarUrl = typeof rawUser.picture === 'string'
|
|
43
|
+
? rawUser.picture
|
|
44
|
+
: typeof rawUser.avatarUrl === 'string'
|
|
45
|
+
? rawUser.avatarUrl
|
|
46
|
+
: typeof rawUser.avatar_url === 'string'
|
|
47
|
+
? rawUser.avatar_url
|
|
48
|
+
: null;
|
|
49
|
+
return {
|
|
50
|
+
id,
|
|
51
|
+
userId: id,
|
|
52
|
+
email,
|
|
53
|
+
emailVerified,
|
|
54
|
+
name,
|
|
55
|
+
displayName: name,
|
|
56
|
+
avatarUrl,
|
|
57
|
+
picture: avatarUrl,
|
|
58
|
+
provider,
|
|
59
|
+
providerAccountId,
|
|
60
|
+
rawProfile: rawUser,
|
|
61
|
+
createdAt: typeof rawUser.createdAt === 'number' ? rawUser.createdAt : Date.now(),
|
|
62
|
+
};
|
|
63
|
+
}
|
package/dist/auth/index.d.ts
CHANGED
package/dist/auth/index.js
CHANGED
|
@@ -20,3 +20,5 @@ __exportStar(require("./github.js"), exports);
|
|
|
20
20
|
__exportStar(require("./apple.js"), exports);
|
|
21
21
|
__exportStar(require("./session.js"), exports);
|
|
22
22
|
__exportStar(require("./local.js"), exports);
|
|
23
|
+
__exportStar(require("./identity.js"), exports);
|
|
24
|
+
__exportStar(require("./unified.js"), exports);
|
package/dist/auth/local.d.ts
CHANGED
|
@@ -90,7 +90,19 @@ export interface LocalAuthEngineOptions {
|
|
|
90
90
|
* Shared SessionManager instance or options to configure internal SessionManager.
|
|
91
91
|
*/
|
|
92
92
|
session?: SessionManager | SessionManagerOptions;
|
|
93
|
+
/**
|
|
94
|
+
* Optional remote authentication handler to exchange local sessions for remote sync provider tokens.
|
|
95
|
+
*/
|
|
96
|
+
remoteAuthHandler?: RemoteAuthHandler;
|
|
97
|
+
}
|
|
98
|
+
export interface RemoteAuthExchangeContext<TMetadata = any> {
|
|
99
|
+
user: LocalUser<TMetadata>;
|
|
100
|
+
session: SessionRecord<LocalUser<TMetadata>>;
|
|
93
101
|
}
|
|
102
|
+
export type RemoteAuthHandler<TMetadata = any> = (context: RemoteAuthExchangeContext<TMetadata>) => Promise<{
|
|
103
|
+
token: string;
|
|
104
|
+
[key: string]: any;
|
|
105
|
+
} | null>;
|
|
94
106
|
export interface SignUpOptions<TMetadata = Record<string, any>> {
|
|
95
107
|
id?: string;
|
|
96
108
|
email: string;
|
|
@@ -198,7 +210,27 @@ export declare class LocalAuthEngine {
|
|
|
198
210
|
private minPasswordLength;
|
|
199
211
|
private customPasswordValidator?;
|
|
200
212
|
private sessionManager;
|
|
201
|
-
|
|
213
|
+
private remoteAuthHandler?;
|
|
214
|
+
constructor(db: DBExecutable, sessionOrManager?: SessionManager | SessionManagerOptions | LocalAuthEngineOptions, events?: EventEmitter | undefined, options?: LocalAuthEngineOptions);
|
|
215
|
+
/**
|
|
216
|
+
* Registers a pluggable remote authentication exchange handler.
|
|
217
|
+
*/
|
|
218
|
+
setRemoteAuthHandler(handler: RemoteAuthHandler): void;
|
|
219
|
+
/**
|
|
220
|
+
* Gets the configured remote authentication exchange handler.
|
|
221
|
+
*/
|
|
222
|
+
getRemoteAuthHandler(): RemoteAuthHandler | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* Triggers token exchange with the registered remote sync provider for the active session.
|
|
225
|
+
*/
|
|
226
|
+
exchangeRemoteAuth(): Promise<{
|
|
227
|
+
token: string;
|
|
228
|
+
[key: string]: any;
|
|
229
|
+
} | null>;
|
|
230
|
+
/**
|
|
231
|
+
* Retrieves the cached remote sync authentication token from the active session.
|
|
232
|
+
*/
|
|
233
|
+
getRemoteAuthToken(): Promise<string | null>;
|
|
202
234
|
/**
|
|
203
235
|
* Retrieves the underlying SessionManager instance.
|
|
204
236
|
*/
|