Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/context/src/models/contextIdKeys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2024 IOTA Stiftung.
// Copyright 2026 3Sixty Trade Ltd.
// SPDX-License-Identifier: Apache-2.0.

/**
Expand Down Expand Up @@ -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;

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/context/tests/helpers/contextIdHelper.spec.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -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();
Expand Down
Loading