@htilabs/platform-common-models 0.64.0 → 0.66.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 +146 -0
- package/dist/index.cjs +70 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -1
- package/dist/org-directory/index.cjs +19 -0
- package/dist/org-directory/index.cjs.map +1 -1
- package/dist/org-directory/index.d.cts +6 -236
- package/dist/org-directory/index.d.ts +6 -236
- package/dist/org-directory/index.js +16 -0
- package/dist/org-directory/index.js.map +1 -1
- package/dist/orgRecord-B4-ELaZ_.d.cts +263 -0
- package/dist/orgRecord-h3Z-V23F.d.ts +263 -0
- package/dist/points-of-contact/index.cjs +6 -0
- package/dist/points-of-contact/index.cjs.map +1 -1
- package/dist/points-of-contact/index.js +6 -0
- package/dist/points-of-contact/index.js.map +1 -1
- package/dist/schemas/index.cjs +57 -0
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +52 -1
- package/dist/schemas/index.d.ts +52 -1
- package/dist/schemas/index.js +54 -0
- package/dist/schemas/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/root-org-key-exports.test.ts +24 -0
- package/src/index.ts +7 -0
- package/src/orgDirectory/__tests__/orgKey.test.ts +84 -0
- package/src/orgDirectory/orgRecord.ts +41 -3
- package/src/orgDirectory/rules.ts +4 -1
- package/src/schemas/index.ts +3 -0
- package/src/schemas/organization.ts +58 -0
|
@@ -28,6 +28,7 @@ __export(orgDirectory_exports, {
|
|
|
28
28
|
ORGANIZATION_ROW_KEYS: () => ORGANIZATION_ROW_KEYS,
|
|
29
29
|
ORGANIZATION_STATUS: () => ORGANIZATION_STATUS,
|
|
30
30
|
ORG_AS_BUILT_FIELD_NAMES: () => ORG_AS_BUILT_FIELD_NAMES,
|
|
31
|
+
ORG_KEY_PATTERN: () => ORG_KEY_PATTERN,
|
|
31
32
|
ORG_RECORD_FIELD_NAMES: () => ORG_RECORD_FIELD_NAMES,
|
|
32
33
|
ORG_REVIEW_STATUS: () => ORG_REVIEW_STATUS,
|
|
33
34
|
ORG_REVIEW_STATUS_VALUES: () => ORG_REVIEW_STATUS_VALUES,
|
|
@@ -43,8 +44,10 @@ __export(orgDirectory_exports, {
|
|
|
43
44
|
isAgencyOwnOrganization: () => isAgencyOwnOrganization,
|
|
44
45
|
isListedOrganization: () => isListedOrganization,
|
|
45
46
|
isLiveOrganizationProgram: () => isLiveOrganizationProgram,
|
|
47
|
+
isOrgKey: () => isOrgKey,
|
|
46
48
|
isProgramReviewStatus: () => isProgramReviewStatus,
|
|
47
49
|
isShortNameOnly: () => isShortNameOnly,
|
|
50
|
+
mintOrgKey: () => mintOrgKey,
|
|
48
51
|
orgArrivalStamp: () => orgArrivalStamp,
|
|
49
52
|
orgCommonName: () => orgCommonName,
|
|
50
53
|
orgDisplayName: () => orgDisplayName,
|
|
@@ -127,6 +130,7 @@ function isListedOrganization(row) {
|
|
|
127
130
|
return active && row.reviewStatus !== ORG_REVIEW_STATUS.REJECTED;
|
|
128
131
|
}
|
|
129
132
|
var ORG_RECORD_FIELD_NAMES = Object.freeze([
|
|
133
|
+
"key",
|
|
130
134
|
"legalName",
|
|
131
135
|
"commonName",
|
|
132
136
|
"shortName",
|
|
@@ -176,6 +180,17 @@ var ORGANIZATION_ENVELOPE_KEYS = Object.freeze([
|
|
|
176
180
|
"updatedUser",
|
|
177
181
|
"updatedTime"
|
|
178
182
|
]);
|
|
183
|
+
var ORG_KEY_PATTERN = /^[a-z0-9][a-z0-9_-]{0,119}$/;
|
|
184
|
+
function isOrgKey(value) {
|
|
185
|
+
return typeof value === "string" && ORG_KEY_PATTERN.test(value);
|
|
186
|
+
}
|
|
187
|
+
function mintOrgKey(id) {
|
|
188
|
+
const hex = (typeof id === "string" ? id : id.toHexString()).trim().toLowerCase();
|
|
189
|
+
if (!/^[0-9a-f]{24}$/.test(hex)) {
|
|
190
|
+
throw new Error("mintOrgKey: needs the organization's 24-hex _id");
|
|
191
|
+
}
|
|
192
|
+
return `org-${hex}`;
|
|
193
|
+
}
|
|
179
194
|
var line = (max) => import_zod2.z.string().trim().min(1).max(max).nullable();
|
|
180
195
|
var ORG_VSP_TWO_STEP_MESSAGE = "vspPrivateNonprofit is step 2 of the HMIS VSP two-step and requires vsp: true";
|
|
181
196
|
var OrgIdentityWriteSchema = import_zod2.z.object({
|
|
@@ -303,6 +318,7 @@ function toDirectoryOrganizationView(raw) {
|
|
|
303
318
|
agencyId: directoryIdString(r.agencyId),
|
|
304
319
|
agencyScope: directoryIdString(r.agencyScope),
|
|
305
320
|
canonicalKey: text(r.canonicalKey),
|
|
321
|
+
key: isOrgKey(r.key) ? r.key : null,
|
|
306
322
|
legalName: line2(r.legalName),
|
|
307
323
|
commonName: line2(r.commonName),
|
|
308
324
|
shortName: line2(r.shortName) ?? line2(r.acronym),
|
|
@@ -353,6 +369,7 @@ async function readAgencyOwnOrganization(db, agencyId, opts = {}) {
|
|
|
353
369
|
ORGANIZATION_ROW_KEYS,
|
|
354
370
|
ORGANIZATION_STATUS,
|
|
355
371
|
ORG_AS_BUILT_FIELD_NAMES,
|
|
372
|
+
ORG_KEY_PATTERN,
|
|
356
373
|
ORG_RECORD_FIELD_NAMES,
|
|
357
374
|
ORG_REVIEW_STATUS,
|
|
358
375
|
ORG_REVIEW_STATUS_VALUES,
|
|
@@ -368,8 +385,10 @@ async function readAgencyOwnOrganization(db, agencyId, opts = {}) {
|
|
|
368
385
|
isAgencyOwnOrganization,
|
|
369
386
|
isListedOrganization,
|
|
370
387
|
isLiveOrganizationProgram,
|
|
388
|
+
isOrgKey,
|
|
371
389
|
isProgramReviewStatus,
|
|
372
390
|
isShortNameOnly,
|
|
391
|
+
mintOrgKey,
|
|
373
392
|
orgArrivalStamp,
|
|
374
393
|
orgCommonName,
|
|
375
394
|
orgDisplayName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/orgDirectory/index.ts","../../src/orgDirectory/vocabulary.ts","../../src/orgDirectory/schemas.ts","../../src/orgDirectory/orgRecord.ts","../../src/orgDirectory/rules.ts","../../src/orgDirectory/read.ts"],"sourcesContent":["/**\n * @htilabs/platform-common-models/org-directory\n *\n * The READ contract for the platform-db org directory: `organizations` rows\n * (Thread / auth shape and PAVE 2.0 shape), their `programs[]`, and the\n * agency's-own-organization rule. The Platform writes through\n * `lib/org-directory/` (platform `docs/ORG_DIRECTORY_CONTRACT.md`); PAVE,\n * Thread and LEADS read through here. No mongoose, no driver import, no SOT.\n * Subpath only. The program vocabulary is also re-exported by the Mongoose\n * fragment (`schemas/organization-program.ts`) — one source.\n */\n\nexport * from \"./vocabulary.js\";\nexport * from \"./schemas.js\";\nexport * from \"./orgRecord.js\";\nexport * from \"./rules.js\";\nexport * from \"./read.js\";\n","/**\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] as const);\n\nexport type OrganizationProgramRowKey = (typeof ORGANIZATION_PROGRAM_ROW_KEYS)[number];\n\nconst optionalText = z.string().nullish();\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).\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});\n\nexport type OrganizationProgramRow = z.infer<typeof OrganizationProgramRowSchema>;\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`). One exception: 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`.\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 \"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// ─── 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, type OrgReviewStatus } from \"./orgRecord.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\nexport interface DirectoryProgramView {\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 };\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 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 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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACcO,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,iBAAkB;AAKX,IAAM,gCAAgC,OAAO,OAAO;AAAA,EACzD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAU;AAIV,IAAM,eAAe,aAAE,OAAO,EAAE,QAAQ;AAOjC,IAAM,+BAA+B,aAAE,OAAO;AAAA,EACnD,WAAW,aAAE,OAAO,EAAE,IAA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abulary.ts","../../src/orgDirectory/schemas.ts","../../src/orgDirectory/orgRecord.ts","../../src/orgDirectory/rules.ts","../../src/orgDirectory/read.ts"],"sourcesContent":["/**\n * @htilabs/platform-common-models/org-directory\n *\n * The READ contract for the platform-db org directory: `organizations` rows\n * (Thread / auth shape and PAVE 2.0 shape), their `programs[]`, and the\n * agency's-own-organization rule. The Platform writes through\n * `lib/org-directory/` (platform `docs/ORG_DIRECTORY_CONTRACT.md`); PAVE,\n * Thread and LEADS read through here. No mongoose, no driver import, no SOT.\n * Subpath only. The program vocabulary is also re-exported by the Mongoose\n * fragment (`schemas/organization-program.ts`) — one source.\n */\n\nexport * from \"./vocabulary.js\";\nexport * from \"./schemas.js\";\nexport * from \"./orgRecord.js\";\nexport * from \"./rules.js\";\nexport * from \"./read.js\";\n","/**\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] as const);\n\nexport type OrganizationProgramRowKey = (typeof ORGANIZATION_PROGRAM_ROW_KEYS)[number];\n\nconst optionalText = z.string().nullish();\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).\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});\n\nexport type OrganizationProgramRow = z.infer<typeof OrganizationProgramRowSchema>;\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 { 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\nexport interface DirectoryProgramView {\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 };\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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MAAM,IAAI,4BAA4B,GAAG,IAAI;AAC1F;","names":["import_zod","line"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export { P as PROGRAM_REVIEW_STATUS, a as PROGRAM_REVIEW_STATUS_VALUES, d as PROGRAM_STATUS, e as PROGRAM_STATUS_VALUES, f as ProgramStatus, i as isLiveOrganizationProgram, c as isProgramReviewStatus, p as programNameKey } from '../vocabulary-Cxhi9EGt.cjs';
|
|
1
|
+
export { P as PROGRAM_REVIEW_STATUS, a as PROGRAM_REVIEW_STATUS_VALUES, d as PROGRAM_STATUS, e as PROGRAM_STATUS_VALUES, b as ProgramReviewStatus, f as ProgramStatus, i as isLiveOrganizationProgram, c as isProgramReviewStatus, p as programNameKey } from '../vocabulary-Cxhi9EGt.cjs';
|
|
3
2
|
import { z } from 'zod';
|
|
3
|
+
import { a as OrgReviewStatus } from '../orgRecord-B4-ELaZ_.cjs';
|
|
4
|
+
export { b as ORGANIZATION_BASE_ROW_KEYS, c as ORGANIZATION_ENVELOPE_KEYS, d as ORGANIZATION_ROW_KEYS, e as ORGANIZATION_STATUS, f as ORG_AS_BUILT_FIELD_NAMES, O as ORG_KEY_PATTERN, g as ORG_RECORD_FIELD_NAMES, h as ORG_REVIEW_STATUS, j as ORG_REVIEW_STATUS_VALUES, k as ORG_VSP_TWO_STEP_MESSAGE, l as OrgArrival, n as OrgAsBuiltFieldName, o as OrgIdentityWrite, p as OrgIdentityWriteSchema, q as OrgRecordFieldName, r as OrgVspWrite, s as OrgVspWriteSchema, t as OrganizationRowKey, u as OrganizationStatus, v as isListedOrganization, i as isOrgKey, w as isShortNameOnly, m as mintOrgKey, x as orgArrivalStamp, y as orgCommonName, z as orgDisplayName, A as orgDisplayParts, B as orgLegalName, C as orgParentIssue } from '../orgRecord-B4-ELaZ_.cjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The stored program row of `organizations.programs[]`, as a Zod schema for
|
|
@@ -50,239 +51,6 @@ declare const OrganizationProgramRowSchema: z.ZodObject<{
|
|
|
50
51
|
}>;
|
|
51
52
|
type OrganizationProgramRow = z.infer<typeof OrganizationProgramRowSchema>;
|
|
52
53
|
|
|
53
|
-
/**
|
|
54
|
-
* The Org record: the ONE definition of what an `organizations` row holds
|
|
55
|
-
* about an organization, for every app that reads or writes the platform-wide
|
|
56
|
-
* registry (Thread, PAVE, the Platform, auth). Pure: no mongoose, no driver.
|
|
57
|
-
* The Mongoose twin is `schemas/organization.ts` (`addOrgRecordFields`); a
|
|
58
|
-
* package test holds the two key lists equal.
|
|
59
|
-
*
|
|
60
|
-
* ## Canon
|
|
61
|
-
*
|
|
62
|
-
* UDD Org Data Object (Notion `7d71ef14abcd832fa3a6816ebe7a5dd9`, § 1 and § 5;
|
|
63
|
-
* schema of record hti-features `udd-schemas/org/Org.v1.json`): an Org is one
|
|
64
|
-
* real-world organization in the one platform-wide registry. It holds its name
|
|
65
|
-
* (legal and common), its acronym, its required type, its parent when it is a
|
|
66
|
-
* unit of a larger one, the two HMIS victim-service-provider answers, and how
|
|
67
|
-
* it arrived and whether HTI Labs has reviewed it. Crysta, 2026-11-10: "It
|
|
68
|
-
* shouldn't be different in thread vs. pave. And the data objects for Org need
|
|
69
|
-
* to be the same in both apps."
|
|
70
|
-
*
|
|
71
|
-
* ## Stored names
|
|
72
|
-
*
|
|
73
|
-
* The UDD spells these snake_case (`legal_name`, `parent_org_id`, ...). The
|
|
74
|
-
* live platform-db writers use camelCase, so the stored names are the UDD's in
|
|
75
|
-
* camelCase, as for the org-type fields (`schemas/agency.ts`) and the program
|
|
76
|
-
* row (`schemas/organization-program.ts`). One exception: the UDD `acronym` is
|
|
77
|
-
* stored as `shortName`. A top-level `acronym` key marks a pre-pl-958 PAVE row
|
|
78
|
-
* (`organizationRowShape`), and PAVE 2.0 already writes `shortName`.
|
|
79
|
-
*
|
|
80
|
-
* ## What is NOT here
|
|
81
|
-
*
|
|
82
|
-
* - `name` and `type`: every writer already stores them. `type` is mid-move
|
|
83
|
-
* from the IC-58 number to the CVC-48 key and each app validates the
|
|
84
|
-
* transition form itself until the migration has run.
|
|
85
|
-
* - The row's tenancy and plumbing (`agencyScope`, `agencyId`, `community`,
|
|
86
|
-
* `canonicalKey`, `status`, `programs`, contact fields): unchanged by this
|
|
87
|
-
* module. {@link ORGANIZATION_ROW_KEYS} lists them so a model can be checked
|
|
88
|
-
* against the whole row.
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Review lifecycle of an organization added from inside an app. The same three
|
|
93
|
-
* words, and the same lifecycle, as a program named inside an app (UDD Org
|
|
94
|
-
* § 5 "how it arrived"; census item 2: "the same lifecycle a program named
|
|
95
|
-
* inside an app has"). Absent on a steward row: nothing to review.
|
|
96
|
-
*/
|
|
97
|
-
declare const ORG_REVIEW_STATUS: {
|
|
98
|
-
readonly PENDING: "pending";
|
|
99
|
-
readonly CONFIRMED: "confirmed";
|
|
100
|
-
readonly REJECTED: "rejected";
|
|
101
|
-
};
|
|
102
|
-
declare const ORG_REVIEW_STATUS_VALUES: readonly ["pending", "confirmed", "rejected"];
|
|
103
|
-
type OrgReviewStatus = ProgramReviewStatus;
|
|
104
|
-
/**
|
|
105
|
-
* `organizations.status`: 1 active, 2 inactive (soft-deleted; never removed).
|
|
106
|
-
* The codes auth, Thread and PAVE already store.
|
|
107
|
-
*/
|
|
108
|
-
declare const ORGANIZATION_STATUS: {
|
|
109
|
-
readonly ACTIVE: 1;
|
|
110
|
-
readonly INACTIVE: 2;
|
|
111
|
-
};
|
|
112
|
-
type OrganizationStatus = (typeof ORGANIZATION_STATUS)[keyof typeof ORGANIZATION_STATUS];
|
|
113
|
-
/**
|
|
114
|
-
* Whether an organization may be OFFERED in a picker: active (an absent
|
|
115
|
-
* `status` reads active, as legacy rows carry none) and not declined by HTI
|
|
116
|
-
* Labs. A pending organization IS offered: an organization added inside an app
|
|
117
|
-
* is available everywhere from the moment it is added (UDD Org § 2 scenario 1).
|
|
118
|
-
* A stored reference to an organization that is no longer offered still
|
|
119
|
-
* resolves by id.
|
|
120
|
-
*/
|
|
121
|
-
declare function isListedOrganization(row: {
|
|
122
|
-
status?: number | null | undefined;
|
|
123
|
-
reviewStatus?: string | null | undefined;
|
|
124
|
-
}): boolean;
|
|
125
|
-
/**
|
|
126
|
-
* The Org definition's fields beyond `name` and `type`, in the Mongoose
|
|
127
|
-
* fragment's declaration order (`orgRecordSchemaDefinition`).
|
|
128
|
-
*/
|
|
129
|
-
declare const ORG_RECORD_FIELD_NAMES: readonly ["legalName", "commonName", "shortName", "website", "parentOrgId", "vsp", "vspPrivateNonprofit", "reviewStatus", "addedInApp", "addedBy"];
|
|
130
|
-
type OrgRecordFieldName = (typeof ORG_RECORD_FIELD_NAMES)[number];
|
|
131
|
-
/**
|
|
132
|
-
* Stored on the row today and NOT part of the Org definition (UDD Org § 5,
|
|
133
|
-
* "As built today, and not part of this definition"; Org.v1's runtime-overlay
|
|
134
|
-
* five: `isCustom`, `added_in_session`, `added_by_user_id`, `type_override`,
|
|
135
|
-
* `division`). PAVE 2.0 writes them; every model declares
|
|
136
|
-
* them so no app silently drops another app's value. `typeKey` is the CVC-48
|
|
137
|
-
* key PAVE writes beside a numeric `type` and retires with the type migration.
|
|
138
|
-
*/
|
|
139
|
-
declare const ORG_AS_BUILT_FIELD_NAMES: readonly ["requiresROI", "isCustom", "addedByUserId", "addedInSession", "division", "typeOverride", "typeKey"];
|
|
140
|
-
type OrgAsBuiltFieldName = (typeof ORG_AS_BUILT_FIELD_NAMES)[number];
|
|
141
|
-
/** The row's keys every writer already stored before this module. */
|
|
142
|
-
declare const ORGANIZATION_BASE_ROW_KEYS: readonly ["name", "type", "phones", "emails", "address", "notes", "status", "agencyScope", "agencyId", "community", "canonicalKey", "isAnonymous", "programs"];
|
|
143
|
-
/**
|
|
144
|
-
* Every top-level key of a shared-shape `organizations` row, the record
|
|
145
|
-
* envelope aside. A model that declares exactly these is the same data object
|
|
146
|
-
* as every other app's (`organizationSchemaIssues`, `schemas/organization.ts`).
|
|
147
|
-
*/
|
|
148
|
-
declare const ORGANIZATION_ROW_KEYS: readonly ["name", "type", "phones", "emails", "address", "notes", "status", "agencyScope", "agencyId", "community", "canonicalKey", "isAnonymous", "programs", "legalName", "commonName", "shortName", "website", "parentOrgId", "vsp", "vspPrivateNonprofit", "reviewStatus", "addedInApp", "addedBy", "requiresROI", "isCustom", "addedByUserId", "addedInSession", "division", "typeOverride", "typeKey"];
|
|
149
|
-
type OrganizationRowKey = (typeof ORGANIZATION_ROW_KEYS)[number];
|
|
150
|
-
/** The record envelope each app's base document adds; never Org facts. */
|
|
151
|
-
declare const ORGANIZATION_ENVELOPE_KEYS: readonly ["_id", "__v", "_schemaVersion", "createdUser", "createdTime", "updatedUser", "updatedTime"];
|
|
152
|
-
/** The two-step message; the same sentence the Mongoose mount throws. */
|
|
153
|
-
declare const ORG_VSP_TWO_STEP_MESSAGE = "vspPrivateNonprofit is step 2 of the HMIS VSP two-step and requires vsp: true";
|
|
154
|
-
/**
|
|
155
|
-
* The identity half of the record, as a request body may carry it. Every key
|
|
156
|
-
* is optional (a PATCH names only what it changes); `null` clears a field.
|
|
157
|
-
* Strict: an unknown key is refused, so a snake_case spelling never passes as
|
|
158
|
-
* a silent no-op.
|
|
159
|
-
*/
|
|
160
|
-
declare const OrgIdentityWriteSchema: z.ZodObject<{
|
|
161
|
-
legalName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
162
|
-
commonName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
163
|
-
shortName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
164
|
-
website: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
165
|
-
parentOrgId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
166
|
-
}, "strict", z.ZodTypeAny, {
|
|
167
|
-
website?: string | null | undefined;
|
|
168
|
-
legalName?: string | null | undefined;
|
|
169
|
-
commonName?: string | null | undefined;
|
|
170
|
-
shortName?: string | null | undefined;
|
|
171
|
-
parentOrgId?: string | null | undefined;
|
|
172
|
-
}, {
|
|
173
|
-
website?: string | null | undefined;
|
|
174
|
-
legalName?: string | null | undefined;
|
|
175
|
-
commonName?: string | null | undefined;
|
|
176
|
-
shortName?: string | null | undefined;
|
|
177
|
-
parentOrgId?: string | null | undefined;
|
|
178
|
-
}>;
|
|
179
|
-
type OrgIdentityWrite = z.infer<typeof OrgIdentityWriteSchema>;
|
|
180
|
-
/**
|
|
181
|
-
* The two HMIS victim-service-provider answers. Tri-state: `null` is "not yet
|
|
182
|
-
* captured", never a coerced false. Step 2 may be answered only with step 1
|
|
183
|
-
* `true` in the same body (an update cannot see the stored row), and a body
|
|
184
|
-
* that sets step 1 to `false` or `null` clears step 2 with it. Only HTI Labs
|
|
185
|
-
* sets them (UDD Org rulings 2026-10-08 and 2026-10-09); the route decides who
|
|
186
|
-
* that is.
|
|
187
|
-
*/
|
|
188
|
-
declare const OrgVspWriteSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
189
|
-
vsp: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
190
|
-
vspPrivateNonprofit: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
191
|
-
}, "strict", z.ZodTypeAny, {
|
|
192
|
-
vspPrivateNonprofit?: boolean | null | undefined;
|
|
193
|
-
vsp?: boolean | null | undefined;
|
|
194
|
-
}, {
|
|
195
|
-
vspPrivateNonprofit?: boolean | null | undefined;
|
|
196
|
-
vsp?: boolean | null | undefined;
|
|
197
|
-
}>, {
|
|
198
|
-
vspPrivateNonprofit?: boolean | null | undefined;
|
|
199
|
-
vsp?: boolean | null | undefined;
|
|
200
|
-
}, {
|
|
201
|
-
vspPrivateNonprofit?: boolean | null | undefined;
|
|
202
|
-
vsp?: boolean | null | undefined;
|
|
203
|
-
}>, {
|
|
204
|
-
vspPrivateNonprofit?: boolean | null | undefined;
|
|
205
|
-
vsp?: boolean | null | undefined;
|
|
206
|
-
}, {
|
|
207
|
-
vspPrivateNonprofit?: boolean | null | undefined;
|
|
208
|
-
vsp?: boolean | null | undefined;
|
|
209
|
-
}>;
|
|
210
|
-
type OrgVspWrite = z.infer<typeof OrgVspWriteSchema>;
|
|
211
|
-
/**
|
|
212
|
-
* How an organization arrived. Never taken from a request body: the server
|
|
213
|
-
* stamps it from the authenticated caller ({@link orgArrivalStamp}).
|
|
214
|
-
*
|
|
215
|
-
* The same three facts, under the same names, as a Program, a Service Listing
|
|
216
|
-
* and a Point of contact carry (`added_by` · `added_in_app` · `review_status`;
|
|
217
|
-
* UDD ratification request R17, "how an organization arrived"). The older
|
|
218
|
-
* runtime-overlay names on the row (`addedByUserId`, `isCustom`) are as-built
|
|
219
|
-
* extras; `addedInSession` is carried as on the program row.
|
|
220
|
-
*/
|
|
221
|
-
interface OrgArrival {
|
|
222
|
-
reviewStatus: OrgReviewStatus;
|
|
223
|
-
/** The app the organization was added in: `thread`, `pave`, `leads`, `platform`. */
|
|
224
|
-
addedInApp: string;
|
|
225
|
-
/** The adding user's platform `users._id`, as a string. */
|
|
226
|
-
addedBy: string;
|
|
227
|
-
/** The session it was added in, when there was one. */
|
|
228
|
-
addedInSession?: string;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* The arrival stamp for an organization a user adds from inside an app: it is
|
|
232
|
-
* on the list at once and waits for HTI Labs' review (UDD Org § 2 scenario 5;
|
|
233
|
-
* census item 2). A steward's own add carries no stamp.
|
|
234
|
-
*/
|
|
235
|
-
declare function orgArrivalStamp(input: {
|
|
236
|
-
app: string;
|
|
237
|
-
userId: string;
|
|
238
|
-
sessionId?: string | null | undefined;
|
|
239
|
-
}): OrgArrival;
|
|
240
|
-
interface OrgNames {
|
|
241
|
-
name?: string | null | undefined;
|
|
242
|
-
commonName?: string | null | undefined;
|
|
243
|
-
legalName?: string | null | undefined;
|
|
244
|
-
shortName?: string | null | undefined;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* The name to use when a sentence or a label names an organization: its common
|
|
248
|
-
* name when it has one, else its name. Canon: the prototype's contact-history
|
|
249
|
-
* register and referral wording (`org.common_name || org.name`).
|
|
250
|
-
*/
|
|
251
|
-
declare function orgCommonName(org: OrgNames | null | undefined): string;
|
|
252
|
-
/**
|
|
253
|
-
* The name a report to a funder or HMIS uses: the legal name when captured,
|
|
254
|
-
* else the name (Org.v1 `legal_name`: "consumers fall back to name when blank").
|
|
255
|
-
*/
|
|
256
|
-
declare function orgLegalName(org: OrgNames | null | undefined): string;
|
|
257
|
-
/** Whether a row's name is nothing but its short name ("ASJS" named "ASJS"). */
|
|
258
|
-
declare function isShortNameOnly(org: OrgNames | null | undefined): boolean;
|
|
259
|
-
/**
|
|
260
|
-
* How a unit of a larger organization reads: its own name, and "<parent> unit"
|
|
261
|
-
* beneath it when the unit has no name beyond its short name (Crysta
|
|
262
|
-
* 2026-09-03, "No names yet — show the parent"). A row with a real name keeps
|
|
263
|
-
* it. Canon: the prototype's one resolver, `orgDisplayParts`.
|
|
264
|
-
*/
|
|
265
|
-
declare function orgDisplayParts(org: OrgNames | null | undefined, parent: OrgNames | null | undefined): {
|
|
266
|
-
name: string;
|
|
267
|
-
sub: string;
|
|
268
|
-
};
|
|
269
|
-
/** {@link orgDisplayParts} on one line: "ASJS · Ascension St. John Medical Center unit". */
|
|
270
|
-
declare function orgDisplayName(org: OrgNames | null | undefined, parent?: OrgNames | null | undefined): string;
|
|
271
|
-
/**
|
|
272
|
-
* Why `parentOrgId` may not be set to this value, or null when it may. One
|
|
273
|
-
* level only (the picker folds units under their organization): an
|
|
274
|
-
* organization is never its own parent, a parent is not itself a unit, and an
|
|
275
|
-
* organization that has units cannot become one.
|
|
276
|
-
*/
|
|
277
|
-
declare function orgParentIssue(input: {
|
|
278
|
-
orgId: string | null | undefined;
|
|
279
|
-
parentOrgId: string | null | undefined;
|
|
280
|
-
/** The proposed parent's own `parentOrgId`, when the parent row was read. */
|
|
281
|
-
parentsParentOrgId?: string | null | undefined;
|
|
282
|
-
/** Whether any organization already names `orgId` as its parent. */
|
|
283
|
-
hasUnits?: boolean | undefined;
|
|
284
|
-
}): "self" | "parent_is_unit" | "org_has_units" | null;
|
|
285
|
-
|
|
286
54
|
/**
|
|
287
55
|
* Read rules for the platform-db org directory: which row shape a document
|
|
288
56
|
* is, when an organization is an agency's OWN record, and the normalised read
|
|
@@ -369,6 +137,8 @@ interface DirectoryOrganizationView {
|
|
|
369
137
|
/** Tenancy scope. Never an identity. */
|
|
370
138
|
agencyScope: string | null;
|
|
371
139
|
canonicalKey: string | null;
|
|
140
|
+
/** The Org's identifier (the UDD `id`): the same in every database. Null on a row not yet given one. */
|
|
141
|
+
key: string | null;
|
|
372
142
|
legalName: string | null;
|
|
373
143
|
commonName: string | null;
|
|
374
144
|
/**
|
|
@@ -430,4 +200,4 @@ declare function readDirectoryOrganization(db: OrgDirectoryDbLike, id: string |
|
|
|
430
200
|
*/
|
|
431
201
|
declare function readAgencyOwnOrganization(db: OrgDirectoryDbLike, agencyId: string | ObjectIdLike, opts?: OrgDirectoryReadOptions): Promise<DirectoryOrganizationView | null>;
|
|
432
202
|
|
|
433
|
-
export { AGENCIES_COLLECTION, type DirectoryOrganizationView, type DirectoryProgramView, ORGANIZATIONS_COLLECTION,
|
|
203
|
+
export { AGENCIES_COLLECTION, type DirectoryOrganizationView, type DirectoryProgramView, ORGANIZATIONS_COLLECTION, ORGANIZATION_PROGRAM_ROW_KEYS, type ObjectIdLike, type OrgDirectoryDbLike, type OrgDirectoryReadOptions, OrgReviewStatus, type OrganizationProgramRow, type OrganizationProgramRowKey, OrganizationProgramRowSchema, type OrganizationRowShape, directoryIdString, isAgencyOwnOrganization, organizationIdForms, organizationRowShape, readAgencyOwnOrganization, readDirectoryOrganization, sameDirectoryId, toDirectoryOrganizationView, toDirectoryProgramView };
|