@htilabs/platform-common-models 0.85.0 → 0.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +30 -0
  2. package/dist/{index-XWSYon40.d.cts → index-1pWiqEBC.d.cts} +1 -1
  3. package/dist/{index-Bh1zO_Vu.d.ts → index-uz57Fic9.d.ts} +1 -1
  4. package/dist/index.cjs +12 -1
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +3 -3
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +12 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/models/index.d.cts +2 -2
  11. package/dist/models/index.d.ts +2 -2
  12. package/dist/org-directory/index.cjs +8 -2
  13. package/dist/org-directory/index.cjs.map +1 -1
  14. package/dist/org-directory/index.d.cts +11 -2
  15. package/dist/org-directory/index.d.ts +11 -2
  16. package/dist/org-directory/index.js +8 -2
  17. package/dist/org-directory/index.js.map +1 -1
  18. package/dist/org-merge/index.cjs +8 -2
  19. package/dist/org-merge/index.cjs.map +1 -1
  20. package/dist/org-merge/index.js +8 -2
  21. package/dist/org-merge/index.js.map +1 -1
  22. package/dist/points-of-contact/index.cjs +229 -24
  23. package/dist/points-of-contact/index.cjs.map +1 -1
  24. package/dist/points-of-contact/index.d.cts +50 -5
  25. package/dist/points-of-contact/index.d.ts +50 -5
  26. package/dist/points-of-contact/index.js +226 -23
  27. package/dist/points-of-contact/index.js.map +1 -1
  28. package/dist/reader-BmhzOis-.d.ts +273 -0
  29. package/dist/reader-DfQtdw6n.d.cts +273 -0
  30. package/dist/schemas/index.cjs +12 -1
  31. package/dist/schemas/index.cjs.map +1 -1
  32. package/dist/schemas/index.d.cts +57 -27
  33. package/dist/schemas/index.d.ts +57 -27
  34. package/dist/schemas/index.js +12 -1
  35. package/dist/schemas/index.js.map +1 -1
  36. package/dist/seat-logs/index.cjs +815 -0
  37. package/dist/seat-logs/index.cjs.map +1 -0
  38. package/dist/seat-logs/index.d.cts +274 -0
  39. package/dist/seat-logs/index.d.ts +274 -0
  40. package/dist/seat-logs/index.js +742 -0
  41. package/dist/seat-logs/index.js.map +1 -0
  42. package/dist/validation/index.d.cts +1 -1
  43. package/dist/validation/index.d.ts +1 -1
  44. package/package.json +6 -1
  45. package/src/orgDirectory/__tests__/programDetails.test.ts +2 -1
  46. package/src/orgDirectory/__tests__/programTeamLink.test.ts +107 -0
  47. package/src/orgDirectory/schemas.ts +8 -1
  48. package/src/pointsOfContact/__tests__/seatContactLog.test.ts +170 -0
  49. package/src/pointsOfContact/readRules.ts +22 -4
  50. package/src/pointsOfContact/reader.ts +95 -1
  51. package/src/pointsOfContact/schemas.ts +4 -3
  52. package/src/schemas/organization-program.ts +25 -2
  53. package/src/seatLogs/__tests__/seatLogs.review.test.ts +222 -0
  54. package/src/seatLogs/__tests__/seatLogs.test.ts +335 -0
  55. package/src/seatLogs/index.ts +15 -0
  56. package/src/seatLogs/log.ts +700 -0
  57. package/src/seatLogs/personId.ts +100 -0
  58. package/src/seatLogs/personSlugWordlists.ts +40 -0
  59. package/src/seatLogs/reader.ts +143 -0
  60. package/src/seatLogs/schemas.ts +118 -0
  61. package/dist/{agency-CnVTwLeV.d.ts → agency-BHv54o79.d.ts} +4 -4
  62. package/dist/{agency-8ufZJJDH.d.cts → agency-Djp57S71.d.cts} +4 -4
  63. package/dist/{cvcEntry-D787utvP.d.cts → cvcEntry-DAuhe0cd.d.cts} +8 -8
  64. package/dist/{cvcEntry-D787utvP.d.ts → cvcEntry-DAuhe0cd.d.ts} +8 -8
@@ -1,4 +1,6 @@
1
1
  import { z } from 'zod';
2
+ import { b as SeatContactEntry, l as SeatLogDbLike, p as SeatLogShapeError } from '../reader-DfQtdw6n.cjs';
3
+ import '../enums/index.cjs';
2
4
 
3
5
  /**
4
6
  * Point of contact vocabularies (pl-3r8): subject types, purposes, urgent
@@ -202,9 +204,10 @@ declare function pocInitialStatus(origin: PocOrigin): PocStatus;
202
204
  *
203
205
  * ## Known deviations (0.30.0)
204
206
  *
205
- * - A seat-linked contact still reads ONE email and ONE phone from `users`
206
- * until a person Contact log exists (pl-9h4). Canon's motivating case
207
- * (Crysta's own seat-linked contact) is therefore not yet met.
207
+ * - A seat-linked contact reads the seat's contact log (`seat_contacts`)
208
+ * when the reader's seat resolver carries it (`withSeatContactLogs`,
209
+ * pl-9h4, 0.87.0); a seat with no log yet still reads ONE email and ONE
210
+ * phone from `users`.
208
211
  * - An entry is removed, not retired: canon's write-in ledger keeps retired
209
212
  * entries stamped `retiredOn` (retire-not-remove, L8181-L8185); this list
210
213
  * keeps only the live ones.
@@ -1132,6 +1135,14 @@ interface SeatReach {
1132
1135
  email: string | null;
1133
1136
  phone: string | null;
1134
1137
  name: string | null;
1138
+ /**
1139
+ * The seat's live emails from its contact log (pl-9h4), preferred marked.
1140
+ * When present, a seat-linked contact reads these instead of `email`.
1141
+ * Absent = the seat has no contact log yet: `email` is read as one entry.
1142
+ */
1143
+ emails?: PocContactEntry[];
1144
+ /** The seat's live phones from its contact log; the same rule against `phone`. */
1145
+ phones?: PocContactEntry[];
1135
1146
  }
1136
1147
  /** The steward view: everything but the identity key, seat resolved. */
1137
1148
  interface PointOfContactStewardView extends Omit<PointOfContactDoc, "identity_key"> {
@@ -1153,7 +1164,7 @@ interface PointOfContactNetworkView {
1153
1164
  agency_id: string | null;
1154
1165
  org_id: string | null;
1155
1166
  display_name: string | null;
1156
- /** The row's emails, or the seat's email as one preferred entry when the contact is seat-linked and a seat resolver was given. */
1167
+ /** The row's emails, or for a seat-linked contact (a seat resolver given) the seat's contact-log emails, else its email as one preferred entry. */
1157
1168
  emails: PocContactEntry[];
1158
1169
  /** The row's phones, or the seat's phone as one preferred entry (the same rules as `emails`). */
1159
1170
  phones: PocContactEntry[];
@@ -1213,6 +1224,9 @@ declare function byContactReadingOrder(a: Pick<PointOfContactDoc, "subject_type"
1213
1224
  * ObjectId filter for `users._id`; the reader passes a {@link SeatResolver}
1214
1225
  * that reads its own `users`. The partner rollup REQUIRES one, so a reader
1215
1226
  * cannot silently drop seat-linked referral contacts.
1227
+ * Wrap it in {@link withSeatContactLogs} to read each seat's contact log
1228
+ * (every email and phone, with the log's preferred mark) instead of the one
1229
+ * email and phone on `users` (pl-9h4).
1216
1230
  *
1217
1231
  * ## Confidential Referrals (magic link) holders (pl-iza, 0.32.0)
1218
1232
  *
@@ -1241,6 +1255,37 @@ interface PocDbLike {
1241
1255
  }
1242
1256
  /** Resolves seat ids (platform-db `users._id`, string form) to their reach. Missing ids are simply absent. */
1243
1257
  type SeatResolver = (userIds: readonly string[]) => Promise<ReadonlyMap<string, SeatReach>>;
1258
+ /**
1259
+ * A seat's contact log → the lists a seat-linked contact reads (pl-9h4): the
1260
+ * live emails (lowercased, as this module keeps emails) and phones, each with
1261
+ * the log's preferred mark (one per type; the first when none is marked).
1262
+ * `null` when the log has no live entry of either type — the caller then
1263
+ * keeps the seat's flat `email` / `phone`.
1264
+ */
1265
+ declare function seatContactListsFromLog(entries: readonly SeatContactEntry[]): {
1266
+ emails: PocContactEntry[];
1267
+ phones: PocContactEntry[];
1268
+ } | null;
1269
+ /**
1270
+ * Wrap a seat resolver so seat-linked contacts read each seat's contact log
1271
+ * (`seat_contacts`, subject_type `user`) instead of the single `users`
1272
+ * email / phone (pl-9h4).
1273
+ *
1274
+ * - Only seats `resolve` returned are enriched. A seat it leaves out (an
1275
+ * ended seat in the network read, an id with no `users` row) stays out:
1276
+ * its log never publishes it.
1277
+ * - Per type: the log's emails (with `email` = its preferred) replace the
1278
+ * seat's flat email only when the log has a live email; likewise phones.
1279
+ * A type the log has no live entry of keeps what `resolve` returned.
1280
+ * - Ids are matched case-insensitively, as the base resolvers match
1281
+ * `users._id`; the result is keyed by the id as asked.
1282
+ * - A stored log row that does not match the entry shape is skipped for its
1283
+ * seat (reported to `onInvalidRow`) and never fails the read; a read ERROR
1284
+ * propagates.
1285
+ */
1286
+ declare function withSeatContactLogs(db: SeatLogDbLike, resolve: SeatResolver, opts?: {
1287
+ onInvalidRow?: (error: SeatLogShapeError) => void;
1288
+ }): SeatResolver;
1244
1289
  /**
1245
1290
  * A subject, always read together with its agency where ids can collide.
1246
1291
  * Program, team and location ids can be slugs two agencies share, so their reads
@@ -1704,4 +1749,4 @@ interface MintPartnerContactArgs {
1704
1749
  */
1705
1750
  declare function mintPartnerContact(db: PocWriteDbLike, args: MintPartnerContactArgs, driver: PocWriterDriver): Promise<PartnerContactResult>;
1706
1751
 
1707
- export { CONTACT_PURPOSES, CONTACT_PURPOSE_CODES, type ConfidentialDeliverOptions, type ConfidentialDeliveryResult, type ConfidentialReferralRecipients, type ConfidentialSendOne, type ContactPurpose, type ContactPurposeCode, type MagicLinkSendList, type MintPartnerContactArgs, PARTNER_CONTACT_FAILURE_REASONS, POC_ADDED_IN_APPS, POC_IDENTITY_INDEX_FILTER, POC_ID_PATTERN, POC_IN_APP_PENDING_CAP_PER_ACTOR, POC_IN_APP_PENDING_CAP_PER_PARTNER, POC_IN_APP_PENDING_INDEX, POC_IN_APP_PENDING_INDEX_FILTER, POC_IN_APP_PENDING_INDEX_KEY, POC_MAX_CONTACT_ENTRIES, POC_ORIGINS, POC_PARTNER_ADD_APPS, POC_PENDING_QUEUE_INDEX, POC_PRIMARY_INDEX_FILTER, POC_STATUSES, POC_SUBJECT_TYPES, POC_SUBJECT_TYPE_LABELS, POC_URGENT_METHODS, POC_URGENT_METHOD_KEYS, POINTS_OF_CONTACT_COLLECTION, POINT_OF_CONTACT_INDEXES, type PartnerContactFailure, type PartnerContactFailureReason, type PartnerContactReceipt, type PartnerContactResult, type PartnerContactSelector, type PartnerContactSelectorInput, PartnerContactSelectorSchema, type PocAddedInApp, type PocCollectionLike, type PocContactEntry, type PocCreateIndexOptions, type PocDbLike, type PocDetails, type PocDetailsInput, PocDetailsSchema, PocEmailListSchema, PocEmailSchema, type PocInApp, type PocInAppActor, type PocInAppInput, PocInAppSchema, type PocIndexInfoLike, PocLinkIdSchema, type PocObjectIdClass, type PocOrigin, type PocOwner, PocOwnerSchema, type PocPartnerAddApp, type PocPartnerSelector, type PocPatch, type PocPatchInput, PocPatchSchema, PocPhoneListSchema, type PocRuleInput, type PocRuleViolation, type PocSeed, type PocSeedInput, PocSeedSchema, type PocStatus, type PocSubjectRef, type PocSubjectType, type PocUrgentMethod, type PocWriteCollectionLike, type PocWriteCursorLike, type PocWriteDbLike, type PocWriterDriver, type PointOfContactDoc, PointOfContactDocSchema, type PointOfContactNetworkView, type PointOfContactOwnerView, PointOfContactShapeError, type PointOfContactStewardView, REFERRALS_MAGIC_LINK_PURPOSE, type ReferralContactsOptions, type ReferralContactsResult, type ReferralRecipient, type SeatReach, type SeatResolver, StoredContactEntrySchema, StoredEmailListSchema, StoredPhoneListSchema, byContactReadingOrder, checkPocIndexes, contactPurposeLabel, definedPatch, ensurePocIndexes, formatPocPhone, getContact, isContactPurposeCode, isNetworkVisible, isPocUrgentMethodCode, listContactsForSubject, listOwnerContactsForSubject, listPendingContacts, listReferralContactsForPartner, mintPartnerContact, normalizePointOfContact, pocDuplicateKeyFailure, pocIdentityKey, pocInitialStatus, pocPhoneDigits, pocRowsWithIdentity, pocRuleViolations, pocSubjectTypeLabel, pocUrgentMethodCode, preferredContactEntry, preferredEmail, preferredPhone, resolveMagicLinkRecipients, toNetworkView, toOwnerView, toStewardView };
1752
+ export { CONTACT_PURPOSES, CONTACT_PURPOSE_CODES, type ConfidentialDeliverOptions, type ConfidentialDeliveryResult, type ConfidentialReferralRecipients, type ConfidentialSendOne, type ContactPurpose, type ContactPurposeCode, type MagicLinkSendList, type MintPartnerContactArgs, PARTNER_CONTACT_FAILURE_REASONS, POC_ADDED_IN_APPS, POC_IDENTITY_INDEX_FILTER, POC_ID_PATTERN, POC_IN_APP_PENDING_CAP_PER_ACTOR, POC_IN_APP_PENDING_CAP_PER_PARTNER, POC_IN_APP_PENDING_INDEX, POC_IN_APP_PENDING_INDEX_FILTER, POC_IN_APP_PENDING_INDEX_KEY, POC_MAX_CONTACT_ENTRIES, POC_ORIGINS, POC_PARTNER_ADD_APPS, POC_PENDING_QUEUE_INDEX, POC_PRIMARY_INDEX_FILTER, POC_STATUSES, POC_SUBJECT_TYPES, POC_SUBJECT_TYPE_LABELS, POC_URGENT_METHODS, POC_URGENT_METHOD_KEYS, POINTS_OF_CONTACT_COLLECTION, POINT_OF_CONTACT_INDEXES, type PartnerContactFailure, type PartnerContactFailureReason, type PartnerContactReceipt, type PartnerContactResult, type PartnerContactSelector, type PartnerContactSelectorInput, PartnerContactSelectorSchema, type PocAddedInApp, type PocCollectionLike, type PocContactEntry, type PocCreateIndexOptions, type PocDbLike, type PocDetails, type PocDetailsInput, PocDetailsSchema, PocEmailListSchema, PocEmailSchema, type PocInApp, type PocInAppActor, type PocInAppInput, PocInAppSchema, type PocIndexInfoLike, PocLinkIdSchema, type PocObjectIdClass, type PocOrigin, type PocOwner, PocOwnerSchema, type PocPartnerAddApp, type PocPartnerSelector, type PocPatch, type PocPatchInput, PocPatchSchema, PocPhoneListSchema, type PocRuleInput, type PocRuleViolation, type PocSeed, type PocSeedInput, PocSeedSchema, type PocStatus, type PocSubjectRef, type PocSubjectType, type PocUrgentMethod, type PocWriteCollectionLike, type PocWriteCursorLike, type PocWriteDbLike, type PocWriterDriver, type PointOfContactDoc, PointOfContactDocSchema, type PointOfContactNetworkView, type PointOfContactOwnerView, PointOfContactShapeError, type PointOfContactStewardView, REFERRALS_MAGIC_LINK_PURPOSE, type ReferralContactsOptions, type ReferralContactsResult, type ReferralRecipient, type SeatReach, type SeatResolver, StoredContactEntrySchema, StoredEmailListSchema, StoredPhoneListSchema, byContactReadingOrder, checkPocIndexes, contactPurposeLabel, definedPatch, ensurePocIndexes, formatPocPhone, getContact, isContactPurposeCode, isNetworkVisible, isPocUrgentMethodCode, listContactsForSubject, listOwnerContactsForSubject, listPendingContacts, listReferralContactsForPartner, mintPartnerContact, normalizePointOfContact, pocDuplicateKeyFailure, pocIdentityKey, pocInitialStatus, pocPhoneDigits, pocRowsWithIdentity, pocRuleViolations, pocSubjectTypeLabel, pocUrgentMethodCode, preferredContactEntry, preferredEmail, preferredPhone, resolveMagicLinkRecipients, seatContactListsFromLog, toNetworkView, toOwnerView, toStewardView, withSeatContactLogs };
@@ -1,4 +1,6 @@
1
1
  import { z } from 'zod';
2
+ import { b as SeatContactEntry, l as SeatLogDbLike, p as SeatLogShapeError } from '../reader-BmhzOis-.js';
3
+ import '../enums/index.js';
2
4
 
3
5
  /**
4
6
  * Point of contact vocabularies (pl-3r8): subject types, purposes, urgent
@@ -202,9 +204,10 @@ declare function pocInitialStatus(origin: PocOrigin): PocStatus;
202
204
  *
203
205
  * ## Known deviations (0.30.0)
204
206
  *
205
- * - A seat-linked contact still reads ONE email and ONE phone from `users`
206
- * until a person Contact log exists (pl-9h4). Canon's motivating case
207
- * (Crysta's own seat-linked contact) is therefore not yet met.
207
+ * - A seat-linked contact reads the seat's contact log (`seat_contacts`)
208
+ * when the reader's seat resolver carries it (`withSeatContactLogs`,
209
+ * pl-9h4, 0.87.0); a seat with no log yet still reads ONE email and ONE
210
+ * phone from `users`.
208
211
  * - An entry is removed, not retired: canon's write-in ledger keeps retired
209
212
  * entries stamped `retiredOn` (retire-not-remove, L8181-L8185); this list
210
213
  * keeps only the live ones.
@@ -1132,6 +1135,14 @@ interface SeatReach {
1132
1135
  email: string | null;
1133
1136
  phone: string | null;
1134
1137
  name: string | null;
1138
+ /**
1139
+ * The seat's live emails from its contact log (pl-9h4), preferred marked.
1140
+ * When present, a seat-linked contact reads these instead of `email`.
1141
+ * Absent = the seat has no contact log yet: `email` is read as one entry.
1142
+ */
1143
+ emails?: PocContactEntry[];
1144
+ /** The seat's live phones from its contact log; the same rule against `phone`. */
1145
+ phones?: PocContactEntry[];
1135
1146
  }
1136
1147
  /** The steward view: everything but the identity key, seat resolved. */
1137
1148
  interface PointOfContactStewardView extends Omit<PointOfContactDoc, "identity_key"> {
@@ -1153,7 +1164,7 @@ interface PointOfContactNetworkView {
1153
1164
  agency_id: string | null;
1154
1165
  org_id: string | null;
1155
1166
  display_name: string | null;
1156
- /** The row's emails, or the seat's email as one preferred entry when the contact is seat-linked and a seat resolver was given. */
1167
+ /** The row's emails, or for a seat-linked contact (a seat resolver given) the seat's contact-log emails, else its email as one preferred entry. */
1157
1168
  emails: PocContactEntry[];
1158
1169
  /** The row's phones, or the seat's phone as one preferred entry (the same rules as `emails`). */
1159
1170
  phones: PocContactEntry[];
@@ -1213,6 +1224,9 @@ declare function byContactReadingOrder(a: Pick<PointOfContactDoc, "subject_type"
1213
1224
  * ObjectId filter for `users._id`; the reader passes a {@link SeatResolver}
1214
1225
  * that reads its own `users`. The partner rollup REQUIRES one, so a reader
1215
1226
  * cannot silently drop seat-linked referral contacts.
1227
+ * Wrap it in {@link withSeatContactLogs} to read each seat's contact log
1228
+ * (every email and phone, with the log's preferred mark) instead of the one
1229
+ * email and phone on `users` (pl-9h4).
1216
1230
  *
1217
1231
  * ## Confidential Referrals (magic link) holders (pl-iza, 0.32.0)
1218
1232
  *
@@ -1241,6 +1255,37 @@ interface PocDbLike {
1241
1255
  }
1242
1256
  /** Resolves seat ids (platform-db `users._id`, string form) to their reach. Missing ids are simply absent. */
1243
1257
  type SeatResolver = (userIds: readonly string[]) => Promise<ReadonlyMap<string, SeatReach>>;
1258
+ /**
1259
+ * A seat's contact log → the lists a seat-linked contact reads (pl-9h4): the
1260
+ * live emails (lowercased, as this module keeps emails) and phones, each with
1261
+ * the log's preferred mark (one per type; the first when none is marked).
1262
+ * `null` when the log has no live entry of either type — the caller then
1263
+ * keeps the seat's flat `email` / `phone`.
1264
+ */
1265
+ declare function seatContactListsFromLog(entries: readonly SeatContactEntry[]): {
1266
+ emails: PocContactEntry[];
1267
+ phones: PocContactEntry[];
1268
+ } | null;
1269
+ /**
1270
+ * Wrap a seat resolver so seat-linked contacts read each seat's contact log
1271
+ * (`seat_contacts`, subject_type `user`) instead of the single `users`
1272
+ * email / phone (pl-9h4).
1273
+ *
1274
+ * - Only seats `resolve` returned are enriched. A seat it leaves out (an
1275
+ * ended seat in the network read, an id with no `users` row) stays out:
1276
+ * its log never publishes it.
1277
+ * - Per type: the log's emails (with `email` = its preferred) replace the
1278
+ * seat's flat email only when the log has a live email; likewise phones.
1279
+ * A type the log has no live entry of keeps what `resolve` returned.
1280
+ * - Ids are matched case-insensitively, as the base resolvers match
1281
+ * `users._id`; the result is keyed by the id as asked.
1282
+ * - A stored log row that does not match the entry shape is skipped for its
1283
+ * seat (reported to `onInvalidRow`) and never fails the read; a read ERROR
1284
+ * propagates.
1285
+ */
1286
+ declare function withSeatContactLogs(db: SeatLogDbLike, resolve: SeatResolver, opts?: {
1287
+ onInvalidRow?: (error: SeatLogShapeError) => void;
1288
+ }): SeatResolver;
1244
1289
  /**
1245
1290
  * A subject, always read together with its agency where ids can collide.
1246
1291
  * Program, team and location ids can be slugs two agencies share, so their reads
@@ -1704,4 +1749,4 @@ interface MintPartnerContactArgs {
1704
1749
  */
1705
1750
  declare function mintPartnerContact(db: PocWriteDbLike, args: MintPartnerContactArgs, driver: PocWriterDriver): Promise<PartnerContactResult>;
1706
1751
 
1707
- export { CONTACT_PURPOSES, CONTACT_PURPOSE_CODES, type ConfidentialDeliverOptions, type ConfidentialDeliveryResult, type ConfidentialReferralRecipients, type ConfidentialSendOne, type ContactPurpose, type ContactPurposeCode, type MagicLinkSendList, type MintPartnerContactArgs, PARTNER_CONTACT_FAILURE_REASONS, POC_ADDED_IN_APPS, POC_IDENTITY_INDEX_FILTER, POC_ID_PATTERN, POC_IN_APP_PENDING_CAP_PER_ACTOR, POC_IN_APP_PENDING_CAP_PER_PARTNER, POC_IN_APP_PENDING_INDEX, POC_IN_APP_PENDING_INDEX_FILTER, POC_IN_APP_PENDING_INDEX_KEY, POC_MAX_CONTACT_ENTRIES, POC_ORIGINS, POC_PARTNER_ADD_APPS, POC_PENDING_QUEUE_INDEX, POC_PRIMARY_INDEX_FILTER, POC_STATUSES, POC_SUBJECT_TYPES, POC_SUBJECT_TYPE_LABELS, POC_URGENT_METHODS, POC_URGENT_METHOD_KEYS, POINTS_OF_CONTACT_COLLECTION, POINT_OF_CONTACT_INDEXES, type PartnerContactFailure, type PartnerContactFailureReason, type PartnerContactReceipt, type PartnerContactResult, type PartnerContactSelector, type PartnerContactSelectorInput, PartnerContactSelectorSchema, type PocAddedInApp, type PocCollectionLike, type PocContactEntry, type PocCreateIndexOptions, type PocDbLike, type PocDetails, type PocDetailsInput, PocDetailsSchema, PocEmailListSchema, PocEmailSchema, type PocInApp, type PocInAppActor, type PocInAppInput, PocInAppSchema, type PocIndexInfoLike, PocLinkIdSchema, type PocObjectIdClass, type PocOrigin, type PocOwner, PocOwnerSchema, type PocPartnerAddApp, type PocPartnerSelector, type PocPatch, type PocPatchInput, PocPatchSchema, PocPhoneListSchema, type PocRuleInput, type PocRuleViolation, type PocSeed, type PocSeedInput, PocSeedSchema, type PocStatus, type PocSubjectRef, type PocSubjectType, type PocUrgentMethod, type PocWriteCollectionLike, type PocWriteCursorLike, type PocWriteDbLike, type PocWriterDriver, type PointOfContactDoc, PointOfContactDocSchema, type PointOfContactNetworkView, type PointOfContactOwnerView, PointOfContactShapeError, type PointOfContactStewardView, REFERRALS_MAGIC_LINK_PURPOSE, type ReferralContactsOptions, type ReferralContactsResult, type ReferralRecipient, type SeatReach, type SeatResolver, StoredContactEntrySchema, StoredEmailListSchema, StoredPhoneListSchema, byContactReadingOrder, checkPocIndexes, contactPurposeLabel, definedPatch, ensurePocIndexes, formatPocPhone, getContact, isContactPurposeCode, isNetworkVisible, isPocUrgentMethodCode, listContactsForSubject, listOwnerContactsForSubject, listPendingContacts, listReferralContactsForPartner, mintPartnerContact, normalizePointOfContact, pocDuplicateKeyFailure, pocIdentityKey, pocInitialStatus, pocPhoneDigits, pocRowsWithIdentity, pocRuleViolations, pocSubjectTypeLabel, pocUrgentMethodCode, preferredContactEntry, preferredEmail, preferredPhone, resolveMagicLinkRecipients, toNetworkView, toOwnerView, toStewardView };
1752
+ export { CONTACT_PURPOSES, CONTACT_PURPOSE_CODES, type ConfidentialDeliverOptions, type ConfidentialDeliveryResult, type ConfidentialReferralRecipients, type ConfidentialSendOne, type ContactPurpose, type ContactPurposeCode, type MagicLinkSendList, type MintPartnerContactArgs, PARTNER_CONTACT_FAILURE_REASONS, POC_ADDED_IN_APPS, POC_IDENTITY_INDEX_FILTER, POC_ID_PATTERN, POC_IN_APP_PENDING_CAP_PER_ACTOR, POC_IN_APP_PENDING_CAP_PER_PARTNER, POC_IN_APP_PENDING_INDEX, POC_IN_APP_PENDING_INDEX_FILTER, POC_IN_APP_PENDING_INDEX_KEY, POC_MAX_CONTACT_ENTRIES, POC_ORIGINS, POC_PARTNER_ADD_APPS, POC_PENDING_QUEUE_INDEX, POC_PRIMARY_INDEX_FILTER, POC_STATUSES, POC_SUBJECT_TYPES, POC_SUBJECT_TYPE_LABELS, POC_URGENT_METHODS, POC_URGENT_METHOD_KEYS, POINTS_OF_CONTACT_COLLECTION, POINT_OF_CONTACT_INDEXES, type PartnerContactFailure, type PartnerContactFailureReason, type PartnerContactReceipt, type PartnerContactResult, type PartnerContactSelector, type PartnerContactSelectorInput, PartnerContactSelectorSchema, type PocAddedInApp, type PocCollectionLike, type PocContactEntry, type PocCreateIndexOptions, type PocDbLike, type PocDetails, type PocDetailsInput, PocDetailsSchema, PocEmailListSchema, PocEmailSchema, type PocInApp, type PocInAppActor, type PocInAppInput, PocInAppSchema, type PocIndexInfoLike, PocLinkIdSchema, type PocObjectIdClass, type PocOrigin, type PocOwner, PocOwnerSchema, type PocPartnerAddApp, type PocPartnerSelector, type PocPatch, type PocPatchInput, PocPatchSchema, PocPhoneListSchema, type PocRuleInput, type PocRuleViolation, type PocSeed, type PocSeedInput, PocSeedSchema, type PocStatus, type PocSubjectRef, type PocSubjectType, type PocUrgentMethod, type PocWriteCollectionLike, type PocWriteCursorLike, type PocWriteDbLike, type PocWriterDriver, type PointOfContactDoc, PointOfContactDocSchema, type PointOfContactNetworkView, type PointOfContactOwnerView, PointOfContactShapeError, type PointOfContactStewardView, REFERRALS_MAGIC_LINK_PURPOSE, type ReferralContactsOptions, type ReferralContactsResult, type ReferralRecipient, type SeatReach, type SeatResolver, StoredContactEntrySchema, StoredEmailListSchema, StoredPhoneListSchema, byContactReadingOrder, checkPocIndexes, contactPurposeLabel, definedPatch, ensurePocIndexes, formatPocPhone, getContact, isContactPurposeCode, isNetworkVisible, isPocUrgentMethodCode, listContactsForSubject, listOwnerContactsForSubject, listPendingContacts, listReferralContactsForPartner, mintPartnerContact, normalizePointOfContact, pocDuplicateKeyFailure, pocIdentityKey, pocInitialStatus, pocPhoneDigits, pocRowsWithIdentity, pocRuleViolations, pocSubjectTypeLabel, pocUrgentMethodCode, preferredContactEntry, preferredEmail, preferredPhone, resolveMagicLinkRecipients, seatContactListsFromLog, toNetworkView, toOwnerView, toStewardView, withSeatContactLogs };
@@ -443,10 +443,17 @@ function reachOf(d, seat) {
443
443
  if (!d.user_id) return { emails: copyEntries(d.emails), phones: copyEntries(d.phones) };
444
444
  const one = (v) => v ? [{ value: v, is_preferred: true }] : [];
445
445
  return {
446
- emails: one(seat?.email?.trim().toLowerCase()),
447
- phones: one(seat?.phone?.trim())
446
+ emails: seat?.emails ? copyEntries(seat.emails) : one(seat?.email?.trim().toLowerCase()),
447
+ phones: seat?.phones ? copyEntries(seat.phones) : one(seat?.phone?.trim())
448
448
  };
449
449
  }
450
+ function copySeat(seat) {
451
+ if (!seat) return null;
452
+ const out = { ...seat };
453
+ if (seat.emails) out.emails = copyEntries(seat.emails);
454
+ if (seat.phones) out.phones = copyEntries(seat.phones);
455
+ return out;
456
+ }
450
457
  var preferredValue = (list) => preferredContactEntry(list)?.value ?? null;
451
458
  function toStewardView(d, seat) {
452
459
  const { identity_key: _internal, ...rest } = d;
@@ -458,7 +465,7 @@ function toStewardView(d, seat) {
458
465
  purposes: [...d.purposes],
459
466
  urgent_methods: [...d.urgent_methods],
460
467
  purpose_labels: d.purposes.map(contactPurposeLabel),
461
- seat: d.user_id ? seat ?? null : null,
468
+ seat: d.user_id ? copySeat(seat) : null,
462
469
  email: preferredValue(reach.emails),
463
470
  phone: preferredValue(reach.phones)
464
471
  };
@@ -508,7 +515,195 @@ function byContactReadingOrder(a, b) {
508
515
  return SUBJECT_ORDER[a.subject_type] - SUBJECT_ORDER[b.subject_type] || a.subject_id.localeCompare(b.subject_id) || Number(b.is_primary) - Number(a.is_primary) || (a.display_name ?? "").localeCompare(b.display_name ?? "") || a.id.localeCompare(b.id);
509
516
  }
510
517
 
518
+ // src/seatLogs/schemas.ts
519
+ import { z as z2 } from "zod";
520
+
521
+ // src/generated/cvc-enums.ts
522
+ var NameTypeKeys = {
523
+ missingness_root: "001-000-000-000-000-000-000",
524
+ unknown: "001-000-000-000-000-000-001",
525
+ anonymous: "001-000-000-000-000-000-002",
526
+ data_not_collected: "001-000-000-000-000-000-003",
527
+ alias: "001-001-000-000-000-000-000",
528
+ code_name: "001-002-000-000-000-000-000",
529
+ handle_screenname: "001-003-000-000-000-000-000",
530
+ legal: "001-004-000-000-000-000-000",
531
+ maiden_former: "001-005-000-000-000-000-000",
532
+ nickname: "001-006-000-000-000-000-000",
533
+ street_name: "001-007-000-000-000-000-000",
534
+ trade_name_stage_name: "001-008-000-000-000-000-000"
535
+ };
536
+
537
+ // src/seatLogs/schemas.ts
538
+ var SEAT_CONTACTS_COLLECTION = "seat_contacts";
539
+ var SEAT_LOG_SUBJECT_TYPES = ["user", "person"];
540
+ var SEAT_CONTACT_TYPES = ["email", "phone"];
541
+ var SEAT_NAME_TYPES = Object.keys(NameTypeKeys);
542
+ var SeatLogEventSchema = z2.object({
543
+ /** `add`, `set_display`, `set_preferred`, `archive`, or `cascade` (a sibling's flag moved). */
544
+ act: z2.string().min(1),
545
+ /** ISO instant. */
546
+ at: z2.string().min(1),
547
+ /** The acting seat's id. */
548
+ actor: z2.string()
549
+ });
550
+ var DayOrEmpty = z2.union([z2.literal(""), z2.string().regex(/^\d{4}-\d{2}-\d{2}$/)]);
551
+ var subjectShape = {
552
+ entry_id: z2.string().min(1),
553
+ subject_id: z2.string().min(1),
554
+ subject_type: z2.enum(SEAT_LOG_SUBJECT_TYPES),
555
+ period_start: DayOrEmpty,
556
+ period_end: DayOrEmpty,
557
+ /** Where the entry came from (`admin_hub` on the profile). */
558
+ source: z2.string(),
559
+ /** How it was captured (`direct_entry` on the profile). */
560
+ method: z2.string(),
561
+ notes: z2.string(),
562
+ events: z2.array(SeatLogEventSchema).optional()
563
+ };
564
+ var SeatNameEntrySchema = z2.object({
565
+ ...subjectShape,
566
+ name_type: z2.enum(SEAT_NAME_TYPES),
567
+ /** The name as written. */
568
+ raw: z2.string().min(1),
569
+ /** The display name: one live entry per subject carries it. */
570
+ is_display: z2.boolean(),
571
+ /** Set with the display mark on the profile (prototype acts both together). */
572
+ is_preferred: z2.boolean()
573
+ });
574
+ var SeatContactEntrySchema = z2.object({
575
+ ...subjectShape,
576
+ contact_type: z2.enum(SEAT_CONTACT_TYPES),
577
+ /** Email trimmed; phone in the store's canonical display form ({@link canonSeatContactValue}). */
578
+ value: z2.string().min(1),
579
+ use: z2.string(),
580
+ /** The preferred entry of its type: one live entry per subject and type carries it. */
581
+ is_preferred: z2.boolean(),
582
+ safety_status: z2.string(),
583
+ /** Phone only: the identity key ({@link seatContactKey}), stamped by the store. */
584
+ digits: z2.string().optional()
585
+ });
586
+
587
+ // src/seatLogs/log.ts
588
+ var isLive = (e) => !e.period_end;
589
+ function liveSeatContacts(entries) {
590
+ return entries.filter(isLive);
591
+ }
592
+ function preferredSeatContact(entries, type) {
593
+ const live = liveSeatContacts(entries).filter((e) => e.contact_type === type);
594
+ return live.find((e) => e.is_preferred) ?? live[0] ?? null;
595
+ }
596
+
597
+ // src/seatLogs/reader.ts
598
+ var SeatLogShapeError = class extends Error {
599
+ constructor(entryId, issues) {
600
+ super(`seat-logs: stored entry ${entryId ?? "(no id)"} does not match the contract: ${issues.join("; ")}`);
601
+ this.entryId = entryId;
602
+ this.issues = issues;
603
+ this.name = "SeatLogShapeError";
604
+ }
605
+ };
606
+ function strip(r) {
607
+ if (r === null || typeof r !== "object") return {};
608
+ const { _id: _ignored, ...rest } = r;
609
+ return rest;
610
+ }
611
+ function parseWith(schema, raw) {
612
+ const row = strip(raw);
613
+ const p = schema.safeParse(row);
614
+ if (p.success) return p.data;
615
+ throw new SeatLogShapeError(
616
+ typeof row.entry_id === "string" ? row.entry_id : null,
617
+ p.error.issues.map((i) => `${i.path.join(".") || "(row)"}: ${i.message}`)
618
+ );
619
+ }
620
+ var idForms = (id) => [.../* @__PURE__ */ new Set([id, id.toLowerCase()])];
621
+ var byEntryId = (a, b) => a.entry_id < b.entry_id ? -1 : a.entry_id > b.entry_id ? 1 : 0;
622
+ async function readLogs(db, collection, subjectType, subjectIds, parse, opts) {
623
+ const ids = [...new Set(subjectIds.filter((s) => typeof s === "string" && s))];
624
+ const out = /* @__PURE__ */ new Map();
625
+ if (!ids.length) return out;
626
+ const askedByKey = /* @__PURE__ */ new Map();
627
+ for (const id of ids) {
628
+ const k = id.toLowerCase();
629
+ askedByKey.set(k, [...askedByKey.get(k) ?? [], id]);
630
+ }
631
+ const raw = await db.collection(collection).find({ subject_type: subjectType, subject_id: { $in: ids.flatMap(idForms) } }).toArray();
632
+ for (const r of raw) {
633
+ let e;
634
+ try {
635
+ e = parse(r);
636
+ } catch (err) {
637
+ if (opts.invalid !== "skip" || !(err instanceof SeatLogShapeError)) throw err;
638
+ opts.onInvalidRow?.(err);
639
+ continue;
640
+ }
641
+ for (const asked of askedByKey.get(e.subject_id.toLowerCase()) ?? []) {
642
+ const list = out.get(asked) ?? [];
643
+ list.push(e);
644
+ out.set(asked, list);
645
+ }
646
+ }
647
+ for (const list of out.values()) list.sort(byEntryId);
648
+ return out;
649
+ }
650
+ function readSeatContactLogs(db, subjectIds, subjectType = "user", opts = {}) {
651
+ return readLogs(
652
+ db,
653
+ SEAT_CONTACTS_COLLECTION,
654
+ subjectType,
655
+ subjectIds,
656
+ (r) => parseWith(SeatContactEntrySchema, r),
657
+ opts
658
+ );
659
+ }
660
+
511
661
  // src/pointsOfContact/reader.ts
662
+ function seatContactListsFromLog(entries) {
663
+ const live = liveSeatContacts(entries);
664
+ if (!live.length) return null;
665
+ const listOf = (type) => {
666
+ const pref = preferredSeatContact(live, type);
667
+ const seen = /* @__PURE__ */ new Set();
668
+ const out = [];
669
+ for (const e of live) {
670
+ if (e.contact_type !== type) continue;
671
+ const value = type === "email" ? e.value.trim().toLowerCase() : e.value.trim();
672
+ if (!value || seen.has(value)) continue;
673
+ seen.add(value);
674
+ out.push({ value, is_preferred: e === pref });
675
+ }
676
+ return out;
677
+ };
678
+ return { emails: listOf("email"), phones: listOf("phone") };
679
+ }
680
+ function withSeatContactLogs(db, resolve, opts = {}) {
681
+ return async (userIds) => {
682
+ const base = await resolve(userIds);
683
+ const ids = userIds.filter((id) => base.has(id));
684
+ const out = new Map(base);
685
+ if (!ids.length) return out;
686
+ const logs = await readSeatContactLogs(db, ids, "user", {
687
+ invalid: "skip",
688
+ onInvalidRow: opts.onInvalidRow
689
+ });
690
+ for (const id of ids) {
691
+ const lists = seatContactListsFromLog(logs.get(id) ?? []);
692
+ if (!lists) continue;
693
+ const next = { ...base.get(id) };
694
+ if (lists.emails.length) {
695
+ next.emails = lists.emails;
696
+ next.email = lists.emails.find((e) => e.is_preferred)?.value ?? null;
697
+ }
698
+ if (lists.phones.length) {
699
+ next.phones = lists.phones;
700
+ next.phone = lists.phones.find((e) => e.is_preferred)?.value ?? null;
701
+ }
702
+ out.set(id, next);
703
+ }
704
+ return out;
705
+ };
706
+ }
512
707
  function subjectFilter(subject) {
513
708
  const type = requireId("subject_type", subject.subject_type);
514
709
  const base = { subject_type: type, subject_id: requireId("subject_id", subject.subject_id) };
@@ -742,10 +937,10 @@ async function listPendingContacts(db, opts = {}) {
742
937
  }
743
938
 
744
939
  // src/pointsOfContact/writer.ts
745
- import { z as z4 } from "zod";
940
+ import { z as z5 } from "zod";
746
941
 
747
942
  // src/orgDirectory/schemas.ts
748
- import { z as z2 } from "zod";
943
+ import { z as z3 } from "zod";
749
944
 
750
945
  // src/orgDirectory/vocabulary.ts
751
946
  var PROGRAM_REVIEW_STATUS = {
@@ -790,31 +985,37 @@ var ORGANIZATION_PROGRAM_ROW_KEYS = Object.freeze([
790
985
  "operatingStartDate",
791
986
  "operatingEndDate",
792
987
  "locationId",
793
- "notes"
988
+ "notes",
989
+ "teamId",
990
+ "teamIds"
794
991
  ]);
795
- var optionalText = z2.string().nullish();
796
- var detailText = z2.string().nullish().catch(void 0);
797
- var OrganizationProgramRowSchema = z2.object({
798
- programId: z2.string().min(1),
799
- name: z2.string().min(1),
992
+ var optionalText = z3.string().nullish();
993
+ var detailText = z3.string().nullish().catch(void 0);
994
+ var OrganizationProgramRowSchema = z3.object({
995
+ programId: z3.string().min(1),
996
+ name: z3.string().min(1),
800
997
  description: optionalText,
801
998
  status: optionalText,
802
999
  defaultSharingPolicy: optionalText,
803
- reviewStatus: z2.enum(PROGRAM_REVIEW_STATUS_VALUES).nullish(),
1000
+ reviewStatus: z3.enum(PROGRAM_REVIEW_STATUS_VALUES).nullish(),
804
1001
  addedBy: optionalText,
805
1002
  addedInApp: optionalText,
806
1003
  addedInSession: optionalText,
807
1004
  programType: detailText,
808
1005
  serviceArea: detailText,
809
- providesRelevantServices: z2.boolean().nullish().catch(void 0),
1006
+ providesRelevantServices: z3.boolean().nullish().catch(void 0),
810
1007
  operatingStartDate: detailText,
811
1008
  operatingEndDate: detailText,
812
1009
  locationId: detailText,
813
- notes: detailText
1010
+ notes: detailText,
1011
+ /** The first team that works for the program (canon `team_id`). */
1012
+ teamId: detailText,
1013
+ /** Every team that works for the program (canon `team_ids`). */
1014
+ teamIds: z3.array(z3.string()).nullish().catch(void 0)
814
1015
  });
815
1016
 
816
1017
  // src/orgDirectory/orgRecord.ts
817
- import { z as z3 } from "zod";
1018
+ import { z as z4 } from "zod";
818
1019
  var ORG_REVIEW_STATUS = PROGRAM_REVIEW_STATUS;
819
1020
  var ORGANIZATION_STATUS = { ACTIVE: 1, INACTIVE: 2 };
820
1021
  function isListedOrganization(row) {
@@ -876,9 +1077,9 @@ var ORG_KEY_PATTERN = /^[a-z0-9][a-z0-9_-]{0,119}$/;
876
1077
  function isOrgKey(value) {
877
1078
  return typeof value === "string" && ORG_KEY_PATTERN.test(value);
878
1079
  }
879
- var line = (max) => z3.string().trim().min(1).max(max).nullable();
1080
+ var line = (max) => z4.string().trim().min(1).max(max).nullable();
880
1081
  var ORG_VSP_TWO_STEP_MESSAGE = "vspPrivateNonprofit is step 2 of the HMIS VSP two-step and requires vsp: true";
881
- var OrgIdentityWriteSchema = z3.object({
1082
+ var OrgIdentityWriteSchema = z4.object({
882
1083
  legalName: line(300),
883
1084
  commonName: line(300),
884
1085
  shortName: line(60),
@@ -886,9 +1087,9 @@ var OrgIdentityWriteSchema = z3.object({
886
1087
  /** Another organization's id (24-hex or a seed slug). Self-reference is the writer's check. */
887
1088
  parentOrgId: line(120)
888
1089
  }).partial().strict();
889
- var OrgVspWriteSchema = z3.object({
890
- vsp: z3.boolean().nullable(),
891
- vspPrivateNonprofit: z3.boolean().nullable()
1090
+ var OrgVspWriteSchema = z4.object({
1091
+ vsp: z4.boolean().nullable(),
1092
+ vspPrivateNonprofit: z4.boolean().nullable()
892
1093
  }).partial().strict().refine((v) => v.vspPrivateNonprofit == null || v.vsp === true, {
893
1094
  message: ORG_VSP_TWO_STEP_MESSAGE,
894
1095
  path: ["vspPrivateNonprofit"]
@@ -1058,8 +1259,8 @@ async function readAgencyOwnOrganization(db, agencyId, opts = {}) {
1058
1259
  var POC_PARTNER_ADD_APPS = POC_ADDED_IN_APPS.filter(
1059
1260
  (a) => a !== "platform"
1060
1261
  );
1061
- var directoryId = z4.string().trim().min(1).max(200);
1062
- var PartnerContactSelectorSchema = z4.object({ agency_id: directoryId.optional(), org_id: directoryId.optional() }).strict().refine((p) => Boolean(p.agency_id || p.org_id), {
1262
+ var directoryId = z5.string().trim().min(1).max(200);
1263
+ var PartnerContactSelectorSchema = z5.object({ agency_id: directoryId.optional(), org_id: directoryId.optional() }).strict().refine((p) => Boolean(p.agency_id || p.org_id), {
1063
1264
  message: "Name the partner's agency_id or org_id."
1064
1265
  });
1065
1266
  var POC_IN_APP_PENDING_CAP_PER_ACTOR = 25;
@@ -1576,8 +1777,10 @@ export {
1576
1777
  preferredEmail,
1577
1778
  preferredPhone,
1578
1779
  resolveMagicLinkRecipients,
1780
+ seatContactListsFromLog,
1579
1781
  toNetworkView,
1580
1782
  toOwnerView,
1581
- toStewardView
1783
+ toStewardView,
1784
+ withSeatContactLogs
1582
1785
  };
1583
1786
  //# sourceMappingURL=index.js.map