@x12i/memorix-service 0.0.0-bootstrap.0

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 (84) hide show
  1. package/README.md +37 -0
  2. package/dist/app.d.ts +21 -0
  3. package/dist/app.d.ts.map +1 -0
  4. package/dist/app.js +67 -0
  5. package/dist/app.js.map +1 -0
  6. package/dist/catalog-bridge.d.ts +7 -0
  7. package/dist/catalog-bridge.d.ts.map +1 -0
  8. package/dist/catalog-bridge.js +155 -0
  9. package/dist/catalog-bridge.js.map +1 -0
  10. package/dist/cli.d.ts +3 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +36 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/errors.d.ts +25 -0
  15. package/dist/errors.d.ts.map +1 -0
  16. package/dist/errors.js +79 -0
  17. package/dist/errors.js.map +1 -0
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +7 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/isolation.d.ts +63 -0
  23. package/dist/isolation.d.ts.map +1 -0
  24. package/dist/isolation.js +175 -0
  25. package/dist/isolation.js.map +1 -0
  26. package/dist/known-packs.d.ts +5 -0
  27. package/dist/known-packs.d.ts.map +1 -0
  28. package/dist/known-packs.js +26 -0
  29. package/dist/known-packs.js.map +1 -0
  30. package/dist/mongo-metadata-store.d.ts +17 -0
  31. package/dist/mongo-metadata-store.d.ts.map +1 -0
  32. package/dist/mongo-metadata-store.js +81 -0
  33. package/dist/mongo-metadata-store.js.map +1 -0
  34. package/dist/openapi/openapi.json +6431 -0
  35. package/dist/platform.d.ts +52 -0
  36. package/dist/platform.d.ts.map +1 -0
  37. package/dist/platform.js +246 -0
  38. package/dist/platform.js.map +1 -0
  39. package/dist/relationships/operator-links.d.ts +23 -0
  40. package/dist/relationships/operator-links.d.ts.map +1 -0
  41. package/dist/relationships/operator-links.js +41 -0
  42. package/dist/relationships/operator-links.js.map +1 -0
  43. package/dist/request-scope.d.ts +7 -0
  44. package/dist/request-scope.d.ts.map +1 -0
  45. package/dist/request-scope.js +24 -0
  46. package/dist/request-scope.js.map +1 -0
  47. package/dist/routes/data.d.ts +4 -0
  48. package/dist/routes/data.d.ts.map +1 -0
  49. package/dist/routes/data.js +237 -0
  50. package/dist/routes/data.js.map +1 -0
  51. package/dist/routes/intelligence.d.ts +5 -0
  52. package/dist/routes/intelligence.d.ts.map +1 -0
  53. package/dist/routes/intelligence.js +94 -0
  54. package/dist/routes/intelligence.js.map +1 -0
  55. package/dist/routes/memory.d.ts +4 -0
  56. package/dist/routes/memory.d.ts.map +1 -0
  57. package/dist/routes/memory.js +80 -0
  58. package/dist/routes/memory.js.map +1 -0
  59. package/dist/routes/metadata.d.ts +4 -0
  60. package/dist/routes/metadata.d.ts.map +1 -0
  61. package/dist/routes/metadata.js +104 -0
  62. package/dist/routes/metadata.js.map +1 -0
  63. package/dist/routes/operations.d.ts +4 -0
  64. package/dist/routes/operations.d.ts.map +1 -0
  65. package/dist/routes/operations.js +66 -0
  66. package/dist/routes/operations.js.map +1 -0
  67. package/dist/routes/pipelines.d.ts +4 -0
  68. package/dist/routes/pipelines.d.ts.map +1 -0
  69. package/dist/routes/pipelines.js +128 -0
  70. package/dist/routes/pipelines.js.map +1 -0
  71. package/dist/routes/relationships.d.ts +4 -0
  72. package/dist/routes/relationships.d.ts.map +1 -0
  73. package/dist/routes/relationships.js +138 -0
  74. package/dist/routes/relationships.js.map +1 -0
  75. package/dist/routes/workflow.d.ts +4 -0
  76. package/dist/routes/workflow.d.ts.map +1 -0
  77. package/dist/routes/workflow.js +104 -0
  78. package/dist/routes/workflow.js.map +1 -0
  79. package/dist/scope.d.ts +19 -0
  80. package/dist/scope.d.ts.map +1 -0
  81. package/dist/scope.js +53 -0
  82. package/dist/scope.js.map +1 -0
  83. package/openapi/openapi.json +6431 -0
  84. package/package.json +65 -0
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @x12i/memorix-service
2
+
3
+ One production HTTP composition root over accepted Memorix packages (Phase 10 / G10).
4
+
5
+ ## Scope
6
+
7
+ Every `/api/*` request requires:
8
+
9
+ - `x-memorix-org-id` — organization data universe
10
+ - `x-memorix-agent-ids` — comma-separated agent ids (effective metadata only)
11
+
12
+ Singular `agentId` headers are rejected.
13
+
14
+ ## Run
15
+
16
+ ```bash
17
+ # production (requires MONGO_URI)
18
+ MEMORIX_SERVICE_MODE=prod MONGO_URI=mongodb://127.0.0.1:27017 npm run serve
19
+
20
+ # local dev without mongo (metadata in-memory; durable routes 503)
21
+ MEMORIX_SERVICE_MODE=dev npm run dev
22
+ ```
23
+
24
+ Default port: `5190`.
25
+
26
+ ## Route families
27
+
28
+ `/api/metadata` · `/api/data` · `/api/relationships` · `/api/memory` · `/api/pipelines` · `/api/operations` · `/api/workflow` · `/api/intelligence`
29
+
30
+ OpenAPI: `GET /api/openapi.json`
31
+
32
+ ## Hard rules
33
+
34
+ - Prod rejects missing Mongo and in-memory metadata/artifact fallbacks
35
+ - No ad-hoc relationship link mutation (`/api/relationships/links` → 405)
36
+ - Intelligence never auto-installs/publishes
37
+ - Only `credentialRef` may cross Memory APIs
package/dist/app.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import Fastify, { type FastifyInstance } from "fastify";
2
+ import { type MemorixPlatform, type PlatformDeps } from "./platform.js";
3
+ export type CreateMemorixServiceAppOptions = PlatformDeps & {
4
+ logger?: boolean;
5
+ platform?: MemorixPlatform;
6
+ };
7
+ export declare function createMemorixServiceApp(opts: CreateMemorixServiceAppOptions): Promise<{
8
+ app: FastifyInstance;
9
+ platform: MemorixPlatform;
10
+ }>;
11
+ export type StartMemorixServiceOptions = CreateMemorixServiceAppOptions & {
12
+ port?: number;
13
+ host?: string;
14
+ };
15
+ export declare function startMemorixServiceHttp(opts: StartMemorixServiceOptions): Promise<{
16
+ app: Fastify.FastifyInstance<Fastify.RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, Fastify.FastifyBaseLogger, Fastify.FastifyTypeProviderDefault>;
17
+ platform: MemorixPlatform;
18
+ port: number;
19
+ host: string;
20
+ }>;
21
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAIA,OAAO,OAAO,EAAE,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAGxD,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAavB,MAAM,MAAM,8BAA8B,GAAG,YAAY,GAAG;IAC1D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,8BAA8B,GACnC,OAAO,CAAC;IAAE,GAAG,EAAE,eAAe,CAAC;IAAC,QAAQ,EAAE,eAAe,CAAA;CAAE,CAAC,CAiD9D;AAED,MAAM,MAAM,0BAA0B,GAAG,8BAA8B,GAAG;IACxE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,0BAA0B;;;;;GAM7E"}
package/dist/app.js ADDED
@@ -0,0 +1,67 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
3
+ import { dirname, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import Fastify from "fastify";
6
+ import cors from "@fastify/cors";
7
+ import { mapErrorToHttp, redactSecrets } from "./errors.js";
8
+ import { createMemorixPlatform, } from "./platform.js";
9
+ import { resolveScope } from "./request-scope.js";
10
+ import { registerMetadataRoutes } from "./routes/metadata.js";
11
+ import { registerDataRoutes } from "./routes/data.js";
12
+ import { registerRelationshipRoutes } from "./routes/relationships.js";
13
+ import { registerMemoryRoutes } from "./routes/memory.js";
14
+ import { registerPipelineRoutes } from "./routes/pipelines.js";
15
+ import { registerOperationsRoutes } from "./routes/operations.js";
16
+ import { registerWorkflowRoutes } from "./routes/workflow.js";
17
+ import { registerIntelligenceRoutes } from "./routes/intelligence.js";
18
+ const __dirname = dirname(fileURLToPath(import.meta.url));
19
+ export async function createMemorixServiceApp(opts) {
20
+ const platform = opts.platform ?? (await createMemorixPlatform(opts));
21
+ const app = Fastify({ logger: opts.logger ?? false });
22
+ await app.register(cors, { origin: true });
23
+ app.addHook("onRequest", async (req, reply) => {
24
+ const correlationId = (typeof req.headers["x-correlation-id"] === "string" &&
25
+ req.headers["x-correlation-id"]) ||
26
+ randomUUID();
27
+ req.correlationId = correlationId;
28
+ reply.header("x-correlation-id", correlationId);
29
+ });
30
+ app.setErrorHandler((err, req, reply) => {
31
+ const correlationId = req.correlationId ?? randomUUID();
32
+ const mapped = mapErrorToHttp(err, correlationId);
33
+ mapped.body.error = redactSecrets(mapped.body.error);
34
+ return reply.code(mapped.status).send(mapped.body);
35
+ });
36
+ app.get("/health", async () => ({
37
+ ok: true,
38
+ service: "@x12i/memorix-service",
39
+ mode: platform.mode,
40
+ }));
41
+ app.get("/api/openapi.json", async (_req, reply) => {
42
+ const path = resolve(__dirname, "../openapi/openapi.json");
43
+ const body = readFileSync(path, "utf8");
44
+ return reply.type("application/json").send(JSON.parse(body));
45
+ });
46
+ app.get("/api/diagnostics/scope", async (req) => {
47
+ const scope = resolveScope(req);
48
+ return { scope, platform: platform.diagnostics(scope) };
49
+ });
50
+ await registerMetadataRoutes(app, platform);
51
+ await registerDataRoutes(app, platform);
52
+ await registerRelationshipRoutes(app, platform);
53
+ await registerMemoryRoutes(app, platform);
54
+ await registerPipelineRoutes(app, platform);
55
+ await registerOperationsRoutes(app, platform);
56
+ await registerWorkflowRoutes(app, platform);
57
+ await registerIntelligenceRoutes(app, platform);
58
+ return { app, platform };
59
+ }
60
+ export async function startMemorixServiceHttp(opts) {
61
+ const { app, platform } = await createMemorixServiceApp(opts);
62
+ const port = opts.port ?? Number(process.env.MEMORIX_SERVICE_PORT ?? 5190);
63
+ const host = opts.host ?? "127.0.0.1";
64
+ await app.listen({ port, host });
65
+ return { app, platform, port, host };
66
+ }
67
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,OAAiC,MAAM,SAAS,CAAC;AACxD,OAAO,IAAI,MAAM,eAAe,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,qBAAqB,GAGtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAEtE,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAO1D,M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,EAAE,CAAC;AAC3B,CAAC;AAOD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,IAAgC;IAC5E,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,MAAM,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,IAAI,CAAC,CAAC;IAC3E,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,WAAW,CAAC;IACtC,MAAM,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACjC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { UnifiedMetadataClient } from "@x12i/memorix-metadata-runtime";
2
+ import type { AbstractWriteCatalog, ReaderMetadataCatalog, WriterMetadataCatalog } from "@x12i/memorix-data";
3
+ import type { RelationshipMetadataResolver } from "@x12i/memorix-relationships";
4
+ export type ServiceCatalog = WriterMetadataCatalog & ReaderMetadataCatalog & AbstractWriteCatalog;
5
+ export declare function catalogFromMetadataClient(metadata: UnifiedMetadataClient, agentIds: string[]): ServiceCatalog;
6
+ export declare function relationshipMetadataResolver(metadata: UnifiedMetadataClient): RelationshipMetadataResolver;
7
+ //# sourceMappingURL=catalog-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog-bridge.d.ts","sourceRoot":"","sources":["../src/catalog-bridge.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,KAAK,EAEV,oBAAoB,EAGpB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAEhF,MAAM,MAAM,cAAc,GAAG,qBAAqB,GAChD,qBAAqB,GACrB,oBAAoB,CAAC;AAOvB,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,qBAAqB,EAC/B,QAAQ,EAAE,MAAM,EAAE,GACjB,cAAc,CAgJhB;AAED,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,qBAAqB,GAC9B,4BAA4B,CAuB9B"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Bridge UnifiedMetadataClient → data-plane catalogs for ops wiring.
3
+ */
4
+ import { BUILTIN_CONTENT_PROFILES } from "@x12i/memorix-format/v2";
5
+ function asCategory(v) {
6
+ if (v === "event" || v === "knowledge" || v === "entity")
7
+ return v;
8
+ return "entity";
9
+ }
10
+ export function catalogFromMetadataClient(metadata, agentIds) {
11
+ const effective = metadata.resolveEffective(agentIds);
12
+ const objectTypes = new Map();
13
+ for (const entry of effective.effective ?? []) {
14
+ const def = entry.definition;
15
+ if (entry.kind === "object-types") {
16
+ const id = String(def.id ?? entry.id);
17
+ const contentTypesRaw = Array.isArray(def.contentTypes) ? def.contentTypes : [];
18
+ const contentTypes = contentTypesRaw
19
+ .map((ct) => typeof ct === "string" ? ct : String(ct.id ?? ""))
20
+ .filter(Boolean);
21
+ objectTypes.set(id, {
22
+ objectType: id,
23
+ dataCategory: asCategory(def.dataCategory),
24
+ contentTypes,
25
+ });
26
+ }
27
+ }
28
+ const abstracts = metadata.resolveAbstracts(agentIds);
29
+ const abstractPlans = new Map();
30
+ if (abstracts.ok) {
31
+ for (const plan of abstracts.plans) {
32
+ const membersByOt = new Map();
33
+ for (const prop of plan.properties) {
34
+ for (const path of prop.concretePaths) {
35
+ let m = membersByOt.get(path.objectType);
36
+ if (!m) {
37
+ m = {
38
+ objectType: path.objectType,
39
+ contentType: path.contentType || "snapshots",
40
+ dataCategory: objectTypes.get(path.objectType)?.dataCategory ?? "entity",
41
+ directBindings: {},
42
+ };
43
+ membersByOt.set(path.objectType, m);
44
+ }
45
+ if (path.propertyPath) {
46
+ m.directBindings[prop.abstractProperty] = path.propertyPath;
47
+ }
48
+ if (path.mappingId) {
49
+ const mapDef = metadata.getDefinition(agentIds, "mappings", path.mappingId);
50
+ if (mapDef?.definition) {
51
+ m.mapping = mapDef.definition;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ // Fallback members from plan.members if properties empty
57
+ if (membersByOt.size === 0) {
58
+ for (const mem of plan.members) {
59
+ membersByOt.set(mem.objectType, {
60
+ objectType: mem.objectType,
61
+ contentType: "snapshots",
62
+ dataCategory: objectTypes.get(mem.objectType)?.dataCategory ?? "entity",
63
+ directBindings: { title: "data.displayName", role: "data.role" },
64
+ });
65
+ }
66
+ }
67
+ const members = [...membersByOt.values()].map((m) => ({
68
+ objectType: m.objectType,
69
+ contentType: m.contentType,
70
+ dataCategory: m.dataCategory,
71
+ directBindings: m.directBindings,
72
+ mapping: (m.mapping ?? {
73
+ id: `synthetic-${plan.abstractType}-${m.objectType}`,
74
+ purpose: "abstract",
75
+ map: Object.fromEntries(Object.entries(m.directBindings).map(([k, p]) => [
76
+ k,
77
+ { op: "path", path: p },
78
+ ])),
79
+ reverse: Object.fromEntries(Object.entries(m.directBindings).map(([k, p]) => [
80
+ k,
81
+ { expr: { op: "path", path: k }, targetPath: p },
82
+ ])),
83
+ }),
84
+ }));
85
+ abstractPlans.set(plan.abstractType, {
86
+ abstractType: plan.abstractType,
87
+ abstractFields: plan.properties.map((p) => p.abstractProperty),
88
+ members,
89
+ });
90
+ }
91
+ }
92
+ return {
93
+ getObjectType(objectType) {
94
+ return objectTypes.get(objectType) ?? null;
95
+ },
96
+ getContentProfile(contentType) {
97
+ return BUILTIN_CONTENT_PROFILES[contentType];
98
+ },
99
+ getAllowedQueryPaths(_objectType, _contentType) {
100
+ return [
101
+ "recordId",
102
+ "revision",
103
+ "concept.title",
104
+ "data.*",
105
+ "data.displayName",
106
+ "data.role",
107
+ "data.status",
108
+ "data.priority",
109
+ ];
110
+ },
111
+ getAbstractPlan(abstractType) {
112
+ return abstractPlans.get(abstractType) ?? null;
113
+ },
114
+ isAbstractMember(abstractType, objectType) {
115
+ const plan = abstractPlans.get(abstractType);
116
+ return Boolean(plan?.members.some((m) => m.objectType === objectType));
117
+ },
118
+ getAbstractWriteBindings(abstractType, objectType) {
119
+ const plan = abstractPlans.get(abstractType);
120
+ const member = plan?.members.find((m) => m.objectType === objectType);
121
+ if (!member)
122
+ return [];
123
+ return Object.keys(member.directBindings).map((abstractProperty) => ({
124
+ abstractProperty,
125
+ objectType,
126
+ contentType: member.contentType,
127
+ dataCategory: member.dataCategory,
128
+ mapping: member.mapping,
129
+ reversible: true,
130
+ }));
131
+ },
132
+ };
133
+ }
134
+ export function relationshipMetadataResolver(metadata) {
135
+ return {
136
+ getRelationshipDefinition(definitionId, agentIds) {
137
+ const def = metadata.getDefinition(agentIds, "relationship-definitions", definitionId);
138
+ return def?.definition ?? null;
139
+ },
140
+ listRelationshipDefinitions(agentIds) {
141
+ const effective = metadata.resolveEffective(agentIds);
142
+ return (effective.effective ?? [])
143
+ .filter((e) => e.kind === "relationship-definitions")
144
+ .map((e) => e.definition);
145
+ },
146
+ getConcreteObjectTypes(abstractType, agentIds) {
147
+ const abstracts = metadata.resolveAbstracts(agentIds);
148
+ if (!abstracts.ok)
149
+ return [];
150
+ const plan = abstracts.plans.find((p) => p.abstractType === abstractType);
151
+ return (plan?.members ?? []).map((m) => m.objectType);
152
+ },
153
+ };
154
+ }
155
+ //# sourceMappingURL=catalog-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog-bridge.js","sourceRoot":"","sources":["../src/catalog-bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAkBnE,SAAS,UAAU,CAAC,CAAU;IAC5B,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,WAAW,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACnE,OA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GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,YAAY,CAAC,CAAC;YAC1E,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QACxD,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import { startMemorixServiceHttp } from "./app.js";
5
+ function loadMongoUri() {
6
+ if (process.env.MONGO_URI)
7
+ return process.env.MONGO_URI;
8
+ try {
9
+ const text = readFileSync(resolve(process.cwd(), "./.env"), "utf8");
10
+ const m = text.match(/^MONGO_URI=(.+)$/m);
11
+ return m?.[1]?.trim().replace(/^['"]|['"]$/g, "");
12
+ }
13
+ catch {
14
+ return undefined;
15
+ }
16
+ }
17
+ async function main() {
18
+ const cmd = process.argv[2] ?? "serve";
19
+ if (cmd !== "serve") {
20
+ console.error("Usage: memorix-service serve");
21
+ process.exit(1);
22
+ }
23
+ const mode = (process.env.MEMORIX_SERVICE_MODE ?? "prod");
24
+ const mongoUri = loadMongoUri();
25
+ const { port, host } = await startMemorixServiceHttp({
26
+ mode,
27
+ mongoUri,
28
+ logger: true,
29
+ });
30
+ console.log(`memorix-service listening on http://${host}:${port} (mode=${mode})`);
31
+ }
32
+ main().catch((err) => {
33
+ console.error(err);
34
+ process.exit(1);
35
+ });
36
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@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AAO,CAAC,GAAG,CAAC,uCAAuC,IAAI,IAAI,IAAI,UAAU,IAAI,GAAG,CAAC,CAAC;AACpF,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ export type ServiceErrorBody = {
2
+ error: {
3
+ code: string;
4
+ message: string;
5
+ correlationId: string;
6
+ details?: unknown;
7
+ scope?: {
8
+ orgId: string;
9
+ agentIds: string[];
10
+ };
11
+ };
12
+ };
13
+ export declare class ServiceError extends Error {
14
+ readonly code: string;
15
+ readonly statusCode: number;
16
+ readonly details?: unknown;
17
+ constructor(code: string, message: string, statusCode?: number, details?: unknown);
18
+ }
19
+ export declare function mapErrorToHttp(err: unknown, correlationId: string): {
20
+ status: number;
21
+ body: ServiceErrorBody;
22
+ };
23
+ /** Never put secrets into error/log payloads. */
24
+ export declare function redactSecrets(value: unknown): unknown;
25
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE,MAAM,CAAC;QACtB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,KAAK,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC;KAC/C,CAAC;CACH,CAAC;AAEF,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEf,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,SAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAO/E;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,gBAAgB,CAAC;CACxB,CAsCA;AAED,iDAAiD;AACjD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAoBrD"}
package/dist/errors.js ADDED
@@ -0,0 +1,79 @@
1
+ export class ServiceError extends Error {
2
+ code;
3
+ statusCode;
4
+ details;
5
+ constructor(code, message, statusCode = 400, details) {
6
+ super(message);
7
+ this.name = "ServiceError";
8
+ this.code = code;
9
+ this.statusCode = statusCode;
10
+ this.details = details;
11
+ }
12
+ }
13
+ export function mapErrorToHttp(err, correlationId) {
14
+ if (err && typeof err === "object" && "code" in err && "statusCode" in err) {
15
+ const e = err;
16
+ return {
17
+ status: e.statusCode,
18
+ body: {
19
+ error: {
20
+ code: e.code,
21
+ message: e.message,
22
+ correlationId,
23
+ details: e.details,
24
+ },
25
+ },
26
+ };
27
+ }
28
+ if (err instanceof Error && err.name === "ScopeValidationError") {
29
+ return {
30
+ status: 400,
31
+ body: {
32
+ error: {
33
+ code: "SCOPE_INVALID",
34
+ message: err.message,
35
+ correlationId,
36
+ },
37
+ },
38
+ };
39
+ }
40
+ const message = err instanceof Error ? err.message : String(err);
41
+ return {
42
+ status: 500,
43
+ body: {
44
+ error: {
45
+ code: "INTERNAL_ERROR",
46
+ message,
47
+ correlationId,
48
+ },
49
+ },
50
+ };
51
+ }
52
+ /** Never put secrets into error/log payloads. */
53
+ export function redactSecrets(value) {
54
+ if (value == null)
55
+ return value;
56
+ if (typeof value === "string") {
57
+ if (/password|secret|token|api[_-]?key|credential/i.test(value))
58
+ return "[REDACTED]";
59
+ if (/mongodb(\+srv)?:\/\/[^/\s]+:[^@\s]+@/i.test(value))
60
+ return "[REDACTED_URI]";
61
+ return value;
62
+ }
63
+ if (Array.isArray(value))
64
+ return value.map(redactSecrets);
65
+ if (typeof value === "object") {
66
+ const out = {};
67
+ for (const [k, v] of Object.entries(value)) {
68
+ if (/password|secret|token|api[_-]?key|credential|mongoUri/i.test(k)) {
69
+ out[k] = "[REDACTED]";
70
+ }
71
+ else {
72
+ out[k] = redactSecrets(v);
73
+ }
74
+ }
75
+ return out;
76
+ }
77
+ return value;
78
+ }
79
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAS;IACb,UAAU,CAAS;IACnB,OAAO,CAAW;IAE3B,YAAY,IAAY,EAAE,OAAe,EAAE,UAAU,GAAG,GAAG,EAAE,OAAiB;QAC5E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAC,GAAY,EAAE,aAAqB;IAIhE,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,YAAY,IAAI,GAAG,EAAE,CAAC;QAC3E,MAAM,CAAC,GAAG,GAAmB,CAAC;QAC9B,OAAO;YACL,MAAM,EAAE,CAAC,CAAC,UAAU;YACpB,IAAI,EAAE;gBACJ,KAAK,EAAE;oBACL,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,OAAO,EAAE,CAAC,CAAC,OAAO;oBAClB,aAAa;oBACb,OAAO,EAA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E,IAAI,wDAAwD,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrE,GAAG,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { canonicalizeScope, scopeFromHeaders, ScopeValidationError, type MemorixScope, } from "./scope.js";
2
+ export { resolveScope } from "./request-scope.js";
3
+ export { ServiceError, mapErrorToHttp, redactSecrets, type ServiceErrorBody, } from "./errors.js";
4
+ export { createMemorixPlatform, PlatformStartupError, type MemorixPlatform, type PlatformDeps, type RuntimeMode, type OrgPorts, } from "./platform.js";
5
+ export { createMemorixServiceApp, startMemorixServiceHttp, type CreateMemorixServiceAppOptions, type StartMemorixServiceOptions, } from "./app.js";
6
+ export { generateG10OrgId, generateG11OrgId, generateG12OrgId, beginIsolationSession, beginG11IsolationSession, beginG12IsolationSession, cleanupIsolationSession, isolationEvidence, assertSafeG10OrgId, assertSafeG11OrgId, assertSafeG12OrgId, assertSafeAcceptanceOrgId, G10_ORG_PATTERN, G11_ORG_PATTERN, G12_ORG_PATTERN, ACCEPTANCE_ORG_PATTERN, IsolationError, type IsolationSession, } from "./isolation.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,aAAa,EACb,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,QAAQ,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,GAChC,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,eAAe,EACf,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { canonicalizeScope, scopeFromHeaders, ScopeValidationError, } from "./scope.js";
2
+ export { resolveScope } from "./request-scope.js";
3
+ export { ServiceError, mapErrorToHttp, redactSecrets, } from "./errors.js";
4
+ export { createMemorixPlatform, PlatformStartupError, } from "./platform.js";
5
+ export { createMemorixServiceApp, startMemorixServiceHttp, } from "./app.js";
6
+ export { generateG10OrgId, generateG11OrgId, generateG12OrgId, beginIsolationSession, beginG11IsolationSession, beginG12IsolationSession, cleanupIsolationSession, isolationEvidence, assertSafeG10OrgId, assertSafeG11OrgId, assertSafeG12OrgId, assertSafeAcceptanceOrgId, G10_ORG_PATTERN, G11_ORG_PATTERN, G12_ORG_PATTERN, ACCEPTANCE_ORG_PATTERN, IsolationError, } from "./isolation.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,GAErB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,aAAa,GAEd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,GAKrB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,uBAAuB,EACvB,uBAAuB,GAGxB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,eAAe,EACf,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,cAAc,GAEf,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { MongoClient } from "mongodb";
2
+ export declare const G10_ORG_PREFIX = "g10ops";
3
+ export declare const G11_ORG_PREFIX = "g11ops";
4
+ export declare const G12_ORG_PREFIX = "g12ops";
5
+ export declare const G10_ORG_PATTERN: RegExp;
6
+ export declare const G11_ORG_PATTERN: RegExp;
7
+ export declare const G12_ORG_PATTERN: RegExp;
8
+ export declare const ACCEPTANCE_ORG_PATTERN: RegExp;
9
+ export declare const FORBIDDEN_ORG_SUBSTRINGS: readonly ["neo", "fieldstone"];
10
+ export type DatabaseKindName = "entity" | "event" | "knowledge" | "operational" | "metadata";
11
+ export type IsolationSession = {
12
+ orgId: string;
13
+ agentIds: ["ops"];
14
+ allowedDatabaseNames: string[];
15
+ createdDatabaseNames: string[];
16
+ preflightExisting: string[];
17
+ isolatedMetadataDb: string;
18
+ zeroPreexistingMutated: true;
19
+ };
20
+ export declare class IsolationError extends Error {
21
+ readonly code = "DB_ISOLATION_VIOLATION";
22
+ constructor(message: string);
23
+ }
24
+ export declare function assertSafeG10OrgId(orgId: string): void;
25
+ export declare function assertSafeG11OrgId(orgId: string): void;
26
+ export declare function assertSafeG12OrgId(orgId: string): void;
27
+ export declare function assertSafeAcceptanceOrgId(orgId: string, gate?: "g10" | "g11" | "g12" | "any"): void;
28
+ export declare function generateG10OrgId(token?: string): string;
29
+ export declare function generateG11OrgId(token?: string): string;
30
+ export declare function generateG12OrgId(token?: string): string;
31
+ export declare function allowedDatabasesForOrg(orgId: string): string[];
32
+ /** Read-only list of DB names that already exist for this org prefix. */
33
+ export declare function preflightOrgDatabases(client: MongoClient, orgId: string): Promise<{
34
+ existing: string[];
35
+ conflict: boolean;
36
+ }>;
37
+ export declare function beginIsolationSession(client: MongoClient, opts?: {
38
+ token?: string;
39
+ maxAttempts?: number;
40
+ prefix?: "g10ops" | "g11ops" | "g12ops";
41
+ }): Promise<IsolationSession>;
42
+ export declare function beginG11IsolationSession(client: MongoClient, opts?: {
43
+ token?: string;
44
+ maxAttempts?: number;
45
+ }): Promise<IsolationSession>;
46
+ export declare function beginG12IsolationSession(client: MongoClient, opts?: {
47
+ token?: string;
48
+ maxAttempts?: number;
49
+ }): Promise<IsolationSession>;
50
+ export declare function recordCreatedDatabase(session: IsolationSession, dbName: string): void;
51
+ /** Drop only DBs recorded in this session's creation ledger (collections then empty DB if permitted). */
52
+ export declare function cleanupIsolationSession(client: MongoClient, session: IsolationSession): Promise<string[]>;
53
+ export declare function isolationEvidence(session: IsolationSession, extra?: Record<string, unknown>): {
54
+ orgId: string;
55
+ agentIds: ["ops"];
56
+ allowedDatabaseNames: string[];
57
+ preflightExisting: string[];
58
+ createdDatabaseNames: string[];
59
+ cleanupTargets: string[];
60
+ isolatedMetadataDb: string;
61
+ zeroPreexistingMutated: true;
62
+ };
63
+ //# sourceMappingURL=isolation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isolation.d.ts","sourceRoot":"","sources":["../src/isolation.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,eAAO,MAAM,cAAc,WAAW,CAAC;AACvC,e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