@htilabs/platform-common-models 0.59.0 → 0.61.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 +90 -1
- package/dist/index.cjs +91 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +91 -13
- package/dist/index.js.map +1 -1
- package/dist/org-directory/index.cjs +5 -4
- package/dist/org-directory/index.cjs.map +1 -1
- package/dist/org-directory/index.d.cts +15 -7
- package/dist/org-directory/index.d.ts +15 -7
- package/dist/org-directory/index.js +5 -4
- package/dist/org-directory/index.js.map +1 -1
- package/dist/points-of-contact/index.cjs +4 -3
- package/dist/points-of-contact/index.cjs.map +1 -1
- package/dist/points-of-contact/index.js +4 -3
- package/dist/points-of-contact/index.js.map +1 -1
- package/dist/schemas/index.cjs +10 -6
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +8 -4
- package/dist/schemas/index.d.ts +8 -4
- package/dist/schemas/index.js +10 -6
- package/dist/schemas/index.js.map +1 -1
- package/dist/sharing-ceiling/index.cjs +81 -7
- package/dist/sharing-ceiling/index.cjs.map +1 -1
- package/dist/sharing-ceiling/index.d.cts +64 -4
- package/dist/sharing-ceiling/index.d.ts +64 -4
- package/dist/sharing-ceiling/index.js +81 -7
- package/dist/sharing-ceiling/index.js.map +1 -1
- package/package.json +1 -1
- package/src/orgDirectory/__tests__/orgRecord.test.ts +6 -3
- package/src/orgDirectory/orgRecord.ts +14 -6
- package/src/orgDirectory/rules.ts +3 -2
- package/src/schemas/organization.ts +7 -4
- package/src/sharingCeiling/__tests__/resolveShare.purposeRule.test.ts +836 -0
- package/src/sharingCeiling/index.ts +4 -0
- package/src/sharingCeiling/resolve.ts +219 -15
|
@@ -136,12 +136,13 @@ var ORG_RECORD_FIELD_NAMES = Object.freeze([
|
|
|
136
136
|
"vspPrivateNonprofit",
|
|
137
137
|
"reviewStatus",
|
|
138
138
|
"addedInApp",
|
|
139
|
-
"
|
|
140
|
-
"addedInSession"
|
|
139
|
+
"addedBy"
|
|
141
140
|
]);
|
|
142
141
|
var ORG_AS_BUILT_FIELD_NAMES = Object.freeze([
|
|
143
142
|
"requiresROI",
|
|
144
143
|
"isCustom",
|
|
144
|
+
"addedByUserId",
|
|
145
|
+
"addedInSession",
|
|
145
146
|
"division",
|
|
146
147
|
"typeOverride",
|
|
147
148
|
"typeKey"
|
|
@@ -201,7 +202,7 @@ function orgArrivalStamp(input) {
|
|
|
201
202
|
return {
|
|
202
203
|
reviewStatus: ORG_REVIEW_STATUS.PENDING,
|
|
203
204
|
addedInApp: app,
|
|
204
|
-
|
|
205
|
+
addedBy: userId,
|
|
205
206
|
...session ? { addedInSession: session } : {}
|
|
206
207
|
};
|
|
207
208
|
}
|
|
@@ -311,7 +312,7 @@ function toDirectoryOrganizationView(raw) {
|
|
|
311
312
|
vspPrivateNonprofit: vsp === true ? flag(r.vspPrivateNonprofit) : null,
|
|
312
313
|
reviewStatus,
|
|
313
314
|
addedInApp: line2(r.addedInApp),
|
|
314
|
-
|
|
315
|
+
addedBy: line2(r.addedBy) ?? line2(r.addedByUserId),
|
|
315
316
|
addedInSession: line2(r.addedInSession),
|
|
316
317
|
status,
|
|
317
318
|
listed: isListedOrganization({ status, reviewStatus }),
|
|
@@ -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 \"addedByUserId\",\n \"addedInSession\",\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 `isCustom`,\n * `type_override`, `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 \"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 */\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 addedByUserId: 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 addedByUserId: 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 addedByUserId: 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 addedByUserId: 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,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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":["import_zod","line"]}
|
|
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,CA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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":["import_zod","line"]}
|
|
@@ -126,16 +126,17 @@ declare function isListedOrganization(row: {
|
|
|
126
126
|
* The Org definition's fields beyond `name` and `type`, in the Mongoose
|
|
127
127
|
* fragment's declaration order (`orgRecordSchemaDefinition`).
|
|
128
128
|
*/
|
|
129
|
-
declare const ORG_RECORD_FIELD_NAMES: readonly ["legalName", "commonName", "shortName", "website", "parentOrgId", "vsp", "vspPrivateNonprofit", "reviewStatus", "addedInApp", "
|
|
129
|
+
declare const ORG_RECORD_FIELD_NAMES: readonly ["legalName", "commonName", "shortName", "website", "parentOrgId", "vsp", "vspPrivateNonprofit", "reviewStatus", "addedInApp", "addedBy"];
|
|
130
130
|
type OrgRecordFieldName = (typeof ORG_RECORD_FIELD_NAMES)[number];
|
|
131
131
|
/**
|
|
132
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
|
|
134
|
-
* `
|
|
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
|
|
135
136
|
* them so no app silently drops another app's value. `typeKey` is the CVC-48
|
|
136
137
|
* key PAVE writes beside a numeric `type` and retires with the type migration.
|
|
137
138
|
*/
|
|
138
|
-
declare const ORG_AS_BUILT_FIELD_NAMES: readonly ["requiresROI", "isCustom", "division", "typeOverride", "typeKey"];
|
|
139
|
+
declare const ORG_AS_BUILT_FIELD_NAMES: readonly ["requiresROI", "isCustom", "addedByUserId", "addedInSession", "division", "typeOverride", "typeKey"];
|
|
139
140
|
type OrgAsBuiltFieldName = (typeof ORG_AS_BUILT_FIELD_NAMES)[number];
|
|
140
141
|
/** The row's keys every writer already stored before this module. */
|
|
141
142
|
declare const ORGANIZATION_BASE_ROW_KEYS: readonly ["name", "type", "phones", "emails", "address", "notes", "status", "agencyScope", "agencyId", "community", "canonicalKey", "isAnonymous", "programs"];
|
|
@@ -144,7 +145,7 @@ declare const ORGANIZATION_BASE_ROW_KEYS: readonly ["name", "type", "phones", "e
|
|
|
144
145
|
* envelope aside. A model that declares exactly these is the same data object
|
|
145
146
|
* as every other app's (`organizationSchemaIssues`, `schemas/organization.ts`).
|
|
146
147
|
*/
|
|
147
|
-
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", "
|
|
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"];
|
|
148
149
|
type OrganizationRowKey = (typeof ORGANIZATION_ROW_KEYS)[number];
|
|
149
150
|
/** The record envelope each app's base document adds; never Org facts. */
|
|
150
151
|
declare const ORGANIZATION_ENVELOPE_KEYS: readonly ["_id", "__v", "_schemaVersion", "createdUser", "createdTime", "updatedUser", "updatedTime"];
|
|
@@ -210,13 +211,19 @@ type OrgVspWrite = z.infer<typeof OrgVspWriteSchema>;
|
|
|
210
211
|
/**
|
|
211
212
|
* How an organization arrived. Never taken from a request body: the server
|
|
212
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.
|
|
213
220
|
*/
|
|
214
221
|
interface OrgArrival {
|
|
215
222
|
reviewStatus: OrgReviewStatus;
|
|
216
223
|
/** The app the organization was added in: `thread`, `pave`, `leads`, `platform`. */
|
|
217
224
|
addedInApp: string;
|
|
218
225
|
/** The adding user's platform `users._id`, as a string. */
|
|
219
|
-
|
|
226
|
+
addedBy: string;
|
|
220
227
|
/** The session it was added in, when there was one. */
|
|
221
228
|
addedInSession?: string;
|
|
222
229
|
}
|
|
@@ -379,7 +386,8 @@ interface DirectoryOrganizationView {
|
|
|
379
386
|
/** pending · confirmed · rejected for an organization added inside an app; null on a steward row. */
|
|
380
387
|
reviewStatus: OrgReviewStatus | null;
|
|
381
388
|
addedInApp: string | null;
|
|
382
|
-
addedByUserId
|
|
389
|
+
/** Who added it (a platform `users._id`); a pre-0.60 row's `addedByUserId` reads here too. */
|
|
390
|
+
addedBy: string | null;
|
|
383
391
|
addedInSession: string | null;
|
|
384
392
|
/** The stored lifecycle code (1 active, 2 inactive), else null. */
|
|
385
393
|
status: number | null;
|
|
@@ -126,16 +126,17 @@ declare function isListedOrganization(row: {
|
|
|
126
126
|
* The Org definition's fields beyond `name` and `type`, in the Mongoose
|
|
127
127
|
* fragment's declaration order (`orgRecordSchemaDefinition`).
|
|
128
128
|
*/
|
|
129
|
-
declare const ORG_RECORD_FIELD_NAMES: readonly ["legalName", "commonName", "shortName", "website", "parentOrgId", "vsp", "vspPrivateNonprofit", "reviewStatus", "addedInApp", "
|
|
129
|
+
declare const ORG_RECORD_FIELD_NAMES: readonly ["legalName", "commonName", "shortName", "website", "parentOrgId", "vsp", "vspPrivateNonprofit", "reviewStatus", "addedInApp", "addedBy"];
|
|
130
130
|
type OrgRecordFieldName = (typeof ORG_RECORD_FIELD_NAMES)[number];
|
|
131
131
|
/**
|
|
132
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
|
|
134
|
-
* `
|
|
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
|
|
135
136
|
* them so no app silently drops another app's value. `typeKey` is the CVC-48
|
|
136
137
|
* key PAVE writes beside a numeric `type` and retires with the type migration.
|
|
137
138
|
*/
|
|
138
|
-
declare const ORG_AS_BUILT_FIELD_NAMES: readonly ["requiresROI", "isCustom", "division", "typeOverride", "typeKey"];
|
|
139
|
+
declare const ORG_AS_BUILT_FIELD_NAMES: readonly ["requiresROI", "isCustom", "addedByUserId", "addedInSession", "division", "typeOverride", "typeKey"];
|
|
139
140
|
type OrgAsBuiltFieldName = (typeof ORG_AS_BUILT_FIELD_NAMES)[number];
|
|
140
141
|
/** The row's keys every writer already stored before this module. */
|
|
141
142
|
declare const ORGANIZATION_BASE_ROW_KEYS: readonly ["name", "type", "phones", "emails", "address", "notes", "status", "agencyScope", "agencyId", "community", "canonicalKey", "isAnonymous", "programs"];
|
|
@@ -144,7 +145,7 @@ declare const ORGANIZATION_BASE_ROW_KEYS: readonly ["name", "type", "phones", "e
|
|
|
144
145
|
* envelope aside. A model that declares exactly these is the same data object
|
|
145
146
|
* as every other app's (`organizationSchemaIssues`, `schemas/organization.ts`).
|
|
146
147
|
*/
|
|
147
|
-
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", "
|
|
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"];
|
|
148
149
|
type OrganizationRowKey = (typeof ORGANIZATION_ROW_KEYS)[number];
|
|
149
150
|
/** The record envelope each app's base document adds; never Org facts. */
|
|
150
151
|
declare const ORGANIZATION_ENVELOPE_KEYS: readonly ["_id", "__v", "_schemaVersion", "createdUser", "createdTime", "updatedUser", "updatedTime"];
|
|
@@ -210,13 +211,19 @@ type OrgVspWrite = z.infer<typeof OrgVspWriteSchema>;
|
|
|
210
211
|
/**
|
|
211
212
|
* How an organization arrived. Never taken from a request body: the server
|
|
212
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.
|
|
213
220
|
*/
|
|
214
221
|
interface OrgArrival {
|
|
215
222
|
reviewStatus: OrgReviewStatus;
|
|
216
223
|
/** The app the organization was added in: `thread`, `pave`, `leads`, `platform`. */
|
|
217
224
|
addedInApp: string;
|
|
218
225
|
/** The adding user's platform `users._id`, as a string. */
|
|
219
|
-
|
|
226
|
+
addedBy: string;
|
|
220
227
|
/** The session it was added in, when there was one. */
|
|
221
228
|
addedInSession?: string;
|
|
222
229
|
}
|
|
@@ -379,7 +386,8 @@ interface DirectoryOrganizationView {
|
|
|
379
386
|
/** pending · confirmed · rejected for an organization added inside an app; null on a steward row. */
|
|
380
387
|
reviewStatus: OrgReviewStatus | null;
|
|
381
388
|
addedInApp: string | null;
|
|
382
|
-
addedByUserId
|
|
389
|
+
/** Who added it (a platform `users._id`); a pre-0.60 row's `addedByUserId` reads here too. */
|
|
390
|
+
addedBy: string | null;
|
|
383
391
|
addedInSession: string | null;
|
|
384
392
|
/** The stored lifecycle code (1 active, 2 inactive), else null. */
|
|
385
393
|
status: number | null;
|
|
@@ -72,12 +72,13 @@ var ORG_RECORD_FIELD_NAMES = Object.freeze([
|
|
|
72
72
|
"vspPrivateNonprofit",
|
|
73
73
|
"reviewStatus",
|
|
74
74
|
"addedInApp",
|
|
75
|
-
"
|
|
76
|
-
"addedInSession"
|
|
75
|
+
"addedBy"
|
|
77
76
|
]);
|
|
78
77
|
var ORG_AS_BUILT_FIELD_NAMES = Object.freeze([
|
|
79
78
|
"requiresROI",
|
|
80
79
|
"isCustom",
|
|
80
|
+
"addedByUserId",
|
|
81
|
+
"addedInSession",
|
|
81
82
|
"division",
|
|
82
83
|
"typeOverride",
|
|
83
84
|
"typeKey"
|
|
@@ -137,7 +138,7 @@ function orgArrivalStamp(input) {
|
|
|
137
138
|
return {
|
|
138
139
|
reviewStatus: ORG_REVIEW_STATUS.PENDING,
|
|
139
140
|
addedInApp: app,
|
|
140
|
-
|
|
141
|
+
addedBy: userId,
|
|
141
142
|
...session ? { addedInSession: session } : {}
|
|
142
143
|
};
|
|
143
144
|
}
|
|
@@ -247,7 +248,7 @@ function toDirectoryOrganizationView(raw) {
|
|
|
247
248
|
vspPrivateNonprofit: vsp === true ? flag(r.vspPrivateNonprofit) : null,
|
|
248
249
|
reviewStatus,
|
|
249
250
|
addedInApp: line2(r.addedInApp),
|
|
250
|
-
|
|
251
|
+
addedBy: line2(r.addedBy) ?? line2(r.addedByUserId),
|
|
251
252
|
addedInSession: line2(r.addedInSession),
|
|
252
253
|
status,
|
|
253
254
|
listed: isListedOrganization({ status, reviewStatus }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/orgDirectory/vocabulary.ts","../../src/orgDirectory/schemas.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] 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 \"addedByUserId\",\n \"addedInSession\",\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 `isCustom`,\n * `type_override`, `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 \"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 */\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 addedByUserId: 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 addedByUserId: 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 addedByUserId: 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 addedByUserId: 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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A,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","line"]}
|
|
1
|
+
{"version":3,"sources":["../../src/orgDirectory/vocabulary.ts","../../src/orgDirectory/schemas.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] 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":";AAcO,IAAM,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,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","line"]}
|
|
@@ -860,12 +860,13 @@ var ORG_RECORD_FIELD_NAMES = Object.freeze([
|
|
|
860
860
|
"vspPrivateNonprofit",
|
|
861
861
|
"reviewStatus",
|
|
862
862
|
"addedInApp",
|
|
863
|
-
"
|
|
864
|
-
"addedInSession"
|
|
863
|
+
"addedBy"
|
|
865
864
|
]);
|
|
866
865
|
var ORG_AS_BUILT_FIELD_NAMES = Object.freeze([
|
|
867
866
|
"requiresROI",
|
|
868
867
|
"isCustom",
|
|
868
|
+
"addedByUserId",
|
|
869
|
+
"addedInSession",
|
|
869
870
|
"division",
|
|
870
871
|
"typeOverride",
|
|
871
872
|
"typeKey"
|
|
@@ -992,7 +993,7 @@ function toDirectoryOrganizationView(raw) {
|
|
|
992
993
|
vspPrivateNonprofit: vsp === true ? flag(r.vspPrivateNonprofit) : null,
|
|
993
994
|
reviewStatus,
|
|
994
995
|
addedInApp: line2(r.addedInApp),
|
|
995
|
-
|
|
996
|
+
addedBy: line2(r.addedBy) ?? line2(r.addedByUserId),
|
|
996
997
|
addedInSession: line2(r.addedInSession),
|
|
997
998
|
status,
|
|
998
999
|
listed: isListedOrganization({ status, reviewStatus }),
|