@unchainedshop/platform 2.0.0-beta8 → 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.
Files changed (92) hide show
  1. package/jest.config.js +9 -0
  2. package/lib/bulk-importer/handlers/assortment/create.d.ts +3 -4
  3. package/lib/bulk-importer/handlers/assortment/create.js +5 -10
  4. package/lib/bulk-importer/handlers/assortment/create.js.map +1 -1
  5. package/lib/bulk-importer/handlers/assortment/remove.d.ts +2 -2
  6. package/lib/bulk-importer/handlers/assortment/remove.js.map +1 -1
  7. package/lib/bulk-importer/handlers/assortment/update.d.ts +3 -4
  8. package/lib/bulk-importer/handlers/assortment/update.js +4 -8
  9. package/lib/bulk-importer/handlers/assortment/update.js.map +1 -1
  10. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.d.ts +3 -4
  11. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js +8 -5
  12. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js.map +1 -1
  13. package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.d.ts +3 -4
  14. package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js +3 -3
  15. package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js.map +1 -1
  16. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.d.ts +3 -4
  17. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js +3 -4
  18. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js.map +1 -1
  19. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.d.ts +3 -4
  20. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js +6 -5
  21. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js.map +1 -1
  22. package/lib/bulk-importer/handlers/assortment/upsertMedia.d.ts +3 -4
  23. package/lib/bulk-importer/handlers/assortment/upsertMedia.js +6 -7
  24. package/lib/bulk-importer/handlers/assortment/upsertMedia.js.map +1 -1
  25. package/lib/bulk-importer/handlers/filter/create.d.ts +3 -4
  26. package/lib/bulk-importer/handlers/filter/create.js +4 -6
  27. package/lib/bulk-importer/handlers/filter/create.js.map +1 -1
  28. package/lib/bulk-importer/handlers/filter/remove.d.ts +2 -2
  29. package/lib/bulk-importer/handlers/filter/remove.js.map +1 -1
  30. package/lib/bulk-importer/handlers/filter/update.d.ts +3 -4
  31. package/lib/bulk-importer/handlers/filter/update.js +3 -4
  32. package/lib/bulk-importer/handlers/filter/update.js.map +1 -1
  33. package/lib/bulk-importer/handlers/filter/upsertFilterContent.d.ts +3 -5
  34. package/lib/bulk-importer/handlers/filter/upsertFilterContent.js +3 -3
  35. package/lib/bulk-importer/handlers/filter/upsertFilterContent.js.map +1 -1
  36. package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.d.ts +2 -2
  37. package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js +2 -2
  38. package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js.map +1 -1
  39. package/lib/bulk-importer/handlers/product/create.d.ts +3 -4
  40. package/lib/bulk-importer/handlers/product/create.js +5 -9
  41. package/lib/bulk-importer/handlers/product/create.js.map +1 -1
  42. package/lib/bulk-importer/handlers/product/remove.d.ts +2 -2
  43. package/lib/bulk-importer/handlers/product/remove.js +2 -2
  44. package/lib/bulk-importer/handlers/product/remove.js.map +1 -1
  45. package/lib/bulk-importer/handlers/product/update.d.ts +3 -4
  46. package/lib/bulk-importer/handlers/product/update.js +4 -7
  47. package/lib/bulk-importer/handlers/product/update.js.map +1 -1
  48. package/lib/bulk-importer/handlers/product/upsertMedia.d.ts +3 -4
  49. package/lib/bulk-importer/handlers/product/upsertMedia.js +6 -7
  50. package/lib/bulk-importer/handlers/product/upsertMedia.js.map +1 -1
  51. package/lib/bulk-importer/handlers/product/upsertProductContent.d.ts +3 -4
  52. package/lib/bulk-importer/handlers/product/upsertProductContent.js +3 -3
  53. package/lib/bulk-importer/handlers/product/upsertProductContent.js.map +1 -1
  54. package/lib/bulk-importer/handlers/product/upsertVariations.d.ts +3 -4
  55. package/lib/bulk-importer/handlers/product/upsertVariations.js +16 -13
  56. package/lib/bulk-importer/handlers/product/upsertVariations.js.map +1 -1
  57. package/lib/bulk-importer/upsertAsset.d.ts +2 -2
  58. package/lib/bulk-importer/upsertAsset.js +2 -3
  59. package/lib/bulk-importer/upsertAsset.js.map +1 -1
  60. package/lib/setup/setupAccounts.js +2 -1
  61. package/lib/setup/setupAccounts.js.map +1 -1
  62. package/lib/setup/setupCarts.js.map +1 -1
  63. package/lib/templates/utils/getOrderAttachmentsData.d.ts +2 -2
  64. package/lib/templates/utils/getOrderAttachmentsData.js.map +1 -1
  65. package/lib/templates/utils/getOrderPositionsData.d.ts +2 -2
  66. package/lib/templates/utils/getOrderPositionsData.js.map +1 -1
  67. package/package.json +15 -14
  68. package/src/bulk-importer/handlers/assortment/create.ts +9 -18
  69. package/src/bulk-importer/handlers/assortment/remove.ts +2 -2
  70. package/src/bulk-importer/handlers/assortment/update.ts +5 -13
  71. package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +9 -18
  72. package/src/bulk-importer/handlers/assortment/upsertAssortmentContent.ts +5 -12
  73. package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +4 -5
  74. package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +10 -18
  75. package/src/bulk-importer/handlers/assortment/upsertMedia.ts +13 -20
  76. package/src/bulk-importer/handlers/filter/create.ts +4 -8
  77. package/src/bulk-importer/handlers/filter/remove.ts +2 -2
  78. package/src/bulk-importer/handlers/filter/update.ts +4 -6
  79. package/src/bulk-importer/handlers/filter/upsertFilterContent.ts +5 -15
  80. package/src/bulk-importer/handlers/filter/upsertFilterOptionContent.ts +12 -12
  81. package/src/bulk-importer/handlers/product/create.ts +12 -23
  82. package/src/bulk-importer/handlers/product/remove.ts +4 -4
  83. package/src/bulk-importer/handlers/product/update.ts +7 -14
  84. package/src/bulk-importer/handlers/product/upsertMedia.ts +12 -16
  85. package/src/bulk-importer/handlers/product/upsertProductContent.ts +5 -15
  86. package/src/bulk-importer/handlers/product/upsertVariations.ts +26 -34
  87. package/src/bulk-importer/upsertAsset.ts +4 -5
  88. package/src/setup/setupAccounts.ts +7 -8
  89. package/src/setup/setupCarts.ts +1 -0
  90. package/src/templates/utils/getOrderAttachmentsData.ts +2 -2
  91. package/src/templates/utils/getOrderPositionsData.ts +2 -2
  92. package/tests/platform-index.test.ts +5 -0
@@ -1,11 +1,11 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import upsertVariations from './upsertVariations';
3
3
  import upsertMedia from './upsertMedia';
4
4
  import upsertProductContent from './upsertProductContent';
5
5
  import transformSpecificationToProductStructure from './transformSpecificationToProductStructure';
6
6
 
7
- export default async function createProduct(payload: any, { logger, authorId }, unchainedAPI: Context) {
8
- const { modules, userId } = unchainedAPI;
7
+ export default async function createProduct(payload: any, { logger }, unchainedAPI: UnchainedCore) {
8
+ const { modules } = unchainedAPI;
9
9
  const { specification, media, variations, _id } = payload;
10
10
 
11
11
  if (!(await modules.products.productExists({ productId: _id }))) {
@@ -15,14 +15,9 @@ export default async function createProduct(payload: any, { logger, authorId },
15
15
  if (specification) {
16
16
  const productData = transformSpecificationToProductStructure(specification);
17
17
  logger.debug('update product object', productData);
18
- await modules.products.update(
19
- _id,
20
- {
21
- ...productData,
22
- authorId,
23
- },
24
- userId,
25
- );
18
+ await modules.products.update(_id, {
19
+ ...productData,
20
+ });
26
21
 
27
22
  if (specification.content) {
28
23
  logger.debug('replace localized content for product', specification.content);
@@ -30,7 +25,6 @@ export default async function createProduct(payload: any, { logger, authorId },
30
25
  {
31
26
  content: specification.content,
32
27
  productId: _id,
33
- authorId,
34
28
  },
35
29
  unchainedAPI,
36
30
  );
@@ -43,7 +37,6 @@ export default async function createProduct(payload: any, { logger, authorId },
43
37
  {
44
38
  variations: variations || [],
45
39
  productId: _id,
46
- authorId,
47
40
  },
48
41
  unchainedAPI,
49
42
  );
@@ -51,7 +44,7 @@ export default async function createProduct(payload: any, { logger, authorId },
51
44
 
52
45
  if (media) {
53
46
  logger.debug('replace product media', media);
54
- await upsertMedia({ media, productId: _id, authorId }, unchainedAPI);
47
+ await upsertMedia({ media, productId: _id }, unchainedAPI);
55
48
  }
56
49
 
57
50
  return {
@@ -1,11 +1,11 @@
1
- import { Context } from '@unchainedshop/types/api';
2
1
  import { ProductMedia, ProductMediaText } from '@unchainedshop/types/products.media';
2
+ import { UnchainedCore } from '@unchainedshop/types/core';
3
3
  import convertTagsToLowerCase from '../utils/convertTagsToLowerCase';
4
4
  import upsertAsset from '../../upsertAsset';
5
5
 
6
- const upsertProductMedia = async (productMedia: ProductMedia, { modules, userId }: Context) => {
6
+ const upsertProductMedia = async (productMedia: ProductMedia, { modules }: UnchainedCore) => {
7
7
  try {
8
- const productMediaObj = await modules.products.media.create(productMedia, userId);
8
+ const productMediaObj = await modules.products.media.create(productMedia);
9
9
  return productMediaObj;
10
10
  } catch (e) {
11
11
  const { _id, ...productMediaData } = productMedia;
@@ -14,8 +14,8 @@ const upsertProductMedia = async (productMedia: ProductMedia, { modules, userId
14
14
  }
15
15
  };
16
16
 
17
- export default async function upsertMedia({ media, authorId, productId }, unchainedAPI: Context) {
18
- const { modules, userId } = unchainedAPI;
17
+ export default async function upsertMedia({ media, productId }, unchainedAPI: UnchainedCore) {
18
+ const { modules } = unchainedAPI;
19
19
 
20
20
  const productMediaObjects = await Promise.all(
21
21
  media.map(async ({ asset, content, ...mediaData }) => {
@@ -29,7 +29,6 @@ export default async function upsertMedia({ media, authorId, productId }, unchai
29
29
  const fileId = file._id;
30
30
  const productMedia = await upsertProductMedia(
31
31
  {
32
- authorId,
33
32
  ...mediaData,
34
33
  tags,
35
34
  productId,
@@ -41,16 +40,13 @@ export default async function upsertMedia({ media, authorId, productId }, unchai
41
40
 
42
41
  if (content) {
43
42
  await Promise.all(
44
- Object.entries(content).map(
45
- async ([locale, { authorId: tAuthorId, ...localizedData }]: [string, ProductMediaText]) => {
46
- return modules.products.media.texts.upsertLocalizedText(
47
- productMedia._id,
48
- locale,
49
- localizedData,
50
- tAuthorId || authorId || userId,
51
- );
52
- },
53
- ),
43
+ Object.entries(content).map(async ([locale, localizedData]: [string, ProductMediaText]) => {
44
+ return modules.products.media.texts.upsertLocalizedText(
45
+ productMedia._id,
46
+ locale,
47
+ localizedData,
48
+ );
49
+ }),
54
50
  );
55
51
  }
56
52
  return productMedia;
@@ -1,20 +1,10 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import { ProductText } from '@unchainedshop/types/products';
3
3
 
4
- export default async function upsertProductContent(
5
- { productId, content, authorId },
6
- { modules, userId }: Context,
7
- ) {
4
+ export default async function upsertProductContent({ productId, content }, { modules }: UnchainedCore) {
8
5
  await Promise.all(
9
- Object.entries(content).map(
10
- async ([locale, { authorId: tAuthorId, ...localizedData }]: [string, ProductText]) => {
11
- return modules.products.texts.upsertLocalizedText(
12
- productId,
13
- locale,
14
- localizedData,
15
- tAuthorId || authorId || userId,
16
- );
17
- },
18
- ),
6
+ Object.entries(content).map(async ([locale, localizedData]: [string, ProductText]) => {
7
+ return modules.products.texts.upsertLocalizedText(productId, locale, localizedData);
8
+ }),
19
9
  );
20
10
  }
@@ -1,27 +1,23 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import { ProductVariation, ProductVariationText } from '@unchainedshop/types/products.variations';
3
3
 
4
- const upsert = async (productVariation: ProductVariation, unchainedAPI: Context) => {
5
- const { modules, userId } = unchainedAPI;
4
+ const upsert = async (productVariation: ProductVariation, unchainedAPI: UnchainedCore) => {
5
+ const { modules } = unchainedAPI;
6
6
  try {
7
- const newVariation = await modules.products.variations.create(productVariation, userId);
7
+ const newVariation = await modules.products.variations.create(productVariation);
8
8
  return newVariation;
9
9
  } catch (e) {
10
10
  return modules.products.variations.update(productVariation._id, productVariation);
11
11
  }
12
12
  };
13
13
 
14
- export default async function upsertVariations(
15
- { variations, authorId, productId },
16
- unchainedAPI: Context,
17
- ) {
18
- const { modules, userId } = unchainedAPI;
14
+ export default async function upsertVariations({ variations, productId }, unchainedAPI: UnchainedCore) {
15
+ const { modules } = unchainedAPI;
19
16
 
20
- const productVariationObjects = await Promise.all(
17
+ const upsertedProductVariationIds = await Promise.all(
21
18
  variations.map(async ({ content, options, ...variationsRest }) => {
22
19
  const variation = await upsert(
23
20
  {
24
- authorId,
25
21
  ...variationsRest,
26
22
  options: options.map((option) => option.value),
27
23
  productId,
@@ -33,10 +29,7 @@ export default async function upsertVariations(
33
29
  options.map(async ({ content: optionContent, value: optionValue }) => {
34
30
  await Promise.all(
35
31
  Object.entries(optionContent).map(
36
- async ([locale, { authorId: tAuthorId, ...localizedData }]: [
37
- string,
38
- ProductVariationText,
39
- ]) => {
32
+ async ([locale, localizedData]: [string, ProductVariationText]) => {
40
33
  return modules.products.variations.texts.upsertLocalizedText(
41
34
  {
42
35
  productVariationId: variation._id,
@@ -44,7 +37,6 @@ export default async function upsertVariations(
44
37
  },
45
38
  locale,
46
39
  localizedData,
47
- tAuthorId || authorId || userId,
48
40
  );
49
41
  },
50
42
  ),
@@ -52,27 +44,27 @@ export default async function upsertVariations(
52
44
  }),
53
45
  );
54
46
  await Promise.all(
55
- Object.entries(content).map(
56
- async ([locale, { authorId: tAuthorId, ...localizedData }]: [
57
- string,
58
- ProductVariationText,
59
- ]) => {
60
- return modules.products.variations.texts.upsertLocalizedText(
61
- {
62
- productVariationId: variation._id,
63
- },
64
- locale,
65
- localizedData,
66
- tAuthorId || authorId || userId,
67
- );
68
- },
69
- ),
47
+ Object.entries(content).map(async ([locale, localizedData]: [string, ProductVariationText]) => {
48
+ return modules.products.variations.texts.upsertLocalizedText(
49
+ {
50
+ productVariationId: variation._id,
51
+ },
52
+ locale,
53
+ localizedData,
54
+ );
55
+ }),
70
56
  );
71
- return variation;
57
+ return variation._id;
72
58
  }),
73
59
  );
74
- await modules.products.variations.deleteVariations({
60
+ const allVariations = await modules.products.variations.findProductVariations({
75
61
  productId,
76
- excludedProductVariationIds: productVariationObjects.map((obj) => obj._id),
77
62
  });
63
+ await Promise.all(
64
+ allVariations.map(async (variation) => {
65
+ if (!upsertedProductVariationIds.includes(variation._id)) {
66
+ await modules.products.variations.delete(variation._id);
67
+ }
68
+ }),
69
+ );
78
70
  }
@@ -1,12 +1,12 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import { File } from '@unchainedshop/types/files';
3
3
 
4
4
  const upsertAsset = async (
5
5
  directoryName: string,
6
6
  asset: File & { fileName: string; headers?: Record<string, unknown> },
7
- unchainedAPI: Context,
7
+ unchainedAPI: UnchainedCore,
8
8
  ) => {
9
- const { modules, services, userId } = unchainedAPI;
9
+ const { modules, services } = unchainedAPI;
10
10
  const { _id: fileId, fileName, url, meta, headers, ...assetData } = asset;
11
11
 
12
12
  try {
@@ -16,7 +16,7 @@ const upsertAsset = async (
16
16
  if (JSON.stringify(newMeta) === JSON.stringify(existingFile.meta)) {
17
17
  return existingFile;
18
18
  }
19
- await modules.files.update(fileId, { meta: newMeta, ...assetData }, userId);
19
+ await modules.files.update(fileId, { meta: newMeta, ...assetData });
20
20
  const updatedFile = await modules.files.findFile({ fileId });
21
21
  return updatedFile;
22
22
  }
@@ -30,7 +30,6 @@ const upsertAsset = async (
30
30
  headers,
31
31
  },
32
32
  meta: { ...meta, fileId },
33
- userId,
34
33
  },
35
34
  unchainedAPI,
36
35
  );
@@ -29,14 +29,11 @@ export const setupAccounts = (unchainedAPI: UnchainedCore) => {
29
29
  if (!input) return true;
30
30
  if (input.skipMessaging) return true;
31
31
 
32
- return unchainedAPI.modules.worker.addWork(
33
- {
34
- type: 'MESSAGE',
35
- retries: 0,
36
- input,
37
- },
38
- undefined,
39
- );
32
+ return unchainedAPI.modules.worker.addWork({
33
+ type: 'MESSAGE',
34
+ retries: 0,
35
+ input,
36
+ });
40
37
  };
41
38
 
42
39
  accountsServer.services.guest = {
@@ -76,6 +73,8 @@ export const setupAccounts = (unchainedAPI: UnchainedCore) => {
76
73
 
77
74
  accountsServer.on('LoginTokenCreated', async (props) => {
78
75
  const { userId, connection = {} } = props;
76
+
77
+ // TODO: Doubt that there is countryContext etc. here?
79
78
  const { userIdBeforeLogin, countryContext, remoteAddress, remotePort, userAgent, normalizedLocale } =
80
79
  connection;
81
80
 
@@ -17,6 +17,7 @@ export const setupCarts = async (unchainedAPI: UnchainedCore, options: SetupCart
17
17
  await Promise.all(
18
18
  users.map((user) => {
19
19
  const locale = unchainedAPI.modules.users.userLocale(user);
20
+
20
21
  return unchainedAPI.modules.orders.ensureCartForUser(
21
22
  { user, countryCode: locale.country },
22
23
  unchainedAPI,
@@ -1,10 +1,10 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import { Order } from '@unchainedshop/types/orders';
3
3
 
4
4
  export const getOrderAttachmentsData = async (
5
5
  order: Order,
6
6
  params: { fileType: string },
7
- { modules }: Context,
7
+ { modules }: UnchainedCore,
8
8
  ) => {
9
9
  const attachments = [];
10
10
 
@@ -1,11 +1,11 @@
1
- import { Context } from '@unchainedshop/types/api';
2
1
  import { Locale } from '@unchainedshop/types/common';
2
+ import { UnchainedCore } from '@unchainedshop/types/core';
3
3
  import { Order } from '@unchainedshop/types/orders';
4
4
 
5
5
  export const getOrderPositionsData = async (
6
6
  order: Order,
7
7
  params: { locale?: Locale },
8
- context: Context,
8
+ context: UnchainedCore,
9
9
  ) => {
10
10
  const { modules } = context;
11
11
  const orderPositions = await modules.orders.positions.findOrderPositions({
@@ -0,0 +1,5 @@
1
+ describe('Platform', () => {
2
+ it('Init', async () => {
3
+ expect(true).toBeTruthy()
4
+ });
5
+ });