@unchainedshop/core 4.6.1 → 4.7.2

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 (171) hide show
  1. package/lib/core-index.d.ts +3 -0
  2. package/lib/core-index.js +6 -2
  3. package/lib/directors/BaseDiscountDirector.js +6 -6
  4. package/lib/directors/BasePricingDirector.js +1 -1
  5. package/lib/directors/DeliveryAdapter.js +1 -0
  6. package/lib/directors/DeliveryDirector.js +11 -2
  7. package/lib/directors/DeliveryPricingAdapter.d.ts +2 -1
  8. package/lib/directors/DeliveryPricingAdapter.js +2 -1
  9. package/lib/directors/DeliveryPricingDirector.d.ts +1 -1
  10. package/lib/directors/DeliveryPricingDirector.js +12 -2
  11. package/lib/directors/DeliveryPricingSheet.d.ts +1 -1
  12. package/lib/directors/DeliveryPricingSheet.js +1 -1
  13. package/lib/directors/EnrollmentAdapter.js +1 -0
  14. package/lib/directors/EnrollmentDirector.js +11 -1
  15. package/lib/directors/FileDirector.d.ts +10 -0
  16. package/lib/directors/FileDirector.js +25 -0
  17. package/lib/directors/FilterAdapter.js +1 -0
  18. package/lib/directors/FilterDirector.js +11 -1
  19. package/lib/directors/OrderDiscountAdapter.d.ts +3 -2
  20. package/lib/directors/OrderDiscountAdapter.js +5 -2
  21. package/lib/directors/OrderDiscountDirector.d.ts +15 -1
  22. package/lib/directors/OrderDiscountDirector.js +14 -1
  23. package/lib/directors/OrderPricingAdapter.d.ts +2 -1
  24. package/lib/directors/OrderPricingAdapter.js +3 -1
  25. package/lib/directors/OrderPricingDirector.d.ts +4 -1
  26. package/lib/directors/OrderPricingDirector.js +12 -1
  27. package/lib/directors/OrderPricingSheet.d.ts +1 -1
  28. package/lib/directors/OrderPricingSheet.js +1 -1
  29. package/lib/directors/PaymentAdapter.js +1 -0
  30. package/lib/directors/PaymentDirector.js +11 -2
  31. package/lib/directors/PaymentPricingAdapter.d.ts +2 -1
  32. package/lib/directors/PaymentPricingAdapter.js +2 -1
  33. package/lib/directors/PaymentPricingDirector.d.ts +2 -1
  34. package/lib/directors/PaymentPricingDirector.js +11 -1
  35. package/lib/directors/PaymentPricingSheet.d.ts +2 -1
  36. package/lib/directors/PaymentPricingSheet.js +2 -1
  37. package/lib/directors/ProductDiscountAdapter.d.ts +3 -2
  38. package/lib/directors/ProductDiscountAdapter.js +5 -2
  39. package/lib/directors/ProductDiscountDirector.d.ts +16 -2
  40. package/lib/directors/ProductDiscountDirector.js +15 -2
  41. package/lib/directors/ProductPricingAdapter.d.ts +2 -1
  42. package/lib/directors/ProductPricingAdapter.js +3 -1
  43. package/lib/directors/ProductPricingDirector.d.ts +3 -1
  44. package/lib/directors/ProductPricingDirector.js +12 -1
  45. package/lib/directors/ProductPricingSheet.d.ts +1 -1
  46. package/lib/directors/ProductPricingSheet.js +1 -1
  47. package/lib/directors/QuotationAdapter.js +1 -0
  48. package/lib/directors/QuotationDirector.js +11 -2
  49. package/lib/directors/WarehousingAdapter.js +1 -0
  50. package/lib/directors/WarehousingDirector.d.ts +1 -1
  51. package/lib/directors/WarehousingDirector.js +12 -2
  52. package/lib/directors/WorkerAdapter.js +1 -0
  53. package/lib/directors/WorkerDirector.d.ts +1 -1
  54. package/lib/directors/WorkerDirector.js +10 -17
  55. package/lib/directors/index.d.ts +2 -0
  56. package/lib/directors/index.js +2 -0
  57. package/lib/errors/common.d.ts +568 -0
  58. package/lib/errors/common.js +789 -0
  59. package/lib/errors/index.d.ts +1 -0
  60. package/lib/errors/index.js +1 -0
  61. package/lib/factory/registerAssortmentSearchFilter.d.ts +2 -1
  62. package/lib/factory/registerAssortmentSearchFilter.js +12 -3
  63. package/lib/factory/registerInvoicePayment.d.ts +2 -2
  64. package/lib/factory/registerInvoicePayment.js +12 -3
  65. package/lib/factory/registerPhysicalWarehousing.d.ts +2 -2
  66. package/lib/factory/registerPhysicalWarehousing.js +12 -3
  67. package/lib/factory/registerPickUpDelivery.d.ts +2 -2
  68. package/lib/factory/registerPickUpDelivery.js +12 -3
  69. package/lib/factory/registerProductDiscoverabilityFilter.d.ts +2 -1
  70. package/lib/factory/registerProductDiscoverabilityFilter.js +12 -3
  71. package/lib/factory/registerProductSearchFilter.d.ts +2 -1
  72. package/lib/factory/registerProductSearchFilter.js +12 -3
  73. package/lib/factory/registerShippingDelivery.d.ts +2 -2
  74. package/lib/factory/registerShippingDelivery.js +12 -3
  75. package/lib/factory/registerVirtualWarehousing.d.ts +2 -2
  76. package/lib/factory/registerVirtualWarehousing.js +12 -3
  77. package/lib/factory/registerWorker.d.ts +2 -1
  78. package/lib/factory/registerWorker.js +12 -3
  79. package/lib/plugins/PluginRegistry.d.ts +42 -0
  80. package/lib/plugins/PluginRegistry.js +113 -0
  81. package/lib/services/addCartDiscount.d.ts +10 -0
  82. package/lib/services/addCartDiscount.js +27 -0
  83. package/lib/services/addCartItem.d.ts +15 -0
  84. package/lib/services/addCartItem.js +41 -0
  85. package/lib/services/addCartQuotation.d.ts +16 -0
  86. package/lib/services/addCartQuotation.js +52 -0
  87. package/lib/services/addEmail.d.ts +7 -0
  88. package/lib/services/addEmail.js +17 -0
  89. package/lib/services/addProductAssignment.d.ts +3 -0
  90. package/lib/services/addProductAssignment.js +63 -0
  91. package/lib/services/authenticateWithPassword.d.ts +15 -0
  92. package/lib/services/authenticateWithPassword.js +34 -0
  93. package/lib/services/changePassword.d.ts +10 -0
  94. package/lib/services/changePassword.js +19 -0
  95. package/lib/services/countOrdersWithFilters.d.ts +3 -0
  96. package/lib/services/countOrdersWithFilters.js +25 -0
  97. package/lib/services/createAssortment.d.ts +7 -0
  98. package/lib/services/createAssortment.js +10 -0
  99. package/lib/services/createBookmark.d.ts +8 -0
  100. package/lib/services/createBookmark.js +21 -0
  101. package/lib/services/createDeliveryProvider.d.ts +6 -0
  102. package/lib/services/createDeliveryProvider.js +19 -0
  103. package/lib/services/createDownloadStream.js +1 -1
  104. package/lib/services/createEnrollment.d.ts +17 -0
  105. package/lib/services/createEnrollment.js +33 -0
  106. package/lib/services/createFileDownloadURL.js +2 -1
  107. package/lib/services/createProduct.d.ts +7 -0
  108. package/lib/services/createProduct.js +8 -0
  109. package/lib/services/createProductBundleItem.d.ts +5 -0
  110. package/lib/services/createProductBundleItem.js +25 -0
  111. package/lib/services/createProductReview.d.ts +8 -0
  112. package/lib/services/createProductReview.js +12 -0
  113. package/lib/services/createSignedURL.js +2 -1
  114. package/lib/services/deliverOrder.d.ts +5 -0
  115. package/lib/services/deliverOrder.js +26 -0
  116. package/lib/services/findActiveWorkTypes.d.ts +2 -0
  117. package/lib/services/findActiveWorkTypes.js +6 -0
  118. package/lib/services/findDeliveryInterfaces.d.ts +7 -0
  119. package/lib/services/findDeliveryInterfaces.js +13 -0
  120. package/lib/services/findOrdersWithFilters.d.ts +9 -0
  121. package/lib/services/findOrdersWithFilters.js +25 -0
  122. package/lib/services/findPaymentInterfaces.d.ts +7 -0
  123. package/lib/services/findPaymentInterfaces.js +13 -0
  124. package/lib/services/findWarehousingInterfaces.d.ts +7 -0
  125. package/lib/services/findWarehousingInterfaces.js +13 -0
  126. package/lib/services/getDeliveryDiscounts.d.ts +8 -0
  127. package/lib/services/getDeliveryDiscounts.js +14 -0
  128. package/lib/services/getPaymentDiscounts.d.ts +8 -0
  129. package/lib/services/getPaymentDiscounts.js +14 -0
  130. package/lib/services/getShopInfo.d.ts +25 -0
  131. package/lib/services/getShopInfo.js +47 -0
  132. package/lib/services/impersonateUser.d.ts +8 -0
  133. package/lib/services/impersonateUser.js +20 -0
  134. package/lib/services/linkFileService.js +1 -1
  135. package/lib/services/loginAsGuest.d.ts +10 -0
  136. package/lib/services/loginAsGuest.js +19 -0
  137. package/lib/services/obfuscateWorkerData.d.ts +4 -0
  138. package/lib/services/obfuscateWorkerData.js +4 -0
  139. package/lib/services/orderPricingAccessors.d.ts +18 -0
  140. package/lib/services/orderPricingAccessors.js +29 -0
  141. package/lib/services/payOrder.d.ts +5 -0
  142. package/lib/services/payOrder.js +25 -0
  143. package/lib/services/registerUser.d.ts +14 -0
  144. package/lib/services/registerUser.js +44 -0
  145. package/lib/services/removeBookmark.d.ts +6 -0
  146. package/lib/services/removeBookmark.js +10 -0
  147. package/lib/services/removeCartItem.d.ts +6 -0
  148. package/lib/services/removeCartItem.js +19 -0
  149. package/lib/services/removeFiles.js +1 -1
  150. package/lib/services/resetPasswordWithMigration.d.ts +14 -0
  151. package/lib/services/resetPasswordWithMigration.js +31 -0
  152. package/lib/services/resolveWorkType.d.ts +1 -0
  153. package/lib/services/resolveWorkType.js +7 -0
  154. package/lib/services/searchProductsWithAssortment.d.ts +19 -0
  155. package/lib/services/searchProductsWithAssortment.js +17 -0
  156. package/lib/services/toggleBookmark.d.ts +8 -0
  157. package/lib/services/toggleBookmark.js +33 -0
  158. package/lib/services/updateCart.d.ts +15 -0
  159. package/lib/services/updateCart.js +27 -0
  160. package/lib/services/updateCartItem.d.ts +11 -0
  161. package/lib/services/updateCartItem.js +37 -0
  162. package/lib/services/updateEnrollment.d.ts +13 -0
  163. package/lib/services/updateEnrollment.js +36 -0
  164. package/lib/services/uploadFileFromStream.js +2 -1
  165. package/lib/services/uploadFileFromURL.js +2 -1
  166. package/lib/services/verifyEmailWithMigration.d.ts +15 -0
  167. package/lib/services/verifyEmailWithMigration.js +23 -0
  168. package/lib/utils/getFileAdapter.d.ts +1 -0
  169. package/lib/utils/getFileAdapter.js +7 -0
  170. package/lib/utils/schedule.js +164 -28
  171. package/package.json +1 -1
@@ -0,0 +1,13 @@
1
+ import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
2
+ import { WarehousingDirector } from "../directors/index.js";
3
+ export async function findWarehousingInterfacesService(type) {
4
+ const allAdapters = await WarehousingDirector.getAdapters();
5
+ const filteredAdapters = type
6
+ ? allAdapters.filter((Adapter) => Adapter.typeSupported(type))
7
+ : allAdapters;
8
+ return filteredAdapters.map((Adapter) => ({
9
+ _id: Adapter.key,
10
+ label: Adapter.label,
11
+ version: Adapter.version,
12
+ }));
13
+ }
@@ -0,0 +1,8 @@
1
+ import type { OrderDelivery } from '@unchainedshop/core-orders';
2
+ export interface DeliveryDiscountPrice {
3
+ item: OrderDelivery;
4
+ amount: number;
5
+ currencyCode: string;
6
+ discountId: string;
7
+ }
8
+ export declare function getDeliveryDiscountsService(orderDelivery: OrderDelivery, currencyCode: string): DeliveryDiscountPrice[];
@@ -0,0 +1,14 @@
1
+ import { DeliveryPricingSheet } from "../directors/index.js";
2
+ export function getDeliveryDiscountsService(orderDelivery, currencyCode) {
3
+ const pricing = DeliveryPricingSheet({
4
+ calculation: orderDelivery.calculation,
5
+ currencyCode,
6
+ });
7
+ if (pricing.isValid()) {
8
+ return pricing.discountPrices().map((discount) => ({
9
+ item: orderDelivery,
10
+ ...discount,
11
+ }));
12
+ }
13
+ return [];
14
+ }
@@ -0,0 +1,8 @@
1
+ import type { OrderPayment } from '@unchainedshop/core-orders';
2
+ export interface PaymentDiscountPrice {
3
+ item: OrderPayment;
4
+ amount: number;
5
+ currencyCode: string;
6
+ discountId: string;
7
+ }
8
+ export declare function getPaymentDiscountsService(orderPayment: OrderPayment, currencyCode: string): PaymentDiscountPrice[];
@@ -0,0 +1,14 @@
1
+ import { PaymentPricingSheet } from "../directors/index.js";
2
+ export function getPaymentDiscountsService(orderPayment, currencyCode) {
3
+ const pricing = PaymentPricingSheet({
4
+ calculation: orderPayment.calculation,
5
+ currencyCode,
6
+ });
7
+ if (pricing.isValid()) {
8
+ return pricing.discountPrices().map((discount) => ({
9
+ item: orderPayment,
10
+ ...discount,
11
+ }));
12
+ }
13
+ return [];
14
+ }
@@ -0,0 +1,25 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export interface AdminUIConfig {
3
+ customProperties?: unknown[];
4
+ singleSignOnURL?: string;
5
+ externalLinks?: unknown[];
6
+ defaultProductTags?: string[];
7
+ defaultAssortmentTags?: string[];
8
+ defaultUserTags?: string[];
9
+ }
10
+ export interface ShopInfoResult {
11
+ version?: string;
12
+ adminUiConfig: {
13
+ customProperties: () => Promise<unknown[]>;
14
+ singleSignOnURL?: string;
15
+ externalLinks: () => unknown[];
16
+ productTags: () => Promise<string[]>;
17
+ assortmentTags: () => Promise<string[]>;
18
+ userTags: () => Promise<string[]>;
19
+ };
20
+ vapidPublicKey?: string;
21
+ }
22
+ export declare function getShopInfoService(this: Modules, params: {
23
+ version?: string;
24
+ adminUiConfig?: AdminUIConfig;
25
+ }): ShopInfoResult;
@@ -0,0 +1,47 @@
1
+ import { readFile } from 'fs/promises';
2
+ async function loadCustomProperties(adminUiConfig) {
3
+ try {
4
+ if (!process.env.UNCHAINED_ADMIN_UI_CUSTOM_PROPERTIES) {
5
+ return adminUiConfig?.customProperties ?? [];
6
+ }
7
+ const raw = await readFile(process.env.UNCHAINED_ADMIN_UI_CUSTOM_PROPERTIES, 'utf-8');
8
+ return JSON.parse(raw);
9
+ }
10
+ catch {
11
+ return adminUiConfig?.customProperties ?? [];
12
+ }
13
+ }
14
+ function loadExternalLinks() {
15
+ try {
16
+ if (!process.env.EXTERNAL_LINKS)
17
+ return [];
18
+ return JSON.parse(process.env.EXTERNAL_LINKS);
19
+ }
20
+ catch {
21
+ return [];
22
+ }
23
+ }
24
+ async function getConfiguredTags(existingTagsFn, envVar, configDefault) {
25
+ const existingTags = await existingTagsFn();
26
+ const envTags = (process.env[envVar] || '')
27
+ .split(',')
28
+ .map((t) => t.trim())
29
+ .filter(Boolean);
30
+ const normalizedDefaultTags = envTags?.length ? envTags : (configDefault || []).filter(Boolean);
31
+ return Array.from(new Set(normalizedDefaultTags.concat(existingTags)));
32
+ }
33
+ export function getShopInfoService(params) {
34
+ const { version, adminUiConfig } = params;
35
+ return {
36
+ version,
37
+ adminUiConfig: {
38
+ customProperties: () => loadCustomProperties(adminUiConfig),
39
+ singleSignOnURL: process.env.UNCHAINED_ADMIN_UI_SINGLE_SIGN_ON_URL || adminUiConfig?.singleSignOnURL,
40
+ externalLinks: loadExternalLinks,
41
+ productTags: () => getConfiguredTags(() => this.products.existingTags(), 'UNCHAINED_ADMIN_UI_DEFAULT_PRODUCT_TAGS', adminUiConfig?.defaultProductTags),
42
+ assortmentTags: () => getConfiguredTags(() => this.assortments.existingTags(), 'UNCHAINED_ADMIN_UI_DEFAULT_ASSORTMENT_TAGS', adminUiConfig?.defaultAssortmentTags),
43
+ userTags: () => getConfiguredTags(() => this.users.existingTags(), 'UNCHAINED_ADMIN_UI_DEFAULT_USER_TAGS', adminUiConfig?.defaultUserTags),
44
+ },
45
+ vapidPublicKey: process.env?.PUSH_NOTIFICATION_PUBLIC_KEY,
46
+ };
47
+ }
@@ -0,0 +1,8 @@
1
+ import type { User } from '@unchainedshop/core-users';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface ImpersonateUserParams {
4
+ userIdToImpersonate: string;
5
+ currentUserId?: string;
6
+ countryCode: string;
7
+ }
8
+ export declare function impersonateUserService(this: Modules, params: ImpersonateUserParams): Promise<User>;
@@ -0,0 +1,20 @@
1
+ import { nextUserCartService } from "./nextUserCart.js";
2
+ import { UserNotFoundError, ImpersonatingAdminUserError } from "../errors/index.js";
3
+ export async function impersonateUserService(params) {
4
+ const { userIdToImpersonate, currentUserId, countryCode } = params;
5
+ const userToImpersonate = await this.users.findUserById(userIdToImpersonate);
6
+ if (!userToImpersonate) {
7
+ throw new UserNotFoundError({ userId: userIdToImpersonate });
8
+ }
9
+ if ((userToImpersonate.roles || []).includes('admin')) {
10
+ throw new ImpersonatingAdminUserError({
11
+ impersonatedUserId: userIdToImpersonate,
12
+ userId: currentUserId,
13
+ });
14
+ }
15
+ await nextUserCartService.bind(this)({
16
+ user: userToImpersonate,
17
+ countryCode,
18
+ });
19
+ return userToImpersonate;
20
+ }
@@ -1,4 +1,4 @@
1
- import { FileDirector } from '@unchainedshop/file-upload';
1
+ import { FileDirector } from "../directors/FileDirector.js";
2
2
  export async function linkFileService({ fileId, size, type }) {
3
3
  const file = await this.files.findFile({ fileId });
4
4
  if (!file)
@@ -0,0 +1,10 @@
1
+ import type { User } from '@unchainedshop/core-users';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface HttpContext {
4
+ remoteAddress?: string;
5
+ remotePort?: number;
6
+ userAgent?: string;
7
+ locale?: string;
8
+ countryCode: string;
9
+ }
10
+ export declare function loginAsGuestService(this: Modules, httpContext: HttpContext): Promise<User>;
@@ -0,0 +1,19 @@
1
+ import { nextUserCartService } from "./nextUserCart.js";
2
+ export async function loginAsGuestService(httpContext) {
3
+ const guestname = `guest-${crypto.randomUUID()}`;
4
+ const guestUserId = await this.users.createUser({
5
+ email: `${guestname}@unchained.local`,
6
+ guest: true,
7
+ password: null,
8
+ initialPassword: true,
9
+ }, { skipMessaging: true });
10
+ const user = (await this.users.updateHeartbeat(guestUserId, {
11
+ remoteAddress: httpContext.remoteAddress,
12
+ remotePort: httpContext.remotePort,
13
+ userAgent: httpContext.userAgent,
14
+ locale: httpContext.locale,
15
+ countryCode: httpContext.countryCode,
16
+ }));
17
+ await nextUserCartService.bind(this)({ user, countryCode: httpContext.countryCode });
18
+ return user;
19
+ }
@@ -0,0 +1,4 @@
1
+ export interface WorkerObfuscationOptions {
2
+ blacklistedVariables?: string[];
3
+ }
4
+ export declare function obfuscateWorkerDataService<T>(data: T, options?: WorkerObfuscationOptions): T;
@@ -0,0 +1,4 @@
1
+ import { buildObfuscatedFieldsFilter } from '@unchainedshop/utils';
2
+ export function obfuscateWorkerDataService(data, options) {
3
+ return buildObfuscatedFieldsFilter(options?.blacklistedVariables)(data);
4
+ }
@@ -0,0 +1,18 @@
1
+ import type { Order, OrderPosition } from '@unchainedshop/core-orders';
2
+ import type { Price } from '@unchainedshop/utils';
3
+ import type { Modules } from '../modules.ts';
4
+ import { type IOrderPricingSheet } from '../directors/OrderPricingSheet.ts';
5
+ import { type IProductPricingSheet } from '../directors/ProductPricingSheet.ts';
6
+ export declare function getOrderPricingSheetService(this: Modules, order: Order): IOrderPricingSheet | null;
7
+ export declare function getOrderTotalService(this: Modules, order: Order, params?: {
8
+ category?: string;
9
+ useNetPrice?: boolean;
10
+ }): Price | null;
11
+ export declare function getPositionPricingSheetService(this: Modules, position: OrderPosition, currencyCode: string): IProductPricingSheet | null;
12
+ export declare function getPositionTotalService(this: Modules, position: OrderPosition, currencyCode: string, params?: {
13
+ category?: string;
14
+ useNetPrice?: boolean;
15
+ }): Price | null;
16
+ export declare function getPositionUnitPriceService(this: Modules, position: OrderPosition, currencyCode: string, params?: {
17
+ useNetPrice?: boolean;
18
+ }): Price | null;
@@ -0,0 +1,29 @@
1
+ import { OrderPricingSheet } from "../directors/OrderPricingSheet.js";
2
+ import { ProductPricingSheet } from "../directors/ProductPricingSheet.js";
3
+ export function getOrderPricingSheetService(order) {
4
+ const pricing = OrderPricingSheet({
5
+ calculation: order.calculation,
6
+ currencyCode: order.currencyCode,
7
+ });
8
+ return pricing.isValid() ? pricing : null;
9
+ }
10
+ export function getOrderTotalService(order, params = {}) {
11
+ const pricing = getOrderPricingSheetService.call(this, order);
12
+ return pricing?.total(params) ?? null;
13
+ }
14
+ export function getPositionPricingSheetService(position, currencyCode) {
15
+ const pricing = ProductPricingSheet({
16
+ calculation: position.calculation,
17
+ currencyCode,
18
+ quantity: position.quantity,
19
+ });
20
+ return pricing.isValid() ? pricing : null;
21
+ }
22
+ export function getPositionTotalService(position, currencyCode, params = {}) {
23
+ const pricing = getPositionPricingSheetService.call(this, position, currencyCode);
24
+ return pricing?.total(params) ?? null;
25
+ }
26
+ export function getPositionUnitPriceService(position, currencyCode, params = {}) {
27
+ const pricing = getPositionPricingSheetService.call(this, position, currencyCode);
28
+ return pricing?.unitPrice(params) ?? null;
29
+ }
@@ -0,0 +1,5 @@
1
+ import { type Order } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ import { OrderNotFoundError, OrderWrongStatusError, OrderPaymentNotFoundError, OrderWrongPaymentStatusError } from '../errors/index.ts';
4
+ export { OrderNotFoundError, OrderWrongStatusError, OrderPaymentNotFoundError, OrderWrongPaymentStatusError, };
5
+ export declare function payOrderService(this: Modules, orderId: string): Promise<Order>;
@@ -0,0 +1,25 @@
1
+ import { OrderPaymentStatus } from '@unchainedshop/core-orders';
2
+ import { processOrderService } from "./processOrder.js";
3
+ import { OrderNotFoundError, OrderWrongStatusError, OrderPaymentNotFoundError, OrderWrongPaymentStatusError, } from "../errors/index.js";
4
+ export { OrderNotFoundError, OrderWrongStatusError, OrderPaymentNotFoundError, OrderWrongPaymentStatusError, };
5
+ export async function payOrderService(orderId) {
6
+ const order = await this.orders.findOrder({ orderId });
7
+ if (!order) {
8
+ throw new OrderNotFoundError({ orderId });
9
+ }
10
+ if (this.orders.isCart(order)) {
11
+ throw new OrderWrongStatusError({ status: order.status });
12
+ }
13
+ const payment = order.paymentId &&
14
+ (await this.orders.payments.findOrderPayment({
15
+ orderPaymentId: order.paymentId,
16
+ }));
17
+ if (!payment) {
18
+ throw new OrderPaymentNotFoundError({ orderPaymentId: order.paymentId });
19
+ }
20
+ if (this.orders.payments.normalizedStatus(payment) !== OrderPaymentStatus.OPEN) {
21
+ throw new OrderWrongPaymentStatusError({ status: payment.status });
22
+ }
23
+ await this.orders.payments.markAsPaid(payment, null);
24
+ return processOrderService.bind(this)(order, {});
25
+ }
@@ -0,0 +1,14 @@
1
+ import type { User, UserRegistrationData } from '@unchainedshop/core-users';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface HttpContext {
4
+ remoteAddress?: string;
5
+ remotePort?: number;
6
+ userAgent?: string;
7
+ locale?: string;
8
+ countryCode: string;
9
+ }
10
+ export interface RegisterUserResult {
11
+ user: User;
12
+ isFirstUser: boolean;
13
+ }
14
+ export declare function registerUserService(this: Modules, params: UserRegistrationData, httpContext: HttpContext): Promise<RegisterUserResult>;
@@ -0,0 +1,44 @@
1
+ import { nextUserCartService } from "./nextUserCart.js";
2
+ import { UsernameOrEmailRequiredError, PasswordOrWebAuthnPublicKeyRequiredError, EmailAlreadyExistsError, UsernameAlreadyExistsError, PasswordInvalidError, WebAuthnVerificationFailedError, AuthOperationFailedError, } from "../errors/index.js";
3
+ export async function registerUserService(params, httpContext) {
4
+ if (!params.username && !params.email) {
5
+ throw new UsernameOrEmailRequiredError();
6
+ }
7
+ if (!params.password && !params.webAuthnPublicKeyCredentials) {
8
+ throw new PasswordOrWebAuthnPublicKeyRequiredError({ username: params.username });
9
+ }
10
+ const usersCountBeforeCreation = await this.users.count({
11
+ includeDeleted: true,
12
+ includeGuests: true,
13
+ });
14
+ const isFirstUser = usersCountBeforeCreation === 0;
15
+ let newUserId;
16
+ try {
17
+ newUserId = await this.users.createUser({
18
+ ...params,
19
+ initialPassword: false,
20
+ roles: isFirstUser ? ['admin'] : [],
21
+ }, {});
22
+ }
23
+ catch (e) {
24
+ if (e.cause === 'EMAIL_INVALID')
25
+ throw new EmailAlreadyExistsError({ email: params.email });
26
+ else if (e.cause === 'USERNAME_INVALID')
27
+ throw new UsernameAlreadyExistsError({ username: params.username });
28
+ else if (e.cause === 'PASSWORD_INVALID')
29
+ throw new PasswordInvalidError({ username: params.username });
30
+ else if (e.cause === 'WEBAUTHN_INVALID')
31
+ throw new WebAuthnVerificationFailedError({ username: params.username });
32
+ else
33
+ throw new AuthOperationFailedError({ username: params.username, email: params.email });
34
+ }
35
+ const user = (await this.users.updateHeartbeat(newUserId, {
36
+ remoteAddress: httpContext.remoteAddress,
37
+ remotePort: httpContext.remotePort,
38
+ userAgent: httpContext.userAgent,
39
+ locale: httpContext.locale,
40
+ countryCode: httpContext.countryCode,
41
+ }));
42
+ await nextUserCartService.bind(this)({ user, countryCode: httpContext.countryCode });
43
+ return { user, isFirstUser };
44
+ }
@@ -0,0 +1,6 @@
1
+ import type { Bookmark } from '@unchainedshop/core-bookmarks';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface RemoveBookmarkParams {
4
+ bookmarkId: string;
5
+ }
6
+ export declare function removeBookmarkService(this: Modules, params: RemoveBookmarkParams): Promise<Bookmark>;
@@ -0,0 +1,10 @@
1
+ import { BookmarkNotFoundError } from "../errors/index.js";
2
+ export async function removeBookmarkService(params) {
3
+ const { bookmarkId } = params;
4
+ const bookmark = await this.bookmarks.findBookmarkById(bookmarkId);
5
+ if (!bookmark) {
6
+ throw new BookmarkNotFoundError({ bookmarkId });
7
+ }
8
+ await this.bookmarks.delete(bookmarkId);
9
+ return bookmark;
10
+ }
@@ -0,0 +1,6 @@
1
+ import type { OrderPosition } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface RemoveCartItemParams {
4
+ itemId: string;
5
+ }
6
+ export declare function removeCartItemService(this: Modules, params: RemoveCartItemParams): Promise<OrderPosition>;
@@ -0,0 +1,19 @@
1
+ import { updateCalculationService } from "./updateCalculation.js";
2
+ import { OrderItemNotFoundError, OrderNotFoundError, OrderWrongStatusError } from "../errors/index.js";
3
+ export async function removeCartItemService(params) {
4
+ const { itemId } = params;
5
+ const orderItem = await this.orders.positions.findOrderPosition({ itemId });
6
+ if (!orderItem) {
7
+ throw new OrderItemNotFoundError({ orderItemId: itemId });
8
+ }
9
+ const order = await this.orders.findOrder({ orderId: orderItem.orderId });
10
+ if (!order) {
11
+ throw new OrderNotFoundError({ orderId: orderItem.orderId });
12
+ }
13
+ if (!this.orders.isCart(order)) {
14
+ throw new OrderWrongStatusError({ status: order.status });
15
+ }
16
+ const removedOrderPosition = await this.orders.positions.delete(itemId);
17
+ await updateCalculationService.bind(this)(order._id);
18
+ return removedOrderPosition;
19
+ }
@@ -1,4 +1,4 @@
1
- import { getFileAdapter } from '@unchainedshop/core-files';
1
+ import { getFileAdapter } from "../utils/getFileAdapter.js";
2
2
  export async function removeFilesService({ fileIds }) {
3
3
  if (fileIds && typeof fileIds !== 'string' && !Array.isArray(fileIds))
4
4
  throw Error('Media id/s to be removed not provided as a string or array');
@@ -0,0 +1,14 @@
1
+ import type { User } from '@unchainedshop/core-users';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface ResetPasswordParams {
4
+ token: string;
5
+ newPassword: string;
6
+ }
7
+ export interface HttpContext {
8
+ remoteAddress?: string;
9
+ remotePort?: number;
10
+ userAgent?: string;
11
+ locale?: string;
12
+ countryCode: string;
13
+ }
14
+ export declare function resetPasswordWithMigrationService(this: Modules, params: ResetPasswordParams, httpContext: HttpContext, currentUserId?: string): Promise<User>;
@@ -0,0 +1,31 @@
1
+ import { migrateUserDataService } from "./migrateUserData.js";
2
+ import { nextUserCartService } from "./nextUserCart.js";
3
+ import { InvalidResetTokenError, PasswordInvalidError } from "../errors/index.js";
4
+ export async function resetPasswordWithMigrationService(params, httpContext, currentUserId) {
5
+ const { token, newPassword } = params;
6
+ let user;
7
+ try {
8
+ user = await this.users.resetPassword(token, newPassword);
9
+ }
10
+ catch (e) {
11
+ if (e && typeof e === 'object' && 'cause' in e && e.cause === 'PASSWORD_INVALID') {
12
+ throw new PasswordInvalidError();
13
+ }
14
+ throw e;
15
+ }
16
+ if (!user) {
17
+ throw new InvalidResetTokenError();
18
+ }
19
+ user = (await this.users.updateHeartbeat(user._id, {
20
+ remoteAddress: httpContext.remoteAddress,
21
+ remotePort: httpContext.remotePort,
22
+ userAgent: httpContext.userAgent,
23
+ locale: httpContext.locale,
24
+ countryCode: httpContext.countryCode,
25
+ }));
26
+ if (currentUserId) {
27
+ await migrateUserDataService.bind(this)(currentUserId, user._id);
28
+ }
29
+ await nextUserCartService.bind(this)({ user, countryCode: httpContext.countryCode });
30
+ return user;
31
+ }
@@ -0,0 +1 @@
1
+ export declare function resolveWorkTypeService(workType: string): string;
@@ -0,0 +1,7 @@
1
+ import { WorkerDirector } from "../directors/WorkerDirector.js";
2
+ export function resolveWorkTypeService(workType) {
3
+ if (WorkerDirector.getActivePluginTypes().includes(workType)) {
4
+ return workType;
5
+ }
6
+ return 'UNKNOWN';
7
+ }
@@ -0,0 +1,19 @@
1
+ import type { Assortment } from '@unchainedshop/core-assortments';
2
+ import type { SearchQuery } from '@unchainedshop/core-filters';
3
+ import type { Modules } from '../modules.ts';
4
+ export interface SearchProductsWithAssortmentParams extends SearchQuery {
5
+ assortmentId?: string;
6
+ assortment?: Assortment;
7
+ ignoreChildAssortments?: boolean;
8
+ }
9
+ export interface SearchProductsOptions {
10
+ locale: Intl.Locale;
11
+ userId?: string;
12
+ forceLiveCollection?: boolean;
13
+ }
14
+ export declare function searchProductsWithAssortmentService(this: Modules, params: SearchProductsWithAssortmentParams, options: SearchProductsOptions): Promise<{
15
+ searchConfiguration: import("../core-index.ts").SearchProductsOptions;
16
+ totalProductIds: string[];
17
+ aggregatedTotalProductIds: string[];
18
+ aggregatedFilteredProductIds: string[];
19
+ }>;
@@ -0,0 +1,17 @@
1
+ import { searchProductsService } from "./searchProducts.js";
2
+ export async function searchProductsWithAssortmentService(params, options) {
3
+ const { assortmentId, assortment: providedAssortment, ignoreChildAssortments, ...searchQuery } = params;
4
+ const assortment = providedAssortment ||
5
+ (assortmentId ? await this.assortments.findAssortment({ assortmentId }) : null);
6
+ if (!assortment) {
7
+ return searchProductsService.call(this, searchQuery, options);
8
+ }
9
+ const [productIds, filterIds] = await Promise.all([
10
+ this.assortments.findProductIds({
11
+ assortment,
12
+ ignoreChildAssortments: ignoreChildAssortments || false,
13
+ }),
14
+ this.assortments.filters.findFilterIds({ assortmentId: assortment._id }),
15
+ ]);
16
+ return searchProductsService.call(this, { ...searchQuery, productIds, filterIds }, options);
17
+ }
@@ -0,0 +1,8 @@
1
+ import type { Bookmark } from '@unchainedshop/core-bookmarks';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface ToggleBookmarkParams {
4
+ productId: string;
5
+ userId: string;
6
+ bookmarked: boolean;
7
+ }
8
+ export declare function toggleBookmarkService(this: Modules, params: ToggleBookmarkParams): Promise<Bookmark>;
@@ -0,0 +1,33 @@
1
+ import { ProductNotFoundError, BookmarkNotFoundError, MultipleBookmarksFoundError, } from "../errors/index.js";
2
+ export async function toggleBookmarkService(params) {
3
+ const { productId, userId, bookmarked } = params;
4
+ if (!(await this.products.productExists({ productId }))) {
5
+ throw new ProductNotFoundError({ productId });
6
+ }
7
+ const foundBookmarks = await this.bookmarks.findBookmarks({
8
+ productId,
9
+ userId,
10
+ });
11
+ if (foundBookmarks.length > 1) {
12
+ throw new MultipleBookmarksFoundError({
13
+ productId,
14
+ userId,
15
+ bookmarkIds: foundBookmarks.map((b) => b._id),
16
+ });
17
+ }
18
+ const foundBookmark = foundBookmarks[0];
19
+ if (bookmarked) {
20
+ if (foundBookmark)
21
+ return foundBookmark;
22
+ const bookmarkId = await this.bookmarks.create({
23
+ productId,
24
+ userId,
25
+ });
26
+ return (await this.bookmarks.findBookmarkById(bookmarkId));
27
+ }
28
+ if (!foundBookmark) {
29
+ throw new BookmarkNotFoundError({ productId, userId });
30
+ }
31
+ await this.bookmarks.delete(foundBookmark._id);
32
+ return foundBookmark;
33
+ }
@@ -0,0 +1,15 @@
1
+ import type { Order } from '@unchainedshop/core-orders';
2
+ import type { User } from '@unchainedshop/core-users';
3
+ import type { Address, Contact } from '@unchainedshop/core-users';
4
+ import type { Modules } from '../modules.ts';
5
+ export interface UpdateCartParams {
6
+ orderId?: string;
7
+ billingAddress?: Address;
8
+ contact?: Contact;
9
+ paymentProviderId?: string;
10
+ deliveryProviderId?: string;
11
+ meta?: any;
12
+ user: User;
13
+ countryCode: string;
14
+ }
15
+ export declare function updateCartService(this: Modules, params: UpdateCartParams): Promise<Order>;
@@ -0,0 +1,27 @@
1
+ import { findOrInitCartService } from "./findOrInitCart.js";
2
+ import { updateCalculationService } from "./updateCalculation.js";
3
+ import { OrderNotFoundError, OrderWrongStatusError } from "../errors/index.js";
4
+ export async function updateCartService(params) {
5
+ const { orderId, billingAddress, contact, paymentProviderId, deliveryProviderId, meta, user, countryCode, } = params;
6
+ const order = await findOrInitCartService.bind(this)({
7
+ orderId,
8
+ user,
9
+ countryCode,
10
+ });
11
+ if (!order) {
12
+ throw new OrderNotFoundError({ orderId });
13
+ }
14
+ if (!this.orders.isCart(order)) {
15
+ throw new OrderWrongStatusError({ status: order.status });
16
+ }
17
+ if (meta || billingAddress || contact) {
18
+ await this.orders.updateCartFields(order._id, { meta, billingAddress, contact });
19
+ }
20
+ if (paymentProviderId) {
21
+ await this.orders.setPaymentProvider(order._id, paymentProviderId);
22
+ }
23
+ if (deliveryProviderId) {
24
+ await this.orders.setDeliveryProvider(order._id, deliveryProviderId);
25
+ }
26
+ return updateCalculationService.bind(this)(order._id);
27
+ }
@@ -0,0 +1,11 @@
1
+ import { type OrderPosition } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface UpdateCartItemParams {
4
+ itemId: string;
5
+ quantity?: number;
6
+ configuration?: {
7
+ key: string;
8
+ value: string;
9
+ }[];
10
+ }
11
+ export declare function updateCartItemService(this: Modules, params: UpdateCartItemParams, context: any): Promise<OrderPosition>;