@unchainedshop/core-users 3.0.1 → 3.1.1

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.
@@ -0,0 +1,3 @@
1
+ import { GetUserCountryService } from '@unchainedshop/types/user.js';
2
+ export declare const getUserCountryService: GetUserCountryService;
3
+ //# sourceMappingURL=getUserCountryService.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,3 @@
1
+ import { GetUserLanguageService } from '@unchainedshop/types/user.js';
2
+ export declare const getUserLanguageService: GetUserLanguageService;
3
+ //# sourceMappingURL=getUserLanguageService.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,3 @@
1
+ import { UpdateUserAvatarAfterUploadService } from '@unchainedshop/types/user.js';
2
+ export declare const updateUserAvatarAfterUploadService: UpdateUserAvatarAfterUploadService;
3
+ //# sourceMappingURL=updateUserAvatarAfterUploadService.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,24 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,3 @@
1
+ import { UserServices } from '@unchainedshop/types/user.js';
2
+ export declare const userServices: UserServices;
3
+ //# sourceMappingURL=userServices.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,9 @@
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
@@ -0,0 +1 @@
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-users",
3
- "version": "3.0.1",
3
+ "version": "3.1.1",
4
4
  "main": "lib/users-index.js",
5
5
  "types": "lib/users-index.d.ts",
6
6
  "type": "module",
@@ -32,12 +32,12 @@
32
32
  "homepage": "https://github.com/unchainedshop/unchained#readme",
33
33
  "dependencies": {
34
34
  "@node-rs/bcrypt": "^1.10.7",
35
- "@unchainedshop/events": "^3.0.0",
36
- "@unchainedshop/file-upload": "^3.0.0",
37
- "@unchainedshop/logger": "^3.0.0",
38
- "@unchainedshop/mongodb": "^3.0.0",
39
- "@unchainedshop/roles": "^3.0.0",
40
- "@unchainedshop/utils": "^3.0.0"
35
+ "@unchainedshop/events": "^3.1.0",
36
+ "@unchainedshop/file-upload": "^3.1.0",
37
+ "@unchainedshop/logger": "^3.1.0",
38
+ "@unchainedshop/mongodb": "^3.1.0",
39
+ "@unchainedshop/roles": "^3.1.0",
40
+ "@unchainedshop/utils": "^3.1.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "fido2-lib": ">= 3.5 < 4"
@@ -48,7 +48,7 @@
48
48
  }
49
49
  },
50
50
  "devDependencies": {
51
- "@types/node": "^22.10.5",
51
+ "@types/node": "^22.13.4",
52
52
  "fido2-lib": "^3.5.3",
53
53
  "jest": "^29.7.0",
54
54
  "ts-jest": "^29.2.5",