@htilabs/platform-common-models 0.1.0-beta.3 → 0.2.0-beta.2

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 (43) hide show
  1. package/dist/constants/index.cjs +437 -153
  2. package/dist/constants/index.cjs.map +1 -1
  3. package/dist/constants/index.d.cts +1 -1
  4. package/dist/constants/index.d.ts +1 -1
  5. package/dist/constants/index.js +414 -153
  6. package/dist/constants/index.js.map +1 -1
  7. package/dist/index.cjs +610 -154
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +3 -3
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +579 -154
  12. package/dist/index.js.map +1 -1
  13. package/dist/models/index.cjs +306 -1
  14. package/dist/models/index.cjs.map +1 -1
  15. package/dist/models/index.d.cts +99 -11
  16. package/dist/models/index.d.ts +99 -11
  17. package/dist/models/index.js +304 -1
  18. package/dist/models/index.js.map +1 -1
  19. package/dist/{index-Cww9rH3H.d.cts → platform-auth-C-G2qeGM.d.cts} +167 -56
  20. package/dist/{index-Cww9rH3H.d.ts → platform-auth-C-G2qeGM.d.ts} +167 -56
  21. package/dist/{scoring-rule-liZlPytD.d.cts → platform-role-AHv1l5Og.d.cts} +177 -1
  22. package/dist/{scoring-rule-liZlPytD.d.ts → platform-role-AHv1l5Og.d.ts} +177 -1
  23. package/dist/schemas/index.cjs +539 -153
  24. package/dist/schemas/index.cjs.map +1 -1
  25. package/dist/schemas/index.d.cts +1 -1
  26. package/dist/schemas/index.d.ts +1 -1
  27. package/dist/schemas/index.js +533 -153
  28. package/dist/schemas/index.js.map +1 -1
  29. package/dist/types/index.cjs.map +1 -1
  30. package/dist/types/index.d.cts +45 -1
  31. package/dist/types/index.d.ts +45 -1
  32. package/package.json +1 -1
  33. package/src/constants/ic.ts +254 -153
  34. package/src/constants/index.ts +1 -0
  35. package/src/constants/platform-auth.ts +189 -0
  36. package/src/models/index.ts +18 -1
  37. package/src/models/platformFunctionModel.ts +33 -0
  38. package/src/models/platformRoleModel.ts +33 -0
  39. package/src/schemas/index.ts +16 -0
  40. package/src/schemas/platform-function.ts +97 -0
  41. package/src/schemas/platform-role.ts +100 -0
  42. package/src/types/index.ts +14 -0
  43. package/src/types/platform-auth.ts +49 -0
@@ -22,6 +22,8 @@ var models_exports = {};
22
22
  __export(models_exports, {
23
23
  createPlatformModels: () => createPlatformModels,
24
24
  formModel: () => formModel_exports,
25
+ platformFunctionModel: () => platformFunctionModel_exports,
26
+ platformRoleModel: () => platformRoleModel_exports,
25
27
  questionModel: () => questionModel_exports,
26
28
  scoringRuleModel: () => scoringRuleModel_exports,
27
29
  sectionModel: () => sectionModel_exports
@@ -641,19 +643,322 @@ function compileModel4(connection, schema = buildScoringRuleSchema()) {
641
643
  return connection.model("ScoringRule", schema);
642
644
  }
643
645
 
646
+ // src/models/platformFunctionModel.ts
647
+ var platformFunctionModel_exports = {};
648
+ __export(platformFunctionModel_exports, {
649
+ buildSchema: () => buildPlatformFunctionSchema,
650
+ compileModel: () => compileModel5
651
+ });
652
+
653
+ // src/schemas/platform-function.ts
654
+ var import_mongoose5 = require("mongoose");
655
+
656
+ // src/constants/platform-auth.ts
657
+ var PERMISSION_STATE = {
658
+ /** Role can always perform this function (mandatory, cannot disable). */
659
+ ALWAYS: "ALWAYS",
660
+ /** Default On — user can opt off. */
661
+ PREF_YES: "PREF_YES",
662
+ /** Default Off — user can opt in. */
663
+ PREF_NO: "PREF_NO",
664
+ /** Role is explicitly barred from this function. */
665
+ NEVER: "NEVER"
666
+ };
667
+ var PERMISSION_STATE_VALUES = [
668
+ PERMISSION_STATE.ALWAYS,
669
+ PERMISSION_STATE.PREF_YES,
670
+ PERMISSION_STATE.PREF_NO,
671
+ PERMISSION_STATE.NEVER
672
+ ];
673
+ var PERMISSION_STATE_LABELS = {
674
+ [PERMISSION_STATE.ALWAYS]: "Always",
675
+ [PERMISSION_STATE.PREF_YES]: "Default On",
676
+ [PERMISSION_STATE.PREF_NO]: "Default Off",
677
+ [PERMISSION_STATE.NEVER]: "Never"
678
+ };
679
+ var PERMISSION_STATE_DISPLAY = {
680
+ [PERMISSION_STATE.ALWAYS]: {
681
+ label: "Always",
682
+ color: "#2e7d32",
683
+ bgColor: "#e8f5e9",
684
+ icon: "\u{1F512}"
685
+ },
686
+ [PERMISSION_STATE.PREF_YES]: {
687
+ label: "Default On",
688
+ color: "#1565c0",
689
+ bgColor: "#e3f2fd",
690
+ icon: "\u{1F513}"
691
+ },
692
+ [PERMISSION_STATE.PREF_NO]: {
693
+ label: "Default Off",
694
+ color: "#e65100",
695
+ bgColor: "#fff3e0",
696
+ icon: "\u{1F513}"
697
+ },
698
+ [PERMISSION_STATE.NEVER]: {
699
+ label: "Never",
700
+ color: "#c62828",
701
+ bgColor: "#ffebee",
702
+ icon: "\u{1F512}"
703
+ }
704
+ };
705
+ var SHARE_VIEW = {
706
+ /** System metadata only (partial access). */
707
+ SYS_INFO: "sys_info",
708
+ /** Full case/record content. */
709
+ ALL: "all",
710
+ /** No data access. */
711
+ NONE: "none"
712
+ };
713
+ var SHARE_VIEW_VALUES = [
714
+ SHARE_VIEW.SYS_INFO,
715
+ SHARE_VIEW.ALL,
716
+ SHARE_VIEW.NONE
717
+ ];
718
+ var SHARE_VIEW_LABELS = {
719
+ [SHARE_VIEW.SYS_INFO]: "System Info Only",
720
+ [SHARE_VIEW.ALL]: "Full Content",
721
+ [SHARE_VIEW.NONE]: "No Data Access"
722
+ };
723
+ var PLATFORM_TOOL = {
724
+ PAVE: "PAVE",
725
+ ECHO: "ECHO",
726
+ LEADS: "LEADS",
727
+ THREAD: "THREAD",
728
+ TRAIL: "TRAIL",
729
+ PLATFORM: "PLATFORM"
730
+ };
731
+ var PLATFORM_TOOL_VALUES = [
732
+ PLATFORM_TOOL.PAVE,
733
+ PLATFORM_TOOL.ECHO,
734
+ PLATFORM_TOOL.LEADS,
735
+ PLATFORM_TOOL.THREAD,
736
+ PLATFORM_TOOL.TRAIL,
737
+ PLATFORM_TOOL.PLATFORM
738
+ ];
739
+ var PLATFORM_TOOL_LABELS = {
740
+ [PLATFORM_TOOL.PAVE]: "PAVE",
741
+ [PLATFORM_TOOL.ECHO]: "Echo",
742
+ [PLATFORM_TOOL.LEADS]: "LEADS",
743
+ [PLATFORM_TOOL.THREAD]: "Thread",
744
+ [PLATFORM_TOOL.TRAIL]: "Trail",
745
+ [PLATFORM_TOOL.PLATFORM]: "Platform"
746
+ };
747
+ var ROLE_LEVEL = {
748
+ /** User-facing roles (staff, volunteers, practitioners). */
749
+ OPERATIONAL: "operational",
750
+ /** Agency-level admin roles. */
751
+ AGENCY: "agency",
752
+ /** Team-level admin roles. */
753
+ TEAM: "team",
754
+ /** HTI-wide platform admin. */
755
+ PLATFORM: "platform",
756
+ /** External governance/oversight roles. */
757
+ OVERSIGHT: "oversight"
758
+ };
759
+ var ROLE_LEVEL_VALUES = [
760
+ ROLE_LEVEL.OPERATIONAL,
761
+ ROLE_LEVEL.AGENCY,
762
+ ROLE_LEVEL.TEAM,
763
+ ROLE_LEVEL.PLATFORM,
764
+ ROLE_LEVEL.OVERSIGHT
765
+ ];
766
+ var ROLE_LEVEL_LABELS = {
767
+ [ROLE_LEVEL.OPERATIONAL]: "Operational",
768
+ [ROLE_LEVEL.AGENCY]: "Agency",
769
+ [ROLE_LEVEL.TEAM]: "Team",
770
+ [ROLE_LEVEL.PLATFORM]: "Platform",
771
+ [ROLE_LEVEL.OVERSIGHT]: "Oversight"
772
+ };
773
+ var FUNCTION_STATUS = {
774
+ NOT_STARTED: "Not started",
775
+ DEFINED_NEW: "Defined; new function",
776
+ DEFINED_EXISTING: "Defined; existing PAVE function",
777
+ FUNCTIONAL: "Functional on all apps",
778
+ FUTURE: "Future function (not v1)"
779
+ };
780
+ var FUNCTION_STATUS_VALUES = [
781
+ FUNCTION_STATUS.NOT_STARTED,
782
+ FUNCTION_STATUS.DEFINED_NEW,
783
+ FUNCTION_STATUS.DEFINED_EXISTING,
784
+ FUNCTION_STATUS.FUNCTIONAL,
785
+ FUNCTION_STATUS.FUTURE
786
+ ];
787
+ var FUNCTION_STATUS_LABELS = {
788
+ [FUNCTION_STATUS.NOT_STARTED]: "Not Started",
789
+ [FUNCTION_STATUS.DEFINED_NEW]: "Defined (New)",
790
+ [FUNCTION_STATUS.DEFINED_EXISTING]: "Defined (Existing PAVE)",
791
+ [FUNCTION_STATUS.FUNCTIONAL]: "Functional",
792
+ [FUNCTION_STATUS.FUTURE]: "Future (Not v1)"
793
+ };
794
+
795
+ // src/schemas/platform-function.ts
796
+ var platformFunctionSchemaDefinition = {
797
+ code: {
798
+ type: String,
799
+ required: true
800
+ },
801
+ label: {
802
+ type: String,
803
+ required: true
804
+ },
805
+ description: {
806
+ type: String,
807
+ default: ""
808
+ },
809
+ category: {
810
+ type: String,
811
+ default: ""
812
+ },
813
+ tools: {
814
+ type: [String],
815
+ enum: [...PLATFORM_TOOL_VALUES],
816
+ default: []
817
+ },
818
+ isAdminRelevant: {
819
+ type: Boolean,
820
+ default: false
821
+ },
822
+ isUserRelevant: {
823
+ type: Boolean,
824
+ default: false
825
+ },
826
+ isHtiOnly: {
827
+ type: Boolean,
828
+ default: false
829
+ },
830
+ status: {
831
+ type: String,
832
+ enum: [...FUNCTION_STATUS_VALUES],
833
+ default: "Not started"
834
+ },
835
+ sortOrder: {
836
+ type: Number,
837
+ default: 0
838
+ }
839
+ };
840
+ var platformFunctionSchemaOptions = {
841
+ timestamps: {
842
+ createdAt: "createdTime",
843
+ updatedAt: "updatedTime"
844
+ },
845
+ collection: "platformFunctions"
846
+ };
847
+ function buildPlatformFunctionSchema() {
848
+ const schema = new import_mongoose5.Schema(
849
+ platformFunctionSchemaDefinition,
850
+ platformFunctionSchemaOptions
851
+ );
852
+ schema.index({ code: 1 }, { unique: true });
853
+ schema.index({ tools: 1 });
854
+ schema.index({ category: 1 });
855
+ schema.index({ sortOrder: 1 });
856
+ return schema;
857
+ }
858
+ var _platformFunctionSchema = buildPlatformFunctionSchema();
859
+
860
+ // src/models/platformFunctionModel.ts
861
+ function compileModel5(connection, schema = buildPlatformFunctionSchema()) {
862
+ return connection.model("PlatformFunction", schema);
863
+ }
864
+
865
+ // src/models/platformRoleModel.ts
866
+ var platformRoleModel_exports = {};
867
+ __export(platformRoleModel_exports, {
868
+ buildSchema: () => buildPlatformRoleSchema,
869
+ compileModel: () => compileModel6
870
+ });
871
+
872
+ // src/schemas/platform-role.ts
873
+ var import_mongoose6 = require("mongoose");
874
+ var platformRoleSchemaDefinition = {
875
+ code: {
876
+ type: String,
877
+ required: true
878
+ },
879
+ label: {
880
+ type: String,
881
+ required: true
882
+ },
883
+ description: {
884
+ type: String,
885
+ default: ""
886
+ },
887
+ level: {
888
+ type: String,
889
+ enum: [...ROLE_LEVEL_VALUES],
890
+ required: true
891
+ },
892
+ tools: {
893
+ type: [String],
894
+ enum: [...PLATFORM_TOOL_VALUES],
895
+ default: []
896
+ },
897
+ shareView: {
898
+ type: String,
899
+ enum: [...SHARE_VIEW_VALUES, null],
900
+ default: null
901
+ },
902
+ trainingRequirements: {
903
+ type: String,
904
+ default: null
905
+ },
906
+ isHtiOnly: {
907
+ type: Boolean,
908
+ default: false
909
+ },
910
+ /** Dynamic map of functionCode → PermissionStateValue. */
911
+ functions: {
912
+ type: import_mongoose6.Schema.Types.Mixed,
913
+ default: {}
914
+ },
915
+ sortOrder: {
916
+ type: Number,
917
+ default: 0
918
+ }
919
+ };
920
+ var platformRoleSchemaOptions = {
921
+ timestamps: {
922
+ createdAt: "createdTime",
923
+ updatedAt: "updatedTime"
924
+ },
925
+ collection: "platformRoles"
926
+ };
927
+ function buildPlatformRoleSchema() {
928
+ const schema = new import_mongoose6.Schema(
929
+ platformRoleSchemaDefinition,
930
+ platformRoleSchemaOptions
931
+ );
932
+ schema.index({ code: 1 }, { unique: true });
933
+ schema.index({ level: 1 });
934
+ schema.index({ tools: 1 });
935
+ schema.index({ isHtiOnly: 1 });
936
+ return schema;
937
+ }
938
+ var _platformRoleSchema = buildPlatformRoleSchema();
939
+
940
+ // src/models/platformRoleModel.ts
941
+ function compileModel6(connection, schema = buildPlatformRoleSchema()) {
942
+ return connection.model("PlatformRole", schema);
943
+ }
944
+
644
945
  // src/models/index.ts
645
946
  function createPlatformModels(connection) {
646
947
  return {
647
948
  FormModel: compileModel(connection),
648
949
  SectionModel: compileModel2(connection),
649
950
  QuestionModel: compileModel3(connection),
650
- ScoringRuleModel: compileModel4(connection)
951
+ ScoringRuleModel: compileModel4(connection),
952
+ PlatformFunctionModel: compileModel5(connection),
953
+ PlatformRoleModel: compileModel6(connection)
651
954
  };
652
955
  }
653
956
  // Annotate the CommonJS export names for ESM import in node:
654
957
  0 && (module.exports = {
655
958
  createPlatformModels,
656
959
  formModel,
960
+ platformFunctionModel,
961
+ platformRoleModel,
657
962
  questionModel,
658
963
  scoringRuleModel,
659
964
  sectionModel
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/models/index.ts","../../src/models/formModel.ts","../../src/schemas/form.ts","../../src/models/sectionModel.ts","../../src/schemas/section.ts","../../src/models/questionModel.ts","../../src/schemas/question.ts","../../src/models/scoringRuleModel.ts","../../src/schemas/scoring-rule.ts"],"sourcesContent":["/**\n * @htilabs/platform-common-models — Models\n *\n * Mongoose model factories for platform models.\n * Each model exports buildSchema() and compileModel(connection) functions.\n *\n * Usage:\n * ```typescript\n * import { createPlatformModels } from '@htilabs/platform-common-models/models';\n * import mongoose from 'mongoose';\n *\n * const platformDb = mongoose.createConnection(PLATFORM_DB_URI);\n * const { FormModel, SectionModel, QuestionModel, ScoringRuleModel } = createPlatformModels(platformDb);\n * ```\n */\n\nimport type { Connection, Model } from \"mongoose\";\n\n// Individual model factories\nimport * as formModel from \"./formModel.js\";\nimport * as sectionModel from \"./sectionModel.js\";\nimport * as questionModel from \"./questionModel.js\";\nimport * as scoringRuleModel from \"./scoringRuleModel.js\";\n\n// Re-export individual model factories\nexport { formModel, sectionModel, questionModel, scoringRuleModel };\n\n// Re-export types\nexport type { FormDoc } from \"./formModel.js\";\nexport type { SectionDoc } from \"./sectionModel.js\";\nexport type { QuestionDoc } from \"./questionModel.js\";\nexport type { ScoringRuleDoc } from \"./scoringRuleModel.js\";\n\n// Re-export schema types\nexport type { Form } from \"../schemas/form.js\";\nexport type { Section } from \"../schemas/section.js\";\nexport type { Question } from \"../schemas/question.js\";\nexport type { ScoringRule } from \"../schemas/scoring-rule.js\";\n\n/**\n * Platform models interface returned by createPlatformModels.\n */\nexport interface PlatformModels {\n FormModel: Model<import(\"../schemas/form.js\").Form>;\n SectionModel: Model<import(\"../schemas/section.js\").Section>;\n QuestionModel: Model<import(\"../schemas/question.js\").Question>;\n ScoringRuleModel: Model<import(\"../schemas/scoring-rule.js\").ScoringRule>;\n}\n\n/**\n * Create all platform models bound to a single connection.\n * Convenience function for apps that need all form-related models.\n *\n * @param connection - Mongoose connection to bind all models to\n * @returns Object with all compiled models\n *\n * @example\n * ```typescript\n * const platformDb = mongoose.createConnection(PLATFORM_DB_URI);\n * const { FormModel, SectionModel, QuestionModel, ScoringRuleModel } = createPlatformModels(platformDb);\n *\n * const forms = await FormModel.find({ status: 'active' });\n * ```\n */\nexport function createPlatformModels(connection: Connection): PlatformModels {\n return {\n FormModel: formModel.compileModel(connection),\n SectionModel: sectionModel.compileModel(connection),\n QuestionModel: questionModel.compileModel(connection),\n ScoringRuleModel: scoringRuleModel.compileModel(connection),\n };\n}\n","/**\n * @htilabs/platform-common-models — Form Model\n *\n * Factory for creating Form model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport { buildFormSchema, type Form } from \"../schemas/form.js\";\n\nexport type FormDoc = HydratedDocument<Form>;\n\n/**\n * Build the Form schema.\n * @returns Mongoose Schema for Form\n */\nexport { buildFormSchema as buildSchema };\n\n/**\n * Compile the Form model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildFormSchema() if not provided)\n * @returns Mongoose Model for Form\n */\nexport function compileModel(\n connection: Connection,\n schema = buildFormSchema(),\n): Model<Form> {\n return connection.model<Form>(\"Form\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Form Schema\n *\n * Versioned form definitions for screening, intake, and assessment forms.\n * Forms contain ordered references to sections with display metadata.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Form Section Reference Sub-Schema ───────────────────────────────────────\n\nexport const formSectionRefSchema = new Schema(\n {\n sectionId: { type: String, required: true },\n sectionVersion: { type: String, required: true },\n index: { type: Number, required: true },\n isStep: { type: Boolean, default: false },\n wizardStep: { type: Number },\n label: { type: String },\n presetsType: { type: String },\n },\n { _id: false },\n);\n\nexport type FormSectionRef = InferRawDocType<typeof formSectionRefSchema>;\n\n// ─── Form Schema ─────────────────────────────────────────────────────────────\n\nexport const formSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Form info\n name: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n },\n formType: {\n type: String,\n index: true,\n },\n appScope: {\n type: [String],\n enum: [\"thread\", \"pave\", \"both\"],\n default: [],\n },\n\n // Ordered sections\n sections: {\n type: [formSectionRefSchema],\n default: [],\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n};\n\nexport const formSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"forms\",\n};\n\n/**\n * Build the Form schema.\n * @returns Mongoose Schema for Form\n */\nexport function buildFormSchema(): Schema {\n const schema = new Schema(formSchemaDefinition, formSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _formSchema = buildFormSchema();\n\nexport type Form = InferRawDocType<typeof _formSchema>;\n","/**\n * @htilabs/platform-common-models — Section Model\n *\n * Factory for creating Section model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport { buildSectionSchema, type Section } from \"../schemas/section.js\";\n\nexport type SectionDoc = HydratedDocument<Section>;\n\n/**\n * Build the Section schema.\n * @returns Mongoose Schema for Section\n */\nexport { buildSectionSchema as buildSchema };\n\n/**\n * Compile the Section model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildSectionSchema() if not provided)\n * @returns Mongoose Model for Section\n */\nexport function compileModel(\n connection: Connection,\n schema = buildSectionSchema(),\n): Model<Section> {\n return connection.model<Section>(\"Section\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Section Schema\n *\n * Logical grouping of questions within a form.\n * Sections contain ordered references to questions with display metadata.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Section Question Reference Sub-Schema ───────────────────────────────────\n\nexport const sectionQuestionRefSchema = new Schema(\n {\n questionId: { type: String, required: true },\n questionVersion: { type: String, required: true },\n index: { type: Number, required: true },\n },\n { _id: false },\n);\n\nexport type SectionQuestionRef = InferRawDocType<\n typeof sectionQuestionRefSchema\n>;\n\n// ─── Guidance Sub-Schema ─────────────────────────────────────────────────────\n\nexport const guidanceSchema = new Schema(\n {\n type: {\n type: String,\n required: true,\n enum: [\"tip\", \"warning\", \"prompt\"],\n },\n text: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type Guidance = InferRawDocType<typeof guidanceSchema>;\n\n// ─── Section Schema ──────────────────────────────────────────────────────────\n\nexport const sectionSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Section info\n name: {\n type: String,\n required: true,\n },\n directions: {\n type: String,\n },\n\n // Typed guidance items\n guidance: {\n type: [guidanceSchema],\n default: [],\n },\n\n // Ordered question refs\n questions: {\n type: [sectionQuestionRefSchema],\n default: [],\n },\n\n // Template visibility\n templateScope: {\n type: [String],\n default: undefined,\n },\n collapsible: {\n type: Boolean,\n default: false,\n },\n defaultCollapsed: {\n type: Boolean,\n default: false,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n\n // PAVE-aligned optional fields\n rephrasing: {\n type: String,\n },\n script: {\n type: String,\n },\n};\n\nexport const sectionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"sections\",\n};\n\n/**\n * Build the Section schema.\n * @returns Mongoose Schema for Section\n */\nexport function buildSectionSchema(): Schema {\n const schema = new Schema(sectionSchemaDefinition, sectionSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _sectionSchema = buildSectionSchema();\n\nexport type Section = InferRawDocType<typeof _sectionSchema>;\n","/**\n * @htilabs/platform-common-models — Question Model\n *\n * Factory for creating Question model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport { buildQuestionSchema, type Question } from \"../schemas/question.js\";\n\nexport type QuestionDoc = HydratedDocument<Question>;\n\n/**\n * Build the Question schema.\n * @returns Mongoose Schema for Question\n */\nexport { buildQuestionSchema as buildSchema };\n\n/**\n * Compile the Question model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildQuestionSchema() if not provided)\n * @returns Mongoose Model for Question\n */\nexport function compileModel(\n connection: Connection,\n schema = buildQuestionSchema(),\n): Model<Question> {\n return connection.model<Question>(\"Question\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Question Schema\n *\n * Individual form fields with validation, choices, visibility rules, and scoring.\n * Questions support static and dynamic choices, conditional visibility, and IC code mapping.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Choice Sub-Schema ───────────────────────────────────────────────────────\n\nexport const choiceSchema = new Schema(\n {\n val: { type: Schema.Types.Mixed, required: true },\n text: { type: String, required: true },\n tip: { type: String },\n trigger: { type: [String] },\n },\n { _id: false },\n);\n\nexport type Choice = InferRawDocType<typeof choiceSchema>;\n\n// ─── Visibility Rule Sub-Schema ──────────────────────────────────────────────\n\nexport const visibilityRuleSchema = new Schema(\n {\n dependsOn: { type: String, required: true },\n condition: {\n type: String,\n required: true,\n enum: [\"equals\", \"not_equals\", \"any_of\", \"in_range\"],\n },\n values: { type: [Schema.Types.Mixed], required: true },\n source: {\n type: String,\n enum: [\"form\", \"session\"],\n default: \"form\",\n },\n },\n { _id: false },\n);\n\nexport type VisibilityRule = InferRawDocType<typeof visibilityRuleSchema>;\n\n// ─── Layout Sub-Schema ───────────────────────────────────────────────────────\n\nexport const layoutSchema = new Schema(\n {\n columns: { type: Number, default: 1, min: 1, max: 4 },\n collapsible: { type: Boolean, default: false },\n groupKey: { type: String },\n },\n { _id: false },\n);\n\nexport type Layout = InferRawDocType<typeof layoutSchema>;\n\n// ─── Question Schema ─────────────────────────────────────────────────────────\n\nexport const questionSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Question definition\n index: {\n type: Number,\n required: true,\n },\n text: {\n type: String,\n required: true,\n },\n format: {\n type: String,\n required: true,\n },\n sectionId: {\n type: String,\n required: true,\n },\n required: {\n type: Boolean,\n default: false,\n },\n allowMultiple: {\n type: Boolean,\n default: false,\n },\n\n // Nesting\n isNested: {\n type: Boolean,\n default: false,\n },\n nested: {\n type: [String],\n default: [],\n },\n\n // Trigger logic\n isTriggered: {\n type: Boolean,\n default: false,\n },\n triggersWhenAnswered: {\n type: [String],\n default: [],\n },\n\n // Display\n header: { type: String },\n directions: { type: String },\n tip: { type: String },\n\n // Dynamic choices\n hasDynamicChoices: {\n type: Boolean,\n default: false,\n },\n dynamicChoiceSet: { type: String },\n group: { type: String },\n\n // Static choices\n choices: {\n type: [choiceSchema],\n default: [],\n },\n\n // UI rendering hints\n componentProps: {\n type: Schema.Types.Mixed,\n },\n\n // Autofill\n autofillRules: {\n type: Schema.Types.Mixed,\n default: [],\n },\n\n // Classification\n formType: {\n type: [String],\n enum: [\"screening\", \"intake\", \"assessment\", \"demographics\"],\n default: [],\n },\n icCode: {\n type: String,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n\n // Entity mapping (dual-write bridge)\n targetEntity: {\n type: String,\n enum: [\n \"caseSession\",\n \"protectedPerson\",\n \"perpetratorPerson\",\n \"personnelPerson\",\n \"caseRecord\",\n \"serviceInstance\",\n ],\n },\n targetField: {\n type: String,\n },\n\n // Conditional visibility\n visibilityRule: {\n type: visibilityRuleSchema,\n },\n\n // Layout hints\n layout: {\n type: layoutSchema,\n },\n microcopy: {\n type: String,\n },\n sensitivity: {\n type: String,\n enum: [\"standard\", \"sensitive\", \"highly_sensitive\"],\n },\n\n // Scoring group\n scoringGroup: {\n type: String,\n },\n\n // PAVE-aligned optional fields\n groups: {\n type: [String],\n default: undefined,\n },\n rephrasingSelector: {\n type: Schema.Types.Mixed,\n },\n textSelector: {\n type: Schema.Types.Mixed,\n },\n tipSelector: {\n type: Schema.Types.Mixed,\n },\n sortChoices: {\n type: Boolean,\n },\n isAllRequired: {\n type: Boolean,\n },\n itemLabel: {\n type: String,\n },\n prompts: {\n type: [String],\n default: undefined,\n },\n rephrasing: {\n type: String,\n },\n dynamicChoiceTrigger: {\n type: String,\n },\n};\n\nexport const questionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"questions\",\n};\n\n/**\n * Build the Question schema.\n * @returns Mongoose Schema for Question\n */\nexport function buildQuestionSchema(): Schema {\n const schema = new Schema(questionSchemaDefinition, questionSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n // Lookup by section + order\n schema.index({ sectionId: 1, index: 1 });\n\n // IC code lookup (sparse — many questions won't have an IC code)\n schema.index({ icCode: 1 }, { sparse: true });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _questionSchema = buildQuestionSchema();\n\nexport type Question = InferRawDocType<typeof _questionSchema>;\n","/**\n * @htilabs/platform-common-models — ScoringRule Model\n *\n * Factory for creating ScoringRule model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport {\n buildScoringRuleSchema,\n type ScoringRule,\n} from \"../schemas/scoring-rule.js\";\n\nexport type ScoringRuleDoc = HydratedDocument<ScoringRule>;\n\n/**\n * Build the ScoringRule schema.\n * @returns Mongoose Schema for ScoringRule\n */\nexport { buildScoringRuleSchema as buildSchema };\n\n/**\n * Compile the ScoringRule model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildScoringRuleSchema() if not provided)\n * @returns Mongoose Model for ScoringRule\n */\nexport function compileModel(\n connection: Connection,\n schema = buildScoringRuleSchema(),\n): Model<ScoringRule> {\n return connection.model<ScoringRule>(\"ScoringRule\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Scoring Rule Schema\n *\n * Evaluation rules for screening and assessment instruments.\n * Defines conditions to evaluate, score thresholds, and risk level recommendations.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Scoring Condition Sub-Schema ────────────────────────────────────────────\n\nexport const scoringConditionSchema = new Schema(\n {\n questionKey: { type: String, required: true },\n operator: {\n type: String,\n required: true,\n enum: [\"eq\", \"ne\", \"in\", \"not_in\", \"gt\", \"gte\", \"lt\", \"lte\"],\n },\n value: { type: Schema.Types.Mixed, required: true },\n weight: { type: Number, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringCondition = InferRawDocType<typeof scoringConditionSchema>;\n\n// ─── Scoring Threshold Sub-Schema ────────────────────────────────────────────\n\nexport const scoringThresholdSchema = new Schema(\n {\n minScore: { type: Number, required: true },\n maxScore: { type: Number, required: true },\n riskLevel: { type: String, required: true },\n label: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringThreshold = InferRawDocType<typeof scoringThresholdSchema>;\n\n// ─── Scoring Recommendation Sub-Schema ───────────────────────────────────────\n\nexport const scoringRecommendationSchema = new Schema(\n {\n riskLevel: { type: String, required: true },\n action: { type: String, required: true },\n description: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringRecommendation = InferRawDocType<\n typeof scoringRecommendationSchema\n>;\n\n// ─── Scoring Rule Schema ─────────────────────────────────────────────────────\n\nexport const scoringRuleSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Reference to Form (cross-db string, not ObjectId)\n formId: {\n type: String,\n required: true,\n },\n formVersion: {\n type: String,\n required: true,\n },\n\n // Rule info\n name: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n appScope: {\n type: [String],\n enum: [\"thread\", \"pave\", \"both\"],\n default: [],\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n effectiveDate: {\n type: Date,\n },\n deprecatedDate: {\n type: Date,\n },\n replacedBy: {\n type: String,\n },\n\n // Scoring logic\n conditions: {\n type: [scoringConditionSchema],\n default: [],\n },\n thresholds: {\n type: [scoringThresholdSchema],\n default: [],\n },\n recommendations: {\n type: [scoringRecommendationSchema],\n default: [],\n },\n};\n\nexport const scoringRuleSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"scoringrules\",\n};\n\n/**\n * Build the ScoringRule schema.\n * @returns Mongoose Schema for ScoringRule\n */\nexport function buildScoringRuleSchema(): Schema {\n const schema = new Schema(\n scoringRuleSchemaDefinition,\n scoringRuleSchemaOptions,\n );\n\n // Compound unique: one rule name per form version\n schema.index(\n { formId: 1, formVersion: 1, version: 1, name: 1 },\n { unique: true },\n );\n\n // Lookup active rules for a form\n schema.index({ formId: 1, formVersion: 1, status: 1 });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _scoringRuleSchema = buildScoringRuleSchema();\n\nexport type ScoringRule = InferRawDocType<typeof _scoringRuleSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;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A,IACV,WAAW;AAAA,IACX,WAAW;AAAA,EACb;AAAA,EACA,YAAY;AACd;AAMO,SAAS,yBAAiC;AAC/C,QAAM,SAAS,IAAI;AAAA,IACjB;AAAA,IACA;AAAA,EACF;AAGA,SAAO;AAAA,IACL,EAAE,QAAQ,GAAG,aAAa,GAAG,SAAS,GAAG,MAAM,EAAE;AAAA,IACjD,EAAE,QAAQ,KAAK;AAAA,EACjB;AAGA,SAAO,MAAM,EAAE,QAAQ,GAAG,aAAa,GAAG,QAAQ,EAAE,CAAC;AAErD,SAAO;AACT;AAGA,IAAM,qBAAqB,uBAAuB;;;AD3I3C,SAASC,cACd,YACA,SAAS,uBAAuB,GACZ;AACpB,SAAO,WAAW,MAAmB,eAAe,MAAM;AAC5D;;;APgCO,SAAS,qBAAqB,YAAwC;AAC3E,SAAO;AAAA,IACL,WAAqB,aAAa,UAAU;AAAA,IAC5C,cAA2BC,cAAa,UAAU;AAAA,IAClD,eAA6BA,cAAa,UAAU;AAAA,IACpD,kBAAmCA,cAAa,UAAU;AAAA,EAC5D;AACF;","names":["compileModel","import_mongoose","compileModel","compileModel","import_mongoose","compileModel","compileModel","import_mongoose","compileModel","compileModel"]}
1
+ {"version":3,"sources":["../../src/models/index.ts","../../src/models/formModel.ts","../../src/schemas/form.ts","../../src/models/sectionModel.ts","../../src/schemas/section.ts","../../src/models/questionModel.ts","../../src/schemas/question.ts","../../src/models/scoringRuleModel.ts","../../src/schemas/scoring-rule.ts","../../src/models/platformFunctionModel.ts","../../src/schemas/platform-function.ts","../../src/constants/platform-auth.ts","../../src/models/platformRoleModel.ts","../../src/schemas/platform-role.ts"],"sourcesContent":["/**\n * @htilabs/platform-common-models — Models\n *\n * Mongoose model factories for platform models.\n * Each model exports buildSchema() and compileModel(connection) functions.\n *\n * Usage:\n * ```typescript\n * import { createPlatformModels } from '@htilabs/platform-common-models/models';\n * import mongoose from 'mongoose';\n *\n * const platformDb = mongoose.createConnection(PLATFORM_DB_URI);\n * const { FormModel, SectionModel, QuestionModel, ScoringRuleModel } = createPlatformModels(platformDb);\n * ```\n */\n\nimport type { Connection, Model } from \"mongoose\";\n\n// Individual model factories\nimport * as formModel from \"./formModel.js\";\nimport * as sectionModel from \"./sectionModel.js\";\nimport * as questionModel from \"./questionModel.js\";\nimport * as scoringRuleModel from \"./scoringRuleModel.js\";\nimport * as platformFunctionModel from \"./platformFunctionModel.js\";\nimport * as platformRoleModel from \"./platformRoleModel.js\";\n\n// Re-export individual model factories\nexport {\n formModel,\n sectionModel,\n questionModel,\n scoringRuleModel,\n platformFunctionModel,\n platformRoleModel,\n};\n\n// Re-export types\nexport type { FormDoc } from \"./formModel.js\";\nexport type { SectionDoc } from \"./sectionModel.js\";\nexport type { QuestionDoc } from \"./questionModel.js\";\nexport type { ScoringRuleDoc } from \"./scoringRuleModel.js\";\nexport type { PlatformFunctionDoc } from \"./platformFunctionModel.js\";\nexport type { PlatformRoleDoc } from \"./platformRoleModel.js\";\n\n// Re-export schema types\nexport type { Form } from \"../schemas/form.js\";\nexport type { Section } from \"../schemas/section.js\";\nexport type { Question } from \"../schemas/question.js\";\nexport type { ScoringRule } from \"../schemas/scoring-rule.js\";\nexport type { PlatformFunction } from \"../schemas/platform-function.js\";\nexport type { PlatformRole } from \"../schemas/platform-role.js\";\n\n/**\n * Platform models interface returned by createPlatformModels.\n */\nexport interface PlatformModels {\n FormModel: Model<import(\"../schemas/form.js\").Form>;\n SectionModel: Model<import(\"../schemas/section.js\").Section>;\n QuestionModel: Model<import(\"../schemas/question.js\").Question>;\n ScoringRuleModel: Model<import(\"../schemas/scoring-rule.js\").ScoringRule>;\n PlatformFunctionModel: Model<import(\"../schemas/platform-function.js\").PlatformFunction>;\n PlatformRoleModel: Model<import(\"../schemas/platform-role.js\").PlatformRole>;\n}\n\n/**\n * Create all platform models bound to a single connection.\n * Convenience function for apps that need all form-related models.\n *\n * @param connection - Mongoose connection to bind all models to\n * @returns Object with all compiled models\n *\n * @example\n * ```typescript\n * const platformDb = mongoose.createConnection(PLATFORM_DB_URI);\n * const { FormModel, SectionModel, QuestionModel, ScoringRuleModel } = createPlatformModels(platformDb);\n *\n * const forms = await FormModel.find({ status: 'active' });\n * ```\n */\nexport function createPlatformModels(connection: Connection): PlatformModels {\n return {\n FormModel: formModel.compileModel(connection),\n SectionModel: sectionModel.compileModel(connection),\n QuestionModel: questionModel.compileModel(connection),\n ScoringRuleModel: scoringRuleModel.compileModel(connection),\n PlatformFunctionModel: platformFunctionModel.compileModel(connection),\n PlatformRoleModel: platformRoleModel.compileModel(connection),\n };\n}\n","/**\n * @htilabs/platform-common-models — Form Model\n *\n * Factory for creating Form model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport { buildFormSchema, type Form } from \"../schemas/form.js\";\n\nexport type FormDoc = HydratedDocument<Form>;\n\n/**\n * Build the Form schema.\n * @returns Mongoose Schema for Form\n */\nexport { buildFormSchema as buildSchema };\n\n/**\n * Compile the Form model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildFormSchema() if not provided)\n * @returns Mongoose Model for Form\n */\nexport function compileModel(\n connection: Connection,\n schema = buildFormSchema(),\n): Model<Form> {\n return connection.model<Form>(\"Form\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Form Schema\n *\n * Versioned form definitions for screening, intake, and assessment forms.\n * Forms contain ordered references to sections with display metadata.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Form Section Reference Sub-Schema ───────────────────────────────────────\n\nexport const formSectionRefSchema = new Schema(\n {\n sectionId: { type: String, required: true },\n sectionVersion: { type: String, required: true },\n index: { type: Number, required: true },\n isStep: { type: Boolean, default: false },\n wizardStep: { type: Number },\n label: { type: String },\n presetsType: { type: String },\n },\n { _id: false },\n);\n\nexport type FormSectionRef = InferRawDocType<typeof formSectionRefSchema>;\n\n// ─── Form Schema ─────────────────────────────────────────────────────────────\n\nexport const formSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Form info\n name: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n },\n formType: {\n type: String,\n index: true,\n },\n appScope: {\n type: [String],\n enum: [\"thread\", \"pave\", \"both\"],\n default: [],\n },\n\n // Ordered sections\n sections: {\n type: [formSectionRefSchema],\n default: [],\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n};\n\nexport const formSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"forms\",\n};\n\n/**\n * Build the Form schema.\n * @returns Mongoose Schema for Form\n */\nexport function buildFormSchema(): Schema {\n const schema = new Schema(formSchemaDefinition, formSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _formSchema = buildFormSchema();\n\nexport type Form = InferRawDocType<typeof _formSchema>;\n","/**\n * @htilabs/platform-common-models — Section Model\n *\n * Factory for creating Section model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport { buildSectionSchema, type Section } from \"../schemas/section.js\";\n\nexport type SectionDoc = HydratedDocument<Section>;\n\n/**\n * Build the Section schema.\n * @returns Mongoose Schema for Section\n */\nexport { buildSectionSchema as buildSchema };\n\n/**\n * Compile the Section model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildSectionSchema() if not provided)\n * @returns Mongoose Model for Section\n */\nexport function compileModel(\n connection: Connection,\n schema = buildSectionSchema(),\n): Model<Section> {\n return connection.model<Section>(\"Section\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Section Schema\n *\n * Logical grouping of questions within a form.\n * Sections contain ordered references to questions with display metadata.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Section Question Reference Sub-Schema ───────────────────────────────────\n\nexport const sectionQuestionRefSchema = new Schema(\n {\n questionId: { type: String, required: true },\n questionVersion: { type: String, required: true },\n index: { type: Number, required: true },\n },\n { _id: false },\n);\n\nexport type SectionQuestionRef = InferRawDocType<\n typeof sectionQuestionRefSchema\n>;\n\n// ─── Guidance Sub-Schema ─────────────────────────────────────────────────────\n\nexport const guidanceSchema = new Schema(\n {\n type: {\n type: String,\n required: true,\n enum: [\"tip\", \"warning\", \"prompt\"],\n },\n text: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type Guidance = InferRawDocType<typeof guidanceSchema>;\n\n// ─── Section Schema ──────────────────────────────────────────────────────────\n\nexport const sectionSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Section info\n name: {\n type: String,\n required: true,\n },\n directions: {\n type: String,\n },\n\n // Typed guidance items\n guidance: {\n type: [guidanceSchema],\n default: [],\n },\n\n // Ordered question refs\n questions: {\n type: [sectionQuestionRefSchema],\n default: [],\n },\n\n // Template visibility\n templateScope: {\n type: [String],\n default: undefined,\n },\n collapsible: {\n type: Boolean,\n default: false,\n },\n defaultCollapsed: {\n type: Boolean,\n default: false,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n\n // PAVE-aligned optional fields\n rephrasing: {\n type: String,\n },\n script: {\n type: String,\n },\n};\n\nexport const sectionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"sections\",\n};\n\n/**\n * Build the Section schema.\n * @returns Mongoose Schema for Section\n */\nexport function buildSectionSchema(): Schema {\n const schema = new Schema(sectionSchemaDefinition, sectionSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _sectionSchema = buildSectionSchema();\n\nexport type Section = InferRawDocType<typeof _sectionSchema>;\n","/**\n * @htilabs/platform-common-models — Question Model\n *\n * Factory for creating Question model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport { buildQuestionSchema, type Question } from \"../schemas/question.js\";\n\nexport type QuestionDoc = HydratedDocument<Question>;\n\n/**\n * Build the Question schema.\n * @returns Mongoose Schema for Question\n */\nexport { buildQuestionSchema as buildSchema };\n\n/**\n * Compile the Question model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildQuestionSchema() if not provided)\n * @returns Mongoose Model for Question\n */\nexport function compileModel(\n connection: Connection,\n schema = buildQuestionSchema(),\n): Model<Question> {\n return connection.model<Question>(\"Question\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Question Schema\n *\n * Individual form fields with validation, choices, visibility rules, and scoring.\n * Questions support static and dynamic choices, conditional visibility, and IC code mapping.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Choice Sub-Schema ───────────────────────────────────────────────────────\n\nexport const choiceSchema = new Schema(\n {\n val: { type: Schema.Types.Mixed, required: true },\n text: { type: String, required: true },\n tip: { type: String },\n trigger: { type: [String] },\n },\n { _id: false },\n);\n\nexport type Choice = InferRawDocType<typeof choiceSchema>;\n\n// ─── Visibility Rule Sub-Schema ──────────────────────────────────────────────\n\nexport const visibilityRuleSchema = new Schema(\n {\n dependsOn: { type: String, required: true },\n condition: {\n type: String,\n required: true,\n enum: [\"equals\", \"not_equals\", \"any_of\", \"in_range\"],\n },\n values: { type: [Schema.Types.Mixed], required: true },\n source: {\n type: String,\n enum: [\"form\", \"session\"],\n default: \"form\",\n },\n },\n { _id: false },\n);\n\nexport type VisibilityRule = InferRawDocType<typeof visibilityRuleSchema>;\n\n// ─── Layout Sub-Schema ───────────────────────────────────────────────────────\n\nexport const layoutSchema = new Schema(\n {\n columns: { type: Number, default: 1, min: 1, max: 4 },\n collapsible: { type: Boolean, default: false },\n groupKey: { type: String },\n },\n { _id: false },\n);\n\nexport type Layout = InferRawDocType<typeof layoutSchema>;\n\n// ─── Question Schema ─────────────────────────────────────────────────────────\n\nexport const questionSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Question definition\n index: {\n type: Number,\n required: true,\n },\n text: {\n type: String,\n required: true,\n },\n format: {\n type: String,\n required: true,\n },\n sectionId: {\n type: String,\n required: true,\n },\n required: {\n type: Boolean,\n default: false,\n },\n allowMultiple: {\n type: Boolean,\n default: false,\n },\n\n // Nesting\n isNested: {\n type: Boolean,\n default: false,\n },\n nested: {\n type: [String],\n default: [],\n },\n\n // Trigger logic\n isTriggered: {\n type: Boolean,\n default: false,\n },\n triggersWhenAnswered: {\n type: [String],\n default: [],\n },\n\n // Display\n header: { type: String },\n directions: { type: String },\n tip: { type: String },\n\n // Dynamic choices\n hasDynamicChoices: {\n type: Boolean,\n default: false,\n },\n dynamicChoiceSet: { type: String },\n group: { type: String },\n\n // Static choices\n choices: {\n type: [choiceSchema],\n default: [],\n },\n\n // UI rendering hints\n componentProps: {\n type: Schema.Types.Mixed,\n },\n\n // Autofill\n autofillRules: {\n type: Schema.Types.Mixed,\n default: [],\n },\n\n // Classification\n formType: {\n type: [String],\n enum: [\"screening\", \"intake\", \"assessment\", \"demographics\"],\n default: [],\n },\n icCode: {\n type: String,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n\n // Entity mapping (dual-write bridge)\n targetEntity: {\n type: String,\n enum: [\n \"caseSession\",\n \"protectedPerson\",\n \"perpetratorPerson\",\n \"personnelPerson\",\n \"caseRecord\",\n \"serviceInstance\",\n ],\n },\n targetField: {\n type: String,\n },\n\n // Conditional visibility\n visibilityRule: {\n type: visibilityRuleSchema,\n },\n\n // Layout hints\n layout: {\n type: layoutSchema,\n },\n microcopy: {\n type: String,\n },\n sensitivity: {\n type: String,\n enum: [\"standard\", \"sensitive\", \"highly_sensitive\"],\n },\n\n // Scoring group\n scoringGroup: {\n type: String,\n },\n\n // PAVE-aligned optional fields\n groups: {\n type: [String],\n default: undefined,\n },\n rephrasingSelector: {\n type: Schema.Types.Mixed,\n },\n textSelector: {\n type: Schema.Types.Mixed,\n },\n tipSelector: {\n type: Schema.Types.Mixed,\n },\n sortChoices: {\n type: Boolean,\n },\n isAllRequired: {\n type: Boolean,\n },\n itemLabel: {\n type: String,\n },\n prompts: {\n type: [String],\n default: undefined,\n },\n rephrasing: {\n type: String,\n },\n dynamicChoiceTrigger: {\n type: String,\n },\n};\n\nexport const questionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"questions\",\n};\n\n/**\n * Build the Question schema.\n * @returns Mongoose Schema for Question\n */\nexport function buildQuestionSchema(): Schema {\n const schema = new Schema(questionSchemaDefinition, questionSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n // Lookup by section + order\n schema.index({ sectionId: 1, index: 1 });\n\n // IC code lookup (sparse — many questions won't have an IC code)\n schema.index({ icCode: 1 }, { sparse: true });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _questionSchema = buildQuestionSchema();\n\nexport type Question = InferRawDocType<typeof _questionSchema>;\n","/**\n * @htilabs/platform-common-models — ScoringRule Model\n *\n * Factory for creating ScoringRule model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport {\n buildScoringRuleSchema,\n type ScoringRule,\n} from \"../schemas/scoring-rule.js\";\n\nexport type ScoringRuleDoc = HydratedDocument<ScoringRule>;\n\n/**\n * Build the ScoringRule schema.\n * @returns Mongoose Schema for ScoringRule\n */\nexport { buildScoringRuleSchema as buildSchema };\n\n/**\n * Compile the ScoringRule model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildScoringRuleSchema() if not provided)\n * @returns Mongoose Model for ScoringRule\n */\nexport function compileModel(\n connection: Connection,\n schema = buildScoringRuleSchema(),\n): Model<ScoringRule> {\n return connection.model<ScoringRule>(\"ScoringRule\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Scoring Rule Schema\n *\n * Evaluation rules for screening and assessment instruments.\n * Defines conditions to evaluate, score thresholds, and risk level recommendations.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Scoring Condition Sub-Schema ────────────────────────────────────────────\n\nexport const scoringConditionSchema = new Schema(\n {\n questionKey: { type: String, required: true },\n operator: {\n type: String,\n required: true,\n enum: [\"eq\", \"ne\", \"in\", \"not_in\", \"gt\", \"gte\", \"lt\", \"lte\"],\n },\n value: { type: Schema.Types.Mixed, required: true },\n weight: { type: Number, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringCondition = InferRawDocType<typeof scoringConditionSchema>;\n\n// ─── Scoring Threshold Sub-Schema ────────────────────────────────────────────\n\nexport const scoringThresholdSchema = new Schema(\n {\n minScore: { type: Number, required: true },\n maxScore: { type: Number, required: true },\n riskLevel: { type: String, required: true },\n label: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringThreshold = InferRawDocType<typeof scoringThresholdSchema>;\n\n// ─── Scoring Recommendation Sub-Schema ───────────────────────────────────────\n\nexport const scoringRecommendationSchema = new Schema(\n {\n riskLevel: { type: String, required: true },\n action: { type: String, required: true },\n description: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringRecommendation = InferRawDocType<\n typeof scoringRecommendationSchema\n>;\n\n// ─── Scoring Rule Schema ─────────────────────────────────────────────────────\n\nexport const scoringRuleSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Reference to Form (cross-db string, not ObjectId)\n formId: {\n type: String,\n required: true,\n },\n formVersion: {\n type: String,\n required: true,\n },\n\n // Rule info\n name: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n appScope: {\n type: [String],\n enum: [\"thread\", \"pave\", \"both\"],\n default: [],\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n effectiveDate: {\n type: Date,\n },\n deprecatedDate: {\n type: Date,\n },\n replacedBy: {\n type: String,\n },\n\n // Scoring logic\n conditions: {\n type: [scoringConditionSchema],\n default: [],\n },\n thresholds: {\n type: [scoringThresholdSchema],\n default: [],\n },\n recommendations: {\n type: [scoringRecommendationSchema],\n default: [],\n },\n};\n\nexport const scoringRuleSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"scoringrules\",\n};\n\n/**\n * Build the ScoringRule schema.\n * @returns Mongoose Schema for ScoringRule\n */\nexport function buildScoringRuleSchema(): Schema {\n const schema = new Schema(\n scoringRuleSchemaDefinition,\n scoringRuleSchemaOptions,\n );\n\n // Compound unique: one rule name per form version\n schema.index(\n { formId: 1, formVersion: 1, version: 1, name: 1 },\n { unique: true },\n );\n\n // Lookup active rules for a form\n schema.index({ formId: 1, formVersion: 1, status: 1 });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _scoringRuleSchema = buildScoringRuleSchema();\n\nexport type ScoringRule = InferRawDocType<typeof _scoringRuleSchema>;\n","/**\n * @htilabs/platform-common-models — PlatformFunction Model\n *\n * Factory for creating PlatformFunction model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport {\n buildPlatformFunctionSchema,\n type PlatformFunction,\n} from \"../schemas/platform-function.js\";\n\nexport type PlatformFunctionDoc = HydratedDocument<PlatformFunction>;\n\n/**\n * Build the PlatformFunction schema.\n * @returns Mongoose Schema for PlatformFunction\n */\nexport { buildPlatformFunctionSchema as buildSchema };\n\n/**\n * Compile the PlatformFunction model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildPlatformFunctionSchema() if not provided)\n * @returns Mongoose Model for PlatformFunction\n */\nexport function compileModel(\n connection: Connection,\n schema = buildPlatformFunctionSchema(),\n): Model<PlatformFunction> {\n return connection.model<PlatformFunction>(\"PlatformFunction\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Platform Function Schema\n *\n * Mongoose schema for the `platformFunctions` collection.\n * Each document represents a discrete action that can be performed\n * within the platform, with tool scope and admin/user relevance flags.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\nimport {\n PLATFORM_TOOL_VALUES,\n FUNCTION_STATUS_VALUES,\n} from \"../constants/platform-auth.js\";\n\n// ─── Schema Definition ──────────────────────────────────────────────\n\nexport const platformFunctionSchemaDefinition = {\n code: {\n type: String,\n required: true,\n },\n label: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n default: \"\",\n },\n category: {\n type: String,\n default: \"\",\n },\n tools: {\n type: [String],\n enum: [...PLATFORM_TOOL_VALUES],\n default: [],\n },\n isAdminRelevant: {\n type: Boolean,\n default: false,\n },\n isUserRelevant: {\n type: Boolean,\n default: false,\n },\n isHtiOnly: {\n type: Boolean,\n default: false,\n },\n status: {\n type: String,\n enum: [...FUNCTION_STATUS_VALUES],\n default: \"Not started\",\n },\n sortOrder: {\n type: Number,\n default: 0,\n },\n};\n\nexport const platformFunctionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"platformFunctions\",\n};\n\n// ─── Schema Builder ─────────────────────────────────────────────────\n\n/**\n * Build the PlatformFunction schema.\n * @returns Mongoose Schema for PlatformFunction\n */\nexport function buildPlatformFunctionSchema(): Schema {\n const schema = new Schema(\n platformFunctionSchemaDefinition,\n platformFunctionSchemaOptions,\n );\n\n // Unique index on function code\n schema.index({ code: 1 }, { unique: true });\n\n // Lookup indexes\n schema.index({ tools: 1 });\n schema.index({ category: 1 });\n schema.index({ sortOrder: 1 });\n\n return schema;\n}\n\n// ─── Type Inference ─────────────────────────────────────────────────\n\nconst _platformFunctionSchema = buildPlatformFunctionSchema();\nexport type PlatformFunction = InferRawDocType<typeof _platformFunctionSchema>;\n","/**\n * @htilabs/platform-common-models — Platform Authorization Constants\n *\n * Enums and labels for the platform role/function permission model.\n * Includes permission states, share view levels, tool codes, role levels,\n * and function implementation statuses.\n *\n * Source: PLATFORM_AUTH_SPEC.md Sections 5 + 6\n */\n\n// ─── Permission State (4-state role→function mapping) ──────────────\n\nexport const PERMISSION_STATE = {\n /** Role can always perform this function (mandatory, cannot disable). */\n ALWAYS: \"ALWAYS\",\n /** Default On — user can opt off. */\n PREF_YES: \"PREF_YES\",\n /** Default Off — user can opt in. */\n PREF_NO: \"PREF_NO\",\n /** Role is explicitly barred from this function. */\n NEVER: \"NEVER\",\n} as const;\n\nexport type PermissionStateValue =\n (typeof PERMISSION_STATE)[keyof typeof PERMISSION_STATE];\n\nexport const PERMISSION_STATE_VALUES = [\n PERMISSION_STATE.ALWAYS,\n PERMISSION_STATE.PREF_YES,\n PERMISSION_STATE.PREF_NO,\n PERMISSION_STATE.NEVER,\n] as const;\n\nexport const PERMISSION_STATE_LABELS: Record<PermissionStateValue, string> = {\n [PERMISSION_STATE.ALWAYS]: \"Always\",\n [PERMISSION_STATE.PREF_YES]: \"Default On\",\n [PERMISSION_STATE.PREF_NO]: \"Default Off\",\n [PERMISSION_STATE.NEVER]: \"Never\",\n};\n\n/** UI display metadata for permission states (colors, icons). */\nexport const PERMISSION_STATE_DISPLAY: Record<\n PermissionStateValue,\n { label: string; color: string; bgColor: string; icon: string }\n> = {\n [PERMISSION_STATE.ALWAYS]: {\n label: \"Always\",\n color: \"#2e7d32\",\n bgColor: \"#e8f5e9\",\n icon: \"\\u{1F512}\",\n },\n [PERMISSION_STATE.PREF_YES]: {\n label: \"Default On\",\n color: \"#1565c0\",\n bgColor: \"#e3f2fd\",\n icon: \"\\u{1F513}\",\n },\n [PERMISSION_STATE.PREF_NO]: {\n label: \"Default Off\",\n color: \"#e65100\",\n bgColor: \"#fff3e0\",\n icon: \"\\u{1F513}\",\n },\n [PERMISSION_STATE.NEVER]: {\n label: \"Never\",\n color: \"#c62828\",\n bgColor: \"#ffebee\",\n icon: \"\\u{1F512}\",\n },\n};\n\n// ─── Share View (data visibility for shared records) ───────────────\n\nexport const SHARE_VIEW = {\n /** System metadata only (partial access). */\n SYS_INFO: \"sys_info\",\n /** Full case/record content. */\n ALL: \"all\",\n /** No data access. */\n NONE: \"none\",\n} as const;\n\nexport type ShareViewValue = (typeof SHARE_VIEW)[keyof typeof SHARE_VIEW];\n\nexport const SHARE_VIEW_VALUES = [\n SHARE_VIEW.SYS_INFO,\n SHARE_VIEW.ALL,\n SHARE_VIEW.NONE,\n] as const;\n\nexport const SHARE_VIEW_LABELS: Record<ShareViewValue, string> = {\n [SHARE_VIEW.SYS_INFO]: \"System Info Only\",\n [SHARE_VIEW.ALL]: \"Full Content\",\n [SHARE_VIEW.NONE]: \"No Data Access\",\n};\n\n// ─── Platform Tool Codes ───────────────────────────────────────────\n\nexport const PLATFORM_TOOL = {\n PAVE: \"PAVE\",\n ECHO: \"ECHO\",\n LEADS: \"LEADS\",\n THREAD: \"THREAD\",\n TRAIL: \"TRAIL\",\n PLATFORM: \"PLATFORM\",\n} as const;\n\nexport type PlatformToolValue =\n (typeof PLATFORM_TOOL)[keyof typeof PLATFORM_TOOL];\n\nexport const PLATFORM_TOOL_VALUES = [\n PLATFORM_TOOL.PAVE,\n PLATFORM_TOOL.ECHO,\n PLATFORM_TOOL.LEADS,\n PLATFORM_TOOL.THREAD,\n PLATFORM_TOOL.TRAIL,\n PLATFORM_TOOL.PLATFORM,\n] as const;\n\nexport const PLATFORM_TOOL_LABELS: Record<PlatformToolValue, string> = {\n [PLATFORM_TOOL.PAVE]: \"PAVE\",\n [PLATFORM_TOOL.ECHO]: \"Echo\",\n [PLATFORM_TOOL.LEADS]: \"LEADS\",\n [PLATFORM_TOOL.THREAD]: \"Thread\",\n [PLATFORM_TOOL.TRAIL]: \"Trail\",\n [PLATFORM_TOOL.PLATFORM]: \"Platform\",\n};\n\n// ─── Role Level (hierarchy tiers) ──────────────────────────────────\n\nexport const ROLE_LEVEL = {\n /** User-facing roles (staff, volunteers, practitioners). */\n OPERATIONAL: \"operational\",\n /** Agency-level admin roles. */\n AGENCY: \"agency\",\n /** Team-level admin roles. */\n TEAM: \"team\",\n /** HTI-wide platform admin. */\n PLATFORM: \"platform\",\n /** External governance/oversight roles. */\n OVERSIGHT: \"oversight\",\n} as const;\n\nexport type RoleLevelValue = (typeof ROLE_LEVEL)[keyof typeof ROLE_LEVEL];\n\nexport const ROLE_LEVEL_VALUES = [\n ROLE_LEVEL.OPERATIONAL,\n ROLE_LEVEL.AGENCY,\n ROLE_LEVEL.TEAM,\n ROLE_LEVEL.PLATFORM,\n ROLE_LEVEL.OVERSIGHT,\n] as const;\n\nexport const ROLE_LEVEL_LABELS: Record<RoleLevelValue, string> = {\n [ROLE_LEVEL.OPERATIONAL]: \"Operational\",\n [ROLE_LEVEL.AGENCY]: \"Agency\",\n [ROLE_LEVEL.TEAM]: \"Team\",\n [ROLE_LEVEL.PLATFORM]: \"Platform\",\n [ROLE_LEVEL.OVERSIGHT]: \"Oversight\",\n};\n\n// ─── Function Implementation Status ────────────────────────────────\n\nexport const FUNCTION_STATUS = {\n NOT_STARTED: \"Not started\",\n DEFINED_NEW: \"Defined; new function\",\n DEFINED_EXISTING: \"Defined; existing PAVE function\",\n FUNCTIONAL: \"Functional on all apps\",\n FUTURE: \"Future function (not v1)\",\n} as const;\n\nexport type FunctionStatusValue =\n (typeof FUNCTION_STATUS)[keyof typeof FUNCTION_STATUS];\n\nexport const FUNCTION_STATUS_VALUES = [\n FUNCTION_STATUS.NOT_STARTED,\n FUNCTION_STATUS.DEFINED_NEW,\n FUNCTION_STATUS.DEFINED_EXISTING,\n FUNCTION_STATUS.FUNCTIONAL,\n FUNCTION_STATUS.FUTURE,\n] as const;\n\nexport const FUNCTION_STATUS_LABELS: Record<FunctionStatusValue, string> = {\n [FUNCTION_STATUS.NOT_STARTED]: \"Not Started\",\n [FUNCTION_STATUS.DEFINED_NEW]: \"Defined (New)\",\n [FUNCTION_STATUS.DEFINED_EXISTING]: \"Defined (Existing PAVE)\",\n [FUNCTION_STATUS.FUNCTIONAL]: \"Functional\",\n [FUNCTION_STATUS.FUTURE]: \"Future (Not v1)\",\n};\n","/**\n * @htilabs/platform-common-models — PlatformRole Model\n *\n * Factory for creating PlatformRole model bound to a specific connection.\n * Follows the platform-common-services pattern with buildSchema/compileModel.\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport {\n buildPlatformRoleSchema,\n type PlatformRole,\n} from \"../schemas/platform-role.js\";\n\nexport type PlatformRoleDoc = HydratedDocument<PlatformRole>;\n\n/**\n * Build the PlatformRole schema.\n * @returns Mongoose Schema for PlatformRole\n */\nexport { buildPlatformRoleSchema as buildSchema };\n\n/**\n * Compile the PlatformRole model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildPlatformRoleSchema() if not provided)\n * @returns Mongoose Model for PlatformRole\n */\nexport function compileModel(\n connection: Connection,\n schema = buildPlatformRoleSchema(),\n): Model<PlatformRole> {\n return connection.model<PlatformRole>(\"PlatformRole\", schema);\n}\n","/**\n * @htilabs/platform-common-models — Platform Role Schema\n *\n * Mongoose schema for the `platformRoles` collection.\n * Each document represents a role that bundles function permissions,\n * tool scope, and share visibility settings.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\nimport {\n PLATFORM_TOOL_VALUES,\n ROLE_LEVEL_VALUES,\n SHARE_VIEW_VALUES,\n} from \"../constants/platform-auth.js\";\n\n// ─── Schema Definition ──────────────────────────────────────────────\n\nexport const platformRoleSchemaDefinition = {\n code: {\n type: String,\n required: true,\n },\n label: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n default: \"\",\n },\n level: {\n type: String,\n enum: [...ROLE_LEVEL_VALUES],\n required: true,\n },\n tools: {\n type: [String],\n enum: [...PLATFORM_TOOL_VALUES],\n default: [],\n },\n shareView: {\n type: String,\n enum: [...SHARE_VIEW_VALUES, null],\n default: null,\n },\n trainingRequirements: {\n type: String,\n default: null,\n },\n isHtiOnly: {\n type: Boolean,\n default: false,\n },\n /** Dynamic map of functionCode → PermissionStateValue. */\n functions: {\n type: Schema.Types.Mixed,\n default: {},\n },\n sortOrder: {\n type: Number,\n default: 0,\n },\n};\n\nexport const platformRoleSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"platformRoles\",\n};\n\n// ─── Schema Builder ─────────────────────────────────────────────────\n\n/**\n * Build the PlatformRole schema.\n * @returns Mongoose Schema for PlatformRole\n */\nexport function buildPlatformRoleSchema(): Schema {\n const schema = new Schema(\n platformRoleSchemaDefinition,\n platformRoleSchemaOptions,\n );\n\n // Unique index on role code\n schema.index({ code: 1 }, { unique: true });\n\n // Lookup indexes\n schema.index({ level: 1 });\n schema.index({ tools: 1 });\n schema.index({ isHtiOnly: 1 });\n\n return schema;\n}\n\n// ─── Type Inference ─────────────────────────────────────────────────\n\nconst _platformRoleSchema = buildPlatformRoleSchema();\nexport type PlatformRole = InferRawDocType<typeof _platformRoleSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,sBAAuB;AAKhB,IAAM,uBAAuB,IAAI;AAAA,EACtC;AAAA,IACE,WAAW,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IAC1C,gBAAgB,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IAC/C,OAAO,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACtC,QAAQ,EAAE,MAAM,SAAS,SAAS,MAAM;AAAA,IACxC,YAAY,EAAE,MAAM,OAAO;AAAA,IAC3B,OAAO,EAAE,MAAM,OAAO;AAAA,IACtB,aAAa,EAAE,MAAM,OAAO;AAAA,EAC9B;AAAA,EACA,EAAE,KAAK,MAAM;AACf;AAMO,IAAM,uBAAuB;AAAA,EAClC,gBAAgB;AAAA,IACd,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS;AAAA,EAC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,EACA,YAAY;AACd;AAQO,SAAS,0BAAkC;AAChD,QAAM,SAAS,IAAI;AAAA,IACjB;AAAA,IACA;AAAA,EACF;AAGA,SAAO,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,KAAK,CAAC;AAG1C,SAAO,MAAM,EAAE,OAAO,EAAE,CAAC;AACzB,SAAO,MAAM,EAAE,OAAO,EAAE,CAAC;AACzB,SAAO,MAAM,EAAE,WAAW,EAAE,CAAC;AAE7B,SAAO;AACT;AAIA,IAAM,sBAAsB,wBAAwB;;;ADvE7C,SAASC,cACd,YACA,SAAS,wBAAwB,GACZ;AACrB,SAAO,WAAW,MAAoB,gBAAgB,MAAM;AAC9D;;;AZ+CO,SAAS,qBAAqB,YAAwC;AAC3E,SAAO;AAAA,IACL,WAAqB,aAAa,UAAU;AAAA,IAC5C,cAA2BC,cAAa,UAAU;AAAA,IAClD,eAA6BA,cAAa,UAAU;AAAA,IACpD,kBAAmCA,cAAa,UAAU;AAAA,IAC1D,uBAA6CA,cAAa,UAAU;AAAA,IACpE,mBAAqCA,cAAa,UAAU;AAAA,EAC9D;AACF;","names":["compileModel","import_mongoose","compileModel","compileModel","import_mongoose","compileModel","compileModel","import_mongoose","compileModel","compileModel","import_mongoose","compileModel","compileModel","import_mongoose","compileModel","compileModel"]}