@unchainedshop/core-users 4.0.0-rc.16 → 4.0.0-rc.17
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/lib/db/UsersCollection.d.ts +2 -2
- package/lib/db/UsersCollection.d.ts.map +1 -1
- package/lib/db/UsersCollection.js +30 -26
- package/lib/db/UsersCollection.js.map +1 -1
- package/lib/module/addMigrations.d.ts +3 -0
- package/lib/module/addMigrations.d.ts.map +1 -0
- package/lib/module/addMigrations.js +48 -0
- package/lib/module/addMigrations.js.map +1 -0
- package/lib/module/configureUsersModule.d.ts +30 -30
- package/lib/module/configureUsersModule.d.ts.map +1 -1
- package/lib/module/configureUsersModule.js +63 -36
- package/lib/module/configureUsersModule.js.map +1 -1
- package/lib/module/configureUsersWebAuthnModule.d.ts +5 -5
- package/lib/module/configureUsersWebAuthnModule.d.ts.map +1 -1
- package/lib/module/configureUsersWebAuthnModule.js +5 -1
- package/lib/module/configureUsersWebAuthnModule.js.map +1 -1
- package/lib/services/getUserCountryService.d.ts +3 -0
- package/lib/services/getUserCountryService.d.ts.map +1 -0
- package/lib/services/getUserCountryService.js +7 -0
- package/lib/services/getUserCountryService.js.map +1 -0
- package/lib/services/getUserLanguageService.d.ts +3 -0
- package/lib/services/getUserLanguageService.d.ts.map +1 -0
- package/lib/services/getUserLanguageService.js +7 -0
- package/lib/services/getUserLanguageService.js.map +1 -0
- package/lib/services/updateUserAvatarAfterUploadService.d.ts +3 -0
- package/lib/services/updateUserAvatarAfterUploadService.d.ts.map +1 -0
- package/lib/services/updateUserAvatarAfterUploadService.js +24 -0
- package/lib/services/updateUserAvatarAfterUploadService.js.map +1 -0
- package/lib/services/userServices.d.ts +3 -0
- package/lib/services/userServices.d.ts.map +1 -0
- package/lib/services/userServices.js +9 -0
- package/lib/services/userServices.js.map +1 -0
- package/lib/users-settings.d.ts +1 -14
- package/lib/users-settings.d.ts.map +1 -1
- package/lib/users-settings.js +24 -24
- package/lib/users-settings.js.map +1 -1
- package/package.json +7 -7
- package/src/db/UsersCollection.ts +33 -29
- package/src/module/buildFindSelector.test.ts +13 -4
- package/src/module/configureUsersModule.ts +102 -80
- package/src/module/configureUsersWebAuthnModule.ts +4 -6
- package/src/users-settings.ts +31 -45
- package/tsconfig.json +2 -1
|
@@ -18,7 +18,7 @@ export interface UserLastLogin {
|
|
|
18
18
|
export interface PushSubscriptionObject {
|
|
19
19
|
userAgent: string;
|
|
20
20
|
endpoint: string;
|
|
21
|
-
expirationTime
|
|
21
|
+
expirationTime: number;
|
|
22
22
|
keys: {
|
|
23
23
|
auth: string;
|
|
24
24
|
p256dh: string;
|
|
@@ -29,7 +29,7 @@ export interface Email {
|
|
|
29
29
|
verified: boolean;
|
|
30
30
|
}
|
|
31
31
|
export type User = {
|
|
32
|
-
_id
|
|
32
|
+
_id: string;
|
|
33
33
|
deleted?: Date;
|
|
34
34
|
avatarId?: string;
|
|
35
35
|
emails: Email[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersCollection.d.ts","sourceRoot":"","sources":["../../src/db/UsersCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,OAAO,EACP,OAAO,EACP,OAAO,EAGR,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AACD,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CA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I,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,GAAG,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,iBAAiB,EAAE,sBAAsB,EAAE,CAAC;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,GAAG,eAAe,CAAC;AAEpB,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;IAC7C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,IAAI,OAAO,CAAC,EAAE,sCAyGnD,CAAC"}
|
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
2
2
|
export const UsersCollection = async (db) => {
|
|
3
3
|
const Users = db.collection('users');
|
|
4
|
+
if (!isDocumentDBCompatModeEnabled()) {
|
|
5
|
+
await buildDbIndexes(Users, [
|
|
6
|
+
{
|
|
7
|
+
index: {
|
|
8
|
+
_id: 'text',
|
|
9
|
+
username: 'text',
|
|
10
|
+
'emails.address': 'text',
|
|
11
|
+
'profile.displayName': 'text',
|
|
12
|
+
'lastBillingAddress.firstName': 'text',
|
|
13
|
+
'lastBillingAddress.lastName': 'text',
|
|
14
|
+
'lastBillingAddress.company': 'text',
|
|
15
|
+
'lastBillingAddress.addressLine': 'text',
|
|
16
|
+
'lastBillingAddress.addressLine2': 'text',
|
|
17
|
+
},
|
|
18
|
+
options: {
|
|
19
|
+
weights: {
|
|
20
|
+
_id: 9,
|
|
21
|
+
'emails.address': 7,
|
|
22
|
+
'profile.displayName': 5,
|
|
23
|
+
'lastBillingAddress.firstName': 3,
|
|
24
|
+
'lastBillingAddress.lastName': 3,
|
|
25
|
+
'lastBillingAddress.company': 1,
|
|
26
|
+
'lastBillingAddress.addressLine': 1,
|
|
27
|
+
'lastBillingAddress.addressLine2': 1,
|
|
28
|
+
},
|
|
29
|
+
name: 'user_fulltext_search',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
4
34
|
await buildDbIndexes(Users, [
|
|
5
35
|
{
|
|
6
36
|
index: {
|
|
@@ -66,32 +96,6 @@ export const UsersCollection = async (db) => {
|
|
|
66
96
|
sparse: true,
|
|
67
97
|
},
|
|
68
98
|
},
|
|
69
|
-
!isDocumentDBCompatModeEnabled() && {
|
|
70
|
-
index: {
|
|
71
|
-
_id: 'text',
|
|
72
|
-
username: 'text',
|
|
73
|
-
'emails.address': 'text',
|
|
74
|
-
'profile.displayName': 'text',
|
|
75
|
-
'lastBillingAddress.firstName': 'text',
|
|
76
|
-
'lastBillingAddress.lastName': 'text',
|
|
77
|
-
'lastBillingAddress.company': 'text',
|
|
78
|
-
'lastBillingAddress.addressLine': 'text',
|
|
79
|
-
'lastBillingAddress.addressLine2': 'text',
|
|
80
|
-
},
|
|
81
|
-
options: {
|
|
82
|
-
weights: {
|
|
83
|
-
_id: 9,
|
|
84
|
-
'emails.address': 7,
|
|
85
|
-
'profile.displayName': 5,
|
|
86
|
-
'lastBillingAddress.firstName': 3,
|
|
87
|
-
'lastBillingAddress.lastName': 3,
|
|
88
|
-
'lastBillingAddress.company': 1,
|
|
89
|
-
'lastBillingAddress.addressLine': 1,
|
|
90
|
-
'lastBillingAddress.addressLine2': 1,
|
|
91
|
-
},
|
|
92
|
-
name: 'user_fulltext_search',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
99
|
]);
|
|
96
100
|
return Users;
|
|
97
101
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersCollection.js","sourceRoot":"","sources":["../../src/db/UsersCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,cAAc,EACd,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AA6DhC,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EAAc,EAAE,EAAE;IACtD,MAAM,KAAK,GAAG,EAAE,CAAC,UAAU,CAAO,OAAO,CAAC,CAAC;IAE3C,MAAM,cAAc,CAAO,KAAK,EAAE;QAChC;YACE,KAAK,EAAE;gBACL,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,CAAC;gBACV,KAAK,EAAE,CAAC;aACT;YACD,OAAO,EAAE,EAAE;SACZ;QACD;YACE,KAAK,EAAE;gBACL,KAAK,EAAE,CAAC;aACT;YACD,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;aACb;SACF;QACD;YACE,KAAK,EAAE;gBACL,OAAO,EAAE,CAAC;aACX;YACD,OAAO,EAAE,EAAE;SACZ;QACD;YACE,KAAK,EAAE;gBACL,QAAQ,EAAE,CAAC;aACZ;YACD,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,IAAI;aACb;SACF;QACD;YACE,KAAK,EAAE;gBACL,gBAAgB,EAAE,CAAC;aACb;YACR,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,IAAI;aACb;SACF;QAED;YACE,KAAK,EAAE;gBACL,yCAAyC,EAAE,CAAC;aACtC;YACR,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;aACb;SACF;QAED;YACE,KAAK,EAAE;gBACL,+BAA+B,EAAE,CAAC;aAC5B;YACR,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;aACb;SACF;QAED;YACE,KAAK,EAAE;gBACL,uBAAuB,EAAE,CAAC;aAC3B;YACD,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;aACb;SACF;
|
|
1
|
+
{"version":3,"file":"UsersCollection.js","sourceRoot":"","sources":["../../src/db/UsersCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,cAAc,EACd,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AA6DhC,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EAAc,EAAE,EAAE;IACtD,MAAM,KAAK,GAAG,EAAE,CAAC,UAAU,CAAO,OAAO,CAAC,CAAC;IAE3C,IAAI,CAAC,6BAA6B,EAAE,EAAE,CAAC;QACrC,MAAM,cAAc,CAAO,KAAK,EAAE;YAChC;gBACE,KAAK,EAAE;oBACL,GAAG,EAAE,MAAM;oBACX,QAAQ,EAAE,MAAM;oBAChB,gBAAgB,EAAE,MAAM;oBACxB,qBAAqB,EAAE,MAAM;oBAC7B,8BAA8B,EAAE,MAAM;oBACtC,6BAA6B,EAAE,MAAM;oBACrC,4BAA4B,EAAE,MAAM;oBACpC,gCAAgC,EAAE,MAAM;oBACxC,iCAAiC,EAAE,MAAM;iBACnC;gBACR,OAAO,EAAE;oBACP,OAAO,EAAE;wBACP,GAAG,EAAE,CAAC;wBACN,gBAAgB,EAAE,CAAC;wBACnB,qBAAqB,EAAE,CAAC;wBACxB,8BAA8B,EAAE,CAAC;wBACjC,6BAA6B,EAAE,CAAC;wBAChC,4BAA4B,EAAE,CAAC;wBAC/B,gCAAgC,EAAE,CAAC;wBACnC,iCAAiC,EAAE,CAAC;qBACrC;oBACD,IAAI,EAAE,sBAAsB;iBAC7B;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,cAAc,CAAO,KAAK,EAAE;QAChC;YACE,KAAK,EAAE;gBACL,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,CAAC;gBACV,KAAK,EAAE,CAAC;aACT;YACD,OAAO,EAAE,EAAE;SACZ;QACD;YACE,KAAK,EAAE;gBACL,KAAK,EAAE,CAAC;aACT;YACD,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;aACb;SACF;QACD;YACE,KAAK,EAAE;gBACL,OAAO,EAAE,CAAC;aACX;YACD,OAAO,EAAE,EAAE;SACZ;QACD;YACE,KAAK,EAAE;gBACL,QAAQ,EAAE,CAAC;aACZ;YACD,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,IAAI;aACb;SACF;QACD;YACE,KAAK,EAAE;gBACL,gBAAgB,EAAE,CAAC;aACb;YACR,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,IAAI;aACb;SACF;QAED;YACE,KAAK,EAAE;gBACL,yCAAyC,EAAE,CAAC;aACtC;YACR,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;aACb;SACF;QAED;YACE,KAAK,EAAE;gBACL,+BAA+B,EAAE,CAAC;aAC5B;YACR,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;aACb;SACF;QAED;YACE,KAAK,EAAE;gBACL,uBAAuB,EAAE,CAAC;aAC3B;YACD,OAAO,EAAE;gBACP,MAAM,EAAE,IAAI;aACb;SACF;KACF,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMigrations.d.ts","sourceRoot":"","sources":["../../src/module/addMigrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAI7D,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,UAAU,EAAE,mBAAmB,QAuDpE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { UsersCollection } from '../db/UsersCollection.js';
|
|
2
|
+
import { systemLocale } from '@unchainedshop/utils';
|
|
3
|
+
export default function addMigrations(repository) {
|
|
4
|
+
repository?.register({
|
|
5
|
+
id: 20230719105000,
|
|
6
|
+
name: 'Rename user.lastLogin.countryContext to user.lastLogin.countryCode',
|
|
7
|
+
up: async () => {
|
|
8
|
+
const Users = await UsersCollection(repository.db);
|
|
9
|
+
await Users.updateMany({
|
|
10
|
+
'lastLogin.countryContext': { $exists: true },
|
|
11
|
+
}, {
|
|
12
|
+
$rename: { 'lastLogin.countryContext': 'lastLogin.countryCode' },
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
repository?.register({
|
|
17
|
+
id: 20241218092300,
|
|
18
|
+
name: 'Convert user.lastLogin.locale',
|
|
19
|
+
up: async () => {
|
|
20
|
+
const Users = await UsersCollection(repository.db);
|
|
21
|
+
const users = await Users.find({
|
|
22
|
+
'lastLogin.locale': { $exists: true },
|
|
23
|
+
}, { projection: { _id: true, lastLogin: true } }).toArray();
|
|
24
|
+
for (const user of users) {
|
|
25
|
+
let newLocale;
|
|
26
|
+
try {
|
|
27
|
+
newLocale = new Intl.Locale(user.lastLogin.locale).baseName;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
/* */
|
|
31
|
+
try {
|
|
32
|
+
newLocale = new Intl.Locale(user.lastLogin.locale.split('_').join('-')).baseName;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* */
|
|
36
|
+
newLocale = systemLocale.baseName;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
await Users.updateOne({
|
|
40
|
+
_id: user._id,
|
|
41
|
+
}, {
|
|
42
|
+
$set: { 'lastLogin.locale': newLocale },
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=addMigrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMigrations.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AC;oBACP,KAAK;oBACL,IAAI,CAAC;wBACH,SAAS,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;oBACnF,CAAC;oBAAC,MAAM,CAAC;wBACP,KAAK;wBACL,SAAS,GAAG,YAAY,CAAC,QAAQ,CAAC;oBACpC,CAAC;gBACH,CAAC;gBAED,MAAM,KAAK,CAAC,SAAS,CACnB;oBACE,GAAG,EAAE,IAAI,CAAC,GAAG;iBACd,EACD;oBACE,IAAI,EAAE,EAAE,kBAAkB,EAAE,SAAS,EAAE;iBACxC,CACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -4,48 +4,48 @@ import { SortOption } from '@unchainedshop/utils';
|
|
|
4
4
|
import { UserRegistrationData, UserSettingsOptions } from '../users-settings.js';
|
|
5
5
|
export declare const removeConfidentialServiceHashes: (rawUser: User) => User;
|
|
6
6
|
export declare const buildFindSelector: ({ includeGuests, includeDeleted, queryString, emailVerified, lastLogin, tags, ...rest }: UserQuery) => mongodb.Filter<User>;
|
|
7
|
-
export declare const configureUsersModule: (
|
|
7
|
+
export declare const configureUsersModule: (moduleInput: ModuleInput<UserSettingsOptions>) => Promise<{
|
|
8
8
|
webAuthn: {
|
|
9
9
|
findMDSMetadataForAAGUID: (aaguid: string) => Promise<any>;
|
|
10
|
-
createCredentialCreationOptions: (origin: string, username: string, extensionOptions?: any) => Promise<Omit<import("fido2-lib").PublicKeyCredentialCreationOptions, "challenge" | "requestId"> & {
|
|
10
|
+
createCredentialCreationOptions: (origin: string, username: string, extensionOptions?: any) => Promise<(Omit<import("fido2-lib").PublicKeyCredentialCreationOptions, "challenge" | "requestId"> & {
|
|
11
11
|
challenge: string;
|
|
12
12
|
requestId: number;
|
|
13
|
-
}>;
|
|
14
|
-
createCredentialRequestOptions: (origin: string, username
|
|
13
|
+
}) | null>;
|
|
14
|
+
createCredentialRequestOptions: (origin: string, username: string, extensionOptions?: any) => Promise<(Omit<import("fido2-lib").PublicKeyCredentialRequestOptions, "challenge" | "requestId"> & {
|
|
15
15
|
challenge: string;
|
|
16
16
|
requestId: number;
|
|
17
|
-
}>;
|
|
17
|
+
}) | null>;
|
|
18
18
|
verifyCredentialCreation: (username: string, credentials: any) => Promise<{
|
|
19
19
|
publicKey: any;
|
|
20
20
|
counter: any;
|
|
21
21
|
id: any;
|
|
22
22
|
aaguid: string;
|
|
23
23
|
created: Date;
|
|
24
|
-
}>;
|
|
24
|
+
} | null>;
|
|
25
25
|
verifyCredentialRequest: (userPublicKeys: any[], username: string, credentials: any) => Promise<{
|
|
26
26
|
userHandle: any;
|
|
27
|
-
}>;
|
|
27
|
+
} | null>;
|
|
28
28
|
deleteUserWebAuthnCredentials: (username: string) => Promise<number>;
|
|
29
29
|
};
|
|
30
30
|
count(query: UserQuery): Promise<number>;
|
|
31
|
-
findUserById(userId: string): Promise<User>;
|
|
32
|
-
findUserByUsername(username: string): Promise<User>;
|
|
33
|
-
findUserByEmail(email: string): Promise<User>;
|
|
31
|
+
findUserById(userId: string): Promise<mongodb.WithId<User> | null>;
|
|
32
|
+
findUserByUsername(username: string): Promise<mongodb.WithId<User> | null>;
|
|
33
|
+
findUserByEmail(email: string): Promise<mongodb.WithId<User> | null>;
|
|
34
34
|
findUnverifiedEmailToken(plainToken: string): Promise<{
|
|
35
35
|
userId: string;
|
|
36
36
|
address: string;
|
|
37
37
|
when: Date;
|
|
38
|
-
}>;
|
|
38
|
+
} | null>;
|
|
39
39
|
verifyEmail(userId: string, address: string): Promise<void>;
|
|
40
40
|
findResetToken(plainToken: string): Promise<{
|
|
41
41
|
userId: string;
|
|
42
42
|
address: string;
|
|
43
43
|
when: Date;
|
|
44
|
-
}>;
|
|
45
|
-
findUserByToken(plainToken: string): Promise<User>;
|
|
44
|
+
} | null>;
|
|
45
|
+
findUserByToken(plainToken: string): Promise<mongodb.WithId<User> | null>;
|
|
46
46
|
findUser(query: UserQuery & {
|
|
47
47
|
sort?: SortOption[];
|
|
48
|
-
}, findOptions?: mongodb.FindOptions): Promise<User>;
|
|
48
|
+
}, findOptions?: mongodb.FindOptions): Promise<User | null>;
|
|
49
49
|
findUsers({ limit, offset, ...query }: UserQuery & {
|
|
50
50
|
sort?: SortOption[];
|
|
51
51
|
limit?: number;
|
|
@@ -55,7 +55,7 @@ export declare const configureUsersModule: ({ db, options }: ModuleInput<UserSet
|
|
|
55
55
|
userId: string;
|
|
56
56
|
}): Promise<boolean>;
|
|
57
57
|
primaryEmail(user: User): Email;
|
|
58
|
-
userLocale(user: User): Intl.Locale;
|
|
58
|
+
userLocale(user: User | null): Intl.Locale;
|
|
59
59
|
createUser(rawUserData: UserRegistrationData, { skipMessaging, skipPasswordEnrollment, }?: {
|
|
60
60
|
skipMessaging?: boolean;
|
|
61
61
|
skipPasswordEnrollment?: boolean;
|
|
@@ -71,26 +71,26 @@ export declare const configureUsersModule: ({ db, options }: ModuleInput<UserSet
|
|
|
71
71
|
removeEmail(userId: string, address: string): Promise<void>;
|
|
72
72
|
sendResetPasswordEmail(userId: string, email: string, isEnrollment?: boolean): Promise<void>;
|
|
73
73
|
sendVerificationEmail(userId: string, email: string): Promise<void>;
|
|
74
|
-
addRoles: (userId: string, roles: string[]) => Promise<
|
|
75
|
-
setUsername(userId: string, username: string): Promise<
|
|
76
|
-
setPassword(userId: string, plainPassword: string): Promise<User>;
|
|
77
|
-
resetPassword(token: string, newPassword: string): Promise<
|
|
78
|
-
updateAvatar: (_id: string, fileId: string) => Promise<User>;
|
|
79
|
-
updateGuest: (user: User, guest: boolean) => Promise<
|
|
80
|
-
updateHeartbeat: (userId: string, lastLogin: UserLastLogin) => Promise<User>;
|
|
81
|
-
markDeleted: (userId: string) => Promise<User>;
|
|
74
|
+
addRoles: (userId: string, roles: string[]) => Promise<mongodb.WithId<User> | null>;
|
|
75
|
+
setUsername(userId: string, username: string): Promise<mongodb.WithId<User> | null>;
|
|
76
|
+
setPassword(userId: string, plainPassword: string): Promise<mongodb.WithId<User> | null>;
|
|
77
|
+
resetPassword(token: string, newPassword: string): Promise<any>;
|
|
78
|
+
updateAvatar: (_id: string, fileId: string) => Promise<mongodb.WithId<User> | null>;
|
|
79
|
+
updateGuest: (user: User, guest: boolean) => Promise<mongodb.WithId<User> | null>;
|
|
80
|
+
updateHeartbeat: (userId: string, lastLogin: UserLastLogin) => Promise<mongodb.WithId<User> | null>;
|
|
81
|
+
markDeleted: (userId: string) => Promise<mongodb.WithId<User> | null>;
|
|
82
82
|
deletePermanently: ({ userId }: {
|
|
83
83
|
userId: string;
|
|
84
|
-
}) => Promise<User>;
|
|
84
|
+
}) => Promise<mongodb.WithId<User> | null>;
|
|
85
85
|
updateProfile: (userId: string, updatedData: {
|
|
86
86
|
profile?: UserProfile;
|
|
87
87
|
meta?: any;
|
|
88
|
-
}) => Promise<User>;
|
|
89
|
-
updateLastBillingAddress: (_id: string, lastBillingAddress: Address) => Promise<User>;
|
|
90
|
-
updateLastContact: (_id: string, lastContact: Contact) => Promise<User>;
|
|
91
|
-
updateRoles: (_id: string, roles: string[]) => Promise<User>;
|
|
92
|
-
updateTags: (_id: string, tags: string[]) => Promise<User>;
|
|
93
|
-
updateUser: (selector: mongodb.Filter<User>, modifier: mongodb.UpdateFilter<User>, updateOptions?: mongodb.FindOneAndUpdateOptions) => Promise<User>;
|
|
88
|
+
}) => Promise<mongodb.WithId<User> | null>;
|
|
89
|
+
updateLastBillingAddress: (_id: string, lastBillingAddress: Address) => Promise<mongodb.WithId<User> | null>;
|
|
90
|
+
updateLastContact: (_id: string, lastContact: Contact) => Promise<mongodb.WithId<User> | null>;
|
|
91
|
+
updateRoles: (_id: string, roles: string[]) => Promise<mongodb.WithId<User> | null>;
|
|
92
|
+
updateTags: (_id: string, tags: string[]) => Promise<mongodb.WithId<User> | null>;
|
|
93
|
+
updateUser: (selector: mongodb.Filter<User>, modifier: mongodb.UpdateFilter<User>, updateOptions?: mongodb.FindOneAndUpdateOptions) => Promise<mongodb.WithId<User> | null>;
|
|
94
94
|
addPushSubscription: (userId: string, subscription: any, subscriptionOptions?: {
|
|
95
95
|
userAgent: string;
|
|
96
96
|
unsubscribeFromOtherUsers: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureUsersModule.d.ts","sourceRoot":"","sources":["../../src/module/configureUsersModule.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,OAAO,EACP,OAAO,EAGP,OAAO,EAIR,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,IAAI,EACJ,SAAS,EACT,KAAK,EACL,aAAa,EACb,WAAW,EAEZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAA+B,UAAU,EAAU,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAEL,oBAAoB,EAEpB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAqB9B,eAAO,MAAM,+BAA+B,GAAI,SAAS,IAAI,KAAG,IAI/D,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,yFAQ/B,SAAS,yBA6BX,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAU,
|
|
1
|
+
{"version":3,"file":"configureUsersModule.d.ts","sourceRoot":"","sources":["../../src/module/configureUsersModule.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,OAAO,EACP,OAAO,EAGP,OAAO,EAIR,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,IAAI,EACJ,SAAS,EACT,KAAK,EACL,aAAa,EACb,WAAW,EAEZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAA+B,UAAU,EAAU,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAEL,oBAAoB,EAEpB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAqB9B,eAAO,MAAM,+BAA+B,GAAI,SAAS,IAAI,KAAG,IAI/D,CAAC;AAEF,eAAO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GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC"}
|
|
@@ -31,9 +31,9 @@ export const removeConfidentialServiceHashes = (rawUser) => {
|
|
|
31
31
|
export const buildFindSelector = ({ includeGuests, includeDeleted, queryString, emailVerified, lastLogin, tags, ...rest }) => {
|
|
32
32
|
const selector = { ...rest };
|
|
33
33
|
if (!includeDeleted)
|
|
34
|
-
selector.deleted =
|
|
34
|
+
selector.deleted = { $exists: false };
|
|
35
35
|
if (!includeGuests)
|
|
36
|
-
selector.guest = { $
|
|
36
|
+
selector.guest = { $ne: true };
|
|
37
37
|
if (emailVerified === true) {
|
|
38
38
|
selector['emails.verified'] = true;
|
|
39
39
|
}
|
|
@@ -60,11 +60,12 @@ export const buildFindSelector = ({ includeGuests, includeDeleted, queryString,
|
|
|
60
60
|
}
|
|
61
61
|
return selector;
|
|
62
62
|
};
|
|
63
|
-
export const configureUsersModule = async (
|
|
63
|
+
export const configureUsersModule = async (moduleInput) => {
|
|
64
|
+
const { db, options } = moduleInput;
|
|
64
65
|
userSettings.configureSettings(options || {}, db);
|
|
65
66
|
registerEvents(USER_EVENTS);
|
|
66
67
|
const Users = await UsersCollection(db);
|
|
67
|
-
const webAuthn = await configureUsersWebAuthnModule(
|
|
68
|
+
const webAuthn = await configureUsersWebAuthnModule(moduleInput);
|
|
68
69
|
return {
|
|
69
70
|
// Queries
|
|
70
71
|
webAuthn,
|
|
@@ -178,7 +179,7 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
178
179
|
}).toArray();
|
|
179
180
|
},
|
|
180
181
|
async userExists({ userId }) {
|
|
181
|
-
const userCount = await Users.countDocuments({ _id: userId, deleted:
|
|
182
|
+
const userCount = await Users.countDocuments({ _id: userId, deleted: { $exists: false } }, { limit: 1 });
|
|
182
183
|
return userCount === 1;
|
|
183
184
|
},
|
|
184
185
|
// Transformations
|
|
@@ -251,7 +252,7 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
251
252
|
catch {
|
|
252
253
|
/* */
|
|
253
254
|
}
|
|
254
|
-
const user = await Users.findOne({ _id: userId }, {});
|
|
255
|
+
const user = (await Users.findOne({ _id: userId }, {}));
|
|
255
256
|
await emit('USER_CREATE', {
|
|
256
257
|
user: removeConfidentialServiceHashes(user),
|
|
257
258
|
});
|
|
@@ -333,28 +334,31 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
333
334
|
},
|
|
334
335
|
addRoles: async (userId, roles) => {
|
|
335
336
|
const selector = generateDbFilterById(userId);
|
|
336
|
-
const
|
|
337
|
+
const user = await Users.findOneAndUpdate(selector, {
|
|
337
338
|
$addToSet: { roles: { $each: roles } },
|
|
338
|
-
});
|
|
339
|
-
|
|
339
|
+
}, { returnDocument: 'after' });
|
|
340
|
+
if (!user)
|
|
341
|
+
return null;
|
|
340
342
|
await emit('USER_ADD_ROLES', {
|
|
341
343
|
user: removeConfidentialServiceHashes(user),
|
|
342
344
|
});
|
|
343
|
-
return
|
|
345
|
+
return user;
|
|
344
346
|
},
|
|
345
347
|
async setUsername(userId, username) {
|
|
346
348
|
if (!(await userSettings.validateUsername(username))) {
|
|
347
349
|
throw new Error(`Username ${username} is invalid`, { cause: 'USERNAME_INVALID' });
|
|
348
350
|
}
|
|
349
|
-
await Users.
|
|
351
|
+
const user = await Users.findOneAndUpdate({ _id: userId }, {
|
|
350
352
|
$set: {
|
|
351
353
|
username: username.trim(),
|
|
352
354
|
},
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
+
}, { returnDocument: 'after' });
|
|
356
|
+
if (!user)
|
|
357
|
+
return null;
|
|
355
358
|
await emit('USER_UPDATE_USERNAME', {
|
|
356
359
|
user: removeConfidentialServiceHashes(user),
|
|
357
360
|
});
|
|
361
|
+
return user;
|
|
358
362
|
},
|
|
359
363
|
async setPassword(userId, plainPassword) {
|
|
360
364
|
if (!(await userSettings.validatePassword(plainPassword))) {
|
|
@@ -367,6 +371,8 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
367
371
|
'services.password': await this.hashPassword(password || crypto.randomUUID().split('-').pop()),
|
|
368
372
|
},
|
|
369
373
|
}, { returnDocument: 'after' });
|
|
374
|
+
if (!user)
|
|
375
|
+
return null;
|
|
370
376
|
await emit('USER_UPDATE_PASSWORD', {
|
|
371
377
|
user: removeConfidentialServiceHashes(user),
|
|
372
378
|
});
|
|
@@ -407,33 +413,40 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
407
413
|
const user = await Users.findOneAndUpdate(userFilter, modifier, {
|
|
408
414
|
returnDocument: 'after',
|
|
409
415
|
});
|
|
416
|
+
if (!user)
|
|
417
|
+
return null;
|
|
410
418
|
await emit('USER_UPDATE_AVATAR', {
|
|
411
419
|
user: removeConfidentialServiceHashes(user),
|
|
412
420
|
});
|
|
413
421
|
return user;
|
|
414
422
|
},
|
|
415
423
|
updateGuest: async (user, guest) => {
|
|
416
|
-
const
|
|
417
|
-
|
|
424
|
+
const updatedUser = await Users.findOneAndUpdate(generateDbFilterById(user._id), {
|
|
425
|
+
$set: { guest },
|
|
426
|
+
}, { returnDocument: 'after' });
|
|
427
|
+
if (!updatedUser)
|
|
428
|
+
return null;
|
|
418
429
|
await emit('USER_UPDATE_GUEST', {
|
|
419
430
|
user: removeConfidentialServiceHashes({
|
|
420
|
-
...
|
|
431
|
+
...updatedUser,
|
|
421
432
|
guest,
|
|
422
433
|
}),
|
|
423
434
|
});
|
|
435
|
+
return updatedUser;
|
|
424
436
|
},
|
|
425
437
|
updateHeartbeat: async (userId, lastLogin) => {
|
|
426
|
-
const
|
|
438
|
+
const user = await Users.findOneAndUpdate(generateDbFilterById(userId), {
|
|
427
439
|
$set: {
|
|
428
440
|
lastLogin: {
|
|
429
441
|
timestamp: new Date(),
|
|
430
442
|
...lastLogin,
|
|
431
443
|
},
|
|
432
444
|
},
|
|
433
|
-
}
|
|
434
|
-
const user = await Users.findOneAndUpdate(generateDbFilterById(userId), modifier, {
|
|
445
|
+
}, {
|
|
435
446
|
returnDocument: 'after',
|
|
436
447
|
});
|
|
448
|
+
if (!user)
|
|
449
|
+
return null;
|
|
437
450
|
await emit('USER_UPDATE_HEARTBEAT', {
|
|
438
451
|
user: removeConfidentialServiceHashes(user),
|
|
439
452
|
});
|
|
@@ -449,16 +462,20 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
449
462
|
deleted: new Date(),
|
|
450
463
|
emails: [],
|
|
451
464
|
roles: [],
|
|
452
|
-
profile: null,
|
|
453
|
-
lastBillingAddress: null,
|
|
454
465
|
services: {},
|
|
455
466
|
pushSubscriptions: [],
|
|
456
|
-
avatarId: null,
|
|
457
467
|
initialPassword: false,
|
|
458
|
-
|
|
459
|
-
|
|
468
|
+
},
|
|
469
|
+
$unset: {
|
|
470
|
+
profile: 1,
|
|
471
|
+
lastBillingAddress: 1,
|
|
472
|
+
lastContact: 1,
|
|
473
|
+
lastLogin: 1,
|
|
474
|
+
avatarId: 1,
|
|
460
475
|
},
|
|
461
476
|
}, { returnDocument: 'after' });
|
|
477
|
+
if (!user)
|
|
478
|
+
return null;
|
|
462
479
|
await emit('USER_REMOVE', {
|
|
463
480
|
user,
|
|
464
481
|
});
|
|
@@ -490,6 +507,8 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
490
507
|
const user = await Users.findOneAndUpdate(userFilter, modifier, {
|
|
491
508
|
returnDocument: 'after',
|
|
492
509
|
});
|
|
510
|
+
if (!user)
|
|
511
|
+
return null;
|
|
493
512
|
await emit('USER_UPDATE_PROFILE', {
|
|
494
513
|
user: removeConfidentialServiceHashes(user),
|
|
495
514
|
});
|
|
@@ -498,6 +517,8 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
498
517
|
updateLastBillingAddress: async (_id, lastBillingAddress) => {
|
|
499
518
|
const userFilter = generateDbFilterById(_id);
|
|
500
519
|
const user = await Users.findOne(userFilter, {});
|
|
520
|
+
if (!user)
|
|
521
|
+
return null;
|
|
501
522
|
if (!lastBillingAddress)
|
|
502
523
|
return user;
|
|
503
524
|
const modifier = {
|
|
@@ -519,16 +540,18 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
519
540
|
const updatedUser = await Users.findOneAndUpdate(generateDbFilterById(_id), modifier, {
|
|
520
541
|
returnDocument: 'after',
|
|
521
542
|
});
|
|
522
|
-
if (updatedUser)
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
543
|
+
if (!updatedUser)
|
|
544
|
+
return null;
|
|
545
|
+
await emit('USER_UPDATE_BILLING_ADDRESS', {
|
|
546
|
+
user: removeConfidentialServiceHashes(updatedUser),
|
|
547
|
+
});
|
|
527
548
|
return updatedUser;
|
|
528
549
|
},
|
|
529
550
|
updateLastContact: async (_id, lastContact) => {
|
|
530
551
|
const userFilter = generateDbFilterById(_id);
|
|
531
552
|
const user = await Users.findOne(userFilter, {});
|
|
553
|
+
if (!user)
|
|
554
|
+
return null;
|
|
532
555
|
const profile = user.profile || {};
|
|
533
556
|
const isGuest = !!user.guest;
|
|
534
557
|
const modifier = {
|
|
@@ -544,6 +567,8 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
544
567
|
const updatedUser = await Users.findOneAndUpdate(userFilter, modifier, {
|
|
545
568
|
returnDocument: 'after',
|
|
546
569
|
});
|
|
570
|
+
if (!updatedUser)
|
|
571
|
+
return null;
|
|
547
572
|
await emit('USER_UPDATE_LAST_CONTACT', {
|
|
548
573
|
user: removeConfidentialServiceHashes(user),
|
|
549
574
|
});
|
|
@@ -559,21 +584,24 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
559
584
|
const user = await Users.findOneAndUpdate(generateDbFilterById(_id), modifier, {
|
|
560
585
|
returnDocument: 'after',
|
|
561
586
|
});
|
|
587
|
+
if (!user)
|
|
588
|
+
return null;
|
|
562
589
|
await emit('USER_UPDATE_ROLE', {
|
|
563
590
|
user: removeConfidentialServiceHashes(user),
|
|
564
591
|
});
|
|
565
592
|
return user;
|
|
566
593
|
},
|
|
567
594
|
updateTags: async (_id, tags) => {
|
|
568
|
-
const
|
|
595
|
+
const user = await Users.findOneAndUpdate(generateDbFilterById(_id), {
|
|
569
596
|
$set: {
|
|
570
597
|
updated: new Date(),
|
|
571
598
|
tags,
|
|
572
599
|
},
|
|
573
|
-
}
|
|
574
|
-
const user = await Users.findOneAndUpdate(generateDbFilterById(_id), modifier, {
|
|
600
|
+
}, {
|
|
575
601
|
returnDocument: 'after',
|
|
576
602
|
});
|
|
603
|
+
if (!user)
|
|
604
|
+
return null;
|
|
577
605
|
await emit('USER_UPDATE_TAGS', {
|
|
578
606
|
user: removeConfidentialServiceHashes(user),
|
|
579
607
|
});
|
|
@@ -584,6 +612,8 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
584
612
|
...updateOptions,
|
|
585
613
|
returnDocument: 'after',
|
|
586
614
|
});
|
|
615
|
+
if (!user)
|
|
616
|
+
return null;
|
|
587
617
|
await emit('USER_UPDATE', {
|
|
588
618
|
user: removeConfidentialServiceHashes(user),
|
|
589
619
|
});
|
|
@@ -618,10 +648,7 @@ export const configureUsersModule = async ({ db, options }) => {
|
|
|
618
648
|
tags: { $exists: true },
|
|
619
649
|
deleted: { $exists: false },
|
|
620
650
|
}));
|
|
621
|
-
return tags
|
|
622
|
-
.filter(Boolean)
|
|
623
|
-
.map((t) => t.trim())
|
|
624
|
-
.filter(Boolean);
|
|
651
|
+
return tags.filter(Boolean).toSorted();
|
|
625
652
|
},
|
|
626
653
|
};
|
|
627
654
|
};
|