@unchainedshop/platform 2.0.0-beta7 → 2.0.0-beta9
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/jest.config.js +9 -0
- package/lib/bulk-importer/handlers/assortment/create.d.ts +3 -4
- package/lib/bulk-importer/handlers/assortment/create.js +5 -10
- package/lib/bulk-importer/handlers/assortment/create.js.map +1 -1
- package/lib/bulk-importer/handlers/assortment/remove.d.ts +2 -2
- package/lib/bulk-importer/handlers/assortment/remove.js +2 -2
- package/lib/bulk-importer/handlers/assortment/remove.js.map +1 -1
- package/lib/bulk-importer/handlers/assortment/update.d.ts +3 -4
- package/lib/bulk-importer/handlers/assortment/update.js +4 -8
- package/lib/bulk-importer/handlers/assortment/update.js.map +1 -1
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.d.ts +3 -4
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js +10 -7
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js.map +1 -1
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.d.ts +3 -4
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js +3 -3
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js.map +1 -1
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.d.ts +3 -4
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js +3 -4
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js.map +1 -1
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.d.ts +3 -4
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js +8 -7
- package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js.map +1 -1
- package/lib/bulk-importer/handlers/assortment/upsertMedia.d.ts +3 -4
- package/lib/bulk-importer/handlers/assortment/upsertMedia.js +8 -38
- package/lib/bulk-importer/handlers/assortment/upsertMedia.js.map +1 -1
- package/lib/bulk-importer/handlers/filter/create.d.ts +3 -4
- package/lib/bulk-importer/handlers/filter/create.js +4 -6
- package/lib/bulk-importer/handlers/filter/create.js.map +1 -1
- package/lib/bulk-importer/handlers/filter/remove.d.ts +2 -2
- package/lib/bulk-importer/handlers/filter/remove.js +2 -2
- package/lib/bulk-importer/handlers/filter/remove.js.map +1 -1
- package/lib/bulk-importer/handlers/filter/update.d.ts +3 -4
- package/lib/bulk-importer/handlers/filter/update.js +3 -4
- package/lib/bulk-importer/handlers/filter/update.js.map +1 -1
- package/lib/bulk-importer/handlers/filter/upsertFilterContent.d.ts +3 -5
- package/lib/bulk-importer/handlers/filter/upsertFilterContent.js +3 -3
- package/lib/bulk-importer/handlers/filter/upsertFilterContent.js.map +1 -1
- package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.d.ts +2 -2
- package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js +2 -2
- package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js.map +1 -1
- package/lib/bulk-importer/handlers/product/create.d.ts +3 -4
- package/lib/bulk-importer/handlers/product/create.js +5 -9
- package/lib/bulk-importer/handlers/product/create.js.map +1 -1
- package/lib/bulk-importer/handlers/product/remove.d.ts +2 -2
- package/lib/bulk-importer/handlers/product/remove.js +1 -1
- package/lib/bulk-importer/handlers/product/remove.js.map +1 -1
- package/lib/bulk-importer/handlers/product/update.d.ts +3 -4
- package/lib/bulk-importer/handlers/product/update.js +4 -7
- package/lib/bulk-importer/handlers/product/update.js.map +1 -1
- package/lib/bulk-importer/handlers/product/upsertMedia.d.ts +3 -4
- package/lib/bulk-importer/handlers/product/upsertMedia.js +8 -38
- package/lib/bulk-importer/handlers/product/upsertMedia.js.map +1 -1
- package/lib/bulk-importer/handlers/product/upsertProductContent.d.ts +3 -4
- package/lib/bulk-importer/handlers/product/upsertProductContent.js +3 -3
- package/lib/bulk-importer/handlers/product/upsertProductContent.js.map +1 -1
- package/lib/bulk-importer/handlers/product/upsertVariations.d.ts +3 -4
- package/lib/bulk-importer/handlers/product/upsertVariations.js +16 -13
- package/lib/bulk-importer/handlers/product/upsertVariations.js.map +1 -1
- package/lib/bulk-importer/upsertAsset.d.ts +7 -0
- package/lib/bulk-importer/upsertAsset.js +33 -0
- package/lib/bulk-importer/upsertAsset.js.map +1 -0
- package/lib/context/setAccessToken.js.map +1 -1
- package/lib/context/withAccessToken.d.ts +2 -1
- package/lib/context/withAccessToken.js.map +1 -1
- package/lib/platform-index.d.ts +4 -0
- package/lib/platform-index.js +3 -0
- package/lib/platform-index.js.map +1 -1
- package/lib/setup/setupAccounts.js +2 -3
- package/lib/setup/setupAccounts.js.map +1 -1
- package/lib/setup/setupCarts.js.map +1 -1
- package/lib/startPlatform.d.ts +6 -2
- package/lib/startPlatform.js +3 -5
- package/lib/startPlatform.js.map +1 -1
- package/lib/templates/resolveQuotationStatusTemplate.js +1 -1
- package/lib/templates/resolveQuotationStatusTemplate.js.map +1 -1
- package/lib/templates/utils/getOrderAttachmentsData.d.ts +2 -2
- package/lib/templates/utils/getOrderAttachmentsData.js +3 -10
- package/lib/templates/utils/getOrderAttachmentsData.js.map +1 -1
- package/lib/templates/utils/getOrderPositionsData.d.ts +2 -2
- package/lib/templates/utils/getOrderPositionsData.js.map +1 -1
- package/package.json +15 -14
- package/src/bulk-importer/handlers/assortment/create.ts +9 -18
- package/src/bulk-importer/handlers/assortment/remove.ts +4 -4
- package/src/bulk-importer/handlers/assortment/update.ts +5 -13
- package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +10 -20
- package/src/bulk-importer/handlers/assortment/upsertAssortmentContent.ts +5 -12
- package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +4 -5
- package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +11 -20
- package/src/bulk-importer/handlers/assortment/upsertMedia.ts +15 -58
- package/src/bulk-importer/handlers/filter/create.ts +4 -8
- package/src/bulk-importer/handlers/filter/remove.ts +4 -4
- package/src/bulk-importer/handlers/filter/update.ts +4 -6
- package/src/bulk-importer/handlers/filter/upsertFilterContent.ts +5 -15
- package/src/bulk-importer/handlers/filter/upsertFilterOptionContent.ts +12 -12
- package/src/bulk-importer/handlers/product/create.ts +12 -23
- package/src/bulk-importer/handlers/product/remove.ts +3 -3
- package/src/bulk-importer/handlers/product/update.ts +7 -14
- package/src/bulk-importer/handlers/product/upsertMedia.ts +14 -54
- package/src/bulk-importer/handlers/product/upsertProductContent.ts +5 -15
- package/src/bulk-importer/handlers/product/upsertVariations.ts +26 -34
- package/src/bulk-importer/upsertAsset.ts +44 -0
- package/src/context/setAccessToken.ts +1 -1
- package/src/context/withAccessToken.ts +2 -1
- package/src/platform-index.ts +6 -0
- package/src/setup/setupAccounts.ts +7 -10
- package/src/setup/setupCarts.ts +1 -0
- package/src/startPlatform.ts +8 -8
- package/src/templates/resolveQuotationStatusTemplate.ts +2 -2
- package/src/templates/utils/getOrderAttachmentsData.ts +8 -15
- package/src/templates/utils/getOrderPositionsData.ts +2 -2
- package/tests/platform-index.test.ts +5 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function updateFilter(payload: any, {
|
|
3
|
-
authorId: string;
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
|
+
export default function updateFilter(payload: any, { logger }: {
|
|
4
3
|
logger: any;
|
|
5
|
-
}, unchainedAPI:
|
|
4
|
+
}, unchainedAPI: UnchainedCore): Promise<{
|
|
6
5
|
entity: string;
|
|
7
6
|
operation: string;
|
|
8
7
|
_id: any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import upsertFilterContent from './upsertFilterContent';
|
|
2
2
|
import upsertFilterOptionContent from './upsertFilterOptionContent';
|
|
3
|
-
export default async function updateFilter(payload, {
|
|
3
|
+
export default async function updateFilter(payload, { logger }, unchainedAPI) {
|
|
4
4
|
const { modules } = unchainedAPI;
|
|
5
5
|
const { specification, _id } = payload;
|
|
6
6
|
if (!(await modules.filters.filterExists({ filterId: _id }))) {
|
|
@@ -12,12 +12,11 @@ export default async function updateFilter(payload, { authorId, logger }, unchai
|
|
|
12
12
|
await modules.filters.update(_id, {
|
|
13
13
|
...filterData,
|
|
14
14
|
options: options?.map((option) => option.value) || [],
|
|
15
|
-
|
|
16
|
-
}, unchainedAPI, { skipInvalidation: true }, unchainedAPI.userId);
|
|
15
|
+
}, unchainedAPI, { skipInvalidation: true });
|
|
17
16
|
}
|
|
18
17
|
if (content) {
|
|
19
18
|
logger.debug('replace localized content for filter', content);
|
|
20
|
-
await upsertFilterContent({ content, filterId: _id
|
|
19
|
+
await upsertFilterContent({ content, filterId: _id }, unchainedAPI);
|
|
21
20
|
}
|
|
22
21
|
if (options) {
|
|
23
22
|
logger.debug('replace localized content for filter options', content);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/filter/update.ts"],"names":[],"mappings":"AACA,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AAEpE,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CACxC,OAAY,EACZ,EAAE,
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/filter/update.ts"],"names":[],"mappings":"AACA,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AAEpE,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CACxC,OAAY,EACZ,EAAE,MAAM,EAAmB,EAC3B,YAA2B;IAE3B,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC;IACjC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAEvC,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE;QAC5D,MAAM,IAAI,KAAK,CAAC,oCAAoC,GAAG,EAAE,CAAC,CAAC;KAC5D;IAED,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,GAAG,aAAa,CAAC;IAE1D,IAAI,aAAa,EAAE;QACjB,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC;QACpD,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAC1B,GAAG,EACH;YACE,GAAG,UAAU;YACb,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE;SACtD,EACD,YAAY,EACZ,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAC3B,CAAC;KACH;IAED,IAAI,OAAO,EAAE;QACX,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,OAAO,CAAC,CAAC;QAC9D,MAAM,mBAAmB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;KACrE;IAED,IAAI,OAAO,EAAE;QACX,MAAM,CAAC,KAAK,CAAC,8CAA8C,EAAE,OAAO,CAAC,CAAC;QACtE,MAAM,yBAAyB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;KAC3E;IAED,OAAO;QACL,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,QAAQ;QACnB,GAAG;QACH,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function upsertFilterContent({ content, filterId
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
|
+
export default function upsertFilterContent({ content, filterId }: {
|
|
3
3
|
content: any;
|
|
4
4
|
filterId: any;
|
|
5
|
-
|
|
6
|
-
}, unchainedAPI: Context): Promise<({
|
|
7
|
-
authorId: string;
|
|
5
|
+
}, unchainedAPI: UnchainedCore): Promise<({
|
|
8
6
|
filterId: string;
|
|
9
7
|
filterOptionValue?: string;
|
|
10
8
|
locale?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export default async function upsertFilterContent({ content, filterId
|
|
2
|
-
return Promise.all(Object.entries(content).map(async ([locale,
|
|
3
|
-
return unchainedAPI.modules.filters.texts.upsertLocalizedText({ filterId }, locale, localizedData
|
|
1
|
+
export default async function upsertFilterContent({ content, filterId }, unchainedAPI) {
|
|
2
|
+
return Promise.all(Object.entries(content).map(async ([locale, localizedData]) => {
|
|
3
|
+
return unchainedAPI.modules.filters.texts.upsertLocalizedText({ filterId }, locale, localizedData);
|
|
4
4
|
}));
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=upsertFilterContent.js.map
|
|
@@ -1 +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,
|
|
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,QAAQ,EAAE,EAAE,YAA2B;IAClG,OAAO,OAAO,CAAC,GAAG,CAChB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,aAAa,CAAuB,EAAE,EAAE;QAClF,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IACrG,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
2
|
export default function upsertFilterOptionContent({ options, filterId }: {
|
|
3
3
|
options: any;
|
|
4
4
|
filterId: any;
|
|
5
|
-
}, unchainedAPI:
|
|
5
|
+
}, unchainedAPI: UnchainedCore): Promise<any[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default async function upsertFilterOptionContent({ options, filterId }, unchainedAPI) {
|
|
2
2
|
return Promise.all((options || []).map(async ({ content: optionContent, value: optionValue }) => {
|
|
3
|
-
await Promise.all(Object.entries(optionContent).map(async ([locale,
|
|
4
|
-
return unchainedAPI.modules.filters.texts.upsertLocalizedText({ filterId, filterOptionValue: optionValue }, locale, localizedData
|
|
3
|
+
await Promise.all(Object.entries(optionContent).map(async ([locale, localizedData]) => {
|
|
4
|
+
return unchainedAPI.modules.filters.texts.upsertLocalizedText({ filterId, filterOptionValue: optionValue }, locale, localizedData);
|
|
5
5
|
}));
|
|
6
6
|
}));
|
|
7
7
|
}
|
|
@@ -1 +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,
|
|
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,CACrD,EAAE,OAAO,EAAE,QAAQ,EAAE,EACrB,YAA2B;IAE3B,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,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,aAAa,CAAuB,EAAE,EAAE;YACxF,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAC3D,EAAE,QAAQ,EAAE,iBAAiB,EAAE,WAAW,EAAE,EAC5C,MAAM,EACN,aAAa,CACd,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function createProduct(payload: any, { logger,
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
|
+
export default function createProduct(payload: any, { logger, createShouldUpsertIfIDExists }: {
|
|
3
3
|
logger: any;
|
|
4
|
-
authorId: any;
|
|
5
4
|
createShouldUpsertIfIDExists: any;
|
|
6
|
-
}, unchainedAPI:
|
|
5
|
+
}, unchainedAPI: UnchainedCore): Promise<{
|
|
7
6
|
entity: string;
|
|
8
7
|
operation: string;
|
|
9
8
|
_id: any;
|
|
@@ -2,8 +2,8 @@ import upsertVariations from './upsertVariations';
|
|
|
2
2
|
import upsertMedia from './upsertMedia';
|
|
3
3
|
import upsertProductContent from './upsertProductContent';
|
|
4
4
|
import transformSpecificationToProductStructure from './transformSpecificationToProductStructure';
|
|
5
|
-
export default async function createProduct(payload, { logger,
|
|
6
|
-
const { modules
|
|
5
|
+
export default async function createProduct(payload, { logger, createShouldUpsertIfIDExists }, unchainedAPI) {
|
|
6
|
+
const { modules } = unchainedAPI;
|
|
7
7
|
const { specification, media, variations, _id } = payload;
|
|
8
8
|
if (!specification)
|
|
9
9
|
throw new Error(`Specification is required when creating new product ${_id}`);
|
|
@@ -15,8 +15,7 @@ export default async function createProduct(payload, { logger, authorId, createS
|
|
|
15
15
|
await modules.products.create({
|
|
16
16
|
...productData,
|
|
17
17
|
_id,
|
|
18
|
-
|
|
19
|
-
}, userId);
|
|
18
|
+
});
|
|
20
19
|
}
|
|
21
20
|
catch (e) {
|
|
22
21
|
if (!createShouldUpsertIfIDExists)
|
|
@@ -24,8 +23,7 @@ export default async function createProduct(payload, { logger, authorId, createS
|
|
|
24
23
|
logger.debug('entity already exists, falling back to update', specification);
|
|
25
24
|
await modules.products.update(_id, {
|
|
26
25
|
...productData,
|
|
27
|
-
|
|
28
|
-
}, userId);
|
|
26
|
+
});
|
|
29
27
|
}
|
|
30
28
|
if (!(await modules.products.productExists({ productId: _id }))) {
|
|
31
29
|
throw new Error(`Can't create product ${_id}, fields missing?`);
|
|
@@ -34,16 +32,14 @@ export default async function createProduct(payload, { logger, authorId, createS
|
|
|
34
32
|
await upsertProductContent({
|
|
35
33
|
content: specification.content,
|
|
36
34
|
productId: _id,
|
|
37
|
-
authorId,
|
|
38
35
|
}, unchainedAPI);
|
|
39
36
|
logger.debug('create product variations', variations);
|
|
40
37
|
await upsertVariations({
|
|
41
38
|
variations: variations || [],
|
|
42
39
|
productId: _id,
|
|
43
|
-
authorId,
|
|
44
40
|
}, unchainedAPI);
|
|
45
41
|
logger.debug('create product media', media);
|
|
46
|
-
await upsertMedia({ media: media || [], productId: _id
|
|
42
|
+
await upsertMedia({ media: media || [], productId: _id }, unchainedAPI);
|
|
47
43
|
return {
|
|
48
44
|
entity: 'PRODUCT',
|
|
49
45
|
operation: 'create',
|
|
@@ -1 +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,CAAC,KAAK,UAAU,aAAa,CACzC,OAA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AAC,aAAa,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE;QAC/D,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,mBAAmB,CAAC,CAAC;KACjE;IAED,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAC5E,MAAM,oBAAoB,CACxB;QACE,OAAO,EAAE,aAAa,CAAC,OAAO;QAC9B,SAAS,EAAE,GAAG;KACf,EACD,YAAY,CACb,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,UAAU,CAAC,CAAC;IACtD,MAAM,gBAAgB,CACpB;QACE,UAAU,EAAE,UAAU,IAAI,EAAE;QAC5B,SAAS,EAAE,GAAG;KACf,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,EAAE,YAAY,CAAC,CAAC;IAExE,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,QAAQ;QACnB,GAAG;QACH,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
2
|
export default function removeProduct(payload: any, { logger }: {
|
|
3
3
|
logger: any;
|
|
4
|
-
}, unchainedAPI:
|
|
4
|
+
}, unchainedAPI: UnchainedCore): Promise<{
|
|
5
5
|
entity: string;
|
|
6
6
|
operation: string;
|
|
7
7
|
_id: any;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default async function removeProduct(payload, { logger }, unchainedAPI) {
|
|
2
2
|
const { services } = unchainedAPI;
|
|
3
3
|
const { _id } = payload;
|
|
4
|
-
logger.debug(
|
|
4
|
+
logger.debug(`remove product ${_id}`);
|
|
5
5
|
await services.products.removeProduct({ productId: _id }, unchainedAPI);
|
|
6
6
|
return {
|
|
7
7
|
entity: 'PRODUCT',
|
|
@@ -1 +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,
|
|
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,YAA2B;IAC/F,MAAM,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC;IAClC,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IACxB,MAAM,CAAC,KAAK,CAAC,kBAAkB,GAAG,EAAE,CAAC,CAAC;IAEtC,MAAM,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;IAExE,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,QAAQ;QACnB,GAAG;QACH,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function createProduct(payload: any, { logger
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
|
+
export default function createProduct(payload: any, { logger }: {
|
|
3
3
|
logger: any;
|
|
4
|
-
|
|
5
|
-
}, unchainedAPI: Context): Promise<{
|
|
4
|
+
}, unchainedAPI: UnchainedCore): Promise<{
|
|
6
5
|
entity: string;
|
|
7
6
|
operation: string;
|
|
8
7
|
_id: any;
|
|
@@ -2,8 +2,8 @@ import upsertVariations from './upsertVariations';
|
|
|
2
2
|
import upsertMedia from './upsertMedia';
|
|
3
3
|
import upsertProductContent from './upsertProductContent';
|
|
4
4
|
import transformSpecificationToProductStructure from './transformSpecificationToProductStructure';
|
|
5
|
-
export default async function createProduct(payload, { logger
|
|
6
|
-
const { modules
|
|
5
|
+
export default async function createProduct(payload, { logger }, unchainedAPI) {
|
|
6
|
+
const { modules } = unchainedAPI;
|
|
7
7
|
const { specification, media, variations, _id } = payload;
|
|
8
8
|
if (!(await modules.products.productExists({ productId: _id }))) {
|
|
9
9
|
throw new Error(`Can't update non-existing product ${_id}`);
|
|
@@ -13,14 +13,12 @@ export default async function createProduct(payload, { logger, authorId }, uncha
|
|
|
13
13
|
logger.debug('update product object', productData);
|
|
14
14
|
await modules.products.update(_id, {
|
|
15
15
|
...productData,
|
|
16
|
-
|
|
17
|
-
}, userId);
|
|
16
|
+
});
|
|
18
17
|
if (specification.content) {
|
|
19
18
|
logger.debug('replace localized content for product', specification.content);
|
|
20
19
|
await upsertProductContent({
|
|
21
20
|
content: specification.content,
|
|
22
21
|
productId: _id,
|
|
23
|
-
authorId,
|
|
24
22
|
}, unchainedAPI);
|
|
25
23
|
}
|
|
26
24
|
}
|
|
@@ -29,12 +27,11 @@ export default async function createProduct(payload, { logger, authorId }, uncha
|
|
|
29
27
|
await upsertVariations({
|
|
30
28
|
variations: variations || [],
|
|
31
29
|
productId: _id,
|
|
32
|
-
authorId,
|
|
33
30
|
}, unchainedAPI);
|
|
34
31
|
}
|
|
35
32
|
if (media) {
|
|
36
33
|
logger.debug('replace product media', media);
|
|
37
|
-
await upsertMedia({ media, productId: _id
|
|
34
|
+
await upsertMedia({ media, productId: _id }, unchainedAPI);
|
|
38
35
|
}
|
|
39
36
|
return {
|
|
40
37
|
entity: 'PRODUCT',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/update.ts"],"names":[],"mappings":"AACA,OAAO,gBAAg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AAC,CAAC;YAC7E,MAAM,oBAAoB,CACxB;gBACE,OAAO,EAAE,aAAa,CAAC,OAAO;gBAC9B,SAAS,EAAE,GAAG;aACf,EACD,YAAY,CACb,CAAC;SACH;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;SACf,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,EAAE,YAAY,CAAC,CAAC;KAC5D;IAED,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,QAAQ;QACnB,GAAG;QACH,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function upsertMedia({ media,
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
|
+
export default function upsertMedia({ media, productId }: {
|
|
3
3
|
media: any;
|
|
4
|
-
authorId: any;
|
|
5
4
|
productId: any;
|
|
6
|
-
}, unchainedAPI:
|
|
5
|
+
}, unchainedAPI: UnchainedCore): Promise<void>;
|
|
@@ -1,37 +1,8 @@
|
|
|
1
1
|
import convertTagsToLowerCase from '../utils/convertTagsToLowerCase';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { _id, fileName, url, meta, headers, ...assetData } = asset;
|
|
5
|
-
const fileId = _id;
|
|
2
|
+
import upsertAsset from '../../upsertAsset';
|
|
3
|
+
const upsertProductMedia = async (productMedia, { modules }) => {
|
|
6
4
|
try {
|
|
7
|
-
|
|
8
|
-
throw new Error('Media already exists');
|
|
9
|
-
const assetObject = await services.files.uploadFileFromURL({
|
|
10
|
-
directoryName: 'product-media',
|
|
11
|
-
fileInput: {
|
|
12
|
-
fileLink: url,
|
|
13
|
-
fileName,
|
|
14
|
-
headers,
|
|
15
|
-
},
|
|
16
|
-
meta: { ...meta, fileId },
|
|
17
|
-
userId,
|
|
18
|
-
}, unchainedAPI);
|
|
19
|
-
if (!assetObject)
|
|
20
|
-
throw new Error('Media not created');
|
|
21
|
-
return assetObject;
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
if (fileId) {
|
|
25
|
-
await modules.files.update(fileId, { meta: { ...meta, fileId }, ...assetData }, userId);
|
|
26
|
-
const file = await modules.files.findFile({ fileId });
|
|
27
|
-
return file;
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const upsertProductMedia = async (productMedia, { modules, userId }) => {
|
|
33
|
-
try {
|
|
34
|
-
const productMediaObj = await modules.products.media.create(productMedia, userId);
|
|
5
|
+
const productMediaObj = await modules.products.media.create(productMedia);
|
|
35
6
|
return productMediaObj;
|
|
36
7
|
}
|
|
37
8
|
catch (e) {
|
|
@@ -40,16 +11,15 @@ const upsertProductMedia = async (productMedia, { modules, userId }) => {
|
|
|
40
11
|
return modules.products.media.update(productMediaId, productMediaData);
|
|
41
12
|
}
|
|
42
13
|
};
|
|
43
|
-
export default async function upsertMedia({ media,
|
|
44
|
-
const { modules
|
|
14
|
+
export default async function upsertMedia({ media, productId }, unchainedAPI) {
|
|
15
|
+
const { modules } = unchainedAPI;
|
|
45
16
|
const productMediaObjects = await Promise.all(media.map(async ({ asset, content, ...mediaData }) => {
|
|
46
17
|
const tags = convertTagsToLowerCase(mediaData?.tags);
|
|
47
|
-
const file = await upsertAsset({ meta: { ...(asset.meta || {}), productId }, ...asset }, unchainedAPI);
|
|
18
|
+
const file = await upsertAsset('product-media', { meta: { ...(asset.meta || {}), productId }, ...asset }, unchainedAPI);
|
|
48
19
|
if (!file)
|
|
49
20
|
throw new Error(`Unable to create binary ${asset._id}`);
|
|
50
21
|
const fileId = file._id;
|
|
51
22
|
const productMedia = await upsertProductMedia({
|
|
52
|
-
authorId,
|
|
53
23
|
...mediaData,
|
|
54
24
|
tags,
|
|
55
25
|
productId,
|
|
@@ -58,8 +28,8 @@ export default async function upsertMedia({ media, authorId, productId }, unchai
|
|
|
58
28
|
if (!productMedia)
|
|
59
29
|
throw new Error(`Unable to create product media object for file ${fileId}`);
|
|
60
30
|
if (content) {
|
|
61
|
-
await Promise.all(Object.entries(content).map(async ([locale,
|
|
62
|
-
return modules.products.media.texts.upsertLocalizedText(productMedia._id, locale, localizedData
|
|
31
|
+
await Promise.all(Object.entries(content).map(async ([locale, localizedData]) => {
|
|
32
|
+
return modules.products.media.texts.upsertLocalizedText(productMedia._id, locale, localizedData);
|
|
63
33
|
}));
|
|
64
34
|
}
|
|
65
35
|
return productMedia;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertMedia.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/upsertMedia.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upsertMedia.js","sourceRoot":"","sources":["../../../../src/bulk-importer/handlers/product/upsertMedia.ts"],"names":[],"mappings":"AAEA,OAAO,sBAAsB,MAAM,iCAAiC,CAAC;AACrE,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAE5C,MAAM,kBAAkB,GAAG,KAAK,EAAE,YAA0B,EAAE,EAAE,OAAO,EAAiB,EAAE,EAAE;IAC1F,IAAI;QACF,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC1E,OAAO,eAAe,CAAC;KACxB;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,EAAE,GAAG,EAAE,GAAG,gBAAgB,EAAE,GAAG,YAAY,CAAC;QAClD,MAAM,cAAc,GAAG,GAAG,CAAC;QAC3B,OAAO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O,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CACrD,YAAY,CAAC,GAAG,EAChB,MAAM,EACN,aAAa,CACd,CAAC;YACJ,CAAC,CAAC,CACH,CAAC;SACH;QACD,OAAO,YAAY,CAAC;IACtB,CAAC,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"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function upsertProductContent({ productId, content
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
|
+
export default function upsertProductContent({ productId, content }: {
|
|
3
3
|
productId: any;
|
|
4
4
|
content: any;
|
|
5
|
-
|
|
6
|
-
}, { modules, userId }: Context): Promise<void>;
|
|
5
|
+
}, { modules }: UnchainedCore): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export default async function upsertProductContent({ productId, content
|
|
2
|
-
await Promise.all(Object.entries(content).map(async ([locale,
|
|
3
|
-
return modules.products.texts.upsertLocalizedText(productId, locale, localizedData
|
|
1
|
+
export default async function upsertProductContent({ productId, content }, { modules }) {
|
|
2
|
+
await Promise.all(Object.entries(content).map(async ([locale, localizedData]) => {
|
|
3
|
+
return modules.products.texts.upsertLocalizedText(productId, locale, localizedData);
|
|
4
4
|
}));
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=upsertProductContent.js.map
|
|
@@ -1 +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,
|
|
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,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAiB;IACnG,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,aAAa,CAAwB,EAAE,EAAE;QACnF,OAAO,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IACtF,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function upsertVariations({ variations,
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
|
+
export default function upsertVariations({ variations, productId }: {
|
|
3
3
|
variations: any;
|
|
4
|
-
authorId: any;
|
|
5
4
|
productId: any;
|
|
6
|
-
}, unchainedAPI:
|
|
5
|
+
}, unchainedAPI: UnchainedCore): Promise<void>;
|
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
const upsert = async (productVariation, unchainedAPI) => {
|
|
2
|
-
const { modules
|
|
2
|
+
const { modules } = unchainedAPI;
|
|
3
3
|
try {
|
|
4
|
-
const newVariation = await modules.products.variations.create(productVariation
|
|
4
|
+
const newVariation = await modules.products.variations.create(productVariation);
|
|
5
5
|
return newVariation;
|
|
6
6
|
}
|
|
7
7
|
catch (e) {
|
|
8
8
|
return modules.products.variations.update(productVariation._id, productVariation);
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
-
export default async function upsertVariations({ variations,
|
|
12
|
-
const { modules
|
|
13
|
-
const
|
|
11
|
+
export default async function upsertVariations({ variations, productId }, unchainedAPI) {
|
|
12
|
+
const { modules } = unchainedAPI;
|
|
13
|
+
const upsertedProductVariationIds = await Promise.all(variations.map(async ({ content, options, ...variationsRest }) => {
|
|
14
14
|
const variation = await upsert({
|
|
15
|
-
authorId,
|
|
16
15
|
...variationsRest,
|
|
17
16
|
options: options.map((option) => option.value),
|
|
18
17
|
productId,
|
|
19
18
|
}, unchainedAPI);
|
|
20
19
|
await Promise.all(options.map(async ({ content: optionContent, value: optionValue }) => {
|
|
21
|
-
await Promise.all(Object.entries(optionContent).map(async ([locale,
|
|
20
|
+
await Promise.all(Object.entries(optionContent).map(async ([locale, localizedData]) => {
|
|
22
21
|
return modules.products.variations.texts.upsertLocalizedText({
|
|
23
22
|
productVariationId: variation._id,
|
|
24
23
|
productVariationOptionValue: optionValue,
|
|
25
|
-
}, locale, localizedData
|
|
24
|
+
}, locale, localizedData);
|
|
26
25
|
}));
|
|
27
26
|
}));
|
|
28
|
-
await Promise.all(Object.entries(content).map(async ([locale,
|
|
27
|
+
await Promise.all(Object.entries(content).map(async ([locale, localizedData]) => {
|
|
29
28
|
return modules.products.variations.texts.upsertLocalizedText({
|
|
30
29
|
productVariationId: variation._id,
|
|
31
|
-
}, locale, localizedData
|
|
30
|
+
}, locale, localizedData);
|
|
32
31
|
}));
|
|
33
|
-
return variation;
|
|
32
|
+
return variation._id;
|
|
34
33
|
}));
|
|
35
|
-
await modules.products.variations.
|
|
34
|
+
const allVariations = await modules.products.variations.findProductVariations({
|
|
36
35
|
productId,
|
|
37
|
-
excludedProductVariationIds: productVariationObjects.map((obj) => obj._id),
|
|
38
36
|
});
|
|
37
|
+
await Promise.all(allVariations.map(async (variation) => {
|
|
38
|
+
if (!upsertedProductVariationIds.includes(variation._id)) {
|
|
39
|
+
await modules.products.variations.delete(variation._id);
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
39
42
|
}
|
|
40
43
|
//# sourceMappingURL=upsertVariations.js.map
|
|
@@ -1 +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,
|
|
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,YAA2B,EAAE,EAAE;IACvF,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC;IACjC,IAAI;QACF,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAChF,OAAO,YAAY,CAAC;KACrB;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,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,YAA2B;IACnG,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC;IAEjC,MAAM,2BAA2B,GAAG,MAAM,OAAO,CAAC,GAAG,CACnD,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,GAAG,cAAc;YACjB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;YAC9C,SAAS;SACV,EACD,YAAY,CACb,CAAC;QAEF,MAAM,OAAO,CAAC,GAAG,CACf,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE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1,7 @@
|
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
|
+
import { File } from '@unchainedshop/types/files';
|
|
3
|
+
declare const upsertAsset: (directoryName: string, asset: File & {
|
|
4
|
+
fileName: string;
|
|
5
|
+
headers?: Record<string, unknown>;
|
|
6
|
+
}, unchainedAPI: UnchainedCore) => Promise<File>;
|
|
7
|
+
export default upsertAsset;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const upsertAsset = async (directoryName, asset, unchainedAPI) => {
|
|
2
|
+
const { modules, services } = unchainedAPI;
|
|
3
|
+
const { _id: fileId, fileName, url, meta, headers, ...assetData } = asset;
|
|
4
|
+
try {
|
|
5
|
+
const existingFile = fileId && (await modules.files.findFile({ fileId }));
|
|
6
|
+
if (existingFile) {
|
|
7
|
+
const newMeta = { ...meta, fileId };
|
|
8
|
+
if (JSON.stringify(newMeta) === JSON.stringify(existingFile.meta)) {
|
|
9
|
+
return existingFile;
|
|
10
|
+
}
|
|
11
|
+
await modules.files.update(fileId, { meta: newMeta, ...assetData });
|
|
12
|
+
const updatedFile = await modules.files.findFile({ fileId });
|
|
13
|
+
return updatedFile;
|
|
14
|
+
}
|
|
15
|
+
const assetObject = await services.files.uploadFileFromURL({
|
|
16
|
+
directoryName,
|
|
17
|
+
fileInput: {
|
|
18
|
+
fileLink: url,
|
|
19
|
+
fileName,
|
|
20
|
+
headers,
|
|
21
|
+
},
|
|
22
|
+
meta: { ...meta, fileId },
|
|
23
|
+
}, unchainedAPI);
|
|
24
|
+
if (!assetObject)
|
|
25
|
+
throw new Error('Media not created');
|
|
26
|
+
return assetObject;
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export default upsertAsset;
|
|
33
|
+
//# sourceMappingURL=upsertAsset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertAsset.js","sourceRoot":"","sources":["../../src/bulk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AO,WAAW,CAAC;KACpB;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,IAAI,CAAC;KACb;AACH,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setAccessToken.js","sourceRoot":"","sources":["../../src/context/setAccessToken.ts"],"names":[],"mappings":"AAEA,eAAe,KAAK,EAAE,YAA2B,EAAE,QAAgB,EAAE,MAAc,
|
|
1
|
+
{"version":3,"file":"setAccessToken.js","sourceRoot":"","sources":["../../src/context/setAccessToken.ts"],"names":[],"mappings":"AAEA,eAAe,KAAK,EAAE,YAA2B,EAAE,QAAgB,EAAE,MAAc,EAAiB,EAAE;IACpG,MAAM,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CACzC,EAAE,QAAQ,EAAE,EACZ;QACE,IAAI,EAAE;YACJ,gBAAgB,EAAE;gBAChB,MAAM;aACP;SACF;KACK,EACR,EAAE,CACH,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withAccessToken.js","sourceRoot":"","sources":["../../src/context/withAccessToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"withAccessToken.js","sourceRoot":"","sources":["../../src/context/withAccessToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,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;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"}
|
package/lib/platform-index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export * from './startPlatform';
|
|
2
2
|
export * from './context';
|
|
3
|
+
declare const connectPlatformToExpress4: (expressApp: import("express").Express, { apolloGraphQLServer }: {
|
|
4
|
+
apolloGraphQLServer: import("@apollo/server").ApolloServer<import("@apollo/server").BaseContext>;
|
|
5
|
+
}) => void;
|
|
6
|
+
export { connectPlatformToExpress4 };
|
package/lib/platform-index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-index.js","sourceRoot":"","sources":["../src/platform-index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"platform-index.js","sourceRoot":"","sources":["../src/platform-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAE1B,MAAM,yBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -23,7 +23,7 @@ export const setupAccounts = (unchainedAPI) => {
|
|
|
23
23
|
type: 'MESSAGE',
|
|
24
24
|
retries: 0,
|
|
25
25
|
input,
|
|
26
|
-
}
|
|
26
|
+
});
|
|
27
27
|
};
|
|
28
28
|
accountsServer.services.guest = {
|
|
29
29
|
async authenticate(params) {
|
|
@@ -31,10 +31,8 @@ export const setupAccounts = (unchainedAPI) => {
|
|
|
31
31
|
const guestUserId = await unchainedAPI.modules.accounts.createUser({
|
|
32
32
|
email: params.email || `${guestname}@unchained.local`,
|
|
33
33
|
guest: true,
|
|
34
|
-
profile: {},
|
|
35
34
|
password: null,
|
|
36
35
|
initialPassword: true,
|
|
37
|
-
lastBillingAddress: {},
|
|
38
36
|
}, {});
|
|
39
37
|
return unchainedAPI.modules.users.findUserById(guestUserId);
|
|
40
38
|
},
|
|
@@ -52,6 +50,7 @@ export const setupAccounts = (unchainedAPI) => {
|
|
|
52
50
|
};
|
|
53
51
|
accountsServer.on('LoginTokenCreated', async (props) => {
|
|
54
52
|
const { userId, connection = {} } = props;
|
|
53
|
+
// TODO: Doubt that there is countryContext etc. here?
|
|
55
54
|
const { userIdBeforeLogin, countryContext, remoteAddress, remotePort, userAgent, normalizedLocale } = connection;
|
|
56
55
|
await unchainedAPI.modules.users.updateHeartbeat(userId, {
|
|
57
56
|
remoteAddress,
|