@unchainedshop/platform 2.0.0-beta8 → 2.0.0-rc.1

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 (107) 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/startPlatform.js +7 -9
  64. package/lib/startPlatform.js.map +1 -1
  65. package/lib/templates/utils/getOrderAttachmentsData.d.ts +2 -2
  66. package/lib/templates/utils/getOrderAttachmentsData.js.map +1 -1
  67. package/lib/templates/utils/getOrderPositionsData.d.ts +2 -2
  68. package/lib/templates/utils/getOrderPositionsData.js.map +1 -1
  69. package/package.json +15 -14
  70. package/src/bulk-importer/handlers/assortment/create.ts +9 -18
  71. package/src/bulk-importer/handlers/assortment/remove.ts +2 -2
  72. package/src/bulk-importer/handlers/assortment/update.ts +5 -13
  73. package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +9 -18
  74. package/src/bulk-importer/handlers/assortment/upsertAssortmentContent.ts +5 -12
  75. package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +4 -5
  76. package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +10 -18
  77. package/src/bulk-importer/handlers/assortment/upsertMedia.ts +13 -20
  78. package/src/bulk-importer/handlers/filter/create.ts +4 -8
  79. package/src/bulk-importer/handlers/filter/remove.ts +2 -2
  80. package/src/bulk-importer/handlers/filter/update.ts +4 -6
  81. package/src/bulk-importer/handlers/filter/upsertFilterContent.ts +5 -15
  82. package/src/bulk-importer/handlers/filter/upsertFilterOptionContent.ts +12 -12
  83. package/src/bulk-importer/handlers/product/create.ts +12 -23
  84. package/src/bulk-importer/handlers/product/remove.ts +4 -4
  85. package/src/bulk-importer/handlers/product/update.ts +7 -14
  86. package/src/bulk-importer/handlers/product/upsertMedia.ts +12 -16
  87. package/src/bulk-importer/handlers/product/upsertProductContent.ts +5 -15
  88. package/src/bulk-importer/handlers/product/upsertVariations.ts +26 -34
  89. package/src/bulk-importer/upsertAsset.ts +4 -5
  90. package/src/setup/setupAccounts.ts +7 -8
  91. package/src/setup/setupCarts.ts +1 -0
  92. package/src/startPlatform.ts +7 -10
  93. package/src/templates/utils/getOrderAttachmentsData.ts +2 -2
  94. package/src/templates/utils/getOrderPositionsData.ts +2 -2
  95. package/tests/platform-index.test.ts +5 -0
  96. package/lib/setup/generateEventTypeDefs.d.ts +0 -1
  97. package/lib/setup/generateEventTypeDefs.js +0 -9
  98. package/lib/setup/generateEventTypeDefs.js.map +0 -1
  99. package/lib/setup/generateRoleActionTypeDefs.d.ts +0 -1
  100. package/lib/setup/generateRoleActionTypeDefs.js +0 -9
  101. package/lib/setup/generateRoleActionTypeDefs.js.map +0 -1
  102. package/lib/setup/generateWorkTypeDefs.d.ts +0 -1
  103. package/lib/setup/generateWorkTypeDefs.js +0 -11
  104. package/lib/setup/generateWorkTypeDefs.js.map +0 -1
  105. package/src/setup/generateEventTypeDefs.ts +0 -9
  106. package/src/setup/generateRoleActionTypeDefs.ts +0 -9
  107. package/src/setup/generateWorkTypeDefs.ts +0 -11
@@ -1,4 +1,4 @@
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';
@@ -6,10 +6,10 @@ import transformSpecificationToProductStructure from './transformSpecificationTo
6
6
 
7
7
  export default async function createProduct(
8
8
  payload: any,
9
- { logger, authorId, createShouldUpsertIfIDExists },
10
- unchainedAPI: Context,
9
+ { logger, createShouldUpsertIfIDExists },
10
+ unchainedAPI: UnchainedCore,
11
11
  ) {
12
- const { modules, userId } = unchainedAPI;
12
+ const { modules } = unchainedAPI;
13
13
  const { specification, media, variations, _id } = payload;
14
14
 
15
15
  if (!specification) throw new Error(`Specification is required when creating new product ${_id}`);
@@ -19,26 +19,17 @@ export default async function createProduct(
19
19
  const productData = transformSpecificationToProductStructure(specification);
20
20
  logger.debug('create product object', productData);
21
21
  try {
22
- await modules.products.create(
23
- {
24
- ...productData,
25
- _id,
26
- authorId,
27
- },
28
- userId,
29
- );
22
+ await modules.products.create({
23
+ ...productData,
24
+ _id,
25
+ });
30
26
  } catch (e) {
31
27
  if (!createShouldUpsertIfIDExists) throw e;
32
28
 
33
29
  logger.debug('entity already exists, falling back to update', specification);
34
- await modules.products.update(
35
- _id,
36
- {
37
- ...productData,
38
- authorId,
39
- },
40
- userId,
41
- );
30
+ await modules.products.update(_id, {
31
+ ...productData,
32
+ });
42
33
  }
43
34
 
44
35
  if (!(await modules.products.productExists({ productId: _id }))) {
@@ -50,7 +41,6 @@ export default async function createProduct(
50
41
  {
51
42
  content: specification.content,
52
43
  productId: _id,
53
- authorId,
54
44
  },
55
45
  unchainedAPI,
56
46
  );
@@ -60,13 +50,12 @@ export default async function createProduct(
60
50
  {
61
51
  variations: variations || [],
62
52
  productId: _id,
63
- authorId,
64
53
  },
65
54
  unchainedAPI,
66
55
  );
67
56
 
68
57
  logger.debug('create product media', media);
69
- await upsertMedia({ media: media || [], productId: _id, authorId }, unchainedAPI);
58
+ await upsertMedia({ media: media || [], productId: _id }, unchainedAPI);
70
59
 
71
60
  return {
72
61
  entity: 'PRODUCT',
@@ -1,11 +1,11 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
 
3
- export default async function removeProduct(payload: any, { logger }, unchainedAPI: Context) {
4
- const { services, userId } = unchainedAPI;
3
+ export default async function removeProduct(payload: any, { logger }, unchainedAPI: UnchainedCore) {
4
+ const { services } = unchainedAPI;
5
5
  const { _id } = payload;
6
6
  logger.debug(`remove product ${_id}`);
7
7
 
8
- await services.products.removeProduct({ productId: _id, userId }, unchainedAPI);
8
+ await services.products.removeProduct({ productId: _id }, unchainedAPI);
9
9
 
10
10
  return {
11
11
  entity: 'PRODUCT',
@@ -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,
@@ -4,11 +4,10 @@ import { initCore } from '@unchainedshop/core';
4
4
  import { initDb } from '@unchainedshop/mongodb';
5
5
  import { createLogger } from '@unchainedshop/logger';
6
6
  import { UnchainedCore } from '@unchainedshop/types/core';
7
+ import { getRegisteredEvents } from '@unchainedshop/events';
8
+ import { WorkerDirector } from '@unchainedshop/core-worker';
7
9
  import { createBulkImporterFactory } from './bulk-importer/createBulkImporter';
8
10
  import { runMigrations } from './migrations/runMigrations';
9
- import { generateEventTypeDefs } from './setup/generateEventTypeDefs';
10
- import { generateWorkerTypeDefs } from './setup/generateWorkTypeDefs';
11
- import { generateRoleActionTypeDefs } from './setup/generateRoleActionTypeDefs';
12
11
  import { setupAccounts } from './setup/setupAccounts';
13
12
  import { setupCarts } from './setup/setupCarts';
14
13
  import { setupTemplates } from './setup/setupTemplates';
@@ -85,6 +84,8 @@ export const startPlatform = async ({
85
84
  }
86
85
 
87
86
  const configuredRoles = roles.configureRoles(rolesOptions);
87
+ const configuredEvents = getRegisteredEvents();
88
+ const configuredWorkTypes = WorkerDirector.getActivePluginTypes();
88
89
 
89
90
  // Setup accountsjs specific extensions and event handlers
90
91
  setupAccounts(unchainedAPI);
@@ -92,17 +93,13 @@ export const startPlatform = async ({
92
93
  // Setup email templates
93
94
  setupTemplates();
94
95
 
95
- const generatedTypeDefs = [
96
- ...generateEventTypeDefs(),
97
- ...generateWorkerTypeDefs(),
98
- ...generateRoleActionTypeDefs(),
99
- ];
100
-
101
96
  // Start the graphQL server
102
97
  const apolloGraphQLServer = await startAPIServer({
103
98
  unchainedAPI,
104
99
  roles: configuredRoles,
105
- typeDefs: [...generatedTypeDefs, ...typeDefs],
100
+ events: configuredEvents,
101
+ workTypes: configuredWorkTypes,
102
+ typeDefs,
106
103
  resolvers,
107
104
  schema,
108
105
  plugins,
@@ -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
+ });
@@ -1 +0,0 @@
1
- export declare const generateEventTypeDefs: () => string[];
@@ -1,9 +0,0 @@
1
- import { getRegisteredEvents } from '@unchainedshop/events';
2
- export const generateEventTypeDefs = () => [
3
- /* GraphQL */ `
4
- extend enum EventType {
5
- ${getRegisteredEvents().join(',')}
6
- }
7
- `,
8
- ];
9
- //# sourceMappingURL=generateEventTypeDefs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateEventTypeDefs.js","sourceRoot":"","sources":["../../src/setup/generateEventTypeDefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE,CAAC;IACzC,aAAa,CAAC;;QAER,mBAAmB,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;;GAEpC;CACF,CAAC"}
@@ -1 +0,0 @@
1
- export declare const generateRoleActionTypeDefs: () => string[];
@@ -1,9 +0,0 @@
1
- import { roles } from '@unchainedshop/api';
2
- export const generateRoleActionTypeDefs = () => [
3
- /* GraphQL */ `
4
- extend enum RoleAction {
5
- ${Object.keys(roles.actions).join(',')}
6
- }
7
- `,
8
- ];
9
- //# sourceMappingURL=generateRoleActionTypeDefs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateRoleActionTypeDefs.js","sourceRoot":"","sources":["../../src/setup/generateRoleActionTypeDefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,EAAE,CAAC;IAC9C,aAAa,CAAC;;UAEN,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;;KAEzC;CACJ,CAAC"}
@@ -1 +0,0 @@
1
- export declare const generateWorkerTypeDefs: () => string[];
@@ -1,11 +0,0 @@
1
- import { WorkerDirector } from '@unchainedshop/core-worker';
2
- export const generateWorkerTypeDefs = () => {
3
- return [
4
- /* GraphQL */ `
5
- extend enum WorkType {
6
- ${WorkerDirector.getActivePluginTypes().join(',')}
7
- }
8
- `,
9
- ];
10
- };
11
- //# sourceMappingURL=generateWorkTypeDefs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateWorkTypeDefs.js","sourceRoot":"","sources":["../../src/setup/generateWorkTypeDefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,OAAO;QACL,aAAa,CAAC;;QAEV,cAAc,CAAC,oBAAoB,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;;GAEpD;KACA,CAAC;AACJ,CAAC,CAAC"}
@@ -1,9 +0,0 @@
1
- import { getRegisteredEvents } from '@unchainedshop/events';
2
-
3
- export const generateEventTypeDefs = () => [
4
- /* GraphQL */ `
5
- extend enum EventType {
6
- ${getRegisteredEvents().join(',')}
7
- }
8
- `,
9
- ];
@@ -1,9 +0,0 @@
1
- import { roles } from '@unchainedshop/api';
2
-
3
- export const generateRoleActionTypeDefs = () => [
4
- /* GraphQL */ `
5
- extend enum RoleAction {
6
- ${Object.keys(roles.actions).join(',')}
7
- }
8
- `,
9
- ];
@@ -1,11 +0,0 @@
1
- import { WorkerDirector } from '@unchainedshop/core-worker';
2
-
3
- export const generateWorkerTypeDefs = () => {
4
- return [
5
- /* GraphQL */ `
6
- extend enum WorkType {
7
- ${WorkerDirector.getActivePluginTypes().join(',')}
8
- }
9
- `,
10
- ];
11
- };