diff --git a/docs/docs/advanced/write-plugins/payment.md b/docs/docs/advanced/write-plugins/payment.md index 5130386431..8bde19ec3c 100644 --- a/docs/docs/advanced/write-plugins/payment.md +++ b/docs/docs/advanced/write-plugins/payment.md @@ -22,7 +22,7 @@ import { PaymentError, } from '@unchainedshop/core-payment'; -const ShopPayment: IPaymentAdapter = { +const ShopPayment: IPaymentAdapter = { key: 'ch.Shop.payment', label: 'Shop Payment', version: '1.0.0', diff --git a/packages/core-delivery/src/types.ts b/packages/core-delivery/src/types.ts index 03065c8b50..641c6d5f4f 100644 --- a/packages/core-delivery/src/types.ts +++ b/packages/core-delivery/src/types.ts @@ -74,12 +74,15 @@ export interface DeliveryAdapterActions { pickUpLocations: () => Promise>; send: () => Promise; } -export type IDeliveryAdapter = IBaseAdapter & { +export type IDeliveryAdapter = IBaseAdapter & { initialConfiguration: DeliveryConfiguration; typeSupported: (type: DeliveryProviderType) => boolean; - actions: (config: DeliveryConfiguration, context: DeliveryContext) => DeliveryAdapterActions; + actions: ( + config: DeliveryConfiguration, + context: DeliveryContext & UnchainedAPI, + ) => DeliveryAdapterActions; }; export type IDeliveryDirector = IBaseDirector & { diff --git a/packages/core-enrollments/src/director/EnrollmentAdapter.ts b/packages/core-enrollments/src/director/EnrollmentAdapter.ts index a4c03b400c..f6901455fa 100644 --- a/packages/core-enrollments/src/director/EnrollmentAdapter.ts +++ b/packages/core-enrollments/src/director/EnrollmentAdapter.ts @@ -44,7 +44,7 @@ export const EnrollmentAdapter: Omit { const { enrollment } = context; - const product = await context.modules.products.findProduct({ + const product = await (context as any).modules.products.findProduct({ productId: enrollment.productId, }); const plan = product?.plan; diff --git a/packages/core-enrollments/src/enrollments-settings.ts b/packages/core-enrollments/src/enrollments-settings.ts index d3d042ea88..724840ab11 100644 --- a/packages/core-enrollments/src/enrollments-settings.ts +++ b/packages/core-enrollments/src/enrollments-settings.ts @@ -1,8 +1,9 @@ import later from '@breejs/later'; -import { WorkerSchedule } from '@unchainedshop/core-worker'; import { generateRandomHash } from '@unchainedshop/utils'; import { Enrollment } from './types.js'; +import type { WorkerSchedule } from '@unchainedshop/core-worker'; + const everyHourSchedule = later.parse.text('every 59 minutes'); export interface EnrollmentsSettingsOptions { diff --git a/packages/core-enrollments/src/module/buildFindSelector.test.ts b/packages/core-enrollments/src/module/buildFindSelector.test.ts index ed1e3272a3..f0056dc7cc 100644 --- a/packages/core-enrollments/src/module/buildFindSelector.test.ts +++ b/packages/core-enrollments/src/module/buildFindSelector.test.ts @@ -1,4 +1,4 @@ -import { EnrollmentStatus } from '@unchainedshop/core-enrollments'; +import { EnrollmentStatus } from '../types.js'; import { buildFindSelector } from './configureEnrollmentsModule.js'; describe('buildFindSelector', () => { diff --git a/packages/core-enrollments/src/module/configureEnrollmentsModule.ts b/packages/core-enrollments/src/module/configureEnrollmentsModule.ts index e65b3931c9..ebae10e868 100644 --- a/packages/core-enrollments/src/module/configureEnrollmentsModule.ts +++ b/packages/core-enrollments/src/module/configureEnrollmentsModule.ts @@ -1,5 +1,4 @@ import { SortDirection, SortOption } from '@unchainedshop/utils'; -import { UnchainedCore } from '@unchainedshop/core'; import { Enrollment, EnrollmentData, @@ -53,10 +52,7 @@ export interface EnrollmentTransformations { // Processing -export type EnrollmentContextParams = ( - enrollment: Enrollment, - unchainedAPI: UnchainedCore, -) => Promise; +export type EnrollmentContextParams = (enrollment: Enrollment, unchainedAPI) => Promise; export interface EnrollmentProcessing { terminateEnrollment: EnrollmentContextParams; @@ -66,7 +62,7 @@ export interface EnrollmentProcessing { export interface EnrollmentMutations { addEnrollmentPeriod: (enrollmentId: string, period: EnrollmentPeriod) => Promise; - create: (doc: EnrollmentData, unchainedAPI: UnchainedCore) => Promise; + create: (doc: EnrollmentData, unchainedAPI) => Promise; createFromCheckout: ( order: Order, @@ -80,7 +76,7 @@ export interface EnrollmentMutations { deliveryContext?: any; }; }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; delete: (enrollmentId: string) => Promise; @@ -97,16 +93,12 @@ export interface EnrollmentMutations { updatePayment: (enrollmentId: string, payment: Enrollment['payment']) => Promise; - updatePlan: ( - enrollmentId: string, - plan: EnrollmentPlan, - unchainedAPI: UnchainedCore, - ) => Promise; + updatePlan: (enrollmentId: string, plan: EnrollmentPlan, unchainedAPI) => Promise; updateStatus: ( enrollmentId: string, params: { status: EnrollmentStatus; info?: string }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; } @@ -157,10 +149,7 @@ export const configureEnrollmentsModule = async ({ return findNewEnrollmentNumber(enrollment, index + 1); }; - const findNextStatus = async ( - enrollment: Enrollment, - unchainedAPI: UnchainedCore, - ): Promise => { + const findNextStatus = async (enrollment: Enrollment, unchainedAPI): Promise => { let status = enrollment.status as EnrollmentStatus; const director = await EnrollmentDirector.actions({ enrollment }, unchainedAPI); @@ -227,7 +216,7 @@ export const configureEnrollmentsModule = async ({ return enrollment; }; - const processEnrollment = async (enrollment: Enrollment, unchainedAPI: UnchainedCore) => { + const processEnrollment = async (enrollment: Enrollment, unchainedAPI) => { let status = await findNextStatus(enrollment, unchainedAPI); if (status === EnrollmentStatus.ACTIVE) { @@ -241,7 +230,7 @@ export const configureEnrollmentsModule = async ({ const initializeEnrollment = async ( enrollment: Enrollment, params: { orderIdForFirstPeriod?: string; reason: string }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { const { modules } = unchainedAPI; @@ -263,7 +252,7 @@ export const configureEnrollmentsModule = async ({ const sendStatusToCustomer = async ( enrollment: Enrollment, params: { locale?: Intl.Locale; reason?: string }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { const { modules } = unchainedAPI; diff --git a/packages/core-enrollments/src/types.ts b/packages/core-enrollments/src/types.ts index ea449cdd9f..6a87c98669 100644 --- a/packages/core-enrollments/src/types.ts +++ b/packages/core-enrollments/src/types.ts @@ -2,7 +2,6 @@ import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils'; import { TimestampFields, LogFields, Address, Contact } from '@unchainedshop/mongodb'; import { Product, ProductPlan } from '@unchainedshop/core-products'; import { OrderPosition } from '@unchainedshop/core-orders'; -import { UnchainedCore } from '@unchainedshop/core'; export enum EnrollmentStatus { INITIAL = 'INITIAL', @@ -78,10 +77,10 @@ export type IEnrollmentAdapter = IBaseAdapter & { transformOrderItemToEnrollmentPlan: ( orderPosition: OrderPosition, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; - actions: (params: EnrollmentContext & UnchainedCore) => EnrollmentAdapterActions; + actions: (params: EnrollmentContext) => EnrollmentAdapterActions; }; export interface EnrollmentData { @@ -103,11 +102,8 @@ export type IEnrollmentDirector = IBaseDirector & { transformOrderItemToEnrollment: ( item: { orderPosition: OrderPosition; product: Product }, doc: Omit, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; - actions: ( - enrollmentContext: EnrollmentContext, - unchainedAPI: UnchainedCore, - ) => Promise; + actions: (enrollmentContext: EnrollmentContext, unchainedAPI) => Promise; }; diff --git a/packages/core-filters/src/module/configureFilterSearchModule.ts b/packages/core-filters/src/module/configureFilterSearchModule.ts index 0876fe54a5..338eb5bd13 100644 --- a/packages/core-filters/src/module/configureFilterSearchModule.ts +++ b/packages/core-filters/src/module/configureFilterSearchModule.ts @@ -16,7 +16,6 @@ import { SearchProductConfiguration, } from '../search/search.js'; import { SearchQuery, Filter } from '../types.js'; -import { UnchainedCore } from '@unchainedshop/core'; import { Assortment } from '@unchainedshop/core-assortments'; export type SearchProducts = { @@ -34,13 +33,13 @@ export type FilterSearchModule = { searchProducts: ( searchQuery: SearchQuery, params: { forceLiveCollection?: boolean }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; searchAssortments: ( searchQuery: SearchQuery, params: { forceLiveCollection?: boolean }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; }; diff --git a/packages/core-filters/src/module/configureFiltersModule.ts b/packages/core-filters/src/module/configureFiltersModule.ts index 2f1c31b318..8dee1db32e 100644 --- a/packages/core-filters/src/module/configureFiltersModule.ts +++ b/packages/core-filters/src/module/configureFiltersModule.ts @@ -9,7 +9,6 @@ import { generateDbObjectId, ModuleInput, } from '@unchainedshop/mongodb'; -import { UnchainedCore } from '@unchainedshop/core'; import { FilterType } from '../db/FilterType.js'; import { FilterDirector } from '../director/FilterDirector.js'; import { FiltersCollection } from '../db/FiltersCollection.js'; @@ -43,25 +42,21 @@ export type FiltersModule = { filterExists: (params: { filterId: string }) => Promise; - invalidateCache: (query: mongodb.Filter, unchainedAPI: UnchainedCore) => Promise; + invalidateCache: (query: mongodb.Filter, unchainedAPI) => Promise; // Mutations create: ( doc: Filter & { title: string; locale: string }, - unchainedAPI: UnchainedCore, + unchainedAPI, options?: { skipInvalidation?: boolean }, ) => Promise; - createFilterOption: ( - filterId: string, - option: { value: string }, - unchainedAPI: UnchainedCore, - ) => Promise; + createFilterOption: (filterId: string, option: { value: string }, unchainedAPI) => Promise; update: ( filterId: string, doc: Filter, - unchainedAPI: UnchainedCore, + unchainedAPI, options?: { skipInvalidation?: boolean }, ) => Promise; @@ -72,7 +67,7 @@ export type FiltersModule = { filterId: string; filterOptionValue?: string; }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; /* @@ -117,7 +112,7 @@ export const configureFiltersModule = async ({ const findProductIds = async ( filter: Filter, { value }: { value?: boolean | string }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { const { modules } = unchainedAPI; const director = await FilterDirector.actions({ filter, searchQuery: {} }, unchainedAPI); @@ -138,7 +133,7 @@ export const configureFiltersModule = async ({ const buildProductIdMap = async ( filter: Filter, - unchainedAPI: UnchainedCore, + unchainedAPI, ): Promise<[Array, Record>]> => { const allProductIds = await findProductIds(filter, {}, unchainedAPI); const productIdsMap = @@ -162,7 +157,7 @@ export const configureFiltersModule = async ({ async function filterProductIdsRaw( filter: Filter, { values, forceLiveCollection }: { values: Array; forceLiveCollection?: boolean }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) { const getProductIds = (!forceLiveCollection && (await filtersSettings.getCachedProductIds(filter._id))) || @@ -186,7 +181,7 @@ export const configureFiltersModule = async ({ }, ); - const invalidateProductIdCache = async (filter: Filter, unchainedAPI: UnchainedCore) => { + const invalidateProductIdCache = async (filter: Filter, unchainedAPI) => { if (!filter) return; log(`Filters: Rebuilding ${filter.key}`, { level: LogLevel.Verbose }); @@ -195,7 +190,7 @@ export const configureFiltersModule = async ({ await filtersSettings.setCachedProductIds(filter._id, productIds, productIdMap); }; - const invalidateCache = async (selector: mongodb.Filter, unchainedAPI: UnchainedCore) => { + const invalidateCache = async (selector: mongodb.Filter, unchainedAPI) => { log('Filters: Start invalidating filter caches', { level: LogLevel.Verbose, }); diff --git a/packages/core-filters/src/search/loadFilter.ts b/packages/core-filters/src/search/loadFilter.ts index c5f3a13e07..fd84854805 100644 --- a/packages/core-filters/src/search/loadFilter.ts +++ b/packages/core-filters/src/search/loadFilter.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { FilterType } from '../db/FilterType.js'; import { intersectSet } from '../utils/intersectSet.js'; import { FilterProductIds } from './search.js'; @@ -14,7 +13,7 @@ const findLoadedOptions = async ( }, filterProductIds: FilterProductIds, filterActions: FilterAdapterActions, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { const { values, forceLiveCollection, productIdSet } = params; const parse = createFilterValueParser(filter.type); @@ -62,7 +61,7 @@ export const loadFilter = async ( }, filterProductIds: FilterProductIds, filterActions: FilterAdapterActions, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { const { allProductIds, filterQuery, forceLiveCollection, otherFilters } = params; diff --git a/packages/core-filters/src/search/productFacetedSearch.ts b/packages/core-filters/src/search/productFacetedSearch.ts index 0fd6e2b021..8c351a662f 100644 --- a/packages/core-filters/src/search/productFacetedSearch.ts +++ b/packages/core-filters/src/search/productFacetedSearch.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { mongodb } from '@unchainedshop/mongodb'; import { intersectSet } from '../utils/intersectSet.js'; import { FilterProductIds, SearchConfiguration } from './search.js'; @@ -8,7 +7,7 @@ export const productFacetedSearch = ( Filters: mongodb.Collection, filterProductIds: FilterProductIds, searchConfiguration: SearchConfiguration, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { const { query, filterSelector, forceLiveCollection } = searchConfiguration; diff --git a/packages/core-filters/src/search/resolveProductSelector.ts b/packages/core-filters/src/search/resolveProductSelector.ts index 8cc245221c..19ac16b6fc 100644 --- a/packages/core-filters/src/search/resolveProductSelector.ts +++ b/packages/core-filters/src/search/resolveProductSelector.ts @@ -1,7 +1,6 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { FilterAdapterActions, SearchQuery } from '../types.js'; -const defaultSelector = ({ includeInactive }: SearchQuery, { modules }: UnchainedCore) => { +const defaultSelector = ({ includeInactive }: SearchQuery, { modules }) => { const selector = !includeInactive ? modules.products.search.buildActiveStatusFilter() : modules.products.search.buildActiveDraftStatusFilter(); @@ -11,7 +10,7 @@ const defaultSelector = ({ includeInactive }: SearchQuery, { modules }: Unchaine export const resolveProductSelector = async ( searchQuery: SearchQuery, filterActions: FilterAdapterActions, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { const selector = defaultSelector(searchQuery, unchainedAPI); return filterActions.transformProductSelector(selector, {}); diff --git a/packages/core-filters/src/search/search.ts b/packages/core-filters/src/search/search.ts index 553655ae9f..4d304f6d57 100644 --- a/packages/core-filters/src/search/search.ts +++ b/packages/core-filters/src/search/search.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { Filter, SearchQuery } from '../types.js'; import { mongodb } from '@unchainedshop/mongodb'; import { Product } from '@unchainedshop/core-products'; @@ -26,5 +25,5 @@ export interface SearchAssortmentConfiguration extends SearchConfiguration { export type FilterProductIds = ( filter: Filter, params: { values: Array; forceLiveCollection?: boolean }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise>; diff --git a/packages/core-filters/src/types.ts b/packages/core-filters/src/types.ts index 48e9edd680..aef868ab34 100644 --- a/packages/core-filters/src/types.ts +++ b/packages/core-filters/src/types.ts @@ -2,7 +2,6 @@ import { Assortment } from '@unchainedshop/core-assortments'; import { TimestampFields, mongodb } from '@unchainedshop/mongodb'; import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils'; import { Product } from '@unchainedshop/core-products'; -import { UnchainedCore } from '@unchainedshop/core'; export enum FilterType { SWITCH = 'SWITCH', @@ -106,12 +105,12 @@ export interface FilterAdapterActions { ) => Promise; } -export type IFilterAdapter = IBaseAdapter & { +export type IFilterAdapter = IBaseAdapter & { orderIndex: number; - actions: (params: FilterContext & UnchainedCore) => FilterAdapterActions; + actions: (params: FilterContext & UnchainedAPI) => FilterAdapterActions; }; export type IFilterDirector = IBaseDirector & { - actions: (filterContext: FilterContext, unchainedAPI: UnchainedCore) => Promise; + actions: (filterContext: FilterContext, unchainedAPI) => Promise; }; diff --git a/packages/core-messaging/src/director/MessagingDirector.ts b/packages/core-messaging/src/director/MessagingDirector.ts index 87cdfe49a0..07bc4906f1 100644 --- a/packages/core-messaging/src/director/MessagingDirector.ts +++ b/packages/core-messaging/src/director/MessagingDirector.ts @@ -1,5 +1,4 @@ import { log } from '@unchainedshop/logger'; -import { UnchainedCore } from '@unchainedshop/core'; export type EmailTemplateType = { type: 'EMAIL'; @@ -39,7 +38,7 @@ export type ArbitraryTemplateType = { export type TemplateResolver = ( params: { template: string; [x: string]: any }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise>; export type IMessagingDirector = { diff --git a/packages/core-orders/src/director/OrderDiscountAdapter.ts b/packages/core-orders/src/director/OrderDiscountAdapter.ts index a01d6efa59..c01241fab2 100644 --- a/packages/core-orders/src/director/OrderDiscountAdapter.ts +++ b/packages/core-orders/src/director/OrderDiscountAdapter.ts @@ -1,8 +1,7 @@ import { BaseDiscountAdapter, IDiscountAdapter } from '@unchainedshop/utils'; import { OrderDiscountConfiguration } from './OrderDiscountConfiguration.js'; -import { UnchainedCore } from '@unchainedshop/core'; export const OrderDiscountAdapter: Omit< - IDiscountAdapter, + IDiscountAdapter, 'key' | 'label' | 'version' > = BaseDiscountAdapter; diff --git a/packages/core-orders/src/director/OrderDiscountDirector.ts b/packages/core-orders/src/director/OrderDiscountDirector.ts index 16144673b4..07f24450aa 100644 --- a/packages/core-orders/src/director/OrderDiscountDirector.ts +++ b/packages/core-orders/src/director/OrderDiscountDirector.ts @@ -1,7 +1,6 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { BaseDiscountDirector } from '@unchainedshop/utils'; import { OrderDiscountConfiguration } from './OrderDiscountConfiguration.js'; -export const OrderDiscountDirector = BaseDiscountDirector( +export const OrderDiscountDirector = BaseDiscountDirector( 'OrderDiscountDirector', ); diff --git a/packages/core-orders/src/director/OrderPricingAdapter.ts b/packages/core-orders/src/director/OrderPricingAdapter.ts index 85be12c99d..0b1e816bb7 100644 --- a/packages/core-orders/src/director/OrderPricingAdapter.ts +++ b/packages/core-orders/src/director/OrderPricingAdapter.ts @@ -1,10 +1,9 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { BasePricingAdapter, IPricingAdapter, BasePricingAdapterContext } from '@unchainedshop/utils'; import { IOrderPricingSheet, OrderPricingCalculation, OrderPricingSheet } from './OrderPricingSheet.js'; import { Order, OrderDelivery, OrderDiscount, OrderPayment, OrderPosition } from '../types.js'; import { User } from '@unchainedshop/core-users'; -export interface OrderPricingAdapterContext extends BasePricingAdapterContext, UnchainedCore { +export interface OrderPricingAdapterContext extends BasePricingAdapterContext { currency?: string; discounts: Array; order: Order; @@ -21,8 +20,8 @@ export interface OrderPricingContext { orderPayment: OrderPayment; } -export type IOrderPricingAdapter = IPricingAdapter< - OrderPricingAdapterContext, +export type IOrderPricingAdapter = IPricingAdapter< + OrderPricingAdapterContext & UnchainedAPI, OrderPricingCalculation, IOrderPricingSheet, DiscountConfiguration @@ -30,11 +29,7 @@ export type IOrderPricingAdapter = IPricingAdap const basePricingAdapter = BasePricingAdapter(); -export const OrderPricingAdapter: IPricingAdapter< - OrderPricingAdapterContext, - OrderPricingCalculation, - IOrderPricingSheet -> = { +export const OrderPricingAdapter: IOrderPricingAdapter = { ...basePricingAdapter, isActivatedFor: () => { diff --git a/packages/core-orders/src/director/OrderPricingDirector.ts b/packages/core-orders/src/director/OrderPricingDirector.ts index 6270ca5f6e..5d7e2657a8 100644 --- a/packages/core-orders/src/director/OrderPricingDirector.ts +++ b/packages/core-orders/src/director/OrderPricingDirector.ts @@ -6,7 +6,6 @@ import { OrderPricingAdapterContext, OrderPricingContext, } from './OrderPricingAdapter.js'; -import { UnchainedCore } from '@unchainedshop/core'; export type OrderPrice = { _id?: string; amount: number; currency: string }; @@ -22,8 +21,7 @@ export type IOrderPricingDirector = IPricingDir OrderPricingCalculation, OrderPricingAdapterContext, IOrderPricingSheet, - IOrderPricingAdapter, - UnchainedCore + IOrderPricingAdapter >; const baseDirector = BasePricingDirector< diff --git a/packages/core-orders/src/module/configureOrderDeliveriesModule.ts b/packages/core-orders/src/module/configureOrderDeliveriesModule.ts index 561e91c7da..362ff8f6f9 100644 --- a/packages/core-orders/src/module/configureOrderDeliveriesModule.ts +++ b/packages/core-orders/src/module/configureOrderDeliveriesModule.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { mongodb, generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb'; import { emit, registerEvents } from '@unchainedshop/events'; import { Order, OrderDelivery, OrderDeliveryStatus, OrderDiscount } from '../types.js'; @@ -17,19 +16,12 @@ export type OrderDeliveriesModule = { discounts: ( orderDelivery: OrderDelivery, params: { order: Order; orderDiscount: OrderDiscount }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Array; - isBlockingOrderConfirmation: ( - orderDelivery: OrderDelivery, - unchainedAPI: UnchainedCore, - ) => Promise; + isBlockingOrderConfirmation: (orderDelivery: OrderDelivery, unchainedAPI) => Promise; isBlockingOrderFullfillment: (orderDelivery: OrderDelivery) => boolean; normalizedStatus: (orderDelivery: OrderDelivery) => string; - pricingSheet: ( - orderDelivery: OrderDelivery, - currency: string, - unchainedAPI: UnchainedCore, - ) => IDeliveryPricingSheet; + pricingSheet: (orderDelivery: OrderDelivery, currency: string, unchainedAPI) => IDeliveryPricingSheet; // Mutations create: (doc: OrderDelivery) => Promise; @@ -37,15 +29,12 @@ export type OrderDeliveriesModule = { markAsDelivered: (orderDelivery: OrderDelivery) => Promise; - activePickUpLocation: ( - orderDelivery: OrderDelivery, - unchainedAPI: UnchainedCore, - ) => Promise; + activePickUpLocation: (orderDelivery: OrderDelivery, unchainedAPI) => Promise; send: ( orderDelivery: OrderDelivery, params: { order: Order; deliveryContext?: any }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; updateContext: (orderDeliveryId: string, context: any) => Promise; @@ -55,10 +44,7 @@ export type OrderDeliveriesModule = { params: { status: OrderDeliveryStatus; info?: string }, ) => Promise; - updateCalculation: ( - orderDelivery: OrderDelivery, - unchainedAPI: UnchainedCore, - ) => Promise; + updateCalculation: (orderDelivery: OrderDelivery, unchainedAPI) => Promise; }; const ORDER_DELIVERY_EVENTS: string[] = ['ORDER_DELIVER', 'ORDER_UPDATE_DELIVERY']; diff --git a/packages/core-orders/src/module/configureOrderDiscountsModule.ts b/packages/core-orders/src/module/configureOrderDiscountsModule.ts index 17eded6b87..76715eed5a 100644 --- a/packages/core-orders/src/module/configureOrderDiscountsModule.ts +++ b/packages/core-orders/src/module/configureOrderDiscountsModule.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { emit, registerEvents } from '@unchainedshop/events'; import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb'; import { OrderDiscountTrigger } from '../db/OrderDiscountTrigger.js'; @@ -20,30 +19,27 @@ export type OrderDiscountsModule = { findOrderDiscounts: (params: { orderId: string }) => Promise>; // Transformations - interface: ( - orderDiscount: OrderDiscount, - unchainedAPI: UnchainedCore, - ) => Promise>; + interface: (orderDiscount: OrderDiscount, unchainedAPI) => Promise>; - isValid: (orderDiscount: OrderDiscount, unchainedAPI: UnchainedCore) => Promise; + isValid: (orderDiscount: OrderDiscount, unchainedAPI) => Promise; // Adapter configurationForPricingAdapterKey: ( orderDiscount: OrderDiscount, adapterKey: string, calculationSheet: IPricingSheet, - pricingContext: DiscountContext & UnchainedCore, + pricingContext: DiscountContext, ) => Promise; // Mutations createManualOrderDiscount: ( params: { code: string; order: Order }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; create: (doc: OrderDiscount) => Promise; update: (orderDiscountId: string, doc: OrderDiscount) => Promise; - delete: (orderDiscountId: string, unchainedAPI: UnchainedCore) => Promise; + delete: (orderDiscountId: string, unchainedAPI) => Promise; }; const ORDER_DISCOUNT_EVENTS: string[] = [ @@ -68,7 +64,7 @@ export const configureOrderDiscountsModule = ({ }): OrderDiscountsModule => { registerEvents(ORDER_DISCOUNT_EVENTS); - const getAdapter = async (orderDiscount: OrderDiscount, unchainedAPI: UnchainedCore) => { + const getAdapter = async (orderDiscount: OrderDiscount, unchainedAPI) => { const order = await unchainedAPI.modules.orders.findOrder({ orderId: orderDiscount.orderId, }); @@ -121,7 +117,7 @@ export const configureOrderDiscountsModule = ({ return discount; }; - const reserveDiscount = async (orderDiscount: OrderDiscount, unchainedAPI: UnchainedCore) => { + const reserveDiscount = async (orderDiscount: OrderDiscount, unchainedAPI) => { const adapter = await getAdapter(orderDiscount, unchainedAPI); if (!adapter) return null; @@ -132,10 +128,7 @@ export const configureOrderDiscountsModule = ({ return updateDiscount(orderDiscount._id, { orderId: orderDiscount.orderId, reservation }); }; - const grabDiscount = async ( - { code, orderId }: { code: string; orderId: string }, - unchainedAPI: UnchainedCore, - ) => { + const grabDiscount = async ({ code, orderId }: { code: string; orderId: string }, unchainedAPI) => { const existingDiscount = await OrderDiscounts.findOne({ code, orderId }); if (existingDiscount) throw new Error(OrderDiscountErrorCode.CODE_ALREADY_PRESENT); const discount = await OrderDiscounts.findOne({ code, orderId: null }); diff --git a/packages/core-orders/src/module/configureOrderPaymentsModule.ts b/packages/core-orders/src/module/configureOrderPaymentsModule.ts index c35cdc4411..647f8d9b86 100644 --- a/packages/core-orders/src/module/configureOrderPaymentsModule.ts +++ b/packages/core-orders/src/module/configureOrderPaymentsModule.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { emit, registerEvents } from '@unchainedshop/events'; import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb'; import { Order, OrderDiscount, OrderPayment, OrderPaymentStatus } from '../types.js'; @@ -32,19 +31,12 @@ export type OrderPaymentsModule = { discounts: ( orderPayment: OrderPayment, params: { order: Order; orderDiscount: OrderDiscount }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Array; - isBlockingOrderConfirmation: ( - orderPayment: OrderPayment, - unchainedAPI: UnchainedCore, - ) => Promise; + isBlockingOrderConfirmation: (orderPayment: OrderPayment, unchainedAPI) => Promise; isBlockingOrderFullfillment: (orderPayment: OrderPayment) => boolean; normalizedStatus: (orderPayment: OrderPayment) => string; - pricingSheet: ( - orderPayment: OrderPayment, - currency: string, - unchainedAPI: UnchainedCore, - ) => IPaymentPricingSheet; + pricingSheet: (orderPayment: OrderPayment, currency: string, unchainedAPI) => IPaymentPricingSheet; // Mutations create: (doc: OrderPayment) => Promise; @@ -55,7 +47,7 @@ export type OrderPaymentsModule = { transactionContext: any; userId: string; }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; confirm: ( @@ -64,7 +56,7 @@ export type OrderPaymentsModule = { transactionContext: any; userId: string; }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; charge: ( @@ -73,7 +65,7 @@ export type OrderPaymentsModule = { transactionContext: any; userId: string; }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; logEvent: (orderPaymentId: string, event: any) => Promise; @@ -87,7 +79,7 @@ export type OrderPaymentsModule = { params: { transactionId?: string; status: OrderPaymentStatus; info?: string }, ) => Promise; - updateCalculation: (orderPayment: OrderPayment, unchainedAPI: UnchainedCore) => Promise; + updateCalculation: (orderPayment: OrderPayment, unchainedAPI) => Promise; }; const ORDER_PAYMENT_EVENTS: string[] = ['ORDER_UPDATE_PAYMENT', 'ORDER_SIGN_PAYMENT', 'ORDER_PAY']; diff --git a/packages/core-orders/src/module/configureOrderPositionsModule.ts b/packages/core-orders/src/module/configureOrderPositionsModule.ts index a91f846aaf..dfcea962d0 100644 --- a/packages/core-orders/src/module/configureOrderPositionsModule.ts +++ b/packages/core-orders/src/module/configureOrderPositionsModule.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { IProductPricingSheet, Product } from '@unchainedshop/core-products'; import { Order, OrderPosition, OrderDiscount, OrderDelivery } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; @@ -18,14 +17,10 @@ export type OrderPositionsModule = { discounts: ( orderPosition: OrderPosition, params: { order: Order; orderDiscount: OrderDiscount }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Array; - pricingSheet: ( - orderPosition: OrderPosition, - currency: string, - unchainedAPI: UnchainedCore, - ) => IProductPricingSheet; + pricingSheet: (orderPosition: OrderPosition, currency: string, unchainedAPI) => IProductPricingSheet; delete: (orderPositionId: string) => Promise; @@ -39,7 +34,7 @@ export type OrderPositionsModule = { quantity?: number; }, params: { order: Order; product: Product; orderPosition: OrderPosition }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; updateScheduling: ( @@ -48,13 +43,10 @@ export type OrderPositionsModule = { orderDelivery: OrderDelivery; orderPosition: OrderPosition; }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; - updateCalculation: ( - orderPosition: OrderPosition, - unchainedAPI: UnchainedCore, - ) => Promise; + updateCalculation: (orderPosition: OrderPosition, unchainedAPI) => Promise; addProductItem: ( doc: { @@ -67,7 +59,7 @@ export type OrderPositionsModule = { quotationId?: string; }, params: { order: Order; product: Product }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; }; diff --git a/packages/core-orders/src/module/configureOrdersModule-mutations.ts b/packages/core-orders/src/module/configureOrdersModule-mutations.ts index c7292f0e42..a36dd0b1b5 100644 --- a/packages/core-orders/src/module/configureOrdersModule-mutations.ts +++ b/packages/core-orders/src/module/configureOrdersModule-mutations.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { Order, OrderStatus, OrderDelivery, OrderPayment, OrderPosition } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; import { @@ -25,16 +24,8 @@ export interface OrderMutations { setCartOwner: (params: { orderId: string; userId: string }) => Promise; moveCartPositions: (params: { fromOrderId: string; toOrderId: string }) => Promise; - setDeliveryProvider: ( - orderId: string, - deliveryProviderId: string, - unchainedAPI: UnchainedCore, - ) => Promise; - setPaymentProvider: ( - orderId: string, - paymentProviderId: string, - unchainedAPI: UnchainedCore, - ) => Promise; + setDeliveryProvider: (orderId: string, deliveryProviderId: string, unchainedAPI) => Promise; + setPaymentProvider: (orderId: string, paymentProviderId: string, unchainedAPI) => Promise; updateBillingAddress: (orderId: string, billingAddress: Address) => Promise; updateContact: (orderId: string, contact: Contact) => Promise; diff --git a/packages/core-orders/src/module/configureOrdersModule-processing.ts b/packages/core-orders/src/module/configureOrdersModule-processing.ts index 52d8ebda63..377745b299 100644 --- a/packages/core-orders/src/module/configureOrdersModule-processing.ts +++ b/packages/core-orders/src/module/configureOrdersModule-processing.ts @@ -1,18 +1,11 @@ import { mongodb, generateDbFilterById } from '@unchainedshop/mongodb'; import { ProductTypes } from '@unchainedshop/core-products'; import { emit, registerEvents } from '@unchainedshop/events'; - import { Locker } from '@kontsedal/locco'; import { Order, OrderStatus, OrderDelivery, OrderPayment, OrderPosition } from '../types.js'; -import { UnchainedCore } from '@unchainedshop/core'; - import { ordersSettings } from '../orders-settings.js'; -export type OrderContextParams

= ( - order: Order, - params: P, - unchainedAPI: UnchainedCore, -) => Promise; +export type OrderContextParams

= (order: Order, params: P, unchainedAPI) => Promise; export type OrderTransactionContext = { paymentContext?: any; @@ -22,11 +15,7 @@ export type OrderTransactionContext = { }; export interface OrderProcessing { - checkout: ( - orderId: string, - params: OrderTransactionContext, - unchainedAPI: UnchainedCore, - ) => Promise; + checkout: (orderId: string, params: OrderTransactionContext, unchainedAPI) => Promise; confirm: OrderContextParams; reject: OrderContextParams; processOrder: OrderContextParams; @@ -160,7 +149,7 @@ export const configureOrderModuleProcessing = ({ return errors; }; - const itemValidationErrors = async (order: Order, unchainedAPI: UnchainedCore) => { + const itemValidationErrors = async (order: Order, unchainedAPI) => { // Check if items are valid const orderPositions = await findOrderPositions(order); if (orderPositions.length === 0) { @@ -204,7 +193,7 @@ export const configureOrderModuleProcessing = ({ return validationErrors.flatMap((f) => f); }; - const isAutoConfirmationEnabled = async (order: Order, unchainedAPI: UnchainedCore) => { + const isAutoConfirmationEnabled = async (order: Order, unchainedAPI) => { const { modules } = unchainedAPI; if (order.status === OrderStatus.FULLFILLED || order.status === OrderStatus.CONFIRMED) { @@ -226,7 +215,7 @@ export const configureOrderModuleProcessing = ({ return true; }; - const isAutoFullfillmentEnabled = async (order: Order, unchainedAPI: UnchainedCore) => { + const isAutoFullfillmentEnabled = async (order: Order, unchainedAPI) => { const { modules } = unchainedAPI; const orderPayment = await findOrderPayment(order); @@ -251,7 +240,7 @@ export const configureOrderModuleProcessing = ({ const findNextStatus = async ( status: OrderStatus | null, order: Order, - unchainedAPI: UnchainedCore, + unchainedAPI, ): Promise => { if (status === null) { return OrderStatus.PENDING; diff --git a/packages/core-orders/src/module/configureOrdersModule-transformations.ts b/packages/core-orders/src/module/configureOrdersModule-transformations.ts index ce102a4242..20bcf316bd 100644 --- a/packages/core-orders/src/module/configureOrdersModule-transformations.ts +++ b/packages/core-orders/src/module/configureOrdersModule-transformations.ts @@ -6,7 +6,6 @@ import { OrderPricingRowCategory, OrderPricingSheet, } from '../director/OrderPricingSheet.js'; -import { UnchainedCore } from '@unchainedshop/core'; import { ProductPricingRowCategory } from '@unchainedshop/core-products'; import { DeliveryPricingRowCategory } from '@unchainedshop/core-delivery'; import { OrderPrice, OrderPricingDiscount } from '../director/OrderPricingDirector.js'; @@ -15,13 +14,9 @@ export interface OrderTransformations { discounted: ( order: Order, orderDiscount: OrderDiscount, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise>; - discountTotal: ( - order: Order, - orderDiscount: OrderDiscount, - unchainedAPI: UnchainedCore, - ) => Promise; + discountTotal: (order: Order, orderDiscount: OrderDiscount, unchainedAPI) => Promise; isCart: (order: Order) => boolean; cart: (order: { countryContext?: string; orderNumber?: string; userId: string }) => Promise; diff --git a/packages/core-orders/src/module/configureOrdersModule.ts b/packages/core-orders/src/module/configureOrdersModule.ts index 60f0d3492c..f7706f6769 100644 --- a/packages/core-orders/src/module/configureOrdersModule.ts +++ b/packages/core-orders/src/module/configureOrdersModule.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { generateDbFilterById, ModuleInput } from '@unchainedshop/mongodb'; import { createRequire } from 'node:module'; import { OrderDeliveriesCollection } from '../db/OrderDeliveriesCollection.js'; @@ -31,9 +30,9 @@ export type OrdersModule = OrderQueries & OrderProcessing & OrderMutations & { // Order context recalculations - initProviders: (order: Order, unchainedAPI: UnchainedCore) => Promise; - updateCalculation: (orderId: string, unchainedAPI: UnchainedCore) => Promise; - invalidateProviders: (unchainedAPI: UnchainedCore, maxAgeDays: number) => Promise; + initProviders: (order: Order, unchainedAPI) => Promise; + updateCalculation: (orderId: string, unchainedAPI) => Promise; + invalidateProviders: (unchainedAPI, maxAgeDays: number) => Promise; // Sub entities deliveries: OrderDeliveriesModule; @@ -82,7 +81,7 @@ export const configureOrdersModule = async ({ const findOrderPayment = async (order: Order) => OrderPayments.findOne(generateDbFilterById(order.paymentId), {}); - const updateDiscounts = async (order: Order, unchainedAPI: UnchainedCore) => { + const updateDiscounts = async (order: Order, unchainedAPI) => { const { modules } = unchainedAPI; // 1. go through existing order-discounts and check if discount still valid, @@ -124,7 +123,7 @@ export const configureOrdersModule = async ({ ); }; - const initProviders = async (order: Order, unchainedAPI: UnchainedCore) => { + const initProviders = async (order: Order, unchainedAPI) => { const { modules } = unchainedAPI; let updatedOrder = order; diff --git a/packages/core-orders/src/orders-settings.ts b/packages/core-orders/src/orders-settings.ts index 0b2e3e412a..bc4558cdd4 100644 --- a/packages/core-orders/src/orders-settings.ts +++ b/packages/core-orders/src/orders-settings.ts @@ -1,6 +1,5 @@ import { generateRandomHash } from '@unchainedshop/utils'; import { Order } from './types.js'; -import { UnchainedCore } from '@unchainedshop/core'; import { Product } from '@unchainedshop/core-products'; export interface OrderSettingsOrderPositionValidation { @@ -15,7 +14,7 @@ export interface OrdersSettingsOptions { orderNumberHashFn?: (order: Order, index: number) => string; validateOrderPosition?: ( validationParams: OrderSettingsOrderPositionValidation, - context: UnchainedCore, + context, ) => Promise; lockOrderDuringCheckout?: boolean; } diff --git a/packages/core-payment/src/director/PaymentDirector.ts b/packages/core-payment/src/director/PaymentDirector.ts index 4cd1a403ea..7166a2e7e1 100644 --- a/packages/core-payment/src/director/PaymentDirector.ts +++ b/packages/core-payment/src/director/PaymentDirector.ts @@ -32,14 +32,11 @@ export const PaymentDirector: IPaymentDirector = { newPaymentContext.order = order; } - const adapter = Adapter.actions({ - config: paymentProvider.configuration, - paymentContext: { - paymentProvider, - paymentProviderId: paymentProvider._id, - ...newPaymentContext, - }, - context: unchainedAPI, + const adapter = Adapter.actions(paymentProvider.configuration, { + paymentProvider, + paymentProviderId: paymentProvider._id, + ...newPaymentContext, + ...unchainedAPI, }); return { diff --git a/packages/core-payment/src/director/PaymentPricingAdapter.ts b/packages/core-payment/src/director/PaymentPricingAdapter.ts index 56fa127e15..cfad316696 100644 --- a/packages/core-payment/src/director/PaymentPricingAdapter.ts +++ b/packages/core-payment/src/director/PaymentPricingAdapter.ts @@ -4,7 +4,6 @@ import { IPricingSheet, PricingCalculation, } from '@unchainedshop/utils'; -import { UnchainedCore } from '@unchainedshop/core'; import { BasePricingAdapter } from '@unchainedshop/utils'; import { PaymentPricingSheet } from './PaymentPricingSheet.js'; import { User } from '@unchainedshop/core-users'; @@ -19,7 +18,7 @@ export interface PaymentPricingCalculation extends PricingCalculation { isNetPrice: boolean; rate?: number; } -export interface PaymentPricingAdapterContext extends BasePricingAdapterContext, UnchainedCore { +export interface PaymentPricingAdapterContext extends BasePricingAdapterContext { country?: string; currency?: string; user: User; diff --git a/packages/core-payment/src/director/PaymentPricingDirector.ts b/packages/core-payment/src/director/PaymentPricingDirector.ts index 0d581721c3..e3f47cf0e9 100644 --- a/packages/core-payment/src/director/PaymentPricingDirector.ts +++ b/packages/core-payment/src/director/PaymentPricingDirector.ts @@ -11,7 +11,6 @@ import { Order } from '@unchainedshop/core-orders'; import { PaymentProvider } from '../types.js'; import { OrderPayment } from '@unchainedshop/core-orders'; import { IPricingDirector } from '@unchainedshop/utils'; -import { UnchainedCore } from '@unchainedshop/core'; export type PaymentPricingContext = | { @@ -31,8 +30,7 @@ export type IPaymentPricingDirector = IPricingD PaymentPricingCalculation, PaymentPricingAdapterContext, IPaymentPricingSheet, - IPaymentPricingAdapter, - UnchainedCore + IPaymentPricingAdapter >; const baseDirector = BasePricingDirector< diff --git a/packages/core-payment/src/module/configurePaymentModule.ts b/packages/core-payment/src/module/configurePaymentModule.ts index 46fe02d28f..c75e2905cc 100644 --- a/packages/core-payment/src/module/configurePaymentModule.ts +++ b/packages/core-payment/src/module/configurePaymentModule.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { PaymentCredentialsCollection, PaymentCredentials as PaymentCredentialsType, @@ -23,7 +22,7 @@ export type PaymentModule = { registerCredentials: ( paymentProviderId: string, paymentContext: PaymentContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; paymentProviders: PaymentProvidersModules; diff --git a/packages/core-payment/src/module/configurePaymentProvidersModule.ts b/packages/core-payment/src/module/configurePaymentProvidersModule.ts index 55ebe67eb7..89ba5ff7b8 100644 --- a/packages/core-payment/src/module/configurePaymentProvidersModule.ts +++ b/packages/core-payment/src/module/configurePaymentProvidersModule.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { PaymentChargeActionResult, PaymentContext, @@ -40,14 +39,11 @@ export type PaymentProvidersModules = { providerExists: (query: { paymentProviderId: string }) => Promise; // Payment adapter - findSupported: ( - query: { order: Order }, - unchainedAPI: UnchainedCore, - ) => Promise>; + findSupported: (query: { order: Order }, unchainedAPI) => Promise>; determineDefault: ( paymentProviders: Array, params: { order: Order; paymentCredentials?: Array }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; findInterface: (query: PaymentProvider) => PaymentInterface; @@ -58,50 +54,31 @@ export type PaymentProvidersModules = { currency: string; }) => IPaymentPricingSheet; - configurationError: ( - paymentProvider: PaymentProvider, - unchainedAPI: UnchainedCore, - ) => Promise; + configurationError: (paymentProvider: PaymentProvider, unchainedAPI) => Promise; - isActive: (paymentProvider: PaymentProvider, unchainedAPI: UnchainedCore) => Promise; + isActive: (paymentProvider: PaymentProvider, unchainedAPI) => Promise; - isPayLaterAllowed: (paymentProvider: PaymentProvider, unchainedAPI: UnchainedCore) => Promise; + isPayLaterAllowed: (paymentProvider: PaymentProvider, unchainedAPI) => Promise; calculate: ( pricingContext: PaymentPricingContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise>; charge: ( paymentProviderId: string, paymentContext: PaymentContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; - register: ( - paymentProviderId: string, - paymentContext: PaymentContext, - unchainedAPI: UnchainedCore, - ) => Promise; - sign: ( - paymentProviderId: string, - paymentContext: PaymentContext, - unchainedAPI: UnchainedCore, - ) => Promise; + register: (paymentProviderId: string, paymentContext: PaymentContext, unchainedAPI) => Promise; + sign: (paymentProviderId: string, paymentContext: PaymentContext, unchainedAPI) => Promise; validate: ( paymentProviderId: string, paymentContext: PaymentContext, - unchainedAPI: UnchainedCore, - ) => Promise; - cancel: ( - paymentProviderId: string, - paymentContext: PaymentContext, - unchainedAPI: UnchainedCore, - ) => Promise; - confirm: ( - paymentProviderId: string, - paymentContext: PaymentContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; + cancel: (paymentProviderId: string, paymentContext: PaymentContext, unchainedAPI) => Promise; + confirm: (paymentProviderId: string, paymentContext: PaymentContext, unchainedAPI) => Promise; }; const PAYMENT_PROVIDER_EVENTS: string[] = [ @@ -128,7 +105,7 @@ export const configurePaymentProvidersModule = ( const getPaymentAdapter = async ( paymentProviderId: string, paymentContext: PaymentContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { const provider = await PaymentProviders.findOne(generateDbFilterById(paymentProviderId), {}); diff --git a/packages/core-payment/src/payment-settings.ts b/packages/core-payment/src/payment-settings.ts index 04b94ac4ca..53dc5dcc9e 100644 --- a/packages/core-payment/src/payment-settings.ts +++ b/packages/core-payment/src/payment-settings.ts @@ -1,6 +1,5 @@ import { Order } from '@unchainedshop/core-orders'; import { PaymentProvider } from './types.js'; -import { UnchainedCore } from '@unchainedshop/core'; import { PaymentCredentials } from './db/PaymentCredentialsCollection.js'; export type FilterProviders = ( @@ -8,7 +7,7 @@ export type FilterProviders = ( providers: Array; order: Order; }, - context: UnchainedCore, + unchainedAPI, ) => Promise>; export type DetermineDefaultProvider = ( @@ -17,7 +16,7 @@ export type DetermineDefaultProvider = ( order: Order; paymentCredentials?: Array; }, - context: UnchainedCore, + unchainedAPI, ) => Promise; export interface PaymentSettingsOptions { sortProviders?: (a: PaymentProvider, b: PaymentProvider) => number; diff --git a/packages/core-payment/src/types.ts b/packages/core-payment/src/types.ts index 3faf5aed53..16802602e6 100644 --- a/packages/core-payment/src/types.ts +++ b/packages/core-payment/src/types.ts @@ -2,7 +2,6 @@ import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils'; import { TimestampFields } from '@unchainedshop/mongodb'; import { Order } from '@unchainedshop/core-orders'; import { OrderPayment } from '@unchainedshop/core-orders'; -import { UnchainedCore } from '@unchainedshop/core'; export enum PaymentProviderType { CARD = 'CARD', @@ -61,26 +60,25 @@ export interface IPaymentActions { confirm: (transactionContext?: any) => Promise; } -export type IPaymentAdapter = IBaseAdapter & { +export type IPaymentAdapter = IBaseAdapter & { initialConfiguration: PaymentConfiguration; typeSupported: (type: PaymentProviderType) => boolean; - actions: (params: { - config: PaymentConfiguration; - paymentContext: PaymentContext & { + actions: ( + config: PaymentConfiguration, + context: PaymentContext & { paymentProviderId: string; paymentProvider: PaymentProvider; - }; - context: UnchainedCore; - }) => IPaymentActions; + } & UnchainedAPI, + ) => IPaymentActions; }; export type IPaymentDirector = IBaseDirector & { actions: ( paymentProvider: PaymentProvider, paymentContext: PaymentContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; }; diff --git a/packages/core-products/src/director/ProductDiscountAdapter.ts b/packages/core-products/src/director/ProductDiscountAdapter.ts index f9f25517ee..43598e50fb 100644 --- a/packages/core-products/src/director/ProductDiscountAdapter.ts +++ b/packages/core-products/src/director/ProductDiscountAdapter.ts @@ -1,8 +1,7 @@ import { BaseDiscountAdapter, IDiscountAdapter } from '@unchainedshop/utils'; import { ProductDiscountConfiguration } from './ProductDiscountConfiguration.js'; -import { UnchainedCore } from '@unchainedshop/core'; export const ProductDiscountAdapter: Omit< - IDiscountAdapter, + IDiscountAdapter, 'key' | 'label' | 'version' > = BaseDiscountAdapter; diff --git a/packages/core-products/src/director/ProductDiscountDirector.ts b/packages/core-products/src/director/ProductDiscountDirector.ts index a797478258..cbf0df8876 100644 --- a/packages/core-products/src/director/ProductDiscountDirector.ts +++ b/packages/core-products/src/director/ProductDiscountDirector.ts @@ -1,7 +1,6 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { BaseDiscountDirector } from '@unchainedshop/utils'; import { ProductDiscountConfiguration } from './ProductDiscountConfiguration.js'; -export const ProductDiscountDirector = BaseDiscountDirector( +export const ProductDiscountDirector = BaseDiscountDirector( 'ProductDiscountDirector', ); diff --git a/packages/core-products/src/director/ProductPricingDirector.ts b/packages/core-products/src/director/ProductPricingDirector.ts index 9db741c14e..120211b448 100644 --- a/packages/core-products/src/director/ProductPricingDirector.ts +++ b/packages/core-products/src/director/ProductPricingDirector.ts @@ -7,7 +7,6 @@ import { } from '../types.js'; import { BasePricingDirector } from '@unchainedshop/utils'; import { ProductPricingSheet } from './ProductPricingSheet.js'; -import { UnchainedCore } from '@unchainedshop/core'; const baseDirector = BasePricingDirector< ProductPricingContext, diff --git a/packages/core-products/src/module/configureProductsModule.ts b/packages/core-products/src/module/configureProductsModule.ts index 631a90b5a4..cbae82c23f 100644 --- a/packages/core-products/src/module/configureProductsModule.ts +++ b/packages/core-products/src/module/configureProductsModule.ts @@ -1,4 +1,3 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { Product, ProductAssignment, @@ -122,7 +121,7 @@ export type ProductsModule = { productExists: (params: { productId?: string; slug?: string }) => Promise; // Transformations - interface: (productDiscount: ProductDiscount) => IDiscountAdapter; + interface: (productDiscount: ProductDiscount) => IDiscountAdapter; isActive: (product: Product) => boolean; isDraft: (product: Product) => boolean; @@ -149,7 +148,7 @@ export type ProductsModule = { resolveOrderableProduct: ( product: Product, params: { configuration?: Array }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; prices: { @@ -168,7 +167,7 @@ export type ProductsModule = { useNetPrice?: boolean; configuration?: Array; }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; catalogPrices: (prodct: Product) => Array; @@ -204,7 +203,7 @@ export type ProductsModule = { useNetPrice?: boolean; vectors: Array; }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; rates: { @@ -226,7 +225,7 @@ export type ProductsModule = { calculate: ( pricingContext: ProductPricingContext & { item: OrderPosition }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise>; // Mutations diff --git a/packages/core-products/src/types.ts b/packages/core-products/src/types.ts index d70fdd39e8..f3dd8098b5 100644 --- a/packages/core-products/src/types.ts +++ b/packages/core-products/src/types.ts @@ -4,7 +4,6 @@ import { TimestampFields, mongodb } from '@unchainedshop/mongodb'; import { OrderDiscount } from '@unchainedshop/core-orders'; import { OrderPosition } from '@unchainedshop/core-orders'; import { OrderPrice } from '@unchainedshop/core-orders'; -import { UnchainedCore } from '@unchainedshop/core'; import { BasePricingAdapterContext, IPricingAdapter, @@ -235,7 +234,7 @@ export interface ProductPricingCalculation extends PricingCalculation { rate?: number; } -export interface ProductPricingAdapterContext extends BasePricingAdapterContext, UnchainedCore { +export interface ProductPricingAdapterContext extends BasePricingAdapterContext { country: string; currency: string; product: Product; @@ -284,8 +283,11 @@ export interface IProductPricingSheet extends IPricingSheet = IPricingAdapter< - ProductPricingAdapterContext, +export type IProductPricingAdapter< + UnchainedAPI = any, + DiscountConfiguration = unknown, +> = IPricingAdapter< + ProductPricingAdapterContext & UnchainedAPI, ProductPricingCalculation, IProductPricingSheet, DiscountConfiguration @@ -296,8 +298,7 @@ export type IProductPricingDirector = IPricingD ProductPricingCalculation, ProductPricingAdapterContext, IProductPricingSheet, - IProductPricingAdapter, - UnchainedCore + IProductPricingAdapter >; export type ProductPriceRate = { diff --git a/packages/core-quotations/src/director/QuotationDirector.ts b/packages/core-quotations/src/director/QuotationDirector.ts index 2d14961f07..936440bbdb 100644 --- a/packages/core-quotations/src/director/QuotationDirector.ts +++ b/packages/core-quotations/src/director/QuotationDirector.ts @@ -1,14 +1,13 @@ import { LogLevel, log } from '@unchainedshop/logger'; import { IQuotationAdapter, IQuotationDirector, QuotationContext } from '../types.js'; import { BaseDirector } from '@unchainedshop/utils'; -import { UnchainedCore } from '@unchainedshop/core'; import { QuotationError } from './QuotationError.js'; const baseDirector = BaseDirector('QuotationDirector', { adapterSortKey: 'orderIndex', }); -const findAppropriateAdapters = (quotationContext: QuotationContext, unchainedAPI: UnchainedCore) => +const findAppropriateAdapters = (quotationContext: QuotationContext, unchainedAPI) => baseDirector.getAdapters({ adapterFilter: (Adapter: IQuotationAdapter) => { const activated = Adapter.isActivatedFor(quotationContext, unchainedAPI); diff --git a/packages/core-quotations/src/module/configureQuotationsModule.ts b/packages/core-quotations/src/module/configureQuotationsModule.ts index a9f60547a5..6c3c43a1e0 100644 --- a/packages/core-quotations/src/module/configureQuotationsModule.ts +++ b/packages/core-quotations/src/module/configureQuotationsModule.ts @@ -1,5 +1,4 @@ import { SortDirection, SortOption } from '@unchainedshop/utils'; -import { UnchainedCore } from '@unchainedshop/core'; import { Quotation, QuotationItemConfiguration, QuotationProposal } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; import { @@ -46,7 +45,7 @@ export interface QuotationTransformations { export type QuotationContextParams = ( quotation: Quotation, params: { quotationContext?: any }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; // Mutations @@ -57,7 +56,7 @@ export interface QuotationData { userId: string; } export interface QuotationMutations { - create: (doc: QuotationData, unchainedAPI: UnchainedCore) => Promise; + create: (doc: QuotationData, unchainedAPI) => Promise; updateContext: (quotationId: string, context: any) => Promise; @@ -70,14 +69,14 @@ export interface QuotationMutations { } export interface QuotationProcessing { - fullfillQuotation: (quotationId: string, info: any, unchainedAPI: UnchainedCore) => Promise; + fullfillQuotation: (quotationId: string, info: any, unchainedAPI) => Promise; proposeQuotation: QuotationContextParams; rejectQuotation: QuotationContextParams; verifyQuotation: QuotationContextParams; transformItemConfiguration: ( quotation: Quotation, configuration: QuotationItemConfiguration, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; } @@ -125,10 +124,7 @@ export const configureQuotationsModule = async ({ return findNewQuotationNumber(quotation, index + 1); }; - const findNextStatus = async ( - quotation: Quotation, - unchainedAPI: UnchainedCore, - ): Promise => { + const findNextStatus = async (quotation: Quotation, unchainedAPI): Promise => { let status = quotation.status as QuotationStatus; const director = await QuotationDirector.actions({ quotation }, unchainedAPI); @@ -200,7 +196,7 @@ export const configureQuotationsModule = async ({ const processQuotation = async ( initialQuotation: Quotation, params: { quotationContext?: any }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { const { modules } = unchainedAPI; @@ -236,7 +232,7 @@ export const configureQuotationsModule = async ({ return updateStatus(quotation._id, { status: nextStatus, info: 'quotation processed' }); }; - const sendStatusToCustomer = async (quotation: Quotation, unchainedAPI: UnchainedCore) => { + const sendStatusToCustomer = async (quotation: Quotation, unchainedAPI) => { const { modules } = unchainedAPI; const user = await modules.users.findUserById(quotation.userId); diff --git a/packages/core-quotations/src/types.ts b/packages/core-quotations/src/types.ts index 9eb9990f2d..5bd31f83f9 100644 --- a/packages/core-quotations/src/types.ts +++ b/packages/core-quotations/src/types.ts @@ -1,6 +1,5 @@ import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils'; import { TimestampFields, LogFields } from '@unchainedshop/mongodb'; -import { UnchainedCore } from '@unchainedshop/core'; export enum QuotationStatus { REQUESTED = 'REQUESTED', @@ -62,13 +61,10 @@ export interface QuotationAdapterActions { export type IQuotationAdapter = IBaseAdapter & { orderIndex: number; - isActivatedFor: (quotationContext: QuotationContext, unchainedAPI: UnchainedCore) => boolean; - actions: (params: QuotationContext & UnchainedCore) => QuotationAdapterActions; + isActivatedFor: (quotationContext: QuotationContext, unchainedAPI) => boolean; + actions: (params: QuotationContext) => QuotationAdapterActions; }; export type IQuotationDirector = IBaseDirector & { - actions: ( - quotationContext: QuotationContext, - unchainedAPI: UnchainedCore, - ) => Promise; + actions: (quotationContext: QuotationContext, unchainedAPI) => Promise; }; diff --git a/packages/core-warehousing/src/director/WarehousingDirector.ts b/packages/core-warehousing/src/director/WarehousingDirector.ts index 2924869aac..41076c8225 100644 --- a/packages/core-warehousing/src/director/WarehousingDirector.ts +++ b/packages/core-warehousing/src/director/WarehousingDirector.ts @@ -1,8 +1,8 @@ import { IWarehousingAdapter, IWarehousingDirector, WarehousingContext } from '../types.js'; -import { DeliveryDirector } from '@unchainedshop/core-delivery'; import { log, LogLevel } from '@unchainedshop/logger'; import { BaseDirector } from '@unchainedshop/utils'; import { WarehousingError } from './WarehousingError.js'; +import { DeliveryDirector } from '@unchainedshop/core-delivery'; const getReferenceDate = (context: WarehousingContext) => { return context && context.referenceDate ? context.referenceDate : new Date(); diff --git a/packages/core-warehousing/src/module/configureWarehousingModule.ts b/packages/core-warehousing/src/module/configureWarehousingModule.ts index aafe85a33a..3aade157f6 100644 --- a/packages/core-warehousing/src/module/configureWarehousingModule.ts +++ b/packages/core-warehousing/src/module/configureWarehousingModule.ts @@ -1,6 +1,3 @@ -import { User } from '@unchainedshop/core-users'; - -import { UnchainedCore } from '@unchainedshop/core'; import { WarehousingContext, WarehousingProvider, @@ -14,9 +11,9 @@ import { WarehousingDirector } from '../director/WarehousingDirector.js'; import { TokenSurrogateCollection } from '../db/TokenSurrogateCollection.js'; import { EstimatedDispatch, EstimatedStock, TokenSurrogate, WarehousingInterface } from '../types.js'; import { WarehousingError } from '../warehousing-index.js'; -import { Order } from '@unchainedshop/core-orders'; -import { OrderPosition } from '@unchainedshop/core-orders'; -import { Product } from '@unchainedshop/core-products'; +import type { Order, OrderPosition } from '@unchainedshop/core-orders'; +import type { Product } from '@unchainedshop/core-products'; +import type { User } from '@unchainedshop/core-users'; export type WarehousingModule = { // Queries @@ -38,26 +35,23 @@ export type WarehousingModule = { findSupported: ( warehousingContext: WarehousingContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise>; findInterface: (query: WarehousingProvider) => WarehousingInterface; findInterfaces: (query: WarehousingProviderQuery) => Array; - configurationError: ( - provider: WarehousingProvider, - unchainedAPI: UnchainedCore, - ) => Promise; - isActive: (provider: WarehousingProvider, unchainedAPI: UnchainedCore) => Promise; + configurationError: (provider: WarehousingProvider, unchainedAPI) => Promise; + isActive: (provider: WarehousingProvider, unchainedAPI) => Promise; estimatedDispatch: ( provider: WarehousingProvider, context: WarehousingContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; estimatedStock: ( provider: WarehousingProvider, context: WarehousingContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; updateTokenOwnership: (input: { @@ -78,19 +72,19 @@ export type WarehousingModule = { product: Product; }>; }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; tokenMetadata: ( chainTokenId: string, params: { product: Product; token: TokenSurrogate; referenceDate: Date; locale: Intl.Locale }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; isInvalidateable: ( chainTokenId: string, params: { product: Product; token: TokenSurrogate; referenceDate: Date }, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise; // Mutations diff --git a/packages/core-warehousing/src/types.ts b/packages/core-warehousing/src/types.ts index 5f466b5bcd..1e2f6d45fb 100644 --- a/packages/core-warehousing/src/types.ts +++ b/packages/core-warehousing/src/types.ts @@ -1,10 +1,8 @@ import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils'; import { TimestampFields } from '@unchainedshop/mongodb'; -import { DeliveryProvider } from '@unchainedshop/core-delivery'; -import { Product } from '@unchainedshop/core-products'; -import { Order } from '@unchainedshop/core-orders'; -import { OrderPosition } from '@unchainedshop/core-orders'; -import { UnchainedCore } from '@unchainedshop/core'; +import type { DeliveryProvider } from '@unchainedshop/core-delivery'; +import type { Product } from '@unchainedshop/core-products'; +import type { Order, OrderPosition } from '@unchainedshop/core-orders'; export enum WarehousingProviderType { PHYSICAL = 'PHYSICAL', @@ -87,17 +85,14 @@ export type IWarehousingAdapter = IBaseAdapter & { initialConfiguration: WarehousingConfiguration; typeSupported: (type: WarehousingProviderType) => boolean; - actions: ( - config: WarehousingConfiguration, - context: WarehousingContext & UnchainedCore, - ) => WarehousingAdapterActions; + actions: (config: WarehousingConfiguration, context: WarehousingContext) => WarehousingAdapterActions; }; export type IWarehousingDirector = IBaseDirector & { actions: ( warehousingProvider: WarehousingProvider, warehousingContext: WarehousingContext, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => Promise<{ configurationError: () => WarehousingError; isActive: () => boolean; diff --git a/packages/core-worker/src/director/WorkerAdapter.ts b/packages/core-worker/src/director/WorkerAdapter.ts index 6181169ec8..06e949a2ae 100644 --- a/packages/core-worker/src/director/WorkerAdapter.ts +++ b/packages/core-worker/src/director/WorkerAdapter.ts @@ -1,6 +1,5 @@ import { log, LogLevel } from '@unchainedshop/logger'; import { IBaseAdapter } from '@unchainedshop/utils'; -import { UnchainedCore } from '@unchainedshop/core'; export interface WorkResult { success: boolean; result?: Result; @@ -12,7 +11,7 @@ export type IWorkerAdapter = IBaseAdapter & { external: boolean; maxParallelAllocations?: number; - doWork: (input: Input, unchainedAPI: UnchainedCore, workId: string) => Promise>; + doWork: (input: Input, unchainedAPI, workId: string) => Promise>; }; export const WorkerAdapter: Omit, 'key' | 'label' | 'type' | 'version'> = { diff --git a/packages/core-worker/src/director/WorkerDirector.ts b/packages/core-worker/src/director/WorkerDirector.ts index 8e6e13d5cb..dc8f4097db 100644 --- a/packages/core-worker/src/director/WorkerDirector.ts +++ b/packages/core-worker/src/director/WorkerDirector.ts @@ -1,6 +1,4 @@ import { WorkData, IWorkerAdapter, WorkResult } from '../worker-index.js'; -import { UnchainedCore } from '@unchainedshop/core'; - import { log, LogLevel } from '@unchainedshop/logger'; import { BaseDirector, IBaseDirector } from '@unchainedshop/utils'; import { Work } from '../types.js'; @@ -28,7 +26,7 @@ export type IWorkerDirector = IBaseDirector> & { disableAutoscheduling: (scheduleId: string) => void; configureAutoscheduling: (workScheduleConfiguration: WorkScheduleConfiguration) => void; getAutoSchedules: () => Array<[string, WorkScheduleConfiguration]>; - doWork: (work: Work, unchainedAPI: UnchainedCore) => Promise>; + doWork: (work: Work, unchainedAPI) => Promise>; }; const AutoScheduleMap = new Map(); diff --git a/packages/core-worker/src/module/configureWorkerModule.ts b/packages/core-worker/src/module/configureWorkerModule.ts index b57f407bad..6c032378a0 100644 --- a/packages/core-worker/src/module/configureWorkerModule.ts +++ b/packages/core-worker/src/module/configureWorkerModule.ts @@ -1,6 +1,4 @@ import { WorkData, WorkResult } from '../worker-index.js'; -import { UnchainedCore } from '@unchainedshop/core'; - import os from 'os'; import { createLogger } from '@unchainedshop/logger'; import { @@ -67,9 +65,9 @@ export type WorkerModule = { allocateWork: (doc: { types: Array; worker: string }) => Promise; - processNextWork: (unchainedAPI: UnchainedCore, workerId?: string) => Promise; + processNextWork: (unchainedAPI, workerId?: string) => Promise; - rescheduleWork: (work: Work, scheduled: Date, unchainedAPI: UnchainedCore) => Promise; + rescheduleWork: (work: Work, scheduled: Date, unchainedAPI) => Promise; ensureOneWork: (work: WorkData) => Promise; diff --git a/packages/core-worker/src/schedulers/FailedRescheduler.ts b/packages/core-worker/src/schedulers/FailedRescheduler.ts index 767651991f..9b1da4bd84 100644 --- a/packages/core-worker/src/schedulers/FailedRescheduler.ts +++ b/packages/core-worker/src/schedulers/FailedRescheduler.ts @@ -1,7 +1,6 @@ import { log } from '@unchainedshop/logger'; import { subscribe } from '@unchainedshop/events'; import { WorkerEventTypes } from '../director/WorkerEventTypes.js'; -import { UnchainedCore } from '@unchainedshop/core'; import { WorkData } from '../worker-index.js'; import { Work } from '../types.js'; @@ -19,7 +18,7 @@ export type IScheduler

= { actions: ( params: P, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { start: () => void; stop: () => void; diff --git a/packages/core-worker/src/workers/BaseWorker.ts b/packages/core-worker/src/workers/BaseWorker.ts index 19c4c51a63..1ee02b9a5c 100644 --- a/packages/core-worker/src/workers/BaseWorker.ts +++ b/packages/core-worker/src/workers/BaseWorker.ts @@ -1,7 +1,6 @@ import later from '@breejs/later'; import { log } from '@unchainedshop/logger'; import { WorkerDirector } from '../director/WorkerDirector.js'; -import { UnchainedCore } from '@unchainedshop/core'; import { Work } from '../types.js'; export type WorkData = Pick< @@ -20,7 +19,7 @@ export type IWorker

= { actions: ( params: P, - unchainedAPI: UnchainedCore, + unchainedAPI, ) => { autorescheduleTypes: (options: { referenceDate: Date }) => Promise>; process: (options: { maxWorkItemCount?: number; referenceDate?: Date }) => Promise; diff --git a/packages/plugins/src/delivery/send-message.ts b/packages/plugins/src/delivery/send-message.ts index 1c8529777d..07486f489b 100644 --- a/packages/plugins/src/delivery/send-message.ts +++ b/packages/plugins/src/delivery/send-message.ts @@ -1,7 +1,8 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IDeliveryAdapter } from '@unchainedshop/core-delivery'; import { DeliveryAdapter, DeliveryDirector, DeliveryProviderType } from '@unchainedshop/core-delivery'; -const SendMessage: IDeliveryAdapter = { +const SendMessage: IDeliveryAdapter = { ...DeliveryAdapter, key: 'shop.unchained.delivery.send-message', diff --git a/packages/plugins/src/filters/local-search.ts b/packages/plugins/src/filters/local-search.ts index 61a70f631f..31559af909 100644 --- a/packages/plugins/src/filters/local-search.ts +++ b/packages/plugins/src/filters/local-search.ts @@ -3,6 +3,7 @@ import { IFilterAdapter } from '@unchainedshop/core-filters'; import { mongodb } from '@unchainedshop/mongodb'; import { ProductText } from '@unchainedshop/core-products'; import { AssortmentText } from '@unchainedshop/core-assortments'; +import { UnchainedCore } from '@unchainedshop/core'; function escapeStringRegexp(string) { if (typeof string !== 'string') { @@ -15,7 +16,7 @@ function escapeStringRegexp(string) { const { AMAZON_DOCUMENTDB_COMPAT_MODE } = process.env; -const LocalSearch: IFilterAdapter = { +const LocalSearch: IFilterAdapter = { ...FilterAdapter, key: 'shop.unchained.filters.local-search', diff --git a/packages/plugins/src/filters/strict-equal.ts b/packages/plugins/src/filters/strict-equal.ts index e5c3ba885c..cabb50107e 100644 --- a/packages/plugins/src/filters/strict-equal.ts +++ b/packages/plugins/src/filters/strict-equal.ts @@ -1,7 +1,8 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IFilterAdapter } from '@unchainedshop/core-filters'; import { FilterDirector, FilterAdapter } from '@unchainedshop/core-filters'; -const StrictQualFilter: IFilterAdapter = { +const StrictQualFilter: IFilterAdapter = { ...FilterAdapter, key: 'shop.unchained.filters.strict-qual', diff --git a/packages/plugins/src/payment/apple-iap/adapter.ts b/packages/plugins/src/payment/apple-iap/adapter.ts index d511494d9a..db678ae56a 100644 --- a/packages/plugins/src/payment/apple-iap/adapter.ts +++ b/packages/plugins/src/payment/apple-iap/adapter.ts @@ -201,7 +201,7 @@ export const appleIAPHandler = async (req, res) => { res.end(); }; -const AppleIAP: IPaymentAdapter = { +const AppleIAP: IPaymentAdapter = { ...PaymentAdapter, key: 'shop.unchained.apple-iap', @@ -213,11 +213,11 @@ const AppleIAP: IPaymentAdapter = { return type === 'GENERIC'; }, - actions: (params) => { - const { modules } = params.context; + actions: (params, context) => { + const { modules } = context; const adapterActions = { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(params, context), configurationError() { // eslint-disable-line @@ -278,11 +278,10 @@ const AppleIAP: IPaymentAdapter = { // eslint-disable-next-line async charge(transactionContext) { - const { order } = params.paymentContext; + const { order } = context; const { meta, paymentCredentials, receiptData } = transactionContext || {}; const { transactionIdentifier } = meta || {}; - const appleTransactions = (params.context.modules as any) - .appleTransactions as AppleTransactionsModule; + const appleTransactions = (context.modules as any).appleTransactions as AppleTransactionsModule; if (!transactionIdentifier) { throw new Error('Apple IAP Plugin: You have to set the transaction id on the order payment'); @@ -343,7 +342,7 @@ const AppleIAP: IPaymentAdapter = { throw new Error('Apple IAP Plugin: Transaction already processed'); // All good - const userId = order?.userId || params.paymentContext?.userId; + const userId = order?.userId || context?.userId; await appleTransactions.createTransaction( { _id: transactionIdentifier, diff --git a/packages/plugins/src/payment/braintree.ts b/packages/plugins/src/payment/braintree.ts index 106fe3acbd..c07f3a2791 100644 --- a/packages/plugins/src/payment/braintree.ts +++ b/packages/plugins/src/payment/braintree.ts @@ -1,3 +1,4 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IPaymentAdapter } from '@unchainedshop/core-payment'; import { PaymentDirector, PaymentAdapter, PaymentError } from '@unchainedshop/core-payment'; import { createLogger } from '@unchainedshop/logger'; @@ -6,7 +7,7 @@ const logger = createLogger('unchained:core-payment:braintree'); const { BRAINTREE_SANDBOX_TOKEN, BRAINTREE_PRIVATE_KEY } = process.env; -const BraintreeDirect: IPaymentAdapter = { +const BraintreeDirect: IPaymentAdapter = { ...PaymentAdapter, key: 'shop.unchained.braintree-direct', @@ -28,16 +29,16 @@ const BraintreeDirect: IPaymentAdapter = { return type === 'GENERIC'; }, - actions: (params) => { + actions: (config, context) => { const getPublicKey = () => { - return params.config.reduce((current, item) => { + return config.reduce((current, item) => { if (item.key === 'publicKey') return item.value; return current; }, null); }; const getMerchantId = () => { - return params.config.reduce((current, item) => { + return config.reduce((current, item) => { if (item.key === 'merchantId') return item.value; return current; }, null); @@ -69,7 +70,7 @@ const BraintreeDirect: IPaymentAdapter = { }; const adapter = { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), configurationError: () => { const publicCredentialsValid = @@ -103,8 +104,7 @@ const BraintreeDirect: IPaymentAdapter = { }, charge: async ({ paypalPaymentMethodNonce }) => { - const { modules } = params.context; - const { order } = params.paymentContext; + const { modules, order } = context; if (!paypalPaymentMethodNonce) throw new Error('You have to provide paypalPaymentMethodNonce in paymentContext'); diff --git a/packages/plugins/src/payment/cryptopay/plugin.ts b/packages/plugins/src/payment/cryptopay/plugin.ts index 509f719c4f..d16ec6ad9c 100644 --- a/packages/plugins/src/payment/cryptopay/plugin.ts +++ b/packages/plugins/src/payment/cryptopay/plugin.ts @@ -44,7 +44,11 @@ const getDerivationPath = (currency: CryptopayCurrencies, index: number): string return `0/${address}`; }; -const Cryptopay: IPaymentAdapter = { +const Cryptopay: IPaymentAdapter< + UnchainedCore & { + modules: { cryptopay: CryptopayModule }; + } +> = { ...PaymentAdapter, key: 'shop.unchained.payment.cryptopay', @@ -55,8 +59,8 @@ const Cryptopay: IPaymentAdapter = { return type === 'GENERIC'; }, - actions: (params) => { - const modules = params.context.modules as UnchainedCore['modules'] & { cryptopay: CryptopayModule }; + actions: (config, context) => { + const { modules } = context; const setConversionRates = async (currencyCode: string, existingAddresses: any[]) => { const originCurrencyObj = await modules.currencies.findCurrency({ isoCode: currencyCode }); @@ -97,7 +101,7 @@ const Cryptopay: IPaymentAdapter = { }; const adapterActions = { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), // eslint-disable-next-line configurationError() { @@ -114,10 +118,10 @@ const Cryptopay: IPaymentAdapter = { isActive() { // Only support orders that have prices in BTC or ETH for the moment if (adapterActions.configurationError() !== null) return false; - if (!params.paymentContext.order) return true; + if (!context.order) return true; // if ( // !Object.values(CryptopayCurrencies).includes( - // params.paymentContext.order.currency as CryptopayCurrencies, + // context.order.currency as CryptopayCurrencies, // ) // ) // return false; @@ -129,7 +133,7 @@ const Cryptopay: IPaymentAdapter = { }, sign: async () => { - const { orderPayment, order } = params.paymentContext; + const { orderPayment, order } = context; const existingAddresses = await modules.cryptopay.getWalletAddressesByOrderPaymentId( orderPayment._id, @@ -190,7 +194,7 @@ const Cryptopay: IPaymentAdapter = { }, charge: async () => { - const { order, orderPayment } = params.paymentContext; + const { order, orderPayment } = context; const foundWalletsWithBalances = await modules.cryptopay.getWalletAddressesByOrderPaymentId( orderPayment._id, diff --git a/packages/plugins/src/payment/datatrans-v2/index.ts b/packages/plugins/src/payment/datatrans-v2/index.ts index 037ee5d85a..fd0d133138 100644 --- a/packages/plugins/src/payment/datatrans-v2/index.ts +++ b/packages/plugins/src/payment/datatrans-v2/index.ts @@ -13,6 +13,7 @@ import { } from './api/types.js'; import parseRegistrationData from './parseRegistrationData.js'; import roundedAmountFromOrder from './roundedAmountFromOrder.js'; +import { UnchainedCore } from '@unchainedshop/core'; export * from './middleware.js'; @@ -39,7 +40,7 @@ const throwIfResponseError = (result) => { } }; -const Datatrans: IPaymentAdapter = { +const Datatrans: IPaymentAdapter = { ...PaymentAdapter, key: 'shop.unchained.datatrans', @@ -57,11 +58,11 @@ const Datatrans: IPaymentAdapter = { return type === 'GENERIC'; }, - actions: (params) => { - const { modules } = params.context; + actions: (config, context) => { + const { modules } = context; const getMerchantId = (): string | undefined => { - return params.config.find((item) => item.key === 'merchantId')?.value || DATATRANS_MERCHANT_ID; + return config.find((item) => item.key === 'merchantId')?.value || DATATRANS_MERCHANT_ID; }; const api = () => { @@ -70,7 +71,7 @@ const Datatrans: IPaymentAdapter = { }; const shouldSettleInUnchained = () => { - return params.config.reduce((current, item) => { + return config.reduce((current, item) => { if (item.key === 'settleInUnchained') return Boolean(item.value); return current; }, true); @@ -83,18 +84,18 @@ const Datatrans: IPaymentAdapter = { commission: number; }[] > => { - const { order, orderPayment } = params.paymentContext; + const { order, orderPayment } = context; const pricingForOrderPayment = modules.orders.payments.pricingSheet( orderPayment, order.currency, - params.context, + context, ); const pricing = modules.orders.pricingSheet(order); const { amount: total } = pricing.total({ useNetPrice: false }); return Promise.all( - params.config + config .filter((item) => item.key === 'marketplaceSplit') .map((item) => { const [subMerchantId, staticDiscountId, sharePercentage] = item.value @@ -119,11 +120,11 @@ const Datatrans: IPaymentAdapter = { }; const authorize = async ({ paymentCredentials, ...arbitraryFields }): Promise => { - const { order, orderPayment } = params.paymentContext; + const { order, orderPayment } = context; const refno = Buffer.from(orderPayment._id, 'hex').toString('base64'); - const userId = order?.userId || params.paymentContext?.userId; + const userId = order?.userId || context?.userId; const refno2 = userId; - const { currency, amount } = roundedAmountFromOrder(order, params.context); + const { currency, amount } = roundedAmountFromOrder(order, context); const splits = await getMarketplaceSplits(); const result = await api().authorize({ ...arbitraryFields, @@ -152,8 +153,8 @@ const Datatrans: IPaymentAdapter = { refno2, ...arbitraryFields }): Promise => { - const { order } = params.paymentContext; - const { currency, amount } = roundedAmountFromOrder(order, params.context); + const { order } = context; + const { currency, amount } = roundedAmountFromOrder(order, context); const result = await api().authorizeAuthenticated({ ...arbitraryFields, transactionId, @@ -168,8 +169,8 @@ const Datatrans: IPaymentAdapter = { }; const isTransactionAmountValid = (transaction: StatusResponseSuccess): boolean => { - const { order } = params.paymentContext; - const { currency, amount } = roundedAmountFromOrder(order, params.context); + const { order } = context; + const { currency, amount } = roundedAmountFromOrder(order, context); if ( transaction.currency !== currency || (transaction.detail.authorize as any)?.amount !== amount @@ -202,8 +203,8 @@ const Datatrans: IPaymentAdapter = { }; const settle = async ({ transactionId, refno, refno2, extensions }): Promise => { - const { order } = params.paymentContext; - const { currency, amount } = roundedAmountFromOrder(order, params.context); + const { order } = context; + const { currency, amount } = roundedAmountFromOrder(order, context); const splits = await getMarketplaceSplits(); const result = await api().settle({ transactionId, @@ -232,7 +233,7 @@ const Datatrans: IPaymentAdapter = { }; const adapterActions = { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), configurationError() { if (!getMerchantId() || !DATATRANS_SECRET || !DATATRANS_SIGN_KEY) { @@ -252,14 +253,14 @@ const Datatrans: IPaymentAdapter = { async sign(transactionContext: any = {}) { const { useSecureFields = false, ...arbitraryFields } = transactionContext || {}; - const { orderPayment, paymentProviderId, order } = params.paymentContext; + const { orderPayment, paymentProviderId, order } = context; const refno = Buffer.from(orderPayment ? orderPayment._id : paymentProviderId, 'hex').toString( 'base64', ); - const userId = order?.userId || params.paymentContext?.userId; + const userId = order?.userId || context?.userId; const refno2 = userId; const price: { amount?: number; currency?: string } = order - ? roundedAmountFromOrder(order, params.context) + ? roundedAmountFromOrder(order, context) : {}; if (useSecureFields) { @@ -314,7 +315,7 @@ const Datatrans: IPaymentAdapter = { async confirm() { if (!shouldSettleInUnchained()) return false; - const { orderPayment, transactionContext } = params.paymentContext; + const { orderPayment, transactionContext } = context; const { transactionId } = orderPayment; const { extensions } = transactionContext || {}; @@ -344,7 +345,7 @@ const Datatrans: IPaymentAdapter = { async cancel() { if (!shouldSettleInUnchained()) return false; - const { orderPayment } = params.paymentContext; + const { orderPayment } = context; const { transactionId } = orderPayment; if (!transactionId) { return false; diff --git a/packages/plugins/src/payment/invoice-prepaid.ts b/packages/plugins/src/payment/invoice-prepaid.ts index 395f91b0fc..7262fd205f 100644 --- a/packages/plugins/src/payment/invoice-prepaid.ts +++ b/packages/plugins/src/payment/invoice-prepaid.ts @@ -1,7 +1,8 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IPaymentAdapter } from '@unchainedshop/core-payment'; import { PaymentDirector, PaymentAdapter, PaymentProviderType } from '@unchainedshop/core-payment'; -const InvoicePrepaid: IPaymentAdapter = { +const InvoicePrepaid: IPaymentAdapter = { ...PaymentAdapter, key: 'shop.unchained.invoice-prepaid', @@ -14,9 +15,9 @@ const InvoicePrepaid: IPaymentAdapter = { return type === PaymentProviderType.INVOICE; }, - actions: (params) => { + actions: (config, context) => { return { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), configurationError: () => { return null; diff --git a/packages/plugins/src/payment/invoice.ts b/packages/plugins/src/payment/invoice.ts index 3f5d8aab5d..b68d7be577 100644 --- a/packages/plugins/src/payment/invoice.ts +++ b/packages/plugins/src/payment/invoice.ts @@ -1,7 +1,8 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IPaymentAdapter } from '@unchainedshop/core-payment'; import { PaymentDirector, PaymentAdapter, PaymentProviderType } from '@unchainedshop/core-payment'; -const Invoice: IPaymentAdapter = { +const Invoice: IPaymentAdapter = { ...PaymentAdapter, key: 'shop.unchained.invoice', @@ -14,9 +15,9 @@ const Invoice: IPaymentAdapter = { return type === PaymentProviderType.INVOICE; }, - actions: (params) => { + actions: (config, context) => { return { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), configurationError: () => { return null; diff --git a/packages/plugins/src/payment/paypal-checkout.ts b/packages/plugins/src/payment/paypal-checkout.ts index 46958e44b1..56a6d3e658 100644 --- a/packages/plugins/src/payment/paypal-checkout.ts +++ b/packages/plugins/src/payment/paypal-checkout.ts @@ -1,3 +1,4 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IPaymentAdapter } from '@unchainedshop/core-payment'; import { PaymentDirector, PaymentAdapter, PaymentError } from '@unchainedshop/core-payment'; import { createLogger } from '@unchainedshop/logger'; @@ -28,7 +29,7 @@ const environment = () => { : new checkoutNodeJssdk.core.LiveEnvironment(clientId, clientSecret); }; -const PaypalCheckout: IPaymentAdapter = { +const PaypalCheckout: IPaymentAdapter = { ...PaymentAdapter, key: 'com.paypal.checkout', @@ -41,9 +42,9 @@ const PaypalCheckout: IPaymentAdapter = { return type === 'GENERIC'; }, - actions: (params) => { + actions: (config, context) => { const adapter = { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), configurationError: () => { const publicCredentialsValid = PAYPAL_CLIENT_ID && PAYPAL_SECRET; @@ -68,8 +69,7 @@ const PaypalCheckout: IPaymentAdapter = { }, charge: async ({ orderID }) => { - const { modules } = params.context; - const { order } = params.paymentContext; + const { modules, order } = context; if (!orderID) { logger.warn('Paypal Native Plugin: PRICE MATCH'); diff --git a/packages/plugins/src/payment/payrexx/index.ts b/packages/plugins/src/payment/payrexx/index.ts index 5dc2c6632a..b4296ac309 100644 --- a/packages/plugins/src/payment/payrexx/index.ts +++ b/packages/plugins/src/payment/payrexx/index.ts @@ -3,12 +3,13 @@ import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/co import { createLogger } from '@unchainedshop/logger'; import { mapOrderDataToGatewayObject, mapUserToGatewayObject } from './payrexx.js'; import createPayrexxAPI, { GatewayObjectStatus } from './api/index.js'; +import { UnchainedCore } from '@unchainedshop/core'; export * from './middleware.js'; const logger = createLogger('unchained:core-payment:payrexx'); -const Payrexx: IPaymentAdapter = { +const Payrexx: IPaymentAdapter = { ...PaymentAdapter, key: 'shop.unchained.payment.payrexx', @@ -19,17 +20,17 @@ const Payrexx: IPaymentAdapter = { return type === 'GENERIC'; }, - actions: (params) => { - const { modules } = params.context; + actions: (config, context) => { + const { modules } = context; const getInstance = () => { - return params.config.find((c) => c.key === 'instance')?.value; + return config.find((c) => c.key === 'instance')?.value; }; const api = createPayrexxAPI(getInstance(), process.env.PAYREXX_SECRET); const adapterActions = { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), configurationError() { if (!process.env.PAYREXX_SECRET) { @@ -51,7 +52,7 @@ const Payrexx: IPaymentAdapter = { }, sign: async (transactionContext = {}) => { - const { orderPayment, userId, order } = params.paymentContext; + const { orderPayment, userId, order } = context; if (orderPayment) { // Order Checkout signing (One-time payment) const pricing = await modules.orders.pricingSheet(order); @@ -100,7 +101,7 @@ const Payrexx: IPaymentAdapter = { }, async confirm() { - const { orderPayment } = params.paymentContext; + const { orderPayment } = context; const { transactionId } = orderPayment; if (!transactionId) { @@ -133,7 +134,7 @@ const Payrexx: IPaymentAdapter = { }, async cancel() { - const { orderPayment } = params.paymentContext; + const { orderPayment } = context; const { transactionId } = orderPayment; if (!transactionId) { return false; @@ -164,7 +165,7 @@ const Payrexx: IPaymentAdapter = { throw new Error('You have to provide gatewayId or paymentCredentials'); } - const { order } = params.paymentContext; + const { order } = context; const orderPayment = await modules.orders.payments.findOrderPayment({ orderPaymentId: order.paymentId, }); diff --git a/packages/plugins/src/payment/postfinance-checkout/index.ts b/packages/plugins/src/payment/postfinance-checkout/index.ts index 2a843ee7f5..42cb9a958f 100644 --- a/packages/plugins/src/payment/postfinance-checkout/index.ts +++ b/packages/plugins/src/payment/postfinance-checkout/index.ts @@ -20,6 +20,7 @@ import { } from './api.js'; import { orderIsPaid } from './utils.js'; import { CompletionModes, IntegrationModes, SignResponse } from './types.js'; +import { UnchainedCore } from '@unchainedshop/core'; export * from './middleware.js'; @@ -41,7 +42,7 @@ const newError = ({ code, message }: { code: string; message: string }) => { return error; }; -const PostfinanceCheckout: IPaymentAdapter = { +const PostfinanceCheckout: IPaymentAdapter = { ...PaymentAdapter, key: 'shop.unchained.payment.postfinance-checkout', @@ -52,17 +53,17 @@ const PostfinanceCheckout: IPaymentAdapter = { return type === 'GENERIC'; }, - actions: (params) => { - const { modules } = params.context; + actions: (config, context) => { + const { modules } = context; const adapter: IPaymentActions & { getCompletionMode: () => CompletionModes; } = { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), getCompletionMode() { return ( - (params.config.find((item) => item.key === 'completionMode')?.value as CompletionModes) || + (config.find((item) => item.key === 'completionMode')?.value as CompletionModes) || CompletionModes.Deferred ); }, @@ -99,7 +100,7 @@ const PostfinanceCheckout: IPaymentAdapter = { }, sign: async (transactionContext: any = {}) => { - const { orderPayment, order } = params.paymentContext; + const { orderPayment, order } = context; const { integrationMode = IntegrationModes.PaymentPage }: { integrationMode: IntegrationModes } = transactionContext; @@ -107,7 +108,7 @@ const PostfinanceCheckout: IPaymentAdapter = { const pricing = modules.orders.pricingSheet(order); const totalAmount = pricing?.total({ useNetPrice: false }).amount; const transaction = new PostFinanceCheckout.model.TransactionCreate(); - const userId = order?.userId || params.paymentContext?.userId; + const userId = order?.userId || context?.userId; transaction.currency = order.currency; transaction.metaData = { orderPaymentId: orderPayment._id, @@ -177,7 +178,7 @@ const PostfinanceCheckout: IPaymentAdapter = { }); } - const isPaid = await orderIsPaid(params.paymentContext.order, transaction, modules.orders); + const isPaid = await orderIsPaid(context.order, transaction, modules.orders); if (!isPaid) { logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`); throw newError({ @@ -186,7 +187,7 @@ const PostfinanceCheckout: IPaymentAdapter = { }); } - if (transaction.metaData.orderPaymentId !== params.paymentContext.orderPayment._id) { + if (transaction.metaData.orderPaymentId !== context.orderPayment._id) { logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`); throw newError({ code: `TRANSACTION_ALREADY_USED`, @@ -207,7 +208,7 @@ const PostfinanceCheckout: IPaymentAdapter = { }, cancel: async () => { - const { orderPayment, order } = params.paymentContext; + const { orderPayment, order } = context; const { transactionId } = orderPayment; if (!transactionId) { return false; @@ -224,7 +225,7 @@ const PostfinanceCheckout: IPaymentAdapter = { }, confirm: async () => { - const { orderPayment } = params.paymentContext; + const { orderPayment } = context; const { transactionId } = orderPayment; if (!transactionId) { return false; diff --git a/packages/plugins/src/payment/saferpay/adapter.ts b/packages/plugins/src/payment/saferpay/adapter.ts index 95d5f6aca9..8160b23e07 100644 --- a/packages/plugins/src/payment/saferpay/adapter.ts +++ b/packages/plugins/src/payment/saferpay/adapter.ts @@ -31,7 +31,11 @@ const addTransactionId = (urlString, saferpayTransactionId) => { return urlWithTransactionId.href; }; -export const WordlineSaferpay: IPaymentAdapter = { +export const WordlineSaferpay: IPaymentAdapter< + UnchainedCore & { + modules: { saferpayTransactions: SaferpayTransactionsModule }; + } +> = { ...PaymentAdapter, key: 'shop.unchained.payment.saferpay', @@ -42,10 +46,8 @@ export const WordlineSaferpay: IPaymentAdapter = { return type === 'GENERIC'; }, - actions: (params) => { - const { modules } = params.context as UnchainedCore & { - modules: { saferpayTransactions: SaferpayTransactionsModule }; - }; + actions: (config, context) => { + const { modules } = context; const createSaferPayClient = () => { if (!SAFERPAY_CUSTOMER_ID || !SAFERPAY_USER || !SAFERPAY_PW) @@ -60,10 +62,10 @@ export const WordlineSaferpay: IPaymentAdapter = { }; const adapter = { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), getTerminalId() { - return params.config.find((item) => item.key === 'terminalId')?.value; + return config.find((item) => item.key === 'terminalId')?.value; }, // eslint-disable-next-line @@ -91,7 +93,7 @@ export const WordlineSaferpay: IPaymentAdapter = { }, sign: async (transactionContext: any = {}) => { - const { orderPayment, order } = params.paymentContext; + const { orderPayment, order } = context; if (!orderPayment || !order) { throw new Error('orderPayment or order not found'); @@ -148,7 +150,7 @@ export const WordlineSaferpay: IPaymentAdapter = { }, charge: async ({ transactionId }: { transactionId: string }) => { - const { orderPayment, order } = params.paymentContext; + const { orderPayment, order } = context; if (!orderPayment || !order) { throw new Error('orderPayment or order not found'); @@ -187,7 +189,7 @@ export const WordlineSaferpay: IPaymentAdapter = { }, async confirm() { - const { orderPayment } = params.paymentContext; + const { orderPayment } = context; if (!orderPayment) { throw new Error('orderPayment not found'); @@ -217,7 +219,7 @@ export const WordlineSaferpay: IPaymentAdapter = { }, cancel: async () => { - const { orderPayment } = params.paymentContext; + const { orderPayment } = context; if (!orderPayment) { throw new Error('orderPayment not found'); diff --git a/packages/plugins/src/payment/stripe/index.ts b/packages/plugins/src/payment/stripe/index.ts index 3414a66f2b..46b8ef2f23 100644 --- a/packages/plugins/src/payment/stripe/index.ts +++ b/packages/plugins/src/payment/stripe/index.ts @@ -2,12 +2,13 @@ import { IPaymentAdapter } from '@unchainedshop/core-payment'; import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment'; import { createLogger } from '@unchainedshop/logger'; import stripeClient, { createOrderPaymentIntent, createRegistrationIntent } from './stripe.js'; +import { UnchainedCore } from '@unchainedshop/core'; export * from './middleware.js'; const logger = createLogger('unchained:core-payment:stripe'); -const Stripe: IPaymentAdapter = { +const Stripe: IPaymentAdapter = { ...PaymentAdapter, key: 'shop.unchained.payment.stripe', @@ -18,13 +19,13 @@ const Stripe: IPaymentAdapter = { return type === 'GENERIC'; }, - actions: (params) => { - const { modules } = params.context; + actions: (config, context) => { + const { modules } = context; - const descriptorPrefix = params.config.find(({ key }) => key === 'descriptorPrefix')?.value; + const descriptorPrefix = config.find(({ key }) => key === 'descriptorPrefix')?.value; const getUserData = async (forcedUserId) => { - const userId = forcedUserId || params.paymentContext?.userId; + const userId = forcedUserId || context?.userId; const user = await modules.users.findUserById(userId); const email = modules.users.primaryEmail(user)?.address; const name = user.profile.displayName || user.username || email; @@ -35,7 +36,7 @@ const Stripe: IPaymentAdapter = { }; }; const adapterActions = { - ...PaymentAdapter.actions(params), + ...PaymentAdapter.actions(config, context), configurationError() { const stripe = stripeClient(); @@ -82,7 +83,7 @@ const Stripe: IPaymentAdapter = { }, sign: async (transactionContext = {}) => { - const { orderPayment, order, paymentProviderId } = params.paymentContext; + const { orderPayment, order, paymentProviderId } = context; if (orderPayment) { const pricing = await modules.orders.pricingSheet(order); @@ -108,7 +109,7 @@ const Stripe: IPaymentAdapter = { throw new Error('You have to provide paymentIntentId or paymentCredentials'); } - const { order } = params.paymentContext; + const { order } = context; const orderPayment = await modules.orders.payments.findOrderPayment({ orderPaymentId: order.paymentId, }); diff --git a/packages/plugins/src/pricing/order-delivery.ts b/packages/plugins/src/pricing/order-delivery.ts index b600c434da..5b159698c6 100644 --- a/packages/plugins/src/pricing/order-delivery.ts +++ b/packages/plugins/src/pricing/order-delivery.ts @@ -1,7 +1,8 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IOrderPricingAdapter } from '@unchainedshop/core-orders'; import { OrderPricingDirector, OrderPricingAdapter } from '@unchainedshop/core-orders'; -export const OrderDelivery: IOrderPricingAdapter = { +export const OrderDelivery: IOrderPricingAdapter = { ...OrderPricingAdapter, key: 'shop.unchained.pricing.order-delivery', diff --git a/packages/plugins/src/pricing/order-discount.ts b/packages/plugins/src/pricing/order-discount.ts index 319625dcbe..c13015843d 100644 --- a/packages/plugins/src/pricing/order-discount.ts +++ b/packages/plugins/src/pricing/order-discount.ts @@ -1,3 +1,4 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IOrderPricingAdapter, OrderPricingRowCategory } from '@unchainedshop/core-orders'; import { OrderPricingDirector, @@ -6,7 +7,7 @@ import { } from '@unchainedshop/core-orders'; import { calculation as calcUtils } from '@unchainedshop/utils'; -export const OrderDiscount: IOrderPricingAdapter = { +export const OrderDiscount: IOrderPricingAdapter = { ...OrderPricingAdapter, key: 'shop.unchained.pricing.order-discount', diff --git a/packages/plugins/src/pricing/order-items-discount.ts b/packages/plugins/src/pricing/order-items-discount.ts index b8c5f49e2a..eb60ffdb70 100644 --- a/packages/plugins/src/pricing/order-items-discount.ts +++ b/packages/plugins/src/pricing/order-items-discount.ts @@ -1,3 +1,4 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IOrderPricingAdapter, OrderPricingRowCategory } from '@unchainedshop/core-orders'; import { OrderPricingDirector, @@ -6,7 +7,7 @@ import { } from '@unchainedshop/core-orders'; import { calculation as calcUtils } from '@unchainedshop/utils'; -const OrderItemsDiscount: IOrderPricingAdapter = { +const OrderItemsDiscount: IOrderPricingAdapter = { ...OrderPricingAdapter, key: 'shop.unchained.pricing.order-items-discount', diff --git a/packages/plugins/src/pricing/order-items.ts b/packages/plugins/src/pricing/order-items.ts index c96b8c19c8..089c187cd8 100644 --- a/packages/plugins/src/pricing/order-items.ts +++ b/packages/plugins/src/pricing/order-items.ts @@ -1,7 +1,8 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IOrderPricingAdapter } from '@unchainedshop/core-orders'; import { OrderPricingDirector, OrderPricingAdapter } from '@unchainedshop/core-orders'; -const OrderItems: IOrderPricingAdapter = { +const OrderItems: IOrderPricingAdapter = { ...OrderPricingAdapter, key: 'shop.unchained.pricing.order-items', diff --git a/packages/plugins/src/pricing/order-payment.ts b/packages/plugins/src/pricing/order-payment.ts index 3dfa986f3f..2f7a5030d2 100644 --- a/packages/plugins/src/pricing/order-payment.ts +++ b/packages/plugins/src/pricing/order-payment.ts @@ -1,7 +1,8 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IOrderPricingAdapter } from '@unchainedshop/core-orders'; import { OrderPricingDirector, OrderPricingAdapter } from '@unchainedshop/core-orders'; -const OrderPayment: IOrderPricingAdapter = { +const OrderPayment: IOrderPricingAdapter = { ...OrderPricingAdapter, key: 'shop.unchained.pricing.order-payment', diff --git a/packages/plugins/src/pricing/order-round.ts b/packages/plugins/src/pricing/order-round.ts index 69870c819d..dc47ed7984 100644 --- a/packages/plugins/src/pricing/order-round.ts +++ b/packages/plugins/src/pricing/order-round.ts @@ -1,3 +1,4 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { OrderPricingAdapter, OrderPricingDirector } from '@unchainedshop/core-orders'; import { IOrderPricingAdapter, OrderPricingRowCategory } from '@unchainedshop/core-orders'; @@ -6,7 +7,7 @@ interface PriceRoundSettings { roundTo: (value: number, precision: number, currency: string) => number; } -export const OrderPriceRound: IOrderPricingAdapter & { +export const OrderPriceRound: IOrderPricingAdapter & { configure: (params: PriceRoundSettings) => void; settings: PriceRoundSettings; } = { diff --git a/packages/plugins/src/pricing/product-catalog-price.ts b/packages/plugins/src/pricing/product-catalog-price.ts index 7b3b6cf4b0..46b23f273a 100644 --- a/packages/plugins/src/pricing/product-catalog-price.ts +++ b/packages/plugins/src/pricing/product-catalog-price.ts @@ -1,3 +1,4 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IProductPricingAdapter } from '@unchainedshop/core-products'; import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products'; import { resolveBestCurrency } from '@unchainedshop/utils'; @@ -23,7 +24,7 @@ export const resolveCurrency = memoizee( }, ); -export const ProductPrice: IProductPricingAdapter = { +export const ProductPrice: IProductPricingAdapter = { ...ProductPricingAdapter, key: 'shop.unchained.pricing.product-price', diff --git a/packages/plugins/src/pricing/product-discount.ts b/packages/plugins/src/pricing/product-discount.ts index edaba3fed6..ed5c67e51e 100644 --- a/packages/plugins/src/pricing/product-discount.ts +++ b/packages/plugins/src/pricing/product-discount.ts @@ -1,13 +1,15 @@ import { Discount } from '@unchainedshop/utils'; -import { IProductPricingAdapter, ProductPricingRowCategory } from '@unchainedshop/core-products'; import { ProductPricingDirector, ProductPricingAdapter, ProductDiscountConfiguration, + IProductPricingAdapter, + ProductPricingRowCategory, } from '@unchainedshop/core-products'; import { calculation as calcUtils } from '@unchainedshop/utils'; +import { UnchainedCore } from '@unchainedshop/core'; -const ProductDiscount: IProductPricingAdapter = { +const ProductDiscount: IProductPricingAdapter = { ...ProductPricingAdapter, key: 'shop.unchained.pricing.product-discount', diff --git a/packages/plugins/src/pricing/product-price-rateconversion.ts b/packages/plugins/src/pricing/product-price-rateconversion.ts index eeb17a0084..bfd07d3f82 100644 --- a/packages/plugins/src/pricing/product-price-rateconversion.ts +++ b/packages/plugins/src/pricing/product-price-rateconversion.ts @@ -1,7 +1,8 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IProductPricingAdapter } from '@unchainedshop/core-products'; import { ProductPricingDirector, ProductPricingAdapter } from '@unchainedshop/core-products'; -export const ProductPriceRateConversion: IProductPricingAdapter = { +export const ProductPriceRateConversion: IProductPricingAdapter = { ...ProductPricingAdapter, key: 'shop.unchained.pricing.rate-conversion', diff --git a/packages/plugins/src/pricing/product-round.ts b/packages/plugins/src/pricing/product-round.ts index 41d2be78a8..fcaeda8c83 100644 --- a/packages/plugins/src/pricing/product-round.ts +++ b/packages/plugins/src/pricing/product-round.ts @@ -1,3 +1,4 @@ +import { UnchainedCore } from '@unchainedshop/core'; import { IProductPricingAdapter } from '@unchainedshop/core-products'; import { ProductPricingAdapter, ProductPricingDirector } from '@unchainedshop/core-products'; @@ -6,7 +7,7 @@ interface PriceRoundSettings { roundTo: (value: number, precision: number, currency: string) => number; } -export const ProductRound: IProductPricingAdapter & { +export const ProductRound: IProductPricingAdapter & { configure: (params: PriceRoundSettings) => void; settings: PriceRoundSettings; } = { diff --git a/packages/plugins/src/pricing/product-swiss-tax.ts b/packages/plugins/src/pricing/product-swiss-tax.ts index da4bb7f099..2bd3a048c9 100644 --- a/packages/plugins/src/pricing/product-swiss-tax.ts +++ b/packages/plugins/src/pricing/product-swiss-tax.ts @@ -5,6 +5,7 @@ import { } from '@unchainedshop/core-products'; import { IProductPricingAdapter, ProductPricingRowCategory } from '@unchainedshop/core-products'; import { SwissTaxCategories } from './tax/ch.js'; +import { UnchainedCore } from '@unchainedshop/core'; export const getTaxRate = (context: ProductPricingAdapterContext) => { const { product, order } = context; @@ -24,7 +25,7 @@ export const isDeliveryAddressInSwitzerland = async ({ order, country, modules, -}: ProductPricingAdapterContext) => { +}: ProductPricingAdapterContext & UnchainedCore) => { let countryCode = country?.toUpperCase().trim(); if (order) { @@ -41,7 +42,7 @@ export const isDeliveryAddressInSwitzerland = async ({ return countryCode === 'CH' || countryCode === 'LI'; }; -export const ProductSwissTax: IProductPricingAdapter = { +export const ProductSwissTax: IProductPricingAdapter = { ...ProductPricingAdapter, key: 'shop.unchained.pricing.product-swiss-tax',