@openinc/parse-server-opendash 4.14.0 → 4.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -242,6 +242,15 @@ exports.customoptions = {
242
242
  default: "false",
243
243
  description: "Enable Parse Classes and Cloud Code for the open.SERVICE v2 plugin.",
244
244
  },
245
+ FEATURE_RAG: {
246
+ env: "OPENINC_PARSE_FEATURE_RAG",
247
+ type: "boolean",
248
+ required: false,
249
+ secret: false,
250
+ public: true,
251
+ default: "false",
252
+ description: "Enable Parse Classes for the RAG plugin (OD3_RAG_*). The knowledge base itself runs in open-rag-chat; these classes hold its sources, prompts and requests.",
253
+ },
245
254
  FORCE_SCHEMA: {
246
255
  env: "OPENINC_PARSE_FORCE_SCHEMA",
247
256
  type: "boolean",
@@ -1,2 +1,2 @@
1
- export type Feature = "CORE" | "MONITORING" | "BDE" | "GTFS" | "KNOWLEDGE" | "MAINTENANCE" | "DOCUMENTATION" | "MIAAS" | "SERVICE";
1
+ export type Feature = "CORE" | "MONITORING" | "BDE" | "GTFS" | "KNOWLEDGE" | "MAINTENANCE" | "DOCUMENTATION" | "MIAAS" | "SERVICE" | "RAG";
2
2
  export declare function isFeatureEnabled(feature: Feature): boolean;
@@ -23,6 +23,8 @@ function isFeatureEnabled(feature) {
23
23
  return config.getBoolean("FEATURE_MIAAS");
24
24
  case "SERVICE":
25
25
  return config.getBoolean("FEATURE_SERVICE");
26
+ case "RAG":
27
+ return config.getBoolean("FEATURE_RAG");
26
28
  default:
27
29
  return false;
28
30
  }
@@ -6,23 +6,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = init;
7
7
  const node_1 = __importDefault(require("parse/node"));
8
8
  const index_js_1 = require("../features/schema/index.js");
9
+ const index_js_2 = require("../features/permissions/index.js");
10
+ const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
9
11
  const ticketSortKeys_js_1 = require("../helper/ticketSortKeys.js");
10
- const index_js_2 = require("../types/index.js");
12
+ const index_js_3 = require("../types/index.js");
11
13
  async function init() {
12
14
  // Soft delete: tickets and meter readings point at equipment, so it is
13
15
  // archived rather than destroyed. Archived rows are hidden from every client
14
16
  // query (see hideSoftDeleted()).
15
- (0, index_js_1.hideSoftDeleted)(index_js_2.Service_Equipment, { field: "deleted" });
16
- (0, index_js_1.beforeSaveHook)(index_js_2.Service_Equipment, async (request) => {
17
- const { object, original, user } = request;
17
+ (0, index_js_1.hideSoftDeleted)(index_js_3.Service_Equipment, { field: "deleted" });
18
+ (0, index_js_1.beforeSaveHook)(index_js_3.Service_Equipment, async (request) => {
19
+ const { object, original } = request;
20
+ // Creating master data is a capability: there is no record yet whose ACL
21
+ // could be asked, and the class-level `create` is open to everybody. Editing
22
+ // an existing row needs no check here — `defaultAclHandler` below grants
23
+ // write to od-admin, the tenant admins and the creator, and nobody else.
24
+ //
25
+ // Passes `request`, not `request.user`: `defaultHandler` refetches the user
26
+ // in place, which drops its session token — so both checks run before it.
27
+ if (!original && !(0, index_js_1.isMigrationMode)()) {
28
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "create equipment");
29
+ }
30
+ // Archiving sets `deleted` — an update, which the ACL grants to the creator
31
+ // as well. Retiring equipment is a decision of its own, and restoring it is
32
+ // the same decision. Compared against `original`, so a client that resends
33
+ // the unchanged flag is not refused.
34
+ if (original &&
35
+ !(0, index_js_1.isMigrationMode)() &&
36
+ Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
37
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive equipment");
38
+ }
18
39
  await (0, index_js_1.defaultHandler)(request);
19
40
  await (0, index_js_1.defaultAclHandler)(request);
20
- // TODO
21
41
  });
22
42
  // Tickets sort by `equipmentSortKey`, derived from this label when the ticket
23
43
  // was saved. A rename therefore has to reach them, or they keep sorting under
24
44
  // the old name until each one is touched by hand.
25
- (0, index_js_1.afterSaveHook)(index_js_2.Service_Equipment, async ({ object, original }) => {
45
+ (0, index_js_1.afterSaveHook)(index_js_3.Service_Equipment, async ({ object, original }) => {
26
46
  if (!(0, ticketSortKeys_js_1.derivedValueChanged)(object, original, "label"))
27
47
  return;
28
48
  await (0, ticketSortKeys_js_1.pushSortKeyToTickets)("equipment", "equipmentSortKey", object, (0, ticketSortKeys_js_1.sortKeyOf)(object.get("label")));
@@ -30,8 +50,15 @@ async function init() {
30
50
  // Block deleting equipment that is still referenced where it matters:
31
51
  // active tickets, and meter readings (whose `equipment` pointer is required,
32
52
  // so orphaning it would break them).
33
- (0, index_js_1.beforeDeleteHook)(index_js_2.Service_Equipment, async ({ object }) => {
34
- const tickets = await new node_1.default.Query(index_js_2.Service_Ticket)
53
+ (0, index_js_1.beforeDeleteHook)(index_js_3.Service_Equipment, async (request) => {
54
+ const { object } = request;
55
+ // Parse has no delete right of its own — an ACL `write` grant covers update
56
+ // *and* delete, so anyone allowed to edit equipment could otherwise remove
57
+ // it. Hiding the button in the UI does not change that.
58
+ if (!(0, index_js_1.isMigrationMode)()) {
59
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "delete equipment");
60
+ }
61
+ const tickets = await new node_1.default.Query(index_js_3.Service_Ticket)
35
62
  .equalTo("equipment", object)
36
63
  .notEqualTo("deleted", true)
37
64
  .count({ useMasterKey: true });
@@ -2,23 +2,52 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
4
  const index_js_1 = require("../features/schema/index.js");
5
+ const index_js_2 = require("../features/permissions/index.js");
6
+ const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
5
7
  const ticketSortKeys_js_1 = require("../helper/ticketSortKeys.js");
6
- const index_js_2 = require("../types/index.js");
8
+ const index_js_3 = require("../types/index.js");
7
9
  async function init() {
8
10
  // Soft delete: tickets point at their project and draw their number from its
9
11
  // counter, so a project is archived rather than destroyed. Archived rows are
10
12
  // hidden from every client query (see hideSoftDeleted()).
11
- (0, index_js_1.hideSoftDeleted)(index_js_2.Service_Project, { field: "deleted" });
12
- (0, index_js_1.beforeSaveHook)(index_js_2.Service_Project, async (request) => {
13
- const { object, original, user } = request;
13
+ (0, index_js_1.hideSoftDeleted)(index_js_3.Service_Project, { field: "deleted" });
14
+ (0, index_js_1.beforeSaveHook)(index_js_3.Service_Project, async (request) => {
15
+ const { object, original } = request;
16
+ // Creating master data is a capability: there is no record yet whose ACL
17
+ // could be asked, and the class-level `create` is open to everybody. Editing
18
+ // an existing row needs no check here — `defaultAclHandler` below grants
19
+ // write to od-admin, the tenant admins and the creator, and nobody else.
20
+ //
21
+ // Both checks run before `defaultHandler`, which refetches the user in place
22
+ // and drops its session token.
23
+ if (!original && !(0, index_js_1.isMigrationMode)()) {
24
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "create a project");
25
+ }
26
+ // Archiving sets `deleted` — an update, which the ACL grants to the creator
27
+ // as well. Retiring a project is a decision of its own, and restoring it is
28
+ // the same decision. Compared against `original`, so a client that resends
29
+ // the unchanged flag is not refused.
30
+ if (original &&
31
+ !(0, index_js_1.isMigrationMode)() &&
32
+ Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
33
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive a project");
34
+ }
14
35
  await (0, index_js_1.defaultHandler)(request);
15
36
  await (0, index_js_1.defaultAclHandler)(request);
16
- // TODO
37
+ });
38
+ // Parse has no delete right of its own — an ACL `write` grant covers update
39
+ // *and* delete, so anyone allowed to edit a project could otherwise remove it.
40
+ // Tickets point at their project and draw their number from its counter, so
41
+ // the frontend archives instead; this covers the direct API call.
42
+ (0, index_js_1.beforeDeleteHook)(index_js_3.Service_Project, async (request) => {
43
+ if ((0, index_js_1.isMigrationMode)())
44
+ return;
45
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "delete a project");
17
46
  });
18
47
  // Tickets sort by `projectSortKey`, derived from this label when the ticket was
19
48
  // saved. A rename therefore has to reach them, or they keep sorting under the
20
49
  // old name until each one is touched by hand.
21
- (0, index_js_1.afterSaveHook)(index_js_2.Service_Project, async ({ object, original }) => {
50
+ (0, index_js_1.afterSaveHook)(index_js_3.Service_Project, async ({ object, original }) => {
22
51
  if (!(0, ticketSortKeys_js_1.derivedValueChanged)(object, original, "label"))
23
52
  return;
24
53
  await (0, ticketSortKeys_js_1.pushSortKeyToTickets)("project", "projectSortKey", object, (0, ticketSortKeys_js_1.sortKeyOf)(object.get("label")));
@@ -6,31 +6,59 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = init;
7
7
  const node_1 = __importDefault(require("parse/node"));
8
8
  const index_js_1 = require("../features/schema/index.js");
9
+ const index_js_2 = require("../features/permissions/index.js");
10
+ const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
9
11
  const ticketSortKeys_js_1 = require("../helper/ticketSortKeys.js");
10
- const index_js_2 = require("../types/index.js");
12
+ const index_js_3 = require("../types/index.js");
11
13
  async function init() {
12
14
  // Soft delete: every ticket carries a required `status` pointer, so a status
13
15
  // is archived rather than destroyed. Archived rows are hidden from every
14
16
  // client query (see hideSoftDeleted() for the escape hatches).
15
- (0, index_js_1.hideSoftDeleted)(index_js_2.Service_Status, { field: "deleted" });
16
- (0, index_js_1.beforeSaveHook)(index_js_2.Service_Status, async (request) => {
17
- const { object, original, user } = request;
17
+ (0, index_js_1.hideSoftDeleted)(index_js_3.Service_Status, { field: "deleted" });
18
+ (0, index_js_1.beforeSaveHook)(index_js_3.Service_Status, async (request) => {
19
+ const { object, original } = request;
20
+ // A status is the ticket workflow: adding one changes what every ticket in
21
+ // the tenant can be set to. There is no record yet whose ACL could be asked
22
+ // and the class-level `create` is open to everybody, so it is a capability.
23
+ // Editing an existing row needs no check here — `defaultAclHandler` below
24
+ // grants write to od-admin, the tenant admins and the creator, nobody else.
25
+ //
26
+ // Both checks run before `defaultHandler`, which refetches the user in place
27
+ // and drops its session token.
28
+ if (!original && !(0, index_js_1.isMigrationMode)()) {
29
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "create a ticket status");
30
+ }
31
+ // Archiving sets `deleted` — an update, which the ACL grants to the creator
32
+ // as well. Retiring a status takes it out of every picker in the tenant, and
33
+ // restoring it is the same decision. Compared against `original`, so a
34
+ // client that resends the unchanged flag is not refused.
35
+ if (original &&
36
+ !(0, index_js_1.isMigrationMode)() &&
37
+ Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
38
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive a ticket status");
39
+ }
18
40
  await (0, index_js_1.defaultHandler)(request);
19
41
  await (0, index_js_1.defaultAclHandler)(request);
20
- // TODO
21
42
  });
22
43
  // A ticket sorts by its status's workflow position, which it carries as
23
44
  // `statusOrder`. Reordering the workflow has to reach the tickets, or the
24
45
  // board keeps the old order until each one is touched by hand.
25
- (0, index_js_1.afterSaveHook)(index_js_2.Service_Status, async ({ object, original }) => {
46
+ (0, index_js_1.afterSaveHook)(index_js_3.Service_Status, async ({ object, original }) => {
26
47
  if (!(0, ticketSortKeys_js_1.derivedValueChanged)(object, original, "order"))
27
48
  return;
28
49
  await (0, ticketSortKeys_js_1.pushSortKeyToTickets)("status", "statusOrder", object, object.get("order"));
29
50
  });
30
51
  // A ticket's `status` is required — deleting a status still in use by active
31
52
  // tickets would orphan that required pointer. Block it.
32
- (0, index_js_1.beforeDeleteHook)(index_js_2.Service_Status, async ({ object }) => {
33
- const inUse = await new node_1.default.Query(index_js_2.Service_Ticket)
53
+ (0, index_js_1.beforeDeleteHook)(index_js_3.Service_Status, async (request) => {
54
+ const { object } = request;
55
+ // Parse has no delete right of its own — an ACL `write` grant covers update
56
+ // *and* delete, so anyone allowed to edit a status could otherwise remove
57
+ // it. Hiding the button in the UI does not change that.
58
+ if (!(0, index_js_1.isMigrationMode)()) {
59
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "delete a ticket status");
60
+ }
61
+ const inUse = await new node_1.default.Query(index_js_3.Service_Ticket)
34
62
  .equalTo("status", object)
35
63
  .notEqualTo("deleted", true)
36
64
  .count({ useMasterKey: true });
@@ -6,19 +6,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = init;
7
7
  const node_1 = __importDefault(require("parse/node"));
8
8
  const index_js_1 = require("../features/schema/index.js");
9
- const index_js_2 = require("../types/index.js");
9
+ const index_js_2 = require("../features/permissions/index.js");
10
+ const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
11
+ const index_js_3 = require("../types/index.js");
10
12
  async function init() {
11
13
  // Soft delete: tags are stored in the ancestor closures on tickets and
12
14
  // equipment, so they are archived rather than destroyed. Archived rows are
13
15
  // hidden from every client query (see hideSoftDeleted()).
14
- (0, index_js_1.hideSoftDeleted)(index_js_2.Service_Tag, { field: "deleted" });
15
- (0, index_js_1.beforeSaveHook)(index_js_2.Service_Tag, async (request) => {
16
- const { object, original, user } = request;
16
+ (0, index_js_1.hideSoftDeleted)(index_js_3.Service_Tag, { field: "deleted" });
17
+ (0, index_js_1.beforeSaveHook)(index_js_3.Service_Tag, async (request) => {
18
+ const { object, original } = request;
19
+ // Creating a tag is a capability: there is no record yet whose ACL could be
20
+ // asked, and the class-level `create` is open to everybody. Editing an
21
+ // existing tag needs no check here — `defaultAclHandler` below grants write
22
+ // to od-admin, the tenant admins and the creator, and nobody else.
23
+ //
24
+ // Runs before `defaultHandler`, which refetches the user in place and drops
25
+ // its session token.
26
+ if (!original && !(0, index_js_1.isMigrationMode)()) {
27
+ await requireTagCreate(request);
28
+ }
29
+ // Archiving sets `deleted` — an update, which the ACL grants to the creator
30
+ // as well. A tag is referenced by the ancestor closures on tickets and
31
+ // equipment, so retiring one reaches further than the row itself: that is
32
+ // master-data administration, not the narrow inline-create capability.
33
+ if (original &&
34
+ !(0, index_js_1.isMigrationMode)() &&
35
+ Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
36
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive a tag");
37
+ }
17
38
  await (0, index_js_1.defaultHandler)(request);
18
39
  await (0, index_js_1.defaultAclHandler)(request);
19
- // TODO
20
40
  });
21
- (0, index_js_1.afterSaveHook)(index_js_2.Service_Tag, async ({ object, original }) => {
41
+ (0, index_js_1.afterSaveHook)(index_js_3.Service_Tag, async ({ object, original }) => {
22
42
  // Entities store the *ancestor closure* of the tags picked on them (see the
23
43
  // tags README). Re-parenting a tag changes those ancestors, so every
24
44
  // equipment/ticket whose closure includes this tag must be rebuilt.
@@ -36,17 +56,45 @@ async function init() {
36
56
  return; // parent unchanged → closures fine
37
57
  await reconcileClosures(object, oldParentId, newParentId);
38
58
  });
39
- (0, index_js_1.afterDeleteHook)(index_js_2.Service_Tag, async (request) => {
59
+ // Parse has no delete right of its own — an ACL `write` grant covers update
60
+ // *and* delete, so anyone allowed to edit a tag could otherwise remove it.
61
+ // Destroying a tag strips it from every ticket and equipment that references
62
+ // it (see `cleanupTagArrays`), which is master-data administration.
63
+ (0, index_js_1.beforeDeleteHook)(index_js_3.Service_Tag, async (request) => {
64
+ if ((0, index_js_1.isMigrationMode)())
65
+ return;
66
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "delete a tag");
67
+ });
68
+ (0, index_js_1.afterDeleteHook)(index_js_3.Service_Tag, async (request) => {
40
69
  const { object } = request;
41
70
  await cleanupTagArrays(object);
42
71
  });
43
72
  }
73
+ /**
74
+ * Either capability may create a tag.
75
+ *
76
+ * `tag_create` is the narrow one the ticket editor's tag picker offers inline —
77
+ * someone who may file a ticket often needs a tag that does not exist yet,
78
+ * without being trusted with the whole master-data administration.
79
+ * `masterdata_manage` is that whole administration, and a superset of it: the
80
+ * Tag admin page's create button is gated on it, so a holder of it must be able
81
+ * to create a tag without also being granted the narrow key.
82
+ */
83
+ async function requireTagCreate(request) {
84
+ if (request.master)
85
+ return;
86
+ if (request.sessionToken &&
87
+ (await (0, index_js_2.hasPermission)(request.sessionToken, Permissions_js_1.Permissions.SERVICE.tag_create))) {
88
+ return;
89
+ }
90
+ await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "create a tag");
91
+ }
44
92
  async function cleanupTagArrays(object) {
45
93
  if (!object.id)
46
94
  return;
47
95
  await Promise.all([
48
- removeTagFromClass(index_js_2.Service_Ticket, object),
49
- removeTagFromClass(index_js_2.Service_Equipment, object),
96
+ removeTagFromClass(index_js_3.Service_Ticket, object),
97
+ removeTagFromClass(index_js_3.Service_Equipment, object),
50
98
  ]);
51
99
  }
52
100
  async function removeTagFromClass(ObjectClass, tag) {
@@ -133,7 +181,7 @@ async function reconcileClosures(tag, oldParentId, newParentId) {
133
181
  if (!tagId)
134
182
  return;
135
183
  const tenant = tag.tenant;
136
- const query = new node_1.default.Query(index_js_2.Service_Tag);
184
+ const query = new node_1.default.Query(index_js_3.Service_Tag);
137
185
  if (tenant)
138
186
  query.equalTo("tenant", tenant);
139
187
  const allTags = await query.findAll({ useMasterKey: true });
@@ -146,8 +194,8 @@ async function reconcileClosures(tag, oldParentId, newParentId) {
146
194
  const oldParents = new Map(newParents);
147
195
  oldParents.set(tagId, oldParentId);
148
196
  await Promise.all([
149
- reconcileClass(index_js_2.Service_Ticket, tagId, tenant, oldParents, newParents),
150
- reconcileClass(index_js_2.Service_Equipment, tagId, tenant, oldParents, newParents),
197
+ reconcileClass(index_js_3.Service_Ticket, tagId, tenant, oldParents, newParents),
198
+ reconcileClass(index_js_3.Service_Equipment, tagId, tenant, oldParents, newParents),
151
199
  ]);
152
200
  }
153
201
  async function reconcileClass(ObjectClass, tagId, tenant, oldParents, newParents) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.14.0",
3
+ "version": "4.15.0",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@12.8.1",
6
6
  "keywords": [
@@ -46,6 +46,11 @@
46
46
  "type": "String",
47
47
  "required": false
48
48
  },
49
+ "parseClassRelated": {
50
+ "type": "Array",
51
+ "required": false,
52
+ "defaultValue": []
53
+ },
49
54
  "text": {
50
55
  "type": "String",
51
56
  "required": false