@unchainedshop/api 3.1.11 → 3.1.13
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/lib/errors.d.ts +1 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -0
- package/lib/errors.js.map +1 -1
- package/lib/express/chatRouter.d.ts +3 -0
- package/lib/express/chatRouter.d.ts.map +1 -0
- package/lib/express/chatRouter.js +86 -0
- package/lib/express/chatRouter.js.map +1 -0
- package/lib/express/createApolloMiddleware.d.ts +4 -0
- package/lib/express/createApolloMiddleware.d.ts.map +1 -0
- package/lib/express/createApolloMiddleware.js +36 -0
- package/lib/express/createApolloMiddleware.js.map +1 -0
- package/lib/express/createMCPMiddleware.d.ts +4 -0
- package/lib/express/createMCPMiddleware.d.ts.map +1 -0
- package/lib/express/createMCPMiddleware.js +68 -0
- package/lib/express/createMCPMiddleware.js.map +1 -0
- package/lib/express/createSingleSignOnMiddleware.d.ts +5 -0
- package/lib/express/createSingleSignOnMiddleware.d.ts.map +1 -0
- package/lib/express/createSingleSignOnMiddleware.js +71 -0
- package/lib/express/createSingleSignOnMiddleware.js.map +1 -0
- package/lib/hashPassword.d.ts +2 -0
- package/lib/hashPassword.d.ts.map +1 -0
- package/lib/hashPassword.js +5 -0
- package/lib/hashPassword.js.map +1 -0
- package/lib/loaders/assortmentLinkLoader.d.ts +12 -0
- package/lib/loaders/assortmentLinkLoader.d.ts.map +1 -0
- package/lib/loaders/assortmentLinkLoader.js +23 -0
- package/lib/loaders/assortmentLinkLoader.js.map +1 -0
- package/lib/loaders/assortmentLinksLoader.d.ts +14 -0
- package/lib/loaders/assortmentLinksLoader.d.ts.map +1 -0
- package/lib/loaders/assortmentLinksLoader.js +38 -0
- package/lib/loaders/assortmentLinksLoader.js.map +1 -0
- package/lib/loaders/assortmentLoader.d.ts +10 -0
- package/lib/loaders/assortmentLoader.d.ts.map +1 -0
- package/lib/loaders/assortmentLoader.js +15 -0
- package/lib/loaders/assortmentLoader.js.map +1 -0
- package/lib/loaders/assortmentMediaTextLoader.d.ts +12 -0
- package/lib/loaders/assortmentMediaTextLoader.d.ts.map +1 -0
- package/lib/loaders/assortmentMediaTextLoader.js +15 -0
- package/lib/loaders/assortmentMediaTextLoader.js.map +1 -0
- package/lib/loaders/assortmentMediasLoader.d.ts +10 -0
- package/lib/loaders/assortmentMediasLoader.d.ts.map +1 -0
- package/lib/loaders/assortmentMediasLoader.js +18 -0
- package/lib/loaders/assortmentMediasLoader.js.map +1 -0
- package/lib/loaders/assortmentProductLoader.d.ts +12 -0
- package/lib/loaders/assortmentProductLoader.d.ts.map +1 -0
- package/lib/loaders/assortmentProductLoader.js +14 -0
- package/lib/loaders/assortmentProductLoader.js.map +1 -0
- package/lib/loaders/assortmentProductsLoader.d.ts +10 -0
- package/lib/loaders/assortmentProductsLoader.d.ts.map +1 -0
- package/lib/loaders/assortmentProductsLoader.js +18 -0
- package/lib/loaders/assortmentProductsLoader.js.map +1 -0
- package/lib/loaders/assortmentTextLoader.d.ts +12 -0
- package/lib/loaders/assortmentTextLoader.d.ts.map +1 -0
- package/lib/loaders/assortmentTextLoader.js +15 -0
- package/lib/loaders/assortmentTextLoader.js.map +1 -0
- package/lib/loaders/buildLocaleMap.d.ts +6 -0
- package/lib/loaders/buildLocaleMap.d.ts.map +1 -0
- package/lib/loaders/buildLocaleMap.js +38 -0
- package/lib/loaders/buildLocaleMap.js.map +1 -0
- package/lib/loaders/buildTextMap.d.ts +1 -1
- package/lib/loaders/buildTextMap.d.ts.map +1 -1
- package/lib/loaders/buildTextMap.js +16 -6
- package/lib/loaders/buildTextMap.js.map +1 -1
- package/lib/loaders/countryLoader.d.ts +10 -0
- package/lib/loaders/countryLoader.d.ts.map +1 -0
- package/lib/loaders/countryLoader.js +14 -0
- package/lib/loaders/countryLoader.js.map +1 -0
- package/lib/loaders/currencyLoader.d.ts +10 -0
- package/lib/loaders/currencyLoader.d.ts.map +1 -0
- package/lib/loaders/currencyLoader.js +14 -0
- package/lib/loaders/currencyLoader.js.map +1 -0
- package/lib/loaders/deliveryProviderLoader.d.ts +10 -0
- package/lib/loaders/deliveryProviderLoader.d.ts.map +1 -0
- package/lib/loaders/deliveryProviderLoader.js +13 -0
- package/lib/loaders/deliveryProviderLoader.js.map +1 -0
- package/lib/loaders/fileLoader.d.ts +10 -0
- package/lib/loaders/fileLoader.d.ts.map +1 -0
- package/lib/loaders/fileLoader.js +13 -0
- package/lib/loaders/fileLoader.js.map +1 -0
- package/lib/loaders/filterLoader.d.ts +10 -0
- package/lib/loaders/filterLoader.d.ts.map +1 -0
- package/lib/loaders/filterLoader.js +14 -0
- package/lib/loaders/filterLoader.js.map +1 -0
- package/lib/loaders/filterTextLoader.d.ts +14 -0
- package/lib/loaders/filterTextLoader.d.ts.map +1 -0
- package/lib/loaders/filterTextLoader.js +15 -0
- package/lib/loaders/filterTextLoader.js.map +1 -0
- package/lib/loaders/index.d.ts.map +1 -1
- package/lib/loaders/index.js +1 -29
- package/lib/loaders/index.js.map +1 -1
- package/lib/loaders/languageLoader.d.ts +10 -0
- package/lib/loaders/languageLoader.d.ts.map +1 -0
- package/lib/loaders/languageLoader.js +14 -0
- package/lib/loaders/languageLoader.js.map +1 -0
- package/lib/loaders/orderLoader.d.ts +10 -0
- package/lib/loaders/orderLoader.d.ts.map +1 -0
- package/lib/loaders/orderLoader.js +16 -0
- package/lib/loaders/orderLoader.js.map +1 -0
- package/lib/loaders/paymentProviderLoader.d.ts +10 -0
- package/lib/loaders/paymentProviderLoader.d.ts.map +1 -0
- package/lib/loaders/paymentProviderLoader.js +13 -0
- package/lib/loaders/paymentProviderLoader.js.map +1 -0
- package/lib/loaders/productLoader.d.ts +10 -0
- package/lib/loaders/productLoader.d.ts.map +1 -0
- package/lib/loaders/productLoader.js +16 -0
- package/lib/loaders/productLoader.js.map +1 -0
- package/lib/loaders/productLoaderBySKU.d.ts +10 -0
- package/lib/loaders/productLoaderBySKU.d.ts.map +1 -0
- package/lib/loaders/productLoaderBySKU.js +16 -0
- package/lib/loaders/productLoaderBySKU.js.map +1 -0
- package/lib/loaders/productMediaTextLoader.d.ts +12 -0
- package/lib/loaders/productMediaTextLoader.d.ts.map +1 -0
- package/lib/loaders/productMediaTextLoader.js +15 -0
- package/lib/loaders/productMediaTextLoader.js.map +1 -0
- package/lib/loaders/productMediasLoader.d.ts +10 -0
- package/lib/loaders/productMediasLoader.d.ts.map +1 -0
- package/lib/loaders/productMediasLoader.js +18 -0
- package/lib/loaders/productMediasLoader.js.map +1 -0
- package/lib/loaders/productTextLoader.d.ts +12 -0
- package/lib/loaders/productTextLoader.d.ts.map +1 -0
- package/lib/loaders/productTextLoader.js +15 -0
- package/lib/loaders/productTextLoader.js.map +1 -0
- package/lib/loaders/userLoader.d.ts +10 -0
- package/lib/loaders/userLoader.d.ts.map +1 -0
- package/lib/loaders/userLoader.js +17 -0
- package/lib/loaders/userLoader.js.map +1 -0
- package/lib/loaders/utils.d.ts +7 -0
- package/lib/loaders/utils.d.ts.map +1 -0
- package/lib/loaders/utils.js +29 -0
- package/lib/loaders/utils.js.map +1 -0
- package/lib/mcp/index.d.ts +4 -0
- package/lib/mcp/index.d.ts.map +1 -0
- package/lib/mcp/index.js +12 -0
- package/lib/mcp/index.js.map +1 -0
- package/lib/mcp/tools/addProductAssignmentHandler.d.ts +52 -0
- package/lib/mcp/tools/addProductAssignmentHandler.d.ts.map +1 -0
- package/lib/mcp/tools/addProductAssignmentHandler.js +97 -0
- package/lib/mcp/tools/addProductAssignmentHandler.js.map +1 -0
- package/lib/mcp/tools/countriesHandler.d.ts +60 -0
- package/lib/mcp/tools/countriesHandler.d.ts.map +1 -0
- package/lib/mcp/tools/countriesHandler.js +48 -0
- package/lib/mcp/tools/countriesHandler.js.map +1 -0
- package/lib/mcp/tools/countryHandler.d.ts +20 -0
- package/lib/mcp/tools/countryHandler.d.ts.map +1 -0
- package/lib/mcp/tools/countryHandler.js +34 -0
- package/lib/mcp/tools/countryHandler.js.map +1 -0
- package/lib/mcp/tools/createProduct.d.ts +138 -0
- package/lib/mcp/tools/createProduct.d.ts.map +1 -0
- package/lib/mcp/tools/createProduct.js +60 -0
- package/lib/mcp/tools/createProduct.js.map +1 -0
- package/lib/mcp/tools/createProductVariationHandler.d.ts +84 -0
- package/lib/mcp/tools/createProductVariationHandler.d.ts.map +1 -0
- package/lib/mcp/tools/createProductVariationHandler.js +67 -0
- package/lib/mcp/tools/createProductVariationHandler.js.map +1 -0
- package/lib/mcp/tools/currenciesHandler.d.ts +60 -0
- package/lib/mcp/tools/currenciesHandler.d.ts.map +1 -0
- package/lib/mcp/tools/currenciesHandler.js +50 -0
- package/lib/mcp/tools/currenciesHandler.js.map +1 -0
- package/lib/mcp/tools/currencyHandler.d.ts +20 -0
- package/lib/mcp/tools/currencyHandler.d.ts.map +1 -0
- package/lib/mcp/tools/currencyHandler.js +34 -0
- package/lib/mcp/tools/currencyHandler.js.map +1 -0
- package/lib/mcp/tools/getProduct.d.ts +48 -0
- package/lib/mcp/tools/getProduct.d.ts.map +1 -0
- package/lib/mcp/tools/getProduct.js +104 -0
- package/lib/mcp/tools/getProduct.js.map +1 -0
- package/lib/mcp/tools/index.d.ts +6 -0
- package/lib/mcp/tools/index.d.ts.map +1 -0
- package/lib/mcp/tools/index.js +6 -0
- package/lib/mcp/tools/index.js.map +1 -0
- package/lib/mcp/tools/languageHandler.d.ts +20 -0
- package/lib/mcp/tools/languageHandler.d.ts.map +1 -0
- package/lib/mcp/tools/languageHandler.js +31 -0
- package/lib/mcp/tools/languageHandler.js.map +1 -0
- package/lib/mcp/tools/languagesHandler.d.ts +60 -0
- package/lib/mcp/tools/languagesHandler.d.ts.map +1 -0
- package/lib/mcp/tools/languagesHandler.js +42 -0
- package/lib/mcp/tools/languagesHandler.js.map +1 -0
- package/lib/mcp/tools/listProducts.d.ts +112 -0
- package/lib/mcp/tools/listProducts.d.ts.map +1 -0
- package/lib/mcp/tools/listProducts.js +98 -0
- package/lib/mcp/tools/listProducts.js.map +1 -0
- package/lib/mcp/tools/normalizeMediaUrl.d.ts +3 -0
- package/lib/mcp/tools/normalizeMediaUrl.d.ts.map +1 -0
- package/lib/mcp/tools/normalizeMediaUrl.js +21 -0
- package/lib/mcp/tools/normalizeMediaUrl.js.map +1 -0
- package/lib/mcp/tools/productsCountHandler.d.ts +32 -0
- package/lib/mcp/tools/productsCountHandler.d.ts.map +1 -0
- package/lib/mcp/tools/productsCountHandler.js +33 -0
- package/lib/mcp/tools/productsCountHandler.js.map +1 -0
- package/lib/mcp/tools/publishProduct.d.ts +20 -0
- package/lib/mcp/tools/publishProduct.d.ts.map +1 -0
- package/lib/mcp/tools/publishProduct.js +40 -0
- package/lib/mcp/tools/publishProduct.js.map +1 -0
- package/lib/mcp/tools/removeProduct.d.ts +20 -0
- package/lib/mcp/tools/removeProduct.d.ts.map +1 -0
- package/lib/mcp/tools/removeProduct.js +34 -0
- package/lib/mcp/tools/removeProduct.js.map +1 -0
- package/lib/mcp/tools/removeProductVariationHandler.d.ts +20 -0
- package/lib/mcp/tools/removeProductVariationHandler.d.ts.map +1 -0
- package/lib/mcp/tools/removeProductVariationHandler.js +43 -0
- package/lib/mcp/tools/removeProductVariationHandler.js.map +1 -0
- package/lib/mcp/tools/unPublishProduct.d.ts +20 -0
- package/lib/mcp/tools/unPublishProduct.d.ts.map +1 -0
- package/lib/mcp/tools/unPublishProduct.js +40 -0
- package/lib/mcp/tools/unPublishProduct.js.map +1 -0
- package/lib/mcp/tools/updateProduct.d.ts +56 -0
- package/lib/mcp/tools/updateProduct.d.ts.map +1 -0
- package/lib/mcp/tools/updateProduct.js +44 -0
- package/lib/mcp/tools/updateProduct.js.map +1 -0
- package/lib/mcp/tools/updateProductCommerceHandler.d.ts +166 -0
- package/lib/mcp/tools/updateProductCommerceHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductCommerceHandler.js +64 -0
- package/lib/mcp/tools/updateProductCommerceHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductPlanHandler.d.ts +72 -0
- package/lib/mcp/tools/updateProductPlanHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductPlanHandler.js +51 -0
- package/lib/mcp/tools/updateProductPlanHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductSupplyHandler.d.ts +64 -0
- package/lib/mcp/tools/updateProductSupplyHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductSupplyHandler.js +52 -0
- package/lib/mcp/tools/updateProductSupplyHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductTextsHandler.d.ts +114 -0
- package/lib/mcp/tools/updateProductTextsHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductTextsHandler.js +50 -0
- package/lib/mcp/tools/updateProductTextsHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductTokenizationHandler.d.ts +72 -0
- package/lib/mcp/tools/updateProductTokenizationHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductTokenizationHandler.js +49 -0
- package/lib/mcp/tools/updateProductTokenizationHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductWarehousingHandler.d.ts +48 -0
- package/lib/mcp/tools/updateProductWarehousingHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductWarehousingHandler.js +45 -0
- package/lib/mcp/tools/updateProductWarehousingHandler.js.map +1 -0
- package/lib/mcp/utils/getNormalizedProductDetails.d.ts +26 -0
- package/lib/mcp/utils/getNormalizedProductDetails.d.ts.map +1 -0
- package/lib/mcp/utils/getNormalizedProductDetails.js +36 -0
- package/lib/mcp/utils/getNormalizedProductDetails.js.map +1 -0
- package/lib/mcp/utils/normalizeMediaUrl.d.ts +3 -0
- package/lib/mcp/utils/normalizeMediaUrl.d.ts.map +1 -0
- package/lib/mcp/utils/normalizeMediaUrl.js +21 -0
- package/lib/mcp/utils/normalizeMediaUrl.js.map +1 -0
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts +3 -0
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js +6 -0
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js.map +1 -0
- package/lib/resolvers/mutations/accounts/disableTOTP.d.ts +6 -0
- package/lib/resolvers/mutations/accounts/disableTOTP.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/disableTOTP.js +27 -0
- package/lib/resolvers/mutations/accounts/disableTOTP.js.map +1 -0
- package/lib/resolvers/mutations/accounts/enableTOTP.d.ts +6 -0
- package/lib/resolvers/mutations/accounts/enableTOTP.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/enableTOTP.js +20 -0
- package/lib/resolvers/mutations/accounts/enableTOTP.js.map +1 -0
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts +7 -0
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.js +30 -0
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.js.map +1 -0
- package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts +8 -0
- package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/loginWithOAuth.js +25 -0
- package/lib/resolvers/mutations/accounts/loginWithOAuth.js.map +1 -0
- package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts +5 -0
- package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/logoutAllSessions.js +20 -0
- package/lib/resolvers/mutations/accounts/logoutAllSessions.js.map +1 -0
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts +6 -0
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js +13 -0
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js.map +1 -0
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts +6 -0
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts.map +1 -0
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.js +18 -0
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.js.map +1 -0
- package/lib/resolvers/mutations/products/addProductAssignment.d.ts.map +1 -1
- package/lib/resolvers/mutations/products/addProductAssignment.js +3 -1
- package/lib/resolvers/mutations/products/addProductAssignment.js.map +1 -1
- package/lib/resolvers/mutations/products/addProductMedia.d.ts +6 -0
- package/lib/resolvers/mutations/products/addProductMedia.d.ts.map +1 -0
- package/lib/resolvers/mutations/products/addProductMedia.js +18 -0
- package/lib/resolvers/mutations/products/addProductMedia.js.map +1 -0
- package/lib/resolvers/mutations/users/updateUserAvatar.d.ts +6 -0
- package/lib/resolvers/mutations/users/updateUserAvatar.d.ts.map +1 -0
- package/lib/resolvers/mutations/users/updateUserAvatar.js +22 -0
- package/lib/resolvers/mutations/users/updateUserAvatar.js.map +1 -0
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts +7 -0
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts.map +1 -0
- package/lib/resolvers/mutations/utils/getOrderCart.js +13 -0
- package/lib/resolvers/mutations/utils/getOrderCart.js.map +1 -0
- package/lib/resolvers/type/dispatch-types.d.ts +15 -0
- package/lib/resolvers/type/dispatch-types.d.ts.map +1 -0
- package/lib/resolvers/type/dispatch-types.js +16 -0
- package/lib/resolvers/type/dispatch-types.js.map +1 -0
- package/lib/resolvers/type/oauth-account.d.ts +6 -0
- package/lib/resolvers/type/oauth-account.d.ts.map +1 -0
- package/lib/resolvers/type/oauth-account.js +7 -0
- package/lib/resolvers/type/oauth-account.js.map +1 -0
- package/lib/resolvers/type/oauth-provider.d.ts +6 -0
- package/lib/resolvers/type/oauth-provider.d.ts.map +1 -0
- package/lib/resolvers/type/oauth-provider.js +6 -0
- package/lib/resolvers/type/oauth-provider.js.map +1 -0
- package/lib/resolvers/type/stock-types.d.ts +14 -0
- package/lib/resolvers/type/stock-types.d.ts.map +1 -0
- package/lib/resolvers/type/stock-types.js +15 -0
- package/lib/resolvers/type/stock-types.js.map +1 -0
- package/lib/user-context.d.ts +7 -0
- package/lib/user-context.d.ts.map +1 -0
- package/lib/user-context.js +76 -0
- package/lib/user-context.js.map +1 -0
- package/package.json +13 -13
- package/src/errors.ts +5 -0
- package/src/loaders/buildLocaleMap.test.ts +61 -0
- package/src/loaders/buildLocaleMap.ts +39 -0
- package/src/loaders/buildTextMap.test.ts +54 -0
- package/src/loaders/buildTextMap.ts +22 -6
- package/src/loaders/index.ts +1 -32
- package/src/resolvers/mutations/products/addProductAssignment.ts +8 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { log } from '@unchainedshop/logger';
|
|
2
|
+
import { UserNotFoundError } from '../../../errors.js';
|
|
3
|
+
export default async function updateUserAvatar(root, params, context) {
|
|
4
|
+
const { modules, services, userId } = context;
|
|
5
|
+
const normalizedUserId = params.userId || userId;
|
|
6
|
+
log(`mutation updateUserAvatar ${normalizedUserId}`, { userId });
|
|
7
|
+
if (!(await modules.users.userExists({ userId: normalizedUserId })))
|
|
8
|
+
throw new UserNotFoundError({ userId: normalizedUserId });
|
|
9
|
+
const user = await modules.users.findUserById(normalizedUserId);
|
|
10
|
+
const file = await services.files.uploadFileFromStream({
|
|
11
|
+
directoryName: 'user-avatars',
|
|
12
|
+
rawFile: params.avatar,
|
|
13
|
+
meta: { userId: normalizedUserId },
|
|
14
|
+
}, context);
|
|
15
|
+
if (user?.avatarId) {
|
|
16
|
+
await services.files.removeFiles({
|
|
17
|
+
fileIds: [user.avatarId],
|
|
18
|
+
}, context);
|
|
19
|
+
}
|
|
20
|
+
return modules.users.updateAvatar(normalizedUserId, file._id);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=updateUserAvatar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateUserAvatar.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/users/updateUserAvatar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,gBAAgB,CAC5C,IAAU,EACV,MAAuC,EACvC,OAAgB;IAEhB,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC;IAEjD,GAAG,CAAC,6BAA6B,gBAAgB,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAEjE,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACjE,MAAM,IAAI,iBAAiB,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAE5D,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IAEhE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,oBAAoB,CACpD;QACE,aAAa,EAAE,cAAc;QAC7B,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,IAAI,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE;KACnC,EACD,OAAO,CACR,CAAC;IAEF,IAAI,IAAI,EAAE,QAAQ,EAAE,CAAC;QACnB,MAAM,QAAQ,CAAC,KAAK,CAAC,WAAW,CAC9B;YACE,OAAO,EAAE,CAAC,IAAI,CAAC,QAAkB,CAAC;SACnC,EACD,OAAO,CACR,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,gBAAgB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/types/api.js';
|
|
2
|
+
import { User } from '@unchainedshop/types/user.js';
|
|
3
|
+
export declare const getOrderCart: (params: {
|
|
4
|
+
orderId?: string;
|
|
5
|
+
user: User;
|
|
6
|
+
}, context: Context) => Promise<import("@unchainedshop/types/orders.js").Order>;
|
|
7
|
+
//# sourceMappingURL=getOrderCart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOrderCart.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/utils/getOrderCart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAGpD,eAAO,MAAM,YAAY,WAAkB;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,WAAW,OAAO,4DAc5F,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OrderNotFoundError } from '../../../errors.js';
|
|
2
|
+
export const getOrderCart = async (params, context) => {
|
|
3
|
+
const { modules, services } = context;
|
|
4
|
+
const { orderId, user } = params;
|
|
5
|
+
if (orderId) {
|
|
6
|
+
const order = await modules.orders.findOrder({ orderId });
|
|
7
|
+
if (!order)
|
|
8
|
+
throw new OrderNotFoundError({ orderId });
|
|
9
|
+
return order;
|
|
10
|
+
}
|
|
11
|
+
return services.orders.nextUserCart({ user, countryCode: context.countryContext, forceCartCreation: true }, context);
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=getOrderCart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOrderCart.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/utils/getOrderCart.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,MAAwC,EAAE,OAAgB,EAAE,EAAE;IAC/F,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACtC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAEjC,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,YAAY,CACjC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,cAAc,EAAE,iBAAiB,EAAE,IAAI,EAAE,EACtE,OAAO,CACR,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DeliveryProvider } from '@unchainedshop/types/delivery.js';
|
|
2
|
+
import { Product } from '@unchainedshop/types/products.js';
|
|
3
|
+
import { WarehousingProvider } from '@unchainedshop/types/warehousing.js';
|
|
4
|
+
export declare const Dispatch: {
|
|
5
|
+
_id: (params: {
|
|
6
|
+
product: Product;
|
|
7
|
+
deliveryProvider: DeliveryProvider;
|
|
8
|
+
warehousingProvider: WarehousingProvider;
|
|
9
|
+
referenceDate: Date;
|
|
10
|
+
quantity: number;
|
|
11
|
+
country: string;
|
|
12
|
+
userId?: string;
|
|
13
|
+
}) => string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=dispatch-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-types.d.ts","sourceRoot":"","sources":["../../../src/resolvers/type/dispatch-types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,eAAO,MAAM,QAAQ;kBACL;QACZ,OAAO,EAAE,OAAO,CAAC;QACjB,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,mBAAmB,EAAE,mBAAmB,CAAC;QACzC,aAAa,EAAE,IAAI,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;CAeF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
export const Dispatch = {
|
|
3
|
+
_id: (params) => crypto
|
|
4
|
+
.createHash('sha256')
|
|
5
|
+
.update([
|
|
6
|
+
params.product._id,
|
|
7
|
+
params.deliveryProvider._id,
|
|
8
|
+
params.warehousingProvider._id,
|
|
9
|
+
params.referenceDate,
|
|
10
|
+
params.quantity,
|
|
11
|
+
params.country,
|
|
12
|
+
params.userId || 'ANONYMOUS',
|
|
13
|
+
].join(''))
|
|
14
|
+
.digest('hex'),
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=dispatch-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-types.js","sourceRoot":"","sources":["../../../src/resolvers/type/dispatch-types.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAK5B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,GAAG,EAAE,CAAC,MAQL,EAAE,EAAE,CACH,MAAM;SACH,UAAU,CAAC,QAAQ,CAAC;SACpB,MAAM,CACL;QACE,MAAM,CAAC,OAAO,CAAC,GAAG;QAClB,MAAM,CAAC,gBAAgB,CAAC,GAAG;QAC3B,MAAM,CAAC,mBAAmB,CAAC,GAAG;QAC9B,MAAM,CAAC,aAAa;QACpB,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,OAAO;QACd,MAAM,CAAC,MAAM,IAAI,WAAW;KAC7B,CAAC,IAAI,CAAC,EAAE,CAAC,CACX;SACA,MAAM,CAAC,KAAK,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/types/api.js';
|
|
2
|
+
export declare const OAuthAccount: {
|
|
3
|
+
_id: (account: any) => any;
|
|
4
|
+
provider: (account: any, _: never, { modules }: Context) => Promise<import("@unchainedshop/types/accounts.js").IOAuth2Adapter>;
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=oauth-account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-account.d.ts","sourceRoot":"","sources":["../../../src/resolvers/type/oauth-account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAEtD,eAAO,MAAM,YAAY;;gCAEM,KAAK,eAAe,OAAO;CAGzD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-account.js","sourceRoot":"","sources":["../../../src/resolvers/type/oauth-account.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE;IAC5B,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,CAAQ,EAAE,EAAE,OAAO,EAAW,EAAE,EAAE;QAC1D,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-provider.d.ts","sourceRoot":"","sources":["../../../src/resolvers/type/oauth-provider.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;CAIzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-provider.js","sourceRoot":"","sources":["../../../src/resolvers/type/oauth-provider.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ;IAClC,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ;IAC/C,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE;CAClD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DeliveryProvider } from '@unchainedshop/types/delivery.js';
|
|
2
|
+
import { Product } from '@unchainedshop/types/products.js';
|
|
3
|
+
import { WarehousingProvider } from '@unchainedshop/types/warehousing.js';
|
|
4
|
+
export declare const Stock: {
|
|
5
|
+
_id: (params: {
|
|
6
|
+
product: Product;
|
|
7
|
+
deliveryProvider: DeliveryProvider;
|
|
8
|
+
warehousingProvider: WarehousingProvider;
|
|
9
|
+
referenceDate: Date;
|
|
10
|
+
country: string;
|
|
11
|
+
userId?: string;
|
|
12
|
+
}) => string;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=stock-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stock-types.d.ts","sourceRoot":"","sources":["../../../src/resolvers/type/stock-types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,eAAO,MAAM,KAAK;kBACF;QACZ,OAAO,EAAE,OAAO,CAAC;QACjB,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,mBAAmB,EAAE,mBAAmB,CAAC;QACzC,aAAa,EAAE,IAAI,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;CAcF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
export const Stock = {
|
|
3
|
+
_id: (params) => crypto
|
|
4
|
+
.createHash('sha256')
|
|
5
|
+
.update([
|
|
6
|
+
params.product._id,
|
|
7
|
+
params.deliveryProvider._id,
|
|
8
|
+
params.warehousingProvider._id,
|
|
9
|
+
params.referenceDate,
|
|
10
|
+
params.country,
|
|
11
|
+
params.userId || 'ANONYMOUS',
|
|
12
|
+
].join(''))
|
|
13
|
+
.digest('hex'),
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=stock-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stock-types.js","sourceRoot":"","sources":["../../../src/resolvers/type/stock-types.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAK5B,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,GAAG,EAAE,CAAC,MAOL,EAAE,EAAE,CACH,MAAM;SACH,UAAU,CAAC,QAAQ,CAAC;SACpB,MAAM,CACL;QACE,MAAM,CAAC,OAAO,CAAC,GAAG;QAClB,MAAM,CAAC,gBAAgB,CAAC,GAAG;QAC3B,MAAM,CAAC,mBAAmB,CAAC,GAAG;QAC9B,MAAM,CAAC,aAAa;QACpB,MAAM,CAAC,OAAO;QACd,MAAM,CAAC,MAAM,IAAI,WAAW;KAC7B,CAAC,IAAI,CAAC,EAAE,CAAC,CACX;SACA,MAAM,CAAC,KAAK,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IncomingMessage, OutgoingMessage } from 'http';
|
|
2
|
+
import { UnchainedUserContext } from '@unchainedshop/types/api.js';
|
|
3
|
+
import { UnchainedCore } from '@unchainedshop/types/core.js';
|
|
4
|
+
export declare const getUserContext: (req: IncomingMessage & {
|
|
5
|
+
cookies?: any;
|
|
6
|
+
}, res: OutgoingMessage, unchainedAPI: UnchainedCore) => Promise<UnchainedUserContext>;
|
|
7
|
+
//# sourceMappingURL=user-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-context.d.ts","sourceRoot":"","sources":["../src/user-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AA0C7D,eAAO,MAAM,cAAc,QACpB,eAAe,GAAG;IAAE,OAAO,CAAC,EAAE,GAAG,CAAA;CAAE,OACnC,eAAe,gBACN,aAAa,KAC1B,OAAO,CAAC,oBAAoB,CAsD9B,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import cookie from 'cookie';
|
|
2
|
+
function isString(input) {
|
|
3
|
+
return typeof input === 'string' && Object.prototype.toString.call(input) === '[object String]';
|
|
4
|
+
}
|
|
5
|
+
const { UNCHAINED_COOKIE_NAME = 'unchained_token', UNCHAINED_COOKIE_PATH = '/', UNCHAINED_COOKIE_DOMAIN, UNCHAINED_COOKIE_SAMESITE, UNCHAINED_COOKIE_INSECURE, } = process.env;
|
|
6
|
+
function setLoginToken(res, token, expires) {
|
|
7
|
+
const cookieName = UNCHAINED_COOKIE_NAME;
|
|
8
|
+
const domain = UNCHAINED_COOKIE_DOMAIN;
|
|
9
|
+
const path = UNCHAINED_COOKIE_PATH;
|
|
10
|
+
const secure = UNCHAINED_COOKIE_INSECURE ? false : true;
|
|
11
|
+
const sameSite = ({
|
|
12
|
+
none: 'none',
|
|
13
|
+
lax: 'lax',
|
|
14
|
+
strict: 'strict',
|
|
15
|
+
'1': true,
|
|
16
|
+
'0': false,
|
|
17
|
+
}[UNCHAINED_COOKIE_SAMESITE?.trim()?.toLowerCase()] || false);
|
|
18
|
+
if (!cookieName)
|
|
19
|
+
return;
|
|
20
|
+
const authCookie = cookie.serialize(cookieName, token || null, {
|
|
21
|
+
domain,
|
|
22
|
+
httpOnly: true,
|
|
23
|
+
path,
|
|
24
|
+
expires: token && expires ? expires : undefined,
|
|
25
|
+
maxAge: token ? undefined : -1,
|
|
26
|
+
sameSite,
|
|
27
|
+
secure,
|
|
28
|
+
});
|
|
29
|
+
res.setHeader('Set-Cookie', authCookie);
|
|
30
|
+
}
|
|
31
|
+
export const getUserContext = async (req, res, unchainedAPI) => {
|
|
32
|
+
// there is a possible current user connected!
|
|
33
|
+
const cookieName = UNCHAINED_COOKIE_NAME;
|
|
34
|
+
let loginToken = req.cookies?.[cookieName];
|
|
35
|
+
if (req.headers.authorization) {
|
|
36
|
+
const [type, token] = req.headers.authorization.split(' ');
|
|
37
|
+
if (type === 'Bearer') {
|
|
38
|
+
loginToken = token;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (loginToken) {
|
|
42
|
+
// throw an error if the token is not a string
|
|
43
|
+
if (!isString(loginToken))
|
|
44
|
+
throw new Error('Access Token is not a string');
|
|
45
|
+
// the hashed token is the key to find the possible current user in the db
|
|
46
|
+
const hashedToken = unchainedAPI.modules.accounts.createHashLoginToken(loginToken);
|
|
47
|
+
const currentUser = await unchainedAPI.modules.users.findUserByToken({
|
|
48
|
+
hashedToken,
|
|
49
|
+
});
|
|
50
|
+
// the current user exists
|
|
51
|
+
if (currentUser) {
|
|
52
|
+
// find the right login token corresponding, the current user may have
|
|
53
|
+
// several sessions logged on different browsers / computers
|
|
54
|
+
const tokenInformation = currentUser.services.resume.loginTokens.find((tokenInfo) => tokenInfo.hashedToken === hashedToken); // eslint-disable-line
|
|
55
|
+
// true if the token is expired
|
|
56
|
+
const isExpired = new Date(tokenInformation.when) < new Date();
|
|
57
|
+
// if the token is still valid, give access to the current user
|
|
58
|
+
// information in the resolvers context
|
|
59
|
+
if (!isExpired) {
|
|
60
|
+
// return a new context object with the current user & her id
|
|
61
|
+
return {
|
|
62
|
+
user: currentUser,
|
|
63
|
+
userId: currentUser._id,
|
|
64
|
+
loginToken: loginToken,
|
|
65
|
+
setLoginToken,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// If there is no user with this token or the token is expires/invalid,
|
|
70
|
+
// we should remove that cookie from the client
|
|
71
|
+
setLoginToken(res, null);
|
|
72
|
+
return { loginToken: loginToken, setLoginToken };
|
|
73
|
+
}
|
|
74
|
+
return { setLoginToken };
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=user-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-context.js","sourceRoot":"","sources":["../src/user-context.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,SAAS,QAAQ,CAAC,KAAK;IACrB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAC;AAClG,CAAC;AAED,MAAM,EACJ,qBAAqB,GAAG,iBAAiB,EACzC,qBAAqB,GAAG,GAAG,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,GAC1B,GAAG,OAAO,CAAC,GAAG,CAAC;AAEhB,SAAS,aAAa,CAAC,GAAoB,EAAE,KAAoB,EAAE,OAAc;IAC/E,MAAM,UAAU,GAAG,qBAAqB,CAAC;IACzC,MAAM,MAAM,GAAG,uBAAuB,CAAC;IACvC,MAAM,IAAI,GAAG,qBAAqB,CAAC;IACnC,MAAM,MAAM,GAAG,yBAAyB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IACxD,MAAM,QAAQ,GAAG,CAAC;QAChB,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,MAAM,EAAE,QAAQ;QAChB,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,KAAK;KACX,CAAC,yBAAyB,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,IAAI,KAAK,CAAwC,CAAC;IAErG,IAAI,CAAC,UAAU;QAAE,OAAO;IAExB,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,IAAI,IAAI,EAAE;QAC7D,MAAM;QACN,QAAQ,EAAE,IAAI;QACd,IAAI;QACJ,OAAO,EAAE,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;QAC/C,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9B,QAAQ;QACR,MAAM;KACP,CAAC,CAAC;IACH,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,GAAwC,EACxC,GAAoB,EACpB,YAA2B,EACI,EAAE;IACjC,8CAA8C;IAC9C,MAAM,UAAU,GAAG,qBAAqB,CAAC;IACzC,IAAI,UAAU,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,CAAC;IAE3C,IAAI,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3D,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,UAAU,GAAG,KAAK,CAAC;QACrB,CAAC;IACH,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACf,8CAA8C;QAC9C,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAE3E,0EAA0E;QAC1E,MAAM,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,UAAoB,CAAC,CAAC;QAE7F,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC;YACnE,WAAW;SACZ,CAAC,CAAC;QAEH,0BAA0B;QAC1B,IAAI,WAAW,EAAE,CAAC;YAChB,sEAAsE;YACtE,4DAA4D;YAC5D,MAAM,gBAAgB,GAAG,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CACnE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,KAAK,WAAW,CACrD,CAAC,CAAC,sBAAsB;YAEzB,+BAA+B;YAC/B,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YAE/D,+DAA+D;YAC/D,uCAAuC;YACvC,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,6DAA6D;gBAC7D,OAAO;oBACL,IAAI,EAAE,WAAW;oBACjB,MAAM,EAAE,WAAW,CAAC,GAAG;oBACvB,UAAU,EAAE,UAAoB;oBAChC,aAAa;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;QAED,uEAAuE;QACvE,+CAA+C;QAC/C,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAEzB,OAAO,EAAE,UAAU,EAAE,UAAoB,EAAE,aAAa,EAAE,CAAC;IAC7D,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/api",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.13",
|
|
4
4
|
"main": "lib/api-index.js",
|
|
5
5
|
"types": "lib/api-index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@ethereumjs/util": ">= 8 <
|
|
34
|
+
"@ethereumjs/util": ">= 8 < 11",
|
|
35
35
|
"@fastify/cookie": ">= 11.0 < 12",
|
|
36
36
|
"@fastify/session": ">= 11.0 < 12",
|
|
37
37
|
"connect-mongo": ">= 5.1.0 < 6",
|
|
@@ -71,11 +71,11 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@unchainedshop/core": "^3.1.
|
|
75
|
-
"@unchainedshop/events": "^3.1.
|
|
76
|
-
"@unchainedshop/logger": "^3.1.
|
|
77
|
-
"@unchainedshop/roles": "^3.1.
|
|
78
|
-
"@unchainedshop/utils": "^3.1.
|
|
74
|
+
"@unchainedshop/core": "^3.1.13",
|
|
75
|
+
"@unchainedshop/events": "^3.1.13",
|
|
76
|
+
"@unchainedshop/logger": "^3.1.13",
|
|
77
|
+
"@unchainedshop/roles": "^3.1.13",
|
|
78
|
+
"@unchainedshop/utils": "^3.1.13",
|
|
79
79
|
"accounting": "0.4.1",
|
|
80
80
|
"dataloader": "^2.2.3",
|
|
81
81
|
"expiry-map": "^2.0.0",
|
|
@@ -84,16 +84,16 @@
|
|
|
84
84
|
"p-memoize": "^7.1.1"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@ethereumjs/util": "^
|
|
87
|
+
"@ethereumjs/util": "^10.0.0",
|
|
88
88
|
"@fastify/cookie": "^11.0.2",
|
|
89
89
|
"@fastify/session": "^11.1.0",
|
|
90
|
-
"@types/express": "^5.0.
|
|
91
|
-
"@types/node": "^
|
|
90
|
+
"@types/express": "^5.0.3",
|
|
91
|
+
"@types/node": "^24.0.4",
|
|
92
92
|
"express": "^5.1.0",
|
|
93
93
|
"express-session": "^1.18.1",
|
|
94
|
-
"fastify": "^5.
|
|
94
|
+
"fastify": "^5.4.0",
|
|
95
95
|
"passport": "^0.7.0",
|
|
96
|
-
"tsx": "^4.
|
|
97
|
-
"typescript": "^5.8.
|
|
96
|
+
"tsx": "^4.20.3",
|
|
97
|
+
"typescript": "^5.8.3"
|
|
98
98
|
}
|
|
99
99
|
}
|
package/src/errors.ts
CHANGED
|
@@ -40,6 +40,11 @@ export const ProductWrongTypeError = createError(
|
|
|
40
40
|
'The current type of the product does not allow this operation',
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
+
export const ProductVariationInfinityLoop = createError(
|
|
44
|
+
'ProductInfinityLoop',
|
|
45
|
+
'Assigning the proxy to itself as child in product assignments is not allowed, this would create an infinite loop',
|
|
46
|
+
);
|
|
47
|
+
|
|
43
48
|
export const AssortmentNotFoundError = createError('AssortmentNotFoundError', 'Assortment not found');
|
|
44
49
|
|
|
45
50
|
export const AssortmentFilterNotFoundError = createError(
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import buildLocaleMap from './buildLocaleMap.js';
|
|
4
|
+
|
|
5
|
+
const testTexts = [
|
|
6
|
+
// 1 has translations in French and German
|
|
7
|
+
{ locale: 'fr', _id: '1', entityId: '1' },
|
|
8
|
+
{ locale: 'de', _id: '2', entityId: '1' },
|
|
9
|
+
|
|
10
|
+
// 2 only has Ialien translations
|
|
11
|
+
{ locale: 'it', _id: '3', entityId: '2' },
|
|
12
|
+
|
|
13
|
+
// 3 only has English translations
|
|
14
|
+
{ locale: 'en', _id: '4', entityId: '3' },
|
|
15
|
+
|
|
16
|
+
// 4 only has German translations
|
|
17
|
+
{ locale: 'de', _id: '5', entityId: '4' },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
describe('buildLocaleMap', () => {
|
|
21
|
+
it('Mixed usage of default locale and forced languages', () => {
|
|
22
|
+
const queries = [{ locale: 'de-CH' }, { locale: 'fr' }, { locale: 'it' }];
|
|
23
|
+
const expected = {
|
|
24
|
+
de: ['de-CH', 'fr', 'it'],
|
|
25
|
+
fr: ['fr'],
|
|
26
|
+
it: ['it'],
|
|
27
|
+
};
|
|
28
|
+
const result = buildLocaleMap(queries, testTexts);
|
|
29
|
+
assert.deepStrictEqual(result, expected);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('Mixed usage of forced languages', () => {
|
|
33
|
+
const queries = [{ locale: 'fr' }, { locale: 'it' }];
|
|
34
|
+
const expected = {
|
|
35
|
+
de: ['fr', 'it'],
|
|
36
|
+
fr: ['fr'],
|
|
37
|
+
it: ['it'],
|
|
38
|
+
};
|
|
39
|
+
const result = buildLocaleMap(queries, testTexts);
|
|
40
|
+
assert.deepStrictEqual(result, expected);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('Only default locale', () => {
|
|
44
|
+
const queries = [{ locale: 'de_CH' }];
|
|
45
|
+
const expected = {
|
|
46
|
+
de: ['de_CH'],
|
|
47
|
+
};
|
|
48
|
+
const result = buildLocaleMap(queries, testTexts);
|
|
49
|
+
assert.deepStrictEqual(result, expected);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('Only one forced language locale', () => {
|
|
53
|
+
const queries = [{ locale: 'fr' }];
|
|
54
|
+
const expected = {
|
|
55
|
+
fr: ['fr'],
|
|
56
|
+
de: ['fr'],
|
|
57
|
+
};
|
|
58
|
+
const result = buildLocaleMap(queries, testTexts);
|
|
59
|
+
assert.deepStrictEqual(result, expected);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { systemLocale } from '@unchainedshop/utils';
|
|
2
|
+
|
|
3
|
+
function getLocaleStrings(locale: string): string[] {
|
|
4
|
+
try {
|
|
5
|
+
const localeObj = new Intl.Locale(locale);
|
|
6
|
+
// Optimized Set creation and spread
|
|
7
|
+
const locales = new Set<string>();
|
|
8
|
+
locales.add(localeObj.baseName);
|
|
9
|
+
locales.add(localeObj.language);
|
|
10
|
+
locales.add(systemLocale.baseName);
|
|
11
|
+
locales.add(systemLocale.language);
|
|
12
|
+
return Array.from(locales);
|
|
13
|
+
} catch {
|
|
14
|
+
// Optimized Set creation and spread
|
|
15
|
+
const locales = new Set<string>();
|
|
16
|
+
locales.add(systemLocale.baseName);
|
|
17
|
+
locales.add(systemLocale.language);
|
|
18
|
+
return Array.from(locales);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export default function buildLocaleMap(
|
|
22
|
+
queries: Readonly<Array<{ locale: string }>>,
|
|
23
|
+
texts: Readonly<Array<{ locale?: string }>>,
|
|
24
|
+
): Record<string, string[]> {
|
|
25
|
+
// key = texts.locale
|
|
26
|
+
// value = input query locale
|
|
27
|
+
const queryLocales = new Set(queries.map((q) => q.locale));
|
|
28
|
+
const textLocales = new Set(texts.map((t) => t.locale));
|
|
29
|
+
const localeMap = {};
|
|
30
|
+
for (const queryLocale of queryLocales) {
|
|
31
|
+
const potentialMatches = getLocaleStrings(queryLocale);
|
|
32
|
+
const matches = potentialMatches.filter((l) => textLocales.has(l));
|
|
33
|
+
for (const match of matches) {
|
|
34
|
+
if (!localeMap[match]) localeMap[match] = [];
|
|
35
|
+
localeMap[match].push(queryLocale);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return localeMap;
|
|
39
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import buildTextMap from './buildTextMap.js';
|
|
4
|
+
|
|
5
|
+
const testTexts = [
|
|
6
|
+
// 1 has translations in French and German
|
|
7
|
+
{ locale: 'fr', _id: 'french-1', entityId: '1' },
|
|
8
|
+
{ locale: 'de', _id: 'german-1', entityId: '1' },
|
|
9
|
+
|
|
10
|
+
// 2 only has Ialien translations
|
|
11
|
+
{ locale: 'it', _id: 'italian-2', entityId: '2' },
|
|
12
|
+
|
|
13
|
+
// 3 only has English translations
|
|
14
|
+
{ locale: 'en', _id: 'english-3', entityId: '3' },
|
|
15
|
+
|
|
16
|
+
// 4 only has German translations
|
|
17
|
+
{ locale: 'de', _id: 'german-4', entityId: '4' },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
describe('buildTextMap', () => {
|
|
21
|
+
it('Generate a correct text map for all fallbacks', () => {
|
|
22
|
+
const localeMap = {
|
|
23
|
+
de: ['de-CH', 'fr', 'it'],
|
|
24
|
+
fr: ['fr'],
|
|
25
|
+
it: ['it'],
|
|
26
|
+
};
|
|
27
|
+
const expected = {
|
|
28
|
+
'de-CH1': {
|
|
29
|
+
_id: 'german-1',
|
|
30
|
+
},
|
|
31
|
+
fr1: {
|
|
32
|
+
_id: 'french-1',
|
|
33
|
+
},
|
|
34
|
+
it1: {
|
|
35
|
+
_id: 'german-1',
|
|
36
|
+
},
|
|
37
|
+
'de-CH4': {
|
|
38
|
+
_id: 'german-4',
|
|
39
|
+
},
|
|
40
|
+
fr4: {
|
|
41
|
+
_id: 'german-4',
|
|
42
|
+
},
|
|
43
|
+
it4: {
|
|
44
|
+
_id: 'german-4',
|
|
45
|
+
},
|
|
46
|
+
it2: {
|
|
47
|
+
_id: 'italian-2',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const result = buildTextMap(localeMap, testTexts, (text) => text.entityId);
|
|
51
|
+
|
|
52
|
+
assert.partialDeepStrictEqual(result, expected);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
type ArrayElement<T> = T extends (infer U)[] ? U : never;
|
|
2
2
|
|
|
3
|
+
/* This file has been optimized for performance to the last drop. Don't refactor! */
|
|
4
|
+
|
|
3
5
|
export default function buildTextMap<T extends Array<{ locale?: string }>>(
|
|
4
6
|
localeMap: Record<string, string[]>,
|
|
5
7
|
texts: Readonly<T>,
|
|
6
8
|
buildId: (item: ArrayElement<T>) => string,
|
|
7
9
|
) {
|
|
8
|
-
const textsMap = {};
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const textsMap: Record<string, ArrayElement<T>> = {}; // Added type for textsMap
|
|
11
|
+
const localeMapKeys = Object.keys(localeMap);
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < localeMapKeys.length; i++) {
|
|
14
|
+
const originLocale = localeMapKeys[i];
|
|
15
|
+
const localesForText = localeMap[originLocale];
|
|
16
|
+
|
|
17
|
+
for (let j = 0; j < texts.length; j++) {
|
|
18
|
+
const text = texts[j];
|
|
11
19
|
if (originLocale !== text.locale) continue;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
|
|
21
|
+
const idPart = buildId(text as ArrayElement<T>); // Ensured correct type for buildId argument
|
|
22
|
+
|
|
23
|
+
for (let k = 0; k < localesForText.length; k++) {
|
|
24
|
+
const locale = localesForText[k];
|
|
25
|
+
const key = locale + idPart;
|
|
26
|
+
if (textsMap[key] && locale !== text.locale) {
|
|
27
|
+
// If the key already exists and the locale is a fallback, skip this text
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
textsMap[key] = text as ArrayElement<T>; // Ensured correct type for assignment
|
|
15
31
|
}
|
|
16
32
|
}
|
|
17
33
|
}
|
package/src/loaders/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import DataLoader from 'dataloader';
|
|
2
|
-
import { systemLocale } from '@unchainedshop/utils';
|
|
3
2
|
import { UnchainedCore } from '@unchainedshop/core';
|
|
4
3
|
import { Product, ProductText, ProductMediaText, ProductMedia } from '@unchainedshop/core-products';
|
|
5
4
|
import { Filter, FilterText } from '@unchainedshop/core-filters';
|
|
@@ -13,37 +12,7 @@ import {
|
|
|
13
12
|
} from '@unchainedshop/core-assortments';
|
|
14
13
|
import { File } from '@unchainedshop/core-files';
|
|
15
14
|
import buildTextMap from './buildTextMap.js';
|
|
16
|
-
|
|
17
|
-
function getLocaleStrings(locale: string) {
|
|
18
|
-
try {
|
|
19
|
-
const localeObj = new Intl.Locale(locale);
|
|
20
|
-
return [
|
|
21
|
-
...new Set([localeObj.baseName, localeObj.language, systemLocale.baseName, systemLocale.language]),
|
|
22
|
-
];
|
|
23
|
-
} catch {
|
|
24
|
-
return [...new Set([systemLocale.baseName, systemLocale.language])];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function buildLocaleMap(
|
|
29
|
-
queries: Readonly<Array<{ locale: string }>>,
|
|
30
|
-
texts: Readonly<Array<{ locale?: string }>>,
|
|
31
|
-
): Record<string, string[]> {
|
|
32
|
-
// key = texts.locale
|
|
33
|
-
// value = input query locale
|
|
34
|
-
const queryLocales: Array<any> = [...new Set(queries.map((q) => q.locale))];
|
|
35
|
-
const textLocales: Array<string> = [...new Set(texts.map((t) => t.locale))];
|
|
36
|
-
const localeMap = {};
|
|
37
|
-
for (const queryLocale of queryLocales) {
|
|
38
|
-
const potentialMatches = getLocaleStrings(queryLocale);
|
|
39
|
-
const matches = potentialMatches.filter((l) => textLocales.includes(l));
|
|
40
|
-
for (const match of matches) {
|
|
41
|
-
if (!localeMap[match]) localeMap[match] = [];
|
|
42
|
-
localeMap[match].push(queryLocale);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return localeMap;
|
|
46
|
-
}
|
|
15
|
+
import buildLocaleMap from './buildLocaleMap.js';
|
|
47
16
|
|
|
48
17
|
const loaders = async (unchainedAPI: UnchainedCore) => {
|
|
49
18
|
return {
|
|
@@ -3,7 +3,12 @@ import { ProductTypes } from '@unchainedshop/core-products';
|
|
|
3
3
|
|
|
4
4
|
import { Context } from '../../../context.js';
|
|
5
5
|
import { ProductConfiguration } from '@unchainedshop/core-products';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ProductNotFoundError,
|
|
8
|
+
InvalidIdError,
|
|
9
|
+
ProductWrongTypeError,
|
|
10
|
+
ProductVariationInfinityLoop,
|
|
11
|
+
} from '../../../errors.js';
|
|
7
12
|
|
|
8
13
|
export default async function addProductAssignment(
|
|
9
14
|
root: never,
|
|
@@ -29,6 +34,8 @@ export default async function addProductAssignment(
|
|
|
29
34
|
});
|
|
30
35
|
if (!proxyProduct) throw new ProductNotFoundError({ proxyId });
|
|
31
36
|
|
|
37
|
+
if (productId === proxyId) throw new ProductVariationInfinityLoop({ productId });
|
|
38
|
+
|
|
32
39
|
if (proxyProduct.type !== ProductTypes.ConfigurableProduct)
|
|
33
40
|
throw new ProductWrongTypeError({
|
|
34
41
|
proxyId,
|