Skip to content

Commit 97c66fa

Browse files
authored
Chore/awareness as a service temporary stub (#959)
* feat: add cross-eName ontology lookup helper * feat: temporary token-gated cross-evault ontology read endpoint
1 parent 62658ff commit 97c66fa

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

infrastructure/evault-core/src/core/db/db.service.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,58 @@ export class DbService {
465465
});
466466
}
467467

468+
/**
469+
* Finds all meta-envelopes by ontology across every eName (no tenant isolation).
470+
* Temporary helper — use with care; intended for the token-gated cross-eVault read endpoint.
471+
*/
472+
async findMetaEnvelopesByOntologyAcrossAllENames<
473+
T extends Record<string, any> = Record<string, any>,
474+
>(
475+
ontology: string,
476+
): Promise<(MetaEnvelopeResult<T> & { eName: string })[]> {
477+
const result = await this.runQueryInternal(
478+
`
479+
MATCH (m:MetaEnvelope { ontology: $ontology })-[:LINKS_TO]->(e:Envelope)
480+
RETURN m.id AS id, m.ontology AS ontology, m.acl AS acl, m.eName AS eName, collect(e) AS envelopes
481+
`,
482+
{ ontology },
483+
);
484+
485+
return result.records.map((record) => {
486+
const envelopes = record
487+
.get("envelopes")
488+
.map((node: any): Envelope<T[keyof T]> => {
489+
const properties = node.properties;
490+
return {
491+
id: properties.id,
492+
ontology: properties.ontology,
493+
value: deserializeValue(
494+
properties.value,
495+
properties.valueType,
496+
) as T[keyof T],
497+
valueType: properties.valueType,
498+
};
499+
});
500+
501+
const parsed = envelopes.reduce(
502+
(acc: T, envelope: Envelope<T[keyof T]>) => {
503+
(acc as any)[envelope.ontology] = envelope.value;
504+
return acc;
505+
},
506+
{} as T,
507+
);
508+
509+
return {
510+
id: record.get("id"),
511+
ontology: record.get("ontology"),
512+
acl: record.get("acl"),
513+
eName: record.get("eName"),
514+
envelopes,
515+
parsed,
516+
};
517+
});
518+
}
519+
468520
/**
469521
* Deletes a meta-envelope and all its associated envelopes.
470522
* @param id - The ID of the meta-envelope to delete

infrastructure/evault-core/src/core/http/server.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,40 @@ export async function registerHttpRoutes(
355355
},
356356
);
357357

358+
// Temporary token-gated cross-eVault read by ontology. Intentionally undocumented in Swagger.
359+
server.get<{ Params: { ontology: string } }>(
360+
"/metaenvelopes/by-ontology/:ontology",
361+
async (request, reply) => {
362+
const authHeader =
363+
request.headers.authorization || request.headers.Authorization;
364+
const tokenPayload = await validateToken(
365+
typeof authHeader === "string" ? authHeader : null,
366+
);
367+
if (!tokenPayload) {
368+
return reply
369+
.status(401)
370+
.send({ error: "Invalid or missing authentication token" });
371+
}
372+
if (!dbService) {
373+
return reply
374+
.status(503)
375+
.send({ error: "Database service unavailable" });
376+
}
377+
try {
378+
const results =
379+
await dbService.findMetaEnvelopesByOntologyAcrossAllENames(
380+
request.params.ontology,
381+
);
382+
return reply.send({ metaEnvelopes: results });
383+
} catch (err) {
384+
request.log.error(err);
385+
return reply
386+
.status(500)
387+
.send({ error: "Failed to fetch meta-envelopes" });
388+
}
389+
},
390+
);
391+
358392
// Watchers signature endpoint - DISABLED: Requires W3ID functionality
359393
// This endpoint is disabled because the eVault no longer creates/manages W3IDs
360394
// The private key is now stored on the user's phone

0 commit comments

Comments
 (0)