@unchainedshop/platform 2.13.0 → 3.0.0-alpha2

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 (51) hide show
  1. package/lib/bulk-importer/handlers/assortment/create.d.ts.map +1 -1
  2. package/lib/bulk-importer/handlers/assortment/create.js +9 -7
  3. package/lib/bulk-importer/handlers/assortment/create.js.map +1 -1
  4. package/lib/bulk-importer/handlers/assortment/update.d.ts.map +1 -1
  5. package/lib/bulk-importer/handlers/assortment/update.js.map +1 -1
  6. package/lib/bulk-importer/handlers/filter/create.d.ts.map +1 -1
  7. package/lib/bulk-importer/handlers/filter/create.js +10 -6
  8. package/lib/bulk-importer/handlers/filter/create.js.map +1 -1
  9. package/lib/bulk-importer/handlers/filter/update.d.ts.map +1 -1
  10. package/lib/bulk-importer/handlers/filter/update.js +10 -6
  11. package/lib/bulk-importer/handlers/filter/update.js.map +1 -1
  12. package/lib/bulk-importer/handlers/product/create.d.ts.map +1 -1
  13. package/lib/bulk-importer/handlers/product/create.js +9 -7
  14. package/lib/bulk-importer/handlers/product/create.js.map +1 -1
  15. package/lib/bulk-importer/handlers/product/upsertVariations.d.ts.map +1 -1
  16. package/lib/bulk-importer/handlers/product/upsertVariations.js +17 -11
  17. package/lib/bulk-importer/handlers/product/upsertVariations.js.map +1 -1
  18. package/lib/context/index.d.ts +0 -1
  19. package/lib/context/index.d.ts.map +1 -1
  20. package/lib/context/index.js +0 -1
  21. package/lib/context/index.js.map +1 -1
  22. package/lib/context/setAccessToken.d.ts +1 -1
  23. package/lib/context/setAccessToken.d.ts.map +1 -1
  24. package/lib/context/setAccessToken.js +3 -1
  25. package/lib/context/setAccessToken.js.map +1 -1
  26. package/lib/platform-index.d.ts +4 -4
  27. package/lib/platform-index.d.ts.map +1 -1
  28. package/lib/setup/setupAccounts.d.ts +1 -1
  29. package/lib/setup/setupAccounts.d.ts.map +1 -1
  30. package/lib/setup/setupAccounts.js +8 -160
  31. package/lib/setup/setupAccounts.js.map +1 -1
  32. package/lib/startPlatform.d.ts +6 -9
  33. package/lib/startPlatform.d.ts.map +1 -1
  34. package/lib/startPlatform.js +4 -10
  35. package/lib/startPlatform.js.map +1 -1
  36. package/package.json +11 -11
  37. package/src/bulk-importer/handlers/assortment/create.ts +12 -10
  38. package/src/bulk-importer/handlers/assortment/update.ts +1 -0
  39. package/src/bulk-importer/handlers/filter/create.ts +13 -11
  40. package/src/bulk-importer/handlers/filter/update.ts +13 -11
  41. package/src/bulk-importer/handlers/product/create.ts +12 -10
  42. package/src/bulk-importer/handlers/product/upsertVariations.ts +24 -20
  43. package/src/context/index.ts +0 -1
  44. package/src/context/setAccessToken.ts +8 -1
  45. package/src/setup/setupAccounts.ts +8 -237
  46. package/src/startPlatform.ts +10 -25
  47. package/lib/context/withAccessToken.d.ts +0 -4
  48. package/lib/context/withAccessToken.d.ts.map +0 -1
  49. package/lib/context/withAccessToken.js +0 -37
  50. package/lib/context/withAccessToken.js.map +0 -1
  51. package/src/context/withAccessToken.ts +0 -40
@@ -1,40 +0,0 @@
1
- import { createLogger } from '@unchainedshop/logger';
2
- import { Context } from '@unchainedshop/types/api.js';
3
- import { timingSafeEqual } from 'crypto';
4
-
5
- const logger = createLogger('unchained:platform');
6
-
7
- const contextIdentity = (params) => params;
8
-
9
- export default (fn: (context: Context) => any = contextIdentity): any => {
10
- return async (params, unchainedContextFn) => {
11
- const unchainedContext = await unchainedContextFn(params);
12
- const newContext = {
13
- userId: unchainedContext.userId,
14
- user: unchainedContext.user,
15
- };
16
- if (!unchainedContext.userId && params.req.headers.authorization) {
17
- const [type, userToken] = params.req.headers.authorization.split(' ');
18
- if (type === 'Bearer' && userToken) {
19
- const [username, secret] = userToken.split(':');
20
- const user = await unchainedContext.modules.users.findUser({
21
- username,
22
- });
23
-
24
- if (secret && user?.services.token?.secret) {
25
- if (timingSafeEqual(Buffer.from(secret), Buffer.from(user?.services.token?.secret))) {
26
- newContext.userId = user._id;
27
- newContext.user = user;
28
- logger.debug('Token login success');
29
- } else {
30
- logger.warn('Token login failed');
31
- }
32
- }
33
- }
34
- }
35
- return fn({
36
- ...unchainedContext,
37
- ...newContext,
38
- });
39
- };
40
- };