@unchainedshop/core-users 3.0.0-alpha7 → 3.0.0-rc2

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 (64) hide show
  1. package/lib/db/UsersCollection.d.ts +54 -2
  2. package/lib/db/UsersCollection.d.ts.map +1 -1
  3. package/lib/db/UsersCollection.js.map +1 -1
  4. package/lib/db/WebAuthnCredentialsCreationRequestsCollection.d.ts +6 -1
  5. package/lib/db/WebAuthnCredentialsCreationRequestsCollection.d.ts.map +1 -1
  6. package/lib/db/WebAuthnCredentialsCreationRequestsCollection.js.map +1 -1
  7. package/lib/module/configureUsersModule.d.ts +22 -70
  8. package/lib/module/configureUsersModule.d.ts.map +1 -1
  9. package/lib/module/configureUsersModule.js +59 -54
  10. package/lib/module/configureUsersModule.js.map +1 -1
  11. package/lib/module/configureUsersModule_BACKUP_57123.d.ts +73 -0
  12. package/lib/module/configureUsersModule_BACKUP_57123.d.ts.map +1 -0
  13. package/lib/module/configureUsersModule_BACKUP_57123.js +567 -0
  14. package/lib/module/configureUsersModule_BACKUP_57123.js.map +1 -0
  15. package/lib/module/configureUsersModule_BASE_57123.d.ts +131 -0
  16. package/lib/module/configureUsersModule_BASE_57123.d.ts.map +1 -0
  17. package/lib/module/configureUsersModule_BASE_57123.js +563 -0
  18. package/lib/module/configureUsersModule_BASE_57123.js.map +1 -0
  19. package/lib/module/configureUsersModule_LOCAL_57123.d.ts +131 -0
  20. package/lib/module/configureUsersModule_LOCAL_57123.d.ts.map +1 -0
  21. package/lib/module/configureUsersModule_LOCAL_57123.js +564 -0
  22. package/lib/module/configureUsersModule_LOCAL_57123.js.map +1 -0
  23. package/lib/module/configureUsersModule_REMOTE_57123.d.ts +74 -0
  24. package/lib/module/configureUsersModule_REMOTE_57123.d.ts.map +1 -0
  25. package/lib/module/configureUsersModule_REMOTE_57123.js +567 -0
  26. package/lib/module/configureUsersModule_REMOTE_57123.js.map +1 -0
  27. package/lib/module/configureUsersWebAuthnModule.d.ts.map +1 -1
  28. package/lib/module/configureUsersWebAuthnModule.js.map +1 -1
  29. package/lib/types.d.ts +5 -2
  30. package/lib/types.d.ts.map +1 -1
  31. package/lib/users-index.d.ts +3 -2
  32. package/lib/users-index.d.ts.map +1 -1
  33. package/lib/users-index.js +3 -2
  34. package/lib/users-index.js.map +1 -1
  35. package/lib/users-settings.d.ts +1 -1
  36. package/lib/users-settings.d.ts.map +1 -1
  37. package/lib/users-settings.js.map +1 -1
  38. package/package.json +14 -17
  39. package/src/db/UsersCollection.ts +59 -2
  40. package/src/db/WebAuthnCredentialsCreationRequestsCollection.ts +7 -1
  41. package/src/module/configureUsersModule.ts +100 -75
  42. package/src/module/configureUsersWebAuthnModule.ts +0 -1
  43. package/src/module/removeConfidentialServiceHashes.test.ts +1 -1
  44. package/src/users-index.ts +3 -2
  45. package/src/users-settings.ts +1 -2
  46. package/tests/mock/user-mock.ts +2 -3
  47. package/tsconfig.json +5 -7
  48. package/lib/services/migrateUserDataService.d.ts +0 -4
  49. package/lib/services/migrateUserDataService.d.ts.map +0 -1
  50. package/lib/services/migrateUserDataService.js +0 -18
  51. package/lib/services/migrateUserDataService.js.map +0 -1
  52. package/lib/services/updateUserAvatarAfterUploadService.d.ts +0 -15
  53. package/lib/services/updateUserAvatarAfterUploadService.d.ts.map +0 -1
  54. package/lib/services/updateUserAvatarAfterUploadService.js +0 -24
  55. package/lib/services/updateUserAvatarAfterUploadService.js.map +0 -1
  56. package/lib/services/userServices.d.ts +0 -8
  57. package/lib/services/userServices.d.ts.map +0 -1
  58. package/lib/services/userServices.js +0 -7
  59. package/lib/services/userServices.js.map +0 -1
  60. package/src/module/sha256.ts +0 -5
  61. package/src/services/migrateUserDataService.ts +0 -37
  62. package/src/services/updateUserAvatarAfterUploadService.ts +0 -42
  63. package/src/services/userServices.ts +0 -15
  64. package/src/types.ts +0 -101
@@ -1,15 +0,0 @@
1
- import { File, FileServices, FilesModule } from '@unchainedshop/core-files';
2
- import { UsersModule } from '../users-index.js';
3
- export type UpdateUserAvatarAfterUploadService = (params: {
4
- file: File;
5
- }, context: {
6
- modules: {
7
- files: FilesModule;
8
- users: UsersModule;
9
- };
10
- services: {
11
- files: FileServices;
12
- };
13
- }) => Promise<void>;
14
- export declare const updateUserAvatarAfterUploadService: UpdateUserAvatarAfterUploadService;
15
- //# sourceMappingURL=updateUserAvatarAfterUploadService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updateUserAvatarAfterUploadService.d.ts","sourceRoot":"","sources":["../../src/services/updateUserAvatarAfterUploadService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE5E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,kCAAkC,GAAG,CAC/C,MAAM,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,EACtB,OAAO,EAAE;IACP,OAAO,EAAE;QAAE,KAAK,EAAE,WAAW,CAAC;QAAC,KAAK,EAAE,WAAW,CAAA;KAAE,CAAC;IACpD,QAAQ,EAAE;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC;CACnC,KACE,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,eAAO,MAAM,kCAAkC,EAAE,kCA6BhD,CAAC"}
@@ -1,24 +0,0 @@
1
- import { log, LogLevel } from '@unchainedshop/logger';
2
- export const updateUserAvatarAfterUploadService = async ({ file }, context) => {
3
- const { modules, services } = context;
4
- const { userId } = file.meta;
5
- const files = await modules.files.findFiles({
6
- _id: { $ne: file._id },
7
- path: file.path,
8
- 'meta.userId': userId,
9
- });
10
- const fileIds = files.map((f) => f._id);
11
- try {
12
- if (fileIds?.length) {
13
- await services.files.removeFiles({
14
- fileIds,
15
- }, context);
16
- }
17
- }
18
- catch (e) {
19
- // cleanup error, not critical
20
- log(`could not clean up all old avatars: ${e.message}`, { level: LogLevel.Warning });
21
- }
22
- await modules.users.updateAvatar(userId, file._id);
23
- };
24
- //# sourceMappingURL=updateUserAvatarAfterUploadService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updateUserAvatarAfterUploadService.js","sourceRoot":"","sources":["../../src/services/updateUserAvatarAfterUploadService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAWtD,MAAM,CAAC,MAAM,kCAAkC,GAAuC,KAAK,EACzF,EAAE,IAAI,EAAE,EACR,OAAO,EACP,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACtC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,IAA0B,CAAC;IAEnD,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC;QAC1C,GAAG,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;QACtB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,aAAa,EAAE,MAAM;KACtB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAExC,IAAI,CAAC;QACH,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;YACpB,MAAM,QAAQ,CAAC,KAAK,CAAC,WAAW,CAC9B;gBACE,OAAO;aACR,EACD,OAAO,CACR,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,CAAU,EAAE,CAAC;QACpB,8BAA8B;QAC9B,GAAG,CAAC,uCAAwC,CAAW,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IAClG,CAAC;IAED,MAAM,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AACrD,CAAC,CAAC"}
@@ -1,8 +0,0 @@
1
- import { UpdateUserAvatarAfterUploadService } from './updateUserAvatarAfterUploadService.js';
2
- import { MigrateUserDataService } from './migrateUserDataService.js';
3
- export interface UserServices {
4
- updateUserAvatarAfterUpload: UpdateUserAvatarAfterUploadService;
5
- migrateUserData: MigrateUserDataService;
6
- }
7
- export declare const userServices: UserServices;
8
- //# sourceMappingURL=userServices.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userServices.d.ts","sourceRoot":"","sources":["../../src/services/userServices.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kCAAkC,EACnC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAA0B,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE7F,MAAM,WAAW,YAAY;IAC3B,2BAA2B,EAAE,kCAAkC,CAAC;IAChE,eAAe,EAAE,sBAAsB,CAAC;CACzC;AAED,eAAO,MAAM,YAAY,EAAE,YAG1B,CAAC"}
@@ -1,7 +0,0 @@
1
- import { updateUserAvatarAfterUploadService, } from './updateUserAvatarAfterUploadService.js';
2
- import { migrateUserDataService } from './migrateUserDataService.js';
3
- export const userServices = {
4
- updateUserAvatarAfterUpload: updateUserAvatarAfterUploadService,
5
- migrateUserData: migrateUserDataService,
6
- };
7
- //# sourceMappingURL=userServices.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userServices.js","sourceRoot":"","sources":["../../src/services/userServices.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,GAEnC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAA0B,MAAM,6BAA6B,CAAC;AAO7F,MAAM,CAAC,MAAM,YAAY,GAAiB;IACxC,2BAA2B,EAAE,kCAAkC;IAC/D,eAAe,EAAE,sBAAsB;CACxC,CAAC"}
@@ -1,5 +0,0 @@
1
- export const hash = async (message) => {
2
- const bytes = new TextEncoder().encode(message);
3
- const hashBuffer = await crypto.subtle.digest('SHA-256', bytes);
4
- return Buffer.from(hashBuffer).toString('hex');
5
- };
@@ -1,37 +0,0 @@
1
- import { UnchainedCore } from '@unchainedshop/core';
2
- import { userSettings } from '../users-settings.js';
3
-
4
- export type MigrateUserDataService = (
5
- userIdBeforeLogin,
6
- userId,
7
- unchainedAPI: UnchainedCore,
8
- ) => Promise<void>;
9
-
10
- export const migrateUserDataService: MigrateUserDataService = async (
11
- userIdBeforeLogin,
12
- userId,
13
- unchainedAPI,
14
- ) => {
15
- const user = await unchainedAPI.modules.users.findUserById(userId);
16
- const userBeforeLogin = await unchainedAPI.modules.users.findUserById(userIdBeforeLogin);
17
-
18
- await unchainedAPI.services.orders.migrateOrderCarts(
19
- {
20
- fromUserId: userIdBeforeLogin,
21
- toUserId: userId,
22
- shouldMerge: userSettings.mergeUserCartsOnLogin,
23
- countryContext: userBeforeLogin.lastLogin?.countryCode || user.lastLogin?.countryCode,
24
- },
25
- unchainedAPI,
26
- );
27
-
28
- await unchainedAPI.services.bookmarks.migrateBookmarks(
29
- {
30
- fromUserId: userIdBeforeLogin,
31
- toUserId: userId,
32
- shouldMerge: userSettings.mergeUserCartsOnLogin,
33
- countryContext: userBeforeLogin.lastLogin?.countryCode || user.lastLogin?.countryCode,
34
- },
35
- unchainedAPI,
36
- );
37
- };
@@ -1,42 +0,0 @@
1
- import { File, FileServices, FilesModule } from '@unchainedshop/core-files';
2
- import { log, LogLevel } from '@unchainedshop/logger';
3
- import { UsersModule } from '../users-index.js';
4
-
5
- export type UpdateUserAvatarAfterUploadService = (
6
- params: { file: File },
7
- context: {
8
- modules: { files: FilesModule; users: UsersModule };
9
- services: { files: FileServices };
10
- },
11
- ) => Promise<void>;
12
-
13
- export const updateUserAvatarAfterUploadService: UpdateUserAvatarAfterUploadService = async (
14
- { file },
15
- context,
16
- ) => {
17
- const { modules, services } = context;
18
- const { userId } = file.meta as { userId: string };
19
-
20
- const files = await modules.files.findFiles({
21
- _id: { $ne: file._id },
22
- path: file.path,
23
- 'meta.userId': userId,
24
- });
25
- const fileIds = files.map((f) => f._id);
26
-
27
- try {
28
- if (fileIds?.length) {
29
- await services.files.removeFiles(
30
- {
31
- fileIds,
32
- },
33
- context,
34
- );
35
- }
36
- } catch (e: unknown) {
37
- // cleanup error, not critical
38
- log(`could not clean up all old avatars: ${(e as Error).message}`, { level: LogLevel.Warning });
39
- }
40
-
41
- await modules.users.updateAvatar(userId, file._id);
42
- };
@@ -1,15 +0,0 @@
1
- import {
2
- updateUserAvatarAfterUploadService,
3
- UpdateUserAvatarAfterUploadService,
4
- } from './updateUserAvatarAfterUploadService.js';
5
- import { migrateUserDataService, MigrateUserDataService } from './migrateUserDataService.js';
6
-
7
- export interface UserServices {
8
- updateUserAvatarAfterUpload: UpdateUserAvatarAfterUploadService;
9
- migrateUserData: MigrateUserDataService;
10
- }
11
-
12
- export const userServices: UserServices = {
13
- updateUserAvatarAfterUpload: updateUserAvatarAfterUploadService,
14
- migrateUserData: migrateUserDataService,
15
- };
package/src/types.ts DELETED
@@ -1,101 +0,0 @@
1
- import type { TimestampFields, Address, Contact, mongodb } from '@unchainedshop/mongodb';
2
-
3
- export interface PushSubscription {
4
- _id: string;
5
- userAgent: string;
6
- expirationTime: number;
7
- endpoint: string;
8
- }
9
-
10
- export interface UserProfile {
11
- displayName?: string;
12
- birthday?: Date;
13
- phoneMobile?: string;
14
- gender?: string;
15
- address?: Address;
16
- }
17
-
18
- export interface UserLastLogin {
19
- timestamp?: Date;
20
- locale?: string;
21
- countryCode?: string;
22
- remoteAddress?: string;
23
- remotePort?: string;
24
- userAgent?: string;
25
- }
26
-
27
- export interface Email {
28
- address: string;
29
- verified: boolean;
30
- }
31
-
32
- export interface WebAuthnCredentials {
33
- id: string;
34
- publicKey: string;
35
- created: Date;
36
- aaguid: string;
37
- counter: number;
38
- mdsMetadata: any;
39
- }
40
-
41
- export interface Web3Address {
42
- address: string;
43
- nonce?: number;
44
- verified: boolean;
45
- }
46
-
47
- export interface PushSubscriptionObject {
48
- userAgent: string;
49
- endpoint: string;
50
- expirationTime?: number;
51
- keys: {
52
- auth: string;
53
- p256dh: string;
54
- };
55
- }
56
-
57
- export type User = {
58
- _id?: string;
59
- deleted?: Date;
60
- avatarId?: string;
61
- emails: Array<Email>;
62
- guest: boolean;
63
- initialPassword: boolean;
64
- lastBillingAddress?: Address;
65
- lastContact?: Contact;
66
- lastLogin?: UserLastLogin;
67
- profile?: UserProfile;
68
- roles: Array<string>;
69
- services: any;
70
- tags?: Array<string>;
71
- pushSubscriptions: Array<PushSubscriptionObject>;
72
- username?: string;
73
- meta?: any;
74
- } & TimestampFields;
75
-
76
- export type UserQuery = mongodb.Filter<User> & {
77
- includeGuests?: boolean;
78
- queryString?: string;
79
- };
80
-
81
- export interface WebAuthnCredentialsCreationRequest {
82
- challenge: string;
83
- username: string;
84
- origin: string;
85
- factor: 'first' | 'second' | 'either';
86
- }
87
-
88
- /*
89
- * Module
90
- */
91
- export interface UserData {
92
- email?: string;
93
- guest?: boolean;
94
- initialPassword?: boolean;
95
- lastBillingAddress?: User['lastBillingAddress'];
96
- password: string | null;
97
- webAuthnPublicKeyCredentials?: any;
98
- profile?: UserProfile;
99
- roles?: Array<string>;
100
- username?: string;
101
- }