@htilabs/platform-common-models 0.85.0 → 0.87.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/{index-XWSYon40.d.cts → index-1pWiqEBC.d.cts} +1 -1
- package/dist/{index-Bh1zO_Vu.d.ts → index-uz57Fic9.d.ts} +1 -1
- package/dist/index.cjs +12 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/models/index.d.cts +2 -2
- package/dist/models/index.d.ts +2 -2
- package/dist/org-directory/index.cjs +8 -2
- package/dist/org-directory/index.cjs.map +1 -1
- package/dist/org-directory/index.d.cts +11 -2
- package/dist/org-directory/index.d.ts +11 -2
- package/dist/org-directory/index.js +8 -2
- package/dist/org-directory/index.js.map +1 -1
- package/dist/org-merge/index.cjs +8 -2
- package/dist/org-merge/index.cjs.map +1 -1
- package/dist/org-merge/index.js +8 -2
- package/dist/org-merge/index.js.map +1 -1
- package/dist/points-of-contact/index.cjs +229 -24
- package/dist/points-of-contact/index.cjs.map +1 -1
- package/dist/points-of-contact/index.d.cts +50 -5
- package/dist/points-of-contact/index.d.ts +50 -5
- package/dist/points-of-contact/index.js +226 -23
- package/dist/points-of-contact/index.js.map +1 -1
- package/dist/reader-BmhzOis-.d.ts +273 -0
- package/dist/reader-DfQtdw6n.d.cts +273 -0
- package/dist/schemas/index.cjs +12 -1
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +57 -27
- package/dist/schemas/index.d.ts +57 -27
- package/dist/schemas/index.js +12 -1
- package/dist/schemas/index.js.map +1 -1
- package/dist/seat-logs/index.cjs +815 -0
- package/dist/seat-logs/index.cjs.map +1 -0
- package/dist/seat-logs/index.d.cts +274 -0
- package/dist/seat-logs/index.d.ts +274 -0
- package/dist/seat-logs/index.js +742 -0
- package/dist/seat-logs/index.js.map +1 -0
- package/dist/validation/index.d.cts +1 -1
- package/dist/validation/index.d.ts +1 -1
- package/package.json +6 -1
- package/src/orgDirectory/__tests__/programDetails.test.ts +2 -1
- package/src/orgDirectory/__tests__/programTeamLink.test.ts +107 -0
- package/src/orgDirectory/schemas.ts +8 -1
- package/src/pointsOfContact/__tests__/seatContactLog.test.ts +170 -0
- package/src/pointsOfContact/readRules.ts +22 -4
- package/src/pointsOfContact/reader.ts +95 -1
- package/src/pointsOfContact/schemas.ts +4 -3
- package/src/schemas/organization-program.ts +25 -2
- package/src/seatLogs/__tests__/seatLogs.review.test.ts +222 -0
- package/src/seatLogs/__tests__/seatLogs.test.ts +335 -0
- package/src/seatLogs/index.ts +15 -0
- package/src/seatLogs/log.ts +700 -0
- package/src/seatLogs/personId.ts +100 -0
- package/src/seatLogs/personSlugWordlists.ts +40 -0
- package/src/seatLogs/reader.ts +143 -0
- package/src/seatLogs/schemas.ts +118 -0
- package/dist/{agency-CnVTwLeV.d.ts → agency-BHv54o79.d.ts} +4 -4
- package/dist/{agency-8ufZJJDH.d.cts → agency-Djp57S71.d.cts} +4 -4
- package/dist/{cvcEntry-D787utvP.d.cts → cvcEntry-DAuhe0cd.d.cts} +8 -8
- package/dist/{cvcEntry-D787utvP.d.ts → cvcEntry-DAuhe0cd.d.ts} +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/orgDirectory/vocabulary.ts","../../src/orgDirectory/schemas.ts","../../src/orgDirectory/programDetails.ts","../../src/orgDirectory/orgRecord.ts","../../src/orgDirectory/rules.ts","../../src/orgDirectory/read.ts"],"sourcesContent":["/**\n * The program-row vocabulary of `organizations.programs[]`: the review\n * lifecycle, the lifecycle codes, the live rule and the name key. Pure (no\n * mongoose): `schemas/organization-program.ts` re-exports these, so the\n * Mongoose fragment and the `org-directory` read contract share one source.\n */\n\n// ─── Review status ──────────────────────────────────────────────────\n\n/**\n * Review lifecycle of a program named inside an app (UDD Program\n * `review_status`). The sheet's own words — a lane's `pending_steward` /\n * `declined` never reach the stored row.\n */\nexport const PROGRAM_REVIEW_STATUS = {\n PENDING: \"pending\",\n CONFIRMED: \"confirmed\",\n REJECTED: \"rejected\",\n} as const;\n\nexport type ProgramReviewStatus =\n (typeof PROGRAM_REVIEW_STATUS)[keyof typeof PROGRAM_REVIEW_STATUS];\n\n/** The three values, for `enum:` declarations and Zod `z.enum`. */\nexport const PROGRAM_REVIEW_STATUS_VALUES = Object.freeze([\n PROGRAM_REVIEW_STATUS.PENDING,\n PROGRAM_REVIEW_STATUS.CONFIRMED,\n PROGRAM_REVIEW_STATUS.REJECTED,\n] as const);\n\nexport function isProgramReviewStatus(value: unknown): value is ProgramReviewStatus {\n return (\n typeof value === \"string\" && (PROGRAM_REVIEW_STATUS_VALUES as readonly string[]).includes(value)\n );\n}\n\n// ─── Lifecycle status ───────────────────────────────────────────────\n\n/**\n * The program lifecycle codes the writers store. `active` is what PAVE 2.0's\n * `POST /organizations/:id/programs` writes; `retired` takes a program out of\n * every picker. Absent reads as active.\n */\nexport const PROGRAM_STATUS = {\n ACTIVE: \"active\",\n RETIRED: \"retired\",\n} as const;\n\nexport type ProgramStatus = (typeof PROGRAM_STATUS)[keyof typeof PROGRAM_STATUS];\n\nexport const PROGRAM_STATUS_VALUES = Object.freeze([\n PROGRAM_STATUS.ACTIVE,\n PROGRAM_STATUS.RETIRED,\n] as const);\n\n// ─── Live rule and name key ─────────────────────────────────────────\n\n/**\n * Whether a program row may be OFFERED (and matched by name on an add).\n * A retired or rejected program is not a place anyone can be enrolled today,\n * so pickers do not list it and typing its name mints a new row rather than\n * binding to it (the prototype's independent pre-review catch, 2026-10-06).\n */\nexport function isLiveOrganizationProgram(row: {\n status?: string | null | undefined;\n reviewStatus?: string | null | undefined;\n}): boolean {\n return (\n row.status !== PROGRAM_STATUS.RETIRED && row.reviewStatus !== PROGRAM_REVIEW_STATUS.REJECTED\n );\n}\n\n/**\n * The key two program names match on: trimmed, lower-cased. Canon:\n * `directoryProgramFor` (platform-prototype `src/surveys.jsx` L4233 @\n * `0fa04c1`); PAVE 2.0's `POST /organizations/:id/programs` dedupes the same\n * way.\n */\nexport function programNameKey(name: string): string {\n return name.trim().toLowerCase();\n}\n","/**\n * The stored program row of `organizations.programs[]`, as a Zod schema for\n * readers. The Mongoose definition (`schemas/organization-program.ts`,\n * `organizationProgramSchemaDefinition`) is the write-side twin; a test holds\n * the key lists equal.\n */\n\nimport { z } from \"zod\";\n\nimport { PROGRAM_REVIEW_STATUS_VALUES } from \"./vocabulary.js\";\n\n/** The program row's keys, in the fragment's declaration order. */\nexport const ORGANIZATION_PROGRAM_ROW_KEYS = Object.freeze([\n \"programId\",\n \"name\",\n \"description\",\n \"status\",\n \"defaultSharingPolicy\",\n \"reviewStatus\",\n \"addedBy\",\n \"addedInApp\",\n \"addedInSession\",\n \"programType\",\n \"serviceArea\",\n \"providesRelevantServices\",\n \"operatingStartDate\",\n \"operatingEndDate\",\n \"locationId\",\n \"notes\",\n] as const);\n\nexport type OrganizationProgramRowKey = (typeof ORGANIZATION_PROGRAM_ROW_KEYS)[number];\n\nconst optionalText = z.string().nullish();\n/**\n * A detail field of the Program record. A value of the wrong kind reads as not\n * on record (`undefined`) rather than failing the row: a malformed detail must\n * never hide a program from a picker. `./programDetails.ts` shapes the values.\n */\nconst detailText = z.string().nullish().catch(undefined);\n\n/**\n * One stored program row. `programId` + `name` are required; the rest are\n * optional and may be null. Unknown keys are stripped (a reader never relies\n * on a key outside the fragment). The seven Program-record detail keys\n * (`programType` … `notes`, 0.76.0) never fail the row.\n */\nexport const OrganizationProgramRowSchema = z.object({\n programId: z.string().min(1),\n name: z.string().min(1),\n description: optionalText,\n status: optionalText,\n defaultSharingPolicy: optionalText,\n reviewStatus: z\n .enum(PROGRAM_REVIEW_STATUS_VALUES as unknown as [\"pending\", \"confirmed\", \"rejected\"])\n .nullish(),\n addedBy: optionalText,\n addedInApp: optionalText,\n addedInSession: optionalText,\n programType: detailText,\n serviceArea: detailText,\n providesRelevantServices: z.boolean().nullish().catch(undefined),\n operatingStartDate: detailText,\n operatingEndDate: detailText,\n locationId: detailText,\n notes: detailText,\n});\n\nexport type OrganizationProgramRow = z.infer<typeof OrganizationProgramRowSchema>;\n","/**\n * The Program record's own fields beyond its name, on a stored\n * `organizations.programs[]` row: what kind of program it is, where it\n * serves, whether it provides direct services to victims, when it operates,\n * which of its organization's sites it works from, and notes.\n *\n * Canon: the UDD Program Data Object (`program_type` · `service_area` ·\n * `provides_relevant_services` · `operating_start_date` ·\n * `operating_end_date` · `location_id` · `notes`; profile confirmed by Crysta\n * 2026-10-05) and the Admin Hub's program editor (platform-prototype\n * `src/screens.jsx`, `OrgProgramFields`). Stored camelCase, like the rest of\n * the row. The Platform's program editor has written these since 2026-11-11\n * (platform #148, #155); this module is the Platform's own reader and write\n * shapes (`lib/org-directory/program-details.ts`) made shared, so Thread, PAVE\n * and the Platform read and validate one program the same way.\n *\n * The rules it carries:\n *\n * - NOT ON RECORD IS NULL. Every field is optional. A value of the wrong\n * kind reads as not on record; it never fails the program row.\n * - `providesRelevantServices` has three states: true, false, and null\n * (never asked). Null is never coerced to No.\n * - A date is a real calendar day, `YYYY-MM-DD`, stored as a string.\n * - `programType` is a key of the organization-type codebook (CVC-48\n * `core-referral_entity_category`). This subpath stays free of the\n * codebook, so the reader returns the stored string and the write check\n * takes the caller's type rule: resolve a read with `resolveOrgTypeKey`\n * (`@htilabs/platform-common-models/constants`) and offer only\n * `ORG_TYPE_SELECTABLE_KEYS`.\n * - `locationId` names a site of the program's OWN organization. Whether it\n * is one is the writer's check (it needs the database); the write check\n * here only bounds the string.\n *\n * NO ZOD HERE, on purpose. This package is built with zod 3; the Platform and\n * Thread run zod 4, and a zod-3 field cannot be nested in a zod-4 object. So\n * the write rules are plain data (`PROGRAM_DETAIL_RULES`) and one plain\n * function (`checkProgramDetails`) that any app wraps in its own schema\n * library.\n *\n * Pure: no mongoose, no driver, no codebook import, no schema library.\n */\n\n/** The detail keys, in the program editor's field order. */\nexport const PROGRAM_DETAIL_KEYS = Object.freeze([\n \"programType\",\n \"serviceArea\",\n \"providesRelevantServices\",\n \"operatingStartDate\",\n \"operatingEndDate\",\n \"locationId\",\n \"notes\",\n] as const);\nexport type ProgramDetailKey = (typeof PROGRAM_DETAIL_KEYS)[number];\n\n/** A program's detail fields as a reader sees them (`null` = not on record). */\nexport interface ProgramDetails {\n /** The stored organization-type key (CVC-48), unresolved; null when absent. */\n programType: string | null;\n /** Free text: the service area or jurisdiction. */\n serviceArea: string | null;\n /** Direct services to victims: true, false, or null (never asked; not a No). */\n providesRelevantServices: boolean | null;\n /** A calendar day, `YYYY-MM-DD`. */\n operatingStartDate: string | null;\n /** A calendar day, `YYYY-MM-DD`. */\n operatingEndDate: string | null;\n /** The id of the organization's site the program works from, or null. */\n locationId: string | null;\n notes: string | null;\n}\n\n/** The longest service area the editor stores. */\nexport const PROGRAM_SERVICE_AREA_MAX = 200;\n/** The longest program note the editor stores. */\nexport const PROGRAM_NOTES_MAX = 4000;\n/** The longest site id a program row stores. */\nexport const PROGRAM_LOCATION_ID_MAX = 200;\n\nconst DAY = /^\\d{4}-\\d{2}-\\d{2}$/;\n\n/** A real calendar day in `YYYY-MM-DD` (what a date input sends). */\nexport function isCalendarDay(v: unknown): v is string {\n if (typeof v !== \"string\" || !DAY.test(v)) return false;\n const [y, m, d] = v.split(\"-\").map(Number) as [number, number, number];\n const t = new Date(Date.UTC(y, m - 1, d));\n return t.getUTCFullYear() === y && t.getUTCMonth() === m - 1 && t.getUTCDate() === d;\n}\n\nconst text = (v: unknown): string | null =>\n typeof v === \"string\" && v.trim() ? v.trim() : null;\n\n/**\n * One stored row's detail fields. A value of the wrong kind (a date that is\n * not a calendar day, a non-boolean answer, a blank string) reads as not on\n * record. `programType` is returned as stored (trimmed), not resolved.\n */\nexport function programDetailsOf(raw: unknown): ProgramDetails {\n const r = raw && typeof raw === \"object\" ? (raw as Record<string, unknown>) : {};\n return {\n programType: text(r.programType),\n serviceArea: text(r.serviceArea),\n providesRelevantServices:\n typeof r.providesRelevantServices === \"boolean\" ? r.providesRelevantServices : null,\n operatingStartDate: isCalendarDay(r.operatingStartDate) ? r.operatingStartDate : null,\n operatingEndDate: isCalendarDay(r.operatingEndDate) ? r.operatingEndDate : null,\n locationId: text(r.locationId),\n notes: text(r.notes),\n };\n}\n\n// ─── Write rules (plain data and one plain function; no schema library) ─────\n\n/** What kind of value a detail field holds. */\nexport type ProgramDetailKind = \"orgType\" | \"text\" | \"yesNo\" | \"calendarDay\" | \"siteId\";\n\n/** One detail field's write rule. `maxLength` is counted after trimming. */\nexport interface ProgramDetailRule {\n readonly kind: ProgramDetailKind;\n readonly maxLength?: number;\n}\n\n/**\n * The write rule of every detail field. On every field: an ADD may leave the\n * key out (not on record) and may not send `null`; an EDIT may leave the key\n * out (unchanged) or send `null` (clear the field). Text is trimmed and may\n * not be blank.\n */\nexport const PROGRAM_DETAIL_RULES: Readonly<Record<ProgramDetailKey, ProgramDetailRule>> =\n Object.freeze({\n programType: Object.freeze({ kind: \"orgType\" }),\n serviceArea: Object.freeze({ kind: \"text\", maxLength: PROGRAM_SERVICE_AREA_MAX }),\n providesRelevantServices: Object.freeze({ kind: \"yesNo\" }),\n operatingStartDate: Object.freeze({ kind: \"calendarDay\" }),\n operatingEndDate: Object.freeze({ kind: \"calendarDay\" }),\n locationId: Object.freeze({ kind: \"siteId\", maxLength: PROGRAM_LOCATION_ID_MAX }),\n notes: Object.freeze({ kind: \"text\", maxLength: PROGRAM_NOTES_MAX }),\n } as const);\n\n/** `create`: a program ADD. `patch`: a program EDIT, where `null` clears. */\nexport type ProgramDetailsWriteMode = \"create\" | \"patch\";\n\nexport type ProgramDetailErrorCode =\n | \"null_on_create\"\n | \"wrong_kind\"\n | \"blank\"\n | \"too_long\"\n | \"not_a_calendar_day\"\n | \"type_not_offered\";\n\n/** One refused field of a program write. */\nexport interface ProgramDetailError {\n readonly field: ProgramDetailKey;\n readonly code: ProgramDetailErrorCode;\n readonly message: string;\n}\n\n/**\n * The cleaned detail fields of a write: ONLY the keys the body carried. An\n * absent key is not written. `null` (an edit only) clears the field.\n */\nexport interface ProgramDetailsWrite {\n programType?: string | null;\n serviceArea?: string | null;\n providesRelevantServices?: boolean | null;\n operatingStartDate?: string | null;\n operatingEndDate?: string | null;\n locationId?: string | null;\n notes?: string | null;\n}\n\nexport interface ProgramDetailsCheckOptions {\n readonly mode: ProgramDetailsWriteMode;\n /**\n * The caller's rule for an offered organization type: the key to store, or\n * `null` when the value is not a type a person may choose. Required, because\n * this subpath does not import the codebook (the Platform passes its\n * `offeredWriteKey`).\n */\n readonly programType: (value: unknown) => string | null | undefined;\n}\n\nexport type ProgramDetailsCheck =\n | { readonly ok: true; readonly details: ProgramDetailsWrite }\n | { readonly ok: false; readonly errors: readonly ProgramDetailError[] };\n\nconst MESSAGES: Readonly<Record<ProgramDetailErrorCode, string>> = Object.freeze({\n null_on_create: \"Leave the field out when there is nothing to record.\",\n wrong_kind: \"That value is not the right kind for this field.\",\n blank: \"Leave the field out, or clear it, rather than sending it blank.\",\n too_long: \"That text is too long for this field.\",\n not_a_calendar_day: \"A date is a calendar day, YYYY-MM-DD.\",\n type_not_offered: \"That is not a program type a person can choose.\",\n});\n\n/**\n * Check and clean the detail fields of a program write body. Reads only the\n * seven detail keys; any other key of the body is the caller's to judge.\n *\n * Returns the cleaned details (text trimmed, the type as the key to store), or\n * EVERY refused field, never just the first. A key whose value is `undefined`\n * counts as absent.\n */\nexport function checkProgramDetails(\n body: unknown,\n options: ProgramDetailsCheckOptions,\n): ProgramDetailsCheck {\n const b = body && typeof body === \"object\" ? (body as Record<string, unknown>) : {};\n const details: Record<string, string | boolean | null> = {};\n const errors: ProgramDetailError[] = [];\n const refuse = (field: ProgramDetailKey, code: ProgramDetailErrorCode): void => {\n errors.push({ field, code, message: MESSAGES[code] });\n };\n\n for (const field of PROGRAM_DETAIL_KEYS) {\n const v = b[field];\n if (v === undefined) continue;\n if (v === null) {\n if (options.mode === \"patch\") details[field] = null;\n else refuse(field, \"null_on_create\");\n continue;\n }\n const rule = PROGRAM_DETAIL_RULES[field];\n if (rule.kind === \"yesNo\") {\n if (typeof v === \"boolean\") details[field] = v;\n else refuse(field, \"wrong_kind\");\n } else if (rule.kind === \"orgType\") {\n const key = options.programType(v);\n if (typeof key === \"string\" && key !== \"\") details[field] = key;\n else refuse(field, \"type_not_offered\");\n } else if (typeof v !== \"string\") {\n refuse(field, \"wrong_kind\");\n } else if (rule.kind === \"calendarDay\") {\n if (isCalendarDay(v)) details[field] = v;\n else refuse(field, \"not_a_calendar_day\");\n } else {\n const t = v.trim();\n if (t === \"\") refuse(field, \"blank\");\n else if (rule.maxLength !== undefined && t.length > rule.maxLength) refuse(field, \"too_long\");\n else details[field] = t;\n }\n }\n\n return errors.length > 0\n ? { ok: false, errors }\n : { ok: true, details: details as ProgramDetailsWrite };\n}\n","/**\n * The Org record: the ONE definition of what an `organizations` row holds\n * about an organization, for every app that reads or writes the platform-wide\n * registry (Thread, PAVE, the Platform, auth). Pure: no mongoose, no driver.\n * The Mongoose twin is `schemas/organization.ts` (`addOrgRecordFields`); a\n * package test holds the two key lists equal.\n *\n * ## Canon\n *\n * UDD Org Data Object (Notion `7d71ef14abcd832fa3a6816ebe7a5dd9`, § 1 and § 5;\n * schema of record hti-features `udd-schemas/org/Org.v1.json`): an Org is one\n * real-world organization in the one platform-wide registry. It holds its name\n * (legal and common), its acronym, its required type, its parent when it is a\n * unit of a larger one, the two HMIS victim-service-provider answers, and how\n * it arrived and whether HTI Labs has reviewed it. Crysta, 2026-11-10: \"It\n * shouldn't be different in thread vs. pave. And the data objects for Org need\n * to be the same in both apps.\"\n *\n * ## Stored names\n *\n * The UDD spells these snake_case (`legal_name`, `parent_org_id`, ...). The\n * live platform-db writers use camelCase, so the stored names are the UDD's in\n * camelCase, as for the org-type fields (`schemas/agency.ts`) and the program\n * row (`schemas/organization-program.ts`). Two exceptions. The UDD `acronym` is\n * stored as `shortName`: a top-level `acronym` key marks a pre-pl-958 PAVE row\n * (`organizationRowShape`), and PAVE 2.0 already writes `shortName`. And the\n * UDD `id` (the Org's one identifier, a slug such as `the_spring`) is stored as\n * `key`: Mongoose gives every document an `id` of its own (the `_id` as a\n * string), and the Admin Hub's curated store already names it `key`.\n *\n * ## What is NOT here\n *\n * - `name` and `type`: every writer already stores them. `type` is mid-move\n * from the IC-58 number to the CVC-48 key and each app validates the\n * transition form itself until the migration has run.\n * - The row's tenancy and plumbing (`agencyScope`, `agencyId`, `community`,\n * `canonicalKey`, `status`, `programs`, contact fields): unchanged by this\n * module. {@link ORGANIZATION_ROW_KEYS} lists them so a model can be checked\n * against the whole row.\n */\nimport { z } from \"zod\";\n\nimport {\n PROGRAM_REVIEW_STATUS,\n PROGRAM_REVIEW_STATUS_VALUES,\n type ProgramReviewStatus,\n} from \"./vocabulary.js\";\n\n// ─── Review status ──────────────────────────────────────────────────\n\n/**\n * Review lifecycle of an organization added from inside an app. The same three\n * words, and the same lifecycle, as a program named inside an app (UDD Org\n * § 5 \"how it arrived\"; census item 2: \"the same lifecycle a program named\n * inside an app has\"). Absent on a steward row: nothing to review.\n */\nexport const ORG_REVIEW_STATUS = PROGRAM_REVIEW_STATUS;\nexport const ORG_REVIEW_STATUS_VALUES = PROGRAM_REVIEW_STATUS_VALUES;\nexport type OrgReviewStatus = ProgramReviewStatus;\n\n// ─── Lifecycle status ───────────────────────────────────────────────\n\n/**\n * `organizations.status`: 1 active, 2 inactive (soft-deleted; never removed).\n * The codes auth, Thread and PAVE already store.\n */\nexport const ORGANIZATION_STATUS = { ACTIVE: 1, INACTIVE: 2 } as const;\nexport type OrganizationStatus = (typeof ORGANIZATION_STATUS)[keyof typeof ORGANIZATION_STATUS];\n\n/**\n * Whether an organization may be OFFERED in a picker: active (an absent\n * `status` reads active, as legacy rows carry none) and not declined by HTI\n * Labs. A pending organization IS offered: an organization added inside an app\n * is available everywhere from the moment it is added (UDD Org § 2 scenario 1).\n * A stored reference to an organization that is no longer offered still\n * resolves by id.\n */\nexport function isListedOrganization(row: {\n status?: number | null | undefined;\n reviewStatus?: string | null | undefined;\n}): boolean {\n const active = row.status == null || row.status === ORGANIZATION_STATUS.ACTIVE;\n return active && row.reviewStatus !== ORG_REVIEW_STATUS.REJECTED;\n}\n\n// ─── The record's fields ────────────────────────────────────────────\n\n/**\n * The Org definition's fields beyond `name` and `type`, in the Mongoose\n * fragment's declaration order (`orgRecordSchemaDefinition`).\n */\nexport const ORG_RECORD_FIELD_NAMES = Object.freeze([\n \"key\",\n \"legalName\",\n \"commonName\",\n \"shortName\",\n \"website\",\n \"parentOrgId\",\n \"vsp\",\n \"vspPrivateNonprofit\",\n \"reviewStatus\",\n \"addedInApp\",\n \"addedBy\",\n] as const);\nexport type OrgRecordFieldName = (typeof ORG_RECORD_FIELD_NAMES)[number];\n\n/**\n * Stored on the row today and NOT part of the Org definition (UDD Org § 5,\n * \"As built today, and not part of this definition\"; Org.v1's runtime-overlay\n * five: `isCustom`, `added_in_session`, `added_by_user_id`, `type_override`,\n * `division`). PAVE 2.0 writes them; every model declares\n * them so no app silently drops another app's value. `typeKey` is the CVC-48\n * key PAVE writes beside a numeric `type` and retires with the type migration.\n */\nexport const ORG_AS_BUILT_FIELD_NAMES = Object.freeze([\n \"requiresROI\",\n \"isCustom\",\n \"addedByUserId\",\n \"addedInSession\",\n \"division\",\n \"typeOverride\",\n \"typeKey\",\n] as const);\nexport type OrgAsBuiltFieldName = (typeof ORG_AS_BUILT_FIELD_NAMES)[number];\n\n/** The row's keys every writer already stored before this module. */\nexport const ORGANIZATION_BASE_ROW_KEYS = Object.freeze([\n \"name\",\n \"type\",\n \"phones\",\n \"emails\",\n \"address\",\n \"notes\",\n \"status\",\n \"agencyScope\",\n \"agencyId\",\n \"community\",\n \"canonicalKey\",\n \"isAnonymous\",\n \"programs\",\n] as const);\n\n/**\n * Every top-level key of a shared-shape `organizations` row, the record\n * envelope aside. A model that declares exactly these is the same data object\n * as every other app's (`organizationSchemaIssues`, `schemas/organization.ts`).\n */\nexport const ORGANIZATION_ROW_KEYS = Object.freeze([\n ...ORGANIZATION_BASE_ROW_KEYS,\n ...ORG_RECORD_FIELD_NAMES,\n ...ORG_AS_BUILT_FIELD_NAMES,\n] as const);\nexport type OrganizationRowKey = (typeof ORGANIZATION_ROW_KEYS)[number];\n\n/** The record envelope each app's base document adds; never Org facts. */\nexport const ORGANIZATION_ENVELOPE_KEYS = Object.freeze([\n \"_id\",\n \"__v\",\n \"_schemaVersion\",\n \"createdUser\",\n \"createdTime\",\n \"updatedUser\",\n \"updatedTime\",\n] as const);\n\n// ─── The identifier ─────────────────────────────────────────────────\n\n/**\n * The Org's identifier (UDD Org `id`; stored as `key`): the one value that\n * names the same organization in every database, where `_id` is each\n * database's own. A lower-case slug: `the_spring`, `ascension_stjohn`,\n * `org-custom-8daxtira`, `org-6a1f5dadd0c33a5a149f3413`.\n *\n * Rules (the curated store's, Kickoff 13 item 3): unique; never changes once\n * set; never taken from a request body (`OrgIdentityWriteSchema` is strict and\n * does not name it); a new organization's key never encodes its name\n * ({@link mintOrgKey}). A row written before 0.65.0 has none until the\n * registry fill stamps one from a reviewed sheet.\n */\nexport const ORG_KEY_PATTERN = /^[a-z0-9][a-z0-9_-]{0,119}$/;\n\n/** Whether a value is a well-formed Org identifier. */\nexport function isOrgKey(value: unknown): value is string {\n return typeof value === \"string\" && ORG_KEY_PATTERN.test(value);\n}\n\n/**\n * The identifier for an organization created without one (added inside an\n * app, or by a steward typing a new organization): `org-<its _id>`. It encodes\n * no name, so a later rename never makes it wrong.\n */\nexport function mintOrgKey(id: string | { toHexString(): string }): string {\n const hex = (typeof id === \"string\" ? id : id.toHexString()).trim().toLowerCase();\n if (!/^[0-9a-f]{24}$/.test(hex)) {\n throw new Error(\"mintOrgKey: needs the organization's 24-hex _id\");\n }\n return `org-${hex}`;\n}\n\n// ─── Write shape ────────────────────────────────────────────────────\n\n/** A trimmed, non-empty line of text, or null to clear the field. */\nconst line = (max: number) => z.string().trim().min(1).max(max).nullable();\n\n/** The two-step message; the same sentence the Mongoose mount throws. */\nexport const ORG_VSP_TWO_STEP_MESSAGE =\n \"vspPrivateNonprofit is step 2 of the HMIS VSP two-step and requires vsp: true\";\n\n/**\n * The identity half of the record, as a request body may carry it. Every key\n * is optional (a PATCH names only what it changes); `null` clears a field.\n * Strict: an unknown key is refused, so a snake_case spelling never passes as\n * a silent no-op.\n */\nexport const OrgIdentityWriteSchema = z\n .object({\n legalName: line(300),\n commonName: line(300),\n shortName: line(60),\n website: line(500),\n /** Another organization's id (24-hex or a seed slug). Self-reference is the writer's check. */\n parentOrgId: line(120),\n })\n .partial()\n .strict();\nexport type OrgIdentityWrite = z.infer<typeof OrgIdentityWriteSchema>;\n\n/**\n * The two HMIS victim-service-provider answers. Tri-state: `null` is \"not yet\n * captured\", never a coerced false. Step 2 may be answered only with step 1\n * `true` in the same body (an update cannot see the stored row), and a body\n * that sets step 1 to `false` or `null` clears step 2 with it. Only HTI Labs\n * sets them (UDD Org rulings 2026-10-08 and 2026-10-09); the route decides who\n * that is.\n */\nexport const OrgVspWriteSchema = z\n .object({\n vsp: z.boolean().nullable(),\n vspPrivateNonprofit: z.boolean().nullable(),\n })\n .partial()\n .strict()\n .refine((v) => v.vspPrivateNonprofit == null || v.vsp === true, {\n message: ORG_VSP_TWO_STEP_MESSAGE,\n path: [\"vspPrivateNonprofit\"],\n })\n // Step 1 set to anything but `true` clears step 2 in the same write, so a\n // stored \"yes\" on step 2 can never outlive its step 1.\n .transform((v) => (\"vsp\" in v && v.vsp !== true ? { ...v, vspPrivateNonprofit: null } : v));\nexport type OrgVspWrite = z.infer<typeof OrgVspWriteSchema>;\n\n/**\n * How an organization arrived. Never taken from a request body: the server\n * stamps it from the authenticated caller ({@link orgArrivalStamp}).\n *\n * The same three facts, under the same names, as a Program, a Service Listing\n * and a Point of contact carry (`added_by` · `added_in_app` · `review_status`;\n * UDD ratification request R17, \"how an organization arrived\"). The older\n * runtime-overlay names on the row (`addedByUserId`, `isCustom`) are as-built\n * extras; `addedInSession` is carried as on the program row.\n */\nexport interface OrgArrival {\n reviewStatus: OrgReviewStatus;\n /** The app the organization was added in: `thread`, `pave`, `leads`, `platform`. */\n addedInApp: string;\n /** The adding user's platform `users._id`, as a string. */\n addedBy: string;\n /** The session it was added in, when there was one. */\n addedInSession?: string;\n}\n\n/**\n * The arrival stamp for an organization a user adds from inside an app: it is\n * on the list at once and waits for HTI Labs' review (UDD Org § 2 scenario 5;\n * census item 2). A steward's own add carries no stamp.\n */\nexport function orgArrivalStamp(input: {\n app: string;\n userId: string;\n sessionId?: string | null | undefined;\n}): OrgArrival {\n const app = input.app.trim().toLowerCase();\n const userId = input.userId.trim();\n if (!app) throw new Error(\"orgArrivalStamp: app is required\");\n if (!userId) throw new Error(\"orgArrivalStamp: userId is required\");\n const session = input.sessionId?.trim();\n return {\n reviewStatus: ORG_REVIEW_STATUS.PENDING,\n addedInApp: app,\n addedBy: userId,\n ...(session ? { addedInSession: session } : {}),\n };\n}\n\n// ─── Naming rules ───────────────────────────────────────────────────\n\ninterface OrgNames {\n name?: string | null | undefined;\n commonName?: string | null | undefined;\n legalName?: string | null | undefined;\n shortName?: string | null | undefined;\n}\n\nconst clean = (v: unknown): string => (typeof v === \"string\" ? v.trim() : \"\");\n\n/**\n * The name to use when a sentence or a label names an organization: its common\n * name when it has one, else its name. Canon: the prototype's contact-history\n * register and referral wording (`org.common_name || org.name`).\n */\nexport function orgCommonName(org: OrgNames | null | undefined): string {\n return clean(org?.commonName) || clean(org?.name);\n}\n\n/**\n * The name a report to a funder or HMIS uses: the legal name when captured,\n * else the name (Org.v1 `legal_name`: \"consumers fall back to name when blank\").\n */\nexport function orgLegalName(org: OrgNames | null | undefined): string {\n return clean(org?.legalName) || clean(org?.name);\n}\n\n/** Whether a row's name is nothing but its short name (\"ASJS\" named \"ASJS\"). */\nexport function isShortNameOnly(org: OrgNames | null | undefined): boolean {\n const n = clean(org?.name);\n const a = clean(org?.shortName);\n return !n || (!!a && n.toLowerCase() === a.toLowerCase());\n}\n\n/**\n * How a unit of a larger organization reads: its own name, and \"<parent> unit\"\n * beneath it when the unit has no name beyond its short name (Crysta\n * 2026-09-03, \"No names yet — show the parent\"). A row with a real name keeps\n * it. Canon: the prototype's one resolver, `orgDisplayParts`.\n */\nexport function orgDisplayParts(\n org: OrgNames | null | undefined,\n parent: OrgNames | null | undefined,\n): { name: string; sub: string } {\n const name = clean(org?.name) || clean(org?.shortName);\n const parentName = clean(parent?.name) || clean(parent?.shortName);\n const sub = parentName && isShortNameOnly(org) ? `${parentName} unit` : \"\";\n return { name, sub };\n}\n\n/** {@link orgDisplayParts} on one line: \"ASJS · Ascension St. John Medical Center unit\". */\nexport function orgDisplayName(\n org: OrgNames | null | undefined,\n parent?: OrgNames | null | undefined,\n): string {\n const d = orgDisplayParts(org, parent);\n return d.sub ? `${d.name} · ${d.sub}` : d.name;\n}\n\n/**\n * Why `parentOrgId` may not be set to this value, or null when it may. One\n * level only (the picker folds units under their organization): an\n * organization is never its own parent, a parent is not itself a unit, and an\n * organization that has units cannot become one.\n */\nexport function orgParentIssue(input: {\n orgId: string | null | undefined;\n parentOrgId: string | null | undefined;\n /** The proposed parent's own `parentOrgId`, when the parent row was read. */\n parentsParentOrgId?: string | null | undefined;\n /** Whether any organization already names `orgId` as its parent. */\n hasUnits?: boolean | undefined;\n}): \"self\" | \"parent_is_unit\" | \"org_has_units\" | null {\n const parent = clean(input.parentOrgId).toLowerCase();\n if (!parent) return null;\n if (clean(input.orgId).toLowerCase() === parent) return \"self\";\n if (clean(input.parentsParentOrgId)) return \"parent_is_unit\";\n if (input.hasUnits) return \"org_has_units\";\n return null;\n}\n","/**\n * Read rules for the platform-db org directory: which row shape a document\n * is, when an organization is an agency's OWN record, and the normalised read\n * view every app shares. Pure: no mongoose, no driver.\n *\n * Contract: platform `docs/ORG_DIRECTORY_CONTRACT.md`.\n */\n\nimport { OrganizationProgramRowSchema, type OrganizationProgramRow } from \"./schemas.js\";\nimport { isListedOrganization, isOrgKey, type OrgReviewStatus } from \"./orgRecord.js\";\nimport { programDetailsOf, type ProgramDetails } from \"./programDetails.js\";\nimport { isLiveOrganizationProgram, isProgramReviewStatus } from \"./vocabulary.js\";\n\n/** A driver ObjectId, or anything that prints itself as one. */\nexport interface ObjectIdLike {\n toHexString(): string;\n}\n\n/** An id's comparable string form: an ObjectId's hex, a string as-is, else null. */\nexport function directoryIdString(value: unknown): string | null {\n if (typeof value === \"string\") return value === \"\" ? null : value;\n if (\n value &&\n typeof value === \"object\" &&\n typeof (value as ObjectIdLike).toHexString === \"function\"\n ) {\n return (value as ObjectIdLike).toHexString();\n }\n return null;\n}\n\n/** Two ids name the same row (string vs ObjectId of one hex are the same). Absent is never a match. */\nexport function sameDirectoryId(a: unknown, b: unknown): boolean {\n const x = directoryIdString(a);\n const y = directoryIdString(b);\n return x !== null && y !== null && x.toLowerCase() === y.toLowerCase();\n}\n\n/**\n * Which writer's shape a stored `organizations` row has.\n *\n * - `canonical`: auth / Thread's global singletons (Unknown, Anonymous), marked by `canonicalKey`.\n * - `pave`: PAVE 2.0's legacy own shape (`packages/db/src/models/organization.ts`\n * before pl-958): a string `id`, `acronym`, `location`. Any ONE of the three\n * marks it.\n * - `thread`: the shared Thread / auth / Platform / PAVE (pl-958) shape: a\n * `type` in either stored form — the IC-58 Int (legacy) or a non-empty string\n * (the CVC-48 key). Whether the value is a VALID type is not this rule's\n * question (the subpath stays SOT-free); readers resolve it.\n * - `unknown`: none of the above (no type, `type: null`, an empty string —\n * e.g. the Platform's account rows).\n *\n * The FORM of `type` never decides `pave`: `organizations.type` is moving from\n * the IC-58 Int to the CVC-48 key on every shared row (auth's provisioning\n * writes the key; the `migrate:org-type-keys` script rewrites the rest), so a\n * key string is a shared-shape row. On platform-prod / platform-dev\n * (2026-10-16) every PAVE-shape row carries all three markers and no\n * Thread / auth / canonical row carries any of them.\n */\nexport type OrganizationRowShape = \"canonical\" | \"pave\" | \"thread\" | \"unknown\";\n\nexport function organizationRowShape(raw: unknown): OrganizationRowShape {\n if (!raw || typeof raw !== \"object\") return \"unknown\";\n const r = raw as Record<string, unknown>;\n if (typeof r.canonicalKey === \"string\" && r.canonicalKey !== \"\") return \"canonical\";\n if (typeof r.id === \"string\" || \"acronym\" in r || \"location\" in r) return \"pave\";\n if (typeof r.type === \"number\" || (typeof r.type === \"string\" && r.type.trim() !== \"\")) {\n return \"thread\";\n }\n return \"unknown\";\n}\n\n/**\n * Whether `org` is `agency`'s OWN organization record: both halves of the pair\n * auth's `ensureOrganizationForAgency` writes hold — `org.agencyId` names the\n * agency AND `agency.organizationId` names the org. Neither half alone counts;\n * `agencyScope` (tenancy) never counts.\n */\nexport function isAgencyOwnOrganization(\n org: { _id?: unknown; agencyId?: unknown } | null | undefined,\n agency: { _id?: unknown; organizationId?: unknown } | null | undefined,\n): boolean {\n if (!org || !agency) return false;\n return (\n sameDirectoryId(org.agencyId, agency._id) && sameDirectoryId(agency.organizationId, org._id)\n );\n}\n\n/**\n * One program as readers see it. Since 0.76.0 it carries the Program record's\n * own fields ({@link ProgramDetails}: kind, service area, direct services,\n * operating dates, site, notes), `null` where nothing is on record.\n * `programType` is the stored string; resolve it with `resolveOrgTypeKey`\n * (this subpath stays free of the codebook).\n */\nexport interface DirectoryProgramView extends ProgramDetails {\n programId: string;\n name: string;\n description: string | null;\n status: string | null;\n reviewStatus: OrganizationProgramRow[\"reviewStatus\"] | null;\n addedBy: string | null;\n addedInApp: string | null;\n /** Offered in pickers: not retired, not rejected. */\n live: boolean;\n}\n\n/** One program row as readers see it, or null when it fails the row schema. */\nexport function toDirectoryProgramView(raw: unknown): DirectoryProgramView | null {\n const parsed = OrganizationProgramRowSchema.safeParse(raw);\n if (!parsed.success) return null;\n const p = parsed.data;\n return {\n programId: p.programId,\n name: p.name,\n description: p.description ?? null,\n status: p.status ?? null,\n reviewStatus: p.reviewStatus ?? null,\n addedBy: p.addedBy ?? null,\n addedInApp: p.addedInApp ?? null,\n live: isLiveOrganizationProgram(p),\n ...programDetailsOf(p),\n };\n}\n\nexport interface DirectoryOrganizationView {\n /** `String(_id)`: the id listings and sharing settings key on. */\n id: string;\n shape: OrganizationRowShape;\n name: string;\n /** The stored `type` when it is a number (the legacy IC-58 Int), else null. */\n type: number | null;\n /**\n * The stored `type` when it is a string, else null: a CVC-48\n * `referral_entity_category` key on a shared-shape row once it is migrated\n * (or written by auth's provisioning), and on a legacy PAVE-shape row.\n */\n typeKey: string | null;\n /** PAVE's own string `id` on a PAVE-shape row, else null. */\n paveId: string | null;\n community: string | null;\n /** auth's identity half; see {@link isAgencyOwnOrganization}. */\n agencyId: string | null;\n /** Tenancy scope. Never an identity. */\n agencyScope: string | null;\n canonicalKey: string | null;\n // ── The Org record (`orgRecord.ts`); null = not captured ──\n /** The Org's identifier (the UDD `id`): the same in every database. Null on a row not yet given one. */\n key: string | null;\n legalName: string | null;\n commonName: string | null;\n /**\n * The curated short name (the UDD `acronym`): the stored `shortName`, else a\n * legacy PAVE-shape row's `acronym`. Never derived from the name here.\n */\n shortName: string | null;\n website: string | null;\n /** The organization this one is a unit of. */\n parentOrgId: string | null;\n /** HMIS VSP step 1. Tri-state: null = never captured. */\n vsp: boolean | null;\n /** HMIS VSP step 2. Null unless `vsp` is true. */\n vspPrivateNonprofit: boolean | null;\n /** pending · confirmed · rejected for an organization added inside an app; null on a steward row. */\n reviewStatus: OrgReviewStatus | null;\n addedInApp: string | null;\n /** Who added it (a platform `users._id`); a pre-0.60 row's `addedByUserId` reads here too. */\n addedBy: string | null;\n addedInSession: string | null;\n /** The stored lifecycle code (1 active, 2 inactive), else null. */\n status: number | null;\n /** Offered in pickers: active and not declined (`isListedOrganization`). */\n listed: boolean;\n programs: DirectoryProgramView[];\n /** Program rows that failed the row schema (not returned). */\n invalidPrograms: number;\n}\n\nconst text = (v: unknown): string | null => (typeof v === \"string\" && v !== \"\" ? v : null);\nconst line = (v: unknown): string | null => (typeof v === \"string\" && v.trim() !== \"\" ? v.trim() : null);\nconst flag = (v: unknown): boolean | null => (typeof v === \"boolean\" ? v : null);\n\n/** Normalise a stored row of any writer's shape into the shared read view. */\nexport function toDirectoryOrganizationView(raw: unknown): DirectoryOrganizationView | null {\n if (!raw || typeof raw !== \"object\") return null;\n const r = raw as Record<string, unknown>;\n const id = directoryIdString(r._id);\n if (!id) return null;\n const rows = Array.isArray(r.programs) ? r.programs : [];\n const programs = rows\n .map(toDirectoryProgramView)\n .filter((p): p is DirectoryProgramView => p !== null);\n const vsp = flag(r.vsp);\n const reviewStatus = isProgramReviewStatus(r.reviewStatus) ? r.reviewStatus : null;\n const status = typeof r.status === \"number\" ? r.status : null;\n return {\n id,\n shape: organizationRowShape(r),\n name: text(r.name) ?? \"\",\n type: typeof r.type === \"number\" ? r.type : null,\n typeKey: typeof r.type === \"string\" ? r.type : null,\n paveId: text(r.id),\n community: text(r.community),\n agencyId: directoryIdString(r.agencyId),\n agencyScope: directoryIdString(r.agencyScope),\n canonicalKey: text(r.canonicalKey),\n key: isOrgKey(r.key) ? r.key : null,\n legalName: line(r.legalName),\n commonName: line(r.commonName),\n shortName: line(r.shortName) ?? line(r.acronym),\n website: line(r.website),\n parentOrgId: directoryIdString(r.parentOrgId),\n vsp,\n vspPrivateNonprofit: vsp === true ? flag(r.vspPrivateNonprofit) : null,\n reviewStatus,\n addedInApp: line(r.addedInApp),\n addedBy: line(r.addedBy) ?? line(r.addedByUserId),\n addedInSession: line(r.addedInSession),\n status,\n listed: isListedOrganization({ status, reviewStatus }),\n programs,\n invalidPrograms: rows.length - programs.length,\n };\n}\n","/**\n * The raw-driver reads of the platform-db org directory. No driver import: the\n * readers take any object with the MongoDB driver's\n * `collection(name).findOne(filter, options)` shape, plus a `toObjectId`\n * factory so a 24-hex string id also matches a row stored under an ObjectId\n * (production `organizations._id` and `agencies._id` are ObjectIds).\n */\n\nimport {\n isAgencyOwnOrganization,\n toDirectoryOrganizationView,\n type DirectoryOrganizationView,\n type ObjectIdLike,\n} from \"./rules.js\";\n\nexport const ORGANIZATIONS_COLLECTION = \"organizations\";\nexport const AGENCIES_COLLECTION = \"agencies\";\n\nexport interface OrgDirectoryDbLike {\n collection(name: string): {\n findOne(filter: Record<string, unknown>, options?: Record<string, unknown>): Promise<unknown>;\n };\n}\n\nexport interface OrgDirectoryReadOptions {\n /** Build the driver's ObjectId from 24-hex (e.g. `(h) => new ObjectId(h)`). */\n toObjectId?: (hex: string) => unknown;\n}\n\nconst HEX = /^[0-9a-fA-F]{24}$/;\n\n/** Every stored form of one id: the string, and its ObjectId when 24-hex. */\nexport function organizationIdForms(\n id: string | ObjectIdLike,\n opts: OrgDirectoryReadOptions = {},\n): unknown[] {\n if (typeof id !== \"string\") return [id.toHexString(), id];\n return HEX.test(id) && opts.toObjectId ? [id, opts.toObjectId(id.toLowerCase())] : [id];\n}\n\n/** One organization in the shared view, or null. Read errors propagate. */\nexport async function readDirectoryOrganization(\n db: OrgDirectoryDbLike,\n id: string | ObjectIdLike,\n opts: OrgDirectoryReadOptions = {},\n): Promise<DirectoryOrganizationView | null> {\n const raw = await db\n .collection(ORGANIZATIONS_COLLECTION)\n .findOne({ _id: { $in: organizationIdForms(id, opts) } });\n return raw ? toDirectoryOrganizationView(raw) : null;\n}\n\n/**\n * An agency's OWN organization (both halves of the pair hold), or null — never\n * an organization the agency merely scopes (`agencyScope`) or that points at it\n * from one side only. The agency is looked up by `_id`.\n */\nexport async function readAgencyOwnOrganization(\n db: OrgDirectoryDbLike,\n agencyId: string | ObjectIdLike,\n opts: OrgDirectoryReadOptions = {},\n): Promise<DirectoryOrganizationView | null> {\n const agency = (await db\n .collection(AGENCIES_COLLECTION)\n .findOne(\n { _id: { $in: organizationIdForms(agencyId, opts) } },\n { projection: { _id: 1, organizationId: 1 } },\n )) as { _id?: unknown; organizationId?: unknown } | null;\n if (!agency || agency.organizationId == null) return null;\n const pointer = agency.organizationId as string | ObjectIdLike;\n const org = (await db\n .collection(ORGANIZATIONS_COLLECTION)\n .findOne({ _id: { $in: organizationIdForms(pointer, opts) } })) as {\n _id?: unknown;\n agencyId?: unknown;\n } | null;\n return org && isAgencyOwnOrganization(org, agency) ? toDirectoryOrganizationView(org) : null;\n}\n"],"mappings":";AAcO,IAAM,wBAAwB;AAAA,EACnC,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AACZ;AAMO,IAAM,+BAA+B,OAAO,OAAO;AAAA,EACxD,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,sBAAsB;AACxB,CAAU;AAEH,SAAS,sBAAsB,OAA8C;AAClF,SACE,OAAO,UAAU,YAAa,6BAAmD,SAAS,KAAK;AAEnG;AASO,IAAM,iBAAiB;AAAA,EAC5B,QAAQ;AAAA,EACR,SAAS;AACX;AAIO,IAAM,wBAAwB,OAAO,OAAO;AAAA,EACjD,eAAe;AAAA,EACf,eAAe;AACjB,CAAU;AAUH,SAAS,0BAA0B,KAG9B;AACV,SACE,IAAI,WAAW,eAAe,WAAW,IAAI,iBAAiB,sBAAsB;AAExF;AAQO,SAAS,eAAe,MAAsB;AACnD,SAAO,KAAK,KAAK,EAAE,YAAY;AACjC;;;ACzEA,SAAS,SAAS;AAKX,IAAM,gCAAgC,OAAO,OAAO;AAAA,EACzD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAU;AAIV,IAAM,eAAe,EAAE,OAAO,EAAE,QAAQ;AAMxC,IAAM,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAS;AAQhD,IAAM,+BAA+B,EAAE,OAAO;AAAA,EACnD,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC3B,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACtB,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,sBAAsB;AAAA,EACtB,cAAc,EACX,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ACX,MAAI,OAAO,OAAO,SAAU,QAAO,CAAC,GAAG,YAAY,GAAG,EAAE;AACxD,SAAO,IAAI,KAAK,EAAE,KAAK,KAAK,aAAa,CAAC,IAAI,KAAK,WAAW,GAAG,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE;AACxF;AAGA,eAAsB,0BACpB,IACA,IACA,OAAgC,CAAC,GACU;AAC3C,QAAM,MAAM,MAAM,GACf,WAAW,wBAAwB,EACnC,QAAQ,EAAE,KAAK,EAAE,KAAK,oBAAoB,IAAI,IAAI,EAAE,EAAE,CAAC;AAC1D,SAAO,MAAM,4BAA4B,GAAG,IAAI;AAClD;AAOA,eAAsB,0BACpB,IACA,UACA,OAAgC,CAAC,GACU;AAC3C,QAAM,SAAU,MAAM,GACnB,WAAW,mBAAmB,EAC9B;AAAA,IACC,EAAE,KAAK,EAAE,KAAK,oBAAoB,UAAU,IAAI,EAAE,EAAE;AAAA,IACpD,EAAE,YAAY,EAAE,KAAK,GAAG,gBAAgB,EAAE,EAAE;AAAA,EAC9C;AACF,MAAI,CAAC,UAAU,OAAO,kBAAkB,KAAM,QAAO;AACrD,QAAM,UAAU,OAAO;AACvB,QAAM,MAAO,MAAM,GAChB,WAAW,wBAAwB,EACnC,QAAQ,EAAE,KAAK,EAAE,KAAK,oBAAoB,SAAS,IAAI,EAAE,EAAE,CAAC;AAI/D,SAAO,OAAO,wBAAwB,KAAK,MAAM,IAAI,4BAA4B,GAAG,IAAI;AAC1F;","names":["z","z","text","line"]}
|
|
1
|
+
{"version":3,"sources":["../../src/orgDirectory/vocabulary.ts","../../src/orgDirectory/schemas.ts","../../src/orgDirectory/programDetails.ts","../../src/orgDirectory/orgRecord.ts","../../src/orgDirectory/rules.ts","../../src/orgDirectory/read.ts"],"sourcesContent":["/**\n * The program-row vocabulary of `organizations.programs[]`: the review\n * lifecycle, the lifecycle codes, the live rule and the name key. Pure (no\n * mongoose): `schemas/organization-program.ts` re-exports these, so the\n * Mongoose fragment and the `org-directory` read contract share one source.\n */\n\n// ─── Review status ──────────────────────────────────────────────────\n\n/**\n * Review lifecycle of a program named inside an app (UDD Program\n * `review_status`). The sheet's own words — a lane's `pending_steward` /\n * `declined` never reach the stored row.\n */\nexport const PROGRAM_REVIEW_STATUS = {\n PENDING: \"pending\",\n CONFIRMED: \"confirmed\",\n REJECTED: \"rejected\",\n} as const;\n\nexport type ProgramReviewStatus =\n (typeof PROGRAM_REVIEW_STATUS)[keyof typeof PROGRAM_REVIEW_STATUS];\n\n/** The three values, for `enum:` declarations and Zod `z.enum`. */\nexport const PROGRAM_REVIEW_STATUS_VALUES = Object.freeze([\n PROGRAM_REVIEW_STATUS.PENDING,\n PROGRAM_REVIEW_STATUS.CONFIRMED,\n PROGRAM_REVIEW_STATUS.REJECTED,\n] as const);\n\nexport function isProgramReviewStatus(value: unknown): value is ProgramReviewStatus {\n return (\n typeof value === \"string\" && (PROGRAM_REVIEW_STATUS_VALUES as readonly string[]).includes(value)\n );\n}\n\n// ─── Lifecycle status ───────────────────────────────────────────────\n\n/**\n * The program lifecycle codes the writers store. `active` is what PAVE 2.0's\n * `POST /organizations/:id/programs` writes; `retired` takes a program out of\n * every picker. Absent reads as active.\n */\nexport const PROGRAM_STATUS = {\n ACTIVE: \"active\",\n RETIRED: \"retired\",\n} as const;\n\nexport type ProgramStatus = (typeof PROGRAM_STATUS)[keyof typeof PROGRAM_STATUS];\n\nexport const PROGRAM_STATUS_VALUES = Object.freeze([\n PROGRAM_STATUS.ACTIVE,\n PROGRAM_STATUS.RETIRED,\n] as const);\n\n// ─── Live rule and name key ─────────────────────────────────────────\n\n/**\n * Whether a program row may be OFFERED (and matched by name on an add).\n * A retired or rejected program is not a place anyone can be enrolled today,\n * so pickers do not list it and typing its name mints a new row rather than\n * binding to it (the prototype's independent pre-review catch, 2026-10-06).\n */\nexport function isLiveOrganizationProgram(row: {\n status?: string | null | undefined;\n reviewStatus?: string | null | undefined;\n}): boolean {\n return (\n row.status !== PROGRAM_STATUS.RETIRED && row.reviewStatus !== PROGRAM_REVIEW_STATUS.REJECTED\n );\n}\n\n/**\n * The key two program names match on: trimmed, lower-cased. Canon:\n * `directoryProgramFor` (platform-prototype `src/surveys.jsx` L4233 @\n * `0fa04c1`); PAVE 2.0's `POST /organizations/:id/programs` dedupes the same\n * way.\n */\nexport function programNameKey(name: string): string {\n return name.trim().toLowerCase();\n}\n","/**\n * The stored program row of `organizations.programs[]`, as a Zod schema for\n * readers. The Mongoose definition (`schemas/organization-program.ts`,\n * `organizationProgramSchemaDefinition`) is the write-side twin; a test holds\n * the key lists equal.\n */\n\nimport { z } from \"zod\";\n\nimport { PROGRAM_REVIEW_STATUS_VALUES } from \"./vocabulary.js\";\n\n/** The program row's keys, in the fragment's declaration order. */\nexport const ORGANIZATION_PROGRAM_ROW_KEYS = Object.freeze([\n \"programId\",\n \"name\",\n \"description\",\n \"status\",\n \"defaultSharingPolicy\",\n \"reviewStatus\",\n \"addedBy\",\n \"addedInApp\",\n \"addedInSession\",\n \"programType\",\n \"serviceArea\",\n \"providesRelevantServices\",\n \"operatingStartDate\",\n \"operatingEndDate\",\n \"locationId\",\n \"notes\",\n \"teamId\",\n \"teamIds\",\n] as const);\n\nexport type OrganizationProgramRowKey = (typeof ORGANIZATION_PROGRAM_ROW_KEYS)[number];\n\nconst optionalText = z.string().nullish();\n/**\n * A detail field of the Program record. A value of the wrong kind reads as not\n * on record (`undefined`) rather than failing the row: a malformed detail must\n * never hide a program from a picker. `./programDetails.ts` shapes the values.\n */\nconst detailText = z.string().nullish().catch(undefined);\n\n/**\n * One stored program row. `programId` + `name` are required; the rest are\n * optional and may be null. Unknown keys are stripped (a reader never relies\n * on a key outside the fragment). The seven Program-record detail keys\n * (`programType` … `notes`, 0.76.0) and the team link (`teamId`, `teamIds`,\n * 0.86.0) never fail the row: a value of the wrong kind reads as not on record.\n */\nexport const OrganizationProgramRowSchema = z.object({\n programId: z.string().min(1),\n name: z.string().min(1),\n description: optionalText,\n status: optionalText,\n defaultSharingPolicy: optionalText,\n reviewStatus: z\n .enum(PROGRAM_REVIEW_STATUS_VALUES as unknown as [\"pending\", \"confirmed\", \"rejected\"])\n .nullish(),\n addedBy: optionalText,\n addedInApp: optionalText,\n addedInSession: optionalText,\n programType: detailText,\n serviceArea: detailText,\n providesRelevantServices: z.boolean().nullish().catch(undefined),\n operatingStartDate: detailText,\n operatingEndDate: detailText,\n locationId: detailText,\n notes: detailText,\n /** The first team that works for the program (canon `team_id`). */\n teamId: detailText,\n /** Every team that works for the program (canon `team_ids`). */\n teamIds: z.array(z.string()).nullish().catch(undefined),\n});\n\nexport type OrganizationProgramRow = z.infer<typeof OrganizationProgramRowSchema>;\n","/**\n * The Program record's own fields beyond its name, on a stored\n * `organizations.programs[]` row: what kind of program it is, where it\n * serves, whether it provides direct services to victims, when it operates,\n * which of its organization's sites it works from, and notes.\n *\n * Canon: the UDD Program Data Object (`program_type` · `service_area` ·\n * `provides_relevant_services` · `operating_start_date` ·\n * `operating_end_date` · `location_id` · `notes`; profile confirmed by Crysta\n * 2026-10-05) and the Admin Hub's program editor (platform-prototype\n * `src/screens.jsx`, `OrgProgramFields`). Stored camelCase, like the rest of\n * the row. The Platform's program editor has written these since 2026-11-11\n * (platform #148, #155); this module is the Platform's own reader and write\n * shapes (`lib/org-directory/program-details.ts`) made shared, so Thread, PAVE\n * and the Platform read and validate one program the same way.\n *\n * The rules it carries:\n *\n * - NOT ON RECORD IS NULL. Every field is optional. A value of the wrong\n * kind reads as not on record; it never fails the program row.\n * - `providesRelevantServices` has three states: true, false, and null\n * (never asked). Null is never coerced to No.\n * - A date is a real calendar day, `YYYY-MM-DD`, stored as a string.\n * - `programType` is a key of the organization-type codebook (CVC-48\n * `core-referral_entity_category`). This subpath stays free of the\n * codebook, so the reader returns the stored string and the write check\n * takes the caller's type rule: resolve a read with `resolveOrgTypeKey`\n * (`@htilabs/platform-common-models/constants`) and offer only\n * `ORG_TYPE_SELECTABLE_KEYS`.\n * - `locationId` names a site of the program's OWN organization. Whether it\n * is one is the writer's check (it needs the database); the write check\n * here only bounds the string.\n *\n * NO ZOD HERE, on purpose. This package is built with zod 3; the Platform and\n * Thread run zod 4, and a zod-3 field cannot be nested in a zod-4 object. So\n * the write rules are plain data (`PROGRAM_DETAIL_RULES`) and one plain\n * function (`checkProgramDetails`) that any app wraps in its own schema\n * library.\n *\n * Pure: no mongoose, no driver, no codebook import, no schema library.\n */\n\n/** The detail keys, in the program editor's field order. */\nexport const PROGRAM_DETAIL_KEYS = Object.freeze([\n \"programType\",\n \"serviceArea\",\n \"providesRelevantServices\",\n \"operatingStartDate\",\n \"operatingEndDate\",\n \"locationId\",\n \"notes\",\n] as const);\nexport type ProgramDetailKey = (typeof PROGRAM_DETAIL_KEYS)[number];\n\n/** A program's detail fields as a reader sees them (`null` = not on record). */\nexport interface ProgramDetails {\n /** The stored organization-type key (CVC-48), unresolved; null when absent. */\n programType: string | null;\n /** Free text: the service area or jurisdiction. */\n serviceArea: string | null;\n /** Direct services to victims: true, false, or null (never asked; not a No). */\n providesRelevantServices: boolean | null;\n /** A calendar day, `YYYY-MM-DD`. */\n operatingStartDate: string | null;\n /** A calendar day, `YYYY-MM-DD`. */\n operatingEndDate: string | null;\n /** The id of the organization's site the program works from, or null. */\n locationId: string | null;\n notes: string | null;\n}\n\n/** The longest service area the editor stores. */\nexport const PROGRAM_SERVICE_AREA_MAX = 200;\n/** The longest program note the editor stores. */\nexport const PROGRAM_NOTES_MAX = 4000;\n/** The longest site id a program row stores. */\nexport const PROGRAM_LOCATION_ID_MAX = 200;\n\nconst DAY = /^\\d{4}-\\d{2}-\\d{2}$/;\n\n/** A real calendar day in `YYYY-MM-DD` (what a date input sends). */\nexport function isCalendarDay(v: unknown): v is string {\n if (typeof v !== \"string\" || !DAY.test(v)) return false;\n const [y, m, d] = v.split(\"-\").map(Number) as [number, number, number];\n const t = new Date(Date.UTC(y, m - 1, d));\n return t.getUTCFullYear() === y && t.getUTCMonth() === m - 1 && t.getUTCDate() === d;\n}\n\nconst text = (v: unknown): string | null =>\n typeof v === \"string\" && v.trim() ? v.trim() : null;\n\n/**\n * One stored row's detail fields. A value of the wrong kind (a date that is\n * not a calendar day, a non-boolean answer, a blank string) reads as not on\n * record. `programType` is returned as stored (trimmed), not resolved.\n */\nexport function programDetailsOf(raw: unknown): ProgramDetails {\n const r = raw && typeof raw === \"object\" ? (raw as Record<string, unknown>) : {};\n return {\n programType: text(r.programType),\n serviceArea: text(r.serviceArea),\n providesRelevantServices:\n typeof r.providesRelevantServices === \"boolean\" ? r.providesRelevantServices : null,\n operatingStartDate: isCalendarDay(r.operatingStartDate) ? r.operatingStartDate : null,\n operatingEndDate: isCalendarDay(r.operatingEndDate) ? r.operatingEndDate : null,\n locationId: text(r.locationId),\n notes: text(r.notes),\n };\n}\n\n// ─── Write rules (plain data and one plain function; no schema library) ─────\n\n/** What kind of value a detail field holds. */\nexport type ProgramDetailKind = \"orgType\" | \"text\" | \"yesNo\" | \"calendarDay\" | \"siteId\";\n\n/** One detail field's write rule. `maxLength` is counted after trimming. */\nexport interface ProgramDetailRule {\n readonly kind: ProgramDetailKind;\n readonly maxLength?: number;\n}\n\n/**\n * The write rule of every detail field. On every field: an ADD may leave the\n * key out (not on record) and may not send `null`; an EDIT may leave the key\n * out (unchanged) or send `null` (clear the field). Text is trimmed and may\n * not be blank.\n */\nexport const PROGRAM_DETAIL_RULES: Readonly<Record<ProgramDetailKey, ProgramDetailRule>> =\n Object.freeze({\n programType: Object.freeze({ kind: \"orgType\" }),\n serviceArea: Object.freeze({ kind: \"text\", maxLength: PROGRAM_SERVICE_AREA_MAX }),\n providesRelevantServices: Object.freeze({ kind: \"yesNo\" }),\n operatingStartDate: Object.freeze({ kind: \"calendarDay\" }),\n operatingEndDate: Object.freeze({ kind: \"calendarDay\" }),\n locationId: Object.freeze({ kind: \"siteId\", maxLength: PROGRAM_LOCATION_ID_MAX }),\n notes: Object.freeze({ kind: \"text\", maxLength: PROGRAM_NOTES_MAX }),\n } as const);\n\n/** `create`: a program ADD. `patch`: a program EDIT, where `null` clears. */\nexport type ProgramDetailsWriteMode = \"create\" | \"patch\";\n\nexport type ProgramDetailErrorCode =\n | \"null_on_create\"\n | \"wrong_kind\"\n | \"blank\"\n | \"too_long\"\n | \"not_a_calendar_day\"\n | \"type_not_offered\";\n\n/** One refused field of a program write. */\nexport interface ProgramDetailError {\n readonly field: ProgramDetailKey;\n readonly code: ProgramDetailErrorCode;\n readonly message: string;\n}\n\n/**\n * The cleaned detail fields of a write: ONLY the keys the body carried. An\n * absent key is not written. `null` (an edit only) clears the field.\n */\nexport interface ProgramDetailsWrite {\n programType?: string | null;\n serviceArea?: string | null;\n providesRelevantServices?: boolean | null;\n operatingStartDate?: string | null;\n operatingEndDate?: string | null;\n locationId?: string | null;\n notes?: string | null;\n}\n\nexport interface ProgramDetailsCheckOptions {\n readonly mode: ProgramDetailsWriteMode;\n /**\n * The caller's rule for an offered organization type: the key to store, or\n * `null` when the value is not a type a person may choose. Required, because\n * this subpath does not import the codebook (the Platform passes its\n * `offeredWriteKey`).\n */\n readonly programType: (value: unknown) => string | null | undefined;\n}\n\nexport type ProgramDetailsCheck =\n | { readonly ok: true; readonly details: ProgramDetailsWrite }\n | { readonly ok: false; readonly errors: readonly ProgramDetailError[] };\n\nconst MESSAGES: Readonly<Record<ProgramDetailErrorCode, string>> = Object.freeze({\n null_on_create: \"Leave the field out when there is nothing to record.\",\n wrong_kind: \"That value is not the right kind for this field.\",\n blank: \"Leave the field out, or clear it, rather than sending it blank.\",\n too_long: \"That text is too long for this field.\",\n not_a_calendar_day: \"A date is a calendar day, YYYY-MM-DD.\",\n type_not_offered: \"That is not a program type a person can choose.\",\n});\n\n/**\n * Check and clean the detail fields of a program write body. Reads only the\n * seven detail keys; any other key of the body is the caller's to judge.\n *\n * Returns the cleaned details (text trimmed, the type as the key to store), or\n * EVERY refused field, never just the first. A key whose value is `undefined`\n * counts as absent.\n */\nexport function checkProgramDetails(\n body: unknown,\n options: ProgramDetailsCheckOptions,\n): ProgramDetailsCheck {\n const b = body && typeof body === \"object\" ? (body as Record<string, unknown>) : {};\n const details: Record<string, string | boolean | null> = {};\n const errors: ProgramDetailError[] = [];\n const refuse = (field: ProgramDetailKey, code: ProgramDetailErrorCode): void => {\n errors.push({ field, code, message: MESSAGES[code] });\n };\n\n for (const field of PROGRAM_DETAIL_KEYS) {\n const v = b[field];\n if (v === undefined) continue;\n if (v === null) {\n if (options.mode === \"patch\") details[field] = null;\n else refuse(field, \"null_on_create\");\n continue;\n }\n const rule = PROGRAM_DETAIL_RULES[field];\n if (rule.kind === \"yesNo\") {\n if (typeof v === \"boolean\") details[field] = v;\n else refuse(field, \"wrong_kind\");\n } else if (rule.kind === \"orgType\") {\n const key = options.programType(v);\n if (typeof key === \"string\" && key !== \"\") details[field] = key;\n else refuse(field, \"type_not_offered\");\n } else if (typeof v !== \"string\") {\n refuse(field, \"wrong_kind\");\n } else if (rule.kind === \"calendarDay\") {\n if (isCalendarDay(v)) details[field] = v;\n else refuse(field, \"not_a_calendar_day\");\n } else {\n const t = v.trim();\n if (t === \"\") refuse(field, \"blank\");\n else if (rule.maxLength !== undefined && t.length > rule.maxLength) refuse(field, \"too_long\");\n else details[field] = t;\n }\n }\n\n return errors.length > 0\n ? { ok: false, errors }\n : { ok: true, details: details as ProgramDetailsWrite };\n}\n","/**\n * The Org record: the ONE definition of what an `organizations` row holds\n * about an organization, for every app that reads or writes the platform-wide\n * registry (Thread, PAVE, the Platform, auth). Pure: no mongoose, no driver.\n * The Mongoose twin is `schemas/organization.ts` (`addOrgRecordFields`); a\n * package test holds the two key lists equal.\n *\n * ## Canon\n *\n * UDD Org Data Object (Notion `7d71ef14abcd832fa3a6816ebe7a5dd9`, § 1 and § 5;\n * schema of record hti-features `udd-schemas/org/Org.v1.json`): an Org is one\n * real-world organization in the one platform-wide registry. It holds its name\n * (legal and common), its acronym, its required type, its parent when it is a\n * unit of a larger one, the two HMIS victim-service-provider answers, and how\n * it arrived and whether HTI Labs has reviewed it. Crysta, 2026-11-10: \"It\n * shouldn't be different in thread vs. pave. And the data objects for Org need\n * to be the same in both apps.\"\n *\n * ## Stored names\n *\n * The UDD spells these snake_case (`legal_name`, `parent_org_id`, ...). The\n * live platform-db writers use camelCase, so the stored names are the UDD's in\n * camelCase, as for the org-type fields (`schemas/agency.ts`) and the program\n * row (`schemas/organization-program.ts`). Two exceptions. The UDD `acronym` is\n * stored as `shortName`: a top-level `acronym` key marks a pre-pl-958 PAVE row\n * (`organizationRowShape`), and PAVE 2.0 already writes `shortName`. And the\n * UDD `id` (the Org's one identifier, a slug such as `the_spring`) is stored as\n * `key`: Mongoose gives every document an `id` of its own (the `_id` as a\n * string), and the Admin Hub's curated store already names it `key`.\n *\n * ## What is NOT here\n *\n * - `name` and `type`: every writer already stores them. `type` is mid-move\n * from the IC-58 number to the CVC-48 key and each app validates the\n * transition form itself until the migration has run.\n * - The row's tenancy and plumbing (`agencyScope`, `agencyId`, `community`,\n * `canonicalKey`, `status`, `programs`, contact fields): unchanged by this\n * module. {@link ORGANIZATION_ROW_KEYS} lists them so a model can be checked\n * against the whole row.\n */\nimport { z } from \"zod\";\n\nimport {\n PROGRAM_REVIEW_STATUS,\n PROGRAM_REVIEW_STATUS_VALUES,\n type ProgramReviewStatus,\n} from \"./vocabulary.js\";\n\n// ─── Review status ──────────────────────────────────────────────────\n\n/**\n * Review lifecycle of an organization added from inside an app. The same three\n * words, and the same lifecycle, as a program named inside an app (UDD Org\n * § 5 \"how it arrived\"; census item 2: \"the same lifecycle a program named\n * inside an app has\"). Absent on a steward row: nothing to review.\n */\nexport const ORG_REVIEW_STATUS = PROGRAM_REVIEW_STATUS;\nexport const ORG_REVIEW_STATUS_VALUES = PROGRAM_REVIEW_STATUS_VALUES;\nexport type OrgReviewStatus = ProgramReviewStatus;\n\n// ─── Lifecycle status ───────────────────────────────────────────────\n\n/**\n * `organizations.status`: 1 active, 2 inactive (soft-deleted; never removed).\n * The codes auth, Thread and PAVE already store.\n */\nexport const ORGANIZATION_STATUS = { ACTIVE: 1, INACTIVE: 2 } as const;\nexport type OrganizationStatus = (typeof ORGANIZATION_STATUS)[keyof typeof ORGANIZATION_STATUS];\n\n/**\n * Whether an organization may be OFFERED in a picker: active (an absent\n * `status` reads active, as legacy rows carry none) and not declined by HTI\n * Labs. A pending organization IS offered: an organization added inside an app\n * is available everywhere from the moment it is added (UDD Org § 2 scenario 1).\n * A stored reference to an organization that is no longer offered still\n * resolves by id.\n */\nexport function isListedOrganization(row: {\n status?: number | null | undefined;\n reviewStatus?: string | null | undefined;\n}): boolean {\n const active = row.status == null || row.status === ORGANIZATION_STATUS.ACTIVE;\n return active && row.reviewStatus !== ORG_REVIEW_STATUS.REJECTED;\n}\n\n// ─── The record's fields ────────────────────────────────────────────\n\n/**\n * The Org definition's fields beyond `name` and `type`, in the Mongoose\n * fragment's declaration order (`orgRecordSchemaDefinition`).\n */\nexport const ORG_RECORD_FIELD_NAMES = Object.freeze([\n \"key\",\n \"legalName\",\n \"commonName\",\n \"shortName\",\n \"website\",\n \"parentOrgId\",\n \"vsp\",\n \"vspPrivateNonprofit\",\n \"reviewStatus\",\n \"addedInApp\",\n \"addedBy\",\n] as const);\nexport type OrgRecordFieldName = (typeof ORG_RECORD_FIELD_NAMES)[number];\n\n/**\n * Stored on the row today and NOT part of the Org definition (UDD Org § 5,\n * \"As built today, and not part of this definition\"; Org.v1's runtime-overlay\n * five: `isCustom`, `added_in_session`, `added_by_user_id`, `type_override`,\n * `division`). PAVE 2.0 writes them; every model declares\n * them so no app silently drops another app's value. `typeKey` is the CVC-48\n * key PAVE writes beside a numeric `type` and retires with the type migration.\n */\nexport const ORG_AS_BUILT_FIELD_NAMES = Object.freeze([\n \"requiresROI\",\n \"isCustom\",\n \"addedByUserId\",\n \"addedInSession\",\n \"division\",\n \"typeOverride\",\n \"typeKey\",\n] as const);\nexport type OrgAsBuiltFieldName = (typeof ORG_AS_BUILT_FIELD_NAMES)[number];\n\n/** The row's keys every writer already stored before this module. */\nexport const ORGANIZATION_BASE_ROW_KEYS = Object.freeze([\n \"name\",\n \"type\",\n \"phones\",\n \"emails\",\n \"address\",\n \"notes\",\n \"status\",\n \"agencyScope\",\n \"agencyId\",\n \"community\",\n \"canonicalKey\",\n \"isAnonymous\",\n \"programs\",\n] as const);\n\n/**\n * Every top-level key of a shared-shape `organizations` row, the record\n * envelope aside. A model that declares exactly these is the same data object\n * as every other app's (`organizationSchemaIssues`, `schemas/organization.ts`).\n */\nexport const ORGANIZATION_ROW_KEYS = Object.freeze([\n ...ORGANIZATION_BASE_ROW_KEYS,\n ...ORG_RECORD_FIELD_NAMES,\n ...ORG_AS_BUILT_FIELD_NAMES,\n] as const);\nexport type OrganizationRowKey = (typeof ORGANIZATION_ROW_KEYS)[number];\n\n/** The record envelope each app's base document adds; never Org facts. */\nexport const ORGANIZATION_ENVELOPE_KEYS = Object.freeze([\n \"_id\",\n \"__v\",\n \"_schemaVersion\",\n \"createdUser\",\n \"createdTime\",\n \"updatedUser\",\n \"updatedTime\",\n] as const);\n\n// ─── The identifier ─────────────────────────────────────────────────\n\n/**\n * The Org's identifier (UDD Org `id`; stored as `key`): the one value that\n * names the same organization in every database, where `_id` is each\n * database's own. A lower-case slug: `the_spring`, `ascension_stjohn`,\n * `org-custom-8daxtira`, `org-6a1f5dadd0c33a5a149f3413`.\n *\n * Rules (the curated store's, Kickoff 13 item 3): unique; never changes once\n * set; never taken from a request body (`OrgIdentityWriteSchema` is strict and\n * does not name it); a new organization's key never encodes its name\n * ({@link mintOrgKey}). A row written before 0.65.0 has none until the\n * registry fill stamps one from a reviewed sheet.\n */\nexport const ORG_KEY_PATTERN = /^[a-z0-9][a-z0-9_-]{0,119}$/;\n\n/** Whether a value is a well-formed Org identifier. */\nexport function isOrgKey(value: unknown): value is string {\n return typeof value === \"string\" && ORG_KEY_PATTERN.test(value);\n}\n\n/**\n * The identifier for an organization created without one (added inside an\n * app, or by a steward typing a new organization): `org-<its _id>`. It encodes\n * no name, so a later rename never makes it wrong.\n */\nexport function mintOrgKey(id: string | { toHexString(): string }): string {\n const hex = (typeof id === \"string\" ? id : id.toHexString()).trim().toLowerCase();\n if (!/^[0-9a-f]{24}$/.test(hex)) {\n throw new Error(\"mintOrgKey: needs the organization's 24-hex _id\");\n }\n return `org-${hex}`;\n}\n\n// ─── Write shape ────────────────────────────────────────────────────\n\n/** A trimmed, non-empty line of text, or null to clear the field. */\nconst line = (max: number) => z.string().trim().min(1).max(max).nullable();\n\n/** The two-step message; the same sentence the Mongoose mount throws. */\nexport const ORG_VSP_TWO_STEP_MESSAGE =\n \"vspPrivateNonprofit is step 2 of the HMIS VSP two-step and requires vsp: true\";\n\n/**\n * The identity half of the record, as a request body may carry it. Every key\n * is optional (a PATCH names only what it changes); `null` clears a field.\n * Strict: an unknown key is refused, so a snake_case spelling never passes as\n * a silent no-op.\n */\nexport const OrgIdentityWriteSchema = z\n .object({\n legalName: line(300),\n commonName: line(300),\n shortName: line(60),\n website: line(500),\n /** Another organization's id (24-hex or a seed slug). Self-reference is the writer's check. */\n parentOrgId: line(120),\n })\n .partial()\n .strict();\nexport type OrgIdentityWrite = z.infer<typeof OrgIdentityWriteSchema>;\n\n/**\n * The two HMIS victim-service-provider answers. Tri-state: `null` is \"not yet\n * captured\", never a coerced false. Step 2 may be answered only with step 1\n * `true` in the same body (an update cannot see the stored row), and a body\n * that sets step 1 to `false` or `null` clears step 2 with it. Only HTI Labs\n * sets them (UDD Org rulings 2026-10-08 and 2026-10-09); the route decides who\n * that is.\n */\nexport const OrgVspWriteSchema = z\n .object({\n vsp: z.boolean().nullable(),\n vspPrivateNonprofit: z.boolean().nullable(),\n })\n .partial()\n .strict()\n .refine((v) => v.vspPrivateNonprofit == null || v.vsp === true, {\n message: ORG_VSP_TWO_STEP_MESSAGE,\n path: [\"vspPrivateNonprofit\"],\n })\n // Step 1 set to anything but `true` clears step 2 in the same write, so a\n // stored \"yes\" on step 2 can never outlive its step 1.\n .transform((v) => (\"vsp\" in v && v.vsp !== true ? { ...v, vspPrivateNonprofit: null } : v));\nexport type OrgVspWrite = z.infer<typeof OrgVspWriteSchema>;\n\n/**\n * How an organization arrived. Never taken from a request body: the server\n * stamps it from the authenticated caller ({@link orgArrivalStamp}).\n *\n * The same three facts, under the same names, as a Program, a Service Listing\n * and a Point of contact carry (`added_by` · `added_in_app` · `review_status`;\n * UDD ratification request R17, \"how an organization arrived\"). The older\n * runtime-overlay names on the row (`addedByUserId`, `isCustom`) are as-built\n * extras; `addedInSession` is carried as on the program row.\n */\nexport interface OrgArrival {\n reviewStatus: OrgReviewStatus;\n /** The app the organization was added in: `thread`, `pave`, `leads`, `platform`. */\n addedInApp: string;\n /** The adding user's platform `users._id`, as a string. */\n addedBy: string;\n /** The session it was added in, when there was one. */\n addedInSession?: string;\n}\n\n/**\n * The arrival stamp for an organization a user adds from inside an app: it is\n * on the list at once and waits for HTI Labs' review (UDD Org § 2 scenario 5;\n * census item 2). A steward's own add carries no stamp.\n */\nexport function orgArrivalStamp(input: {\n app: string;\n userId: string;\n sessionId?: string | null | undefined;\n}): OrgArrival {\n const app = input.app.trim().toLowerCase();\n const userId = input.userId.trim();\n if (!app) throw new Error(\"orgArrivalStamp: app is required\");\n if (!userId) throw new Error(\"orgArrivalStamp: userId is required\");\n const session = input.sessionId?.trim();\n return {\n reviewStatus: ORG_REVIEW_STATUS.PENDING,\n addedInApp: app,\n addedBy: userId,\n ...(session ? { addedInSession: session } : {}),\n };\n}\n\n// ─── Naming rules ───────────────────────────────────────────────────\n\ninterface OrgNames {\n name?: string | null | undefined;\n commonName?: string | null | undefined;\n legalName?: string | null | undefined;\n shortName?: string | null | undefined;\n}\n\nconst clean = (v: unknown): string => (typeof v === \"string\" ? v.trim() : \"\");\n\n/**\n * The name to use when a sentence or a label names an organization: its common\n * name when it has one, else its name. Canon: the prototype's contact-history\n * register and referral wording (`org.common_name || org.name`).\n */\nexport function orgCommonName(org: OrgNames | null | undefined): string {\n return clean(org?.commonName) || clean(org?.name);\n}\n\n/**\n * The name a report to a funder or HMIS uses: the legal name when captured,\n * else the name (Org.v1 `legal_name`: \"consumers fall back to name when blank\").\n */\nexport function orgLegalName(org: OrgNames | null | undefined): string {\n return clean(org?.legalName) || clean(org?.name);\n}\n\n/** Whether a row's name is nothing but its short name (\"ASJS\" named \"ASJS\"). */\nexport function isShortNameOnly(org: OrgNames | null | undefined): boolean {\n const n = clean(org?.name);\n const a = clean(org?.shortName);\n return !n || (!!a && n.toLowerCase() === a.toLowerCase());\n}\n\n/**\n * How a unit of a larger organization reads: its own name, and \"<parent> unit\"\n * beneath it when the unit has no name beyond its short name (Crysta\n * 2026-09-03, \"No names yet — show the parent\"). A row with a real name keeps\n * it. Canon: the prototype's one resolver, `orgDisplayParts`.\n */\nexport function orgDisplayParts(\n org: OrgNames | null | undefined,\n parent: OrgNames | null | undefined,\n): { name: string; sub: string } {\n const name = clean(org?.name) || clean(org?.shortName);\n const parentName = clean(parent?.name) || clean(parent?.shortName);\n const sub = parentName && isShortNameOnly(org) ? `${parentName} unit` : \"\";\n return { name, sub };\n}\n\n/** {@link orgDisplayParts} on one line: \"ASJS · Ascension St. John Medical Center unit\". */\nexport function orgDisplayName(\n org: OrgNames | null | undefined,\n parent?: OrgNames | null | undefined,\n): string {\n const d = orgDisplayParts(org, parent);\n return d.sub ? `${d.name} · ${d.sub}` : d.name;\n}\n\n/**\n * Why `parentOrgId` may not be set to this value, or null when it may. One\n * level only (the picker folds units under their organization): an\n * organization is never its own parent, a parent is not itself a unit, and an\n * organization that has units cannot become one.\n */\nexport function orgParentIssue(input: {\n orgId: string | null | undefined;\n parentOrgId: string | null | undefined;\n /** The proposed parent's own `parentOrgId`, when the parent row was read. */\n parentsParentOrgId?: string | null | undefined;\n /** Whether any organization already names `orgId` as its parent. */\n hasUnits?: boolean | undefined;\n}): \"self\" | \"parent_is_unit\" | \"org_has_units\" | null {\n const parent = clean(input.parentOrgId).toLowerCase();\n if (!parent) return null;\n if (clean(input.orgId).toLowerCase() === parent) return \"self\";\n if (clean(input.parentsParentOrgId)) return \"parent_is_unit\";\n if (input.hasUnits) return \"org_has_units\";\n return null;\n}\n","/**\n * Read rules for the platform-db org directory: which row shape a document\n * is, when an organization is an agency's OWN record, and the normalised read\n * view every app shares. Pure: no mongoose, no driver.\n *\n * Contract: platform `docs/ORG_DIRECTORY_CONTRACT.md`.\n */\n\nimport { OrganizationProgramRowSchema, type OrganizationProgramRow } from \"./schemas.js\";\nimport { isListedOrganization, isOrgKey, type OrgReviewStatus } from \"./orgRecord.js\";\nimport { programDetailsOf, type ProgramDetails } from \"./programDetails.js\";\nimport { isLiveOrganizationProgram, isProgramReviewStatus } from \"./vocabulary.js\";\n\n/** A driver ObjectId, or anything that prints itself as one. */\nexport interface ObjectIdLike {\n toHexString(): string;\n}\n\n/** An id's comparable string form: an ObjectId's hex, a string as-is, else null. */\nexport function directoryIdString(value: unknown): string | null {\n if (typeof value === \"string\") return value === \"\" ? null : value;\n if (\n value &&\n typeof value === \"object\" &&\n typeof (value as ObjectIdLike).toHexString === \"function\"\n ) {\n return (value as ObjectIdLike).toHexString();\n }\n return null;\n}\n\n/** Two ids name the same row (string vs ObjectId of one hex are the same). Absent is never a match. */\nexport function sameDirectoryId(a: unknown, b: unknown): boolean {\n const x = directoryIdString(a);\n const y = directoryIdString(b);\n return x !== null && y !== null && x.toLowerCase() === y.toLowerCase();\n}\n\n/**\n * Which writer's shape a stored `organizations` row has.\n *\n * - `canonical`: auth / Thread's global singletons (Unknown, Anonymous), marked by `canonicalKey`.\n * - `pave`: PAVE 2.0's legacy own shape (`packages/db/src/models/organization.ts`\n * before pl-958): a string `id`, `acronym`, `location`. Any ONE of the three\n * marks it.\n * - `thread`: the shared Thread / auth / Platform / PAVE (pl-958) shape: a\n * `type` in either stored form — the IC-58 Int (legacy) or a non-empty string\n * (the CVC-48 key). Whether the value is a VALID type is not this rule's\n * question (the subpath stays SOT-free); readers resolve it.\n * - `unknown`: none of the above (no type, `type: null`, an empty string —\n * e.g. the Platform's account rows).\n *\n * The FORM of `type` never decides `pave`: `organizations.type` is moving from\n * the IC-58 Int to the CVC-48 key on every shared row (auth's provisioning\n * writes the key; the `migrate:org-type-keys` script rewrites the rest), so a\n * key string is a shared-shape row. On platform-prod / platform-dev\n * (2026-10-16) every PAVE-shape row carries all three markers and no\n * Thread / auth / canonical row carries any of them.\n */\nexport type OrganizationRowShape = \"canonical\" | \"pave\" | \"thread\" | \"unknown\";\n\nexport function organizationRowShape(raw: unknown): OrganizationRowShape {\n if (!raw || typeof raw !== \"object\") return \"unknown\";\n const r = raw as Record<string, unknown>;\n if (typeof r.canonicalKey === \"string\" && r.canonicalKey !== \"\") return \"canonical\";\n if (typeof r.id === \"string\" || \"acronym\" in r || \"location\" in r) return \"pave\";\n if (typeof r.type === \"number\" || (typeof r.type === \"string\" && r.type.trim() !== \"\")) {\n return \"thread\";\n }\n return \"unknown\";\n}\n\n/**\n * Whether `org` is `agency`'s OWN organization record: both halves of the pair\n * auth's `ensureOrganizationForAgency` writes hold — `org.agencyId` names the\n * agency AND `agency.organizationId` names the org. Neither half alone counts;\n * `agencyScope` (tenancy) never counts.\n */\nexport function isAgencyOwnOrganization(\n org: { _id?: unknown; agencyId?: unknown } | null | undefined,\n agency: { _id?: unknown; organizationId?: unknown } | null | undefined,\n): boolean {\n if (!org || !agency) return false;\n return (\n sameDirectoryId(org.agencyId, agency._id) && sameDirectoryId(agency.organizationId, org._id)\n );\n}\n\n/**\n * One program as readers see it. Since 0.76.0 it carries the Program record's\n * own fields ({@link ProgramDetails}: kind, service area, direct services,\n * operating dates, site, notes), `null` where nothing is on record.\n * `programType` is the stored string; resolve it with `resolveOrgTypeKey`\n * (this subpath stays free of the codebook).\n */\nexport interface DirectoryProgramView extends ProgramDetails {\n programId: string;\n name: string;\n description: string | null;\n status: string | null;\n reviewStatus: OrganizationProgramRow[\"reviewStatus\"] | null;\n addedBy: string | null;\n addedInApp: string | null;\n /** Offered in pickers: not retired, not rejected. */\n live: boolean;\n}\n\n/** One program row as readers see it, or null when it fails the row schema. */\nexport function toDirectoryProgramView(raw: unknown): DirectoryProgramView | null {\n const parsed = OrganizationProgramRowSchema.safeParse(raw);\n if (!parsed.success) return null;\n const p = parsed.data;\n return {\n programId: p.programId,\n name: p.name,\n description: p.description ?? null,\n status: p.status ?? null,\n reviewStatus: p.reviewStatus ?? null,\n addedBy: p.addedBy ?? null,\n addedInApp: p.addedInApp ?? null,\n live: isLiveOrganizationProgram(p),\n ...programDetailsOf(p),\n };\n}\n\nexport interface DirectoryOrganizationView {\n /** `String(_id)`: the id listings and sharing settings key on. */\n id: string;\n shape: OrganizationRowShape;\n name: string;\n /** The stored `type` when it is a number (the legacy IC-58 Int), else null. */\n type: number | null;\n /**\n * The stored `type` when it is a string, else null: a CVC-48\n * `referral_entity_category` key on a shared-shape row once it is migrated\n * (or written by auth's provisioning), and on a legacy PAVE-shape row.\n */\n typeKey: string | null;\n /** PAVE's own string `id` on a PAVE-shape row, else null. */\n paveId: string | null;\n community: string | null;\n /** auth's identity half; see {@link isAgencyOwnOrganization}. */\n agencyId: string | null;\n /** Tenancy scope. Never an identity. */\n agencyScope: string | null;\n canonicalKey: string | null;\n // ── The Org record (`orgRecord.ts`); null = not captured ──\n /** The Org's identifier (the UDD `id`): the same in every database. Null on a row not yet given one. */\n key: string | null;\n legalName: string | null;\n commonName: string | null;\n /**\n * The curated short name (the UDD `acronym`): the stored `shortName`, else a\n * legacy PAVE-shape row's `acronym`. Never derived from the name here.\n */\n shortName: string | null;\n website: string | null;\n /** The organization this one is a unit of. */\n parentOrgId: string | null;\n /** HMIS VSP step 1. Tri-state: null = never captured. */\n vsp: boolean | null;\n /** HMIS VSP step 2. Null unless `vsp` is true. */\n vspPrivateNonprofit: boolean | null;\n /** pending · confirmed · rejected for an organization added inside an app; null on a steward row. */\n reviewStatus: OrgReviewStatus | null;\n addedInApp: string | null;\n /** Who added it (a platform `users._id`); a pre-0.60 row's `addedByUserId` reads here too. */\n addedBy: string | null;\n addedInSession: string | null;\n /** The stored lifecycle code (1 active, 2 inactive), else null. */\n status: number | null;\n /** Offered in pickers: active and not declined (`isListedOrganization`). */\n listed: boolean;\n programs: DirectoryProgramView[];\n /** Program rows that failed the row schema (not returned). */\n invalidPrograms: number;\n}\n\nconst text = (v: unknown): string | null => (typeof v === \"string\" && v !== \"\" ? v : null);\nconst line = (v: unknown): string | null => (typeof v === \"string\" && v.trim() !== \"\" ? v.trim() : null);\nconst flag = (v: unknown): boolean | null => (typeof v === \"boolean\" ? v : null);\n\n/** Normalise a stored row of any writer's shape into the shared read view. */\nexport function toDirectoryOrganizationView(raw: unknown): DirectoryOrganizationView | null {\n if (!raw || typeof raw !== \"object\") return null;\n const r = raw as Record<string, unknown>;\n const id = directoryIdString(r._id);\n if (!id) return null;\n const rows = Array.isArray(r.programs) ? r.programs : [];\n const programs = rows\n .map(toDirectoryProgramView)\n .filter((p): p is DirectoryProgramView => p !== null);\n const vsp = flag(r.vsp);\n const reviewStatus = isProgramReviewStatus(r.reviewStatus) ? r.reviewStatus : null;\n const status = typeof r.status === \"number\" ? r.status : null;\n return {\n id,\n shape: organizationRowShape(r),\n name: text(r.name) ?? \"\",\n type: typeof r.type === \"number\" ? r.type : null,\n typeKey: typeof r.type === \"string\" ? r.type : null,\n paveId: text(r.id),\n community: text(r.community),\n agencyId: directoryIdString(r.agencyId),\n agencyScope: directoryIdString(r.agencyScope),\n canonicalKey: text(r.canonicalKey),\n key: isOrgKey(r.key) ? r.key : null,\n legalName: line(r.legalName),\n commonName: line(r.commonName),\n shortName: line(r.shortName) ?? line(r.acronym),\n website: line(r.website),\n parentOrgId: directoryIdString(r.parentOrgId),\n vsp,\n vspPrivateNonprofit: vsp === true ? flag(r.vspPrivateNonprofit) : null,\n reviewStatus,\n addedInApp: line(r.addedInApp),\n addedBy: line(r.addedBy) ?? line(r.addedByUserId),\n addedInSession: line(r.addedInSession),\n status,\n listed: isListedOrganization({ status, reviewStatus }),\n programs,\n invalidPrograms: rows.length - programs.length,\n };\n}\n","/**\n * The raw-driver reads of the platform-db org directory. No driver import: the\n * readers take any object with the MongoDB driver's\n * `collection(name).findOne(filter, options)` shape, plus a `toObjectId`\n * factory so a 24-hex string id also matches a row stored under an ObjectId\n * (production `organizations._id` and `agencies._id` are ObjectIds).\n */\n\nimport {\n isAgencyOwnOrganization,\n toDirectoryOrganizationView,\n type DirectoryOrganizationView,\n type ObjectIdLike,\n} from \"./rules.js\";\n\nexport const ORGANIZATIONS_COLLECTION = \"organizations\";\nexport const AGENCIES_COLLECTION = \"agencies\";\n\nexport interface OrgDirectoryDbLike {\n collection(name: string): {\n findOne(filter: Record<string, unknown>, options?: Record<string, unknown>): Promise<unknown>;\n };\n}\n\nexport interface OrgDirectoryReadOptions {\n /** Build the driver's ObjectId from 24-hex (e.g. `(h) => new ObjectId(h)`). */\n toObjectId?: (hex: string) => unknown;\n}\n\nconst HEX = /^[0-9a-fA-F]{24}$/;\n\n/** Every stored form of one id: the string, and its ObjectId when 24-hex. */\nexport function organizationIdForms(\n id: string | ObjectIdLike,\n opts: OrgDirectoryReadOptions = {},\n): unknown[] {\n if (typeof id !== \"string\") return [id.toHexString(), id];\n return HEX.test(id) && opts.toObjectId ? [id, opts.toObjectId(id.toLowerCase())] : [id];\n}\n\n/** One organization in the shared view, or null. Read errors propagate. */\nexport async function readDirectoryOrganization(\n db: OrgDirectoryDbLike,\n id: string | ObjectIdLike,\n opts: OrgDirectoryReadOptions = {},\n): Promise<DirectoryOrganizationView | null> {\n const raw = await db\n .collection(ORGANIZATIONS_COLLECTION)\n .findOne({ _id: { $in: organizationIdForms(id, opts) } });\n return raw ? toDirectoryOrganizationView(raw) : null;\n}\n\n/**\n * An agency's OWN organization (both halves of the pair hold), or null — never\n * an organization the agency merely scopes (`agencyScope`) or that points at it\n * from one side only. The agency is looked up by `_id`.\n */\nexport async function readAgencyOwnOrganization(\n db: OrgDirectoryDbLike,\n agencyId: string | ObjectIdLike,\n opts: OrgDirectoryReadOptions = {},\n): Promise<DirectoryOrganizationView | null> {\n const agency = (await db\n .collection(AGENCIES_COLLECTION)\n .findOne(\n { _id: { $in: organizationIdForms(agencyId, opts) } },\n { projection: { _id: 1, organizationId: 1 } },\n )) as { _id?: unknown; organizationId?: unknown } | null;\n if (!agency || agency.organizationId == null) return null;\n const pointer = agency.organizationId as string | ObjectIdLike;\n const org = (await db\n .collection(ORGANIZATIONS_COLLECTION)\n .findOne({ _id: { $in: organizationIdForms(pointer, opts) } })) as {\n _id?: unknown;\n agencyId?: unknown;\n } | null;\n return org && isAgencyOwnOrganization(org, agency) ? toDirectoryOrganizationView(org) : null;\n}\n"],"mappings":";AAcO,IAAM,wBAAwB;AAAA,EACnC,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AACZ;AAMO,IAAM,+BAA+B,OAAO,OAAO;AAAA,EACxD,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,sBAAsB;AACxB,CAAU;AAEH,SAAS,sBAAsB,OAA8C;AAClF,SACE,OAAO,UAAU,YAAa,6BAAmD,SAAS,KAAK;AAEnG;AASO,IAAM,iBAAiB;AAAA,EAC5B,QAAQ;AAAA,EACR,SAAS;AACX;AAIO,IAAM,wBAAwB,OAAO,OAAO;AAAA,EACjD,eAAe;AAAA,EACf,eAAe;AACjB,CAAU;AAUH,SAAS,0BAA0B,KAG9B;AACV,SACE,IAAI,WAAW,eAAe,WAAW,IAAI,iBAAiB,sBAAsB;AAExF;AAQO,SAAS,eAAe,MAAsB;AACnD,SAAO,KAAK,KAAK,EAAE,YAAY;AACjC;;;ACzEA,SAAS,SAAS;AAKX,IAAM,gCAAgC,OAAO,OAAO;AAAA,EACzD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAU;AAIV,IAAM,eAAe,EAAE,OAAO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AAI/D,SAAO,OAAO,wBAAwB,KAAK,MAAM,IAAI,4BAA4B,GAAG,IAAI;AAC1F;","names":["z","z","text","line"]}
|
package/dist/org-merge/index.cjs
CHANGED
|
@@ -174,7 +174,9 @@ var ORGANIZATION_PROGRAM_ROW_KEYS = Object.freeze([
|
|
|
174
174
|
"operatingStartDate",
|
|
175
175
|
"operatingEndDate",
|
|
176
176
|
"locationId",
|
|
177
|
-
"notes"
|
|
177
|
+
"notes",
|
|
178
|
+
"teamId",
|
|
179
|
+
"teamIds"
|
|
178
180
|
]);
|
|
179
181
|
var optionalText = import_zod2.z.string().nullish();
|
|
180
182
|
var detailText = import_zod2.z.string().nullish().catch(void 0);
|
|
@@ -194,7 +196,11 @@ var OrganizationProgramRowSchema = import_zod2.z.object({
|
|
|
194
196
|
operatingStartDate: detailText,
|
|
195
197
|
operatingEndDate: detailText,
|
|
196
198
|
locationId: detailText,
|
|
197
|
-
notes: detailText
|
|
199
|
+
notes: detailText,
|
|
200
|
+
/** The first team that works for the program (canon `team_id`). */
|
|
201
|
+
teamId: detailText,
|
|
202
|
+
/** Every team that works for the program (canon `team_ids`). */
|
|
203
|
+
teamIds: import_zod2.z.array(import_zod2.z.string()).nullish().catch(void 0)
|
|
198
204
|
});
|
|
199
205
|
|
|
200
206
|
// src/orgDirectory/programDetails.ts
|