@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.
Files changed (35) hide show
  1. package/README.md +90 -1
  2. package/dist/index.cjs +91 -13
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +91 -13
  5. package/dist/index.js.map +1 -1
  6. package/dist/org-directory/index.cjs +5 -4
  7. package/dist/org-directory/index.cjs.map +1 -1
  8. package/dist/org-directory/index.d.cts +15 -7
  9. package/dist/org-directory/index.d.ts +15 -7
  10. package/dist/org-directory/index.js +5 -4
  11. package/dist/org-directory/index.js.map +1 -1
  12. package/dist/points-of-contact/index.cjs +4 -3
  13. package/dist/points-of-contact/index.cjs.map +1 -1
  14. package/dist/points-of-contact/index.js +4 -3
  15. package/dist/points-of-contact/index.js.map +1 -1
  16. package/dist/schemas/index.cjs +10 -6
  17. package/dist/schemas/index.cjs.map +1 -1
  18. package/dist/schemas/index.d.cts +8 -4
  19. package/dist/schemas/index.d.ts +8 -4
  20. package/dist/schemas/index.js +10 -6
  21. package/dist/schemas/index.js.map +1 -1
  22. package/dist/sharing-ceiling/index.cjs +81 -7
  23. package/dist/sharing-ceiling/index.cjs.map +1 -1
  24. package/dist/sharing-ceiling/index.d.cts +64 -4
  25. package/dist/sharing-ceiling/index.d.ts +64 -4
  26. package/dist/sharing-ceiling/index.js +81 -7
  27. package/dist/sharing-ceiling/index.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/orgDirectory/__tests__/orgRecord.test.ts +6 -3
  30. package/src/orgDirectory/orgRecord.ts +14 -6
  31. package/src/orgDirectory/rules.ts +3 -2
  32. package/src/schemas/organization.ts +7 -4
  33. package/src/sharingCeiling/__tests__/resolveShare.purposeRule.test.ts +836 -0
  34. package/src/sharingCeiling/index.ts +4 -0
  35. package/src/sharingCeiling/resolve.ts +219 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htilabs/platform-common-models",
3
- "version": "0.59.0",
3
+ "version": "0.61.0",
4
4
  "description": "Shared constants, types, and models for HTI Labs applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -152,7 +152,7 @@ describe("arrival and the listed rule", () => {
152
152
  expect(orgArrivalStamp({ app: " Thread ", userId: "u1", sessionId: "s1" })).toEqual({
153
153
  reviewStatus: "pending",
154
154
  addedInApp: "thread",
155
- addedByUserId: "u1",
155
+ addedBy: "u1",
156
156
  addedInSession: "s1",
157
157
  });
158
158
  expect(orgArrivalStamp({ app: "pave", userId: "u1" })).not.toHaveProperty("addedInSession");
@@ -227,7 +227,7 @@ describe("the read view carries the record", () => {
227
227
  vspPrivateNonprofit: true,
228
228
  reviewStatus: "pending",
229
229
  addedInApp: "thread",
230
- addedByUserId: "u1",
230
+ addedBy: "u1",
231
231
  status: 1,
232
232
  });
233
233
  expect(view).toMatchObject({
@@ -240,7 +240,7 @@ describe("the read view carries the record", () => {
240
240
  vspPrivateNonprofit: true,
241
241
  reviewStatus: "pending",
242
242
  addedInApp: "thread",
243
- addedByUserId: "u1",
243
+ addedBy: "u1",
244
244
  addedInSession: null,
245
245
  status: 1,
246
246
  listed: true,
@@ -273,6 +273,9 @@ describe("the read view carries the record", () => {
273
273
  reviewStatus: "rejected",
274
274
  });
275
275
  expect(view?.shortName).toBe("TPD");
276
+ expect(toDirectoryOrganizationView({ _id: ID, name: "x", addedByUserId: "u9" })?.addedBy).toBe(
277
+ "u9",
278
+ );
276
279
  expect(view?.vsp).toBe(false);
277
280
  expect(view?.vspPrivateNonprofit).toBeNull();
278
281
  expect(view?.listed).toBe(false);
@@ -96,21 +96,23 @@ export const ORG_RECORD_FIELD_NAMES = Object.freeze([
96
96
  "vspPrivateNonprofit",
97
97
  "reviewStatus",
98
98
  "addedInApp",
99
- "addedByUserId",
100
- "addedInSession",
99
+ "addedBy",
101
100
  ] as const);
102
101
  export type OrgRecordFieldName = (typeof ORG_RECORD_FIELD_NAMES)[number];
103
102
 
104
103
  /**
105
104
  * Stored on the row today and NOT part of the Org definition (UDD Org § 5,
106
- * "As built today, and not part of this definition"; Org.v1 `isCustom`,
107
- * `type_override`, `division`). PAVE 2.0 writes them; every model declares
105
+ * "As built today, and not part of this definition"; Org.v1's runtime-overlay
106
+ * five: `isCustom`, `added_in_session`, `added_by_user_id`, `type_override`,
107
+ * `division`). PAVE 2.0 writes them; every model declares
108
108
  * them so no app silently drops another app's value. `typeKey` is the CVC-48
109
109
  * key PAVE writes beside a numeric `type` and retires with the type migration.
110
110
  */
111
111
  export const ORG_AS_BUILT_FIELD_NAMES = Object.freeze([
112
112
  "requiresROI",
113
113
  "isCustom",
114
+ "addedByUserId",
115
+ "addedInSession",
114
116
  "division",
115
117
  "typeOverride",
116
118
  "typeKey",
@@ -212,13 +214,19 @@ export type OrgVspWrite = z.infer<typeof OrgVspWriteSchema>;
212
214
  /**
213
215
  * How an organization arrived. Never taken from a request body: the server
214
216
  * stamps it from the authenticated caller ({@link orgArrivalStamp}).
217
+ *
218
+ * The same three facts, under the same names, as a Program, a Service Listing
219
+ * and a Point of contact carry (`added_by` · `added_in_app` · `review_status`;
220
+ * UDD ratification request R17, "how an organization arrived"). The older
221
+ * runtime-overlay names on the row (`addedByUserId`, `isCustom`) are as-built
222
+ * extras; `addedInSession` is carried as on the program row.
215
223
  */
216
224
  export interface OrgArrival {
217
225
  reviewStatus: OrgReviewStatus;
218
226
  /** The app the organization was added in: `thread`, `pave`, `leads`, `platform`. */
219
227
  addedInApp: string;
220
228
  /** The adding user's platform `users._id`, as a string. */
221
- addedByUserId: string;
229
+ addedBy: string;
222
230
  /** The session it was added in, when there was one. */
223
231
  addedInSession?: string;
224
232
  }
@@ -241,7 +249,7 @@ export function orgArrivalStamp(input: {
241
249
  return {
242
250
  reviewStatus: ORG_REVIEW_STATUS.PENDING,
243
251
  addedInApp: app,
244
- addedByUserId: userId,
252
+ addedBy: userId,
245
253
  ...(session ? { addedInSession: session } : {}),
246
254
  };
247
255
  }
@@ -153,7 +153,8 @@ export interface DirectoryOrganizationView {
153
153
  /** pending · confirmed · rejected for an organization added inside an app; null on a steward row. */
154
154
  reviewStatus: OrgReviewStatus | null;
155
155
  addedInApp: string | null;
156
- addedByUserId: string | null;
156
+ /** Who added it (a platform `users._id`); a pre-0.60 row's `addedByUserId` reads here too. */
157
+ addedBy: string | null;
157
158
  addedInSession: string | null;
158
159
  /** The stored lifecycle code (1 active, 2 inactive), else null. */
159
160
  status: number | null;
@@ -201,7 +202,7 @@ export function toDirectoryOrganizationView(raw: unknown): DirectoryOrganization
201
202
  vspPrivateNonprofit: vsp === true ? flag(r.vspPrivateNonprofit) : null,
202
203
  reviewStatus,
203
204
  addedInApp: line(r.addedInApp),
204
- addedByUserId: line(r.addedByUserId),
205
+ addedBy: line(r.addedBy) ?? line(r.addedByUserId),
205
206
  addedInSession: line(r.addedInSession),
206
207
  status,
207
208
  listed: isListedOrganization({ status, reviewStatus }),
@@ -83,8 +83,7 @@ export const orgRecordSchemaDefinition = {
83
83
  /** The app it was added in (`thread`, `pave`, `leads`, `platform`). */
84
84
  addedInApp: { type: String },
85
85
  /** The adding user's platform `users._id`. */
86
- addedByUserId: { type: String },
87
- addedInSession: { type: String },
86
+ addedBy: { type: String },
88
87
  };
89
88
 
90
89
  /**
@@ -95,6 +94,9 @@ export const orgAsBuiltSchemaDefinition = {
95
94
  /** Informational only: the release check reads the sender's `vsp` (GDR § 5.17 clause 2). */
96
95
  requiresROI: { type: Boolean },
97
96
  isCustom: { type: Boolean },
97
+ /** The pre-0.60 spelling of `addedBy`; PAVE 2.0 rows carry it. */
98
+ addedByUserId: { type: String },
99
+ addedInSession: { type: String },
98
100
  division: { type: String },
99
101
  typeOverride: { type: String },
100
102
  /** The CVC-48 key PAVE writes beside a numeric `type`; retires with the type migration. */
@@ -141,10 +143,11 @@ const EXPECTED_INSTANCE: Record<string, string> = {
141
143
  vspPrivateNonprofit: "Boolean",
142
144
  reviewStatus: "String",
143
145
  addedInApp: "String",
144
- addedByUserId: "String",
145
- addedInSession: "String",
146
+ addedBy: "String",
146
147
  requiresROI: "Boolean",
147
148
  isCustom: "Boolean",
149
+ addedByUserId: "String",
150
+ addedInSession: "String",
148
151
  division: "String",
149
152
  typeOverride: "String",
150
153
  typeKey: "String",