From 33711cdf891ebd8795d659d7506320ae0bd616ee Mon Sep 17 00:00:00 2001 From: Adrian Sanchez Date: Fri, 23 Oct 2026 12:05:54 +0200 Subject: [PATCH 1/2] feat: add an account context key --- packages/context/src/models/contextIdKeys.ts | 9 ++++++++- .../context/tests/helpers/contextIdHelper.spec.ts | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/context/src/models/contextIdKeys.ts b/packages/context/src/models/contextIdKeys.ts index 42ed71533..a3dd517ea 100644 --- a/packages/context/src/models/contextIdKeys.ts +++ b/packages/context/src/models/contextIdKeys.ts @@ -1,4 +1,5 @@ // Copyright 2024 IOTA Stiftung. +// Copyright 2026 3Sixty Trade Ltd. // SPDX-License-Identifier: Apache-2.0. /** @@ -29,7 +30,13 @@ export const ContextIdKeys = { /** * Standard property type definition for user organization. */ - UserOrganization: "userOrganization" + UserOrganization: "userOrganization", + + /** + * Standard property type definition for account. + * The token subject. This is not a DID. + */ + Account: "account" } as const; /** diff --git a/packages/context/tests/helpers/contextIdHelper.spec.ts b/packages/context/tests/helpers/contextIdHelper.spec.ts index f6c18df7e..e4b740b06 100644 --- a/packages/context/tests/helpers/contextIdHelper.spec.ts +++ b/packages/context/tests/helpers/contextIdHelper.spec.ts @@ -1,8 +1,10 @@ // Copyright 2024 IOTA Stiftung. +// Copyright 2026 3Sixty Trade Ltd. // SPDX-License-Identifier: Apache-2.0. import { Guards } from "@3sixty/core"; import { ContextIdHandlerFactory } from "../../src/factories/contextIdHandlerFactory.js"; import { ContextIdHelper } from "../../src/helpers/contextIdHelper.js"; +import { ContextIdKeys } from "../../src/models/contextIdKeys.js"; import type { IContextIdHandler } from "../../src/models/IContextIdHandler.js"; /** @@ -99,6 +101,17 @@ describe("ContextIdHelper", () => { ); }); + it("guard accepts an account id when no handler is registered", () => { + const ctx = { [ContextIdKeys.Account]: "01932a7e-0000-7000-8000-000000000001" }; + expect(() => ContextIdHelper.guard(ctx, ContextIdKeys.Account)).not.toThrow(); + }); + + it("guard throws when the account id is missing", () => { + expect(() => ContextIdHelper.guard({}, ContextIdKeys.Account)).toThrow( + expect.objectContaining({ name: "GeneralError", message: "contextIdHelper.contextIdMissing" }) + ); + }); + it("guard delegates to handler and passes", () => { const ctx = { organization: "ORG1234" }; expect(() => ContextIdHelper.guard(ctx, "organization")).not.toThrow(); From 58aba1be2d529dc7769beeeb713ca2b8e2be4a73 Mon Sep 17 00:00:00 2001 From: Adrian Sanchez Date: Fri, 23 Oct 2026 13:19:29 +0200 Subject: [PATCH 2/2] fix: pr reviews #1 --- packages/context/src/models/contextIdKeys.ts | 4 ++-- packages/context/tests/helpers/contextIdHelper.spec.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/context/src/models/contextIdKeys.ts b/packages/context/src/models/contextIdKeys.ts index a3dd517ea..90376016f 100644 --- a/packages/context/src/models/contextIdKeys.ts +++ b/packages/context/src/models/contextIdKeys.ts @@ -33,8 +33,8 @@ export const ContextIdKeys = { UserOrganization: "userOrganization", /** - * Standard property type definition for account. - * The token subject. This is not a DID. + * Standard property type definition for account, the stable account identifier. + * Unlike `User` this is not a DID. */ Account: "account" } as const; diff --git a/packages/context/tests/helpers/contextIdHelper.spec.ts b/packages/context/tests/helpers/contextIdHelper.spec.ts index e4b740b06..e1b88aed1 100644 --- a/packages/context/tests/helpers/contextIdHelper.spec.ts +++ b/packages/context/tests/helpers/contextIdHelper.spec.ts @@ -106,9 +106,10 @@ describe("ContextIdHelper", () => { expect(() => ContextIdHelper.guard(ctx, ContextIdKeys.Account)).not.toThrow(); }); - it("guard throws when the account id is missing", () => { - expect(() => ContextIdHelper.guard({}, ContextIdKeys.Account)).toThrow( - expect.objectContaining({ name: "GeneralError", message: "contextIdHelper.contextIdMissing" }) + it("guard rejects an empty account id when no handler is registered", () => { + const ctx = { [ContextIdKeys.Account]: "" }; + expect(() => ContextIdHelper.guard(ctx, ContextIdKeys.Account)).toThrow( + expect.objectContaining({ name: "GuardError", message: "guard.stringEmpty" }) ); });