diff --git a/packages/context/src/models/contextIdKeys.ts b/packages/context/src/models/contextIdKeys.ts index 42ed7153..90376016 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 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 f6c18df7..e1b88aed 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,18 @@ 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 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" }) + ); + }); + it("guard delegates to handler and passes", () => { const ctx = { organization: "ORG1234" }; expect(() => ContextIdHelper.guard(ctx, "organization")).not.toThrow();