@open-mercato/cli 0.11.1-develop.8805.1.6357054d1a → 0.11.1-develop.8843.1.b02f9b125d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/.turbo/turbo-build.log +6 -2
  2. package/dist/agentic/guides/module-facts.json +622 -230
  3. package/dist/agentic/guides/module-facts.v2.json +622 -230
  4. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  5. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  6. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  7. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  8. package/dist/agentic/guides/modules/assisted_selling/index.md +1 -1
  9. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  10. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  11. package/dist/agentic/guides/modules/auth/index.md +1 -1
  12. package/dist/agentic/guides/modules/availability/index.md +1 -1
  13. package/dist/agentic/guides/modules/backups/index.md +1 -1
  14. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  15. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  16. package/dist/agentic/guides/modules/cart/index.md +1 -1
  17. package/dist/agentic/guides/modules/catalog/index.md +1 -1
  18. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  19. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  20. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  21. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  22. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  23. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  24. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  25. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  26. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  27. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  28. package/dist/agentic/guides/modules/communication_channels/exact-override-targets.md +1 -1
  29. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  30. package/dist/agentic/guides/modules/communication_channels/workers.md +1 -1
  31. package/dist/agentic/guides/modules/configs/entities.md +0 -1
  32. package/dist/agentic/guides/modules/configs/index.md +1 -1
  33. package/dist/agentic/guides/modules/configs/umes-hosts.md +0 -1
  34. package/dist/agentic/guides/modules/content/index.md +1 -1
  35. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  36. package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
  37. package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
  38. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  39. package/dist/agentic/guides/modules/customers/acl-features.md +2 -1
  40. package/dist/agentic/guides/modules/customers/domain-commands.md +1 -1
  41. package/dist/agentic/guides/modules/customers/exact-override-targets.md +1 -0
  42. package/dist/agentic/guides/modules/customers/index.md +1 -1
  43. package/dist/agentic/guides/modules/dashboards/index.md +1 -1
  44. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  45. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  46. package/dist/agentic/guides/modules/devices/index.md +1 -1
  47. package/dist/agentic/guides/modules/devices/owned-contract-module-metadata.md +1 -1
  48. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  49. package/dist/agentic/guides/modules/directory/index.md +1 -1
  50. package/dist/agentic/guides/modules/documents/index.md +1 -1
  51. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  52. package/dist/agentic/guides/modules/ecommerce/owned-contract-module-metadata.md +1 -1
  53. package/dist/agentic/guides/modules/entities/index.md +1 -1
  54. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  55. package/dist/agentic/guides/modules/events/index.md +1 -1
  56. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  57. package/dist/agentic/guides/modules/forms/index.md +1 -1
  58. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  59. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  60. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  61. package/dist/agentic/guides/modules/generators/index.md +1 -1
  62. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  63. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  64. package/dist/agentic/guides/modules/ledger/index.md +1 -1
  65. package/dist/agentic/guides/modules/maintenance/contribution-resolutions.md +11 -0
  66. package/dist/agentic/guides/modules/maintenance/events.md +14 -0
  67. package/dist/agentic/guides/modules/maintenance/exact-override-targets.md +11 -0
  68. package/dist/agentic/guides/modules/maintenance/index.md +17 -0
  69. package/dist/agentic/guides/modules/maintenance/owned-contract-module-metadata.md +11 -0
  70. package/dist/agentic/guides/modules/maintenance/umes-contributions.md +11 -0
  71. package/dist/agentic/guides/modules/maintenance/umes-hosts.md +14 -0
  72. package/dist/agentic/guides/modules/messages/index.md +1 -1
  73. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  74. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  75. package/dist/agentic/guides/modules/payment_gateways/exact-override-targets.md +3 -3
  76. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  77. package/dist/agentic/guides/modules/payment_gateways/setup.md +1 -1
  78. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  79. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  80. package/dist/agentic/guides/modules/phone_calls/owned-contract-module-metadata.md +1 -1
  81. package/dist/agentic/guides/modules/planner/index.md +1 -1
  82. package/dist/agentic/guides/modules/portal/index.md +1 -1
  83. package/dist/agentic/guides/modules/progress/index.md +1 -1
  84. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  85. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  86. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  87. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  88. package/dist/agentic/guides/modules/resources/index.md +1 -1
  89. package/dist/agentic/guides/modules/sales/index.md +1 -1
  90. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  91. package/dist/agentic/guides/modules/search/index.md +1 -1
  92. package/dist/agentic/guides/modules/security/index.md +1 -1
  93. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  94. package/dist/agentic/guides/modules/shipping_carriers/active-extension-bindings.md +1 -1
  95. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  96. package/dist/agentic/guides/modules/sso/index.md +1 -1
  97. package/dist/agentic/guides/modules/staff/index.md +1 -1
  98. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  99. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  100. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  101. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  102. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  103. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  104. package/dist/agentic/guides/modules/translations/index.md +1 -1
  105. package/dist/agentic/guides/modules/upgrade_actions/cli-commands.md +11 -0
  106. package/dist/agentic/guides/modules/upgrade_actions/entities.md +11 -0
  107. package/dist/agentic/guides/modules/upgrade_actions/exact-override-targets.md +1 -0
  108. package/dist/agentic/guides/modules/upgrade_actions/index.md +5 -2
  109. package/dist/agentic/guides/modules/upgrade_actions/umes-hosts.md +11 -0
  110. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  111. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  112. package/dist/agentic/guides/modules/wms/index.md +1 -1
  113. package/dist/agentic/guides/modules/workflows/domain-commands.md +3 -0
  114. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  115. package/dist/agentic/guides/production-deployment.md +6 -0
  116. package/dist/agentic/guides/reference-module-facts.json +1 -1
  117. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +17 -9
  118. package/dist/agentic/guides/upstream/manifest.json +2 -2
  119. package/dist/agentic/shared/AGENTS.md.template +1 -1
  120. package/dist/agentic/shared/ai/harness/cases.json +7 -7
  121. package/dist/lib/generators/module-registry.js +28 -0
  122. package/dist/lib/generators/module-registry.js.map +2 -2
  123. package/dist/lib/testing/ephemeral-database-guard.js +89 -0
  124. package/dist/lib/testing/ephemeral-database-guard.js.map +7 -0
  125. package/dist/mercato.js +26 -3
  126. package/dist/mercato.js.map +2 -2
  127. package/package.json +7 -7
  128. package/src/__tests__/init-ephemeral-database.test.ts +112 -0
  129. package/src/__tests__/mercato.test.ts +15 -0
  130. package/src/lib/__tests__/modules-config.test.ts +1 -0
  131. package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +2 -1
  132. package/src/lib/generators/__tests__/module-registry-requires-enforcement.test.ts +18 -0
  133. package/src/lib/generators/__tests__/registry-variant-parity.test.ts +95 -19
  134. package/src/lib/generators/module-registry.ts +44 -0
  135. package/src/lib/testing/__tests__/ephemeral-database-guard.test.ts +88 -0
  136. package/src/lib/testing/ephemeral-database-guard.ts +105 -0
  137. package/src/mercato.ts +26 -3
@@ -0,0 +1,89 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { lstatSync, readFileSync } from "node:fs";
3
+ import { mkdir, writeFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ const identityQuery = "SELECT current_database() AS database_name, shobj_description(oid, 'pg_database') AS ownership_marker FROM pg_database WHERE datname = current_database()";
6
+ function connectionTarget(databaseUrl) {
7
+ if (!databaseUrl) throw new Error("[internal] Ephemeral initialization requires an explicit database connection.");
8
+ let parsed;
9
+ try {
10
+ parsed = new URL(databaseUrl);
11
+ } catch {
12
+ throw new Error("[internal] Ephemeral database connection is invalid.");
13
+ }
14
+ if (!["postgres:", "postgresql:"].includes(parsed.protocol) || !parsed.hostname || parsed.pathname.length < 2) {
15
+ throw new Error("[internal] Ephemeral database connection is invalid.");
16
+ }
17
+ const databaseName = decodeURIComponent(parsed.pathname.slice(1));
18
+ const port = parsed.port || "5432";
19
+ return `postgresql://${decodeURIComponent(parsed.username)}@${parsed.hostname.toLowerCase()}:${port}/${databaseName}`;
20
+ }
21
+ function connectionDigest(databaseUrl) {
22
+ return createHash("sha256").update(connectionTarget(databaseUrl)).digest("hex");
23
+ }
24
+ function readEphemeralDatabaseGuard(args) {
25
+ const prefix = "--ephemeral-database-guard=";
26
+ const values = args.filter((argument) => argument === "--ephemeral-database-guard" || argument.startsWith(prefix));
27
+ if (values.length === 0) return null;
28
+ if (values.length !== 1 || !values[0].startsWith(prefix) || !values[0].slice(prefix.length)) {
29
+ throw new Error("[internal] Ephemeral initialization requires one database ownership proof file.");
30
+ }
31
+ const proofPath = values[0].slice(prefix.length);
32
+ const metadata = lstatSync(proofPath);
33
+ if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size > 4096 || process.platform !== "win32" && ((metadata.mode & 63) !== 0 || metadata.uid !== process.getuid?.())) {
34
+ throw new Error("[internal] Ephemeral database ownership proof must be a private regular file.");
35
+ }
36
+ const value = JSON.parse(readFileSync(proofPath, "utf8"));
37
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
38
+ throw new Error("[internal] Ephemeral database ownership proof is invalid.");
39
+ }
40
+ const record = value;
41
+ if (record.version !== 1 || typeof record.databaseName !== "string" || !record.databaseName || typeof record.connectionDigest !== "string" || !/^[a-f0-9]{64}$/.test(record.connectionDigest) || typeof record.ownershipMarker !== "string" || !/^open-mercato-ephemeral:[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/.test(record.ownershipMarker)) {
42
+ throw new Error("[internal] Ephemeral database ownership proof is invalid.");
43
+ }
44
+ return { version: 1, databaseName: record.databaseName, connectionDigest: record.connectionDigest, ownershipMarker: record.ownershipMarker };
45
+ }
46
+ function assertEphemeralDatabaseConnection(guard, databaseUrl) {
47
+ if (connectionDigest(databaseUrl) !== guard.connectionDigest) {
48
+ throw new Error("[internal] Refusing initialization: the effective database connection is not the owned disposable target.");
49
+ }
50
+ }
51
+ async function assertEphemeralDatabaseOwnership(guard, client) {
52
+ const identity = (await client.query(identityQuery)).rows[0];
53
+ if (identity?.database_name !== guard.databaseName || identity?.ownership_marker !== guard.ownershipMarker) {
54
+ throw new Error("[internal] Refusing initialization: database ownership could not be verified.");
55
+ }
56
+ }
57
+ async function createEphemeralDatabaseGuard(databaseUrl, databaseName, directory) {
58
+ const digest = connectionDigest(databaseUrl);
59
+ if (decodeURIComponent(new URL(databaseUrl).pathname.slice(1)) !== databaseName) {
60
+ throw new Error("[internal] Disposable database identity does not match its allocation.");
61
+ }
62
+ const { Client } = await import("pg");
63
+ const client = new Client({ connectionString: databaseUrl, connectionTimeoutMillis: 5e3 });
64
+ const ownershipMarker = `open-mercato-ephemeral:${randomUUID()}`;
65
+ try {
66
+ await client.connect();
67
+ const identity = (await client.query(identityQuery)).rows[0];
68
+ if (identity?.database_name !== databaseName) {
69
+ throw new Error("[internal] Connected database identity does not match its allocation.");
70
+ }
71
+ const quotedName = `"${databaseName.replace(/"/g, '""')}"`;
72
+ await client.query(`COMMENT ON DATABASE ${quotedName} IS '${ownershipMarker}'`);
73
+ const guard = { version: 1, databaseName, connectionDigest: digest, ownershipMarker };
74
+ await assertEphemeralDatabaseOwnership(guard, client);
75
+ await mkdir(directory, { recursive: true, mode: 448 });
76
+ const proofPath = path.join(directory, `${randomUUID()}.json`);
77
+ await writeFile(proofPath, JSON.stringify(guard), { mode: 384, flag: "wx" });
78
+ return proofPath;
79
+ } finally {
80
+ await client.end();
81
+ }
82
+ }
83
+ export {
84
+ assertEphemeralDatabaseConnection,
85
+ assertEphemeralDatabaseOwnership,
86
+ createEphemeralDatabaseGuard,
87
+ readEphemeralDatabaseGuard
88
+ };
89
+ //# sourceMappingURL=ephemeral-database-guard.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/testing/ephemeral-database-guard.ts"],
4
+ "sourcesContent": ["import { createHash, randomUUID } from 'node:crypto'\nimport { lstatSync, readFileSync } from 'node:fs'\nimport { mkdir, writeFile } from 'node:fs/promises'\nimport path from 'node:path'\n\ntype DatabaseIdentity = { database_name: unknown; ownership_marker: unknown }\n\nexport type EphemeralDatabaseConnection = {\n query: (statement: string) => Promise<{ rows: DatabaseIdentity[] }>\n}\n\nexport type EphemeralDatabaseGuard = {\n version: 1\n databaseName: string\n connectionDigest: string\n ownershipMarker: string\n}\n\nconst identityQuery = \"SELECT current_database() AS database_name, shobj_description(oid, 'pg_database') AS ownership_marker FROM pg_database WHERE datname = current_database()\"\n\nfunction connectionTarget(databaseUrl: string | undefined): string {\n if (!databaseUrl) throw new Error('[internal] Ephemeral initialization requires an explicit database connection.')\n let parsed: URL\n try {\n parsed = new URL(databaseUrl)\n } catch {\n throw new Error('[internal] Ephemeral database connection is invalid.')\n }\n if (!['postgres:', 'postgresql:'].includes(parsed.protocol) || !parsed.hostname || parsed.pathname.length < 2) {\n throw new Error('[internal] Ephemeral database connection is invalid.')\n }\n const databaseName = decodeURIComponent(parsed.pathname.slice(1))\n const port = parsed.port || '5432'\n return `postgresql://${decodeURIComponent(parsed.username)}@${parsed.hostname.toLowerCase()}:${port}/${databaseName}`\n}\n\nfunction connectionDigest(databaseUrl: string | undefined): string {\n return createHash('sha256').update(connectionTarget(databaseUrl)).digest('hex')\n}\n\nexport function readEphemeralDatabaseGuard(args: string[]): EphemeralDatabaseGuard | null {\n const prefix = '--ephemeral-database-guard='\n const values = args.filter((argument) => argument === '--ephemeral-database-guard' || argument.startsWith(prefix))\n if (values.length === 0) return null\n if (values.length !== 1 || !values[0].startsWith(prefix) || !values[0].slice(prefix.length)) {\n throw new Error('[internal] Ephemeral initialization requires one database ownership proof file.')\n }\n const proofPath = values[0].slice(prefix.length)\n const metadata = lstatSync(proofPath)\n if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size > 4096\n || (process.platform !== 'win32' && ((metadata.mode & 0o077) !== 0 || metadata.uid !== process.getuid?.()))) {\n throw new Error('[internal] Ephemeral database ownership proof must be a private regular file.')\n }\n const value: unknown = JSON.parse(readFileSync(proofPath, 'utf8'))\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n throw new Error('[internal] Ephemeral database ownership proof is invalid.')\n }\n const record = value as Record<string, unknown>\n if (record.version !== 1 || typeof record.databaseName !== 'string' || !record.databaseName\n || typeof record.connectionDigest !== 'string' || !/^[a-f0-9]{64}$/.test(record.connectionDigest)\n || typeof record.ownershipMarker !== 'string' || !/^open-mercato-ephemeral:[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/.test(record.ownershipMarker)) {\n throw new Error('[internal] Ephemeral database ownership proof is invalid.')\n }\n return { version: 1, databaseName: record.databaseName, connectionDigest: record.connectionDigest, ownershipMarker: record.ownershipMarker }\n}\n\nexport function assertEphemeralDatabaseConnection(guard: EphemeralDatabaseGuard, databaseUrl: string | undefined): void {\n if (connectionDigest(databaseUrl) !== guard.connectionDigest) {\n throw new Error('[internal] Refusing initialization: the effective database connection is not the owned disposable target.')\n }\n}\n\nexport async function assertEphemeralDatabaseOwnership(guard: EphemeralDatabaseGuard, client: EphemeralDatabaseConnection): Promise<void> {\n const identity = (await client.query(identityQuery)).rows[0]\n if (identity?.database_name !== guard.databaseName || identity?.ownership_marker !== guard.ownershipMarker) {\n throw new Error('[internal] Refusing initialization: database ownership could not be verified.')\n }\n}\n\nexport async function createEphemeralDatabaseGuard(databaseUrl: string, databaseName: string, directory: string): Promise<string> {\n const digest = connectionDigest(databaseUrl)\n if (decodeURIComponent(new URL(databaseUrl).pathname.slice(1)) !== databaseName) {\n throw new Error('[internal] Disposable database identity does not match its allocation.')\n }\n const { Client } = await import('pg')\n const client = new Client({ connectionString: databaseUrl, connectionTimeoutMillis: 5000 })\n const ownershipMarker = `open-mercato-ephemeral:${randomUUID()}`\n try {\n await client.connect()\n const identity = (await client.query<DatabaseIdentity>(identityQuery)).rows[0]\n if (identity?.database_name !== databaseName) {\n throw new Error('[internal] Connected database identity does not match its allocation.')\n }\n const quotedName = `\"${databaseName.replace(/\"/g, '\"\"')}\"`\n await client.query(`COMMENT ON DATABASE ${quotedName} IS '${ownershipMarker}'`)\n const guard: EphemeralDatabaseGuard = { version: 1, databaseName, connectionDigest: digest, ownershipMarker }\n await assertEphemeralDatabaseOwnership(guard, client)\n await mkdir(directory, { recursive: true, mode: 0o700 })\n const proofPath = path.join(directory, `${randomUUID()}.json`)\n await writeFile(proofPath, JSON.stringify(guard), { mode: 0o600, flag: 'wx' })\n return proofPath\n } finally {\n await client.end()\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,YAAY,kBAAkB;AACvC,SAAS,WAAW,oBAAoB;AACxC,SAAS,OAAO,iBAAiB;AACjC,OAAO,UAAU;AAejB,MAAM,gBAAgB;AAEtB,SAAS,iBAAiB,aAAyC;AACjE,MAAI,CAAC,YAAa,OAAM,IAAI,MAAM,+EAA+E;AACjH,MAAI;AACJ,MAAI;AACF,aAAS,IAAI,IAAI,WAAW;AAAA,EAC9B,QAAQ;AACN,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,MAAI,CAAC,CAAC,aAAa,aAAa,EAAE,SAAS,OAAO,QAAQ,KAAK,CAAC,OAAO,YAAY,OAAO,SAAS,SAAS,GAAG;AAC7G,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,QAAM,eAAe,mBAAmB,OAAO,SAAS,MAAM,CAAC,CAAC;AAChE,QAAM,OAAO,OAAO,QAAQ;AAC5B,SAAO,gBAAgB,mBAAmB,OAAO,QAAQ,CAAC,IAAI,OAAO,SAAS,YAAY,CAAC,IAAI,IAAI,IAAI,YAAY;AACrH;AAEA,SAAS,iBAAiB,aAAyC;AACjE,SAAO,WAAW,QAAQ,EAAE,OAAO,iBAAiB,WAAW,CAAC,EAAE,OAAO,KAAK;AAChF;AAEO,SAAS,2BAA2B,MAA+C;AACxF,QAAM,SAAS;AACf,QAAM,SAAS,KAAK,OAAO,CAAC,aAAa,aAAa,gCAAgC,SAAS,WAAW,MAAM,CAAC;AACjH,MAAI,OAAO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UrlOrThrow, parseRedisUrl } from "@open-mercato/sh
7
7
  import { formatInitSummary } from "./lib/init-summary.js";
8
8
  import { resolveInitDerivedSecrets, resolveInitSuperadminCredentials } from "./lib/init-secrets.js";
9
9
  import { decideExistingDatabase, formatSkipIfInitializedMessage } from "./lib/init-existing-database.js";
10
+ import { assertEphemeralDatabaseConnection, assertEphemeralDatabaseOwnership, readEphemeralDatabaseGuard } from "./lib/testing/ephemeral-database-guard.js";
10
11
  import {
11
12
  resolveAutoSpawnWorkersMode,
12
13
  resolveLazySpawnMode,
@@ -811,6 +812,18 @@ async function run(argv = process.argv) {
811
812
  try {
812
813
  const initArgs = parts.slice(1).filter(Boolean);
813
814
  const reinstall = initArgs.includes("--reinstall") || initArgs.includes("-r");
815
+ const ephemeralDatabaseGuard = readEphemeralDatabaseGuard(initArgs);
816
+ if (ephemeralDatabaseGuard) {
817
+ assertEphemeralDatabaseConnection(ephemeralDatabaseGuard, process.env.DATABASE_URL);
818
+ const { Client: Client2 } = await import("pg");
819
+ const verificationClient = new Client2({ connectionString: process.env.DATABASE_URL, ssl: getSslConfig(), connectionTimeoutMillis: 5e3 });
820
+ try {
821
+ await verificationClient.connect();
822
+ await assertEphemeralDatabaseOwnership(ephemeralDatabaseGuard, verificationClient);
823
+ } finally {
824
+ await verificationClient.end();
825
+ }
826
+ }
814
827
  process.env.OM_INIT_FLOW = "true";
815
828
  if (reinstall) {
816
829
  process.env.OM_INIT_REINSTALL = "true";
@@ -870,11 +883,15 @@ async function run(argv = process.argv) {
870
883
  console.error("DATABASE_URL is not set. Aborting reinstall.");
871
884
  return 1;
872
885
  }
873
- const dbExists = await ensureDatabaseExists(dbUrl2);
886
+ const dbExists = ephemeralDatabaseGuard ? true : await ensureDatabaseExists(dbUrl2);
874
887
  if (!dbExists) return 1;
875
888
  const client = new Client2({ connectionString: dbUrl2, ssl: getSslConfig() });
876
889
  try {
877
890
  await client.connect();
891
+ if (ephemeralDatabaseGuard) {
892
+ assertEphemeralDatabaseConnection(ephemeralDatabaseGuard, dbUrl2);
893
+ await assertEphemeralDatabaseOwnership(ephemeralDatabaseGuard, client);
894
+ }
878
895
  const res = await client.query(`SELECT tablename FROM pg_tables WHERE schemaname = current_schema()`);
879
896
  const dropTargets = new Set((res.rows || []).map((r) => String(r.tablename)));
880
897
  for (const forced of ["vector_search", "vector_search_migrations"]) {
@@ -911,7 +928,7 @@ async function run(argv = process.argv) {
911
928
  }
912
929
  }
913
930
  const redisUrl = getRedisUrl();
914
- if (redisUrl) {
931
+ if (redisUrl && !ephemeralDatabaseGuard) {
915
932
  const Redis = (await import("ioredis")).default;
916
933
  const redis = new Redis({
917
934
  ...parseRedisUrl(redisUrl),
@@ -936,6 +953,8 @@ async function run(argv = process.argv) {
936
953
  } catch {
937
954
  }
938
955
  }
956
+ } else if (ephemeralDatabaseGuard) {
957
+ console.log("[internal] Redis flush skipped: ephemeral database initialization does not own Redis.");
939
958
  } else {
940
959
  console.log(" Redis flush skipped (REDIS_URL not configured).");
941
960
  }
@@ -949,7 +968,7 @@ async function run(argv = process.argv) {
949
968
  return 1;
950
969
  }
951
970
  const { Client: Client2 } = await import("pg");
952
- const dbExists = await ensureDatabaseExists(dbUrl2);
971
+ const dbExists = ephemeralDatabaseGuard ? true : await ensureDatabaseExists(dbUrl2);
953
972
  if (!dbExists) return 1;
954
973
  const client = new Client2({ connectionString: dbUrl2, ssl: getSslConfig() });
955
974
  try {
@@ -2332,6 +2351,10 @@ async function run(argv = process.argv) {
2332
2351
  }
2333
2352
  const mod = all.find((m) => m.id === modName);
2334
2353
  if (!mod) {
2354
+ if (modName === "maintenance") {
2355
+ console.error("Maintenance mode requires the Enterprise maintenance module. Set OM_ENABLE_ENTERPRISE_MODULES=true and regenerate the app after enabling Enterprise.");
2356
+ return 1;
2357
+ }
2335
2358
  console.error(`\u274C Module not found: "${modName}"`);
2336
2359
  return 1;
2337
2360
  }