@groton/authjs-firestore-adapter 1.0.1 → 1.0.3
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/CHANGELOG.md +10 -0
- package/dist/{AdapterAccounts.d.ts → Collections/Accounts.d.ts} +3 -3
- package/dist/Collections/Accounts.js +45 -0
- package/dist/{AdapterAuthenticators.d.ts → Collections/Authenticators.d.ts} +2 -2
- package/dist/{AdapterAuthenticators.js → Collections/Authenticators.js} +8 -7
- package/dist/{AdapterSessions.d.ts → Collections/Sessions.d.ts} +4 -4
- package/dist/{AdapterSessions.js → Collections/Sessions.js} +12 -10
- package/dist/{AdapterUsers.d.ts → Collections/Users.d.ts} +5 -5
- package/dist/Collections/Users.js +60 -0
- package/dist/{VerificationTokens.d.ts → Collections/VerificationTokens.d.ts} +3 -3
- package/dist/{VerificationTokens.js → Collections/VerificationTokens.js} +9 -4
- package/dist/index.js +15 -15
- package/package.json +12 -8
- package/dist/AdapterAccounts.js +0 -50
- package/dist/AdapterUsers.js +0 -54
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.0.3](https://github.com/groton-school/authjs/compare/firestore-adapter/1.0.1...firestore-adapter/1.0.3) (2026-11-15)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* nullify undefined properties on creation, delete undefined properties on update ([9ce52cc](https://github.com/groton-school/authjs/commit/9ce52ccccc7be4bf6391bbbdc758391e377e8fed))
|
|
10
|
+
## [1.0.2](https://github.com/groton-school/authjs/compare/firestore-adapter/1.0.1...firestore-adapter/1.0.2) (2026-11-15)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* nullify undefined properties on creation, delete undefined properties on update ([9ce52cc](https://github.com/groton-school/authjs/commit/9ce52ccccc7be4bf6391bbbdc758391e377e8fed))
|
|
5
15
|
## [1.0.1](https://github.com/groton-school/authjs/compare/firestore-adapter/1.0.0...firestore-adapter/1.0.1) (2026-11-15)
|
|
6
16
|
|
|
7
17
|
### Bug Fixes
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AdapterAccount, AdapterUser } from '@auth/core/adapters';
|
|
2
2
|
import { Collection, CollectionOptions } from '@battis/lazy-firestore';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class Accounts extends Collection<AdapterAccount> {
|
|
4
4
|
static readonly DEFAULT: {
|
|
5
5
|
path: string;
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
|
-
export declare function
|
|
9
|
-
linkAccount: (
|
|
8
|
+
export declare function AccountsAdapter({ path, ...options }?: CollectionOptions): {
|
|
9
|
+
linkAccount: (account: AdapterAccount) => Promise<AdapterAccount | null>;
|
|
10
10
|
getAccount: (providerAccountId: AdapterAccount['providerAccountId'], provider: AdapterAccount['provider']) => Promise<AdapterAccount | null>;
|
|
11
11
|
getUserByAccount: ({ provider, providerAccountId }: Pick<AdapterAccount, 'provider' | 'providerAccountId'>) => Promise<AdapterUser | null>;
|
|
12
12
|
unlinkAccount: (account: Pick<AdapterAccount, 'provider' | 'providerAccountId'>) => Promise<AdapterAccount | undefined>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Collection } from '@battis/lazy-firestore';
|
|
2
|
+
import { nullifyUndefinedProperties } from '@battis/lazy-firestore/directives/nullifyUndefinedProperties';
|
|
3
|
+
import { requireUnique } from '@battis/lazy-firestore/directives/requireUnique';
|
|
4
|
+
import { users } from './Users.js';
|
|
5
|
+
export class Accounts extends Collection {
|
|
6
|
+
static DEFAULT = { path: 'accounts' };
|
|
7
|
+
}
|
|
8
|
+
export function AccountsAdapter({ path = Accounts.DEFAULT.path, ...options } = Accounts.DEFAULT) {
|
|
9
|
+
const accounts = new Accounts({ path, ...options });
|
|
10
|
+
async function getAccount(providerAccountId, provider) {
|
|
11
|
+
return requireUnique({
|
|
12
|
+
list: await accounts.list({
|
|
13
|
+
...identify({ provider, providerAccountId }),
|
|
14
|
+
strict: false
|
|
15
|
+
}),
|
|
16
|
+
strict: false
|
|
17
|
+
}).data;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
linkAccount: async (account) => (await accounts.create({
|
|
21
|
+
...identify(account),
|
|
22
|
+
data: nullifyUndefinedProperties(account),
|
|
23
|
+
strict: false
|
|
24
|
+
})).data,
|
|
25
|
+
getAccount,
|
|
26
|
+
getUserByAccount: async ({ provider, providerAccountId }) => {
|
|
27
|
+
const account = await getAccount(providerAccountId, provider);
|
|
28
|
+
if (account) {
|
|
29
|
+
return (await users().read({ id: account.userId, strict: false })).data;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
},
|
|
33
|
+
unlinkAccount: async (account) => (await accounts.delete({
|
|
34
|
+
...identify(account),
|
|
35
|
+
strict: false
|
|
36
|
+
})).data ?? undefined
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function identify({ provider, providerAccountId }) {
|
|
40
|
+
return {
|
|
41
|
+
query: (ref) => ref
|
|
42
|
+
.where('provider', '==', provider)
|
|
43
|
+
.where('providerAccountId', '==', providerAccountId)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AdapterAuthenticator } from '@auth/core/adapters';
|
|
2
2
|
import { CollectionOptions } from '@battis/lazy-firestore';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function AuthenticatorsAdapter({ path, ...options }?: CollectionOptions): {
|
|
4
|
+
createAuthenticator: (authenticator: AdapterAuthenticator) => Promise<AdapterAuthenticator>;
|
|
4
5
|
getAuthenticator: (id: AdapterAuthenticator['credentialID']) => Promise<AdapterAuthenticator | null>;
|
|
5
|
-
createAuthenticator: (data: AdapterAuthenticator) => Promise<AdapterAuthenticator>;
|
|
6
6
|
listAuthenticatorsByUserId: (userId: AdapterAuthenticator['userId']) => Promise<AdapterAuthenticator[]>;
|
|
7
7
|
updateAuthenticatorCounter: (credentialID: AdapterAuthenticator['credentialID'], newCounter: AdapterAuthenticator['counter']) => Promise<AdapterAuthenticator>;
|
|
8
8
|
};
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { Collection } from '@battis/lazy-firestore';
|
|
2
2
|
import { DateConverter } from '@battis/lazy-firestore/converters/Date';
|
|
3
|
-
|
|
3
|
+
import { nullifyUndefinedProperties } from '@battis/lazy-firestore/directives/nullifyUndefinedProperties';
|
|
4
|
+
class Authenticators extends Collection {
|
|
4
5
|
static DEFAULT = { path: 'authenticators' };
|
|
5
6
|
constructor(options) {
|
|
6
7
|
super({ ...options, converter: { expires: DateConverter } });
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
|
-
export function
|
|
10
|
-
const authenticators = new
|
|
10
|
+
export function AuthenticatorsAdapter({ path = Authenticators.DEFAULT.path, ...options } = Authenticators.DEFAULT) {
|
|
11
|
+
const authenticators = new Authenticators({
|
|
11
12
|
path,
|
|
12
13
|
...options
|
|
13
14
|
});
|
|
14
15
|
return {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
id: data.credentialID,
|
|
16
|
+
createAuthenticator: async (authenticator) => (await authenticators.create({
|
|
17
|
+
data: nullifyUndefinedProperties(authenticator),
|
|
18
|
+
id: authenticator.credentialID,
|
|
19
19
|
strict: true
|
|
20
20
|
})).data,
|
|
21
|
+
getAuthenticator: async (id) => (await authenticators.read({ id, strict: false })).data,
|
|
21
22
|
listAuthenticatorsByUserId: async (userId) => (await authenticators.list({
|
|
22
23
|
query: (ref) => ref.where('userId', '==', userId)
|
|
23
24
|
})).map((doc) => doc.data),
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { AdapterSession } from '@auth/core/adapters';
|
|
2
2
|
import { Collection, CollectionOptions } from '@battis/lazy-firestore';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class Sessions extends Collection<AdapterSession> {
|
|
4
4
|
static readonly DEFAULT: {
|
|
5
5
|
path: string;
|
|
6
6
|
};
|
|
7
7
|
constructor(options: CollectionOptions);
|
|
8
8
|
}
|
|
9
|
-
export declare function
|
|
10
|
-
createSession: (
|
|
9
|
+
export declare function SessionsAdapter({ path, ...options }?: CollectionOptions): {
|
|
10
|
+
createSession: (session: AdapterSession) => Promise<AdapterSession>;
|
|
11
11
|
getSessionAndUser: (id: string) => Promise<{
|
|
12
12
|
session: AdapterSession;
|
|
13
13
|
user: import("@auth/core/adapters").AdapterUser;
|
|
14
14
|
} | null>;
|
|
15
|
-
updateSession: (
|
|
15
|
+
updateSession: (session: Partial<AdapterSession> & Pick<AdapterSession, 'sessionToken'>) => Promise<AdapterSession | null>;
|
|
16
16
|
deleteSession: (id: string) => Promise<AdapterSession | null>;
|
|
17
17
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Collection } from '@battis/lazy-firestore';
|
|
2
2
|
import { DateConverter } from '@battis/lazy-firestore/converters/Date';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { deleteUndefinedProperties } from '@battis/lazy-firestore/directives/deleteUndefinedProperties';
|
|
4
|
+
import { nullifyUndefinedProperties } from '@battis/lazy-firestore/directives/nullifyUndefinedProperties';
|
|
5
|
+
import { users } from './Users.js';
|
|
6
|
+
export class Sessions extends Collection {
|
|
5
7
|
static DEFAULT = { path: 'sessions' };
|
|
6
8
|
constructor(options) {
|
|
7
9
|
super({
|
|
@@ -10,12 +12,12 @@ export class AdapterSessionsCollection extends Collection {
|
|
|
10
12
|
});
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
|
-
export function
|
|
14
|
-
const sessions = new
|
|
15
|
+
export function SessionsAdapter({ path = Sessions.DEFAULT.path, ...options } = Sessions.DEFAULT) {
|
|
16
|
+
const sessions = new Sessions({ path, ...options });
|
|
15
17
|
return {
|
|
16
|
-
createSession: async (
|
|
17
|
-
id:
|
|
18
|
-
data,
|
|
18
|
+
createSession: async (session) => (await sessions.create({
|
|
19
|
+
id: session.sessionToken,
|
|
20
|
+
data: nullifyUndefinedProperties(session),
|
|
19
21
|
strict: true
|
|
20
22
|
})).data,
|
|
21
23
|
getSessionAndUser: async (id) => {
|
|
@@ -32,9 +34,9 @@ export function AdapterSessions({ path = AdapterSessionsCollection.DEFAULT.path,
|
|
|
32
34
|
}
|
|
33
35
|
return null;
|
|
34
36
|
},
|
|
35
|
-
updateSession: async (
|
|
36
|
-
id:
|
|
37
|
-
patch,
|
|
37
|
+
updateSession: async (session) => (await sessions.update({
|
|
38
|
+
id: session.sessionToken,
|
|
39
|
+
patch: deleteUndefinedProperties(session),
|
|
38
40
|
strict: false
|
|
39
41
|
})).data,
|
|
40
42
|
deleteSession: async (id) => (await sessions.delete({
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { AdapterUser } from '@auth/core/adapters';
|
|
2
2
|
import { Collection, CollectionOptions } from '@battis/lazy-firestore';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class Users extends Collection<AdapterUser> {
|
|
4
4
|
static readonly DEFAULT: {
|
|
5
5
|
path: string;
|
|
6
6
|
};
|
|
7
7
|
constructor(options: CollectionOptions);
|
|
8
8
|
}
|
|
9
|
-
export declare function users():
|
|
10
|
-
export declare function
|
|
11
|
-
createUser: (
|
|
9
|
+
export declare function users(): Users;
|
|
10
|
+
export declare function UsersAdapter({ path, ...options }?: CollectionOptions): {
|
|
11
|
+
createUser: (user: AdapterUser) => Promise<AdapterUser>;
|
|
12
12
|
getUser: (id: string) => Promise<AdapterUser | null>;
|
|
13
13
|
getUserByEmail: (email: string) => Promise<AdapterUser | null>;
|
|
14
|
-
updateUser: (
|
|
14
|
+
updateUser: (user: Partial<AdapterUser> & Pick<AdapterUser, 'id'>) => Promise<AdapterUser>;
|
|
15
15
|
deleteUser: (id: string) => Promise<AdapterUser | null>;
|
|
16
16
|
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Collection } from '@battis/lazy-firestore';
|
|
2
|
+
import { deleteUndefinedProperties } from '@battis/lazy-firestore/directives/deleteUndefinedProperties';
|
|
3
|
+
import { nullifyUndefinedProperties } from '@battis/lazy-firestore/directives/nullifyUndefinedProperties';
|
|
4
|
+
import { requireUnique } from '@battis/lazy-firestore/directives/requireUnique';
|
|
5
|
+
export class Users extends Collection {
|
|
6
|
+
static DEFAULT = { path: 'users' };
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super({
|
|
9
|
+
...options,
|
|
10
|
+
converter: {
|
|
11
|
+
emailVerified: {
|
|
12
|
+
deflate: (value) => (value ? value.toISOString() : null),
|
|
13
|
+
inflate: (value) => (value ? new Date(value) : null)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let _users = undefined;
|
|
20
|
+
export function users() {
|
|
21
|
+
if (_users) {
|
|
22
|
+
return _users;
|
|
23
|
+
}
|
|
24
|
+
throw new Error('Users collection not initialized');
|
|
25
|
+
}
|
|
26
|
+
export function UsersAdapter({ path = Users.DEFAULT.path, ...options } = Users.DEFAULT) {
|
|
27
|
+
_users = new Users({ path, ...options });
|
|
28
|
+
return {
|
|
29
|
+
createUser: async (user) => (await users().create({
|
|
30
|
+
data: nullifyUndefinedProperties(user),
|
|
31
|
+
id: user.id,
|
|
32
|
+
query: (ref) => ref.where('email', '==', user.email),
|
|
33
|
+
strict: true
|
|
34
|
+
})).data,
|
|
35
|
+
getUser: async (id) => {
|
|
36
|
+
return (await users().read({
|
|
37
|
+
id,
|
|
38
|
+
strict: false
|
|
39
|
+
})).data;
|
|
40
|
+
},
|
|
41
|
+
getUserByEmail: async (email) => {
|
|
42
|
+
return requireUnique({
|
|
43
|
+
list: await users().list({
|
|
44
|
+
query: (ref) => ref.where('email', '==', email),
|
|
45
|
+
strict: false
|
|
46
|
+
}),
|
|
47
|
+
strict: false
|
|
48
|
+
}).data;
|
|
49
|
+
},
|
|
50
|
+
updateUser: async (user) => (await users().update({
|
|
51
|
+
id: user.id,
|
|
52
|
+
patch: deleteUndefinedProperties(user),
|
|
53
|
+
strict: true
|
|
54
|
+
})).data,
|
|
55
|
+
deleteUser: async (id) => (await users().delete({
|
|
56
|
+
id,
|
|
57
|
+
strict: false
|
|
58
|
+
})).data
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { VerificationToken } from '@auth/core/adapters';
|
|
2
2
|
import { Collection, CollectionOptions } from '@battis/lazy-firestore';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class VerificationTokens extends Collection<VerificationToken> {
|
|
4
4
|
static readonly DEFAULT: {
|
|
5
5
|
path: string;
|
|
6
6
|
};
|
|
7
7
|
constructor(options: CollectionOptions);
|
|
8
8
|
}
|
|
9
|
-
export declare function
|
|
10
|
-
createVerificationToken: (
|
|
9
|
+
export declare function VerificationTokensAdapter({ path, ...options }?: CollectionOptions): {
|
|
10
|
+
createVerificationToken: (token: VerificationToken) => Promise<VerificationToken | null>;
|
|
11
11
|
useVerificationToken: (token: Pick<VerificationToken, 'identifier' | 'token'>) => Promise<VerificationToken | null>;
|
|
12
12
|
};
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { Collection } from '@battis/lazy-firestore';
|
|
2
2
|
import { DateConverter } from '@battis/lazy-firestore/converters/Date';
|
|
3
|
-
|
|
3
|
+
import { nullifyUndefinedProperties } from '@battis/lazy-firestore/directives/nullifyUndefinedProperties';
|
|
4
|
+
export class VerificationTokens extends Collection {
|
|
4
5
|
static DEFAULT = { path: 'verificationTokens' };
|
|
5
6
|
constructor(options) {
|
|
6
7
|
super({ ...options, converter: { expires: DateConverter } });
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
|
-
export function
|
|
10
|
-
const tokens = new
|
|
10
|
+
export function VerificationTokensAdapter({ path = VerificationTokens.DEFAULT.path, ...options } = VerificationTokens.DEFAULT) {
|
|
11
|
+
const tokens = new VerificationTokens({ path, ...options });
|
|
11
12
|
return {
|
|
12
|
-
createVerificationToken: async (
|
|
13
|
+
createVerificationToken: async (token) => (await tokens.create({
|
|
14
|
+
...identify(token),
|
|
15
|
+
data: nullifyUndefinedProperties(token),
|
|
16
|
+
strict: false
|
|
17
|
+
})).data,
|
|
13
18
|
useVerificationToken: async (token) => (await tokens.delete({ ...identify(token), strict: false })).data
|
|
14
19
|
};
|
|
15
20
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { Firestore } from '@google-cloud/firestore';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { VerificationTokens,
|
|
3
|
+
import { Accounts, AccountsAdapter } from './Collections/Accounts.js';
|
|
4
|
+
import { AuthenticatorsAdapter } from './Collections/Authenticators.js';
|
|
5
|
+
import { Sessions, SessionsAdapter } from './Collections/Sessions.js';
|
|
6
|
+
import { Users, UsersAdapter } from './Collections/Users.js';
|
|
7
|
+
import { VerificationTokens, VerificationTokensAdapter } from './Collections/VerificationTokens.js';
|
|
8
8
|
export function FirestoreAdapter({ db, databaseId, basePath = '.', usersPath, accountsPath, sessionsPath, verificationTokensPath, authenticatorsPath, firestore } = {}) {
|
|
9
9
|
db = db || new Firestore({ databaseId, ...firestore });
|
|
10
10
|
return {
|
|
11
|
-
...
|
|
11
|
+
...UsersAdapter({
|
|
12
12
|
db,
|
|
13
13
|
path: path.join(
|
|
14
|
-
/*turbopackIgnore: true*/ basePath, usersPath ||
|
|
14
|
+
/*turbopackIgnore: true*/ basePath, usersPath || Users.DEFAULT.path)
|
|
15
15
|
}),
|
|
16
|
-
...
|
|
16
|
+
...AccountsAdapter({
|
|
17
17
|
db,
|
|
18
18
|
path: path.join(
|
|
19
|
-
/*turbopackIgnore: true*/ basePath, accountsPath ||
|
|
19
|
+
/*turbopackIgnore: true*/ basePath, accountsPath || Accounts.DEFAULT.path)
|
|
20
20
|
}),
|
|
21
|
-
...
|
|
21
|
+
...SessionsAdapter({
|
|
22
22
|
db,
|
|
23
23
|
path: path.join(
|
|
24
|
-
/*turbopackIgnore: true*/ basePath, sessionsPath ||
|
|
24
|
+
/*turbopackIgnore: true*/ basePath, sessionsPath || Sessions.DEFAULT.path)
|
|
25
25
|
}),
|
|
26
|
-
...
|
|
26
|
+
...VerificationTokensAdapter({
|
|
27
27
|
db,
|
|
28
28
|
path: path.join(
|
|
29
|
-
/*turbopackIgnore: true*/ basePath, verificationTokensPath ||
|
|
29
|
+
/*turbopackIgnore: true*/ basePath, verificationTokensPath || VerificationTokens.DEFAULT.path)
|
|
30
30
|
}),
|
|
31
|
-
...
|
|
31
|
+
...AuthenticatorsAdapter({
|
|
32
32
|
db,
|
|
33
33
|
path: path.join(
|
|
34
|
-
/*turbopackIgnore: true*/ basePath, authenticatorsPath ||
|
|
34
|
+
/*turbopackIgnore: true*/ basePath, authenticatorsPath || Accounts.DEFAULT.path)
|
|
35
35
|
})
|
|
36
36
|
};
|
|
37
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@groton/authjs-firestore-adapter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"homepage": "https://github.com/groton-school/authjs/tree/main/packages/firestore-adapter#readme",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "github",
|
|
@@ -13,15 +13,18 @@
|
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|
|
15
15
|
"exports": {
|
|
16
|
-
".":
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"./collections
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./collections/*": {
|
|
21
|
+
"types": "./dist/Collections/*.d.ts",
|
|
22
|
+
"default": "./dist/Collections/*.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
21
25
|
},
|
|
22
|
-
"types": "./dist/index.d.ts",
|
|
23
26
|
"dependencies": {
|
|
24
|
-
"@battis/lazy-firestore": "^1.
|
|
27
|
+
"@battis/lazy-firestore": "^1.1.0"
|
|
25
28
|
},
|
|
26
29
|
"devDependencies": {
|
|
27
30
|
"@battis/workspace": "^0.0.12",
|
|
@@ -39,6 +42,7 @@
|
|
|
39
42
|
"build": "run-s build:*",
|
|
40
43
|
"build:clean": "del ./dist",
|
|
41
44
|
"build:compile": "tsc",
|
|
45
|
+
"start": "echo 'noop'",
|
|
42
46
|
"release": "commit-and-tag-version --noBumpWhenEmptyChanges"
|
|
43
47
|
}
|
|
44
48
|
}
|
package/dist/AdapterAccounts.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Collection } from '@battis/lazy-firestore';
|
|
2
|
-
import { requireUnique } from '@battis/lazy-firestore/directives/requireUnique';
|
|
3
|
-
import { users } from './AdapterUsers.js';
|
|
4
|
-
export class AdapterAccountsCollection extends Collection {
|
|
5
|
-
static DEFAULT = { path: 'accounts' };
|
|
6
|
-
}
|
|
7
|
-
export function AdapterAccounts({ path = AdapterAccountsCollection.DEFAULT.path, ...options } = AdapterAccountsCollection.DEFAULT) {
|
|
8
|
-
const accounts = new AdapterAccountsCollection({ path, ...options });
|
|
9
|
-
const getAccount = async (providerAccountId, provider) => requireUnique({
|
|
10
|
-
list: await accounts.list({
|
|
11
|
-
...identify({ provider, providerAccountId }),
|
|
12
|
-
strict: false
|
|
13
|
-
}),
|
|
14
|
-
strict: false
|
|
15
|
-
}).data;
|
|
16
|
-
return {
|
|
17
|
-
linkAccount: async (data) => (await accounts.create({
|
|
18
|
-
...identify(data),
|
|
19
|
-
data,
|
|
20
|
-
strict: false
|
|
21
|
-
})).data,
|
|
22
|
-
getAccount: async (providerAccountId, provider) => {
|
|
23
|
-
return requireUnique({
|
|
24
|
-
list: await accounts.list({
|
|
25
|
-
...identify({ provider, providerAccountId }),
|
|
26
|
-
strict: false
|
|
27
|
-
}),
|
|
28
|
-
strict: false
|
|
29
|
-
}).data;
|
|
30
|
-
},
|
|
31
|
-
getUserByAccount: async ({ provider, providerAccountId }) => {
|
|
32
|
-
const account = await getAccount(provider, providerAccountId);
|
|
33
|
-
if (account) {
|
|
34
|
-
return (await users().read({ id: account.userId, strict: false })).data;
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
},
|
|
38
|
-
unlinkAccount: async (account) => (await accounts.delete({
|
|
39
|
-
...identify(account),
|
|
40
|
-
strict: false
|
|
41
|
-
})).data ?? undefined
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function identify({ provider, providerAccountId }) {
|
|
45
|
-
return {
|
|
46
|
-
query: (ref) => ref
|
|
47
|
-
.where('provider', '==', provider)
|
|
48
|
-
.where('providerAccountId', '==', providerAccountId)
|
|
49
|
-
};
|
|
50
|
-
}
|
package/dist/AdapterUsers.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Collection } from '@battis/lazy-firestore';
|
|
2
|
-
import { requireUnique } from '@battis/lazy-firestore/directives/requireUnique';
|
|
3
|
-
export class AdapterUsersCollection extends Collection {
|
|
4
|
-
static DEFAULT = { path: 'users' };
|
|
5
|
-
constructor(options) {
|
|
6
|
-
super({
|
|
7
|
-
...options,
|
|
8
|
-
converter: {
|
|
9
|
-
emailVerified: {
|
|
10
|
-
deflate: (value) => (value ? value.toISOString() : null),
|
|
11
|
-
inflate: (value) => (value ? new Date(value) : null)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
let _users = undefined;
|
|
18
|
-
export function users() {
|
|
19
|
-
if (_users) {
|
|
20
|
-
return _users;
|
|
21
|
-
}
|
|
22
|
-
throw new Error('Users collection not initialized');
|
|
23
|
-
}
|
|
24
|
-
export function AdapterUsers({ path = AdapterUsersCollection.DEFAULT.path, ...options } = AdapterUsersCollection.DEFAULT) {
|
|
25
|
-
_users = new AdapterUsersCollection({ path, ...options });
|
|
26
|
-
return {
|
|
27
|
-
createUser: async (data) => (await users().create({
|
|
28
|
-
data,
|
|
29
|
-
id: data.id,
|
|
30
|
-
query: (ref) => ref.where('email', '==', data.email),
|
|
31
|
-
strict: true
|
|
32
|
-
})).data,
|
|
33
|
-
getUser: async (id) => (await users().read({
|
|
34
|
-
id,
|
|
35
|
-
strict: false
|
|
36
|
-
})).data,
|
|
37
|
-
getUserByEmail: async (email) => requireUnique({
|
|
38
|
-
list: await users().list({
|
|
39
|
-
query: (ref) => ref.where('email', '==', email),
|
|
40
|
-
strict: false
|
|
41
|
-
}),
|
|
42
|
-
strict: false
|
|
43
|
-
}).data,
|
|
44
|
-
updateUser: async (patch) => (await users().update({
|
|
45
|
-
id: patch.id,
|
|
46
|
-
patch,
|
|
47
|
-
strict: true
|
|
48
|
-
})).data,
|
|
49
|
-
deleteUser: async (id) => (await users().delete({
|
|
50
|
-
id,
|
|
51
|
-
strict: false
|
|
52
|
-
})).data
|
|
53
|
-
};
|
|
54
|
-
}
|