The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
chore: v2.0.0-canary.42
vholikda56aca5edbe
diff --git a/packages/admin/package.json b/packages/admin/package.jsonindex 923be0d6c..cbd7a5447 100644--- a/packages/admin/package.json+++ b/packages/admin/package.json@@ -1,6 +1,6 @@{"name": "@mercurjs/admin",- "version": "2.0.0-canary.41",+ "version": "2.0.0-canary.42","repository": {"type": "git","url": "https://github.com/mercurjs/mercur",diff --git a/packages/cli/package.json b/packages/cli/package.jsonindex 2070bb485..30bee92df 100644--- a/packages/cli/package.json+++ b/packages/cli/package.json@@ -1,6 +1,6 @@{"name": "@mercurjs/cli",- "version": "2.0.0-canary.41",+ "version": "2.0.0-canary.42","repository": {"type": "git","url": "https://github.com/mercurjs/mercur",diff --git a/packages/client/package.json b/packages/client/package.jsonindex 6e45fccc6..d681006d5 100644--- a/packages/client/package.json+++ b/packages/client/package.json@@ -1,6 +1,6 @@{"name": "@mercurjs/client",- "version": "2.0.0-canary.41",+ "version": "2.0.0-canary.42","repository": {"type": "git","url": "https://github.com/mercurjs/mercur",diff --git a/packages/core-plugin/package.json b/packages/core-plugin/package.jsonindex 7b69acf3b..48a9fabbf 100644--- a/packages/core-plugin/package.json+++ b/packages/core-plugin/package.json@@ -1,6 +1,6 @@{"name": "@mercurjs/core-plugin",- "version": "2.0.0-canary.41",+ "version": "2.0.0-canary.42","repository": {"type": "git","url": "https://github.com/mercurjs/mercur",diff --git a/packages/core-plugin/src/migration-scripts/sync-custom-fields.ts b/packages/core-plugin/src/migration-scripts/sync-custom-fields.tsdeleted file mode 100644index 5383d0332..000000000--- a/packages/core-plugin/src/migration-scripts/sync-custom-fields.ts+++ /dev/null@@ -1,120 +0,0 @@-import { ExecArgs } from "@medusajs/framework/types";-import {- camelToSnakeCase,- ContainerRegistrationKeys,- DALUtils,- ModulesSdkUtils,- normalizeMigrationSQL,-} from "@medusajs/framework/utils";-import { DatabaseSchema } from "@medusajs/framework/mikro-orm/knex";-import { generateEntity } from "../modules/custom-fields/utils/generate-entity";-import { CUSTOM_FIELDS_MODULE, CustomFieldsModuleOptions } from "../modules/custom-fields";--function pickTableRelatedCommands(tableNames: string[], sqlCommand: string) {- const ignoreColumns = ["created_at", "updated_at", "deleted_at"];- const commands = sqlCommand.split(";");- const returnedCommands = commands- .filter((command) => {- const cmd = command.trim();- return (- cmd.length &&- cmd !== "set names 'utf8'" &&- tableNames.some((t) => cmd.includes(`"${t}"`)) &&- !ignoreColumns.some((column) => cmd.includes(`column "${column}"`))- );- })- .map((cmd) => cmd.trim());-- if (returnedCommands.length > 0) {- returnedCommands.push("");- }-- return returnedCommands.join(";");-}--export default async function syncCustomFields({ container }: ExecArgs) {- const logger = container.resolve(ContainerRegistrationKeys.LOGGER);- const configModule = container.resolve(ContainerRegistrationKeys.CONFIG_MODULE);-- let moduleConfig;- if (configModule.modules) {- for (const [key, value] of Object.entries(configModule.modules)) {- if (- key === CUSTOM_FIELDS_MODULE ||- (typeof value === "object" &&- value !== null &&- "resolve" in value &&- value.resolve === "./src/modules/custom-fields")- ) {- moduleConfig = value;- break;- }- }- }-- const options = (moduleConfig?.options ?? {}) as CustomFieldsModuleOptions;- const { customFields = {} } = options;-- const tableNames: string[] = [];- const entities = Object.entries(customFields).map(([entityName, fields]) => {- const tableName = `${camelToSnakeCase(entityName)}_custom_fields`;- tableNames.push(tableName);-- const fieldDefs = Object.entries(fields ?? {}).map(([name, field]) => ({- ...field,- name,- nullable: field.nullable ?? true,- defaultValue: field.defaultValue ?? null,- }));-- return generateEntity(tableName, fieldDefs);- });-- if (!entities.length) {- logger.info("No custom fields configured. Skipping.");- return;- }-- logger.info("Syncing custom fields...");-- const dbConfig = ModulesSdkUtils.loadDatabaseConfig("custom_fields");- const orm = await DALUtils.mikroOrmCreateConnection(dbConfig, entities, "");-- try {- const generator = orm.getSchemaGenerator();- const connection = orm.em.getConnection();- const platform = orm.em.getPlatform();- const schemaName = dbConfig.schema || "public";-- const dbSchema = new DatabaseSchema(platform, schemaName);- try {- await platform.getSchemaHelper?.()?.loadInformationSchema(- dbSchema,- connection,- tableNames.map((table_name) => ({- table_name,- schema_name: schemaName,- })),- );- } catch {- // Tables don't exist yet — empty schema will generate CREATE TABLE- }-- const rawSql = normalizeMigrationSQL(- await generator.getUpdateSchemaSQL({- fromSchema: dbSchema,- }),- );-- const sql = pickTableRelatedCommands(tableNames, rawSql);-- if (sql) {- await connection.execute(sql);- logger.info("Custom fields migrated successfully.");- } else {- logger.info("Custom fields are up to date.");- }- } finally {- await orm.close(true);- }-}diff --git a/packages/core-plugin/src/modules/custom-fields/loaders.ts b/packages/core-plugin/src/modules/custom-fields/loaders.tsindex c21328eee..08bc50f29 100644--- a/packages/core-plugin/src/modules/custom-fields/loaders.ts+++ b/packages/core-plugin/src/modules/custom-fields/loaders.ts@@ -1,9 +1,104 @@import { LoaderOptions, ModuleJoinerConfig } from "@medusajs/framework/types";import {camelToSnakeCase,+ DALUtils,+ ModulesSdkUtils,+ normalizeMigrationSQL,} from "@medusajs/framework/utils";+import { DatabaseSchema } from "@medusajs/framework/mikro-orm/knex";import { CustomFieldsModuleOptions } from "@mercurjs/types";import { MedusaModule } from "@medusajs/framework/modules-sdk";+import { generateEntity } from "./utils/generate-entity";++function pickTableRelatedCommands(tableNames: string[], sqlCommand: string) {+ const ignoreColumns = ["created_at", "updated_at", "deleted_at"];+ const commands = sqlCommand.split(";");+ const returnedCommands = commands+ .filter((command) => {+ const cmd = command.trim();+ return (+ cmd.length &&+ cmd !== "set names 'utf8'" &&+ tableNames.some((t) => cmd.includes(`"${t}"`)) &&+ !ignoreColumns.some((column) => cmd.includes(`column "${column}"`))+ );+ })+ .map((cmd) => cmd.trim());++ if (returnedCommands.length > 0) {+ returnedCommands.push("");+ }++ return returnedCommands.join(";");+}++async function syncCustomFields(+ logger: LoaderOptions["logger"],+ customFields: NonNullable<CustomFieldsModuleOptions["customFields"]>,+) {+ const tableNames: string[] = [];+ const entities = Object.entries(customFields).map(([entityName, fields]) => {+ const tableName = `${camelToSnakeCase(entityName)}_custom_fields`;+ tableNames.push(tableName);++ const fieldDefs = Object.entries(fields ?? {}).map(([name, field]) => ({+ ...field,+ name,+ nullable: field.nullable ?? true,+ defaultValue: field.defaultValue ?? null,+ }));++ return generateEntity(tableName, fieldDefs);+ });++ if (!entities.length) {+ logger?.info("No custom fields configured. Skipping.");+ return;+ }++ logger?.info("Syncing custom fields...");++ const dbConfig = ModulesSdkUtils.loadDatabaseConfig("custom_fields");+ const orm = await DALUtils.mikroOrmCreateConnection(dbConfig, entities, "");++ try {+ const generator = orm.getSchemaGenerator();+ const connection = orm.em.getConnection();+ const platform = orm.em.getPlatform();+ const schemaName = dbConfig.schema || "public";++ const dbSchema = new DatabaseSchema(platform, schemaName);+ try {+ await platform.getSchemaHelper?.()?.loadInformationSchema(+ dbSchema,+ connection,+ tableNames.map((table_name) => ({+ table_name,+ schema_name: schemaName,+ })),+ );+ } catch {+ // Tables don't exist yet — empty schema will generate CREATE TABLE+ }++ const rawSql = normalizeMigrationSQL(+ await generator.getUpdateSchemaSQL({+ fromSchema: dbSchema,+ }),+ );++ const sql = pickTableRelatedCommands(tableNames, rawSql);++ if (sql) {+ await connection.execute(sql);+ logger?.info("Custom fields migrated successfully.");+ } else {+ logger?.info("Custom fields are up to date.");+ }+ } finally {+ await orm.close(true);+ }+}export default async function customFieldsLoader({logger,@@ -11,6 +106,12 @@ export default async function customFieldsLoader({}: LoaderOptions) {const { customFields = {} } = (options ?? {}) as CustomFieldsModuleOptions;+ const isMigration = process.argv.some((arg) => arg === "db:migrate");++ if (isMigration) {+ await syncCustomFields(logger, customFields);+ }+MedusaModule.setCustomLink((joinerConfigs) => {const entityJoinerConfigMap = new Map<string, ModuleJoinerConfig>();diff --git a/packages/core-plugin/src/workflows/custom-fields/index.ts b/packages/core-plugin/src/workflows/custom-fields/index.tsnew file mode 100644index 000000000..c1f49c23f--- /dev/null+++ b/packages/core-plugin/src/workflows/custom-fields/index.ts@@ -0,0 +1 @@+export * from "./steps"diff --git a/packages/core-plugin/src/workflows/custom-fields/steps/create-custom-fields.ts b/packages/core-plugin/src/workflows/custom-fields/steps/create-custom-fields.tsnew file mode 100644index 000000000..c3dab0111--- /dev/null+++ b/packages/core-plugin/src/workflows/custom-fields/steps/create-custom-fields.ts@@ -0,0 +1,30 @@+import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"+import { MercurModules } from "@mercurjs/types"++import CustomFieldsModuleService from "../../../modules/custom-fields/services/custom-fields-module-service"++type CreateCustomFieldsStepInput = {+ alias: string+ data: { id: string; [key: string]: unknown }[]+}++export const createCustomFieldsStep = createStep(+ "create-custom-fields",+ async (input: CreateCustomFieldsStepInput, { container }) => {+ const service = container.resolve<CustomFieldsModuleService>(MercurModules.CUSTOM_FIELDS)++ const created = await service.create(input.alias, input.data)++ return new StepResponse(created, {+ alias: input.alias,+ ids: created.map((row) => row.id),+ })+ },+ async (data, { container }) => {+ if (!data) return++ const service = container.resolve<CustomFieldsModuleService>(MercurModules.CUSTOM_FIELDS)++ await service.delete(data.alias, data.ids)+ }+)diff --git a/packages/core-plugin/src/workflows/custom-fields/steps/delete-custom-fields.ts b/packages/core-plugin/src/workflows/custom-fields/steps/delete-custom-fields.tsnew file mode 100644index 000000000..1c9ce4de9--- /dev/null+++ b/packages/core-plugin/src/workflows/custom-fields/steps/delete-custom-fields.ts@@ -0,0 +1,20 @@+import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"+import { MercurModules } from "@mercurjs/types"++import CustomFieldsModuleService from "../../../modules/custom-fields/services/custom-fields-module-service"++type DeleteCustomFieldsStepInput = {+ alias: string+ ids: string[]+}++export const deleteCustomFieldsStep = createStep(+ "delete-custom-fields",+ async (input: DeleteCustomFieldsStepInput, { container }) => {+ const service = container.resolve<CustomFieldsModuleService>(MercurModules.CUSTOM_FIELDS)++ await service.delete(input.alias, input.ids)++ return new StepResponse(undefined, input)+ }+)diff --git a/packages/core-plugin/src/workflows/custom-fields/steps/index.ts b/packages/core-plugin/src/workflows/custom-fields/steps/index.tsnew file mode 100644index 000000000..6b3c2411b--- /dev/null+++ b/packages/core-plugin/src/workflows/custom-fields/steps/index.ts@@ -0,0 +1,3 @@+export * from "./create-custom-fields"+export * from "./update-custom-fields"+export * from "./delete-custom-fields"diff --git a/packages/core-plugin/src/workflows/custom-fields/steps/update-custom-fields.ts b/packages/core-plugin/src/workflows/custom-fields/steps/update-custom-fields.tsnew file mode 100644index 000000000..6e20350c2--- /dev/null+++ b/packages/core-plugin/src/workflows/custom-fields/steps/update-custom-fields.ts@@ -0,0 +1,35 @@+import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"+import { MercurModules } from "@mercurjs/types"++import CustomFieldsModuleService from "../../../modules/custom-fields/services/custom-fields-module-service"++type UpdateCustomFieldsStepInput = {+ alias: string+ data: { id: string; [key: string]: unknown }[]+}++export const updateCustomFieldsStep = createStep(+ "update-custom-fields",+ async (input: UpdateCustomFieldsStepInput, { container }) => {+ const service = container.resolve<CustomFieldsModuleService>(MercurModules.CUSTOM_FIELDS)++ const previousData = await service.list(+ { [input.data[0] ? Object.keys(input.data[0]).find((k) => k.endsWith("_id")) || "id" : "id"]: input.data.map((d) => d.id) },+ {}+ )++ const updated = await service.update(input.alias, input.data)++ return new StepResponse(updated, {+ alias: input.alias,+ data: previousData,+ })+ },+ async (data, { container }) => {+ if (!data) return++ const service = container.resolve<CustomFieldsModuleService>(MercurModules.CUSTOM_FIELDS)++ await service.update(data.alias, data.data)+ }+)diff --git a/packages/core-plugin/src/workflows/index.ts b/packages/core-plugin/src/workflows/index.tsindex 2209b31da..c157a9596 100644--- a/packages/core-plugin/src/workflows/index.ts+++ b/packages/core-plugin/src/workflows/index.ts@@ -10,4 +10,5 @@ export * from "./shipping-option"export * from "./shipping-profile"export * from "./stock-location"export * from './cart'-export * from './events'\ No newline at end of file+export * from './events'+export * from './custom-fields'\ No newline at end of filediff --git a/packages/dashboard-sdk/package.json b/packages/dashboard-sdk/package.jsonindex ba32079ec..2771ec9ad 100644--- a/packages/dashboard-sdk/package.json+++ b/packages/dashboard-sdk/package.json@@ -1,6 +1,6 @@{"name": "@mercurjs/dashboard-sdk",- "version": "2.0.0-canary.41",+ "version": "2.0.0-canary.42","repository": {"type": "git","url": "https://github.com/mercurjs/mercur",diff --git a/packages/dashboard-shared/package.json b/packages/dashboard-shared/package.jsonindex 54e7fc237..f2019750e 100644--- a/packages/dashboard-shared/package.json+++ b/packages/dashboard-shared/package.json@@ -1,6 +1,6 @@{"name": "@mercurjs/dashboard-shared",- "version": "2.0.0-canary.41",+ "version": "2.0.0-canary.42","repository": {"type": "git","url": "https://github.com/mercurjs/mercur",diff --git a/packages/types/package.json b/packages/types/package.jsonindex 1ca975245..b7356de72 100644--- a/packages/types/package.json+++ b/packages/types/package.json@@ -1,6 +1,6 @@{"name": "@mercurjs/types",- "version": "2.0.0-canary.41",+ "version": "2.0.0-canary.42","repository": {"type": "git","url": "https://github.com/mercurjs/mercur",diff --git a/packages/vendor/package.json b/packages/vendor/package.jsonindex 892630177..696a435cb 100644--- a/packages/vendor/package.json+++ b/packages/vendor/package.json@@ -1,6 +1,6 @@{"name": "@mercurjs/vendor",- "version": "2.0.0-canary.41",+ "version": "2.0.0-canary.42","repository": {"type": "git","url": "https://github.com/mercurjs/mercur",