law-common 14.1.2-beta.0 → 14.1.2-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.
@@ -1,6 +1,39 @@
1
1
  import { FlowConfig } from "./flow-config.type";
2
2
  import { ExpenseTypeActionEnum } from "../../entities";
3
3
  import { ExpenseTypeStatusEnum } from "../enums/expense_type_status_enum";
4
+ import { PermissionGroupEnum } from "../enums/permission_group_enum";
4
5
  export interface IExpenseTypeFlowConfigContextData {
5
6
  }
7
+ export declare const ACTION_MAP: {
8
+ CREATE: {
9
+ reachableStatues: readonly [ExpenseTypeStatusEnum.APPROVED];
10
+ permissions: string[];
11
+ group: PermissionGroupEnum.CREATE;
12
+ };
13
+ UPDATE: {
14
+ reachableStatues: readonly [ExpenseTypeStatusEnum.APPROVED];
15
+ permissions: string[];
16
+ group: PermissionGroupEnum.UPDATE;
17
+ };
18
+ DELETE: {
19
+ reachableStatues: readonly [ExpenseTypeStatusEnum.DELETED];
20
+ permissions: string[];
21
+ group: PermissionGroupEnum.DELETE;
22
+ };
23
+ DEACTIVATE: {
24
+ reachableStatues: readonly [ExpenseTypeStatusEnum.DEACTIVATED];
25
+ permissions: string[];
26
+ group: PermissionGroupEnum.UPDATE;
27
+ };
28
+ ACTIVATE: {
29
+ reachableStatues: readonly [ExpenseTypeStatusEnum.APPROVED];
30
+ permissions: string[];
31
+ group: PermissionGroupEnum.UPDATE;
32
+ };
33
+ RESTORE: {
34
+ reachableStatues: readonly [ExpenseTypeStatusEnum.APPROVED];
35
+ permissions: string[];
36
+ group: PermissionGroupEnum.UPDATE;
37
+ };
38
+ };
6
39
  export declare const expenseTypeFlowConfig: FlowConfig<ExpenseTypeStatusEnum, ExpenseTypeActionEnum, IExpenseTypeFlowConfigContextData>;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.expenseTypeFlowConfig = void 0;
3
+ exports.expenseTypeFlowConfig = exports.ACTION_MAP = void 0;
4
4
  const base_flow_config_factory_1 = require("./base-flow-config.factory");
5
5
  const entities_1 = require("../../entities");
6
- const permission_group_enum_1 = require("../enums/permission_group_enum");
7
6
  const expense_type_status_enum_1 = require("../enums/expense_type_status_enum");
7
+ const permission_group_enum_1 = require("../enums/permission_group_enum");
8
8
  const EXPENSE_TYPE_CREATE_PERMISSION = ["EXPENSE_TYPE_CREATE"];
9
9
  const EXPENSE_TYPE_UPDATE_PERMISSION = ["EXPENSE_TYPE_UPDATE"];
10
10
  const EXPENSE_TYPE_DELETE_PERMISSION = ["EXPENSE_TYPE_DELETE"];
@@ -19,7 +19,7 @@ const EXPENSE_TYPE_RESTORE_PERMISSION = ["EXPENSE_TYPE_RESTORE"];
19
19
  // classifies them — matching work_from_home_flow.config.ts, where RECALL is likewise UPDATE. They are
20
20
  // still distinguished by `permissions` above, which `getNextStatus` consults per action, so grouping
21
21
  // them together narrows nothing.
22
- const ACTION_MAP = {
22
+ exports.ACTION_MAP = {
23
23
  [entities_1.ExpenseTypeActionEnum.CREATE]: {
24
24
  reachableStatues: [expense_type_status_enum_1.ExpenseTypeStatusEnum.APPROVED],
25
25
  permissions: EXPENSE_TYPE_CREATE_PERMISSION,
@@ -51,7 +51,7 @@ const ACTION_MAP = {
51
51
  group: permission_group_enum_1.PermissionGroupEnum.UPDATE,
52
52
  },
53
53
  };
54
- const { createActionConfig } = (0, base_flow_config_factory_1.createFlowConfigFactory)()(ACTION_MAP);
54
+ const { createActionConfig } = (0, base_flow_config_factory_1.createFlowConfigFactory)()(exports.ACTION_MAP);
55
55
  // APPROVED status transitions
56
56
  const transitionApprovedStatusUpdateAction = createActionConfig(entities_1.ExpenseTypeActionEnum.UPDATE, expense_type_status_enum_1.ExpenseTypeStatusEnum.APPROVED);
57
57
  const transitionApprovedStatusDeleteAction = createActionConfig(entities_1.ExpenseTypeActionEnum.DELETE, expense_type_status_enum_1.ExpenseTypeStatusEnum.DELETED);
@@ -0,0 +1,110 @@
1
+ import { PermissionGroupEnum } from "../../enums/permission_group_enum";
2
+ /**
3
+ * Registry of per-entity action maps used by {@link FlowConfigUtils}.
4
+ *
5
+ * Every entry maps an {@link EntityEnum} member to the `ACTION_MAP` declared by that entity's
6
+ * flow config file. To register another entity: add `export` to its `ACTION_MAP` (only
7
+ * expense_type and work_from_home export it today) and add one line here. The typing below
8
+ * follows automatically:
9
+ * the entity parameter and the action parameter of `getPermissionGroupByAction` both derive
10
+ * from this object, so a new entity's actions are accepted only with that entity, and rejected
11
+ * for every other entity — including actions from a different enum that share the same string
12
+ * value (string enums are nominal across types).
13
+ */
14
+ export declare const enumToActionMap: {
15
+ expense_type: {
16
+ CREATE: {
17
+ reachableStatues: readonly [import("../..").ExpenseTypeStatusEnum.APPROVED];
18
+ permissions: string[];
19
+ group: PermissionGroupEnum.CREATE;
20
+ };
21
+ UPDATE: {
22
+ reachableStatues: readonly [import("../..").ExpenseTypeStatusEnum.APPROVED];
23
+ permissions: string[];
24
+ group: PermissionGroupEnum.UPDATE;
25
+ };
26
+ DELETE: {
27
+ reachableStatues: readonly [import("../..").ExpenseTypeStatusEnum.DELETED];
28
+ permissions: string[];
29
+ group: PermissionGroupEnum.DELETE;
30
+ };
31
+ DEACTIVATE: {
32
+ reachableStatues: readonly [import("../..").ExpenseTypeStatusEnum.DEACTIVATED];
33
+ permissions: string[];
34
+ group: PermissionGroupEnum.UPDATE;
35
+ };
36
+ ACTIVATE: {
37
+ reachableStatues: readonly [import("../..").ExpenseTypeStatusEnum.APPROVED];
38
+ permissions: string[];
39
+ group: PermissionGroupEnum.UPDATE;
40
+ };
41
+ RESTORE: {
42
+ reachableStatues: readonly [import("../..").ExpenseTypeStatusEnum.APPROVED];
43
+ permissions: string[];
44
+ group: PermissionGroupEnum.UPDATE;
45
+ };
46
+ };
47
+ work_from_home: {
48
+ CREATE: {
49
+ reachableStatues: readonly [import("../..").WorkFromHomeStatusEnum.CREATE_APPROVAL_PENDING];
50
+ permissions: string[];
51
+ group: PermissionGroupEnum.CREATE;
52
+ };
53
+ UPDATE: {
54
+ reachableStatues: readonly [import("../..").WorkFromHomeStatusEnum.CREATE_APPROVAL_PENDING, import("../..").WorkFromHomeStatusEnum.UPDATE_APPROVAL_PENDING];
55
+ permissions: string[];
56
+ group: PermissionGroupEnum.UPDATE;
57
+ };
58
+ DELETE: {
59
+ reachableStatues: readonly [import("../..").WorkFromHomeStatusEnum.DELETE_APPROVAL_PENDING, import("../..").WorkFromHomeStatusEnum.DELETED];
60
+ permissions: string[];
61
+ group: PermissionGroupEnum.DELETE;
62
+ };
63
+ APPROVE: {
64
+ reachableStatues: readonly [import("../..").WorkFromHomeStatusEnum.APPROVED, import("../..").WorkFromHomeStatusEnum.DELETED];
65
+ permissions: string[];
66
+ group: PermissionGroupEnum.APPROVAL_FLOW;
67
+ };
68
+ REJECT: {
69
+ reachableStatues: readonly [import("../..").WorkFromHomeStatusEnum.REJECTED, import("../..").WorkFromHomeStatusEnum.RESOLVED_REJECTED];
70
+ permissions: string[];
71
+ group: PermissionGroupEnum.APPROVAL_FLOW;
72
+ };
73
+ RECALL: {
74
+ reachableStatues: readonly [import("../..").WorkFromHomeStatusEnum.APPROVED];
75
+ permissions: string[];
76
+ group: PermissionGroupEnum.UPDATE;
77
+ };
78
+ };
79
+ };
80
+ export type EnumToActionMap = typeof enumToActionMap;
81
+ /**
82
+ * The action enum registered for entity `E`, derived from {@link enumToActionMap}.
83
+ *
84
+ * Written as a mapped-union lookup rather than `EnumToActionMap[E]`'s `keyof`: both forms are
85
+ * strict at the call site, but only this form also lets the method body index the erased map
86
+ * below without a cast (TS cannot resolve `EnumToActionMap[E][keyof EnumToActionMap[E]]` —
87
+ * property access on that deferred generic indexed access is a compile error). Intersected
88
+ * with `string` because a bare `keyof` constraint includes `symbol`, which forbids template
89
+ * interpolation of the parameter (TS2731); map keys are always string enum members, so the
90
+ * intersection loses nothing.
91
+ */
92
+ export type RegisteredActions<E extends keyof EnumToActionMap> = {
93
+ [K in keyof EnumToActionMap]: keyof EnumToActionMap[K] & string;
94
+ }[E];
95
+ export declare class FlowConfigUtils {
96
+ /**
97
+ * Resolves the permission group an entity's action is authorised under, from the entity's
98
+ * flat `ACTION_MAP`. Needs only the entity and the action — deliberately no status and no
99
+ * existing entity — so callers building search filters can use it before any entity data
100
+ * has been fetched.
101
+ *
102
+ * @param entity Registered entity; entities missing from `enumToActionMap` are compile errors.
103
+ * @param action That entity's action enum member. A member of another entity's action enum
104
+ * is a compile error even when its string value coincides.
105
+ * @throws AppBadRequestException (400) when the registry, the action, or the action's
106
+ * `group` annotation is missing. Never falls back to a default group: defaulting
107
+ * would authorise the action under another action's permissions.
108
+ */
109
+ static getPermissionGroupByAction<E extends keyof EnumToActionMap>(entity: E, action: RegisteredActions<E>): PermissionGroupEnum;
110
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowConfigUtils = exports.enumToActionMap = void 0;
4
+ const error_key_enum_1 = require("../../../enums/error.key.enum");
5
+ const exceptions_1 = require("../../../exceptions");
6
+ const entity_utils_interface_1 = require("../../interface/entity.utils.interface");
7
+ const expense_type_flow_config_1 = require("../expense_type_flow.config");
8
+ const work_from_home_flow_config_1 = require("../work_from_home_flow.config");
9
+ /**
10
+ * Registry of per-entity action maps used by {@link FlowConfigUtils}.
11
+ *
12
+ * Every entry maps an {@link EntityEnum} member to the `ACTION_MAP` declared by that entity's
13
+ * flow config file. To register another entity: add `export` to its `ACTION_MAP` (only
14
+ * expense_type and work_from_home export it today) and add one line here. The typing below
15
+ * follows automatically:
16
+ * the entity parameter and the action parameter of `getPermissionGroupByAction` both derive
17
+ * from this object, so a new entity's actions are accepted only with that entity, and rejected
18
+ * for every other entity — including actions from a different enum that share the same string
19
+ * value (string enums are nominal across types).
20
+ */
21
+ exports.enumToActionMap = {
22
+ [entity_utils_interface_1.EntityEnum.EXPENSE_TYPE]: expense_type_flow_config_1.ACTION_MAP,
23
+ [entity_utils_interface_1.EntityEnum.WORK_FROM_HOME]: work_from_home_flow_config_1.ACTION_MAP,
24
+ };
25
+ class FlowConfigUtils {
26
+ /**
27
+ * Resolves the permission group an entity's action is authorised under, from the entity's
28
+ * flat `ACTION_MAP`. Needs only the entity and the action — deliberately no status and no
29
+ * existing entity — so callers building search filters can use it before any entity data
30
+ * has been fetched.
31
+ *
32
+ * @param entity Registered entity; entities missing from `enumToActionMap` are compile errors.
33
+ * @param action That entity's action enum member. A member of another entity's action enum
34
+ * is a compile error even when its string value coincides.
35
+ * @throws AppBadRequestException (400) when the registry, the action, or the action's
36
+ * `group` annotation is missing. Never falls back to a default group: defaulting
37
+ * would authorise the action under another action's permissions.
38
+ */
39
+ static getPermissionGroupByAction(entity, action) {
40
+ const actionMap = exports.enumToActionMap[entity];
41
+ if (!actionMap) {
42
+ throw new exceptions_1.AppBadRequestException({
43
+ key: error_key_enum_1.ErrorKeyEnum.ENTITY,
44
+ message: [`No action map registered for entity '${entity}'`],
45
+ });
46
+ }
47
+ const actionConfig = actionMap[action];
48
+ if (!actionConfig) {
49
+ throw new exceptions_1.AppBadRequestException({
50
+ key: error_key_enum_1.ErrorKeyEnum.ACTION,
51
+ message: [`Action '${action}' is not configured for entity '${entity}'`],
52
+ });
53
+ }
54
+ const group = actionConfig.group;
55
+ if (!group) {
56
+ throw new exceptions_1.AppBadRequestException({
57
+ key: error_key_enum_1.ErrorKeyEnum.PERMISSION_GROUP,
58
+ message: [`Action '${action}' for entity '${entity}' has no permission group configured. Declare it in the entity's flow config.`],
59
+ });
60
+ }
61
+ return group;
62
+ }
63
+ }
64
+ exports.FlowConfigUtils = FlowConfigUtils;
@@ -1,6 +1,39 @@
1
1
  import { FlowConfig } from "./flow-config.type";
2
+ import { PermissionGroupEnum } from "../enums/permission_group_enum";
2
3
  import { WorkFromHomeActionEnum } from "../enums/work_from_home_action_enum";
3
4
  import { WorkFromHomeStatusEnum } from "../enums/work_from_home_status_enum";
4
5
  export interface IWorkFromHomeFlowConfigContextData {
5
6
  }
7
+ export declare const ACTION_MAP: {
8
+ CREATE: {
9
+ reachableStatues: readonly [WorkFromHomeStatusEnum.CREATE_APPROVAL_PENDING];
10
+ permissions: string[];
11
+ group: PermissionGroupEnum.CREATE;
12
+ };
13
+ UPDATE: {
14
+ reachableStatues: readonly [WorkFromHomeStatusEnum.CREATE_APPROVAL_PENDING, WorkFromHomeStatusEnum.UPDATE_APPROVAL_PENDING];
15
+ permissions: string[];
16
+ group: PermissionGroupEnum.UPDATE;
17
+ };
18
+ DELETE: {
19
+ reachableStatues: readonly [WorkFromHomeStatusEnum.DELETE_APPROVAL_PENDING, WorkFromHomeStatusEnum.DELETED];
20
+ permissions: string[];
21
+ group: PermissionGroupEnum.DELETE;
22
+ };
23
+ APPROVE: {
24
+ reachableStatues: readonly [WorkFromHomeStatusEnum.APPROVED, WorkFromHomeStatusEnum.DELETED];
25
+ permissions: string[];
26
+ group: PermissionGroupEnum.APPROVAL_FLOW;
27
+ };
28
+ REJECT: {
29
+ reachableStatues: readonly [WorkFromHomeStatusEnum.REJECTED, WorkFromHomeStatusEnum.RESOLVED_REJECTED];
30
+ permissions: string[];
31
+ group: PermissionGroupEnum.APPROVAL_FLOW;
32
+ };
33
+ RECALL: {
34
+ reachableStatues: readonly [WorkFromHomeStatusEnum.APPROVED];
35
+ permissions: string[];
36
+ group: PermissionGroupEnum.UPDATE;
37
+ };
38
+ };
6
39
  export declare const workFromHomeFlowConfig: FlowConfig<WorkFromHomeStatusEnum, WorkFromHomeActionEnum, IWorkFromHomeFlowConfigContextData>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.workFromHomeFlowConfig = void 0;
3
+ exports.workFromHomeFlowConfig = exports.ACTION_MAP = void 0;
4
4
  const base_flow_config_factory_1 = require("./base-flow-config.factory");
5
5
  const permission_group_enum_1 = require("../enums/permission_group_enum");
6
6
  const work_from_home_action_enum_1 = require("../enums/work_from_home_action_enum");
@@ -14,7 +14,8 @@ const WORK_FROM_HOME_REJECT_PERMISSION = ["WORK_FROM_HOME_APPROVER_ORG"];
14
14
  const WORK_FROM_HOME_RECALL_PERMISSION = ["WORK_FROM_HOME_UPDATE_ORG", "WORK_FROM_HOME_UPDATE_SELF"];
15
15
  // Every action declares its group. work_from_home_bulk_update.transaction.ts refuses to
16
16
  // default an absent group, so all six must be annotated for any transition to keep working.
17
- const ACTION_MAP = {
17
+ // Exported for the FlowConfigUtils.getPermissionGroupByAction registry.
18
+ exports.ACTION_MAP = {
18
19
  [work_from_home_action_enum_1.WorkFromHomeActionEnum.CREATE]: {
19
20
  reachableStatues: [work_from_home_status_enum_1.WorkFromHomeStatusEnum.CREATE_APPROVAL_PENDING],
20
21
  permissions: WORK_FROM_HOME_CREATE_PERMISSION,
@@ -50,7 +51,7 @@ const ACTION_MAP = {
50
51
  group: permission_group_enum_1.PermissionGroupEnum.UPDATE,
51
52
  },
52
53
  };
53
- const { createActionConfig } = (0, base_flow_config_factory_1.createFlowConfigFactory)()(ACTION_MAP);
54
+ const { createActionConfig } = (0, base_flow_config_factory_1.createFlowConfigFactory)()(exports.ACTION_MAP);
54
55
  // CREATE_APPROVAL_PENDING status transitions
55
56
  const transitionCreateApprovalPendingStatusUpdateAction = createActionConfig(work_from_home_action_enum_1.WorkFromHomeActionEnum.UPDATE, work_from_home_status_enum_1.WorkFromHomeStatusEnum.CREATE_APPROVAL_PENDING);
56
57
  const transitionCreateApprovalPendingStatusDeleteAction = createActionConfig(work_from_home_action_enum_1.WorkFromHomeActionEnum.DELETE, work_from_home_status_enum_1.WorkFromHomeStatusEnum.DELETED);
@@ -403,10 +403,11 @@ export * from "./interface/field-constraint/rate_field_constraints.interface";
403
403
  export * from "./model/rate.entity.model";
404
404
  export * from "./enums/work_from_home_action_enum";
405
405
  export * from "./enums/work_from_home_status_enum";
406
- export * from "./flow-configs/work_from_home_flow.config";
406
+ export { IWorkFromHomeFlowConfigContextData, ACTION_MAP as WORK_FROM_HOME_ACTION_MAP, workFromHomeFlowConfig } from "./flow-configs/work_from_home_flow.config";
407
407
  export * from "./interface/field-constraint/work_from_home_field_constraints.interface";
408
408
  export * from "./interface/work_from_home.entity.interface";
409
409
  export * from "./model/work_from_home.entity.model";
410
410
  export * from "./enums/user_gender_enum";
411
411
  export * from "./enums/user_role_enum";
412
412
  export * from "./enums/user_status_enum";
413
+ export * from "./flow-configs/utils/flow-config.utils";
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.workFromHomeFlowConfig = exports.WORK_FROM_HOME_ACTION_MAP = void 0;
17
18
  __exportStar(require("./enums/organization_action_enum"), exports);
18
19
  __exportStar(require("./enums/organization_status_enum"), exports);
19
20
  __exportStar(require("./flow-configs/organization_flow.config"), exports);
@@ -420,10 +421,13 @@ __exportStar(require("./interface/field-constraint/rate_field_constraints.interf
420
421
  __exportStar(require("./model/rate.entity.model"), exports);
421
422
  __exportStar(require("./enums/work_from_home_action_enum"), exports);
422
423
  __exportStar(require("./enums/work_from_home_status_enum"), exports);
423
- __exportStar(require("./flow-configs/work_from_home_flow.config"), exports);
424
+ var work_from_home_flow_config_1 = require("./flow-configs/work_from_home_flow.config");
425
+ Object.defineProperty(exports, "WORK_FROM_HOME_ACTION_MAP", { enumerable: true, get: function () { return work_from_home_flow_config_1.ACTION_MAP; } });
426
+ Object.defineProperty(exports, "workFromHomeFlowConfig", { enumerable: true, get: function () { return work_from_home_flow_config_1.workFromHomeFlowConfig; } });
424
427
  __exportStar(require("./interface/field-constraint/work_from_home_field_constraints.interface"), exports);
425
428
  __exportStar(require("./interface/work_from_home.entity.interface"), exports);
426
429
  __exportStar(require("./model/work_from_home.entity.model"), exports);
427
430
  __exportStar(require("./enums/user_gender_enum"), exports);
428
431
  __exportStar(require("./enums/user_role_enum"), exports);
429
432
  __exportStar(require("./enums/user_status_enum"), exports);
433
+ __exportStar(require("./flow-configs/utils/flow-config.utils"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "14.1.2-beta.0",
3
+ "version": "14.1.2-beta.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [