diff --git a/package-lock.json b/package-lock.json index 90ce849cd0..9cc48cb2b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,37 @@ "version": "3.0.0-alpha3", "license": "EUPL-1.2", "workspaces": [ - "packages/*", + "packages/logger", + "packages/mongodb", + "packages/utils", + "packages/events", + "packages/file-upload", + "packages/roles", + "packages/shared", + "packages/core-accountsjs", + "packages/core-assortments", + "packages/core-bookmarks", + "packages/core-countries", + "packages/core-currencies", + "packages/core-delivery", + "packages/core-enrollments", + "packages/core-events", + "packages/core-files", + "packages/core-filters", + "packages/core-languages", + "packages/core-messaging", + "packages/core-orders", + "packages/core-payment", + "packages/core-products", + "packages/core-quotations", + "packages/core-users", + "packages/core-warehousing", + "packages/core-worker", + "packages/core", + "packages/api", + "packages/plugins", + "packages/ticketing", + "packages/platform", "examples/kitchensink", "examples/minimal" ], diff --git a/package.json b/package.json index 67ad72411a..ad3353b53c 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,41 @@ "npm": ">=10.0.0" }, "workspaces": [ - "packages/*", + "packages/logger", + "packages/utils", + "packages/mongodb", + "packages/events", + "packages/file-upload", + "packages/roles", + "packages/shared", + + "packages/core-countries", + "packages/core-currencies", + "packages/core-languages", + "packages/core-events", + "packages/core-files", + "packages/core-users", + + "packages/core-bookmarks", + "packages/core-delivery", + "packages/core-messaging", + "packages/core-payment", + "packages/core-quotations", + + "packages/core-products", + "packages/core-assortments", + "packages/core-filters", + "packages/core-orders", + "packages/core-warehousing", + "packages/core-worker", + "packages/core-enrollments", + "packages/core", + + "packages/api", + "packages/plugins", + "packages/ticketing", + "packages/platform", + "examples/kitchensink", "examples/minimal" ], diff --git a/packages/core-assortments/src/migrations/addMigrations.ts b/packages/core-assortments/src/migrations/addMigrations.ts index 41d5ac4569..fde421e8f0 100644 --- a/packages/core-assortments/src/migrations/addMigrations.ts +++ b/packages/core-assortments/src/migrations/addMigrations.ts @@ -1,5 +1,4 @@ -import { Migration, MigrationRepository } from '@unchainedshop/core'; -import { mongodb } from '@unchainedshop/mongodb'; +import { mongodb, MigrationRepository } from '@unchainedshop/mongodb'; import { AssortmentMediaCollection } from '../db/AssortmentMediaCollection.js'; import { AssortmentsCollection } from '../db/AssortmentsCollection.js'; @@ -22,7 +21,7 @@ const convertTagsToLowerCase = async (collection: mongodb.Collection<any>) => { if (count > 0) bulk.execute(); }; -export default function addMigrations(repository: MigrationRepository<Migration>) { +export default function addMigrations(repository: MigrationRepository) { repository?.register({ id: 20220216000000, name: 'Move _cachedProductIds cache to own collection in order to save a lot of bandwidth', @@ -44,8 +43,8 @@ export default function addMigrations(repository: MigrationRepository<Migration> }, { // eslint-disable-next-line - // @ts-ignore - $set: { productIds: assortment._cachedProductIds }, // eslint-disable-line + // @ts-ignore + $set: { productIds: assortment._cachedProductIds }, // eslint-disable-line }, { upsert: true, diff --git a/packages/core-assortments/src/module/configureAssortmentMediaModule.ts b/packages/core-assortments/src/module/configureAssortmentMediaModule.ts index 43ce43aa63..3d060cec7f 100644 --- a/packages/core-assortments/src/module/configureAssortmentMediaModule.ts +++ b/packages/core-assortments/src/module/configureAssortmentMediaModule.ts @@ -1,10 +1,10 @@ -import { ModuleInput } from '@unchainedshop/core'; import { emit, registerEvents } from '@unchainedshop/events'; import { findLocalizedText, generateDbFilterById, generateDbObjectId, mongodb, + ModuleInput, } from '@unchainedshop/mongodb'; import { FileDirector } from '@unchainedshop/file-upload'; import { AssortmentMediaCollection } from '../db/AssortmentMediaCollection.js'; @@ -17,13 +17,6 @@ const ASSORTMENT_MEDIA_EVENTS = [ 'ASSORTMENT_UPDATE_MEDIA_TEXT', ]; -FileDirector.registerFileUploadCallback('assortment-media', async (file, { modules }) => { - await modules.assortments.media.create({ - assortmentId: file.meta.assortmentId as string, - mediaId: file._id, - }); -}); - export type AssortmentMediaModule = { // Queries findAssortmentMedia: (params: { assortmentMediaId: string }) => Promise<AssortmentMediaType>; @@ -280,3 +273,16 @@ export const configureAssortmentMediaModule = async ({ }, }; }; + +FileDirector.registerFileUploadCallback<{ + modules: { + assortments: { + media: AssortmentMediaModule; + }; + }; +}>('assortment-media', async (file, { modules }) => { + await modules.assortments.media.create({ + assortmentId: file.meta.assortmentId as string, + mediaId: file._id, + }); +}); diff --git a/packages/core-assortments/src/module/configureAssortmentsModule.ts b/packages/core-assortments/src/module/configureAssortmentsModule.ts index 71512f4842..da35c92c1e 100644 --- a/packages/core-assortments/src/module/configureAssortmentsModule.ts +++ b/packages/core-assortments/src/module/configureAssortmentsModule.ts @@ -1,5 +1,4 @@ import { Tree, SortOption, SortDirection } from '@unchainedshop/utils'; -import { ModuleInput } from '@unchainedshop/core'; import { emit, registerEvents } from '@unchainedshop/events'; import { log, LogLevel } from '@unchainedshop/logger'; import { @@ -8,6 +7,7 @@ import { buildSortOptions, mongodb, generateDbObjectId, + ModuleInput, } from '@unchainedshop/mongodb'; import { resolveAssortmentProductFromDatabase } from '../utils/breadcrumbs/resolveAssortmentProductFromDatabase.js'; import { resolveAssortmentLinkFromDatabase } from '../utils/breadcrumbs/resolveAssortmentLinkFromDatabase.js'; diff --git a/packages/core-bookmarks/src/module/configureBookmarksModule.ts b/packages/core-bookmarks/src/module/configureBookmarksModule.ts index d5698c8beb..0285693b73 100644 --- a/packages/core-bookmarks/src/module/configureBookmarksModule.ts +++ b/packages/core-bookmarks/src/module/configureBookmarksModule.ts @@ -1,8 +1,7 @@ import { emit, registerEvents } from '@unchainedshop/events'; -import { ModuleInput } from '@unchainedshop/core'; import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb'; import { BookmarksCollection } from '../db/BookmarksCollection.js'; -import type { TimestampFields } from '@unchainedshop/mongodb'; +import type { TimestampFields, ModuleInput } from '@unchainedshop/mongodb'; const BOOKMARK_EVENTS: string[] = ['BOOKMARK_CREATE', 'BOOKMARK_UPDATE', 'BOOKMARK_REMOVE']; diff --git a/packages/core-countries/src/migrations/addMigrations.ts b/packages/core-countries/src/migrations/addMigrations.ts index 03f6d30122..f92e7fa3c5 100644 --- a/packages/core-countries/src/migrations/addMigrations.ts +++ b/packages/core-countries/src/migrations/addMigrations.ts @@ -1,8 +1,8 @@ -import { Migration, MigrationRepository } from '@unchainedshop/core'; +import { MigrationRepository } from '@unchainedshop/mongodb'; import { CountriesCollection } from '../db/CountriesCollection.js'; import { Country } from '../countries-index.js'; -export default function addMigrations(repository: MigrationRepository<Migration>) { +export default function addMigrations(repository: MigrationRepository) { repository?.register({ id: 20240712123500, name: 'Convert all tags to lower case to make it easy for search', diff --git a/packages/core-countries/src/module/configureCountriesModule.ts b/packages/core-countries/src/module/configureCountriesModule.ts index 9101d4137b..f734d31df5 100644 --- a/packages/core-countries/src/module/configureCountriesModule.ts +++ b/packages/core-countries/src/module/configureCountriesModule.ts @@ -1,5 +1,4 @@ -import type { mongodb, TimestampFields } from '@unchainedshop/mongodb'; -import { ModuleInput } from '@unchainedshop/core'; +import type { mongodb, TimestampFields, ModuleInput } from '@unchainedshop/mongodb'; import { emit, registerEvents } from '@unchainedshop/events'; import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb'; import { SortDirection, SortOption } from '@unchainedshop/utils'; diff --git a/packages/core-currencies/src/module/configureCurrenciesModule.ts b/packages/core-currencies/src/module/configureCurrenciesModule.ts index ef05497e0c..cfcb1a0d52 100644 --- a/packages/core-currencies/src/module/configureCurrenciesModule.ts +++ b/packages/core-currencies/src/module/configureCurrenciesModule.ts @@ -1,7 +1,11 @@ -import { ModuleInput } from '@unchainedshop/core'; import { Currency, CurrencyQuery } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; -import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb'; +import { + generateDbFilterById, + buildSortOptions, + generateDbObjectId, + ModuleInput, +} from '@unchainedshop/mongodb'; import { SortDirection, SortOption } from '@unchainedshop/utils'; import { CurrenciesCollection } from '../db/CurrenciesCollection.js'; diff --git a/packages/core-delivery/src/module/configureDeliveryModule.ts b/packages/core-delivery/src/module/configureDeliveryModule.ts index 66a4892346..f1428353c9 100644 --- a/packages/core-delivery/src/module/configureDeliveryModule.ts +++ b/packages/core-delivery/src/module/configureDeliveryModule.ts @@ -1,7 +1,7 @@ -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { DeliveryContext, DeliveryInterface, DeliveryProvider, DeliveryProviderType } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; -import { mongodb, generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb'; +import { mongodb, generateDbFilterById, generateDbObjectId, ModuleInput } from '@unchainedshop/mongodb'; import { DeliveryPricingSheet } from '../director/DeliveryPricingSheet.js'; import { DeliveryProvidersCollection } from '../db/DeliveryProvidersCollection.js'; import { deliverySettings, DeliverySettingsOptions } from '../delivery-settings.js'; diff --git a/packages/core-enrollments/src/module/configureEnrollmentsModule.ts b/packages/core-enrollments/src/module/configureEnrollmentsModule.ts index 54eff2cd88..e65b3931c9 100644 --- a/packages/core-enrollments/src/module/configureEnrollmentsModule.ts +++ b/packages/core-enrollments/src/module/configureEnrollmentsModule.ts @@ -1,5 +1,5 @@ import { SortDirection, SortOption } from '@unchainedshop/utils'; -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { Enrollment, EnrollmentData, @@ -15,6 +15,7 @@ import { Address, Contact, generateDbObjectId, + ModuleInput, } from '@unchainedshop/mongodb'; import { EnrollmentsCollection } from '../db/EnrollmentsCollection.js'; import { EnrollmentStatus } from '../db/EnrollmentStatus.js'; diff --git a/packages/core-events/src/module/configureEventsModule.ts b/packages/core-events/src/module/configureEventsModule.ts index 100c5b3a5d..d8c85dbfd9 100644 --- a/packages/core-events/src/module/configureEventsModule.ts +++ b/packages/core-events/src/module/configureEventsModule.ts @@ -3,7 +3,7 @@ import type { mongodb } from '@unchainedshop/mongodb'; import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb'; import { getRegisteredEvents } from '@unchainedshop/events'; import { SortDirection, SortOption } from '@unchainedshop/utils'; -import { ModuleCreateMutation, ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import { EventsCollection, Event } from '../db/EventsCollection.js'; import { configureEventHistoryAdapter } from './configureEventHistoryAdapter.js'; @@ -27,7 +27,7 @@ export const buildFindSelector = ({ types, queryString, created }: EventQuery) = return selector; }; -export interface EventsModule extends ModuleCreateMutation<Event> { +export interface EventsModule { findEvent: ( params: mongodb.Filter<Event> & { eventId: string }, options?: mongodb.FindOptions, @@ -43,6 +43,7 @@ export interface EventsModule extends ModuleCreateMutation<Event> { ) => Promise<Array<Event>>; type: (event: Event) => string; + create: (doc: Event) => Promise<string | null>; count: (query: EventQuery) => Promise<number>; getReport: (params?: { from?: Date; to?: Date; types?: string[] }) => Promise<EventReport[]>; diff --git a/packages/core-files/src/module/configureFilesModule.ts b/packages/core-files/src/module/configureFilesModule.ts index 3604f14a20..e28d2d6934 100644 --- a/packages/core-files/src/module/configureFilesModule.ts +++ b/packages/core-files/src/module/configureFilesModule.ts @@ -1,4 +1,4 @@ -import { ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import { File } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb'; @@ -61,7 +61,7 @@ export const configureFilesModule = async ({ return fileId; }, - update: async (fileId: string, doc: File) => { + update: async (fileId: string, doc: Partial<File>) => { await Files.updateOne( { _id: fileId }, { diff --git a/packages/core-files/src/service/createDownloadStreamService.ts b/packages/core-files/src/service/createDownloadStreamService.ts index 8604a9a123..51971a7803 100644 --- a/packages/core-files/src/service/createDownloadStreamService.ts +++ b/packages/core-files/src/service/createDownloadStreamService.ts @@ -1,12 +1,12 @@ import { getFileAdapter } from '../utils/getFileAdapter.js'; -import { UnchainedCore } from '@unchainedshop/core'; import { Readable } from 'stream'; +import { FilesModule } from '../files-index.js'; export type CreateDownloadStreamService = ( params: { fileId: string; }, - unchainedAPI: UnchainedCore, + unchainedAPI: { modules: { files: FilesModule } }, ) => Promise<Readable>; export const createDownloadStreamService: CreateDownloadStreamService = async ( diff --git a/packages/core-files/src/service/createSignedURLService.ts b/packages/core-files/src/service/createSignedURLService.ts index 182517b6a1..339ec268a5 100644 --- a/packages/core-files/src/service/createSignedURLService.ts +++ b/packages/core-files/src/service/createSignedURLService.ts @@ -1,11 +1,11 @@ -import { UnchainedCore } from '@unchainedshop/core'; +import { getFileFromFileData } from '@unchainedshop/file-upload'; import { getFileAdapter } from '../utils/getFileAdapter.js'; -import { getFileFromFileData } from '../utils/getFileFromFileData.js'; import { SignedFileUpload } from '../types.js'; +import { FilesModule } from '../files-index.js'; export type CreateSignedURLService = ( params: { directoryName: string; fileName: string; meta?: any }, - unchainedAPI: UnchainedCore, + unchainedAPI: { modules: { files: FilesModule } }, ) => Promise<SignedFileUpload>; export const createSignedURLService: CreateSignedURLService = async ( diff --git a/packages/core-files/src/service/linkFileService.ts b/packages/core-files/src/service/linkFileService.ts index 73235c83c0..3238fd6fff 100644 --- a/packages/core-files/src/service/linkFileService.ts +++ b/packages/core-files/src/service/linkFileService.ts @@ -1,10 +1,10 @@ import { FileDirector } from '@unchainedshop/file-upload'; -import { UnchainedCore } from '@unchainedshop/core'; import { File } from '../types.js'; +import { FilesModule } from '../files-index.js'; export type LinkFileService = ( params: { fileId: string; size: number; type?: string }, - unchainedAPI: UnchainedCore, + unchainedAPI: { modules: { files: FilesModule } }, ) => Promise<File>; export const linkFileService: LinkFileService = async ({ fileId, size, type }, unchainedAPI) => { diff --git a/packages/core-files/src/service/removeFilesService.ts b/packages/core-files/src/service/removeFilesService.ts index e691274abf..200f3c03f8 100644 --- a/packages/core-files/src/service/removeFilesService.ts +++ b/packages/core-files/src/service/removeFilesService.ts @@ -1,11 +1,11 @@ import { mongodb } from '@unchainedshop/mongodb'; import { getFileAdapter } from '../utils/getFileAdapter.js'; -import { UnchainedCore } from '@unchainedshop/core'; import { File } from '../types.js'; +import { FilesModule } from '../files-index.js'; export type RemoveFilesService = ( params: { fileIds: Array<string> }, - unchainedAPI: UnchainedCore, + unchainedAPI: { modules: { files: FilesModule } }, ) => Promise<number>; export const removeFilesService: RemoveFilesService = async ({ fileIds }, unchainedAPI) => { diff --git a/packages/core-files/src/service/uploadFileFromStreamService.ts b/packages/core-files/src/service/uploadFileFromStreamService.ts index c515e14f03..60c15ee091 100644 --- a/packages/core-files/src/service/uploadFileFromStreamService.ts +++ b/packages/core-files/src/service/uploadFileFromStreamService.ts @@ -1,11 +1,11 @@ -import { UnchainedCore } from '@unchainedshop/core'; import { getFileAdapter } from '../utils/getFileAdapter.js'; -import { getFileFromFileData } from '../utils/getFileFromFileData.js'; +import { getFileFromFileData } from '@unchainedshop/file-upload'; import { File } from '../types.js'; +import { FilesModule } from '../files-index.js'; export type UploadFileFromStreamService = ( params: { directoryName: string; rawFile: any; meta?: any }, - unchainedAPI: UnchainedCore, + unchainedAPI: { modules: { files: FilesModule } }, ) => Promise<File>; export const uploadFileFromStreamService: UploadFileFromStreamService = async ( diff --git a/packages/core-files/src/service/uploadFileFromURLService.ts b/packages/core-files/src/service/uploadFileFromURLService.ts index 513a14fd9f..6e63cc803d 100644 --- a/packages/core-files/src/service/uploadFileFromURLService.ts +++ b/packages/core-files/src/service/uploadFileFromURLService.ts @@ -1,7 +1,7 @@ import { getFileAdapter } from '../utils/getFileAdapter.js'; -import { getFileFromFileData } from '../utils/getFileFromFileData.js'; -import { UnchainedCore } from '@unchainedshop/core'; +import { getFileFromFileData } from '@unchainedshop/file-upload'; import { File } from '../types.js'; +import { FilesModule } from '../files-index.js'; export type UploadFileFromURLService = ( params: { @@ -14,7 +14,7 @@ export type UploadFileFromURLService = ( }; meta?: any; }, - unchainedAPI: UnchainedCore, + unchainedAPI: { modules: { files: FilesModule } }, ) => Promise<File>; export const uploadFileFromURLService: UploadFileFromURLService = async ( diff --git a/packages/core-files/src/types.ts b/packages/core-files/src/types.ts index 5d1ad9d402..3a4afc47ea 100644 --- a/packages/core-files/src/types.ts +++ b/packages/core-files/src/types.ts @@ -14,15 +14,3 @@ export type File = { export type SignedFileUpload = File & { putURL: string; }; - -export interface UploadFileData { - _id?: string; - directoryName: string; - expiryDate: Date; - fileName: string; - hash: string; - hashedName: string; - size?: number; - type: string; - url: string; -} diff --git a/packages/core-filters/src/module/configureFiltersModule.ts b/packages/core-filters/src/module/configureFiltersModule.ts index 52f1ba96f9..a941d98c72 100644 --- a/packages/core-filters/src/module/configureFiltersModule.ts +++ b/packages/core-filters/src/module/configureFiltersModule.ts @@ -7,8 +7,9 @@ import { generateDbFilterById, buildSortOptions, generateDbObjectId, + ModuleInput, } from '@unchainedshop/mongodb'; -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { FilterType } from '../db/FilterType.js'; import { FilterDirector } from '../director/FilterDirector.js'; import { FiltersCollection } from '../db/FiltersCollection.js'; diff --git a/packages/core-languages/src/module/configureLanguagesModule.ts b/packages/core-languages/src/module/configureLanguagesModule.ts index ddd5673efb..344df3b5ed 100644 --- a/packages/core-languages/src/module/configureLanguagesModule.ts +++ b/packages/core-languages/src/module/configureLanguagesModule.ts @@ -1,4 +1,4 @@ -import { ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import { emit, registerEvents } from '@unchainedshop/events'; import { generateDbFilterById, diff --git a/packages/core-messaging/src/module/configureMessagingModule.ts b/packages/core-messaging/src/module/configureMessagingModule.ts index 1b16bc1040..a38f02ab2d 100644 --- a/packages/core-messaging/src/module/configureMessagingModule.ts +++ b/packages/core-messaging/src/module/configureMessagingModule.ts @@ -1,7 +1,7 @@ import mustache from 'mustache'; import { MessagingModule } from '@unchainedshop/core-messaging'; import { createLogger } from '@unchainedshop/logger'; -import { ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; export const messagingLogger = createLogger('unchained:core-messaging'); diff --git a/packages/core-orders/src/module/configureOrdersModule.ts b/packages/core-orders/src/module/configureOrdersModule.ts index f5d2390ec6..531580b007 100644 --- a/packages/core-orders/src/module/configureOrdersModule.ts +++ b/packages/core-orders/src/module/configureOrdersModule.ts @@ -1,7 +1,7 @@ -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { OrderDelivery } from '@unchainedshop/core-orders'; import { OrderPayment } from '@unchainedshop/core-orders'; -import { generateDbFilterById } from '@unchainedshop/mongodb'; +import { generateDbFilterById, ModuleInput } from '@unchainedshop/mongodb'; import { createRequire } from 'node:module'; import { OrderDeliveriesCollection } from '../db/OrderDeliveriesCollection.js'; import { OrderDiscountsCollection } from '../db/OrderDiscountsCollection.js'; diff --git a/packages/core-payment/src/module/configurePaymentModule.ts b/packages/core-payment/src/module/configurePaymentModule.ts index d000bfeffd..0bd0cc3b0f 100644 --- a/packages/core-payment/src/module/configurePaymentModule.ts +++ b/packages/core-payment/src/module/configurePaymentModule.ts @@ -1,4 +1,4 @@ -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { PaymentCredentialsCollection } from '../db/PaymentCredentialsCollection.js'; import { PaymentProvidersCollection } from '../db/PaymentProvidersCollection.js'; import { @@ -11,6 +11,7 @@ import { } from './configurePaymentProvidersModule.js'; import { paymentSettings, PaymentSettingsOptions } from '../payment-settings.js'; import { PaymentContext, PaymentCredentials as PaymentCredentialsType } from '../types.js'; +import { ModuleInput } from '@unchainedshop/mongodb'; export type PaymentModule = { /* * Payment Providers Module diff --git a/packages/core-products/src/migrations/addMigrations.ts b/packages/core-products/src/migrations/addMigrations.ts index a049984598..c081a40e1a 100644 --- a/packages/core-products/src/migrations/addMigrations.ts +++ b/packages/core-products/src/migrations/addMigrations.ts @@ -1,5 +1,4 @@ -import { Migration, MigrationRepository } from '@unchainedshop/core'; -import { mongodb } from '@unchainedshop/mongodb'; +import { mongodb, MigrationRepository } from '@unchainedshop/mongodb'; import { ProductMediaCollection } from '../db/ProductMediaCollection.js'; import { ProductsCollection } from '../db/ProductsCollection.js'; @@ -22,7 +21,7 @@ const convertTagsToLowerCase = async (collection: mongodb.Collection<any>) => { if (count > 0) bulk.execute(); }; -export default function addMigrations(repository: MigrationRepository<Migration>) { +export default function addMigrations(repository: MigrationRepository) { repository?.register({ id: 20220920122600, name: 'Convert all tags to lower case to make it easy for search', diff --git a/packages/core-products/src/module/configureProductMediaModule.ts b/packages/core-products/src/module/configureProductMediaModule.ts index f95d109865..272b130416 100644 --- a/packages/core-products/src/module/configureProductMediaModule.ts +++ b/packages/core-products/src/module/configureProductMediaModule.ts @@ -1,5 +1,5 @@ import { ProductMedia, ProductMediaText } from '../types.js'; -import { ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import { emit, registerEvents } from '@unchainedshop/events'; import { findLocalizedText, @@ -69,13 +69,6 @@ const PRODUCT_MEDIA_EVENTS = [ 'PRODUCT_UPDATE_MEDIA_TEXT', ]; -FileDirector.registerFileUploadCallback('product-media', async (file, { modules }) => { - await modules.products.media.create({ - productId: file.meta?.productId as string, - mediaId: file._id, - }); -}); - export const configureProductMediaModule = async ({ db, }: ModuleInput<Record<string, never>>): Promise<ProductMediaModule> => { @@ -287,3 +280,16 @@ export const configureProductMediaModule = async ({ }, }; }; + +FileDirector.registerFileUploadCallback<{ + modules: { + products: { + media: ProductMediaModule; + }; + }; +}>('product-media', async (file, { modules }) => { + await modules.products.media.create({ + productId: file.meta?.productId as string, + mediaId: file._id, + }); +}); diff --git a/packages/core-products/src/module/configureProductReviewsModule.ts b/packages/core-products/src/module/configureProductReviewsModule.ts index 369c4e4f66..b39e8e91e6 100644 --- a/packages/core-products/src/module/configureProductReviewsModule.ts +++ b/packages/core-products/src/module/configureProductReviewsModule.ts @@ -1,4 +1,4 @@ -import { ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import { ProductReview, ProductReviewQuery, ProductReviewVoteType, ProductVote } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; import { diff --git a/packages/core-products/src/module/configureProductVariationsModule.ts b/packages/core-products/src/module/configureProductVariationsModule.ts index 4a881146cb..a26158ba8a 100644 --- a/packages/core-products/src/module/configureProductVariationsModule.ts +++ b/packages/core-products/src/module/configureProductVariationsModule.ts @@ -1,4 +1,4 @@ -import { ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import { emit, registerEvents } from '@unchainedshop/events'; import { findLocalizedText, diff --git a/packages/core-products/src/module/configureProductsModule.ts b/packages/core-products/src/module/configureProductsModule.ts index 92ee4ae39d..f50ef5888f 100644 --- a/packages/core-products/src/module/configureProductsModule.ts +++ b/packages/core-products/src/module/configureProductsModule.ts @@ -1,4 +1,4 @@ -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { Product, ProductAssignment, @@ -17,6 +17,7 @@ import { buildSortOptions, mongodb, generateDbObjectId, + ModuleInput, } from '@unchainedshop/mongodb'; import { SortDirection, SortOption, IDiscountAdapter } from '@unchainedshop/utils'; import { ProductDiscountDirector } from '../director/ProductDiscountDirector.js'; diff --git a/packages/core-quotations/src/module/configureQuotationsModule.ts b/packages/core-quotations/src/module/configureQuotationsModule.ts index 036e938f7e..a9f60547a5 100644 --- a/packages/core-quotations/src/module/configureQuotationsModule.ts +++ b/packages/core-quotations/src/module/configureQuotationsModule.ts @@ -1,5 +1,5 @@ import { SortDirection, SortOption } from '@unchainedshop/utils'; -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { Quotation, QuotationItemConfiguration, QuotationProposal } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; import { @@ -7,6 +7,7 @@ import { buildSortOptions, mongodb, generateDbObjectId, + ModuleInput, } from '@unchainedshop/mongodb'; import { QuotationsCollection } from '../db/QuotationsCollection.js'; import { QuotationStatus } from '../db/QuotationStatus.js'; diff --git a/packages/core-users/src/module/addMigrations.ts b/packages/core-users/src/module/addMigrations.ts index 13399d7a41..28d39637dd 100644 --- a/packages/core-users/src/module/addMigrations.ts +++ b/packages/core-users/src/module/addMigrations.ts @@ -1,4 +1,4 @@ -import { Migration, MigrationRepository } from '@unchainedshop/core'; +import { MigrationRepository } from '@unchainedshop/mongodb'; import { UsersCollection } from '../db/UsersCollection.js'; const convertTagsToLowerCase = async (collection: Awaited<ReturnType<typeof UsersCollection>>) => { @@ -20,7 +20,7 @@ const convertTagsToLowerCase = async (collection: Awaited<ReturnType<typeof User if (count > 0) bulk.execute(); }; -export default function addMigrations(repository: MigrationRepository<Migration>) { +export default function addMigrations(repository: MigrationRepository) { repository?.register({ id: 20220603115000, name: 'Copy user.profile.customFields to user.meta', diff --git a/packages/core-users/src/module/configureUsersModule.ts b/packages/core-users/src/module/configureUsersModule.ts index d02d258a68..e274b1bd65 100644 --- a/packages/core-users/src/module/configureUsersModule.ts +++ b/packages/core-users/src/module/configureUsersModule.ts @@ -1,5 +1,5 @@ import bcrypt from 'bcryptjs'; -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import { User, UserQuery, Email, UserLastLogin, UserProfile, UserData } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; import { @@ -18,6 +18,8 @@ import { configureUsersWebAuthnModule, UsersWebAuthnModule } from './configureUs import * as pbkdf2 from './pbkdf2.js'; import * as sha256 from './sha256.js'; import type { Address, Contact } from '@unchainedshop/mongodb'; +import { UserServices } from '../services/userServices.js'; +import { FileServices, FilesModule } from '@unchainedshop/core-files'; export type UsersModule = { // Submodules @@ -125,9 +127,17 @@ export const buildFindSelector = ({ includeGuests, queryString, ...rest }: UserQ return selector; }; -FileDirector.registerFileUploadCallback('user-avatars', async (file, context: UnchainedCore) => { +FileDirector.registerFileUploadCallback<{ + services: { + users: UserServices; + files: FileServices; + }; + modules: { + users: UsersModule; + files: FilesModule; + }; +}>('user-avatars', async (file, context) => { const { services } = context; - return services.users.updateUserAvatarAfterUpload({ file }, context); }); diff --git a/packages/core-users/src/module/configureUsersWebAuthnModule.ts b/packages/core-users/src/module/configureUsersWebAuthnModule.ts index bdd5e25ad1..ab0ef25d44 100644 --- a/packages/core-users/src/module/configureUsersWebAuthnModule.ts +++ b/packages/core-users/src/module/configureUsersWebAuthnModule.ts @@ -1,5 +1,5 @@ /// <reference lib="dom" /> -import { ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import { Fido2Lib, PublicKeyCredentialCreationOptions, diff --git a/packages/core-users/src/services/updateUserAvatarAfterUploadService.ts b/packages/core-users/src/services/updateUserAvatarAfterUploadService.ts index 7082bf754f..e9f6929a8c 100644 --- a/packages/core-users/src/services/updateUserAvatarAfterUploadService.ts +++ b/packages/core-users/src/services/updateUserAvatarAfterUploadService.ts @@ -1,10 +1,13 @@ -import { File } from '@unchainedshop/core-files'; +import { File, FileServices, FilesModule } from '@unchainedshop/core-files'; import { log, LogLevel } from '@unchainedshop/logger'; -import { UnchainedCore } from '@unchainedshop/core'; +import { UsersModule } from '../users-index.js'; export type UpdateUserAvatarAfterUploadService = ( params: { file: File }, - context: UnchainedCore, + context: { + modules: { files: FilesModule; users: UsersModule }; + services: { files: FileServices }; + }, ) => Promise<void>; export const updateUserAvatarAfterUploadService: UpdateUserAvatarAfterUploadService = async ( diff --git a/packages/core-warehousing/src/module/configureWarehousingModule.ts b/packages/core-warehousing/src/module/configureWarehousingModule.ts index 8c7a51d548..ae59d95350 100644 --- a/packages/core-warehousing/src/module/configureWarehousingModule.ts +++ b/packages/core-warehousing/src/module/configureWarehousingModule.ts @@ -1,6 +1,6 @@ import type { User } from '@unchainedshop/core-users'; -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { WarehousingContext, WarehousingProvider, @@ -8,7 +8,7 @@ import { WarehousingProviderType, } from '../types.js'; import { emit, registerEvents } from '@unchainedshop/events'; -import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb'; +import { generateDbFilterById, generateDbObjectId, mongodb, ModuleInput } from '@unchainedshop/mongodb'; import { WarehousingProvidersCollection } from '../db/WarehousingProvidersCollection.js'; import { WarehousingDirector } from '../director/WarehousingDirector.js'; import { TokenSurrogateCollection } from '../db/TokenSurrogateCollection.js'; diff --git a/packages/core-worker/src/module/configureWorkerModule.ts b/packages/core-worker/src/module/configureWorkerModule.ts index 9d811cd9a8..db91c91b48 100644 --- a/packages/core-worker/src/module/configureWorkerModule.ts +++ b/packages/core-worker/src/module/configureWorkerModule.ts @@ -1,5 +1,5 @@ import type { WorkData, WorkResult } from '../worker-index.js'; -import type { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import type { UnchainedCore } from '@unchainedshop/core'; import os from 'os'; import { createLogger } from '@unchainedshop/logger'; @@ -8,6 +8,7 @@ import { buildSortOptions, mongodb, generateDbObjectId, + ModuleInput, } from '@unchainedshop/mongodb'; import { emit, registerEvents } from '@unchainedshop/events'; import { buildObfuscatedFieldsFilter, SortDirection, SortOption } from '@unchainedshop/utils'; diff --git a/packages/core-worker/src/module/migrations/addMigrations.ts b/packages/core-worker/src/module/migrations/addMigrations.ts index 09581bad6b..146e182ac4 100644 --- a/packages/core-worker/src/module/migrations/addMigrations.ts +++ b/packages/core-worker/src/module/migrations/addMigrations.ts @@ -1,7 +1,7 @@ -import { Migration, MigrationRepository } from '@unchainedshop/core'; +import { MigrationRepository } from '@unchainedshop/mongodb'; import { WorkQueueCollection } from '../../db/WorkQueueCollection.js'; -export default function addMigrations(repository: MigrationRepository<Migration>) { +export default function addMigrations(repository: MigrationRepository) { repository?.register({ id: 20240905161400, name: 'Remove all autoscheduled work items so they get scheduled freshly', diff --git a/packages/core/src/core-index.ts b/packages/core/src/core-index.ts index 7614bb696c..5852804700 100644 --- a/packages/core/src/core-index.ts +++ b/packages/core/src/core-index.ts @@ -1,4 +1,4 @@ -import { BulkImporter, Migration, MigrationRepository, ModuleInput } from './types.js'; +import { BulkImporter } from './types.js'; import { AssortmentsModule, AssortmentsSettingsOptions, @@ -70,7 +70,7 @@ import { } from '@unchainedshop/core-users'; import { configureWarehousingModule, WarehousingModule } from '@unchainedshop/core-warehousing'; import { configureWorkerModule, WorkerModule, WorkerSettingsOptions } from '@unchainedshop/core-worker'; -import { mongodb } from '@unchainedshop/mongodb'; +import { mongodb, MigrationRepository, ModuleInput } from '@unchainedshop/mongodb'; export * from './types.js'; @@ -90,7 +90,7 @@ export interface ModuleOptions { export interface UnchainedCoreOptions { db: mongodb.Db; - migrationRepository: MigrationRepository<Migration>; + migrationRepository: MigrationRepository<UnchainedCore>; bulkImporter: any; modules?: Record< string, diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index f894deab69..b0034d367a 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1,38 +1,7 @@ -import type { mongodb } from '@unchainedshop/mongodb'; -import type { UnchainedCore } from './core-index.js'; - export interface BulkImporter { createBulkImporter: (options: any) => any; } -export interface Migration { - id: number; - name: string; - up: (params: { logger: any | Console; unchainedAPI: UnchainedCore }) => Promise<void>; -} - -export interface MigrationRepository<MigrationInstance extends Migration> { - db: mongodb.Db; - migrations: Map<number, MigrationInstance>; - register: (migration: MigrationInstance) => void; - allMigrations: () => Array<MigrationInstance>; -} - /* * Module */ - -export interface ModuleInput<Options extends Record<string, any>> { - db: mongodb.Db; - migrationRepository?: MigrationRepository<Migration>; - options?: Options; -} - -export interface ModuleCreateMutation<T> { - create: (doc: T) => Promise<string | null>; -} - -export interface ModuleMutations<T> extends ModuleCreateMutation<T> { - update: (_id: string, doc: mongodb.UpdateFilter<T> | T) => Promise<string>; - delete: (_id: string) => Promise<number>; -} diff --git a/packages/file-upload/package.json b/packages/file-upload/package.json index 897a8b9f29..27fe52df71 100644 --- a/packages/file-upload/package.json +++ b/packages/file-upload/package.json @@ -24,7 +24,7 @@ "ecommerce", "core" ], - "author": "Joël Meiller", + "authors": ["Joël Meiller", "Pascal Kaufmann"], "license": "EUPL-1.2", "bugs": { "url": "https://github.com/unchainedshop/unchained/issues" diff --git a/packages/file-upload/src/director/FileAdapter.ts b/packages/file-upload/src/director/FileAdapter.ts index 19d43e8b30..cb10810ba7 100644 --- a/packages/file-upload/src/director/FileAdapter.ts +++ b/packages/file-upload/src/director/FileAdapter.ts @@ -1,20 +1,19 @@ -import { log, LogLevel } from '@unchainedshop/logger'; -import { UnchainedCore } from '@unchainedshop/core'; -import { File, UploadFileData } from '@unchainedshop/core-files'; import { Readable } from 'stream'; +import { log, LogLevel } from '@unchainedshop/logger'; import { IBaseAdapter } from '@unchainedshop/utils'; +import { UploadedFile, UploadFileData } from '../types.js'; -export interface IFileAdapter extends IBaseAdapter { +export interface IFileAdapter<Context = unknown> extends IBaseAdapter { createSignedURL: ( directoryName: string, fileName: string, - unchainedAPI: UnchainedCore, + unchainedAPI: Context, ) => Promise<(UploadFileData & { putURL: string }) | null>; - removeFiles: (files: Array<File>, unchainedContext: UnchainedCore) => Promise<void>; + removeFiles: (files: Array<UploadedFile>, unchainedContext: Context) => Promise<void>; uploadFileFromStream: ( directoryName: string, rawFile: any, - unchainedAPI: UnchainedCore, + unchainedAPI: Context, ) => Promise<UploadFileData | null>; uploadFileFromURL: ( directoryName: string, @@ -24,9 +23,9 @@ export interface IFileAdapter extends IBaseAdapter { fileId?: string; headers?: Record<string, unknown>; }, - unchainedAPI: UnchainedCore, + unchainedAPI: Context, ) => Promise<UploadFileData | null>; - createDownloadStream: (file: File, unchainedAPI: UnchainedCore) => Promise<Readable>; + createDownloadStream: (file: UploadedFile, unchainedAPI: Context) => Promise<Readable>; } export const FileAdapter: Omit<IFileAdapter, 'key' | 'label' | 'version'> = { createSignedURL() { diff --git a/packages/file-upload/src/director/FileDirector.ts b/packages/file-upload/src/director/FileDirector.ts index bc0bb28696..952d1e6f1b 100644 --- a/packages/file-upload/src/director/FileDirector.ts +++ b/packages/file-upload/src/director/FileDirector.ts @@ -1,9 +1,11 @@ import { BaseDirector } from '@unchainedshop/utils'; -import { UnchainedCore } from '@unchainedshop/core'; -import { File } from '@unchainedshop/core-files'; import { IFileAdapter } from './FileAdapter.js'; +import { UploadedFile } from '../types.js'; -export type UploadFileCallback = (file: File, unchainedAPI: UnchainedCore) => Promise<void>; +export type UploadFileCallback<UnchainedAPI = unknown> = ( + file: UploadedFile, + unchainedAPI: UnchainedAPI, +) => Promise<void>; const FileUploadRegistry = new Map<string, UploadFileCallback>(); @@ -12,7 +14,7 @@ const baseDirector = BaseDirector<IFileAdapter>('FileDirector'); export const FileDirector = { ...baseDirector, - registerFileUploadCallback(directoryName: string, fn: UploadFileCallback) { + registerFileUploadCallback<UnchainedAPI>(directoryName: string, fn: UploadFileCallback<UnchainedAPI>) { if (!FileUploadRegistry.has(directoryName)) { FileUploadRegistry.set(directoryName, fn); } diff --git a/packages/file-upload/src/file-upload-index.ts b/packages/file-upload/src/file-upload-index.ts index b1de2eeba2..a5eff953cf 100644 --- a/packages/file-upload/src/file-upload-index.ts +++ b/packages/file-upload/src/file-upload-index.ts @@ -1,6 +1,8 @@ import buildHashedFilename from './build-hashed-filename.js'; import resolveExpirationDate from './put-expiration.js'; +import getFileFromFileData from './get-file-from-file-data.js'; export { FileDirector } from './director/FileDirector.js'; export { FileAdapter, IFileAdapter } from './director/FileAdapter.js'; -export { buildHashedFilename, resolveExpirationDate }; +export { buildHashedFilename, resolveExpirationDate, getFileFromFileData }; +export type * from './types.js'; diff --git a/packages/core-files/src/utils/getFileFromFileData.ts b/packages/file-upload/src/get-file-from-file-data.ts similarity index 78% rename from packages/core-files/src/utils/getFileFromFileData.ts rename to packages/file-upload/src/get-file-from-file-data.ts index aefe7ee9f4..b7b4a5df49 100644 --- a/packages/core-files/src/utils/getFileFromFileData.ts +++ b/packages/file-upload/src/get-file-from-file-data.ts @@ -1,4 +1,4 @@ -import { UploadFileData } from '../types.js'; +import { UploadFileData } from './types.js'; export const getFileFromFileData = (fileData: UploadFileData, meta: any) => ({ _id: fileData._id, @@ -10,3 +10,5 @@ export const getFileFromFileData = (fileData: UploadFileData, meta: any) => ({ url: fileData.url, meta, }); + +export default getFileFromFileData; diff --git a/packages/file-upload/src/types.ts b/packages/file-upload/src/types.ts new file mode 100644 index 0000000000..9078d7edc6 --- /dev/null +++ b/packages/file-upload/src/types.ts @@ -0,0 +1,21 @@ +export interface UploadFileData { + _id?: string; + directoryName: string; + expiryDate: Date; + fileName: string; + hash: string; + hashedName: string; + size?: number; + type: string; + url: string; +} + +export interface UploadedFile { + _id?: string; + path: string; + meta?: Record<string, unknown>; + name: string; + size?: number; + type?: string; + url?: string; +} diff --git a/packages/mongodb/src/mongodb-index.ts b/packages/mongodb/src/mongodb-index.ts index cc8fee5319..cccd3e473c 100644 --- a/packages/mongodb/src/mongodb-index.ts +++ b/packages/mongodb/src/mongodb-index.ts @@ -46,3 +46,22 @@ export interface Contact { telNumber?: string; emailAddress?: string; } + +export interface Migration<Context = unknown> { + id: number; + name: string; + up: (params: { logger: any | Console; unchainedAPI: Context }) => Promise<void>; +} + +export interface MigrationRepository<Context = unknown> { + db: mongodb.Db; + migrations: Map<number, Migration<Context>>; + register: (migration: Migration<Context>) => void; + allMigrations: () => Array<Migration<Context>>; +} + +export interface ModuleInput<Options extends Record<string, any>> { + db: mongodb.Db; + migrationRepository?: MigrationRepository; + options?: Options; +} diff --git a/packages/platform/src/migrations/migrationRepository.ts b/packages/platform/src/migrations/migrationRepository.ts index a1cc8f3101..769a4d81bd 100644 --- a/packages/platform/src/migrations/migrationRepository.ts +++ b/packages/platform/src/migrations/migrationRepository.ts @@ -1,7 +1,6 @@ -import { Migration, MigrationRepository } from '@unchainedshop/core'; -import { mongodb } from '@unchainedshop/mongodb'; +import { mongodb, Migration, MigrationRepository } from '@unchainedshop/mongodb'; -export const createMigrationRepository = (db: mongodb.Db): MigrationRepository<Migration> => { +export const createMigrationRepository = (db: mongodb.Db): MigrationRepository => { const migrations = new Map(); return { db, diff --git a/packages/platform/src/migrations/runMigrations.ts b/packages/platform/src/migrations/runMigrations.ts index a8184fd219..350b26a4c7 100644 --- a/packages/platform/src/migrations/runMigrations.ts +++ b/packages/platform/src/migrations/runMigrations.ts @@ -1,6 +1,6 @@ -import { Migration, UnchainedCore, MigrationRepository } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { createLogger } from '@unchainedshop/logger'; -import { generateDbFilterById } from '@unchainedshop/mongodb'; +import { generateDbFilterById, MigrationRepository } from '@unchainedshop/mongodb'; import { createMigrationRunner } from './createMigrationRunner.js'; export const runMigrations = async ({ @@ -8,7 +8,7 @@ export const runMigrations = async ({ logger = createLogger('unchained:migrations'), unchainedAPI, }: { - migrationRepository: MigrationRepository<Migration>; + migrationRepository: MigrationRepository<UnchainedCore>; logger?: any; unchainedAPI: UnchainedCore; }) => { diff --git a/packages/plugins/src/files/gridfs/gridfs-adapter.ts b/packages/plugins/src/files/gridfs/gridfs-adapter.ts index c7e6a1545e..60a314128f 100644 --- a/packages/plugins/src/files/gridfs/gridfs-adapter.ts +++ b/packages/plugins/src/files/gridfs/gridfs-adapter.ts @@ -10,7 +10,7 @@ import { resolveExpirationDate, IFileAdapter, } from '@unchainedshop/file-upload'; -import { UploadFileData } from '@unchainedshop/core-files'; +import { UploadFileData } from '@unchainedshop/file-upload'; import sign from './sign.js'; const { ROOT_URL } = process.env; diff --git a/packages/plugins/src/files/minio/minio-adapter.ts b/packages/plugins/src/files/minio/minio-adapter.ts index be228deb99..99c4ad7101 100644 --- a/packages/plugins/src/files/minio/minio-adapter.ts +++ b/packages/plugins/src/files/minio/minio-adapter.ts @@ -2,7 +2,7 @@ import https from 'https'; import http, { OutgoingHttpHeaders } from 'http'; import { Readable } from 'stream'; import { URL } from 'url'; -import { UploadFileData } from '@unchainedshop/core-files'; +import { UploadFileData } from '@unchainedshop/file-upload'; import { FileAdapter, FileDirector, diff --git a/packages/plugins/src/plugins-index.ts b/packages/plugins/src/plugins-index.ts index 4aa18bdb6d..d40e6811d8 100644 --- a/packages/plugins/src/plugins-index.ts +++ b/packages/plugins/src/plugins-index.ts @@ -1,5 +1,6 @@ -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; import express from 'express'; +import { UnchainedCore } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import baseModules from './presets/base-modules.js'; import './presets/countries/ch.js'; diff --git a/packages/plugins/src/presets/base-modules.ts b/packages/plugins/src/presets/base-modules.ts index d8f235e608..669f8fb381 100644 --- a/packages/plugins/src/presets/base-modules.ts +++ b/packages/plugins/src/presets/base-modules.ts @@ -1,4 +1,4 @@ -import { ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; // Delivery import '../delivery/post.js'; diff --git a/packages/plugins/src/presets/crypto-modules.ts b/packages/plugins/src/presets/crypto-modules.ts index 4a5a75e466..4715abbad5 100644 --- a/packages/plugins/src/presets/crypto-modules.ts +++ b/packages/plugins/src/presets/crypto-modules.ts @@ -1,4 +1,4 @@ -import { ModuleInput } from '@unchainedshop/core'; +import { ModuleInput } from '@unchainedshop/mongodb'; import { configureCryptopayModule } from '../payment/cryptopay/index.js'; // Warehousing diff --git a/packages/ticketing/src/module.ts b/packages/ticketing/src/module.ts index f3be20fb9f..1ce13c41b0 100644 --- a/packages/ticketing/src/module.ts +++ b/packages/ticketing/src/module.ts @@ -1,8 +1,8 @@ import { createLogger } from '@unchainedshop/logger'; -import { buildDbIndexes } from '@unchainedshop/mongodb'; +import { buildDbIndexes, ModuleInput } from '@unchainedshop/mongodb'; import { MediaObjectsCollection } from '@unchainedshop/core-files/db/MediaObjectsCollection.js'; import { TokenSurrogateCollection } from '@unchainedshop/core-warehousing/db/TokenSurrogateCollection.js'; -import { ModuleInput, UnchainedCore } from '@unchainedshop/core'; +import { UnchainedCore } from '@unchainedshop/core'; import { TokenSurrogate } from '@unchainedshop/core-warehousing'; import { File } from '@unchainedshop/core-files'; diff --git a/packages/utils/src/locale-helpers.ts b/packages/utils/src/locale-helpers.ts index f235ec4fd9..649b26bdd4 100644 --- a/packages/utils/src/locale-helpers.ts +++ b/packages/utils/src/locale-helpers.ts @@ -1,5 +1,3 @@ -import { Country } from '@unchainedshop/core-countries'; -import { Currency } from '@unchainedshop/core-currencies'; import { resolveAcceptLanguage } from 'resolve-accept-language'; const { UNCHAINED_LANG = 'de', UNCHAINED_COUNTRY = 'CH', UNCHAINED_CURRENCY = 'CHF' } = process.env; @@ -20,7 +18,7 @@ export const resolveBestSupported = ( export const resolveBestCountry = ( localeCountry: string, shopCountry: string, - countries: Array<Country>, + countries: Array<{ isoCode: string }>, ) => { if (shopCountry) { const resolvedCountry = countries.reduce<string>((lastResolved, country) => { @@ -36,7 +34,7 @@ export const resolveBestCountry = ( return localeCountry || systemLocale.region; }; -export const resolveBestCurrency = (localeCurrency: string, currencies: Array<Currency>) => { +export const resolveBestCurrency = (localeCurrency: string, currencies: Array<{ isoCode: string }>) => { if (localeCurrency) { const resolvedCurrency = currencies.find((currency) => currency.isoCode === localeCurrency); if (resolvedCurrency) {