@unchainedshop/core-users 4.3.4 → 4.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-users",
3
- "version": "4.3.4",
3
+ "version": "4.3.5",
4
4
  "main": "lib/users-index.js",
5
5
  "types": "lib/users-index.d.ts",
6
6
  "type": "module",
@@ -1,3 +0,0 @@
1
- import { Migration, MigrationRepository } from '@unchainedshop/types/core.js';
2
- export default function addMigrations(repository: MigrationRepository<Migration>): void;
3
- //# sourceMappingURL=addMigrations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addMigrations.d.ts","sourceRoot":"","sources":["../../src/module/addMigrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAsB9E,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,UAAU,EAAE,mBAAmB,CAAC,SAAS,CAAC,QAkD/E"}
@@ -1,57 +0,0 @@
1
- import { UsersCollection } from '../db/UsersCollection.js';
2
- const convertTagsToLowerCase = async (collection) => {
3
- let bulk = collection.initializeUnorderedBulkOp();
4
- let count = 0;
5
- const cursor = await collection.find({ tags: { $regex: '.*[A-Z]' } });
6
- // eslint-disable-next-line no-restricted-syntax
7
- for await (const doc of cursor) {
8
- const transformedTags = doc.tags.map((tag) => tag.toLowerCase());
9
- count += 1;
10
- bulk.find({ _id: doc._id }).updateOne({ $set: { tags: transformedTags } });
11
- if (count % 500 === 0) {
12
- bulk.execute();
13
- bulk = collection.initializeUnorderedBulkOp();
14
- count = 0;
15
- }
16
- }
17
- if (count > 0)
18
- bulk.execute();
19
- };
20
- export default function addMigrations(repository) {
21
- repository?.register({
22
- id: 20220603115000,
23
- name: 'Copy user.profile.customFields to user.meta',
24
- up: async () => {
25
- const Users = await UsersCollection(repository.db);
26
- const users = await Users.find({ meta: { $exists: false }, 'profile.customFields': { $exists: true } }, { projection: { _id: true, profile: true, meta: true } }).toArray();
27
- await Promise.all(users.map(async (user) => {
28
- await Users.updateOne({
29
- _id: user._id,
30
- }, {
31
- $set: { meta: user.profile.customFields },
32
- });
33
- }));
34
- },
35
- });
36
- repository?.register({
37
- id: 20220920122500,
38
- name: 'Convert user tags to lower case for easy search',
39
- up: async () => {
40
- const Users = await UsersCollection(repository.db);
41
- await convertTagsToLowerCase(Users);
42
- },
43
- });
44
- repository?.register({
45
- id: 20230719105000,
46
- name: 'Rename user.lastLogin.countryContext to user.lastLogin.countryCode',
47
- up: async () => {
48
- const Users = await UsersCollection(repository.db);
49
- await Users.updateMany({
50
- 'lastLogin.countryContext': { $exists: true },
51
- }, {
52
- $rename: { 'lastLogin.countryContext': 'lastLogin.countryCode' },
53
- });
54
- },
55
- });
56
- }
57
- //# sourceMappingURL=addMigrations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addMigrations.js","sourceRoot":"","sources":["../../src/module/addMigrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,sBAAsB,GAAG,KAAK,EAAE,UAAuD,EAAE,EAAE;IAC/F,IAAI,IAAI,GAAG,UAAU,CAAC,yBAAyB,EAAE,CAAC;IAClD,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IACtE,gDAAgD;IAChD,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QAC/B,MAAM,eAAe,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QACjE,KAAK,IAAI,CAAC,CAAC;QACX,IAAI,CAAC,IAAI,CAA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,CACH,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,UAAU,EAAE,QAAQ,CAAC;QACnB,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,iDAAiD;QACvD,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACnD,MAAM,sBAAsB,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;KACF,CAAC,CAAC;IAEH,UAAU,EAAE,QAAQ,CAAC;QACnB,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,oEAAoE;QAC1E,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACnD,MAAM,KAAK,CAAC,UAAU,CACpB;gBACE,0BAA0B,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aAC9C,EACD;gBACE,OAAO,EAAE,EAAE,0BAA0B,EAAE,uBAAuB,EAAE;aACjE,CACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -1,3 +0,0 @@
1
- import { GetUserCountryService } from '@unchainedshop/types/user.js';
2
- export declare const getUserCountryService: GetUserCountryService;
3
- //# sourceMappingURL=getUserCountryService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getUserCountryService.d.ts","sourceRoot":"","sources":["../../src/services/getUserCountryService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,eAAO,MAAM,qBAAqB,EAAE,qBAKnC,CAAC"}
@@ -1,7 +0,0 @@
1
- export const getUserCountryService = async (user, { modules }) => {
2
- const userLocale = modules.users.userLocale(user);
3
- return modules.countries.findCountry({
4
- isoCode: userLocale.country.toUpperCase(),
5
- });
6
- };
7
- //# sourceMappingURL=getUserCountryService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getUserCountryService.js","sourceRoot":"","sources":["../../src/services/getUserCountryService.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAA0B,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;IACtF,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC;QACnC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE;KAC1C,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { GetUserLanguageService } from '@unchainedshop/types/user.js';
2
- export declare const getUserLanguageService: GetUserLanguageService;
3
- //# sourceMappingURL=getUserLanguageService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getUserLanguageService.d.ts","sourceRoot":"","sources":["../../src/services/getUserLanguageService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,eAAO,MAAM,sBAAsB,EAAE,sBAKpC,CAAC"}
@@ -1,7 +0,0 @@
1
- export const getUserLanguageService = async (user, { modules }) => {
2
- const userLocale = modules.users.userLocale(user);
3
- return modules.languages.findLanguage({
4
- isoCode: userLocale.language,
5
- });
6
- };
7
- //# sourceMappingURL=getUserLanguageService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getUserLanguageService.js","sourceRoot":"","sources":["../../src/services/getUserLanguageService.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAA2B,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;IACxF,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC;QACpC,OAAO,EAAE,UAAU,CAAC,QAAQ;KAC7B,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { UpdateUserAvatarAfterUploadService } from '@unchainedshop/types/user.js';
2
- export declare const updateUserAvatarAfterUploadService: UpdateUserAvatarAfterUploadService;
3
- //# 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,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAGlF,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;AAEtD,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,3 +0,0 @@
1
- import { UserServices } from '@unchainedshop/types/user.js';
2
- export declare const userServices: UserServices;
3
- //# 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,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAK5D,eAAO,MAAM,YAAY,EAAE,YAI1B,CAAC"}
@@ -1,9 +0,0 @@
1
- import { getUserCountryService } from './getUserCountryService.js';
2
- import { getUserLanguageService } from './getUserLanguageService.js';
3
- import { updateUserAvatarAfterUploadService } from './updateUserAvatarAfterUploadService.js';
4
- export const userServices = {
5
- getUserCountry: getUserCountryService,
6
- getUserLanguage: getUserLanguageService,
7
- updateUserAvatarAfterUpload: updateUserAvatarAfterUploadService,
8
- };
9
- //# sourceMappingURL=userServices.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userServices.js","sourceRoot":"","sources":["../../src/services/userServices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,kCAAkC,EAAE,MAAM,yCAAyC,CAAC;AAE7F,MAAM,CAAC,MAAM,YAAY,GAAiB;IACxC,cAAc,EAAE,qBAAqB;IACrC,eAAe,EAAE,sBAAsB;IACvC,2BAA2B,EAAE,kCAAkC;CAChE,CAAC"}