@open-mercato/cli 0.11.1-develop.8557.1.e615240a3e → 0.11.1-develop.8572.1.85986dc508
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +6 -2
- package/dist/agentic/guides/module-facts.json +824 -195
- package/dist/agentic/guides/module-facts.v2.json +824 -195
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/di-registrations-rich.md +1 -1
- package/dist/agentic/guides/modules/api_keys/di-service-tokens.md +1 -1
- package/dist/agentic/guides/modules/api_keys/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/di-registrations-rich.md +2 -1
- package/dist/agentic/guides/modules/audit_logs/di-service-tokens.md +2 -1
- package/dist/agentic/guides/modules/audit_logs/exact-override-targets.md +2 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +2 -2
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/backups/index.md +12 -0
- package/dist/agentic/guides/modules/backups/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/exact-override-targets.md +2 -2
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/setup.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/di-registrations-rich.md +2 -2
- package/dist/agentic/guides/modules/record_locks/di-service-tokens.md +2 -2
- package/dist/agentic/guides/modules/record_locks/exact-override-targets.md +2 -2
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/search/setup.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/di-registrations-rich.md +10 -10
- package/dist/agentic/guides/modules/workflows/di-service-tokens.md +10 -10
- package/dist/agentic/guides/modules/workflows/events.md +14 -1
- package/dist/agentic/guides/modules/workflows/exact-override-targets.md +10 -10
- package/dist/agentic/guides/modules/workflows/index.md +3 -3
- package/dist/agentic/guides/modules/workflows/umes-hosts.md +13 -0
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +8 -0
- package/dist/agentic/guides/upstream/manifest.json +2 -2
- package/dist/agentic/shared/ai/harness/cases.json +1 -1
- package/dist/bin.js +2 -1
- package/dist/bin.js.map +2 -2
- package/dist/lib/db/migration-reindex.js +1 -1
- package/dist/lib/db/migration-reindex.js.map +2 -2
- package/dist/lib/rotation-kms-warning-presentation.js +12 -0
- package/dist/lib/rotation-kms-warning-presentation.js.map +7 -0
- package/package.json +7 -7
- package/src/__tests__/mercato.test.ts +105 -0
- package/src/bin.ts +2 -1
- package/src/lib/__tests__/rotation-kms-warning-presentation.test.ts +73 -0
- package/src/lib/db/__tests__/migration-reindex.test.ts +1 -1
- package/src/lib/db/migration-reindex.ts +2 -2
- package/src/lib/generators/__tests__/instance-config-defaults-discovery.test.ts +195 -0
- package/src/lib/rotation-kms-warning-presentation.ts +11 -0
|
@@ -71,7 +71,7 @@ async function requestQueryIndexReindex(entityTypes, deps) {
|
|
|
71
71
|
await eventBus.emitEvent(
|
|
72
72
|
"query_index.reindex",
|
|
73
73
|
{ entityType, allowAllTenants: true, force: false },
|
|
74
|
-
{ persistent: true }
|
|
74
|
+
{ persistent: true, tenantId: null, allowAllTenants: true }
|
|
75
75
|
);
|
|
76
76
|
queued.push(entityType);
|
|
77
77
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/db/migration-reindex.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { parseBooleanWithDefault } from '@open-mercato/shared/lib/boolean'\nimport {\n formatQueryIndexRebuildCommands,\n readQueryIndexReindexDeclaration,\n} from '@open-mercato/shared/lib/query/migration-reindex'\n\nconst MIGRATION_FILE_NAME_PATTERN = /^[A-Za-z0-9._-]+$/\nconst MIGRATION_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs']\n\nexport type AppliedMigration = {\n moduleId: string\n migrationsPath: string\n name: string\n filePath?: string | null\n}\n\nexport type MigrationReindexDeps = {\n importModule: (filePath: string) => Promise<unknown>\n fileExists?: (filePath: string) => boolean\n onWarn?: (message: string) => void\n}\n\nexport function isMigrationReindexEnabled(env: NodeJS.ProcessEnv = process.env): boolean {\n return parseBooleanWithDefault(env.OM_MIGRATION_REINDEX, true)\n}\n\nexport function resolveMigrationFilePath(\n migrationsPath: string,\n migrationName: string,\n knownPath?: string | null,\n fileExists: (filePath: string) => boolean = fs.existsSync,\n): string | null {\n if (knownPath && fileExists(knownPath)) return knownPath\n const stem = path.basename(migrationName).replace(/\\.(ts|js|mjs|cjs)$/i, '')\n if (!stem || !MIGRATION_FILE_NAME_PATTERN.test(stem)) return null\n for (const extension of MIGRATION_EXTENSIONS) {\n const candidate = path.join(migrationsPath, `${stem}${extension}`)\n if (fileExists(candidate)) return candidate\n }\n return null\n}\n\nexport async function collectQueryIndexReindexEntityTypes(\n applied: readonly AppliedMigration[],\n deps: MigrationReindexDeps,\n): Promise<string[]> {\n const fileExists = deps.fileExists ?? fs.existsSync\n const collected: string[] = []\n for (const migration of applied) {\n const filePath = resolveMigrationFilePath(\n migration.migrationsPath,\n migration.name,\n migration.filePath,\n fileExists,\n )\n if (!filePath) continue\n let moduleExports: unknown\n try {\n moduleExports = await deps.importModule(pathToFileURL(path.resolve(filePath)).href)\n } catch (error) {\n deps.onWarn?.(\n `[query_index] Could not read reindex declarations from ${migration.moduleId}/${migration.name}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n continue\n }\n const declared = readQueryIndexReindexDeclaration(moduleExports, (rejected: unknown) => {\n deps.onWarn?.(\n `[query_index] Ignoring an invalid reindex declaration in ${migration.moduleId}/${migration.name}: ${\n JSON.stringify(rejected) ?? String(rejected)\n } is not a \"module:entity\" identifier, so its projection will NOT be rebuilt.`,\n )\n })\n for (const entityType of declared) {\n if (!collected.includes(entityType)) collected.push(entityType)\n }\n }\n return collected\n}\n\nexport function formatManualReindexInstructions(entityTypes: readonly string[]): string {\n const commands = formatQueryIndexRebuildCommands(entityTypes)\n .map((command) => ` ${command}`)\n .join('\\n')\n return [\n '[query_index] Could not queue the reindex requested by the migrations that just ran.',\n ' Their query-index projections still hold pre-migration values until you run:',\n commands,\n ].join('\\n')\n}\n\nexport type QueryIndexReindexEmitter = {\n emitEvent: (event: string, payload: Record<string, unknown>, options?: { persistent?: boolean }) => Promise<void>\n}\n\nexport type QueryIndexReindexContainer = {\n resolve: (name: string) => unknown\n dispose?: () => Promise<void> | void\n}\n\nexport type RequestQueryIndexReindexDeps = {\n createContainer: () => Promise<QueryIndexReindexContainer>\n onInfo?: (message: string) => void\n onWarn?: (message: string) => void\n}\n\n/**\n * Queued rather than executed inline: a rebuild of a large entity type must not hold up a\n * deploy's migration step. `force` stays false so the existing `query_index.reindex`\n * subscriber upserts in place \u2014 a forced run purges the entity's rows first, which would\n * leave the projection empty for the duration of the rebuild.\n */\nexport async function requestQueryIndexReindex(\n entityTypes: readonly string[],\n deps: RequestQueryIndexReindexDeps,\n): Promise<{ requested: string[]; queued: boolean }> {\n if (!entityTypes.length) return { requested: [], queued: false }\n\n let container: QueryIndexReindexContainer | null = null\n const queued: string[] = []\n try {\n container = await deps.createContainer()\n const eventBus = container.resolve('eventBus') as QueryIndexReindexEmitter\n for (const entityType of entityTypes) {\n await eventBus.emitEvent(\n 'query_index.reindex',\n { entityType, allowAllTenants: true, force: false },\n { persistent: true },\n )\n queued.push(entityType)\n }\n deps.onInfo?.(\n `[query_index] Queued a reindex for ${queued.length} entity type(s) touched by data migrations: ${queued.join(', ')}`,\n )\n return { requested: queued, queued: true }\n } catch (error) {\n const unqueued = entityTypes.filter((entityType) => !queued.includes(entityType))\n deps.onWarn?.(\n `${formatManualReindexInstructions(unqueued)}\\n Reason: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n return { requested: queued, queued: false }\n } finally {\n if (container && typeof container.dispose === 'function') {\n try {\n await container.dispose()\n } catch {\n // A container that fails to dispose must not turn a successful migration into a failure.\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AACxC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,8BAA8B;AACpC,MAAM,uBAAuB,CAAC,OAAO,OAAO,QAAQ,MAAM;AAenD,SAAS,0BAA0B,MAAyB,QAAQ,KAAc;AACvF,SAAO,wBAAwB,IAAI,sBAAsB,IAAI;AAC/D;AAEO,SAAS,yBACd,gBACA,eACA,WACA,aAA4C,GAAG,YAChC;AACf,MAAI,aAAa,WAAW,SAAS,EAAG,QAAO;AAC/C,QAAM,OAAO,KAAK,SAAS,aAAa,EAAE,QAAQ,uBAAuB,EAAE;AAC3E,MAAI,CAAC,QAAQ,CAAC,4BAA4B,KAAK,IAAI,EAAG,QAAO;AAC7D,aAAW,aAAa,sBAAsB;AAC5C,UAAM,YAAY,KAAK,KAAK,gBAAgB,GAAG,IAAI,GAAG,SAAS,EAAE;AACjE,QAAI,WAAW,SAAS,EAAG,QAAO;AAAA,EACpC;AACA,SAAO;AACT;AAEA,eAAsB,oCACpB,SACA,MACmB;AACnB,QAAM,aAAa,KAAK,cAAc,GAAG;AACzC,QAAM,YAAsB,CAAC;AAC7B,aAAW,aAAa,SAAS;AAC/B,UAAM,WAAW;AAAA,MACf,UAAU;AAAA,MACV,UAAU;AAAA,MACV,UAAU;AAAA,MACV;AAAA,IACF;AACA,QAAI,CAAC,SAAU;AACf,QAAI;AACJ,QAAI;AACF,sBAAgB,MAAM,KAAK,aAAa,cAAc,KAAK,QAAQ,QAAQ,CAAC,EAAE,IAAI;AAAA,IACpF,SAAS,OAAO;AACd,WAAK;AAAA,QACH,0DAA0D,UAAU,QAAQ,IAAI,UAAU,IAAI,KAC5F,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;AAAA,MACF;AACA;AAAA,IACF;AACA,UAAM,WAAW,iCAAiC,eAAe,CAAC,aAAsB;AACtF,WAAK;AAAA,QACH,4DAA4D,UAAU,QAAQ,IAAI,UAAU,IAAI,KAC9F,KAAK,UAAU,QAAQ,KAAK,OAAO,QAAQ,CAC7C;AAAA,MACF;AAAA,IACF,CAAC;AACD,eAAW,cAAc,UAAU;AACjC,UAAI,CAAC,UAAU,SAAS,UAAU,EAAG,WAAU,KAAK,UAAU;AAAA,IAChE;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,gCAAgC,aAAwC;AACtF,QAAM,WAAW,gCAAgC,WAAW,EACzD,IAAI,CAAC,YAAY,QAAQ,OAAO,EAAE,EAClC,KAAK,IAAI;AACZ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAE,KAAK,IAAI;AACb;AAuBA,eAAsB,yBACpB,aACA,MACmD;AACnD,MAAI,CAAC,YAAY,OAAQ,QAAO,EAAE,WAAW,CAAC,GAAG,QAAQ,MAAM;AAE/D,MAAI,YAA+C;AACnD,QAAM,SAAmB,CAAC;AAC1B,MAAI;AACF,gBAAY,MAAM,KAAK,gBAAgB;AACvC,UAAM,WAAW,UAAU,QAAQ,UAAU;AAC7C,eAAW,cAAc,aAAa;AACpC,YAAM,SAAS;AAAA,QACb;AAAA,QACA,EAAE,YAAY,iBAAiB,MAAM,OAAO,MAAM;AAAA,QAClD,EAAE,YAAY,KAAK;AAAA,
|
|
4
|
+
"sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { parseBooleanWithDefault } from '@open-mercato/shared/lib/boolean'\nimport {\n formatQueryIndexRebuildCommands,\n readQueryIndexReindexDeclaration,\n} from '@open-mercato/shared/lib/query/migration-reindex'\n\nconst MIGRATION_FILE_NAME_PATTERN = /^[A-Za-z0-9._-]+$/\nconst MIGRATION_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs']\n\nexport type AppliedMigration = {\n moduleId: string\n migrationsPath: string\n name: string\n filePath?: string | null\n}\n\nexport type MigrationReindexDeps = {\n importModule: (filePath: string) => Promise<unknown>\n fileExists?: (filePath: string) => boolean\n onWarn?: (message: string) => void\n}\n\nexport function isMigrationReindexEnabled(env: NodeJS.ProcessEnv = process.env): boolean {\n return parseBooleanWithDefault(env.OM_MIGRATION_REINDEX, true)\n}\n\nexport function resolveMigrationFilePath(\n migrationsPath: string,\n migrationName: string,\n knownPath?: string | null,\n fileExists: (filePath: string) => boolean = fs.existsSync,\n): string | null {\n if (knownPath && fileExists(knownPath)) return knownPath\n const stem = path.basename(migrationName).replace(/\\.(ts|js|mjs|cjs)$/i, '')\n if (!stem || !MIGRATION_FILE_NAME_PATTERN.test(stem)) return null\n for (const extension of MIGRATION_EXTENSIONS) {\n const candidate = path.join(migrationsPath, `${stem}${extension}`)\n if (fileExists(candidate)) return candidate\n }\n return null\n}\n\nexport async function collectQueryIndexReindexEntityTypes(\n applied: readonly AppliedMigration[],\n deps: MigrationReindexDeps,\n): Promise<string[]> {\n const fileExists = deps.fileExists ?? fs.existsSync\n const collected: string[] = []\n for (const migration of applied) {\n const filePath = resolveMigrationFilePath(\n migration.migrationsPath,\n migration.name,\n migration.filePath,\n fileExists,\n )\n if (!filePath) continue\n let moduleExports: unknown\n try {\n moduleExports = await deps.importModule(pathToFileURL(path.resolve(filePath)).href)\n } catch (error) {\n deps.onWarn?.(\n `[query_index] Could not read reindex declarations from ${migration.moduleId}/${migration.name}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n continue\n }\n const declared = readQueryIndexReindexDeclaration(moduleExports, (rejected: unknown) => {\n deps.onWarn?.(\n `[query_index] Ignoring an invalid reindex declaration in ${migration.moduleId}/${migration.name}: ${\n JSON.stringify(rejected) ?? String(rejected)\n } is not a \"module:entity\" identifier, so its projection will NOT be rebuilt.`,\n )\n })\n for (const entityType of declared) {\n if (!collected.includes(entityType)) collected.push(entityType)\n }\n }\n return collected\n}\n\nexport function formatManualReindexInstructions(entityTypes: readonly string[]): string {\n const commands = formatQueryIndexRebuildCommands(entityTypes)\n .map((command) => ` ${command}`)\n .join('\\n')\n return [\n '[query_index] Could not queue the reindex requested by the migrations that just ran.',\n ' Their query-index projections still hold pre-migration values until you run:',\n commands,\n ].join('\\n')\n}\n\nexport type QueryIndexReindexEmitter = {\n emitEvent: (event: string, payload: Record<string, unknown>, options?: { persistent?: boolean; tenantId?: string | null; allowAllTenants?: boolean }) => Promise<void>\n}\n\nexport type QueryIndexReindexContainer = {\n resolve: (name: string) => unknown\n dispose?: () => Promise<void> | void\n}\n\nexport type RequestQueryIndexReindexDeps = {\n createContainer: () => Promise<QueryIndexReindexContainer>\n onInfo?: (message: string) => void\n onWarn?: (message: string) => void\n}\n\n/**\n * Queued rather than executed inline: a rebuild of a large entity type must not hold up a\n * deploy's migration step. `force` stays false so the existing `query_index.reindex`\n * subscriber upserts in place \u2014 a forced run purges the entity's rows first, which would\n * leave the projection empty for the duration of the rebuild.\n */\nexport async function requestQueryIndexReindex(\n entityTypes: readonly string[],\n deps: RequestQueryIndexReindexDeps,\n): Promise<{ requested: string[]; queued: boolean }> {\n if (!entityTypes.length) return { requested: [], queued: false }\n\n let container: QueryIndexReindexContainer | null = null\n const queued: string[] = []\n try {\n container = await deps.createContainer()\n const eventBus = container.resolve('eventBus') as QueryIndexReindexEmitter\n for (const entityType of entityTypes) {\n await eventBus.emitEvent(\n 'query_index.reindex',\n { entityType, allowAllTenants: true, force: false },\n { persistent: true, tenantId: null, allowAllTenants: true },\n )\n queued.push(entityType)\n }\n deps.onInfo?.(\n `[query_index] Queued a reindex for ${queued.length} entity type(s) touched by data migrations: ${queued.join(', ')}`,\n )\n return { requested: queued, queued: true }\n } catch (error) {\n const unqueued = entityTypes.filter((entityType) => !queued.includes(entityType))\n deps.onWarn?.(\n `${formatManualReindexInstructions(unqueued)}\\n Reason: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n return { requested: queued, queued: false }\n } finally {\n if (container && typeof container.dispose === 'function') {\n try {\n await container.dispose()\n } catch {\n // A container that fails to dispose must not turn a successful migration into a failure.\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { runWithKmsWarningWriter } from "@open-mercato/shared/lib/encryption/kms-warning-presentation";
|
|
2
|
+
function runWithRotationKmsWarningPresentation(argv, operation) {
|
|
3
|
+
if (argv[2] !== "entities" || argv[3] !== "rotate-encryption-key") return operation();
|
|
4
|
+
return runWithKmsWarningWriter((lines) => {
|
|
5
|
+
if (process.env.OM_ROTATION_PROGRESS !== "json") return false;
|
|
6
|
+
process.stderr.write(JSON.stringify({ schemaVersion: 1, type: "phase.changed", runId: "rotation", phase: "rotation.kms.warning", entity: lines.map((line) => line.replace(/^\s*🚨\uFE0F?\s*/u, "")).join("\n"), rowsDone: "0", rowsTotal: "0", rowsTotalExact: false, bytesDone: "0", chunksDone: 0, at: (/* @__PURE__ */ new Date()).toISOString() }) + "\n");
|
|
7
|
+
}, operation);
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
runWithRotationKmsWarningPresentation
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=rotation-kms-warning-presentation.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/rotation-kms-warning-presentation.ts"],
|
|
4
|
+
"sourcesContent": ["import { runWithKmsWarningWriter } from '@open-mercato/shared/lib/encryption/kms-warning-presentation'\n\n/** Establish presentation before app env loading and bootstrap can activate KMS. */\nexport function runWithRotationKmsWarningPresentation<T>(argv: readonly string[], operation: () => T): T {\n if (argv[2] !== 'entities' || argv[3] !== 'rotate-encryption-key') return operation()\n return runWithKmsWarningWriter(lines => {\n // App env may be loaded inside operation; do not decide from entry-time env.\n if (process.env.OM_ROTATION_PROGRESS !== 'json') return false\n process.stderr.write(JSON.stringify({ schemaVersion: 1, type: 'phase.changed', runId: 'rotation', phase: 'rotation.kms.warning', entity: lines.map(line => line.replace(/^\\s*\uD83D\uDEA8\\uFE0F?\\s*/u, '')).join('\\n'), rowsDone: '0', rowsTotal: '0', rowsTotalExact: false, bytesDone: '0', chunksDone: 0, at: new Date().toISOString() }) + '\\n')\n }, operation)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,+BAA+B;AAGjC,SAAS,sCAAyC,MAAyB,WAAuB;AACvG,MAAI,KAAK,CAAC,MAAM,cAAc,KAAK,CAAC,MAAM,wBAAyB,QAAO,UAAU;AACpF,SAAO,wBAAwB,WAAS;AAEtC,QAAI,QAAQ,IAAI,yBAAyB,OAAQ,QAAO;AACxD,YAAQ,OAAO,MAAM,KAAK,UAAU,EAAE,eAAe,GAAG,MAAM,iBAAiB,OAAO,YAAY,OAAO,wBAAwB,QAAQ,MAAM,IAAI,UAAQ,KAAK,QAAQ,qBAAqB,EAAE,CAAC,EAAE,KAAK,IAAI,GAAG,UAAU,KAAK,WAAW,KAAK,gBAAgB,OAAO,WAAW,KAAK,YAAY,GAAG,KAAI,oBAAI,KAAK,GAAE,YAAY,EAAE,CAAC,IAAI,IAAI;AAAA,EAC3U,GAAG,SAAS;AACd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/cli",
|
|
3
|
-
"version": "0.11.1-develop.
|
|
3
|
+
"version": "0.11.1-develop.8572.1.85986dc508",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"@mikro-orm/decorators": "^7.1.14",
|
|
61
61
|
"@mikro-orm/migrations": "^7.1.14",
|
|
62
62
|
"@mikro-orm/postgresql": "^7.1.14",
|
|
63
|
-
"@open-mercato/events": "0.11.1-develop.
|
|
64
|
-
"@open-mercato/queue": "0.11.1-develop.
|
|
65
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
66
|
-
"@open-mercato/telemetry": "0.11.1-develop.
|
|
63
|
+
"@open-mercato/events": "0.11.1-develop.8572.1.85986dc508",
|
|
64
|
+
"@open-mercato/queue": "0.11.1-develop.8572.1.85986dc508",
|
|
65
|
+
"@open-mercato/shared": "0.11.1-develop.8572.1.85986dc508",
|
|
66
|
+
"@open-mercato/telemetry": "0.11.1-develop.8572.1.85986dc508",
|
|
67
67
|
"cross-spawn": "^7.0.6",
|
|
68
68
|
"minisearch": "7.2.0",
|
|
69
69
|
"pg": "8.23.0",
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
"typescript-js": "npm:typescript@6.0.3"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
78
|
+
"@open-mercato/shared": "0.11.1-develop.8572.1.85986dc508"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
81
|
+
"@open-mercato/shared": "0.11.1-develop.8572.1.85986dc508",
|
|
82
82
|
"@types/jest": "^30.0.0",
|
|
83
83
|
"jest": "^30.4.2",
|
|
84
84
|
"ts-jest": "^29.4.12"
|
|
@@ -661,6 +661,29 @@ describe('--help never triggers side effects (issue #5581)', () => {
|
|
|
661
661
|
consoleErrorSpy.mockRestore()
|
|
662
662
|
})
|
|
663
663
|
|
|
664
|
+
it('prints usage instead of executing configs restore-defaults when --help is passed', async () => {
|
|
665
|
+
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
|
|
666
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
667
|
+
const restoreDefaults = jest.fn()
|
|
668
|
+
|
|
669
|
+
registerCliModules([
|
|
670
|
+
{
|
|
671
|
+
id: 'configs',
|
|
672
|
+
cli: [{ command: 'restore-defaults', run: restoreDefaults }],
|
|
673
|
+
} as any,
|
|
674
|
+
])
|
|
675
|
+
|
|
676
|
+
const exitCode = await run(['node', 'mercato', 'configs', 'restore-defaults', '--help'])
|
|
677
|
+
|
|
678
|
+
expect(exitCode).toBe(0)
|
|
679
|
+
expect(restoreDefaults).not.toHaveBeenCalled()
|
|
680
|
+
const printed = consoleLogSpy.mock.calls.map((call) => String(call[0])).join('\n')
|
|
681
|
+
expect(printed).toContain('mercato configs restore-defaults [args]')
|
|
682
|
+
|
|
683
|
+
consoleLogSpy.mockRestore()
|
|
684
|
+
consoleErrorSpy.mockRestore()
|
|
685
|
+
})
|
|
686
|
+
|
|
664
687
|
it('still runs the command when no help flag is present', async () => {
|
|
665
688
|
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
|
|
666
689
|
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
@@ -1180,12 +1203,94 @@ describe('init command failure output', () => {
|
|
|
1180
1203
|
)
|
|
1181
1204
|
expect(configsRestoreDefaults).toHaveBeenCalledTimes(expectedRestoreCount)
|
|
1182
1205
|
expect(authSetup).toHaveBeenCalled()
|
|
1206
|
+
if (configsEnabled) {
|
|
1207
|
+
expect(configsRestoreDefaults.mock.invocationCallOrder[0]).toBeLessThan(
|
|
1208
|
+
authSetup.mock.invocationCallOrder[0],
|
|
1209
|
+
)
|
|
1210
|
+
}
|
|
1183
1211
|
expect(queryIndexReindex).toHaveBeenCalledWith(['--force', '--tenant', 'tenant-1'])
|
|
1184
1212
|
|
|
1185
1213
|
consoleErrorSpy.mockRestore()
|
|
1186
1214
|
consoleLogSpy.mockRestore()
|
|
1187
1215
|
})
|
|
1188
1216
|
|
|
1217
|
+
it('aborts init with nonzero exit and never runs auth setup when configs restore-defaults fails', async () => {
|
|
1218
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
1219
|
+
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
|
|
1220
|
+
|
|
1221
|
+
const configsRestoreDefaults = jest.fn().mockRejectedValue(new Error('strict restore rollback'))
|
|
1222
|
+
const authSetup = jest.fn().mockResolvedValue(undefined)
|
|
1223
|
+
const authSeedRoles = jest.fn().mockResolvedValue(undefined)
|
|
1224
|
+
const entitiesSeedEncryption = jest.fn().mockResolvedValue(undefined)
|
|
1225
|
+
const queryIndexReindex = jest.fn().mockResolvedValue(undefined)
|
|
1226
|
+
|
|
1227
|
+
jest.doMock('child_process', () => ({
|
|
1228
|
+
execSync: jest.fn(),
|
|
1229
|
+
}))
|
|
1230
|
+
jest.doMock('pg', () => ({
|
|
1231
|
+
Client: jest.fn().mockImplementation(() => ({
|
|
1232
|
+
connect: jest.fn().mockResolvedValue(undefined),
|
|
1233
|
+
query: jest.fn().mockResolvedValue({ rows: [] }),
|
|
1234
|
+
end: jest.fn().mockResolvedValue(undefined),
|
|
1235
|
+
})),
|
|
1236
|
+
}))
|
|
1237
|
+
jest.doMock('../lib/generators', () => ({
|
|
1238
|
+
generateEntityIds: jest.fn().mockResolvedValue(undefined),
|
|
1239
|
+
generateModuleRegistries: jest.fn().mockResolvedValue(undefined),
|
|
1240
|
+
generateModuleEntities: jest.fn().mockResolvedValue(undefined),
|
|
1241
|
+
generateModuleDi: jest.fn().mockResolvedValue(undefined),
|
|
1242
|
+
generateModulePackageSources: jest.fn().mockResolvedValue(undefined),
|
|
1243
|
+
generateWebResearchAdapters: jest.fn().mockResolvedValue(undefined),
|
|
1244
|
+
generateOpenApi: jest.fn().mockResolvedValue(undefined),
|
|
1245
|
+
}))
|
|
1246
|
+
jest.doMock('../lib/db', () => ({
|
|
1247
|
+
dbMigrate: jest.fn().mockResolvedValue(undefined),
|
|
1248
|
+
}))
|
|
1249
|
+
jest.doMock('../lib/resolver', () => ({
|
|
1250
|
+
createResolver: () => ({
|
|
1251
|
+
getAppDir: () => '/tmp/test-app',
|
|
1252
|
+
}),
|
|
1253
|
+
}))
|
|
1254
|
+
jest.doMock('@open-mercato/shared/lib/bootstrap/dynamicLoader', () => ({
|
|
1255
|
+
bootstrapFromAppRoot: jest.fn().mockResolvedValue({
|
|
1256
|
+
modules: [
|
|
1257
|
+
{
|
|
1258
|
+
id: 'configs',
|
|
1259
|
+
cli: [{ command: 'restore-defaults', run: configsRestoreDefaults }],
|
|
1260
|
+
},
|
|
1261
|
+
{
|
|
1262
|
+
id: 'auth',
|
|
1263
|
+
cli: [
|
|
1264
|
+
{ command: 'setup', run: authSetup },
|
|
1265
|
+
{ command: 'seed-roles', run: authSeedRoles },
|
|
1266
|
+
],
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
id: 'entities',
|
|
1270
|
+
cli: [{ command: 'seed-encryption', run: entitiesSeedEncryption }],
|
|
1271
|
+
},
|
|
1272
|
+
{
|
|
1273
|
+
id: 'query_index',
|
|
1274
|
+
cli: [{ command: 'reindex', run: queryIndexReindex }],
|
|
1275
|
+
},
|
|
1276
|
+
],
|
|
1277
|
+
}),
|
|
1278
|
+
}))
|
|
1279
|
+
|
|
1280
|
+
const mercato = await import('../mercato')
|
|
1281
|
+
const exitCode = await mercato.run(['node', 'mercato', 'init'])
|
|
1282
|
+
|
|
1283
|
+
expect(exitCode).toBe(1)
|
|
1284
|
+
expect(configsRestoreDefaults).toHaveBeenCalledTimes(1)
|
|
1285
|
+
expect(authSetup).not.toHaveBeenCalled()
|
|
1286
|
+
expect(authSeedRoles).not.toHaveBeenCalled()
|
|
1287
|
+
expect(entitiesSeedEncryption).not.toHaveBeenCalled()
|
|
1288
|
+
expect(queryIndexReindex).not.toHaveBeenCalled()
|
|
1289
|
+
|
|
1290
|
+
consoleErrorSpy.mockRestore()
|
|
1291
|
+
consoleLogSpy.mockRestore()
|
|
1292
|
+
})
|
|
1293
|
+
|
|
1189
1294
|
function mockInitDependencies({
|
|
1190
1295
|
authSetup,
|
|
1191
1296
|
}: {
|
package/src/bin.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/ru
|
|
|
8
8
|
import { installNextSubpathResolveHook } from '@open-mercato/shared/lib/bootstrap/next-subpath-resolve-hook'
|
|
9
9
|
import { resolveCliBootstrapMode, type CliBootstrapMode } from './lib/cli-bootstrap-mode.js'
|
|
10
10
|
import { flushBeforeExit } from './lib/flush-before-exit.js'
|
|
11
|
+
import { runWithRotationKmsWarningPresentation } from './lib/rotation-kms-warning-presentation.js'
|
|
11
12
|
// `run` is imported dynamically inside `main()` so telemetry can initialize
|
|
12
13
|
// before the mercato entry (and its Postgres driver) loads — see main().
|
|
13
14
|
|
|
@@ -125,7 +126,7 @@ async function main(): Promise<void> {
|
|
|
125
126
|
process.exit(code ?? 0)
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
main
|
|
129
|
+
runWithRotationKmsWarningPresentation(process.argv, main).catch((error: unknown) => {
|
|
129
130
|
if (error instanceof Error) {
|
|
130
131
|
console.error(error.message)
|
|
131
132
|
} else {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { runWithRotationKmsWarningPresentation } from '../rotation-kms-warning-presentation'
|
|
2
|
+
import { writeKmsWarning } from '@open-mercato/shared/lib/encryption/kms-warning-presentation'
|
|
3
|
+
const originalEnv = { ...process.env }
|
|
4
|
+
afterEach(() => { process.env = { ...originalEnv }; jest.restoreAllMocks() })
|
|
5
|
+
|
|
6
|
+
test('exact rotation route captures warnings before bootstrap and after environment loads inside main', async () => {
|
|
7
|
+
delete process.env.OM_ROTATION_PROGRESS
|
|
8
|
+
process.env.NO_COLOR = ''
|
|
9
|
+
const output = jest.spyOn(process.stderr, 'write').mockReturnValue(true)
|
|
10
|
+
await runWithRotationKmsWarningPresentation(['node', 'mercato', 'entities', 'rotate-encryption-key'], async () => {
|
|
11
|
+
writeKmsWarning(['normal before env'])
|
|
12
|
+
process.env.OM_ROTATION_PROGRESS = 'json'
|
|
13
|
+
writeKmsWarning(['🚨 bootstrap warning', 'Retain the previous root', 'Source: EXPLICIT_SETTING'])
|
|
14
|
+
await Promise.resolve()
|
|
15
|
+
writeKmsWarning(['handler warning'])
|
|
16
|
+
})
|
|
17
|
+
expect(output.mock.calls[0][0]).toBe('normal before env\n')
|
|
18
|
+
for (const [chunk] of output.mock.calls.slice(1)) expect(JSON.parse(String(chunk))).toMatchObject({ schemaVersion: 1, type: 'phase.changed', runId: 'rotation', phase: 'rotation.kms.warning', rowsDone: '0', rowsTotal: '0', rowsTotalExact: false, bytesDone: '0', chunksDone: 0, at: expect.any(String) })
|
|
19
|
+
expect(JSON.parse(String(output.mock.calls[1][0])).entity).toBe('bootstrap warning\nRetain the previous root\nSource: EXPLICIT_SETTING')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test.each([
|
|
23
|
+
['entities', 'rotate-encryption-key-extra'], ['other', 'rotate-encryption-key'], ['entities', 'list'],
|
|
24
|
+
])('unrelated route %s %s retains normal warning even with JSON rotation env', (module, command) => {
|
|
25
|
+
process.env.OM_ROTATION_PROGRESS = 'json'; process.env.NO_COLOR = ''
|
|
26
|
+
const output = jest.spyOn(process.stderr, 'write').mockReturnValue(true)
|
|
27
|
+
runWithRotationKmsWarningPresentation(['node', 'mercato', module, command], () => writeKmsWarning(['visible normal warning']))
|
|
28
|
+
expect(output).toHaveBeenCalledWith('visible normal warning\n')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// Execute the actual bin entry with a synthetic bootstrap graph, without an app,
|
|
32
|
+
// credentials, driver or network. Warnings fire during env load and bootstrap,
|
|
33
|
+
// before the command handler, so wrapping only run() cannot satisfy this test.
|
|
34
|
+
test.each([['entities', 'rotate-encryption-key', true], ['entities', 'list', false]])('actual bin scopes %s/%s before environment loading and bootstrap', async (module, command, structured) => {
|
|
35
|
+
const fs = await import('node:fs/promises')
|
|
36
|
+
const os = await import('node:os')
|
|
37
|
+
const path = await import('node:path')
|
|
38
|
+
const { spawnSync } = await import('node:child_process')
|
|
39
|
+
const { build } = await import('esbuild')
|
|
40
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'om-bin-kms-warning-'))
|
|
41
|
+
try {
|
|
42
|
+
const warningImport = "import { writeKmsWarning } from '@open-mercato/shared/lib/encryption/kms-warning-presentation';"
|
|
43
|
+
const fixtures: Record<string, string> = {
|
|
44
|
+
'@open-mercato/telemetry': 'export const initTelemetry = async () => {}',
|
|
45
|
+
'./lib/dev-supervisor-manifest.js': 'export const canUseLightweightDevSupervisor=()=>false; export const loadDevSupervisorManifest=()=>null; export const registerDevSupervisorManifest=()=>{}',
|
|
46
|
+
'@open-mercato/shared/lib/telemetry/runtime': 'export const isTelemetryBackendEnabled = () => false',
|
|
47
|
+
'@open-mercato/shared/lib/bootstrap/next-subpath-resolve-hook': 'export const installNextSubpathResolveHook = () => {}',
|
|
48
|
+
'./lib/cli-bootstrap-mode.js': "export const resolveCliBootstrapMode = () => 'full'",
|
|
49
|
+
'./lib/flush-before-exit.js': 'export const flushBeforeExit = async () => {}',
|
|
50
|
+
'./lib/resolver.js': 'export const createResolver = () => ({getAppDir: () => "/fixture-app"})',
|
|
51
|
+
'./lib/load-env.js': warningImport + 'export const loadAppEnv = async () => { process.env.OM_ROTATION_PROGRESS="json"; writeKmsWarning(["environment custody warning"]) }',
|
|
52
|
+
'@open-mercato/shared/lib/bootstrap/dynamicLoader': warningImport + 'export const bootstrapFromAppRoot = async () => { writeKmsWarning(["bootstrap custody warning"]); return {modules:[]} }',
|
|
53
|
+
'./mercato.js': warningImport + 'export const registerCliModules = () => {}; export const run = async () => { writeKmsWarning(["handler custody warning"]); return 0 }',
|
|
54
|
+
}
|
|
55
|
+
const output = path.join(directory, 'bin.mjs')
|
|
56
|
+
await build({ entryPoints: [path.resolve(__dirname, '../../bin.ts')], outfile: output, bundle: true, platform: 'node', format: 'esm', logLevel: 'silent', plugins: [{
|
|
57
|
+
name: 'fixture-bootstrap', setup(builder) {
|
|
58
|
+
builder.onResolve({ filter: /.*/ }, args => {
|
|
59
|
+
if (args.path in fixtures) return { path: args.path, namespace: 'fixture' }
|
|
60
|
+
if (args.path === '@open-mercato/shared/lib/encryption/kms-warning-presentation') return { path: path.resolve(__dirname, '../../../../shared/src/lib/encryption/kms-warning-presentation.ts') }
|
|
61
|
+
return undefined
|
|
62
|
+
})
|
|
63
|
+
builder.onLoad({ filter: /.*/, namespace: 'fixture' }, args => ({ contents: fixtures[args.path], loader: 'js' }))
|
|
64
|
+
},
|
|
65
|
+
}] })
|
|
66
|
+
const env = { ...process.env, NO_COLOR: '' }; delete env.OM_ROTATION_PROGRESS
|
|
67
|
+
const child = spawnSync(process.execPath, [output, module, command], { env, encoding: 'utf8' })
|
|
68
|
+
expect(child.status).toBe(0); expect(child.stdout).toBe('')
|
|
69
|
+
const lines = child.stderr.trim().split('\n')
|
|
70
|
+
if (structured) expect(lines.map(line => JSON.parse(line))).toEqual(['environment custody warning', 'bootstrap custody warning', 'handler custody warning'].map(entity => expect.objectContaining({ schemaVersion: 1, type: 'phase.changed', phase: 'rotation.kms.warning', entity })))
|
|
71
|
+
else expect(lines).toEqual(['environment custody warning', 'bootstrap custody warning', 'handler custody warning'])
|
|
72
|
+
} finally { await fs.rm(directory, { recursive: true, force: true }) }
|
|
73
|
+
})
|
|
@@ -193,7 +193,7 @@ describe('requestQueryIndexReindex', () => {
|
|
|
193
193
|
1,
|
|
194
194
|
'query_index.reindex',
|
|
195
195
|
{ entityType: 'customers:customer_dictionary_entry', allowAllTenants: true, force: false },
|
|
196
|
-
{ persistent: true },
|
|
196
|
+
{ persistent: true, tenantId: null, allowAllTenants: true },
|
|
197
197
|
)
|
|
198
198
|
expect(dispose).toHaveBeenCalled()
|
|
199
199
|
})
|
|
@@ -94,7 +94,7 @@ export function formatManualReindexInstructions(entityTypes: readonly string[]):
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export type QueryIndexReindexEmitter = {
|
|
97
|
-
emitEvent: (event: string, payload: Record<string, unknown>, options?: { persistent?: boolean }) => Promise<void>
|
|
97
|
+
emitEvent: (event: string, payload: Record<string, unknown>, options?: { persistent?: boolean; tenantId?: string | null; allowAllTenants?: boolean }) => Promise<void>
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
export type QueryIndexReindexContainer = {
|
|
@@ -129,7 +129,7 @@ export async function requestQueryIndexReindex(
|
|
|
129
129
|
await eventBus.emitEvent(
|
|
130
130
|
'query_index.reindex',
|
|
131
131
|
{ entityType, allowAllTenants: true, force: false },
|
|
132
|
-
{ persistent: true },
|
|
132
|
+
{ persistent: true, tenantId: null, allowAllTenants: true },
|
|
133
133
|
)
|
|
134
134
|
queued.push(entityType)
|
|
135
135
|
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import type { ModuleEntry, PackageResolver } from '../../resolver'
|
|
5
|
+
import {
|
|
6
|
+
generateModuleRegistry,
|
|
7
|
+
generateModuleRegistryApp,
|
|
8
|
+
generateModuleRegistryCli,
|
|
9
|
+
} from '../module-registry'
|
|
10
|
+
|
|
11
|
+
let fileMtimeNonce = 0
|
|
12
|
+
|
|
13
|
+
function touchFile(filePath: string, content = ''): void {
|
|
14
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true })
|
|
15
|
+
fs.writeFileSync(filePath, content)
|
|
16
|
+
const mtime = new Date(Date.now() + fileMtimeNonce)
|
|
17
|
+
fileMtimeNonce += 1
|
|
18
|
+
fs.utimesSync(filePath, mtime, mtime)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createMonorepoResolver(tmpDir: string, enabled: ModuleEntry[]): PackageResolver {
|
|
22
|
+
const outputDir = path.join(tmpDir, 'output', 'generated')
|
|
23
|
+
fs.mkdirSync(outputDir, { recursive: true })
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
isMonorepo: () => true,
|
|
27
|
+
getRootDir: () => tmpDir,
|
|
28
|
+
getAppDir: () => path.join(tmpDir, 'app'),
|
|
29
|
+
getOutputDir: () => outputDir,
|
|
30
|
+
getModulesConfigPath: () => path.join(tmpDir, 'app', 'src', 'modules.ts'),
|
|
31
|
+
discoverPackages: () => [],
|
|
32
|
+
loadEnabledModules: () => enabled,
|
|
33
|
+
getModulePaths: (entry: ModuleEntry) => {
|
|
34
|
+
const pkgDir = entry.from === '@open-mercato/search' ? 'search' : 'core'
|
|
35
|
+
return {
|
|
36
|
+
appBase: path.join(tmpDir, 'app', 'src', 'modules', entry.id),
|
|
37
|
+
pkgBase: path.join(tmpDir, 'packages', pkgDir, 'src', 'modules', entry.id),
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
getModuleImportBase: (entry: ModuleEntry) => ({
|
|
41
|
+
appBase: `@/modules/${entry.id}`,
|
|
42
|
+
pkgBase: `${entry.from ?? '@open-mercato/core'}/modules/${entry.id}`,
|
|
43
|
+
}),
|
|
44
|
+
getPackageOutputDir: () => outputDir,
|
|
45
|
+
getPackageRoot: () => path.join(tmpDir, 'packages', 'core'),
|
|
46
|
+
} as unknown as PackageResolver
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function createStandalonePackedResolver(tmpDir: string, enabled: ModuleEntry[]): PackageResolver {
|
|
50
|
+
const outputDir = path.join(tmpDir, '.mercato', 'generated')
|
|
51
|
+
fs.mkdirSync(outputDir, { recursive: true })
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
isMonorepo: () => false,
|
|
55
|
+
getRootDir: () => tmpDir,
|
|
56
|
+
getAppDir: () => tmpDir,
|
|
57
|
+
getOutputDir: () => outputDir,
|
|
58
|
+
getModulesConfigPath: () => path.join(tmpDir, 'src', 'modules.ts'),
|
|
59
|
+
discoverPackages: () => [],
|
|
60
|
+
loadEnabledModules: () => enabled,
|
|
61
|
+
getModulePaths: (entry: ModuleEntry) => ({
|
|
62
|
+
appBase: path.join(tmpDir, 'src', 'modules', entry.id),
|
|
63
|
+
pkgBase: path.join(tmpDir, 'node_modules', entry.from ?? '@open-mercato/core', 'dist', 'modules', entry.id),
|
|
64
|
+
}),
|
|
65
|
+
getModuleImportBase: (entry: ModuleEntry) => ({
|
|
66
|
+
appBase: `@/modules/${entry.id}`,
|
|
67
|
+
pkgBase: `${entry.from ?? '@open-mercato/core'}/modules/${entry.id}`,
|
|
68
|
+
}),
|
|
69
|
+
getPackageOutputDir: () => outputDir,
|
|
70
|
+
getPackageRoot: () => path.join(tmpDir, 'node_modules', '@open-mercato/core'),
|
|
71
|
+
} as unknown as PackageResolver
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
describe('instanceConfigDefaults setup discovery and client-bundle isolation', () => {
|
|
75
|
+
const createdDirs: string[] = []
|
|
76
|
+
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
while (createdDirs.length > 0) {
|
|
79
|
+
const dir = createdDirs.pop()!
|
|
80
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('discovers setup.ts for enabled app-local and workspace modules, omits disabled owners, and keeps client/metadata outputs isolated', async () => {
|
|
85
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'instance-defaults-monorepo-'))
|
|
86
|
+
createdDirs.push(tmpDir)
|
|
87
|
+
|
|
88
|
+
touchFile(
|
|
89
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'index.ts'),
|
|
90
|
+
"export const metadata = { id: 'notifications' }\n",
|
|
91
|
+
)
|
|
92
|
+
touchFile(
|
|
93
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'setup.ts'),
|
|
94
|
+
"export const setup = { instanceConfigDefaults: () => [{ name: 'delivery_strategies', value: { panelPath: '/backend/notifications' } }] }\nexport default setup\n",
|
|
95
|
+
)
|
|
96
|
+
touchFile(
|
|
97
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'backend', 'notifications', 'page.tsx'),
|
|
98
|
+
'export default function NotificationsPage() { return null }\n',
|
|
99
|
+
)
|
|
100
|
+
touchFile(
|
|
101
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'api', 'notifications', 'route.ts'),
|
|
102
|
+
"export const metadata = { GET: { requireAuth: true } }\nexport async function GET() { return new Response('ok') }\n",
|
|
103
|
+
)
|
|
104
|
+
touchFile(
|
|
105
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'i18n', 'en.json'),
|
|
106
|
+
JSON.stringify({ notifications: { title: 'Notifications' } }),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
// Disabled workspace owner (not listed in enabled modules)
|
|
110
|
+
touchFile(
|
|
111
|
+
path.join(tmpDir, 'packages', 'search', 'src', 'modules', 'search', 'index.ts'),
|
|
112
|
+
"export const metadata = { id: 'search' }\n",
|
|
113
|
+
)
|
|
114
|
+
touchFile(
|
|
115
|
+
path.join(tmpDir, 'packages', 'search', 'src', 'modules', 'search', 'setup.ts'),
|
|
116
|
+
"export const setup = { instanceConfigDefaults: () => [{ name: 'auto_index_enabled', value: true, legacyStorageNamespace: 'vector' }] }\nexport default setup\n",
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
// Enabled app-local owner
|
|
120
|
+
touchFile(
|
|
121
|
+
path.join(tmpDir, 'app', 'src', 'modules', 'custom_defaults', 'index.ts'),
|
|
122
|
+
"export const metadata = { id: 'custom_defaults' }\n",
|
|
123
|
+
)
|
|
124
|
+
touchFile(
|
|
125
|
+
path.join(tmpDir, 'app', 'src', 'modules', 'custom_defaults', 'setup.ts'),
|
|
126
|
+
"export const setup = { instanceConfigDefaults: () => [{ name: 'feature_flag', value: true }] }\nexport default setup\n",
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
const resolver = createMonorepoResolver(tmpDir, [
|
|
130
|
+
{ id: 'notifications', from: '@open-mercato/core' },
|
|
131
|
+
{ id: 'custom_defaults', from: '@app' },
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
await generateModuleRegistry({ resolver, quiet: true })
|
|
135
|
+
await generateModuleRegistryApp({ resolver, quiet: true })
|
|
136
|
+
await generateModuleRegistryCli({ resolver, quiet: true })
|
|
137
|
+
|
|
138
|
+
const outDir = resolver.getOutputDir()
|
|
139
|
+
const serverRegistry = fs.readFileSync(path.join(outDir, 'modules.generated.ts'), 'utf8')
|
|
140
|
+
const bootstrapRegistry = fs.readFileSync(path.join(outDir, 'modules.bootstrap.generated.ts'), 'utf8')
|
|
141
|
+
const cliRegistry = fs.readFileSync(path.join(outDir, 'modules.cli.generated.ts'), 'utf8')
|
|
142
|
+
|
|
143
|
+
for (const content of [serverRegistry, bootstrapRegistry, cliRegistry]) {
|
|
144
|
+
expect(content).toContain('@open-mercato/core/modules/notifications/setup')
|
|
145
|
+
expect(content).toContain('modules/custom_defaults/setup')
|
|
146
|
+
expect(content).toContain('SETUP_custom_defaults_')
|
|
147
|
+
expect(content).not.toContain('modules/search/setup')
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Client and route-metadata generated artifacts must never reach setup.ts providers.
|
|
151
|
+
for (const isolatedArtifact of [
|
|
152
|
+
'api-route-metadata.generated.ts',
|
|
153
|
+
'backend-route-metadata.generated.ts',
|
|
154
|
+
'modules.i18n.generated.ts',
|
|
155
|
+
'dashboard-widgets.generated.ts',
|
|
156
|
+
'injection-widgets.generated.ts',
|
|
157
|
+
'injection-tables.generated.ts',
|
|
158
|
+
'enabled-module-ids.generated.ts',
|
|
159
|
+
]) {
|
|
160
|
+
const artifactPath = path.join(outDir, isolatedArtifact)
|
|
161
|
+
if (!fs.existsSync(artifactPath)) continue
|
|
162
|
+
const artifact = fs.readFileSync(artifactPath, 'utf8')
|
|
163
|
+
expect(artifact).not.toContain('/setup')
|
|
164
|
+
expect(artifact).not.toContain('instanceConfigDefaults')
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('discovers compiled setup.js from packed node_modules packages in standalone apps', async () => {
|
|
169
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'instance-defaults-packed-'))
|
|
170
|
+
createdDirs.push(tmpDir)
|
|
171
|
+
|
|
172
|
+
touchFile(
|
|
173
|
+
path.join(tmpDir, 'node_modules', '@open-mercato/search', 'dist', 'modules', 'search', 'index.js'),
|
|
174
|
+
"export const metadata = { id: 'search' }\n",
|
|
175
|
+
)
|
|
176
|
+
touchFile(
|
|
177
|
+
path.join(tmpDir, 'node_modules', '@open-mercato/search', 'dist', 'modules', 'search', 'setup.js'),
|
|
178
|
+
"export const setup = { instanceConfigDefaults: () => [{ name: 'auto_index_enabled', value: true, legacyStorageNamespace: 'vector' }] }\nexport default setup\n",
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
const resolver = createStandalonePackedResolver(tmpDir, [
|
|
182
|
+
{ id: 'search', from: '@open-mercato/search' },
|
|
183
|
+
])
|
|
184
|
+
|
|
185
|
+
await generateModuleRegistry({ resolver, quiet: true })
|
|
186
|
+
await generateModuleRegistryCli({ resolver, quiet: true })
|
|
187
|
+
|
|
188
|
+
const outDir = resolver.getOutputDir()
|
|
189
|
+
const serverRegistry = fs.readFileSync(path.join(outDir, 'modules.generated.ts'), 'utf8')
|
|
190
|
+
const cliRegistry = fs.readFileSync(path.join(outDir, 'modules.cli.generated.ts'), 'utf8')
|
|
191
|
+
|
|
192
|
+
expect(serverRegistry).toContain('@open-mercato/search/modules/search/setup')
|
|
193
|
+
expect(cliRegistry).toContain('@open-mercato/search/modules/search/setup')
|
|
194
|
+
})
|
|
195
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { runWithKmsWarningWriter } from '@open-mercato/shared/lib/encryption/kms-warning-presentation'
|
|
2
|
+
|
|
3
|
+
/** Establish presentation before app env loading and bootstrap can activate KMS. */
|
|
4
|
+
export function runWithRotationKmsWarningPresentation<T>(argv: readonly string[], operation: () => T): T {
|
|
5
|
+
if (argv[2] !== 'entities' || argv[3] !== 'rotate-encryption-key') return operation()
|
|
6
|
+
return runWithKmsWarningWriter(lines => {
|
|
7
|
+
// App env may be loaded inside operation; do not decide from entry-time env.
|
|
8
|
+
if (process.env.OM_ROTATION_PROGRESS !== 'json') return false
|
|
9
|
+
process.stderr.write(JSON.stringify({ schemaVersion: 1, type: 'phase.changed', runId: 'rotation', phase: 'rotation.kms.warning', entity: lines.map(line => line.replace(/^\s*🚨\uFE0F?\s*/u, '')).join('\n'), rowsDone: '0', rowsTotal: '0', rowsTotalExact: false, bytesDone: '0', chunksDone: 0, at: new Date().toISOString() }) + '\n')
|
|
10
|
+
}, operation)
|
|
11
|
+
}
|