@unchainedshop/platform 1.1.3
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/README.md +3 -0
- package/lib/bulk-importer/createBulkImporter.d.ts +4 -0
- package/lib/bulk-importer/createBulkImporter.js +102 -0
- package/lib/bulk-importer/createBulkImporter.js.map +1 -0
- package/lib/bulk-importer/handlers/assortment/create.d.ts +11 -0
- package/lib/bulk-importer/handlers/assortment/create.js +59 -0
- package/lib/bulk-importer/handlers/assortment/create.js.map +1 -0
- package/lib/bulk-importer/handlers/assortment/index.d.ts +3 -0
- package/lib/bulk-importer/handlers/assortment/index.js +4 -0
- package/lib/bulk-importer/handlers/assortment/index.js.map +1 -0
- package/lib/bulk-importer/handlers/assortment/remove.d.ts +9 -0
- package/lib/bulk-importer/handlers/assortment/remove.js +13 -0
- package/lib/bulk-importer/handlers/assortment/remove.js.map +1 -0
- package/lib/bulk-importer/handlers/assortment/update.d.ts +10 -0
- package/lib/bulk-importer/handlers/assortment/update.js +61 -0
- package/lib/bulk-importer/handlers/assortment/update.js.map +1 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.d.ts +7 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js +30 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js.map +1 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.d.ts +7 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js +9 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js.map +1 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.d.ts +7 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js +29 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js.map +1 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.d.ts +7 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js +32 -0
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js.map +1 -0
- package/lib/bulk-importer/handlers/assortment/upsertMedia.d.ts +7 -0
- package/lib/bulk-importer/handlers/assortment/upsertMedia.js +67 -0
- package/lib/bulk-importer/handlers/assortment/upsertMedia.js.map +1 -0
- package/lib/bulk-importer/handlers/filter/create.d.ts +11 -0
- package/lib/bulk-importer/handlers/filter/create.js +42 -0
- package/lib/bulk-importer/handlers/filter/create.js.map +1 -0
- package/lib/bulk-importer/handlers/filter/index.d.ts +3 -0
- package/lib/bulk-importer/handlers/filter/index.js +4 -0
- package/lib/bulk-importer/handlers/filter/index.js.map +1 -0
- package/lib/bulk-importer/handlers/filter/remove.d.ts +9 -0
- package/lib/bulk-importer/handlers/filter/remove.js +14 -0
- package/lib/bulk-importer/handlers/filter/remove.js.map +1 -0
- package/lib/bulk-importer/handlers/filter/update.d.ts +10 -0
- package/lib/bulk-importer/handlers/filter/update.js +34 -0
- package/lib/bulk-importer/handlers/filter/update.js.map +1 -0
- package/lib/bulk-importer/handlers/filter/upsertFilterContent.d.ts +13 -0
- package/lib/bulk-importer/handlers/filter/upsertFilterContent.js +6 -0
- package/lib/bulk-importer/handlers/filter/upsertFilterContent.js.map +1 -0
- package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.d.ts +5 -0
- package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js +8 -0
- package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js.map +1 -0
- package/lib/bulk-importer/handlers/product/create.d.ts +11 -0
- package/lib/bulk-importer/handlers/product/create.js +51 -0
- package/lib/bulk-importer/handlers/product/create.js.map +1 -0
- package/lib/bulk-importer/handlers/product/index.d.ts +3 -0
- package/lib/bulk-importer/handlers/product/index.js +4 -0
- package/lib/bulk-importer/handlers/product/index.js.map +1 -0
- package/lib/bulk-importer/handlers/product/remove.d.ts +9 -0
- package/lib/bulk-importer/handlers/product/remove.js +14 -0
- package/lib/bulk-importer/handlers/product/remove.js.map +1 -0
- package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.d.ts +2 -0
- package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.js +13 -0
- package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.js.map +1 -0
- package/lib/bulk-importer/handlers/product/update.d.ts +10 -0
- package/lib/bulk-importer/handlers/product/update.js +48 -0
- package/lib/bulk-importer/handlers/product/update.js.map +1 -0
- package/lib/bulk-importer/handlers/product/upsertMedia.d.ts +6 -0
- package/lib/bulk-importer/handlers/product/upsertMedia.js +69 -0
- package/lib/bulk-importer/handlers/product/upsertMedia.js.map +1 -0
- package/lib/bulk-importer/handlers/product/upsertProductContent.d.ts +6 -0
- package/lib/bulk-importer/handlers/product/upsertProductContent.js +9 -0
- package/lib/bulk-importer/handlers/product/upsertProductContent.js.map +1 -0
- package/lib/bulk-importer/handlers/product/upsertVariations.d.ts +6 -0
- package/lib/bulk-importer/handlers/product/upsertVariations.js +39 -0
- package/lib/bulk-importer/handlers/product/upsertVariations.js.map +1 -0
- package/lib/context/index.d.ts +2 -0
- package/lib/context/index.js +3 -0
- package/lib/context/index.js.map +1 -0
- package/lib/context/setAccessToken.d.ts +3 -0
- package/lib/context/setAccessToken.js +10 -0
- package/lib/context/setAccessToken.js.map +1 -0
- package/lib/context/withAccessToken.d.ts +2 -0
- package/lib/context/withAccessToken.js +33 -0
- package/lib/context/withAccessToken.js.map +1 -0
- package/lib/migrations/createMigrationRunner.d.ts +14 -0
- package/lib/migrations/createMigrationRunner.js +49 -0
- package/lib/migrations/createMigrationRunner.js.map +1 -0
- package/lib/migrations/migrationRepository.d.ts +3 -0
- package/lib/migrations/migrationRepository.js +16 -0
- package/lib/migrations/migrationRepository.js.map +1 -0
- package/lib/migrations/runMigrations.d.ts +7 -0
- package/lib/migrations/runMigrations.js +47 -0
- package/lib/migrations/runMigrations.js.map +1 -0
- package/lib/platform-index.d.ts +2 -0
- package/lib/platform-index.js +3 -0
- package/lib/platform-index.js.map +1 -0
- package/lib/setup/generateEventTypeDefs.d.ts +1 -0
- package/lib/setup/generateEventTypeDefs.js +9 -0
- package/lib/setup/generateEventTypeDefs.js.map +1 -0
- package/lib/setup/generateRoleActionTypeDefs.d.ts +1 -0
- package/lib/setup/generateRoleActionTypeDefs.js +9 -0
- package/lib/setup/generateRoleActionTypeDefs.js.map +1 -0
- package/lib/setup/generateWorkTypeDefs.d.ts +1 -0
- package/lib/setup/generateWorkTypeDefs.js +11 -0
- package/lib/setup/generateWorkTypeDefs.js.map +1 -0
- package/lib/setup/setupAccounts.d.ts +2 -0
- package/lib/setup/setupAccounts.js +91 -0
- package/lib/setup/setupAccounts.js.map +1 -0
- package/lib/setup/setupAutoScheduling.d.ts +1 -0
- package/lib/setup/setupAutoScheduling.js +5 -0
- package/lib/setup/setupAutoScheduling.js.map +1 -0
- package/lib/setup/setupCarts.d.ts +3 -0
- package/lib/setup/setupCarts.js +14 -0
- package/lib/setup/setupCarts.js.map +1 -0
- package/lib/setup/setupTemplates.d.ts +1 -0
- package/lib/setup/setupTemplates.js +17 -0
- package/lib/setup/setupTemplates.js.map +1 -0
- package/lib/setup/setupWorkqueue.d.ts +6 -0
- package/lib/setup/setupWorkqueue.js +11 -0
- package/lib/setup/setupWorkqueue.js.map +1 -0
- package/lib/startPlatform.d.ts +8 -0
- package/lib/startPlatform.js +105 -0
- package/lib/startPlatform.js.map +1 -0
- package/lib/templates/resolveAccountActionTemplate.d.ts +2 -0
- package/lib/templates/resolveAccountActionTemplate.js +131 -0
- package/lib/templates/resolveAccountActionTemplate.js.map +1 -0
- package/lib/templates/resolveEnrollmentStatusTemplate.d.ts +2 -0
- package/lib/templates/resolveEnrollmentStatusTemplate.js +34 -0
- package/lib/templates/resolveEnrollmentStatusTemplate.js.map +1 -0
- package/lib/templates/resolveForwardDeliveryTemplate.d.ts +2 -0
- package/lib/templates/resolveForwardDeliveryTemplate.js +114 -0
- package/lib/templates/resolveForwardDeliveryTemplate.js.map +1 -0
- package/lib/templates/resolveOrderConfirmationTemplate.d.ts +2 -0
- package/lib/templates/resolveOrderConfirmationTemplate.js +111 -0
- package/lib/templates/resolveOrderConfirmationTemplate.js.map +1 -0
- package/lib/templates/resolveOrderRejectionTemplate.d.ts +2 -0
- package/lib/templates/resolveOrderRejectionTemplate.js +77 -0
- package/lib/templates/resolveOrderRejectionTemplate.js.map +1 -0
- package/lib/templates/resolveQuotationStatusTemplate.d.ts +2 -0
- package/lib/templates/resolveQuotationStatusTemplate.js +40 -0
- package/lib/templates/resolveQuotationStatusTemplate.js.map +1 -0
- package/lib/templates/utils/getOrderAttachmentsData.d.ts +8 -0
- package/lib/templates/utils/getOrderAttachmentsData.js +28 -0
- package/lib/templates/utils/getOrderAttachmentsData.js.map +1 -0
- package/lib/templates/utils/getOrderPositionsData.d.ts +6 -0
- package/lib/templates/utils/getOrderPositionsData.js +32 -0
- package/lib/templates/utils/getOrderPositionsData.js.map +1 -0
- package/package.json +58 -0
- package/src/bulk-importer/createBulkImporter.ts +120 -0
- package/src/bulk-importer/handlers/assortment/create.ts +86 -0
- package/src/bulk-importer/handlers/assortment/index.js +3 -0
- package/src/bulk-importer/handlers/assortment/remove.ts +15 -0
- package/src/bulk-importer/handlers/assortment/update.ts +85 -0
- package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +51 -0
- package/src/bulk-importer/handlers/assortment/upsertAssortmentContent.ts +20 -0
- package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +39 -0
- package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +55 -0
- package/src/bulk-importer/handlers/assortment/upsertMedia.ts +99 -0
- package/src/bulk-importer/handlers/filter/create.ts +62 -0
- package/src/bulk-importer/handlers/filter/index.js +3 -0
- package/src/bulk-importer/handlers/filter/remove.ts +16 -0
- package/src/bulk-importer/handlers/filter/update.ts +49 -0
- package/src/bulk-importer/handlers/filter/upsertFilterContent.ts +17 -0
- package/src/bulk-importer/handlers/filter/upsertFilterOptionContent.ts +21 -0
- package/src/bulk-importer/handlers/product/create.ts +73 -0
- package/src/bulk-importer/handlers/product/index.js +3 -0
- package/src/bulk-importer/handlers/product/remove.ts +17 -0
- package/src/bulk-importer/handlers/product/transformSpecificationToProductStructure.js +19 -0
- package/src/bulk-importer/handlers/product/update.ts +65 -0
- package/src/bulk-importer/handlers/product/upsertMedia.ts +97 -0
- package/src/bulk-importer/handlers/product/upsertProductContent.ts +23 -0
- package/src/bulk-importer/handlers/product/upsertVariations.ts +77 -0
- package/src/context/index.ts +2 -0
- package/src/context/setAccessToken.ts +15 -0
- package/src/context/withAccessToken.ts +34 -0
- package/src/migrations/createMigrationRunner.js +61 -0
- package/src/migrations/migrationRepository.ts +18 -0
- package/src/migrations/runMigrations.ts +64 -0
- package/src/platform-index.ts +2 -0
- package/src/setup/generateEventTypeDefs.js +9 -0
- package/src/setup/generateRoleActionTypeDefs.js +9 -0
- package/src/setup/generateWorkTypeDefs.js +11 -0
- package/src/setup/setupAccounts.ts +129 -0
- package/src/setup/setupAutoScheduling.ts +5 -0
- package/src/setup/setupCarts.ts +27 -0
- package/src/setup/setupTemplates.ts +17 -0
- package/src/setup/setupWorkqueue.ts +17 -0
- package/src/startPlatform.ts +145 -0
- package/src/templates/resolveAccountActionTemplate.ts +144 -0
- package/src/templates/resolveEnrollmentStatusTemplate.ts +43 -0
- package/src/templates/resolveForwardDeliveryTemplate.ts +128 -0
- package/src/templates/resolveOrderConfirmationTemplate.ts +133 -0
- package/src/templates/resolveOrderRejectionTemplate.ts +85 -0
- package/src/templates/resolveQuotationStatusTemplate.ts +54 -0
- package/src/templates/utils/getOrderAttachmentsData.ts +47 -0
- package/src/templates/utils/getOrderPositionsData.ts +49 -0
- package/tsconfig.build.json +26 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/filter/index.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default async function removeFilter(payload, { logger }, unchainedAPI) {
|
|
2
|
+
const { modules, userId } = unchainedAPI;
|
|
3
|
+
const { _id } = payload;
|
|
4
|
+
logger.debug('remove filter');
|
|
5
|
+
await modules.assortments.filters.deleteMany({ filterId: _id }, userId);
|
|
6
|
+
await modules.filters.delete(_id);
|
|
7
|
+
return {
|
|
8
|
+
entity: 'FILTER',
|
|
9
|
+
operation: 'remove',
|
|
10
|
+
_id,
|
|
11
|
+
success: true,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=remove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/filter/remove.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CAAC,OAAY,EAAE,EAAE,MAAM,EAAE,EAAE,YAAqB;IACxF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;IACzC,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IACxB,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAC9B,MAAM,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;IACxE,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAElC,OAAO;QACL,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,QAAQ;QACnB,GAAG;QACH,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/types/api';
|
|
2
|
+
export default function updateFilter(payload: any, { authorId, logger }: {
|
|
3
|
+
authorId: string;
|
|
4
|
+
logger: any;
|
|
5
|
+
}, unchainedAPI: Context): Promise<{
|
|
6
|
+
entity: string;
|
|
7
|
+
operation: string;
|
|
8
|
+
_id: any;
|
|
9
|
+
success: boolean;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import upsertFilterContent from './upsertFilterContent';
|
|
2
|
+
import upsertFilterOptionContent from './upsertFilterOptionContent';
|
|
3
|
+
export default async function updateFilter(payload, { authorId, logger }, unchainedAPI) {
|
|
4
|
+
const { modules } = unchainedAPI;
|
|
5
|
+
const { specification, _id } = payload;
|
|
6
|
+
if (!specification)
|
|
7
|
+
throw new Error('Specification is required when creating a new filter');
|
|
8
|
+
logger.debug('update filter object', specification);
|
|
9
|
+
const { content, options, ...filterData } = specification;
|
|
10
|
+
const filter = await modules.filters.update(_id, {
|
|
11
|
+
...filterData,
|
|
12
|
+
options: options?.map((option) => option.value) || [],
|
|
13
|
+
authorId,
|
|
14
|
+
}, unchainedAPI, { skipInvalidation: true }, unchainedAPI.userId);
|
|
15
|
+
if (content || options) {
|
|
16
|
+
if (!filter)
|
|
17
|
+
throw new Error(`Can't update non-existing filter ${_id}`);
|
|
18
|
+
}
|
|
19
|
+
if (content) {
|
|
20
|
+
logger.debug('replace localized content for filter', content);
|
|
21
|
+
await upsertFilterContent({ content, filter, authorId }, unchainedAPI);
|
|
22
|
+
}
|
|
23
|
+
if (options) {
|
|
24
|
+
logger.debug('replace localized content for filter options', content);
|
|
25
|
+
await upsertFilterOptionContent({ options, filter }, unchainedAPI);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
entity: 'FILTER',
|
|
29
|
+
operation: 'update',
|
|
30
|
+
_id,
|
|
31
|
+
success: true,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=update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AE,YAAY,CAAC,CAAC;KACxE;IAED,IAAI,OAAO,EAAE;QACX,MAAM,CAAC,KAAK,CAAC,8CAA8C,EAAE,OAAO,CAAC,CAAC;QACtE,MAAM,yBAAyB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,YAAY,CAAC,CAAC;KACpE;IAED,OAAO;QACL,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,QAAQ;QACnB,GAAG;QACH,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/types/api';
|
|
2
|
+
export default function upsertFilterContent({ content, filter, authorId }: {
|
|
3
|
+
content: any;
|
|
4
|
+
filter: any;
|
|
5
|
+
authorId: any;
|
|
6
|
+
}, unchainedAPI: Context): Promise<({
|
|
7
|
+
authorId: string;
|
|
8
|
+
filterId: string;
|
|
9
|
+
filterOptionValue?: string;
|
|
10
|
+
locale?: string;
|
|
11
|
+
subtitle?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
} & import("@unchainedshop/types/common").TimestampFields)[]>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export default async function upsertFilterContent({ content, filter, authorId }, unchainedAPI) {
|
|
2
|
+
return Promise.all(Object.entries(content).map(async ([locale, { authorId: tAuthorId, ...localizedData }]) => {
|
|
3
|
+
return unchainedAPI.modules.filters.texts.upsertLocalizedText({ filterId: filter._id }, locale, localizedData, tAuthorId || authorId || unchainedAPI.userId);
|
|
4
|
+
}));
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=upsertFilterContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertFilterContent.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/filter/upsertFilterContent.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,mBAAmB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,YAAqB;IACpG,OAAO,OAAO,CAAC,GAAG,CAChB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CACzB,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,aAAa,EAAE,CAAuB,EAAE,EAAE;QAClF,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAC3D,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,EACxB,MAAM,EACN,aAAa,EACb,SAAS,IAAI,QAAQ,IAAI,YAAY,CAAC,MAAM,CAC7C,CAAC;IACJ,CAAC,CACF,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default async function upsertFilterOptionContent({ options, filter }, unchainedAPI) {
|
|
2
|
+
return Promise.all((options || []).map(async ({ content: optionContent, value: optionValue }) => {
|
|
3
|
+
await Promise.all(Object.entries(optionContent).map(async ([locale, { authorId, ...localizedData }]) => {
|
|
4
|
+
return unchainedAPI.modules.filters.texts.upsertLocalizedText({ filterId: filter._id, filterOptionValue: optionValue }, locale, localizedData, authorId || unchainedAPI.userId);
|
|
5
|
+
}));
|
|
6
|
+
}));
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=upsertFilterOptionContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertFilterOptionContent.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/filter/upsertFilterOptionContent.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,yBAAyB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,YAAqB;IAChG,OAAO,OAAO,CAAC,GAAG,CAChB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE;QAC3E,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,CAC/B,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAuB,EAAE,EAAE;YACvE,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAC3D,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,iBAAiB,EAAE,WAAW,EAAE,EACxD,MAAM,EACN,aAAa,EACb,QAAQ,IAAI,YAAY,CAAC,MAAM,CAChC,CAAC;QACJ,CAAC,CACF,CACF,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/types/api';
|
|
2
|
+
export default function createProduct(payload: any, { logger, authorId, createShouldUpsertIfIDExists }: {
|
|
3
|
+
logger: any;
|
|
4
|
+
authorId: any;
|
|
5
|
+
createShouldUpsertIfIDExists: any;
|
|
6
|
+
}, unchainedAPI: Context): Promise<{
|
|
7
|
+
entity: string;
|
|
8
|
+
operation: string;
|
|
9
|
+
_id: any;
|
|
10
|
+
success: boolean;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import upsertVariations from './upsertVariations';
|
|
2
|
+
import upsertMedia from './upsertMedia';
|
|
3
|
+
import upsertProductContent from './upsertProductContent';
|
|
4
|
+
import transformSpecificationToProductStructure from './transformSpecificationToProductStructure';
|
|
5
|
+
export default async function createProduct(payload, { logger, authorId, createShouldUpsertIfIDExists }, unchainedAPI) {
|
|
6
|
+
const { modules, userId } = unchainedAPI;
|
|
7
|
+
const { specification, media, variations, _id } = payload;
|
|
8
|
+
if (!specification)
|
|
9
|
+
throw new Error(`Specification is required when creating new product ${_id}`);
|
|
10
|
+
if (!specification.content)
|
|
11
|
+
throw new Error(`Content is required when creating new product ${_id}`);
|
|
12
|
+
const productData = transformSpecificationToProductStructure(specification);
|
|
13
|
+
logger.debug('create product object', productData);
|
|
14
|
+
try {
|
|
15
|
+
await modules.products.create({
|
|
16
|
+
...productData,
|
|
17
|
+
_id,
|
|
18
|
+
authorId,
|
|
19
|
+
}, userId);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
if (!createShouldUpsertIfIDExists)
|
|
23
|
+
throw e;
|
|
24
|
+
logger.debug('entity already exists, falling back to update', specification);
|
|
25
|
+
await modules.products.update(_id, {
|
|
26
|
+
...productData,
|
|
27
|
+
authorId,
|
|
28
|
+
}, userId);
|
|
29
|
+
}
|
|
30
|
+
logger.debug('create localized content for product', specification.content);
|
|
31
|
+
await upsertProductContent({
|
|
32
|
+
content: specification.content,
|
|
33
|
+
productId: _id,
|
|
34
|
+
authorId,
|
|
35
|
+
}, unchainedAPI);
|
|
36
|
+
logger.debug('create product variations', variations);
|
|
37
|
+
await upsertVariations({
|
|
38
|
+
variations: variations || [],
|
|
39
|
+
productId: _id,
|
|
40
|
+
authorId,
|
|
41
|
+
}, unchainedAPI);
|
|
42
|
+
logger.debug('create product media', media);
|
|
43
|
+
await upsertMedia({ media: media || [], productId: _id, authorId }, unchainedAPI);
|
|
44
|
+
return {
|
|
45
|
+
entity: 'PRODUCT',
|
|
46
|
+
operation: 'create',
|
|
47
|
+
_id,
|
|
48
|
+
success: true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/create.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAC1D,OAAO,wCAAwC,MAAM,4CAA4C,CAAC;AAElG,MAAM,CAAC,OAAO,CAA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ACE,UAAU,EAAE,UAAU,IAAI,EAAE;QAC5B,SAAS,EAAE,GAAG;QACd,QAAQ;KACT,EACD,YAAY,CACb,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;IAC5C,MAAM,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,YAAY,CAAC,CAAC;IAElF,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,QAAQ;QACnB,GAAG;QACH,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/index.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default async function removeProduct(payload, { logger }, unchainedAPI) {
|
|
2
|
+
const { modules, userId } = unchainedAPI;
|
|
3
|
+
const { _id } = payload;
|
|
4
|
+
logger.debug('remove product');
|
|
5
|
+
// Use service services.product.removeProduct
|
|
6
|
+
await modules.products.delete(_id, userId);
|
|
7
|
+
return {
|
|
8
|
+
entity: 'PRODUCT',
|
|
9
|
+
operation: 'remove',
|
|
10
|
+
_id,
|
|
11
|
+
success: true,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=remove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/remove.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,aAAa,CAAC,OAAY,EAAE,EAAE,MAAM,EAAE,EAAE,YAAqB;IACzF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;IACzC,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IACxB,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAE/B,6CAA6C;IAC7C,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAE3C,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,QAAQ;QACnB,GAAG;QACH,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default (specification) => {
|
|
2
|
+
const { variationResolvers: assignments, content, // eslint-disable-line
|
|
3
|
+
warehousing: warehousingEmbeddedSupply, ...productData } = specification;
|
|
4
|
+
const { dimensions: supply, ...warehousing } = warehousingEmbeddedSupply || {};
|
|
5
|
+
const proxy = assignments ? { assignments } : undefined;
|
|
6
|
+
return {
|
|
7
|
+
...productData,
|
|
8
|
+
warehousing,
|
|
9
|
+
supply,
|
|
10
|
+
proxy,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=transformSpecificationToProductStructure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformSpecificationToProductStructure.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/transformSpecificationToProductStructure.js"],"names":[],"mappings":"AAAA,eAAe,CAAC,aAAa,EAAE,EAAE;IAC/B,MAAM,EACJ,kBAAkB,EAAE,WAAW,EAC/B,OAAO,EAAE,sBAAsB;IAC/B,WAAW,EAAE,yBAAyB,EACtC,GAAG,WAAW,EACf,GAAG,aAAa,CAAC;IAElB,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,GAAG,yBAAyB,IAAI,EAAE,CAAC;IAE/E,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAExD,OAAO;QACL,GAAG,WAAW;QACd,WAAW;QACX,MAAM;QACN,KAAK;KACN,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/types/api';
|
|
2
|
+
export default function createProduct(payload: any, { logger, authorId }: {
|
|
3
|
+
logger: any;
|
|
4
|
+
authorId: any;
|
|
5
|
+
}, unchainedAPI: Context): Promise<{
|
|
6
|
+
entity: string;
|
|
7
|
+
operation: string;
|
|
8
|
+
_id: any;
|
|
9
|
+
success: boolean;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import upsertVariations from './upsertVariations';
|
|
2
|
+
import upsertMedia from './upsertMedia';
|
|
3
|
+
import upsertProductContent from './upsertProductContent';
|
|
4
|
+
import transformSpecificationToProductStructure from './transformSpecificationToProductStructure';
|
|
5
|
+
export default async function createProduct(payload, { logger, authorId }, unchainedAPI) {
|
|
6
|
+
const { modules, userId } = unchainedAPI;
|
|
7
|
+
const { specification, media, variations, _id } = payload;
|
|
8
|
+
if (specification) {
|
|
9
|
+
const productData = transformSpecificationToProductStructure(specification);
|
|
10
|
+
logger.debug('update product object', productData);
|
|
11
|
+
await modules.products.update(_id, {
|
|
12
|
+
...productData,
|
|
13
|
+
authorId,
|
|
14
|
+
}, userId);
|
|
15
|
+
if (specification.content) {
|
|
16
|
+
logger.debug('replace localized content for product', specification.content);
|
|
17
|
+
await upsertProductContent({
|
|
18
|
+
content: specification.content,
|
|
19
|
+
productId: _id,
|
|
20
|
+
authorId,
|
|
21
|
+
}, unchainedAPI);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (variations || media) {
|
|
25
|
+
if (!(await modules.products.productExists({ productId: _id }))) {
|
|
26
|
+
throw new Error(`Can't update non-existing product ${_id}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (variations) {
|
|
30
|
+
logger.debug('replace variations', variations);
|
|
31
|
+
await upsertVariations({
|
|
32
|
+
variations: variations || [],
|
|
33
|
+
productId: _id,
|
|
34
|
+
authorId,
|
|
35
|
+
}, unchainedAPI);
|
|
36
|
+
}
|
|
37
|
+
if (media) {
|
|
38
|
+
logger.debug('replace product media', media);
|
|
39
|
+
await upsertMedia({ media, productId: _id, authorId }, unchainedAPI);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
entity: 'PRODUCT',
|
|
43
|
+
operation: 'update',
|
|
44
|
+
_id,
|
|
45
|
+
success: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/update.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAC1D,OAAO,wCAAwC,MAAM,4CAA4C,CAAC;AAElG,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,aAAa,CAAC,OAAY,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,YAAqB;IACnG,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;IACzC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAE1D,IAAI,aAAa,EAAE;QACjB,MAAM,WAAW,GAAG,wCAAwC,CAAC,aAAa,CAAC,CAAC;QAC5E,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,WAAW,CAAC,CAAC;QACnD,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAC3B,GAAG,EACH;YACE,GAAG,WAAW;YACd,QAAQ;SACT,EACD,MAAM,CACP,CAAC;QAEF,IAAI,aAAa,CAAC,OAAO,EAAE;YACzB,MAAM,CAAC,KAAK,CAAC,uCAAuC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;YAC7E,MAAM,oBAAoB,CACxB;gBACE,OAAO,EAAE,aAAa,CAAC,OAAO;gBAC9B,SAAS,EAAE,GAAG;gBACd,QAAQ;aACT,EACD,YAAY,CACb,CAAC;SACH;KACF;IAED,IAAI,UAAU,IAAI,KAAK,EAAE;QACvB,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE;YAC/D,MAAM,IAAI,KAAK,CAAC,qCAAqC,GAAG,EAAE,CAAC,CAAC;SAC7D;KACF;IAED,IAAI,UAAU,EAAE;QACd,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC;QAC/C,MAAM,gBAAgB,CACpB;YACE,UAAU,EAAE,UAAU,IAAI,EAAE;YAC5B,SAAS,EAAE,GAAG;YACd,QAAQ;SACT,EACD,YAAY,CACb,CAAC;KACH;IAED,IAAI,KAAK,EAAE;QACT,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;QAC7C,MAAM,WAAW,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,YAAY,CAAC,CAAC;KACtE;IAED,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,QAAQ;QACnB,GAAG;QACH,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const upsertAsset = async (asset, unchainedAPI) => {
|
|
2
|
+
const { modules, services, userId } = unchainedAPI;
|
|
3
|
+
const { _id, fileName, url, meta, headers, ...assetData } = asset;
|
|
4
|
+
const fileId = _id;
|
|
5
|
+
try {
|
|
6
|
+
if (_id && (await modules.files.findFile({ fileId })))
|
|
7
|
+
throw new Error('Media already exists');
|
|
8
|
+
const assetObject = await services.files.uploadFileFromURL({
|
|
9
|
+
directoryName: 'product-media',
|
|
10
|
+
fileInput: {
|
|
11
|
+
fileLink: url,
|
|
12
|
+
fileName,
|
|
13
|
+
headers,
|
|
14
|
+
},
|
|
15
|
+
meta: { ...meta, fileId },
|
|
16
|
+
userId,
|
|
17
|
+
}, unchainedAPI);
|
|
18
|
+
if (!assetObject)
|
|
19
|
+
throw new Error('Media not created');
|
|
20
|
+
return assetObject;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
if (fileId) {
|
|
24
|
+
await modules.files.update(fileId, { meta: { ...meta, fileId }, ...assetData }, userId);
|
|
25
|
+
const file = await modules.files.findFile({ fileId });
|
|
26
|
+
return file;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const upsertProductMedia = async (productMedia, { modules, userId }) => {
|
|
32
|
+
try {
|
|
33
|
+
const productMediaObj = await modules.products.media.create(productMedia, userId);
|
|
34
|
+
return productMediaObj;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
const { _id, ...productMediaData } = productMedia;
|
|
38
|
+
const productMediaId = _id;
|
|
39
|
+
return modules.products.media.update(productMediaId, productMediaData);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export default async function upsertMedia({ media, authorId, productId }, unchainedAPI) {
|
|
43
|
+
const { modules, userId } = unchainedAPI;
|
|
44
|
+
const productMediaObjects = await Promise.all(media.map(async ({ asset, content, ...mediaData }) => {
|
|
45
|
+
const file = await upsertAsset({ meta: { ...(asset.meta || {}), productId }, ...asset }, unchainedAPI);
|
|
46
|
+
if (!file)
|
|
47
|
+
throw new Error(`Unable to create binary ${asset._id}`);
|
|
48
|
+
const fileId = file._id;
|
|
49
|
+
const productMedia = await upsertProductMedia({
|
|
50
|
+
authorId,
|
|
51
|
+
...mediaData,
|
|
52
|
+
productId,
|
|
53
|
+
mediaId: file._id,
|
|
54
|
+
}, unchainedAPI);
|
|
55
|
+
if (!productMedia)
|
|
56
|
+
throw new Error(`Unable to create product media object for file ${fileId}`);
|
|
57
|
+
if (content) {
|
|
58
|
+
await Promise.all(Object.entries(content).map(async ([locale, { authorId: tAuthorId, ...localizedData }]) => {
|
|
59
|
+
return modules.products.media.texts.upsertLocalizedText(productMedia._id, locale, localizedData, tAuthorId || authorId || userId);
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
return productMedia;
|
|
63
|
+
}));
|
|
64
|
+
await modules.products.media.deleteMediaFiles({
|
|
65
|
+
productId,
|
|
66
|
+
excludedProductMediaIds: productMediaObjects.map((obj) => obj._id),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=upsertMedia.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertMedia.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/upsertMedia.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,GAAG,KAAK,EACvB,KAAqE,EACrE,YAAqB,EACrB,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;IACnD,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IAClE,MAAM,MAAM,GAAG,GAAG,CAAC;IAEnB,IAAI;QACF,IAAI,GAAG,IAAI,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAE/F,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,iBAAiB,CACxD;YACE,aAAa,EAAE,eAAe;YAC9B,SA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CAAC,CACH,CAAC;IAEF,MAAM,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC;QAC5C,SAAS;QACT,uBAAuB,EAAE,mBAAmB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC;KACnE,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default async function upsertProductContent({ productId, content, authorId }, { modules, userId }) {
|
|
2
|
+
const product = await modules.products.findProduct({ productId });
|
|
3
|
+
if (!product)
|
|
4
|
+
throw new Error(`Can't update content of non-existing product ${productId}`);
|
|
5
|
+
await Promise.all(Object.entries(content).map(async ([locale, { authorId: tAuthorId, ...localizedData }]) => {
|
|
6
|
+
return modules.products.texts.upsertLocalizedText(productId, locale, localizedData, tAuthorId || authorId || userId);
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=upsertProductContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertProductContent.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/upsertProductContent.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,oBAAoB,CAChD,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,EAChC,EAAE,OAAO,EAAE,MAAM,EAAW;IAE5B,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAClE,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,gDAAgD,SAAS,EAAE,CAAC,CAAC;IAE3F,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CACzB,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,aAAa,EAAE,CAAwB,EAAE,EAAE;QACnF,OAAO,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,mBAAmB,CAC/C,SAAS,EACT,MAAM,EACN,aAAa,EACb,SAAS,IAAI,QAAQ,IAAI,MAAM,CAChC,CAAC;IACJ,CAAC,CACF,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const upsert = async (productVariation, unchainedAPI) => {
|
|
2
|
+
const { modules, userId } = unchainedAPI;
|
|
3
|
+
try {
|
|
4
|
+
return modules.products.variations.create(productVariation, userId);
|
|
5
|
+
}
|
|
6
|
+
catch (e) {
|
|
7
|
+
return modules.products.variations.update(productVariation._id, productVariation);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export default async function upsertVariations({ variations, authorId, productId }, unchainedAPI) {
|
|
11
|
+
const { modules, userId } = unchainedAPI;
|
|
12
|
+
const productVariationObjects = await Promise.all(variations.map(async ({ content, options, ...variationsRest }) => {
|
|
13
|
+
const variation = await upsert({
|
|
14
|
+
authorId,
|
|
15
|
+
...variationsRest,
|
|
16
|
+
options: options.map((option) => option.value),
|
|
17
|
+
productId,
|
|
18
|
+
}, unchainedAPI);
|
|
19
|
+
await Promise.all(options.map(async ({ content: optionContent, value: optionValue }) => {
|
|
20
|
+
await Promise.all(Object.entries(optionContent).map(async ([locale, { authorId: tAuthorId, ...localizedData }]) => {
|
|
21
|
+
return modules.products.variations.texts.upsertLocalizedText({
|
|
22
|
+
productVariationId: variation._id,
|
|
23
|
+
productVariationOptionValue: optionValue,
|
|
24
|
+
}, locale, localizedData, tAuthorId || authorId || userId);
|
|
25
|
+
}));
|
|
26
|
+
}));
|
|
27
|
+
await Promise.all(Object.entries(content).map(async ([locale, { authorId: tAuthorId, ...localizedData }]) => {
|
|
28
|
+
return modules.products.variations.texts.upsertLocalizedText({
|
|
29
|
+
productVariationId: variation._id,
|
|
30
|
+
}, locale, localizedData, tAuthorId || authorId || userId);
|
|
31
|
+
}));
|
|
32
|
+
return variation;
|
|
33
|
+
}));
|
|
34
|
+
await modules.products.variations.deleteVariations({
|
|
35
|
+
productId,
|
|
36
|
+
excludedProductVariationIds: productVariationObjects.map((obj) => obj._id),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=upsertVariations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertVariations.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/upsertVariations.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,GAAG,KAAK,EAAE,gBAAkC,EAAE,YAAqB,EAAE,EAAE;IACjF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;IACzC,IAAI;QACF,OAAO,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;KACrE;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;KACnF;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,gBAAgB,CAC5C,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,EACnC,YAAqB;IAErB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;IAEzC,MAAM,uBAAuB,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/C,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE,EAAE;QAC/D,MAAM,SAAS,GAAG,MAAM,MAAM,CAC5B;YACE,QAAQ;YACR,GAAG,cAAc;YACjB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;YAC9C,SAAS;SACV,EACD,YAAY,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GAAG,CAAC;KAC3E,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setAccessToken.js","sourceRoot":"","sources":["../../src/context/setAccessToken.ts"],"names":[],"mappings":"AAEA,eAAe,KAAK,EAAE,YAAqB,EAAE,QAAgB,EAAE,MAAc,EAAE,EAAE;IAC/E,MAAM,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CACzC,EAAE,QAAQ,EAAE,EACZ;QACE,IAAI,EAAE;YACJ,gBAAgB,EAAE;gBAChB,MAAM;aACP;SACF;KACF,EACD,EAAE,CACH,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
const logger = createLogger('unchained:platform');
|
|
3
|
+
const contextIdentity = (params) => params;
|
|
4
|
+
export default (fn = contextIdentity) => {
|
|
5
|
+
return async (params, unchainedContextFn) => {
|
|
6
|
+
const unchainedContext = await unchainedContextFn(params);
|
|
7
|
+
const newContext = {
|
|
8
|
+
userId: unchainedContext.userId,
|
|
9
|
+
user: unchainedContext.user,
|
|
10
|
+
};
|
|
11
|
+
if (!unchainedContext.userId && params.req.headers.authorization) {
|
|
12
|
+
const [type, userToken] = params.req.headers.authorization.split(' ');
|
|
13
|
+
if (type === 'Bearer' && userToken) {
|
|
14
|
+
const [username, secret] = userToken.split(':');
|
|
15
|
+
const user = await unchainedContext.modules.users.findUser({
|
|
16
|
+
username,
|
|
17
|
+
});
|
|
18
|
+
if (secret && user?.services.token?.secret === secret) {
|
|
19
|
+
newContext.userId = user._id;
|
|
20
|
+
newContext.user = user;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
logger.warn('Token login failed');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return fn({
|
|
28
|
+
...unchainedContext,
|
|
29
|
+
...newContext,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=withAccessToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAccessToken.js","sourceRoot":"","sources":["../../src/context/withAccessToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,MAAM,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC;AAElD,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;AAE3C,eAAe,CAAC,EAAE,GAAG,eAAe,EAAE,EAAE;IACtC,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;YAChE,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;gBAClC,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;gBACH,IAAI,MAAM,IAAI,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE;oBACrD,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;oBAC7B,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC;iBACxB;qBAAM;oBACL,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;iBACnC;aACF;SACF;QACD,OAAO,EAAE,CAAC;YACR,GAAG,gBAAgB;YACnB,GAAG,UAAU;SACd,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function createMigrationRunner({ currentId, logger, migrationRepository, onMigrationComplete, unchainedAPI, }: {
|
|
2
|
+
currentId: any;
|
|
3
|
+
logger?: Console;
|
|
4
|
+
migrationRepository: any;
|
|
5
|
+
onMigrationComplete: any;
|
|
6
|
+
unchainedAPI: any;
|
|
7
|
+
}): {
|
|
8
|
+
operationFactory(action: any): (migration: any) => () => Promise<any>;
|
|
9
|
+
isIdAfterCurrentId({ id }: {
|
|
10
|
+
id: any;
|
|
11
|
+
}): boolean;
|
|
12
|
+
migrateToLatest(): any;
|
|
13
|
+
run(): Promise<any[]>;
|
|
14
|
+
};
|