@unchainedshop/platform 4.0.0-rc.14 → 4.0.0-rc.16
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/bulk-importer/createBulkImporter.d.ts.map +1 -1
- package/lib/bulk-importer/createBulkImporter.js +28 -0
- package/lib/bulk-importer/createBulkImporter.js.map +1 -1
- package/lib/platform-index.d.ts +0 -1
- package/lib/platform-index.d.ts.map +1 -1
- package/lib/platform-index.js +0 -1
- package/lib/platform-index.js.map +1 -1
- package/lib/setup/setupAccounts.d.ts.map +1 -1
- package/lib/setup/setupAccounts.js +3 -8
- package/lib/setup/setupAccounts.js.map +1 -1
- package/lib/setup/setupTemplates.d.ts.map +1 -1
- package/lib/setup/setupTemplates.js +9 -24
- package/lib/setup/setupTemplates.js.map +1 -1
- package/lib/startPlatform.d.ts +2 -6
- package/lib/startPlatform.d.ts.map +1 -1
- package/lib/startPlatform.js +2 -4
- package/lib/startPlatform.js.map +1 -1
- package/package.json +10 -10
- package/src/platform-index.ts +0 -1
- package/src/setup/setupAccounts.ts +3 -8
- package/src/setup/setupTemplates.ts +9 -24
- package/src/startPlatform.ts +3 -8
- package/src/bulk-importer/createBulkImporter.ts +0 -134
- package/src/bulk-importer/handlers/assortment/create.ts +0 -86
- package/src/bulk-importer/handlers/assortment/index.ts +0 -3
- package/src/bulk-importer/handlers/assortment/remove.ts +0 -15
- package/src/bulk-importer/handlers/assortment/update.ts +0 -88
- package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +0 -49
- package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +0 -42
- package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +0 -50
- package/src/bulk-importer/handlers/assortment/upsertMedia.ts +0 -54
- package/src/bulk-importer/handlers/filter/create.ts +0 -76
- package/src/bulk-importer/handlers/filter/index.ts +0 -3
- package/src/bulk-importer/handlers/filter/remove.ts +0 -16
- package/src/bulk-importer/handlers/filter/update.ts +0 -67
- package/src/bulk-importer/handlers/product/create.ts +0 -69
- package/src/bulk-importer/handlers/product/index.ts +0 -3
- package/src/bulk-importer/handlers/product/remove.ts +0 -16
- package/src/bulk-importer/handlers/product/transformSpecificationToProductStructure.ts +0 -22
- package/src/bulk-importer/handlers/product/update.ts +0 -65
- package/src/bulk-importer/handlers/product/upsertMedia.ts +0 -60
- package/src/bulk-importer/handlers/product/upsertVariations.ts +0 -68
- package/src/bulk-importer/handlers/utils/convertTagsToLowerCase.ts +0 -4
- package/src/bulk-importer/upsertAsset.ts +0 -41
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
-
import upsertVariations from './upsertVariations.js';
|
|
3
|
-
import upsertMedia from './upsertMedia.js';
|
|
4
|
-
import transformSpecificationToProductStructure from './transformSpecificationToProductStructure.js';
|
|
5
|
-
import createProduct from './create.js';
|
|
6
|
-
|
|
7
|
-
export default async function updateProduct(
|
|
8
|
-
payload: any,
|
|
9
|
-
{ logger, updateShouldUpsertIfIDNotExists },
|
|
10
|
-
unchainedAPI: UnchainedCore,
|
|
11
|
-
) {
|
|
12
|
-
const { modules } = unchainedAPI;
|
|
13
|
-
const { specification, media, variations, _id } = payload;
|
|
14
|
-
|
|
15
|
-
if (!(await modules.products.productExists({ productId: _id }))) {
|
|
16
|
-
if (updateShouldUpsertIfIDNotExists) {
|
|
17
|
-
return createProduct(payload, { logger, createShouldUpsertIfIDExists: false }, unchainedAPI);
|
|
18
|
-
}
|
|
19
|
-
throw new Error(`Can't update non-existing product ${_id}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (specification) {
|
|
23
|
-
const productData = transformSpecificationToProductStructure(specification);
|
|
24
|
-
logger.debug('update product object', productData);
|
|
25
|
-
await modules.products.update(_id, {
|
|
26
|
-
...productData,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
if (specification.content) {
|
|
30
|
-
logger.debug('replace localized content for product', specification.content);
|
|
31
|
-
await modules.products.texts.updateTexts(
|
|
32
|
-
_id,
|
|
33
|
-
Object.entries(specification.content).map(([locale, localizedData]: [string, any]) => {
|
|
34
|
-
return {
|
|
35
|
-
locale,
|
|
36
|
-
...localizedData,
|
|
37
|
-
};
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (variations) {
|
|
44
|
-
logger.debug('replace variations', variations);
|
|
45
|
-
await upsertVariations(
|
|
46
|
-
{
|
|
47
|
-
variations: variations || [],
|
|
48
|
-
productId: _id,
|
|
49
|
-
},
|
|
50
|
-
unchainedAPI,
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (media) {
|
|
55
|
-
logger.debug('replace product media', media);
|
|
56
|
-
await upsertMedia({ media, productId: _id }, unchainedAPI);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
entity: 'PRODUCT',
|
|
61
|
-
operation: 'update',
|
|
62
|
-
_id,
|
|
63
|
-
success: true,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ProductMedia } from '@unchainedshop/core-products';
|
|
2
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
3
|
-
import convertTagsToLowerCase from '../utils/convertTagsToLowerCase.js';
|
|
4
|
-
import upsertAsset from '../../upsertAsset.js';
|
|
5
|
-
|
|
6
|
-
const upsertProductMedia = async (productMedia: ProductMedia, { modules }: UnchainedCore) => {
|
|
7
|
-
try {
|
|
8
|
-
const productMediaObj = await modules.products.media.create(productMedia);
|
|
9
|
-
return productMediaObj;
|
|
10
|
-
} catch {
|
|
11
|
-
const { _id, ...productMediaData } = productMedia;
|
|
12
|
-
const productMediaId = _id;
|
|
13
|
-
return modules.products.media.update(productMediaId, productMediaData);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default async function upsertMedia({ media, productId }, unchainedAPI: UnchainedCore) {
|
|
18
|
-
const { modules } = unchainedAPI;
|
|
19
|
-
|
|
20
|
-
const productMediaObjects = await Promise.all(
|
|
21
|
-
media.map(async ({ asset, content, ...mediaData }) => {
|
|
22
|
-
const tags = convertTagsToLowerCase(mediaData?.tags);
|
|
23
|
-
const file = await upsertAsset(
|
|
24
|
-
'product-media',
|
|
25
|
-
{ meta: { ...(asset.meta || {}), productId }, ...asset },
|
|
26
|
-
unchainedAPI,
|
|
27
|
-
);
|
|
28
|
-
if (!file) throw new Error(`Unable to create binary ${asset._id}`);
|
|
29
|
-
const fileId = file._id;
|
|
30
|
-
const productMedia = await upsertProductMedia(
|
|
31
|
-
{
|
|
32
|
-
...mediaData,
|
|
33
|
-
tags,
|
|
34
|
-
productId,
|
|
35
|
-
mediaId: file._id,
|
|
36
|
-
} as ProductMedia,
|
|
37
|
-
unchainedAPI,
|
|
38
|
-
);
|
|
39
|
-
if (!productMedia) throw new Error(`Unable to create product media object for file ${fileId}`);
|
|
40
|
-
|
|
41
|
-
if (content) {
|
|
42
|
-
await modules.products.media.texts.updateMediaTexts(
|
|
43
|
-
productMedia._id,
|
|
44
|
-
Object.entries(content).map(([locale, localizedData]: [string, any]) => {
|
|
45
|
-
return {
|
|
46
|
-
locale,
|
|
47
|
-
...localizedData,
|
|
48
|
-
};
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
return productMedia;
|
|
53
|
-
}),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
await modules.products.media.deleteMediaFiles({
|
|
57
|
-
productId,
|
|
58
|
-
excludedProductMediaIds: productMediaObjects.map((obj) => obj._id),
|
|
59
|
-
});
|
|
60
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
-
import { ProductVariation } from '@unchainedshop/core-products';
|
|
3
|
-
|
|
4
|
-
const upsert = async (productVariation: ProductVariation, unchainedAPI: UnchainedCore) => {
|
|
5
|
-
const { modules } = unchainedAPI;
|
|
6
|
-
try {
|
|
7
|
-
const newVariation = await modules.products.variations.create(productVariation);
|
|
8
|
-
return newVariation;
|
|
9
|
-
} catch {
|
|
10
|
-
return modules.products.variations.update(productVariation._id, productVariation);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default async function upsertVariations({ variations, productId }, unchainedAPI: UnchainedCore) {
|
|
15
|
-
const { modules } = unchainedAPI;
|
|
16
|
-
|
|
17
|
-
const upsertedProductVariationIds = await Promise.all(
|
|
18
|
-
variations.map(async ({ content, options, ...variationsRest }) => {
|
|
19
|
-
const variation = await upsert(
|
|
20
|
-
{
|
|
21
|
-
...variationsRest,
|
|
22
|
-
options: options.map((option) => option.value),
|
|
23
|
-
productId,
|
|
24
|
-
},
|
|
25
|
-
unchainedAPI,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
await Promise.all(
|
|
29
|
-
options.map(async ({ content: optionContent, value: optionValue }) => {
|
|
30
|
-
if (optionContent) {
|
|
31
|
-
await modules.products.variations.texts.updateVariationTexts(
|
|
32
|
-
variation._id,
|
|
33
|
-
Object.entries(optionContent).map(([locale, localizedData]: [string, any]) => {
|
|
34
|
-
return {
|
|
35
|
-
locale,
|
|
36
|
-
...localizedData,
|
|
37
|
-
};
|
|
38
|
-
}),
|
|
39
|
-
optionValue,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
}),
|
|
43
|
-
);
|
|
44
|
-
if (content) {
|
|
45
|
-
await modules.products.variations.texts.updateVariationTexts(
|
|
46
|
-
variation._id,
|
|
47
|
-
Object.entries(content).map(([locale, localizedData]: [string, any]) => {
|
|
48
|
-
return {
|
|
49
|
-
locale,
|
|
50
|
-
...localizedData,
|
|
51
|
-
};
|
|
52
|
-
}),
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return variation._id;
|
|
56
|
-
}),
|
|
57
|
-
);
|
|
58
|
-
const allVariations = await modules.products.variations.findProductVariations({
|
|
59
|
-
productId,
|
|
60
|
-
});
|
|
61
|
-
await Promise.all(
|
|
62
|
-
allVariations.map(async (variation) => {
|
|
63
|
-
if (!upsertedProductVariationIds.includes(variation._id)) {
|
|
64
|
-
await modules.products.variations.delete(variation._id);
|
|
65
|
-
}
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
68
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
-
import { File } from '@unchainedshop/core-files';
|
|
3
|
-
|
|
4
|
-
const upsertAsset = async (
|
|
5
|
-
directoryName: string,
|
|
6
|
-
asset: File & { fileName: string; headers?: Record<string, unknown> },
|
|
7
|
-
unchainedAPI: UnchainedCore,
|
|
8
|
-
) => {
|
|
9
|
-
const { modules, services } = unchainedAPI;
|
|
10
|
-
const { _id: fileId, fileName, url, meta, headers, ...assetData } = asset;
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
const existingFile = fileId && (await modules.files.findFile({ fileId }));
|
|
14
|
-
if (existingFile) {
|
|
15
|
-
if (JSON.stringify(meta) === JSON.stringify(existingFile.meta)) {
|
|
16
|
-
return existingFile;
|
|
17
|
-
}
|
|
18
|
-
await modules.files.update(fileId, { meta, ...assetData });
|
|
19
|
-
const updatedFile = await modules.files.findFile({ fileId });
|
|
20
|
-
return updatedFile;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const assetObject = await services.files.uploadFileFromURL({
|
|
24
|
-
directoryName,
|
|
25
|
-
fileInput: {
|
|
26
|
-
fileLink: url,
|
|
27
|
-
fileName,
|
|
28
|
-
fileId,
|
|
29
|
-
headers,
|
|
30
|
-
},
|
|
31
|
-
meta,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (!assetObject) throw new Error('Media not created');
|
|
35
|
-
return assetObject;
|
|
36
|
-
} catch {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export default upsertAsset;
|