@htilabs/platform-common-models 0.1.0-beta.3 → 0.2.0-beta.1
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/dist/constants/index.cjs +183 -4465
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +612 -127
- package/dist/constants/index.d.ts +612 -127
- package/dist/constants/index.js +167 -4298
- package/dist/constants/index.js.map +1 -1
- package/dist/index.cjs +356 -4466
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +332 -4299
- package/dist/index.js.map +1 -1
- package/dist/models/index.cjs +306 -1
- package/dist/models/index.cjs.map +1 -1
- package/dist/models/index.d.cts +99 -11
- package/dist/models/index.d.ts +99 -11
- package/dist/models/index.js +304 -1
- package/dist/models/index.js.map +1 -1
- package/dist/{scoring-rule-liZlPytD.d.cts → platform-role-CcFTFHUr.d.cts} +185 -9
- package/dist/{scoring-rule-liZlPytD.d.ts → platform-role-CcFTFHUr.d.ts} +185 -9
- package/dist/schemas/index.cjs +297 -2666
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +5 -5
- package/dist/schemas/index.d.ts +5 -5
- package/dist/schemas/index.js +291 -2666
- package/dist/schemas/index.js.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +45 -1
- package/dist/types/index.d.ts +45 -1
- package/package.json +1 -1
- package/src/constants/ic.ts +28 -3513
- package/src/constants/index.ts +1 -2
- package/src/constants/platform-auth.ts +189 -0
- package/src/models/index.ts +18 -1
- package/src/models/platformFunctionModel.ts +33 -0
- package/src/models/platformRoleModel.ts +33 -0
- package/src/schemas/index.ts +16 -0
- package/src/schemas/platform-function.ts +97 -0
- package/src/schemas/platform-role.ts +100 -0
- package/src/types/index.ts +14 -0
- package/src/types/platform-auth.ts +49 -0
- package/dist/index-Cww9rH3H.d.cts +0 -1695
- package/dist/index-Cww9rH3H.d.ts +0 -1695
- package/src/constants/service-catalog.json +0 -1349
- package/src/constants/service-catalog.ts +0 -225
package/src/constants/index.ts
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Shared constants for HTI Labs applications including:
|
|
5
5
|
* - Information Concept (IC) codes for victim services data standards
|
|
6
|
-
* - IC-48 Universal Service Catalog
|
|
7
6
|
* - Data quality indicators
|
|
8
7
|
* - Person types and involvement roles
|
|
9
8
|
* - Form configuration constants
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
11
|
export * from "./ic.js";
|
|
13
|
-
export * from "./
|
|
12
|
+
export * from "./platform-auth.js";
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — Platform Authorization Constants
|
|
3
|
+
*
|
|
4
|
+
* Enums and labels for the platform role/function permission model.
|
|
5
|
+
* Includes permission states, share view levels, tool codes, role levels,
|
|
6
|
+
* and function implementation statuses.
|
|
7
|
+
*
|
|
8
|
+
* Source: PLATFORM_AUTH_SPEC.md Sections 5 + 6
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// ─── Permission State (4-state role→function mapping) ──────────────
|
|
12
|
+
|
|
13
|
+
export const PERMISSION_STATE = {
|
|
14
|
+
/** Role can always perform this function (mandatory, cannot disable). */
|
|
15
|
+
ALWAYS: "ALWAYS",
|
|
16
|
+
/** Default On — user can opt off. */
|
|
17
|
+
PREF_YES: "PREF_YES",
|
|
18
|
+
/** Default Off — user can opt in. */
|
|
19
|
+
PREF_NO: "PREF_NO",
|
|
20
|
+
/** Role is explicitly barred from this function. */
|
|
21
|
+
NEVER: "NEVER",
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
export type PermissionStateValue =
|
|
25
|
+
(typeof PERMISSION_STATE)[keyof typeof PERMISSION_STATE];
|
|
26
|
+
|
|
27
|
+
export const PERMISSION_STATE_VALUES = [
|
|
28
|
+
PERMISSION_STATE.ALWAYS,
|
|
29
|
+
PERMISSION_STATE.PREF_YES,
|
|
30
|
+
PERMISSION_STATE.PREF_NO,
|
|
31
|
+
PERMISSION_STATE.NEVER,
|
|
32
|
+
] as const;
|
|
33
|
+
|
|
34
|
+
export const PERMISSION_STATE_LABELS: Record<PermissionStateValue, string> = {
|
|
35
|
+
[PERMISSION_STATE.ALWAYS]: "Always",
|
|
36
|
+
[PERMISSION_STATE.PREF_YES]: "Default On",
|
|
37
|
+
[PERMISSION_STATE.PREF_NO]: "Default Off",
|
|
38
|
+
[PERMISSION_STATE.NEVER]: "Never",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** UI display metadata for permission states (colors, icons). */
|
|
42
|
+
export const PERMISSION_STATE_DISPLAY: Record<
|
|
43
|
+
PermissionStateValue,
|
|
44
|
+
{ label: string; color: string; bgColor: string; icon: string }
|
|
45
|
+
> = {
|
|
46
|
+
[PERMISSION_STATE.ALWAYS]: {
|
|
47
|
+
label: "Always",
|
|
48
|
+
color: "#2e7d32",
|
|
49
|
+
bgColor: "#e8f5e9",
|
|
50
|
+
icon: "\u{1F512}",
|
|
51
|
+
},
|
|
52
|
+
[PERMISSION_STATE.PREF_YES]: {
|
|
53
|
+
label: "Default On",
|
|
54
|
+
color: "#1565c0",
|
|
55
|
+
bgColor: "#e3f2fd",
|
|
56
|
+
icon: "\u{1F513}",
|
|
57
|
+
},
|
|
58
|
+
[PERMISSION_STATE.PREF_NO]: {
|
|
59
|
+
label: "Default Off",
|
|
60
|
+
color: "#e65100",
|
|
61
|
+
bgColor: "#fff3e0",
|
|
62
|
+
icon: "\u{1F513}",
|
|
63
|
+
},
|
|
64
|
+
[PERMISSION_STATE.NEVER]: {
|
|
65
|
+
label: "Never",
|
|
66
|
+
color: "#c62828",
|
|
67
|
+
bgColor: "#ffebee",
|
|
68
|
+
icon: "\u{1F512}",
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// ─── Share View (data visibility for shared records) ───────────────
|
|
73
|
+
|
|
74
|
+
export const SHARE_VIEW = {
|
|
75
|
+
/** System metadata only (partial access). */
|
|
76
|
+
SYS_INFO: "sys_info",
|
|
77
|
+
/** Full case/record content. */
|
|
78
|
+
ALL: "all",
|
|
79
|
+
/** No data access. */
|
|
80
|
+
NONE: "none",
|
|
81
|
+
} as const;
|
|
82
|
+
|
|
83
|
+
export type ShareViewValue = (typeof SHARE_VIEW)[keyof typeof SHARE_VIEW];
|
|
84
|
+
|
|
85
|
+
export const SHARE_VIEW_VALUES = [
|
|
86
|
+
SHARE_VIEW.SYS_INFO,
|
|
87
|
+
SHARE_VIEW.ALL,
|
|
88
|
+
SHARE_VIEW.NONE,
|
|
89
|
+
] as const;
|
|
90
|
+
|
|
91
|
+
export const SHARE_VIEW_LABELS: Record<ShareViewValue, string> = {
|
|
92
|
+
[SHARE_VIEW.SYS_INFO]: "System Info Only",
|
|
93
|
+
[SHARE_VIEW.ALL]: "Full Content",
|
|
94
|
+
[SHARE_VIEW.NONE]: "No Data Access",
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// ─── Platform Tool Codes ───────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
export const PLATFORM_TOOL = {
|
|
100
|
+
PAVE: "PAVE",
|
|
101
|
+
ECHO: "ECHO",
|
|
102
|
+
LEADS: "LEADS",
|
|
103
|
+
THREAD: "THREAD",
|
|
104
|
+
TRAIL: "TRAIL",
|
|
105
|
+
PLATFORM: "PLATFORM",
|
|
106
|
+
} as const;
|
|
107
|
+
|
|
108
|
+
export type PlatformToolValue =
|
|
109
|
+
(typeof PLATFORM_TOOL)[keyof typeof PLATFORM_TOOL];
|
|
110
|
+
|
|
111
|
+
export const PLATFORM_TOOL_VALUES = [
|
|
112
|
+
PLATFORM_TOOL.PAVE,
|
|
113
|
+
PLATFORM_TOOL.ECHO,
|
|
114
|
+
PLATFORM_TOOL.LEADS,
|
|
115
|
+
PLATFORM_TOOL.THREAD,
|
|
116
|
+
PLATFORM_TOOL.TRAIL,
|
|
117
|
+
PLATFORM_TOOL.PLATFORM,
|
|
118
|
+
] as const;
|
|
119
|
+
|
|
120
|
+
export const PLATFORM_TOOL_LABELS: Record<PlatformToolValue, string> = {
|
|
121
|
+
[PLATFORM_TOOL.PAVE]: "PAVE",
|
|
122
|
+
[PLATFORM_TOOL.ECHO]: "Echo",
|
|
123
|
+
[PLATFORM_TOOL.LEADS]: "LEADS",
|
|
124
|
+
[PLATFORM_TOOL.THREAD]: "Thread",
|
|
125
|
+
[PLATFORM_TOOL.TRAIL]: "Trail",
|
|
126
|
+
[PLATFORM_TOOL.PLATFORM]: "Platform",
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// ─── Role Level (hierarchy tiers) ──────────────────────────────────
|
|
130
|
+
|
|
131
|
+
export const ROLE_LEVEL = {
|
|
132
|
+
/** User-facing roles (staff, volunteers, practitioners). */
|
|
133
|
+
OPERATIONAL: "operational",
|
|
134
|
+
/** Agency-level admin roles. */
|
|
135
|
+
AGENCY: "agency",
|
|
136
|
+
/** Team-level admin roles. */
|
|
137
|
+
TEAM: "team",
|
|
138
|
+
/** HTI-wide platform admin. */
|
|
139
|
+
PLATFORM: "platform",
|
|
140
|
+
/** External governance/oversight roles. */
|
|
141
|
+
OVERSIGHT: "oversight",
|
|
142
|
+
} as const;
|
|
143
|
+
|
|
144
|
+
export type RoleLevelValue = (typeof ROLE_LEVEL)[keyof typeof ROLE_LEVEL];
|
|
145
|
+
|
|
146
|
+
export const ROLE_LEVEL_VALUES = [
|
|
147
|
+
ROLE_LEVEL.OPERATIONAL,
|
|
148
|
+
ROLE_LEVEL.AGENCY,
|
|
149
|
+
ROLE_LEVEL.TEAM,
|
|
150
|
+
ROLE_LEVEL.PLATFORM,
|
|
151
|
+
ROLE_LEVEL.OVERSIGHT,
|
|
152
|
+
] as const;
|
|
153
|
+
|
|
154
|
+
export const ROLE_LEVEL_LABELS: Record<RoleLevelValue, string> = {
|
|
155
|
+
[ROLE_LEVEL.OPERATIONAL]: "Operational",
|
|
156
|
+
[ROLE_LEVEL.AGENCY]: "Agency",
|
|
157
|
+
[ROLE_LEVEL.TEAM]: "Team",
|
|
158
|
+
[ROLE_LEVEL.PLATFORM]: "Platform",
|
|
159
|
+
[ROLE_LEVEL.OVERSIGHT]: "Oversight",
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// ─── Function Implementation Status ────────────────────────────────
|
|
163
|
+
|
|
164
|
+
export const FUNCTION_STATUS = {
|
|
165
|
+
NOT_STARTED: "Not started",
|
|
166
|
+
DEFINED_NEW: "Defined; new function",
|
|
167
|
+
DEFINED_EXISTING: "Defined; existing PAVE function",
|
|
168
|
+
FUNCTIONAL: "Functional on all apps",
|
|
169
|
+
FUTURE: "Future function (not v1)",
|
|
170
|
+
} as const;
|
|
171
|
+
|
|
172
|
+
export type FunctionStatusValue =
|
|
173
|
+
(typeof FUNCTION_STATUS)[keyof typeof FUNCTION_STATUS];
|
|
174
|
+
|
|
175
|
+
export const FUNCTION_STATUS_VALUES = [
|
|
176
|
+
FUNCTION_STATUS.NOT_STARTED,
|
|
177
|
+
FUNCTION_STATUS.DEFINED_NEW,
|
|
178
|
+
FUNCTION_STATUS.DEFINED_EXISTING,
|
|
179
|
+
FUNCTION_STATUS.FUNCTIONAL,
|
|
180
|
+
FUNCTION_STATUS.FUTURE,
|
|
181
|
+
] as const;
|
|
182
|
+
|
|
183
|
+
export const FUNCTION_STATUS_LABELS: Record<FunctionStatusValue, string> = {
|
|
184
|
+
[FUNCTION_STATUS.NOT_STARTED]: "Not Started",
|
|
185
|
+
[FUNCTION_STATUS.DEFINED_NEW]: "Defined (New)",
|
|
186
|
+
[FUNCTION_STATUS.DEFINED_EXISTING]: "Defined (Existing PAVE)",
|
|
187
|
+
[FUNCTION_STATUS.FUNCTIONAL]: "Functional",
|
|
188
|
+
[FUNCTION_STATUS.FUTURE]: "Future (Not v1)",
|
|
189
|
+
};
|
package/src/models/index.ts
CHANGED
|
@@ -21,21 +21,34 @@ import * as formModel from "./formModel.js";
|
|
|
21
21
|
import * as sectionModel from "./sectionModel.js";
|
|
22
22
|
import * as questionModel from "./questionModel.js";
|
|
23
23
|
import * as scoringRuleModel from "./scoringRuleModel.js";
|
|
24
|
+
import * as platformFunctionModel from "./platformFunctionModel.js";
|
|
25
|
+
import * as platformRoleModel from "./platformRoleModel.js";
|
|
24
26
|
|
|
25
27
|
// Re-export individual model factories
|
|
26
|
-
export {
|
|
28
|
+
export {
|
|
29
|
+
formModel,
|
|
30
|
+
sectionModel,
|
|
31
|
+
questionModel,
|
|
32
|
+
scoringRuleModel,
|
|
33
|
+
platformFunctionModel,
|
|
34
|
+
platformRoleModel,
|
|
35
|
+
};
|
|
27
36
|
|
|
28
37
|
// Re-export types
|
|
29
38
|
export type { FormDoc } from "./formModel.js";
|
|
30
39
|
export type { SectionDoc } from "./sectionModel.js";
|
|
31
40
|
export type { QuestionDoc } from "./questionModel.js";
|
|
32
41
|
export type { ScoringRuleDoc } from "./scoringRuleModel.js";
|
|
42
|
+
export type { PlatformFunctionDoc } from "./platformFunctionModel.js";
|
|
43
|
+
export type { PlatformRoleDoc } from "./platformRoleModel.js";
|
|
33
44
|
|
|
34
45
|
// Re-export schema types
|
|
35
46
|
export type { Form } from "../schemas/form.js";
|
|
36
47
|
export type { Section } from "../schemas/section.js";
|
|
37
48
|
export type { Question } from "../schemas/question.js";
|
|
38
49
|
export type { ScoringRule } from "../schemas/scoring-rule.js";
|
|
50
|
+
export type { PlatformFunction } from "../schemas/platform-function.js";
|
|
51
|
+
export type { PlatformRole } from "../schemas/platform-role.js";
|
|
39
52
|
|
|
40
53
|
/**
|
|
41
54
|
* Platform models interface returned by createPlatformModels.
|
|
@@ -45,6 +58,8 @@ export interface PlatformModels {
|
|
|
45
58
|
SectionModel: Model<import("../schemas/section.js").Section>;
|
|
46
59
|
QuestionModel: Model<import("../schemas/question.js").Question>;
|
|
47
60
|
ScoringRuleModel: Model<import("../schemas/scoring-rule.js").ScoringRule>;
|
|
61
|
+
PlatformFunctionModel: Model<import("../schemas/platform-function.js").PlatformFunction>;
|
|
62
|
+
PlatformRoleModel: Model<import("../schemas/platform-role.js").PlatformRole>;
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
/**
|
|
@@ -68,5 +83,7 @@ export function createPlatformModels(connection: Connection): PlatformModels {
|
|
|
68
83
|
SectionModel: sectionModel.compileModel(connection),
|
|
69
84
|
QuestionModel: questionModel.compileModel(connection),
|
|
70
85
|
ScoringRuleModel: scoringRuleModel.compileModel(connection),
|
|
86
|
+
PlatformFunctionModel: platformFunctionModel.compileModel(connection),
|
|
87
|
+
PlatformRoleModel: platformRoleModel.compileModel(connection),
|
|
71
88
|
};
|
|
72
89
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — PlatformFunction Model
|
|
3
|
+
*
|
|
4
|
+
* Factory for creating PlatformFunction model bound to a specific connection.
|
|
5
|
+
* Follows the platform-common-services pattern with buildSchema/compileModel.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Connection, Model, HydratedDocument } from "mongoose";
|
|
9
|
+
import {
|
|
10
|
+
buildPlatformFunctionSchema,
|
|
11
|
+
type PlatformFunction,
|
|
12
|
+
} from "../schemas/platform-function.js";
|
|
13
|
+
|
|
14
|
+
export type PlatformFunctionDoc = HydratedDocument<PlatformFunction>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Build the PlatformFunction schema.
|
|
18
|
+
* @returns Mongoose Schema for PlatformFunction
|
|
19
|
+
*/
|
|
20
|
+
export { buildPlatformFunctionSchema as buildSchema };
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Compile the PlatformFunction model on a specific connection.
|
|
24
|
+
* @param connection - Mongoose connection to bind the model to
|
|
25
|
+
* @param schema - Optional pre-built schema (uses buildPlatformFunctionSchema() if not provided)
|
|
26
|
+
* @returns Mongoose Model for PlatformFunction
|
|
27
|
+
*/
|
|
28
|
+
export function compileModel(
|
|
29
|
+
connection: Connection,
|
|
30
|
+
schema = buildPlatformFunctionSchema(),
|
|
31
|
+
): Model<PlatformFunction> {
|
|
32
|
+
return connection.model<PlatformFunction>("PlatformFunction", schema);
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — PlatformRole Model
|
|
3
|
+
*
|
|
4
|
+
* Factory for creating PlatformRole model bound to a specific connection.
|
|
5
|
+
* Follows the platform-common-services pattern with buildSchema/compileModel.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Connection, Model, HydratedDocument } from "mongoose";
|
|
9
|
+
import {
|
|
10
|
+
buildPlatformRoleSchema,
|
|
11
|
+
type PlatformRole,
|
|
12
|
+
} from "../schemas/platform-role.js";
|
|
13
|
+
|
|
14
|
+
export type PlatformRoleDoc = HydratedDocument<PlatformRole>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Build the PlatformRole schema.
|
|
18
|
+
* @returns Mongoose Schema for PlatformRole
|
|
19
|
+
*/
|
|
20
|
+
export { buildPlatformRoleSchema as buildSchema };
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Compile the PlatformRole model on a specific connection.
|
|
24
|
+
* @param connection - Mongoose connection to bind the model to
|
|
25
|
+
* @param schema - Optional pre-built schema (uses buildPlatformRoleSchema() if not provided)
|
|
26
|
+
* @returns Mongoose Model for PlatformRole
|
|
27
|
+
*/
|
|
28
|
+
export function compileModel(
|
|
29
|
+
connection: Connection,
|
|
30
|
+
schema = buildPlatformRoleSchema(),
|
|
31
|
+
): Model<PlatformRole> {
|
|
32
|
+
return connection.model<PlatformRole>("PlatformRole", schema);
|
|
33
|
+
}
|
package/src/schemas/index.ts
CHANGED
|
@@ -68,3 +68,19 @@ export {
|
|
|
68
68
|
type ScoringRecommendation,
|
|
69
69
|
type ScoringRule,
|
|
70
70
|
} from "./scoring-rule.js";
|
|
71
|
+
|
|
72
|
+
// Platform function schema
|
|
73
|
+
export {
|
|
74
|
+
buildPlatformFunctionSchema,
|
|
75
|
+
platformFunctionSchemaDefinition,
|
|
76
|
+
platformFunctionSchemaOptions,
|
|
77
|
+
type PlatformFunction,
|
|
78
|
+
} from "./platform-function.js";
|
|
79
|
+
|
|
80
|
+
// Platform role schema
|
|
81
|
+
export {
|
|
82
|
+
buildPlatformRoleSchema,
|
|
83
|
+
platformRoleSchemaDefinition,
|
|
84
|
+
platformRoleSchemaOptions,
|
|
85
|
+
type PlatformRole,
|
|
86
|
+
} from "./platform-role.js";
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — Platform Function Schema
|
|
3
|
+
*
|
|
4
|
+
* Mongoose schema for the `platformFunctions` collection.
|
|
5
|
+
* Each document represents a discrete action that can be performed
|
|
6
|
+
* within the platform, with tool scope and admin/user relevance flags.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Schema } from "mongoose";
|
|
10
|
+
import type { InferRawDocType } from "mongoose";
|
|
11
|
+
import {
|
|
12
|
+
PLATFORM_TOOL_VALUES,
|
|
13
|
+
FUNCTION_STATUS_VALUES,
|
|
14
|
+
} from "../constants/platform-auth.js";
|
|
15
|
+
|
|
16
|
+
// ─── Schema Definition ──────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
export const platformFunctionSchemaDefinition = {
|
|
19
|
+
code: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: true,
|
|
22
|
+
},
|
|
23
|
+
label: {
|
|
24
|
+
type: String,
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
description: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: "",
|
|
30
|
+
},
|
|
31
|
+
category: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: "",
|
|
34
|
+
},
|
|
35
|
+
tools: {
|
|
36
|
+
type: [String],
|
|
37
|
+
enum: [...PLATFORM_TOOL_VALUES],
|
|
38
|
+
default: [],
|
|
39
|
+
},
|
|
40
|
+
isAdminRelevant: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: false,
|
|
43
|
+
},
|
|
44
|
+
isUserRelevant: {
|
|
45
|
+
type: Boolean,
|
|
46
|
+
default: false,
|
|
47
|
+
},
|
|
48
|
+
isHtiOnly: {
|
|
49
|
+
type: Boolean,
|
|
50
|
+
default: false,
|
|
51
|
+
},
|
|
52
|
+
status: {
|
|
53
|
+
type: String,
|
|
54
|
+
enum: [...FUNCTION_STATUS_VALUES],
|
|
55
|
+
default: "Not started",
|
|
56
|
+
},
|
|
57
|
+
sortOrder: {
|
|
58
|
+
type: Number,
|
|
59
|
+
default: 0,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const platformFunctionSchemaOptions = {
|
|
64
|
+
timestamps: {
|
|
65
|
+
createdAt: "createdTime",
|
|
66
|
+
updatedAt: "updatedTime",
|
|
67
|
+
},
|
|
68
|
+
collection: "platformFunctions",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// ─── Schema Builder ─────────────────────────────────────────────────
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Build the PlatformFunction schema.
|
|
75
|
+
* @returns Mongoose Schema for PlatformFunction
|
|
76
|
+
*/
|
|
77
|
+
export function buildPlatformFunctionSchema(): Schema {
|
|
78
|
+
const schema = new Schema(
|
|
79
|
+
platformFunctionSchemaDefinition,
|
|
80
|
+
platformFunctionSchemaOptions,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// Unique index on function code
|
|
84
|
+
schema.index({ code: 1 }, { unique: true });
|
|
85
|
+
|
|
86
|
+
// Lookup indexes
|
|
87
|
+
schema.index({ tools: 1 });
|
|
88
|
+
schema.index({ category: 1 });
|
|
89
|
+
schema.index({ sortOrder: 1 });
|
|
90
|
+
|
|
91
|
+
return schema;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ─── Type Inference ─────────────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
const _platformFunctionSchema = buildPlatformFunctionSchema();
|
|
97
|
+
export type PlatformFunction = InferRawDocType<typeof _platformFunctionSchema>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — Platform Role Schema
|
|
3
|
+
*
|
|
4
|
+
* Mongoose schema for the `platformRoles` collection.
|
|
5
|
+
* Each document represents a role that bundles function permissions,
|
|
6
|
+
* tool scope, and share visibility settings.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Schema } from "mongoose";
|
|
10
|
+
import type { InferRawDocType } from "mongoose";
|
|
11
|
+
import {
|
|
12
|
+
PLATFORM_TOOL_VALUES,
|
|
13
|
+
ROLE_LEVEL_VALUES,
|
|
14
|
+
SHARE_VIEW_VALUES,
|
|
15
|
+
} from "../constants/platform-auth.js";
|
|
16
|
+
|
|
17
|
+
// ─── Schema Definition ──────────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
export const platformRoleSchemaDefinition = {
|
|
20
|
+
code: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
label: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
description: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: "",
|
|
31
|
+
},
|
|
32
|
+
level: {
|
|
33
|
+
type: String,
|
|
34
|
+
enum: [...ROLE_LEVEL_VALUES],
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
tools: {
|
|
38
|
+
type: [String],
|
|
39
|
+
enum: [...PLATFORM_TOOL_VALUES],
|
|
40
|
+
default: [],
|
|
41
|
+
},
|
|
42
|
+
shareView: {
|
|
43
|
+
type: String,
|
|
44
|
+
enum: [...SHARE_VIEW_VALUES, null],
|
|
45
|
+
default: null,
|
|
46
|
+
},
|
|
47
|
+
trainingRequirements: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: null,
|
|
50
|
+
},
|
|
51
|
+
isHtiOnly: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: false,
|
|
54
|
+
},
|
|
55
|
+
/** Dynamic map of functionCode → PermissionStateValue. */
|
|
56
|
+
functions: {
|
|
57
|
+
type: Schema.Types.Mixed,
|
|
58
|
+
default: {},
|
|
59
|
+
},
|
|
60
|
+
sortOrder: {
|
|
61
|
+
type: Number,
|
|
62
|
+
default: 0,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const platformRoleSchemaOptions = {
|
|
67
|
+
timestamps: {
|
|
68
|
+
createdAt: "createdTime",
|
|
69
|
+
updatedAt: "updatedTime",
|
|
70
|
+
},
|
|
71
|
+
collection: "platformRoles",
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// ─── Schema Builder ─────────────────────────────────────────────────
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Build the PlatformRole schema.
|
|
78
|
+
* @returns Mongoose Schema for PlatformRole
|
|
79
|
+
*/
|
|
80
|
+
export function buildPlatformRoleSchema(): Schema {
|
|
81
|
+
const schema = new Schema(
|
|
82
|
+
platformRoleSchemaDefinition,
|
|
83
|
+
platformRoleSchemaOptions,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// Unique index on role code
|
|
87
|
+
schema.index({ code: 1 }, { unique: true });
|
|
88
|
+
|
|
89
|
+
// Lookup indexes
|
|
90
|
+
schema.index({ level: 1 });
|
|
91
|
+
schema.index({ tools: 1 });
|
|
92
|
+
schema.index({ isHtiOnly: 1 });
|
|
93
|
+
|
|
94
|
+
return schema;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ─── Type Inference ─────────────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
const _platformRoleSchema = buildPlatformRoleSchema();
|
|
100
|
+
export type PlatformRole = InferRawDocType<typeof _platformRoleSchema>;
|
package/src/types/index.ts
CHANGED
|
@@ -45,3 +45,17 @@ export type {
|
|
|
45
45
|
PersonDisplayCategoryValue,
|
|
46
46
|
PersonTypeValue,
|
|
47
47
|
} from "../constants/ic.js";
|
|
48
|
+
|
|
49
|
+
// Re-export platform authorization types
|
|
50
|
+
export type {
|
|
51
|
+
PermissionStateValue,
|
|
52
|
+
ShareViewValue,
|
|
53
|
+
PlatformToolValue,
|
|
54
|
+
RoleLevelValue,
|
|
55
|
+
FunctionStatusValue,
|
|
56
|
+
} from "../constants/platform-auth.js";
|
|
57
|
+
|
|
58
|
+
export type {
|
|
59
|
+
PlatformFunctionDef,
|
|
60
|
+
PlatformRoleDef,
|
|
61
|
+
} from "./platform-auth.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — Platform Authorization Types
|
|
3
|
+
*
|
|
4
|
+
* Plain interfaces for platform role and function documents.
|
|
5
|
+
* These represent the logical shape of the data — no Mongoose dependency.
|
|
6
|
+
* Consumers add `_id: string` or `_id: ObjectId` depending on context.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
PermissionStateValue,
|
|
11
|
+
PlatformToolValue,
|
|
12
|
+
RoleLevelValue,
|
|
13
|
+
ShareViewValue,
|
|
14
|
+
FunctionStatusValue,
|
|
15
|
+
} from "../constants/platform-auth.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A platform function definition (action that can be performed).
|
|
19
|
+
* Stored in the `platformFunctions` collection.
|
|
20
|
+
*/
|
|
21
|
+
export interface PlatformFunctionDef {
|
|
22
|
+
code: string;
|
|
23
|
+
label: string;
|
|
24
|
+
description: string;
|
|
25
|
+
category: string;
|
|
26
|
+
tools: PlatformToolValue[];
|
|
27
|
+
isAdminRelevant: boolean;
|
|
28
|
+
isUserRelevant: boolean;
|
|
29
|
+
isHtiOnly: boolean;
|
|
30
|
+
status: FunctionStatusValue;
|
|
31
|
+
sortOrder: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A platform role definition (permission bundle mapping functions).
|
|
36
|
+
* Stored in the `platformRoles` collection.
|
|
37
|
+
*/
|
|
38
|
+
export interface PlatformRoleDef {
|
|
39
|
+
code: string;
|
|
40
|
+
label: string;
|
|
41
|
+
description: string;
|
|
42
|
+
level: RoleLevelValue;
|
|
43
|
+
tools: PlatformToolValue[];
|
|
44
|
+
shareView: ShareViewValue | null;
|
|
45
|
+
trainingRequirements: string | null;
|
|
46
|
+
isHtiOnly: boolean;
|
|
47
|
+
functions: Record<string, PermissionStateValue>;
|
|
48
|
+
sortOrder: number;
|
|
49
|
+
}
|