@feedmepos/mf-hrm-portal 2.2.1-dev → 2.2.1-dev.3

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/{ApprovalCodeList-BgPrC2H1.js → ApprovalCodeList-rL8dh-6s.js} +5 -5
  2. package/dist/{AuditLogList-B9k56ux1.js → AuditLogList-NvISIfUq.js} +4 -4
  3. package/dist/ConditionBuilderForm.vue_vue_type_script_setup_true_lang-BJgpH-kw.js +438 -0
  4. package/dist/{EmployeeList-f05XEwMS.js → EmployeeList-C3VvVY6A.js} +6 -6
  5. package/dist/{GrantUserList-Db4_e87R.js → GrantUserList-DjZ4O0VB.js} +6 -6
  6. package/dist/{Main-DPmBwatV.js → Main-ByWrRV70.js} +8 -8
  7. package/dist/{Main-C83-6ZYQ.js → Main-DVTx58X9.js} +11 -11
  8. package/dist/{Main-CZoUt9IM.js → Main-LaAbAOfs.js} +5 -5
  9. package/dist/{PermissionSetList-CqcbzdXp.js → PermissionSetList-DD45SSY3.js} +19 -19
  10. package/dist/PortalPermissionEditor.vue_vue_type_script_setup_true_lang-yDPvNHiW.js +4169 -0
  11. package/dist/{PortalUserSearcher.vue_vue_type_style_index_0_scoped_827dfd60_lang-DVVSBIx2.js → PortalUserSearcher.vue_vue_type_style_index_0_scoped_827dfd60_lang-XHuHin8t.js} +1 -1
  12. package/dist/RoleList-BDxgwmAV.js +725 -0
  13. package/dist/{TeamMemberList-DuP1QWAS.js → TeamMemberList-DrLbMN34.js} +9 -9
  14. package/dist/{TimesheetList-D_Xq4ESR.js → TimesheetList-CdaxlO97.js} +7 -7
  15. package/dist/{TimesheetList.vue_vue_type_style_index_0_scoped_2c7a177a_lang-O2_M0Ktw.js → TimesheetList.vue_vue_type_style_index_0_scoped_2c7a177a_lang-ogjfztLs.js} +3 -3
  16. package/dist/{app-3bHRu-TD.js → app-B8eo04d6.js} +169 -158
  17. package/dist/app.js +1 -1
  18. package/dist/{approval-code-Q4666xp5.js → approval-code-jIjkeVEb.js} +1 -1
  19. package/dist/{dayjs.min-BjrK6J3b.js → dayjs.min-DZEHW2QB.js} +1 -1
  20. package/dist/{employee-Ck_DJyl9.js → employee-DX0CZF-B.js} +4 -4
  21. package/dist/{grant-user-CQZaTzVt.js → grant-user-SNiDV22U.js} +1 -1
  22. package/dist/{iteration-Bl07BT2c.js → iteration-yBS4dpFh.js} +1 -1
  23. package/dist/{lodash-CwAowwGK.js → lodash-344d5Ope.js} +1 -1
  24. package/dist/{restaurant-YOVMuuFY.js → restaurant-BTpBmfBV.js} +12 -14
  25. package/dist/role-BXBuBxs5.js +92 -0
  26. package/dist/rule-DWlFon04.js +1094 -0
  27. package/dist/src/composables/useReportPermissions.d.ts +1 -0
  28. package/dist/src/helpers/rule.d.ts +10 -1
  29. package/dist/src/stores/role.d.ts +6 -6
  30. package/dist/src/views/team/components/PortalConditionForm.vue.d.ts +44 -0
  31. package/dist/src/views/team/condition-builders/ConditionBuilderForm.vue.d.ts +39 -0
  32. package/dist/src/views/team/locales/index.d.ts +4 -0
  33. package/dist/tsconfig.app.tsbuildinfo +1 -1
  34. package/dist/{useAppStore-DNTlIeMv.js → useAppStore-DCwd8GWN.js} +1 -1
  35. package/dist/{useLoading-BH02lYns.js → useLoading-CXzTpIVv.js} +1 -1
  36. package/dist/useReportPermissions-C0exkIxU.js +71 -0
  37. package/package.json +2 -2
  38. package/dist/ConditionFormHost.vue_vue_type_script_setup_true_lang-BKxQPhjZ.js +0 -387
  39. package/dist/PortalPermissionEditor.vue_vue_type_script_setup_true_lang-DMS04nsd.js +0 -4122
  40. package/dist/RoleList-DsINcxpz.js +0 -685
  41. package/dist/role-Z1BT4HFT.js +0 -82
  42. package/dist/rule-DYmHm3nE.js +0 -1066
  43. package/dist/useReportPermissions-DCF1U1Us.js +0 -70
@@ -0,0 +1,1094 @@
1
+ import { s as W, c as Z, e as h } from "./iteration-yBS4dpFh.js";
2
+ import { h as O, P as V, e as _, b as F, n as j, d as q } from "./app-B8eo04d6.js";
3
+ import { s as ee } from "./utils-BZkjJbju.js";
4
+ import { g as b, b as v, q as x, u as te } from "./restaurant-BTpBmfBV.js";
5
+ import { defineStore as z, storeToRefs as K } from "pinia";
6
+ import { ref as S, computed as U } from "vue";
7
+ import { useCoreStore as X } from "@feedmepos/mf-common";
8
+ const L = [
9
+ {
10
+ label: "",
11
+ subject: "order",
12
+ actions: ["update"],
13
+ conditions: {
14
+ operation: "discount",
15
+ adjustment: {
16
+ $lte: 1
17
+ }
18
+ },
19
+ inverted: !1,
20
+ reason: null
21
+ },
22
+ {
23
+ label: "",
24
+ subject: "order",
25
+ actions: ["update"],
26
+ conditions: { operation: "changePrice" },
27
+ inverted: !1,
28
+ reason: null
29
+ },
30
+ {
31
+ label: "",
32
+ subject: "order",
33
+ actions: ["update"],
34
+ conditions: { operation: "void" },
35
+ inverted: !1,
36
+ reason: null
37
+ },
38
+ {
39
+ label: "",
40
+ subject: "order",
41
+ actions: ["update"],
42
+ conditions: { operation: "waiveServiceCharge" },
43
+ inverted: !1,
44
+ reason: null
45
+ },
46
+ {
47
+ label: "",
48
+ subject: "order",
49
+ actions: ["update"],
50
+ conditions: { operation: "payment" },
51
+ inverted: !1,
52
+ reason: null
53
+ },
54
+ {
55
+ label: "",
56
+ subject: "order",
57
+ actions: ["update"],
58
+ conditions: { operation: "claimDeposit" },
59
+ inverted: !1,
60
+ reason: null
61
+ },
62
+ {
63
+ label: "",
64
+ subject: "order",
65
+ actions: ["update"],
66
+ conditions: { operation: "resend" },
67
+ inverted: !1,
68
+ reason: null
69
+ },
70
+ {
71
+ label: "",
72
+ subject: "order",
73
+ actions: ["update"],
74
+ conditions: { operation: "changePaymentType" },
75
+ inverted: !1,
76
+ reason: null
77
+ },
78
+ {
79
+ label: "",
80
+ subject: "refund",
81
+ actions: ["create"],
82
+ conditions: null,
83
+ inverted: !1,
84
+ reason: null
85
+ },
86
+ {
87
+ label: "",
88
+ subject: "counter",
89
+ actions: ["manage"],
90
+ conditions: null,
91
+ inverted: !1,
92
+ reason: null
93
+ },
94
+ {
95
+ label: "",
96
+ subject: "mallIntegration",
97
+ actions: ["manage"],
98
+ conditions: null,
99
+ inverted: !1,
100
+ reason: null
101
+ },
102
+ {
103
+ label: "",
104
+ subject: "drawer",
105
+ actions: ["manage"],
106
+ conditions: null,
107
+ inverted: !1,
108
+ reason: null
109
+ },
110
+ {
111
+ label: "",
112
+ subject: "menu",
113
+ actions: ["manage"],
114
+ conditions: null,
115
+ inverted: !1,
116
+ reason: null
117
+ },
118
+ {
119
+ label: "",
120
+ subject: "inventory",
121
+ actions: ["manage"],
122
+ conditions: null,
123
+ inverted: !1,
124
+ reason: null
125
+ },
126
+ {
127
+ label: "",
128
+ subject: "deposit",
129
+ actions: ["manage"],
130
+ conditions: null,
131
+ inverted: !1,
132
+ reason: null
133
+ },
134
+ {
135
+ label: "",
136
+ subject: "delivery",
137
+ actions: ["manage"],
138
+ conditions: null,
139
+ inverted: !1,
140
+ reason: null
141
+ },
142
+ {
143
+ label: "",
144
+ subject: "counterRecord",
145
+ actions: ["manage"],
146
+ conditions: null,
147
+ inverted: !1,
148
+ reason: null
149
+ },
150
+ {
151
+ label: "",
152
+ subject: "restaurantSetting",
153
+ actions: ["manage"],
154
+ conditions: null,
155
+ inverted: !1,
156
+ reason: null
157
+ },
158
+ {
159
+ label: "",
160
+ subject: "display",
161
+ actions: ["manage"],
162
+ conditions: null,
163
+ inverted: !1,
164
+ reason: null
165
+ },
166
+ {
167
+ label: "",
168
+ subject: "printer",
169
+ actions: ["manage"],
170
+ conditions: null,
171
+ inverted: !1,
172
+ reason: null
173
+ },
174
+ {
175
+ label: "",
176
+ subject: "table",
177
+ actions: ["manage"],
178
+ conditions: null,
179
+ inverted: !1,
180
+ reason: null
181
+ },
182
+ {
183
+ label: "",
184
+ subject: "employee",
185
+ actions: ["manage"],
186
+ conditions: null,
187
+ inverted: !1,
188
+ reason: null
189
+ },
190
+ {
191
+ label: "",
192
+ subject: "system",
193
+ actions: ["manage"],
194
+ conditions: null,
195
+ inverted: !1,
196
+ reason: null
197
+ },
198
+ {
199
+ label: "",
200
+ subject: "tax",
201
+ actions: ["manage"],
202
+ conditions: null,
203
+ inverted: !1,
204
+ reason: null
205
+ },
206
+ {
207
+ label: "",
208
+ subject: "paymentType",
209
+ actions: ["manage"],
210
+ conditions: null,
211
+ inverted: !1,
212
+ reason: null
213
+ },
214
+ {
215
+ label: "",
216
+ subject: "faceId",
217
+ actions: ["manage"],
218
+ conditions: null,
219
+ inverted: !1,
220
+ reason: null
221
+ },
222
+ {
223
+ label: "",
224
+ subject: "report",
225
+ actions: ["read"],
226
+ conditions: { name: "closeup" },
227
+ inverted: !1,
228
+ reason: ""
229
+ },
230
+ {
231
+ label: "",
232
+ subject: "report",
233
+ actions: ["read"],
234
+ conditions: { name: "counter" },
235
+ inverted: !1,
236
+ reason: ""
237
+ },
238
+ {
239
+ label: "",
240
+ subject: "report",
241
+ actions: ["read"],
242
+ conditions: { name: "hourlySales" },
243
+ inverted: !1,
244
+ reason: ""
245
+ },
246
+ {
247
+ label: "",
248
+ subject: "report",
249
+ actions: ["read"],
250
+ conditions: { name: "dailySales" },
251
+ inverted: !1,
252
+ reason: ""
253
+ },
254
+ {
255
+ label: "",
256
+ subject: "report",
257
+ actions: ["read"],
258
+ conditions: { name: "productSales" },
259
+ inverted: !1,
260
+ reason: ""
261
+ },
262
+ {
263
+ label: "",
264
+ subject: "report",
265
+ actions: ["read"],
266
+ conditions: { name: "sourceProductSales" },
267
+ inverted: !1,
268
+ reason: ""
269
+ },
270
+ {
271
+ label: "",
272
+ subject: "report",
273
+ actions: ["read"],
274
+ conditions: { name: "userProductSales" },
275
+ inverted: !1,
276
+ reason: ""
277
+ },
278
+ {
279
+ label: "",
280
+ subject: "report",
281
+ actions: ["read"],
282
+ conditions: { name: "categorySales" },
283
+ inverted: !1,
284
+ reason: ""
285
+ },
286
+ {
287
+ label: "",
288
+ subject: "report",
289
+ actions: ["read"],
290
+ conditions: { name: "addonSales" },
291
+ inverted: !1,
292
+ reason: ""
293
+ },
294
+ {
295
+ label: "",
296
+ subject: "report",
297
+ actions: ["read"],
298
+ conditions: { name: "slotSales" },
299
+ inverted: !1,
300
+ reason: ""
301
+ },
302
+ {
303
+ label: "",
304
+ subject: "report",
305
+ actions: ["read"],
306
+ conditions: { name: "drawer" },
307
+ inverted: !1,
308
+ reason: ""
309
+ },
310
+ {
311
+ label: "",
312
+ subject: "report",
313
+ actions: ["read"],
314
+ conditions: { name: "discount" },
315
+ inverted: !1,
316
+ reason: ""
317
+ },
318
+ {
319
+ label: "",
320
+ subject: "report",
321
+ actions: ["read"],
322
+ conditions: { name: "refund" },
323
+ inverted: !1,
324
+ reason: ""
325
+ },
326
+ {
327
+ label: "",
328
+ subject: "report",
329
+ actions: ["read"],
330
+ conditions: { name: "void" },
331
+ inverted: !1,
332
+ reason: ""
333
+ },
334
+ {
335
+ label: "",
336
+ subject: "report",
337
+ actions: ["read"],
338
+ conditions: { name: "timesheet" },
339
+ inverted: !1,
340
+ reason: ""
341
+ },
342
+ {
343
+ label: "",
344
+ subject: "report",
345
+ actions: ["read"],
346
+ conditions: { name: "counterPayment" },
347
+ inverted: !1,
348
+ reason: ""
349
+ }
350
+ ], E = "/permission-sets", N = {
351
+ async read() {
352
+ return b(await v().get(E));
353
+ },
354
+ async create(e) {
355
+ return b(await v().post(E, e));
356
+ },
357
+ async update(e, s) {
358
+ return b(await v().put(`${E}/${e}`, s));
359
+ },
360
+ async delete(e) {
361
+ return b(await v().delete(`${E}/${e}`));
362
+ }
363
+ }, se = z("permissionSet", () => {
364
+ const { currentBusiness: e } = X(), s = S([]), o = S(!1), n = S(null);
365
+ async function r() {
366
+ var l;
367
+ const c = ((l = e.value) == null ? void 0 : l._id) ?? null;
368
+ if (n.value !== c)
369
+ try {
370
+ o.value = !0;
371
+ const d = await N.read();
372
+ s.value = u(d), n.value = c;
373
+ } finally {
374
+ o.value = !1;
375
+ }
376
+ }
377
+ async function t(c) {
378
+ const l = await N.create(c);
379
+ s.value = u([...s.value, l]);
380
+ }
381
+ async function i(c, l) {
382
+ const d = await N.update(c, l);
383
+ s.value = u(s.value.map((f) => f.id === c ? d : f));
384
+ }
385
+ async function a(c) {
386
+ await N.delete(c), s.value = u(s.value.filter((l) => l.id !== c));
387
+ }
388
+ function u(c) {
389
+ return c.sort((l, d) => l.name.localeCompare(d.name));
390
+ }
391
+ return {
392
+ permissionSets: s,
393
+ isLoading: o,
394
+ readPermissionSets: r,
395
+ createPermissionSet: t,
396
+ updatePermissionSet: i,
397
+ deletePermissionSet: a
398
+ };
399
+ }), ne = () => {
400
+ const e = se();
401
+ return {
402
+ ...e,
403
+ ...K(e)
404
+ };
405
+ };
406
+ function k(e) {
407
+ if (e) {
408
+ if (typeof e == "string") {
409
+ if (e === "{}") return;
410
+ try {
411
+ return JSON.parse(e);
412
+ } catch {
413
+ return;
414
+ }
415
+ }
416
+ if (typeof e == "object")
417
+ return Object.keys(e).length > 0 ? e : void 0;
418
+ }
419
+ }
420
+ function y(e) {
421
+ return e ? Object.values(e).every(
422
+ (s) => s !== null && typeof s == "object" && !Array.isArray(s) && Object.keys(s).length === 1 && Array.isArray(s.$in)
423
+ ) : !0;
424
+ }
425
+ function Q(e) {
426
+ const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), n = (r, t, i) => {
427
+ var a, u;
428
+ const c = k(t.conditions);
429
+ let l = `${t.subject}::${JSON.stringify([...t.actions].sort())}`;
430
+ y(c) || (l += `::${JSON.stringify(c)}`);
431
+ const d = r.get(l);
432
+ if (!d) {
433
+ r.set(l, { ...t, setNames: [i.name], setId: i._id });
434
+ return;
435
+ }
436
+ d.setNames.push(i.name);
437
+ const f = k(d.conditions);
438
+ if (!f || !c) {
439
+ d.conditions = void 0;
440
+ return;
441
+ }
442
+ for (const m in c)
443
+ (a = f[m]) != null && a.$in && (u = c[m]) != null && u.$in ? f[m].$in = Array.from(
444
+ /* @__PURE__ */ new Set([...f[m].$in, ...c[m].$in])
445
+ ) : f[m] || (f[m] = c[m]);
446
+ d.conditions = JSON.stringify(f);
447
+ };
448
+ for (const r of e)
449
+ for (const t of r.permissions)
450
+ n(t.inverted ? o : s, t, r);
451
+ return [...Array.from(s.values()), ...Array.from(o.values())];
452
+ }
453
+ function B(e, s) {
454
+ return `${e}::${[...s].sort().join(",")}`;
455
+ }
456
+ function G(e, s) {
457
+ const o = [...e], n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set();
458
+ for (const a of e) {
459
+ const u = O(a.subject);
460
+ n.add(B(u, a.actions)), a.inverted && a.actions.includes("manage") && r.add(`set_${u}`), !a.inverted && a.actions.includes("manage") && t.add(u);
461
+ }
462
+ const i = [...e];
463
+ for (; i.length > 0; ) {
464
+ const a = i.shift(), u = `set_${O(a.subject)}`, c = s[u];
465
+ if (!c || r.has(u) || !a.actions.includes("manage") || a.inverted) continue;
466
+ r.add(u);
467
+ const l = oe(a);
468
+ a.source && !a.source.trace && (a.source = { ...a.source, trace: l });
469
+ const d = [...l, `${c.name} (system)`];
470
+ for (const f of c.permissions ?? []) {
471
+ const m = O(f.subject), p = B(m, f.actions);
472
+ n.has(p) || t.has(m) || (n.add(p), o.push({
473
+ ...f,
474
+ // FdoPermissionRule.fields is string[] | null; RawRule expects string[] | undefined
475
+ fields: f.fields ?? void 0,
476
+ source: {
477
+ type: "systemPermissionSet",
478
+ permissionSetId: c.key,
479
+ permissionSetName: c.name,
480
+ trace: d
481
+ }
482
+ }));
483
+ }
484
+ for (const f of c.permissionSets ?? []) {
485
+ const m = O(f), p = B(m, ["manage"]), g = {
486
+ subject: m,
487
+ actions: ["manage"],
488
+ source: {
489
+ type: "systemPermissionSet",
490
+ permissionSetId: c.key,
491
+ permissionSetName: c.name,
492
+ trace: d
493
+ }
494
+ };
495
+ n.has(p) || (n.add(p), o.push(g)), i.push(g);
496
+ }
497
+ }
498
+ return [...o.filter((a) => !a.inverted), ...o.filter((a) => a.inverted)];
499
+ }
500
+ function oe(e) {
501
+ if (!e.source) return [];
502
+ const { type: s, trace: o, permissionSetName: n } = e.source;
503
+ if (o && o.length > 0) return o;
504
+ switch (s) {
505
+ case "permissionSet":
506
+ return n ? [n] : [];
507
+ case "custom":
508
+ return ["custom"];
509
+ default:
510
+ return [];
511
+ }
512
+ }
513
+ function H(e, s, o = /* @__PURE__ */ new Set()) {
514
+ var r;
515
+ const n = [];
516
+ for (const t of e) {
517
+ if (o.has(t)) continue;
518
+ o.add(t);
519
+ const i = s.find((a) => a.id === t);
520
+ i && (n.push(i), (r = i.permissionSetIds) != null && r.length && n.push(...H(i.permissionSetIds, s, o)));
521
+ }
522
+ return n;
523
+ }
524
+ function Ie(e) {
525
+ const s = Q(e).map(
526
+ ({ setNames: r, setId: t, ...i }) => i
527
+ ), o = s.filter((r) => !r.inverted), n = s.filter((r) => r.inverted);
528
+ return M(o, n);
529
+ }
530
+ function Ae(e, s, o) {
531
+ const n = /* @__PURE__ */ new Map();
532
+ return e.forEach(
533
+ ({ name: r, permissions: t }) => t.forEach(({ conditions: i, actions: a }) => {
534
+ var c, l;
535
+ const u = JSON.parse(i || "{}");
536
+ (c = u[s]) != null && c.$in ? (l = u[s]) == null || l.$in.forEach(
537
+ (d) => (n.get(d) ?? n.set(d, /* @__PURE__ */ new Set()).get(d)).add(r)
538
+ ) : a[0] === "manage" && o.forEach((d) => {
539
+ (n.get(d) ?? n.set(d, /* @__PURE__ */ new Set()).get(d)).add(r);
540
+ });
541
+ })
542
+ ), [...n].map(([r, t]) => ({
543
+ id: r,
544
+ setNames: [...t]
545
+ }));
546
+ }
547
+ function Oe(e, s) {
548
+ const o = (a, u) => {
549
+ const c = { ...a }, l = JSON.parse(c.conditions || "{}");
550
+ if (u)
551
+ if (u.length > 0) {
552
+ const d = Object.keys(l)[0];
553
+ l[d].$in = u;
554
+ } else
555
+ delete c.conditions;
556
+ return {
557
+ ...c,
558
+ inverted: !0,
559
+ ...c.conditions && { conditions: JSON.stringify(l) }
560
+ };
561
+ }, n = new Map(e.map((a) => [a.subject, a])), r = new Map(s.map((a) => [a.subject, a])), t = [], i = /* @__PURE__ */ new Set([...n.keys(), ...r.keys()]);
562
+ for (const a of i) {
563
+ const u = n.get(a), c = r.get(a);
564
+ if (u && c) {
565
+ if (u.conditions && c.conditions) {
566
+ const l = JSON.parse(u.conditions), d = JSON.parse(c.conditions);
567
+ if (!y(l) || !y(d)) {
568
+ JSON.stringify(l) !== JSON.stringify(d) && t.push(c);
569
+ continue;
570
+ }
571
+ const f = Object.keys(l)[0], m = l[f].$in.filter(
572
+ (g) => !d[f].$in.includes(g)
573
+ );
574
+ m.length > 0 && t.push(o(u, m)), d[f].$in.filter(
575
+ (g) => !l[f].$in.includes(g)
576
+ ).length > 0 && t.push(c);
577
+ } else if (!u.conditions && c.conditions)
578
+ t.push(c);
579
+ else if (u.conditions && !c.conditions)
580
+ y(JSON.parse(u.conditions)) || t.push(c);
581
+ else if (!u.conditions && !c.conditions) {
582
+ const l = new Set(u.actions), d = new Set(c.actions), f = c.actions.some((p) => !l.has(p)), m = u.actions.filter((p) => !d.has(p));
583
+ if (f) {
584
+ const p = c.actions.filter((g) => !l.has(g));
585
+ t.push({
586
+ ...c,
587
+ actions: p
588
+ });
589
+ }
590
+ m.length > 0 && t.push({
591
+ ...u,
592
+ actions: m,
593
+ inverted: !0
594
+ });
595
+ }
596
+ continue;
597
+ }
598
+ if (u) {
599
+ t.push(
600
+ o(
601
+ u,
602
+ // If base has conditions, set diffIds to empty array, disallow all access to collection
603
+ // otherwise, invert directly
604
+ u.conditions && []
605
+ )
606
+ );
607
+ continue;
608
+ }
609
+ c && t.push(c);
610
+ }
611
+ return t;
612
+ }
613
+ function _e(e) {
614
+ const s = G(
615
+ e,
616
+ V
617
+ ), o = new Set(
618
+ s.filter((r) => {
619
+ var t;
620
+ return ((t = r.source) == null ? void 0 : t.type) === "systemPermissionSet" && !r.inverted;
621
+ }).map((r) => r.subject)
622
+ ), n = new Set(
623
+ s.filter(
624
+ (r) => {
625
+ var t;
626
+ return ((t = r.source) == null ? void 0 : t.type) === "systemPermissionSet" && !r.inverted && r.actions.includes("manage");
627
+ }
628
+ ).map((r) => r.subject)
629
+ );
630
+ return e.filter((r) => r.inverted ? !(o.has(r.subject) && !n.has(r.subject)) : !o.has(r.subject));
631
+ }
632
+ const re = "business::report::";
633
+ function Ee(e, s) {
634
+ const o = [], n = e.filter((r) => {
635
+ const t = r.subject;
636
+ return !t.startsWith(re) || s.has(t) ? !0 : (o.push(t), !1);
637
+ });
638
+ return o.length > 0 && console.warn("[filterStalePermissions] dropped stale report permissions:", o), n;
639
+ }
640
+ const ie = "business::report::reports::", ae = _.Subject.Business.report_reports_allDefaultReports, ce = _.Subject.Business.report_reports_allCustomReports;
641
+ function ue(e, s) {
642
+ return e.conditions ? !!s.conditions && e.conditions === s.conditions : !s.conditions;
643
+ }
644
+ function Ne(e, s) {
645
+ const o = e.find(
646
+ (i) => !i.inverted && i.subject === ae
647
+ ), n = e.find(
648
+ (i) => !i.inverted && i.subject === ce
649
+ );
650
+ if (!o && !n) return e;
651
+ const r = o ? new Set(o.actions) : null, t = n ? new Set(n.actions) : null;
652
+ return e.reduce((i, a) => {
653
+ if (a.inverted)
654
+ return i.push(a), i;
655
+ const u = a.subject;
656
+ if (!u.startsWith(ie))
657
+ return i.push(a), i;
658
+ const c = s.has(u), l = c ? r : t, d = c ? o : n;
659
+ if (!l || !d || !ue(d, a))
660
+ return i.push(a), i;
661
+ if (l.has("manage")) return i;
662
+ const f = a.actions;
663
+ if (f.includes("manage"))
664
+ return i.push(a), i;
665
+ const m = new Set(f);
666
+ for (const p of l)
667
+ m.delete(p);
668
+ return m.size === 0 || i.push({ ...a, actions: Array.from(m) }), i;
669
+ }, []);
670
+ }
671
+ function M(e, s) {
672
+ var n, r;
673
+ const o = new Map(e.map((t) => [t.subject, t]));
674
+ for (const t of s) {
675
+ if (t.inverted) {
676
+ const a = o.get(t.subject);
677
+ if (t.conditions) {
678
+ if (a != null && a.conditions) {
679
+ const u = JSON.parse(a.conditions), c = JSON.parse(t.conditions);
680
+ if (!y(u) || !y(c)) {
681
+ o.delete(t.subject);
682
+ continue;
683
+ }
684
+ const l = Object.keys(c)[0], d = ((n = c[l]) == null ? void 0 : n.$in) ?? [], m = (((r = u[l]) == null ? void 0 : r.$in) ?? []).filter((p) => !d.includes(p));
685
+ m.length > 0 ? o.set(t.subject, {
686
+ ...a,
687
+ conditions: JSON.stringify({ [l]: { $in: m } })
688
+ }) : o.delete(t.subject);
689
+ } else
690
+ o.delete(t.subject);
691
+ continue;
692
+ }
693
+ if (a) {
694
+ const u = new Set(t.actions), c = a.actions.filter((l) => !u.has(l));
695
+ c.length > 0 ? o.set(t.subject, { ...a, actions: c }) : o.delete(t.subject);
696
+ continue;
697
+ }
698
+ continue;
699
+ }
700
+ if (t.conditions) {
701
+ o.set(t.subject, t);
702
+ continue;
703
+ }
704
+ const i = o.get(t.subject);
705
+ if (i != null && i.conditions && !y(JSON.parse(i.conditions))) {
706
+ o.set(t.subject, t);
707
+ continue;
708
+ }
709
+ if (i) {
710
+ const a = [
711
+ .../* @__PURE__ */ new Set([
712
+ ...i.actions,
713
+ ...t.actions
714
+ ])
715
+ ];
716
+ o.set(t.subject, { ...i, actions: a });
717
+ } else
718
+ o.set(t.subject, t);
719
+ }
720
+ return Array.from(o.values());
721
+ }
722
+ function le(e, s) {
723
+ const o = M(e, s), n = new Set(e.map((t) => t.subject)), r = s.filter(
724
+ (t) => t.inverted && !n.has(t.subject)
725
+ );
726
+ return [...o, ...r];
727
+ }
728
+ const P = "/permission-assignments", R = {
729
+ async readAll() {
730
+ return b(await v().get(P));
731
+ },
732
+ async readByUserId(e) {
733
+ return b(await v().get(`${P}/user/${e}`));
734
+ },
735
+ async readById(e) {
736
+ return b(await v().get(`${P}/${e}`));
737
+ },
738
+ async create(e) {
739
+ return b(await v().post(P, e));
740
+ },
741
+ async update(e, s) {
742
+ return b(await v().put(`${P}/${e}`, s));
743
+ },
744
+ async delete(e) {
745
+ return b(await v().delete(`${P}/${e}`));
746
+ },
747
+ async addReportManagePermission(e, s) {
748
+ return b(
749
+ await v().post("/my-permissions/report-manage", { permissionKey: e, label: s })
750
+ );
751
+ }
752
+ }, de = z("permissionAssignment", () => {
753
+ const e = S([]);
754
+ async function s() {
755
+ const a = await R.readAll();
756
+ e.value = a;
757
+ }
758
+ async function o(a) {
759
+ return await R.readByUserId(a);
760
+ }
761
+ async function n(a) {
762
+ const u = await R.create(a);
763
+ e.value = [...e.value, u];
764
+ }
765
+ async function r(a, u) {
766
+ const c = await R.update(a, u);
767
+ e.value = e.value.map((l) => l.id === a ? c : l);
768
+ }
769
+ async function t(a) {
770
+ await R.delete(a), e.value = e.value.filter((u) => u.id !== a);
771
+ }
772
+ function i(a) {
773
+ return e.value.find((u) => u.userId === a);
774
+ }
775
+ return {
776
+ permissionAssignments: e,
777
+ readPermissionAssignments: s,
778
+ readPermissionAssignmentByUserId: o,
779
+ createPermissionAssignment: n,
780
+ updatePermissionAssignment: r,
781
+ deletePermissionAssignment: t,
782
+ getPermissionAssignmentByUserId: i
783
+ };
784
+ }), fe = () => {
785
+ const e = de();
786
+ return {
787
+ ...e,
788
+ ...K(e)
789
+ };
790
+ }, me = {
791
+ async fetchReportPermissions(e, s) {
792
+ const o = s ? { lang: s } : {};
793
+ return b(
794
+ await x().get(`/report-query/hrm/${e}/reports`, { params: o })
795
+ );
796
+ },
797
+ async fetchReportPermissionsForPortal(e, s) {
798
+ const o = s ? { isSupportPos: !1, lang: s } : { isSupportPos: !1 };
799
+ return b(
800
+ await x().get(`/report-query/hrm/${e}/reports`, { params: o })
801
+ );
802
+ }
803
+ }, C = S([]), T = S(!1), $ = S(!1), I = S(null), D = S(null), J = S(!1);
804
+ function pe() {
805
+ const e = X();
806
+ async function s() {
807
+ var t;
808
+ const n = (t = e.currentBusiness.value) == null ? void 0 : t.id;
809
+ if (!n) return;
810
+ const r = localStorage.getItem("locale");
811
+ if (I.value !== n && (C.value = [], T.value = !1, $.value = !1, I.value = n, J.value = !1), !(T.value && D.value === r)) {
812
+ if ($.value) {
813
+ J.value = !0;
814
+ return;
815
+ }
816
+ $.value = !0;
817
+ try {
818
+ const i = await me.fetchReportPermissionsForPortal(n, r);
819
+ if (I.value !== n) return;
820
+ C.value = i, T.value = !0, D.value = r;
821
+ } catch (i) {
822
+ if (I.value !== n) return;
823
+ console.warn("Failed to fetch custom report permissions:", i), C.value = [];
824
+ } finally {
825
+ I.value === n && ($.value = !1, J.value && (J.value = !1, await s()));
826
+ }
827
+ }
828
+ }
829
+ const o = U(() => C.value.map(
830
+ (n) => n.isDefault ? {
831
+ label: n.name,
832
+ subject: `business::report::reports::${n.permissionKey}`,
833
+ actions: [j.manage, j.read, j.create],
834
+ category: F.reports
835
+ } : {
836
+ label: n.name,
837
+ subject: `business::report::reports::${n.permissionKey}`,
838
+ actions: [
839
+ j.manage,
840
+ j.read,
841
+ j.create,
842
+ j.update,
843
+ j.delete
844
+ ],
845
+ category: F.customReports
846
+ }
847
+ ));
848
+ return {
849
+ fetchCustomReportPermissions: s,
850
+ customReportPermissions: o,
851
+ isLoading: U(() => $.value),
852
+ isLoaded: U(() => T.value)
853
+ };
854
+ }
855
+ function A(e) {
856
+ const s = ne(), o = fe(), n = te().restaurants, { customReportPermissions: r } = pe(), t = o.getPermissionAssignmentByUserId(e.id), i = H(
857
+ (t == null ? void 0 : t.permissionSetIds) ?? [],
858
+ s.permissionSets.value
859
+ ), a = Q(i).map(
860
+ ({ setNames: p, ...g }) => g
861
+ ), u = t == null ? void 0 : t.customPermissions, c = u ?? e.permissions.map((p) => ({
862
+ ...p,
863
+ subject: O(p.subject)
864
+ })), l = M(a, c), d = G(
865
+ le(a, c),
866
+ V
867
+ ).filter((p) => !p.inverted), f = ve(d), m = f ?? n.value.map((p) => p._id);
868
+ return {
869
+ doc: e,
870
+ id: e.id,
871
+ name: e.name && e.name !== e.email && e.name !== e.phoneNumber ? e.name : "-",
872
+ phoneNumber: e.phoneNumber,
873
+ email: e.email,
874
+ restaurants: W(
875
+ m.map((p) => {
876
+ var g;
877
+ return ((g = n.value.find((Y) => Y._id === p)) == null ? void 0 : g.profile.name) ?? "";
878
+ })
879
+ ),
880
+ managableRestaurantIds: f,
881
+ permissionLabels: Se(d, r.value),
882
+ permissions: l
883
+ };
884
+ }
885
+ const be = Object.freeze(
886
+ Object.values(q)
887
+ ), Ce = {
888
+ async readTeamMembers() {
889
+ return b(
890
+ await v().get("/portal-users")
891
+ ).map(A);
892
+ },
893
+ async readTeamMembersPage(e) {
894
+ var o, n, r;
895
+ const s = b(
896
+ await v().get("/portal-users/paged", {
897
+ params: {
898
+ limit: e.limit,
899
+ offset: e.offset,
900
+ search: e.search,
901
+ restaurantIds: (o = e.restaurantIds) != null && o.length ? e.restaurantIds : void 0,
902
+ permissionSubjects: (n = e.permissionSubjects) != null && n.length ? e.permissionSubjects : void 0,
903
+ permissionSetIds: (r = e.permissionSetIds) != null && r.length ? e.permissionSetIds : void 0
904
+ }
905
+ })
906
+ );
907
+ return {
908
+ items: s.items.map(A),
909
+ total: s.total
910
+ };
911
+ },
912
+ async readTeamMember(e) {
913
+ return A(
914
+ b(await v().get(`/portal-users/${e}`))
915
+ );
916
+ },
917
+ async createTeamMember(e) {
918
+ return A(
919
+ b(await v().post("/portal-users", e))
920
+ );
921
+ },
922
+ async updateTeamMember(e, s) {
923
+ return A(
924
+ b(await v().put(`/portal-users/${e}`, s))
925
+ );
926
+ },
927
+ async deleteTeamMember(e) {
928
+ return b(await v().delete(`/portal-users/${e}`));
929
+ },
930
+ async readTeamMemberPosUserIds() {
931
+ return b(await v().get("/portal-users")).map((s) => s.posUserId);
932
+ }
933
+ };
934
+ function Te(e, s, o) {
935
+ if (e.some((i) => i.subject === "all")) return "All";
936
+ const n = (o ?? L).filter(
937
+ (i) => i.subject === s
938
+ ), r = new Set(n.map((i) => w(i).value)), t = e.filter((i) => i.subject === s).filter((i) => r.has(w(i).value));
939
+ return t.length === n.length ? "All" : t.length === 0 ? "-" : `${t.length} permission allow`;
940
+ }
941
+ function w(e) {
942
+ const s = Z(e), o = s.subject;
943
+ return {
944
+ ...s,
945
+ get conditions() {
946
+ if (typeof s.conditions != "string") return s.conditions;
947
+ try {
948
+ return JSON.parse(s.conditions);
949
+ } catch {
950
+ return;
951
+ }
952
+ },
953
+ get isDiscountOperation() {
954
+ var n;
955
+ return o === h.F_RULE_SUBJECT.enum.order && ((n = this.conditions) == null ? void 0 : n.operation) === h.F_RULE_ORDER_OPERATION.enum.discount;
956
+ },
957
+ get isOrderOperation() {
958
+ return o === h.F_RULE_SUBJECT.enum.order;
959
+ },
960
+ get isReportPermission() {
961
+ return o === h.F_RULE_SUBJECT.enum.report;
962
+ },
963
+ get formatted() {
964
+ var r, t;
965
+ const n = (i) => i.endsWith("_") ? i.slice(0, i.length - 1) : i;
966
+ return this.isOrderOperation ? n(((r = this.conditions) == null ? void 0 : r.operation) ?? "") : this.isReportPermission ? n(((t = this.conditions) == null ? void 0 : t.name) ?? "") : o.toString();
967
+ },
968
+ get label() {
969
+ return s.label || ee(this.formatted);
970
+ },
971
+ get value() {
972
+ var n, r;
973
+ return this.isOrderOperation ? `${o}:${(n = this.conditions) == null ? void 0 : n.operation}` : this.isReportPermission ? `${o}:${(r = this.conditions) == null ? void 0 : r.name}` : o.toString();
974
+ }
975
+ };
976
+ }
977
+ function Je(e) {
978
+ var n, r;
979
+ const s = e.map((t) => w(t)).find((t) => t.isDiscountOperation);
980
+ if (!s) return 100;
981
+ const o = Number((r = (n = s.conditions) == null ? void 0 : n.adjustment) == null ? void 0 : r.$lte);
982
+ return Number.isFinite(o) ? parseInt((o * 100).toFixed(0)) : 0;
983
+ }
984
+ function ve(e) {
985
+ const s = e.find(
986
+ (o) => o.subject === _.Subject.Restaurant.restaurant
987
+ );
988
+ return s ? s.conditions ? JSON.parse(s.conditions).restaurantId.$in : null : [];
989
+ }
990
+ function Ue(e) {
991
+ return (e == null ? void 0 : e.some((s) => s.subject === "all")) ?? !1;
992
+ }
993
+ function Be(e) {
994
+ const s = e.find((o) => o.subject === _.Subject.Business.role);
995
+ return s ? s.conditions ? JSON.parse(s.conditions).roleId.$in : null : [];
996
+ }
997
+ function Le(e) {
998
+ const s = w(e);
999
+ if (!s.isReportPermission) return;
1000
+ const { name: o, ...n } = s.conditions ?? {};
1001
+ return Object.keys(n).length > 0 ? n : void 0;
1002
+ }
1003
+ function Me(e, s, o) {
1004
+ return e.flatMap((n) => {
1005
+ const r = ge(n);
1006
+ if (!r) return [];
1007
+ const t = r.isReportPermission ? o == null ? void 0 : o.get(n) : void 0;
1008
+ return [
1009
+ {
1010
+ subject: r.subject,
1011
+ actions: r.actions,
1012
+ conditions: {
1013
+ ...r.conditions,
1014
+ ...t ?? {},
1015
+ adjustment: r.isDiscountOperation ? { $lte: parseFloat((s / 100).toFixed(2)) } : void 0
1016
+ }
1017
+ }
1018
+ ];
1019
+ });
1020
+ }
1021
+ function ge(e) {
1022
+ const s = e.indexOf(":"), o = s === -1 ? e : e.slice(0, s), n = s === -1 ? void 0 : e.slice(s + 1);
1023
+ if (s !== -1 && !n) return;
1024
+ let r;
1025
+ return n ? (r = L.find((t) => {
1026
+ if (t.subject !== o) return !1;
1027
+ const i = typeof t.conditions == "string" ? JSON.parse(t.conditions) : t.conditions;
1028
+ return [i == null ? void 0 : i.operation, i == null ? void 0 : i.name].includes(n);
1029
+ }), !r && o === h.F_RULE_SUBJECT.enum.report && (r = {
1030
+ label: "",
1031
+ subject: h.F_RULE_SUBJECT.enum.report,
1032
+ actions: ["read"],
1033
+ conditions: { name: n },
1034
+ inverted: !1,
1035
+ reason: ""
1036
+ })) : r = L.find((t) => t.subject === o), r ? w(r) : void 0;
1037
+ }
1038
+ function Fe(e, s) {
1039
+ const o = { values: [], passthrough: [], dropped: [] };
1040
+ for (const n of e) {
1041
+ const r = n == null ? void 0 : n.actions;
1042
+ if (typeof (n == null ? void 0 : n.subject) != "string" || n.subject.trim().length === 0 || !Array.isArray(r) || r.length === 0 || r.some((u) => typeof u != "string" || u.trim().length === 0)) {
1043
+ o.dropped.push(n);
1044
+ continue;
1045
+ }
1046
+ const t = w(n).value, i = `${h.F_RULE_SUBJECT.enum.report}:`, a = t.startsWith(i) ? t.slice(i.length) : "";
1047
+ s.has(t) || a && a !== "undefined" ? o.values.push(t) : o.passthrough.push(n);
1048
+ }
1049
+ return o;
1050
+ }
1051
+ function Se(e, s = []) {
1052
+ return W(
1053
+ e.reduce((o, n) => {
1054
+ const r = be.find(
1055
+ (t) => t.subject === n.subject && n.actions.includes("manage")
1056
+ ) || s.find((t) => t.subject === n.subject);
1057
+ if (r) {
1058
+ const t = r.subject === _.Subject.Business.inventory_stock ? "Warehouse Management" : r.label;
1059
+ o.push(t);
1060
+ }
1061
+ return o;
1062
+ }, [])
1063
+ );
1064
+ }
1065
+ export {
1066
+ G as N,
1067
+ Q as P,
1068
+ me as R,
1069
+ Le as a,
1070
+ Te as b,
1071
+ H as c,
1072
+ le as d,
1073
+ L as e,
1074
+ Me as f,
1075
+ Je as g,
1076
+ Ue as h,
1077
+ pe as i,
1078
+ re as j,
1079
+ Be as k,
1080
+ ve as l,
1081
+ Ie as m,
1082
+ _e as n,
1083
+ Oe as o,
1084
+ be as p,
1085
+ Ee as q,
1086
+ w as r,
1087
+ Fe as s,
1088
+ Ce as t,
1089
+ ne as u,
1090
+ Ne as v,
1091
+ fe as w,
1092
+ Se as x,
1093
+ Ae as y
1094
+ };