@unchainedshop/platform 4.0.0-rc.4 → 4.0.0-rc.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/platform",
3
- "version": "4.0.0-rc.4",
3
+ "version": "4.0.0-rc.5",
4
4
  "main": "lib/platform-index.js",
5
5
  "types": "lib/platform-index.d.ts",
6
6
  "type": "module",
@@ -1,4 +0,0 @@
1
- import { Context } from '@unchainedshop/types/api.js';
2
- declare const _default: (fn?: (context: Context) => any) => any;
3
- export default _default;
4
- //# sourceMappingURL=withAccessToken.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withAccessToken.d.ts","sourceRoot":"","sources":["../../src/context/withAccessToken.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;8BAOlC,CAAC,OAAO,EAAE,OAAO,KAAK,GAAG,KAAqB,GAAG;AAArE,wBAmCE"}
@@ -1,42 +0,0 @@
1
- import { createLogger } from '@unchainedshop/logger';
2
- import { timingSafeEqual } from 'crypto';
3
- const logger = createLogger('unchained:platform');
4
- const contextIdentity = (params) => params;
5
- export default (fn = contextIdentity) => {
6
- return async (params, unchainedContextFn) => {
7
- const unchainedContext = await unchainedContextFn(params);
8
- const newContext = {
9
- userId: unchainedContext.userId,
10
- user: unchainedContext.user,
11
- };
12
- if (!unchainedContext.userId && params.req.headers.authorization) {
13
- const [type, userToken] = params.req.headers.authorization.split(' ');
14
- if (type === 'Bearer' && userToken) {
15
- const [username, secret] = userToken.split(':');
16
- const user = await unchainedContext.modules.users.findUser({
17
- username,
18
- });
19
- if (secret && user?.services.token?.secret) {
20
- try {
21
- if (timingSafeEqual(Buffer.from(secret), Buffer.from(user?.services.token?.secret))) {
22
- newContext.userId = user._id;
23
- newContext.user = user;
24
- logger.debug('Token login success');
25
- }
26
- else {
27
- throw new Error('Access Token not valid');
28
- }
29
- }
30
- catch (e) {
31
- logger.warn(`Token login failed: ${e.message}`);
32
- }
33
- }
34
- }
35
- }
36
- return fn({
37
- ...unchainedContext,
38
- ...newContext,
39
- });
40
- };
41
- };
42
- //# sourceMappingURL=withAccessToken.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withAccessToken.js","sourceRoot":"","sources":["../../src/context/withAccessToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,MAAM,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC;AAElD,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;AAE3C,eAAe,CAAC,KAAgC,eAAe,EAAO,EAAE;IACtE,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAAE;QAC1C,MAAM,gBAAgB,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAC1D,MAAM,UAAU,GAAG;YACjB,MAAM,EAAE,gBAAgB,CAAC,MAAM;YAC/B,IAAI,EAAE,gBAAgB,CAAC,IAAI;SAC5B,CAAC;QACF,IAAI,CAAC,gBAAgB,CAAC,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YACjE,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACtE,IAAI,IAAI,KAAK,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACnC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAChD,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;oBACzD,QAAQ;iBACT,CAAC,CAAC;gBAEH,IAAI,MAAM,IAAI,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;oBAC3C,IAAI,CAAC;wBACH,IAAI,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;4BACpF,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;4BAC7B,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC;4BACvB,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;wBACtC,CAAC;6BAAM,CAAC;4BACN,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;wBAC5C,CAAC;oBACH,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBACX,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;oBAClD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC;YACR,GAAG,gBAAgB;YACnB,GAAG,UAAU;SACd,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,8 +0,0 @@
1
- import { UnchainedCore } from '@unchainedshop/core';
2
- export interface SetupCartsOptions {
3
- invalidateProviders?: boolean;
4
- providerInvalidationMaxAgeDays?: number;
5
- assignCartForUsers?: boolean;
6
- }
7
- export declare const setupCarts: (unchainedAPI: UnchainedCore, options?: SetupCartsOptions) => Promise<void>;
8
- //# sourceMappingURL=setupCarts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setupCarts.d.ts","sourceRoot":"","sources":["../../src/setup/setupCarts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,8BAA8B,CAAC,EAAE,MAAM,CAAC;IACxC,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAGD,eAAO,MAAM,UAAU,GAAU,cAAc,aAAa,EAAE,UAAS,iBAAsB,kBAyB5F,CAAC"}
@@ -1,20 +0,0 @@
1
- const { UNCHAINED_DISABLE_PROVIDER_INVALIDATION, UNCHAINED_ASSIGN_CART_FOR_USERS } = process.env;
2
- export const setupCarts = async (unchainedAPI, options = {}) => {
3
- if (options.invalidateProviders ?? !UNCHAINED_DISABLE_PROVIDER_INVALIDATION) {
4
- const orders = await unchainedAPI.modules.orders.findCartsToInvalidate(options.providerInvalidationMaxAgeDays);
5
- await Promise.allSettled(orders.map(async (order) => {
6
- await unchainedAPI.services.orders.updateCalculation(order._id);
7
- }));
8
- }
9
- if (options.assignCartForUsers ?? Boolean(UNCHAINED_ASSIGN_CART_FOR_USERS)) {
10
- const users = await unchainedAPI.modules.users.findUsers({});
11
- await Promise.all(users.map((user) => {
12
- const locale = unchainedAPI.modules.users.userLocale(user);
13
- return unchainedAPI.services.orders.nextUserCart({
14
- user,
15
- countryCode: locale.region,
16
- });
17
- }));
18
- }
19
- };
20
- //# sourceMappingURL=setupCarts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setupCarts.js","sourceRoot":"","sources":["../../src/setup/setupCarts.ts"],"names":[],"mappings":"AAOA,MAAM,EAAE,uCAAuC,EAAE,+BAA+B,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEjG,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,YAA2B,EAAE,UAA6B,EAAE,EAAE,EAAE;IAC/F,IAAI,OAAO,CAAC,mBAAmB,IAAI,CAAC,uCAAuC,EAAE,CAAC;QAC5E,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,qBAAqB,CACpE,OAAO,CAAC,8BAA8B,CACvC,CAAC;QACF,MAAM,OAAO,CAAC,UAAU,CACtB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YACzB,MAAM,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClE,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,kBAAkB,IAAI,OAAO,CAAC,+BAA+B,CAAC,EAAE,CAAC;QAC3E,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAE7D,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACjB,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAC3D,OAAO,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC;gBAC/C,IAAI;gBACJ,WAAW,EAAE,MAAM,CAAC,MAAM;aAC3B,CAAC,CAAC;QACL,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Address } from '@unchainedshop/types/common.js';
2
- export declare const formatAddress: (address: Address) => string;
3
- //# sourceMappingURL=formatAddress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatAddress.d.ts","sourceRoot":"","sources":["../../../src/templates/order-parser/formatAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAEzD,eAAO,MAAM,aAAa,YAAa,OAAO,WAY7C,CAAC"}
@@ -1,14 +0,0 @@
1
- export const formatAddress = (address) => {
2
- return [
3
- [address.firstName, address.lastName].filter(Boolean).join(' '),
4
- address.company,
5
- address.addressLine,
6
- address.addressLine2,
7
- [address.postalCode, address.city].filter(Boolean).join(' '),
8
- address.regionCode,
9
- [address.countryCode].filter(Boolean).join(''),
10
- ]
11
- .filter(Boolean)
12
- .join('\n');
13
- };
14
- //# sourceMappingURL=formatAddress.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatAddress.js","sourceRoot":"","sources":["../../../src/templates/order-parser/formatAddress.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAE,EAAE;IAChD,OAAO;QACL,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC/D,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,WAAW;QACnB,OAAO,CAAC,YAAY;QACpB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC5D,OAAO,CAAC,UAAU;QAClB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;KAC/C;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const formatPrice: ({ amount, currency }: {
2
- amount: number;
3
- currency: string;
4
- }) => string;
5
- export default formatPrice;
6
- //# sourceMappingURL=formatPrice.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatPrice.d.ts","sourceRoot":"","sources":["../../../src/templates/order-parser/formatPrice.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,yBAA0B;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,WAGrF,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1,6 +0,0 @@
1
- export const formatPrice = ({ amount, currency }) => {
2
- const fixedPrice = amount / 100;
3
- return `${currency} ${fixedPrice}`;
4
- };
5
- export default formatPrice;
6
- //# sourceMappingURL=formatPrice.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatPrice.js","sourceRoot":"","sources":["../../../src/templates/order-parser/formatPrice.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAwC,EAAE,EAAE;IACxF,MAAM,UAAU,GAAG,MAAM,GAAG,GAAG,CAAC;IAChC,OAAO,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrC,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}