@unchainedshop/platform 4.0.0-rc.2 → 4.0.0-rc.21

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.
Files changed (110) hide show
  1. package/lib/bulk-importer/createBulkImporter.d.ts +5 -3
  2. package/lib/bulk-importer/createBulkImporter.d.ts.map +1 -1
  3. package/lib/bulk-importer/createBulkImporter.js.map +1 -1
  4. package/lib/context/withAccessToken.d.ts +4 -0
  5. package/lib/context/withAccessToken.d.ts.map +1 -0
  6. package/lib/context/withAccessToken.js +42 -0
  7. package/lib/context/withAccessToken.js.map +1 -0
  8. package/lib/migrations/createMigrationRunner.d.ts +1 -1
  9. package/lib/migrations/migrationRepository.d.ts.map +1 -1
  10. package/lib/migrations/migrationRepository.js +3 -0
  11. package/lib/migrations/migrationRepository.js.map +1 -1
  12. package/lib/migrations/runMigrations.d.ts.map +1 -1
  13. package/lib/migrations/runMigrations.js.map +1 -1
  14. package/lib/platform-index.d.ts +1 -1
  15. package/lib/platform-index.d.ts.map +1 -1
  16. package/lib/platform-index.js +1 -1
  17. package/lib/platform-index.js.map +1 -1
  18. package/lib/setup/setupAccounts.d.ts.map +1 -1
  19. package/lib/setup/setupAccounts.js +3 -8
  20. package/lib/setup/setupAccounts.js.map +1 -1
  21. package/lib/setup/setupTemplates.d.ts.map +1 -1
  22. package/lib/setup/setupTemplates.js +9 -24
  23. package/lib/setup/setupTemplates.js.map +1 -1
  24. package/lib/setup/setupUploadHandlers.js +1 -1
  25. package/lib/setup/setupUploadHandlers.js.map +1 -1
  26. package/lib/setup/setupWorkqueue.d.ts +3 -2
  27. package/lib/setup/setupWorkqueue.d.ts.map +1 -1
  28. package/lib/setup/setupWorkqueue.js +12 -3
  29. package/lib/setup/setupWorkqueue.js.map +1 -1
  30. package/lib/startPlatform.d.ts +2 -6
  31. package/lib/startPlatform.d.ts.map +1 -1
  32. package/lib/startPlatform.js +12 -18
  33. package/lib/startPlatform.js.map +1 -1
  34. package/lib/templates/order-parser/formatAddress.d.ts +3 -0
  35. package/lib/templates/order-parser/formatAddress.d.ts.map +1 -0
  36. package/lib/templates/order-parser/formatAddress.js +14 -0
  37. package/lib/templates/order-parser/formatAddress.js.map +1 -0
  38. package/lib/templates/order-parser/formatPrice.d.ts +6 -0
  39. package/lib/templates/order-parser/formatPrice.d.ts.map +1 -0
  40. package/lib/templates/order-parser/formatPrice.js +6 -0
  41. package/lib/templates/order-parser/formatPrice.js.map +1 -0
  42. package/lib/templates/order-parser/getOrderPositionsData.d.ts +1 -1
  43. package/lib/templates/order-parser/getOrderSummaryData.d.ts +2 -2
  44. package/lib/templates/order-parser/getOrderSummaryData.d.ts.map +1 -1
  45. package/lib/templates/order-parser/getOrderSummaryData.js +14 -8
  46. package/lib/templates/order-parser/getOrderSummaryData.js.map +1 -1
  47. package/lib/templates/order-parser/index.d.ts.map +1 -1
  48. package/lib/templates/order-parser/index.js +50 -36
  49. package/lib/templates/order-parser/index.js.map +1 -1
  50. package/lib/templates/resolveAccountActionTemplate.d.ts.map +1 -1
  51. package/lib/templates/resolveAccountActionTemplate.js +13 -13
  52. package/lib/templates/resolveAccountActionTemplate.js.map +1 -1
  53. package/lib/templates/resolveEnrollmentStatusTemplate.d.ts.map +1 -1
  54. package/lib/templates/resolveEnrollmentStatusTemplate.js +10 -16
  55. package/lib/templates/resolveEnrollmentStatusTemplate.js.map +1 -1
  56. package/lib/templates/resolveErrorReportTemplate.d.ts.map +1 -1
  57. package/lib/templates/resolveErrorReportTemplate.js +6 -11
  58. package/lib/templates/resolveErrorReportTemplate.js.map +1 -1
  59. package/lib/templates/resolveForwardDeliveryTemplate.d.ts.map +1 -1
  60. package/lib/templates/resolveForwardDeliveryTemplate.js +8 -13
  61. package/lib/templates/resolveForwardDeliveryTemplate.js.map +1 -1
  62. package/lib/templates/resolveOrderConfirmationTemplate.d.ts.map +1 -1
  63. package/lib/templates/resolveOrderConfirmationTemplate.js +8 -13
  64. package/lib/templates/resolveOrderConfirmationTemplate.js.map +1 -1
  65. package/lib/templates/resolveOrderRejectionTemplate.d.ts.map +1 -1
  66. package/lib/templates/resolveOrderRejectionTemplate.js +11 -16
  67. package/lib/templates/resolveOrderRejectionTemplate.js.map +1 -1
  68. package/lib/templates/resolveQuotationStatusTemplate.d.ts.map +1 -1
  69. package/lib/templates/resolveQuotationStatusTemplate.js +11 -17
  70. package/lib/templates/resolveQuotationStatusTemplate.js.map +1 -1
  71. package/package.json +14 -15
  72. package/src/migrations/migrationRepository.ts +5 -0
  73. package/src/migrations/runMigrations.ts +6 -1
  74. package/src/platform-index.ts +1 -1
  75. package/src/setup/setupAccounts.ts +3 -8
  76. package/src/setup/setupTemplates.ts +9 -24
  77. package/src/setup/setupUploadHandlers.ts +1 -1
  78. package/src/setup/setupWorkqueue.ts +13 -4
  79. package/src/startPlatform.ts +15 -23
  80. package/src/templates/order-parser/getOrderSummaryData.ts +18 -8
  81. package/src/templates/order-parser/index.ts +53 -43
  82. package/src/templates/resolveAccountActionTemplate.ts +25 -21
  83. package/src/templates/resolveEnrollmentStatusTemplate.ts +12 -26
  84. package/src/templates/resolveErrorReportTemplate.ts +7 -17
  85. package/src/templates/resolveForwardDeliveryTemplate.ts +9 -19
  86. package/src/templates/resolveOrderConfirmationTemplate.ts +9 -19
  87. package/src/templates/resolveOrderRejectionTemplate.ts +13 -23
  88. package/src/templates/resolveQuotationStatusTemplate.ts +11 -26
  89. package/src/bulk-importer/createBulkImporter.ts +0 -134
  90. package/src/bulk-importer/handlers/assortment/create.ts +0 -86
  91. package/src/bulk-importer/handlers/assortment/index.ts +0 -3
  92. package/src/bulk-importer/handlers/assortment/remove.ts +0 -15
  93. package/src/bulk-importer/handlers/assortment/update.ts +0 -88
  94. package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +0 -49
  95. package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +0 -42
  96. package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +0 -50
  97. package/src/bulk-importer/handlers/assortment/upsertMedia.ts +0 -54
  98. package/src/bulk-importer/handlers/filter/create.ts +0 -76
  99. package/src/bulk-importer/handlers/filter/index.ts +0 -3
  100. package/src/bulk-importer/handlers/filter/remove.ts +0 -16
  101. package/src/bulk-importer/handlers/filter/update.ts +0 -67
  102. package/src/bulk-importer/handlers/product/create.ts +0 -69
  103. package/src/bulk-importer/handlers/product/index.ts +0 -3
  104. package/src/bulk-importer/handlers/product/remove.ts +0 -16
  105. package/src/bulk-importer/handlers/product/transformSpecificationToProductStructure.ts +0 -22
  106. package/src/bulk-importer/handlers/product/update.ts +0 -65
  107. package/src/bulk-importer/handlers/product/upsertMedia.ts +0 -60
  108. package/src/bulk-importer/handlers/product/upsertVariations.ts +0 -68
  109. package/src/bulk-importer/handlers/utils/convertTagsToLowerCase.ts +0 -4
  110. package/src/bulk-importer/upsertAsset.ts +0 -41
@@ -1,67 +0,0 @@
1
- import { UnchainedCore } from '@unchainedshop/core';
2
- import createFilter from './create.js';
3
-
4
- export default async function updateFilter(
5
- payload: any,
6
- { logger, updateShouldUpsertIfIDNotExists }: { logger: any; updateShouldUpsertIfIDNotExists: boolean },
7
- unchainedAPI: UnchainedCore,
8
- ) {
9
- const { modules } = unchainedAPI;
10
- const { specification, _id } = payload;
11
-
12
- if (!(await modules.filters.filterExists({ filterId: _id }))) {
13
- if (updateShouldUpsertIfIDNotExists) {
14
- return createFilter(payload, { logger, createShouldUpsertIfIDExists: false }, unchainedAPI);
15
- }
16
- throw new Error(`Can't update non-existing filter ${_id}`);
17
- }
18
-
19
- const { content, options, ...filterData } = specification;
20
-
21
- if (specification) {
22
- logger.debug('update filter object', specification);
23
- await modules.filters.update(_id, {
24
- ...filterData,
25
- options: options?.map((option) => option.value) || [],
26
- });
27
- }
28
-
29
- if (content) {
30
- logger.debug('replace localized content for filter', content);
31
- await modules.filters.texts.updateTexts(
32
- { filterId: _id },
33
- Object.entries(content).map(([locale, localizedData]: [string, any]) => {
34
- return {
35
- locale,
36
- ...localizedData,
37
- };
38
- }),
39
- );
40
- }
41
-
42
- if (options) {
43
- logger.debug('replace localized content for filter options', content);
44
- await Promise.all(
45
- options.map(async ({ content: optionContent, value: optionValue }) => {
46
- if (optionContent) {
47
- await modules.filters.texts.updateTexts(
48
- { filterId: _id, filterOptionValue: optionValue },
49
- Object.entries(optionContent).map(([locale, localizedData]: [string, any]) => {
50
- return {
51
- locale,
52
- ...localizedData,
53
- };
54
- }),
55
- );
56
- }
57
- }),
58
- );
59
- }
60
-
61
- return {
62
- entity: 'FILTER',
63
- operation: 'update',
64
- _id,
65
- success: true,
66
- };
67
- }
@@ -1,69 +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
-
6
- export default async function createProduct(
7
- payload: any,
8
- { logger, createShouldUpsertIfIDExists },
9
- unchainedAPI: UnchainedCore,
10
- ) {
11
- const { modules } = unchainedAPI;
12
- const { specification, media, variations, _id } = payload;
13
-
14
- if (!specification) throw new Error(`Specification is required when creating new product ${_id}`);
15
-
16
- if (!specification.content) throw new Error(`Content is required when creating new product ${_id}`);
17
-
18
- const productData = transformSpecificationToProductStructure(specification);
19
- logger.debug('create product object', productData);
20
- try {
21
- await modules.products.create({
22
- ...productData,
23
- _id,
24
- });
25
- } catch (e) {
26
- if (!createShouldUpsertIfIDExists) throw e;
27
-
28
- logger.debug('entity already exists, falling back to update', specification);
29
- await modules.products.update(_id, {
30
- ...productData,
31
- });
32
- }
33
-
34
- if (!(await modules.products.productExists({ productId: _id }))) {
35
- throw new Error(`Can't create product ${_id}, fields missing?`);
36
- }
37
-
38
- if (specification.content) {
39
- logger.debug('create localized content for product', specification.content);
40
- await modules.products.texts.updateTexts(
41
- _id,
42
- Object.entries(specification.content).map(([locale, localizedData]: [string, any]) => {
43
- return {
44
- locale,
45
- ...localizedData,
46
- };
47
- }),
48
- );
49
- }
50
-
51
- logger.debug('create product variations', variations);
52
- await upsertVariations(
53
- {
54
- variations: variations || [],
55
- productId: _id,
56
- },
57
- unchainedAPI,
58
- );
59
-
60
- logger.debug('create product media', media);
61
- await upsertMedia({ media: media || [], productId: _id }, unchainedAPI);
62
-
63
- return {
64
- entity: 'PRODUCT',
65
- operation: 'create',
66
- _id,
67
- success: true,
68
- };
69
- }
@@ -1,3 +0,0 @@
1
- export { default as create } from './create.js';
2
- export { default as update } from './update.js';
3
- export { default as remove } from './remove.js';
@@ -1,16 +0,0 @@
1
- import { UnchainedCore } from '@unchainedshop/core';
2
-
3
- export default async function removeProduct(payload: any, { logger }, unchainedAPI: UnchainedCore) {
4
- const { services } = unchainedAPI;
5
- const { _id } = payload;
6
- logger.debug(`remove product ${_id}`);
7
-
8
- await services.products.removeProduct({ productId: _id });
9
-
10
- return {
11
- entity: 'PRODUCT',
12
- operation: 'remove',
13
- _id,
14
- success: true,
15
- };
16
- }
@@ -1,22 +0,0 @@
1
- import convertTagsToLowerCase from '../utils/convertTagsToLowerCase.js';
2
-
3
- export default (specification) => {
4
- const {
5
- variationResolvers: assignments,
6
- content, // eslint-disable-line
7
- warehousing: warehousingEmbeddedSupply,
8
- ...productData
9
- } = specification;
10
-
11
- const { dimensions: supply, ...warehousing } = warehousingEmbeddedSupply || {};
12
- const tags = convertTagsToLowerCase(productData?.tags);
13
- const proxy = assignments ? { assignments } : undefined;
14
-
15
- return {
16
- ...productData,
17
- tags,
18
- warehousing,
19
- supply,
20
- proxy,
21
- };
22
- };
@@ -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,4 +0,0 @@
1
- export default (tags) => {
2
- if (Array.isArray(tags)) return tags.map((tag) => tag.toLowerCase());
3
- return null;
4
- };
@@ -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;