/** * @fileoverview Shared WorkOS types: `WorkosAuthInput`, `WorkosPageInfo`, `WorkosOrganizationSummary`, * `WorkosUserSummary`, `WorkosConnectionSummary`, `DryRunResult`, and related shapes plus parsing helpers. * Import from `kody:@kody/workos/types` when typing WorkOS helpers without pulling runtime clients. * * @example * import { type WorkosAuthInput, requireRecord } from 'kody:@kody/workos/types' * const auth: WorkosAuthInput = { account: 'work' } */ export type JsonRecord = Record export type WorkosAuthInput = { /** * Short account alias. `work` → secret `workosApiKey-work`. * `default` / `workos` / omitted → `workosApiKey`. */ account?: string /** User secret name for the WorkOS API key. Defaults to `workosApiKey`. */ secretName?: string } export type WorkosPageInfo = { before: string | null after: string | null } export type WorkosOrganizationSummary = { id: string name: string | null domains: Array externalId: string | null createdAt: string | null updatedAt: string | null } export type WorkosUserSummary = { id: string email: string | null firstName: string | null lastName: string | null emailVerified: boolean | null externalId: string | null createdAt: string | null updatedAt: string | null } export type WorkosConnectionSummary = { id: string name: string | null connectionType: string | null state: string | null organizationId: string | null domains: Array createdAt: string | null updatedAt: string | null } export type WorkosDirectorySummary = { id: string name: string | null type: string | null state: string | null organizationId: string | null domain: string | null createdAt: string | null updatedAt: string | null } export type WorkosDirectoryUserSummary = { id: string idpId: string | null directoryId: string | null organizationId: string | null firstName: string | null lastName: string | null email: string | null state: string | null createdAt: string | null updatedAt: string | null } export type WorkosEventSummary = { id: string event: string | null createdAt: string | null } export type WorkosPortalIntent = | 'sso' | 'dsync' | 'audit_logs' | 'log_streams' | 'domain_verification' | 'certificate_renewal' export type DryRunResult = { dryRun: true wouldCall: T } /** * Shared WorkOS types and parsing helpers for this package. * Import from `kody:@kody/workos/types` when typing other WorkOS exports. * * @returns Catalog of exported type/helper names for agent discovery. * * @example * import types from 'kody:@kody/workos/types' * const catalog = await types() */ export function requireRecord(value: unknown, label: string): JsonRecord { if (!value || typeof value !== 'object' || Array.isArray(value)) { throw new Error(`${label} must be an object.`) } return value as JsonRecord } export function requireString( value: unknown, label: string, options: { allowEmpty?: boolean } = {}, ): string { if (typeof value !== 'string' || (!options.allowEmpty && value.trim().length === 0)) { throw new Error( `${label} must be ${options.allowEmpty ? 'a string' : 'a non-empty string'}.`, ) } return options.allowEmpty ? value : value.trim() } export function optionalString(value: unknown, label: string): string | undefined { if (value === undefined || value === null) return undefined return requireString(value, label) } export function optionalBoolean(value: unknown, label: string): boolean | undefined { if (value === undefined) return undefined if (typeof value !== 'boolean') throw new Error(`${label} must be a boolean.`) return value } export function optionalStringArray(value: unknown, label: string): Array | undefined { if (value === undefined || value === null) return undefined if (!Array.isArray(value)) throw new Error(`${label} must be an array of strings.`) return value.map((item, index) => requireString(item, `${label}[${index}]`)) } export function clampInt( value: unknown, min: number, max: number, fallback: number, label = 'limit', ): number { if (value === undefined || value === null) return fallback if (typeof value !== 'number' || !Number.isInteger(value)) { throw new Error(`${label} must be an integer.`) } if (value < min || value > max) { throw new Error(`${label} must be between ${min} and ${max}.`) } return value } export function compactRecord(value: T): T { const output: JsonRecord = {} for (const [key, item] of Object.entries(value)) { if (item === undefined) continue output[key] = item } return output as T } export function stringField(value: unknown): string | null { return typeof value === 'string' && value.length > 0 ? value : null } export function booleanField(value: unknown): boolean | null { return typeof value === 'boolean' ? value : null } /** * Shared WorkOS types for this package: `WorkosAuthInput`, `WorkosPageInfo`, * `WorkosOrganizationSummary`, `WorkosUserSummary`, `WorkosConnectionSummary`, and related shapes. * Import from `kody:@kody/workos/types` when typing WorkOS helpers without pulling runtime clients. * * @returns Catalog of exported type names for agent discovery. * * @example * import types from 'kody:@kody/workos/types' * const catalog = await types() */ export default async function typesOverview() { return { auth: ['WorkosAuthInput'], models: [ 'WorkosOrganizationSummary', 'WorkosUserSummary', 'WorkosConnectionSummary', 'WorkosDirectorySummary', 'WorkosDirectoryUserSummary', 'WorkosEventSummary', ], } }