diff --git a/packages/models/src/authorization/authorizationReadModelAdapter.ts b/packages/models/src/authorization/authorizationReadModelAdapter.ts index 881cfb0d52..da80602c04 100644 --- a/packages/models/src/authorization/authorizationReadModelAdapter.ts +++ b/packages/models/src/authorization/authorizationReadModelAdapter.ts @@ -2,8 +2,7 @@ import { ClientReadModel, KeyReadModel, } from "../read-models/authorizationReadModel.js"; -import { Client } from "./client.js"; -import { Key } from "./key.js"; +import { Client, Key } from "./client.js"; export const toReadModelKey = (key: Key): KeyReadModel => ({ ...key, diff --git a/packages/models/src/authorization/client.ts b/packages/models/src/authorization/client.ts index f172ade8df..1570548a46 100644 --- a/packages/models/src/authorization/client.ts +++ b/packages/models/src/authorization/client.ts @@ -1,6 +1,28 @@ import { z } from "zod"; import { ClientId, PurposeId, TenantId, UserId } from "../brandedIds.js"; -import { Key } from "./key.js"; + +export const keyUse = { + sig: "Sig", + enc: "Enc", +} as const; +export const KeyUse = z.enum([ + Object.values(keyUse)[0], + ...Object.values(keyUse).slice(1), +]); +export type KeyUse = z.infer; + +export const Key = z.object({ + clientId: ClientId, + userId: UserId, + kid: z.string(), + name: z.string(), + encodedPem: z.string(), + algorithm: z.string(), + use: KeyUse, + createdAt: z.coerce.date(), +}); + +export type Key = z.infer; export const clientKind = { consumer: "Consumer", @@ -25,3 +47,51 @@ export const Client = z.object({ }); export type Client = z.infer; + +export const KeyWithClient = z.object({ + JWKKey: z.object({ + kty: z.string(), + keyOps: z.array(z.string()).optional(), + use: z.string().optional(), + alg: z.string().optional(), + kid: z.string(), + x5u: z.string().optional(), + x5t: z.string().optional(), + x5tS256: z.string().optional(), + x5c: z.array(z.string()).optional(), + crv: z.string().optional(), + x: z.string().optional(), + y: z.string().optional(), + d: z.string().optional(), + k: z.string().optional(), + n: z.string().optional(), + e: z.string().optional(), + p: z.string().optional(), + q: z.string().optional(), + dp: z.string().optional(), + dq: z.string().optional(), + qi: z.string().optional(), + oth: z + .array( + z.object({ + r: z.string(), + d: z.string(), + t: z.string(), + }) + ) + .optional(), + }), + client: z.object({ + id: ClientId, + consumerId: TenantId, + name: z.string(), + purposes: z.array(PurposeId), + description: z.string().optional(), + users: z.array(UserId), + kind: ClientKind, + createdAt: z.coerce.date(), + keys: z.array(Key), + }), +}); + +export type KeyWithClient = z.infer; diff --git a/packages/models/src/authorization/key.ts b/packages/models/src/authorization/key.ts deleted file mode 100644 index 6111196680..0000000000 --- a/packages/models/src/authorization/key.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { z } from "zod"; -import { ClientId, PurposeId, TenantId, UserId } from "../brandedIds.js"; -import { ClientKind } from "./client.js"; - -export const keyUse = { - sig: "Sig", - enc: "Enc", -} as const; -export const KeyUse = z.enum([ - Object.values(keyUse)[0], - ...Object.values(keyUse).slice(1), -]); -export type KeyUse = z.infer; - -export const Key = z.object({ - clientId: ClientId, - userId: UserId, - kid: z.string(), - name: z.string(), - encodedPem: z.string(), - algorithm: z.string(), - use: KeyUse, - createdAt: z.coerce.date(), -}); - -export type Key = z.infer; - -export const KeyWithClient = z.object({ - JWKKey: z.object({ - kty: z.string(), - keyOps: z.array(z.string()).optional(), - use: z.string().optional(), - alg: z.string().optional(), - kid: z.string(), - x5u: z.string().optional(), - x5t: z.string().optional(), - x5tS256: z.string().optional(), - x5c: z.array(z.string()).optional(), - crv: z.string().optional(), - x: z.string().optional(), - y: z.string().optional(), - d: z.string().optional(), - k: z.string().optional(), - n: z.string().optional(), - e: z.string().optional(), - p: z.string().optional(), - q: z.string().optional(), - dp: z.string().optional(), - dq: z.string().optional(), - qi: z.string().optional(), - oth: z - .array( - z.object({ - r: z.string(), - d: z.string(), - t: z.string(), - }) - ) - .optional(), - }), - client: z.object({ - id: ClientId, - consumerId: TenantId, - name: z.string(), - purposes: z.array(PurposeId), - description: z.string().optional(), - users: z.array(UserId), - kind: ClientKind, - createdAt: z.coerce.date(), - keys: z.array(Key), - }), -}); - -export type KeyWithClient = z.infer; diff --git a/packages/models/src/authorization/protobufConverterFromV1.ts b/packages/models/src/authorization/protobufConverterFromV1.ts index 695bed61e5..1c8b976e82 100644 --- a/packages/models/src/authorization/protobufConverterFromV1.ts +++ b/packages/models/src/authorization/protobufConverterFromV1.ts @@ -5,7 +5,7 @@ import { ClientKindV1, ClientV1 } from "../gen/v1/authorization/client.js"; import { KeyUseV1, KeyV1 } from "../gen/v1/authorization/key.js"; import { bigIntToDate } from "../utils.js"; import { Client, ClientKind, clientKind } from "./client.js"; -import { Key, KeyUse, keyUse } from "./key.js"; +import { Key, KeyUse, keyUse } from "./client.js"; const fromKeyUseV1 = (input: KeyUseV1): KeyUse => { switch (input) { diff --git a/packages/models/src/authorization/protobufConverterFromV2.ts b/packages/models/src/authorization/protobufConverterFromV2.ts index 9bc00a9b44..8af4ae7af9 100644 --- a/packages/models/src/authorization/protobufConverterFromV2.ts +++ b/packages/models/src/authorization/protobufConverterFromV2.ts @@ -4,7 +4,7 @@ import { ClientKindV2, ClientV2 } from "../gen/v2/authorization/client.js"; import { KeyUseV2, KeyV2 } from "../gen/v2/authorization/key.js"; import { bigIntToDate } from "../utils.js"; import { Client, ClientKind, clientKind } from "./client.js"; -import { Key, KeyUse, keyUse } from "./key.js"; +import { Key, KeyUse, keyUse } from "./client.js"; const fromKeyUseV2 = (input: KeyUseV2): KeyUse => { switch (input) { diff --git a/packages/models/src/authorization/protobufConverterToV1.ts b/packages/models/src/authorization/protobufConverterToV1.ts index 20e26b527c..c17137b1ff 100644 --- a/packages/models/src/authorization/protobufConverterToV1.ts +++ b/packages/models/src/authorization/protobufConverterToV1.ts @@ -9,7 +9,7 @@ import { } from "../gen/v1/authorization/client.js"; import { dateToBigInt } from "../utils.js"; import { PurposeId, generateId } from "../brandedIds.js"; -import { Key, KeyUse, keyUse } from "./key.js"; +import { Key, KeyUse, keyUse } from "./client.js"; import { Client, ClientKind, clientKind } from "./client.js"; const clientComponentState = { diff --git a/packages/models/src/authorization/protobufConverterToV2.ts b/packages/models/src/authorization/protobufConverterToV2.ts index 9e5393f858..ea40572e91 100644 --- a/packages/models/src/authorization/protobufConverterToV2.ts +++ b/packages/models/src/authorization/protobufConverterToV2.ts @@ -2,7 +2,7 @@ import { match } from "ts-pattern"; import { dateToBigInt } from "../utils.js"; import { ClientKindV2, ClientV2 } from "../gen/v2/authorization/client.js"; import { KeyUseV2, KeyV2 } from "../gen/v2/authorization/key.js"; -import { Key, KeyUse, keyUse } from "./key.js"; +import { Key, KeyUse, keyUse } from "./client.js"; import { Client, ClientKind, clientKind } from "./client.js"; const toKeyUseV2 = (input: KeyUse): KeyUseV2 => diff --git a/packages/models/src/index.ts b/packages/models/src/index.ts index 0d6651312b..c859107ecd 100644 --- a/packages/models/src/index.ts +++ b/packages/models/src/index.ts @@ -40,7 +40,6 @@ export * from "./purpose/protobufConverterFromV2.js"; export * from "./purpose/protobufConverterToV2.js"; export * from "./authorization/client.js"; -export * from "./authorization/key.js"; export * from "./authorization/authorizationEvents.js"; export * from "./authorization/protobufConverterFromV1.js"; export * from "./authorization/protobufConverterToV1.js"; diff --git a/packages/models/src/read-models/authorizationReadModel.ts b/packages/models/src/read-models/authorizationReadModel.ts index 2cd5a87448..25fed00cda 100644 --- a/packages/models/src/read-models/authorizationReadModel.ts +++ b/packages/models/src/read-models/authorizationReadModel.ts @@ -1,6 +1,6 @@ import { z } from "zod"; import { Client } from "../authorization/client.js"; -import { Key } from "../authorization/key.js"; +import { Key } from "../authorization/client.js"; export const KeyReadModel = Key.extend({ createdAt: z.string().datetime(),