@htilabs/platform-common-models 0.64.0 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -0
- package/dist/index.cjs +70 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -1
- package/dist/org-directory/index.cjs +19 -0
- package/dist/org-directory/index.cjs.map +1 -1
- package/dist/org-directory/index.d.cts +6 -236
- package/dist/org-directory/index.d.ts +6 -236
- package/dist/org-directory/index.js +16 -0
- package/dist/org-directory/index.js.map +1 -1
- package/dist/orgRecord-B4-ELaZ_.d.cts +263 -0
- package/dist/orgRecord-h3Z-V23F.d.ts +263 -0
- package/dist/points-of-contact/index.cjs +6 -0
- package/dist/points-of-contact/index.cjs.map +1 -1
- package/dist/points-of-contact/index.js +6 -0
- package/dist/points-of-contact/index.js.map +1 -1
- package/dist/schemas/index.cjs +57 -0
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +52 -1
- package/dist/schemas/index.d.ts +52 -1
- package/dist/schemas/index.js +54 -0
- package/dist/schemas/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/root-org-key-exports.test.ts +24 -0
- package/src/index.ts +7 -0
- package/src/orgDirectory/__tests__/orgKey.test.ts +84 -0
- package/src/orgDirectory/orgRecord.ts +41 -3
- package/src/orgDirectory/rules.ts +4 -1
- package/src/schemas/index.ts +3 -0
- package/src/schemas/organization.ts +58 -0
package/dist/schemas/index.cjs
CHANGED
|
@@ -22,6 +22,9 @@ var schemas_exports = {};
|
|
|
22
22
|
__export(schemas_exports, {
|
|
23
23
|
AGENCY_ORG_TYPE_VALIDATED_UPDATE_OPS: () => AGENCY_ORG_TYPE_VALIDATED_UPDATE_OPS,
|
|
24
24
|
ORGANIZATION_PROGRAM_VALIDATED_UPDATE_OPS: () => ORGANIZATION_PROGRAM_VALIDATED_UPDATE_OPS,
|
|
25
|
+
ORG_KEY_INDEX_NAME: () => ORG_KEY_INDEX_NAME,
|
|
26
|
+
ORG_KEY_INDEX_OPTIONS: () => ORG_KEY_INDEX_OPTIONS,
|
|
27
|
+
ORG_KEY_INDEX_SPEC: () => ORG_KEY_INDEX_SPEC,
|
|
25
28
|
ORG_TYPE_FIELD_NAMES: () => ORG_TYPE_FIELD_NAMES,
|
|
26
29
|
PROGRAM_REVIEW_STATUS: () => PROGRAM_REVIEW_STATUS,
|
|
27
30
|
PROGRAM_REVIEW_STATUS_VALUES: () => PROGRAM_REVIEW_STATUS_VALUES,
|
|
@@ -5941,6 +5944,7 @@ function isLiveOrganizationProgram(row) {
|
|
|
5941
5944
|
// src/orgDirectory/orgRecord.ts
|
|
5942
5945
|
var ORG_REVIEW_STATUS_VALUES = PROGRAM_REVIEW_STATUS_VALUES;
|
|
5943
5946
|
var ORG_RECORD_FIELD_NAMES = Object.freeze([
|
|
5947
|
+
"key",
|
|
5944
5948
|
"legalName",
|
|
5945
5949
|
"commonName",
|
|
5946
5950
|
"shortName",
|
|
@@ -5990,6 +5994,10 @@ var ORGANIZATION_ENVELOPE_KEYS = Object.freeze([
|
|
|
5990
5994
|
"updatedUser",
|
|
5991
5995
|
"updatedTime"
|
|
5992
5996
|
]);
|
|
5997
|
+
var ORG_KEY_PATTERN = /^[a-z0-9][a-z0-9_-]{0,119}$/;
|
|
5998
|
+
function isOrgKey(value) {
|
|
5999
|
+
return typeof value === "string" && ORG_KEY_PATTERN.test(value);
|
|
6000
|
+
}
|
|
5993
6001
|
var line = (max) => import_zod.z.string().trim().min(1).max(max).nullable();
|
|
5994
6002
|
var ORG_VSP_TWO_STEP_MESSAGE = "vspPrivateNonprofit is step 2 of the HMIS VSP two-step and requires vsp: true";
|
|
5995
6003
|
var OrgIdentityWriteSchema = import_zod.z.object({
|
|
@@ -6010,12 +6018,50 @@ var OrgVspWriteSchema = import_zod.z.object({
|
|
|
6010
6018
|
|
|
6011
6019
|
// src/schemas/organization.ts
|
|
6012
6020
|
var HEX_24 = /^[0-9a-fA-F]{24}$/;
|
|
6021
|
+
var ORG_KEY_INDEX_NAME = "org_key_unique";
|
|
6022
|
+
var ORG_KEY_INDEX_SPEC = Object.freeze({ key: 1 });
|
|
6023
|
+
var ORG_KEY_INDEX_OPTIONS = Object.freeze({
|
|
6024
|
+
name: ORG_KEY_INDEX_NAME,
|
|
6025
|
+
unique: true,
|
|
6026
|
+
partialFilterExpression: Object.freeze({ key: Object.freeze({ $type: "string" }) })
|
|
6027
|
+
});
|
|
6013
6028
|
function isStoredDirectoryId(value) {
|
|
6014
6029
|
if (value == null) return true;
|
|
6015
6030
|
if (typeof value === "string") return value.trim() !== "";
|
|
6016
6031
|
return typeof value === "object" && typeof value.toHexString === "function" && HEX_24.test(value.toHexString());
|
|
6017
6032
|
}
|
|
6018
6033
|
var orgRecordSchemaDefinition = {
|
|
6034
|
+
/**
|
|
6035
|
+
* The Org's identifier (the UDD `id`): the same value in every database.
|
|
6036
|
+
* Never taken from a request body.
|
|
6037
|
+
*
|
|
6038
|
+
* `immutable` means the model stores a key only while it is creating the
|
|
6039
|
+
* row. Measured on Mongoose 9.3.1 against MongoDB (the fill's test file
|
|
6040
|
+
* holds each line):
|
|
6041
|
+
*
|
|
6042
|
+
* - `new Model({ key }).save()` and `Model.create({ key })` store it.
|
|
6043
|
+
* - An upsert stores it when the upsert inserts the row (`$setOnInsert`, or
|
|
6044
|
+
* `$set`, which Mongoose moves to `$setOnInsert`); on a row that already
|
|
6045
|
+
* exists the upsert leaves `key` as it was.
|
|
6046
|
+
* - On a row that already exists, `doc.key = …; doc.save()` and
|
|
6047
|
+
* `updateOne` / `findOneAndUpdate` with `$set: { key }` do NOT write it,
|
|
6048
|
+
* and do not report an error. That holds whether the row has a key or has
|
|
6049
|
+
* none yet, so a model cannot give an old row its first key either.
|
|
6050
|
+
*
|
|
6051
|
+
* So an app stores `key: mintOrgKey(_id)` where it creates the
|
|
6052
|
+
* organization (`new Model().save()`, `create()`, or `$setOnInsert` on an
|
|
6053
|
+
* upsert). Rows that already exist get theirs from the registry fill's key
|
|
6054
|
+
* sheet, which writes with the plain MongoDB driver.
|
|
6055
|
+
*/
|
|
6056
|
+
key: {
|
|
6057
|
+
type: String,
|
|
6058
|
+
trim: true,
|
|
6059
|
+
immutable: true,
|
|
6060
|
+
validate: {
|
|
6061
|
+
validator: (value) => value == null || isOrgKey(value),
|
|
6062
|
+
message: "key must be a lower-case slug (a-z, 0-9, _ and -)"
|
|
6063
|
+
}
|
|
6064
|
+
},
|
|
6019
6065
|
/** The canonical reporting name (HMIS, funders). Readers fall back to `name`. */
|
|
6020
6066
|
legalName: { type: String, trim: true },
|
|
6021
6067
|
/** The name people use, when it differs from `name`. */
|
|
@@ -6064,6 +6110,13 @@ var orgAsBuiltSchemaDefinition = {
|
|
|
6064
6110
|
};
|
|
6065
6111
|
function addOrgRecordFields(schema, options = {}) {
|
|
6066
6112
|
schema.add(orgRecordSchemaDefinition);
|
|
6113
|
+
schema.index(
|
|
6114
|
+
{ ...ORG_KEY_INDEX_SPEC },
|
|
6115
|
+
{
|
|
6116
|
+
...ORG_KEY_INDEX_OPTIONS,
|
|
6117
|
+
partialFilterExpression: { key: { ...ORG_KEY_INDEX_OPTIONS.partialFilterExpression.key } }
|
|
6118
|
+
}
|
|
6119
|
+
);
|
|
6067
6120
|
for (const key of ORG_AS_BUILT_FIELD_NAMES) {
|
|
6068
6121
|
if (schema.pathType(key) === "adhocOrUndefined") {
|
|
6069
6122
|
schema.add({ [key]: orgAsBuiltSchemaDefinition[key] });
|
|
@@ -6072,6 +6125,7 @@ function addOrgRecordFields(schema, options = {}) {
|
|
|
6072
6125
|
return installVspTwoStepHooks(schema, options);
|
|
6073
6126
|
}
|
|
6074
6127
|
var EXPECTED_INSTANCE = {
|
|
6128
|
+
key: "String",
|
|
6075
6129
|
legalName: "String",
|
|
6076
6130
|
commonName: "String",
|
|
6077
6131
|
shortName: "String",
|
|
@@ -6194,6 +6248,9 @@ function addOrganizationProgramsField(schema, options = {}) {
|
|
|
6194
6248
|
0 && (module.exports = {
|
|
6195
6249
|
AGENCY_ORG_TYPE_VALIDATED_UPDATE_OPS,
|
|
6196
6250
|
ORGANIZATION_PROGRAM_VALIDATED_UPDATE_OPS,
|
|
6251
|
+
ORG_KEY_INDEX_NAME,
|
|
6252
|
+
ORG_KEY_INDEX_OPTIONS,
|
|
6253
|
+
ORG_KEY_INDEX_SPEC,
|
|
6197
6254
|
ORG_TYPE_FIELD_NAMES,
|
|
6198
6255
|
PROGRAM_REVIEW_STATUS,
|
|
6199
6256
|
PROGRAM_REVIEW_STATUS_VALUES,
|