@unchainedshop/api 4.2.2 → 4.3.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 (117) hide show
  1. package/lib/express/chatHandler.d.ts.map +1 -1
  2. package/lib/express/chatHandler.js +1 -3
  3. package/lib/express/chatHandler.js.map +1 -1
  4. package/lib/express/index.d.ts.map +1 -1
  5. package/lib/express/index.js +1 -1
  6. package/lib/express/index.js.map +1 -1
  7. package/lib/fastify/chatHandler.d.ts.map +1 -1
  8. package/lib/fastify/chatHandler.js +1 -3
  9. package/lib/fastify/chatHandler.js.map +1 -1
  10. package/lib/fastify/ercMetadataHandler.d.ts.map +1 -1
  11. package/lib/fastify/ercMetadataHandler.js +7 -4
  12. package/lib/fastify/ercMetadataHandler.js.map +1 -1
  13. package/lib/fastify/index.js +1 -1
  14. package/lib/fastify/index.js.map +1 -1
  15. package/lib/loaders/index.d.ts +27 -1
  16. package/lib/loaders/index.d.ts.map +1 -1
  17. package/lib/loaders/index.js +10 -2
  18. package/lib/loaders/index.js.map +1 -1
  19. package/lib/loaders/productBySKULoader.d.ts +10 -0
  20. package/lib/loaders/productBySKULoader.d.ts.map +1 -0
  21. package/lib/loaders/productBySKULoader.js +16 -0
  22. package/lib/loaders/productBySKULoader.js.map +1 -0
  23. package/lib/loaders/productVariationByKeyLoader.d.ts +12 -0
  24. package/lib/loaders/productVariationByKeyLoader.d.ts.map +1 -0
  25. package/lib/loaders/productVariationByKeyLoader.js +14 -0
  26. package/lib/loaders/productVariationByKeyLoader.js.map +1 -0
  27. package/lib/loaders/productVariationLoader.d.ts +10 -0
  28. package/lib/loaders/productVariationLoader.d.ts.map +1 -0
  29. package/lib/loaders/productVariationLoader.js +13 -0
  30. package/lib/loaders/productVariationLoader.js.map +1 -0
  31. package/lib/loaders/productVariationTextLoader.d.ts +14 -0
  32. package/lib/loaders/productVariationTextLoader.d.ts.map +1 -0
  33. package/lib/loaders/productVariationTextLoader.js +24 -0
  34. package/lib/loaders/productVariationTextLoader.js.map +1 -0
  35. package/lib/loaders/quotationLoader.d.ts +10 -0
  36. package/lib/loaders/quotationLoader.d.ts.map +1 -0
  37. package/lib/loaders/quotationLoader.js +13 -0
  38. package/lib/loaders/quotationLoader.js.map +1 -0
  39. package/lib/mcp/resources/localization.d.ts.map +1 -1
  40. package/lib/mcp/resources/localization.js +0 -15
  41. package/lib/mcp/resources/localization.js.map +1 -1
  42. package/lib/mongo-store.d.ts +94 -0
  43. package/lib/mongo-store.d.ts.map +1 -0
  44. package/lib/mongo-store.js +368 -0
  45. package/lib/mongo-store.js.map +1 -0
  46. package/lib/resolvers/type/delivery-provider-interface.d.ts +18 -0
  47. package/lib/resolvers/type/delivery-provider-interface.d.ts.map +1 -0
  48. package/lib/resolvers/type/delivery-provider-interface.js +48 -0
  49. package/lib/resolvers/type/delivery-provider-interface.js.map +1 -0
  50. package/lib/resolvers/type/delivery-provider-pickup-types.d.ts +20 -0
  51. package/lib/resolvers/type/delivery-provider-pickup-types.d.ts.map +1 -0
  52. package/lib/resolvers/type/delivery-provider-pickup-types.js +10 -0
  53. package/lib/resolvers/type/delivery-provider-pickup-types.js.map +1 -0
  54. package/lib/resolvers/type/delivery-provider-shipping-types.d.ts +17 -0
  55. package/lib/resolvers/type/delivery-provider-shipping-types.d.ts.map +1 -0
  56. package/lib/resolvers/type/delivery-provider-shipping-types.js +5 -0
  57. package/lib/resolvers/type/delivery-provider-shipping-types.js.map +1 -0
  58. package/lib/resolvers/type/delivery-provider-types.d.ts +7 -11
  59. package/lib/resolvers/type/delivery-provider-types.d.ts.map +1 -1
  60. package/lib/resolvers/type/delivery-provider-types.js +17 -43
  61. package/lib/resolvers/type/delivery-provider-types.js.map +1 -1
  62. package/lib/resolvers/type/index.d.ts +40 -11
  63. package/lib/resolvers/type/index.d.ts.map +1 -1
  64. package/lib/resolvers/type/index.js +4 -0
  65. package/lib/resolvers/type/index.js.map +1 -1
  66. package/lib/resolvers/type/order/order-item-types.d.ts +1 -1
  67. package/lib/resolvers/type/order/order-item-types.d.ts.map +1 -1
  68. package/lib/resolvers/type/order/order-item-types.js +2 -3
  69. package/lib/resolvers/type/order/order-item-types.js.map +1 -1
  70. package/lib/resolvers/type/price-types.d.ts.map +1 -1
  71. package/lib/resolvers/type/price-types.js +19 -5
  72. package/lib/resolvers/type/price-types.js.map +1 -1
  73. package/lib/resolvers/type/product/product-variation-assignment-vector.d.ts.map +1 -1
  74. package/lib/resolvers/type/product/product-variation-assignment-vector.js +4 -6
  75. package/lib/resolvers/type/product/product-variation-assignment-vector.js.map +1 -1
  76. package/lib/resolvers/type/product/product-variation-option-types.d.ts.map +1 -1
  77. package/lib/resolvers/type/product/product-variation-option-types.js +2 -3
  78. package/lib/resolvers/type/product/product-variation-option-types.js.map +1 -1
  79. package/lib/resolvers/type/product/product-variation-types.d.ts.map +1 -1
  80. package/lib/resolvers/type/product/product-variation-types.js +2 -3
  81. package/lib/resolvers/type/product/product-variation-types.js.map +1 -1
  82. package/lib/schema/types/delivery.d.ts.map +1 -1
  83. package/lib/schema/types/delivery.js +38 -1
  84. package/lib/schema/types/delivery.js.map +1 -1
  85. package/lib/schema/types/order/delivery.d.ts.map +1 -1
  86. package/lib/schema/types/order/delivery.js +3 -2
  87. package/lib/schema/types/order/delivery.js.map +1 -1
  88. package/lib/schema/types/order/pick-up-location.d.ts.map +1 -1
  89. package/lib/schema/types/order/pick-up-location.js +1 -2
  90. package/lib/schema/types/order/pick-up-location.js.map +1 -1
  91. package/package.json +11 -14
  92. package/src/express/chatHandler.ts +3 -8
  93. package/src/express/index.ts +3 -2
  94. package/src/fastify/chatHandler.ts +3 -8
  95. package/src/fastify/ercMetadataHandler.ts +9 -4
  96. package/src/fastify/index.ts +1 -1
  97. package/src/loaders/index.ts +11 -2
  98. package/src/loaders/productVariationByKeyLoader.ts +20 -0
  99. package/src/loaders/productVariationLoader.ts +19 -0
  100. package/src/loaders/productVariationTextLoader.ts +37 -0
  101. package/src/loaders/quotationLoader.ts +19 -0
  102. package/src/mcp/resources/localization.ts +0 -15
  103. package/src/mongo-store.ts +500 -0
  104. package/src/resolvers/type/delivery-provider-interface.ts +55 -0
  105. package/src/resolvers/type/delivery-provider-pickup-types.ts +12 -0
  106. package/src/resolvers/type/delivery-provider-shipping-types.ts +5 -0
  107. package/src/resolvers/type/delivery-provider-types.ts +22 -68
  108. package/src/resolvers/type/index.ts +4 -0
  109. package/src/resolvers/type/order/order-item-types.ts +2 -3
  110. package/src/resolvers/type/price-types.ts +19 -5
  111. package/src/resolvers/type/product/product-variation-assignment-vector.ts +4 -6
  112. package/src/resolvers/type/product/product-variation-option-types.ts +2 -3
  113. package/src/resolvers/type/product/product-variation-types.ts +2 -3
  114. package/src/schema/types/delivery.ts +38 -1
  115. package/src/schema/types/order/delivery.ts +3 -2
  116. package/src/schema/types/order/pick-up-location.ts +1 -2
  117. /package/src/loaders/{productLoaderBySKU.ts → productBySKULoader.ts} +0 -0
@@ -19,11 +19,25 @@ export const Price = {
19
19
  },
20
20
  amount(obj: PriceType) {
21
21
  if (obj.amount) {
22
- return Number(obj.amount).toLocaleString(undefined, {
23
- minimumFractionDigits: 0,
24
- maximumFractionDigits: 0,
25
- useGrouping: false,
26
- });
22
+ /*
23
+ Why toFixed(0) Is Actually Reliable
24
+ For integer rounding specifically:
25
+
26
+ Half-values are exact: Numbers like 0.5, 1.5, 2.5 can be represented exactly in binary floating-point (they're powers of 2), so they round correctly.
27
+ Floating-point errors are tiny: Even with calculation errors, they're usually on the order of 0.0000000001, which won't affect rounding to the nearest integer.
28
+ Integer boundaries are far apart: Unlike toFixed(2) where the difference between 1.004 and 1.005 matters, for toFixed(0) you need errors approaching 0.5 to cause problems.
29
+
30
+ Theoretical Edge Cases
31
+ The only cases where toFixed(0) might fail would be:
32
+ javascript// Extremely contrived calculation that should equal exactly 0.5
33
+ // but might be 0.49999999999999994 (would round to 0 instead of 1)
34
+
35
+ // Very large numbers where precision is lost entirely
36
+ (9007199254740992.5).toFixed(0) // Might have issues past MAX_SAFE_INTEGER
37
+
38
+ // But in practice, these are incredibly rare
39
+ */
40
+ return Math.round(obj.amount).toFixed(0);
27
41
  }
28
42
  return 0;
29
43
  },
@@ -17,9 +17,8 @@ export interface ProductVariationAssignmentVectorHelperTypes {
17
17
  export const ProductVariationAssignmentVector: ProductVariationAssignmentVectorHelperTypes = {
18
18
  _id: ({ product, key, value }) => `${product._id}:${key}=${value}`,
19
19
 
20
- option: async (obj, _, { modules }) => {
21
- // TODO: use product variation loader
22
- const productVariation = await modules.products.variations.findProductVariationByKey({
20
+ option: async (obj, _, { loaders }) => {
21
+ const productVariation = await loaders.productVariationByKeyLoader.load({
23
22
  productId: obj.product._id,
24
23
  key: obj.key,
25
24
  });
@@ -32,9 +31,8 @@ export const ProductVariationAssignmentVector: ProductVariationAssignmentVectorH
32
31
  };
33
32
  },
34
33
 
35
- variation: (obj, _, { modules }) => {
36
- // TODO: use product variation loader
37
- return modules.products.variations.findProductVariationByKey({
34
+ variation: (obj, _, { loaders }) => {
35
+ return loaders.productVariationByKeyLoader.load({
38
36
  productId: obj?.product?._id,
39
37
  key: obj?.key,
40
38
  });
@@ -20,9 +20,8 @@ export const ProductVariationOption: ProductVariationOptionHelperTypes = {
20
20
  return obj.productVariationOption;
21
21
  },
22
22
 
23
- texts: async (obj, { forceLocale }, { modules, locale }) => {
24
- // TODO: use variation text loader
25
- return modules.products.variations.texts.findLocalizedVariationText({
23
+ texts: async (obj, { forceLocale }, { loaders, locale }) => {
24
+ return loaders.productVariationTextLoader.load({
26
25
  productVariationId: obj._id,
27
26
  productVariationOptionValue: obj.productVariationOption,
28
27
  locale: forceLocale ? new Intl.Locale(forceLocale) : locale,
@@ -28,9 +28,8 @@ export const ProductVariation: ProductVariationHelperTypes = {
28
28
  }));
29
29
  },
30
30
 
31
- texts: async (obj, { forceLocale }, { modules, locale }) => {
32
- // TODO: use variation text loader
33
- return modules.products.variations.texts.findLocalizedVariationText({
31
+ texts: async (obj, { forceLocale }, { loaders, locale }) => {
32
+ return loaders.productVariationTextLoader.load({
34
33
  productVariationId: obj._id,
35
34
  locale: forceLocale ? new Intl.Locale(forceLocale) : locale,
36
35
  });
@@ -25,7 +25,44 @@ export default [
25
25
  WRONG_CREDENTIALS
26
26
  }
27
27
 
28
- type DeliveryProvider @cacheControl(maxAge: 60) {
28
+ interface DeliveryProvider {
29
+ _id: ID!
30
+ created: DateTime
31
+ updated: DateTime
32
+ deleted: DateTime
33
+ type: DeliveryProviderType
34
+ interface: DeliveryInterface
35
+ configuration: JSON
36
+ configurationError: DeliveryProviderError
37
+ isActive: Boolean
38
+ simulatedPrice(
39
+ currencyCode: String
40
+ useNetPrice: Boolean = false
41
+ orderId: ID
42
+ context: JSON
43
+ ): Price @cacheControl(scope: PRIVATE, maxAge: 10)
44
+ }
45
+
46
+ type DeliveryProviderPickUp implements DeliveryProvider @cacheControl(maxAge: 60) {
47
+ _id: ID!
48
+ created: DateTime
49
+ updated: DateTime
50
+ deleted: DateTime
51
+ type: DeliveryProviderType
52
+ interface: DeliveryInterface
53
+ configuration: JSON
54
+ configurationError: DeliveryProviderError
55
+ isActive: Boolean
56
+ simulatedPrice(
57
+ currencyCode: String
58
+ useNetPrice: Boolean = false
59
+ orderId: ID
60
+ context: JSON
61
+ ): Price @cacheControl(scope: PRIVATE, maxAge: 10)
62
+ pickUpLocations: [PickUpLocation!]!
63
+ }
64
+
65
+ type DeliveryProviderShipping implements DeliveryProvider @cacheControl(maxAge: 60) {
29
66
  _id: ID!
30
67
  created: DateTime
31
68
  updated: DateTime
@@ -33,8 +33,9 @@ export default [
33
33
  delivered: DateTime
34
34
  fee: Price
35
35
  discounts: [OrderDeliveryDiscount!]
36
- pickUpLocations: [OrderPickUpLocation!]!
37
- activePickUpLocation: OrderPickUpLocation
36
+ pickUpLocations: [PickUpLocation!]!
37
+ @deprecated(reason: "Use DeliveryProvider.pickupLocations instead")
38
+ activePickUpLocation: PickUpLocation
38
39
  }
39
40
 
40
41
  type OrderDeliveryShipping implements OrderDelivery {
@@ -1,8 +1,7 @@
1
1
  export default [
2
2
  /* GraphQL */ `
3
- type OrderPickUpLocation {
3
+ type PickUpLocation {
4
4
  _id: ID!
5
- order: Order!
6
5
  name: String!
7
6
  address: Address
8
7
  geoPoint: GeoPosition