@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
@@ -1,1066 +0,0 @@
1
- import { s as W, c as Z, e as y } from "./iteration-Bl07BT2c.js";
2
- import { h as A, P as V, d as _, v as F, n as j, b as q } from "./app-3bHRu-TD.js";
3
- import { s as ee } from "./utils-BZkjJbju.js";
4
- import { g as b, b as v, q as k, u as ne } from "./restaurant-YOVMuuFY.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, n) {
358
- return b(await v().put(`${E}/${e}`, n));
359
- },
360
- async delete(e) {
361
- return b(await v().delete(`${E}/${e}`));
362
- }
363
- }, se = z("permissionSet", () => {
364
- const { currentBusiness: e } = X(), n = S([]), t = S(!1), o = S(null);
365
- async function i() {
366
- var l;
367
- const a = ((l = e.value) == null ? void 0 : l._id) ?? null;
368
- if (o.value !== a)
369
- try {
370
- t.value = !0;
371
- const d = await N.read();
372
- n.value = u(d), o.value = a;
373
- } finally {
374
- t.value = !1;
375
- }
376
- }
377
- async function s(a) {
378
- const l = await N.create(a);
379
- n.value = u([...n.value, l]);
380
- }
381
- async function c(a, l) {
382
- const d = await N.update(a, l);
383
- n.value = u(n.value.map((m) => m.id === a ? d : m));
384
- }
385
- async function r(a) {
386
- await N.delete(a), n.value = u(n.value.filter((l) => l.id !== a));
387
- }
388
- function u(a) {
389
- return a.sort((l, d) => l.name.localeCompare(d.name));
390
- }
391
- return {
392
- permissionSets: n,
393
- isLoading: t,
394
- readPermissionSets: i,
395
- createPermissionSet: s,
396
- updatePermissionSet: c,
397
- deletePermissionSet: r
398
- };
399
- }), te = () => {
400
- const e = se();
401
- return {
402
- ...e,
403
- ...K(e)
404
- };
405
- };
406
- function D(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 h(e) {
421
- return e ? Object.values(e).every(
422
- (n) => n !== null && typeof n == "object" && !Array.isArray(n) && Object.keys(n).length === 1 && Array.isArray(n.$in)
423
- ) : !0;
424
- }
425
- function Q(e) {
426
- const n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), o = (i, s, c) => {
427
- var r, u;
428
- const a = D(s.conditions);
429
- let l = `${s.subject}::${JSON.stringify([...s.actions].sort())}`;
430
- h(a) || (l += `::${JSON.stringify(a)}`);
431
- const d = i.get(l);
432
- if (!d) {
433
- i.set(l, { ...s, setNames: [c.name], setId: c._id });
434
- return;
435
- }
436
- d.setNames.push(c.name);
437
- const m = D(d.conditions);
438
- if (!m || !a) {
439
- d.conditions = void 0;
440
- return;
441
- }
442
- for (const f in a)
443
- (r = m[f]) != null && r.$in && (u = a[f]) != null && u.$in ? m[f].$in = Array.from(
444
- /* @__PURE__ */ new Set([...m[f].$in, ...a[f].$in])
445
- ) : m[f] || (m[f] = a[f]);
446
- d.conditions = JSON.stringify(m);
447
- };
448
- for (const i of e)
449
- for (const s of i.permissions)
450
- o(s.inverted ? t : n, s, i);
451
- return [...Array.from(n.values()), ...Array.from(t.values())];
452
- }
453
- function B(e, n) {
454
- return `${e}::${[...n].sort().join(",")}`;
455
- }
456
- function G(e, n) {
457
- const t = [...e], o = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
458
- for (const r of e) {
459
- const u = A(r.subject);
460
- o.add(B(u, r.actions)), r.inverted && r.actions.includes("manage") && i.add(`set_${u}`), !r.inverted && r.actions.includes("manage") && s.add(u);
461
- }
462
- const c = [...e];
463
- for (; c.length > 0; ) {
464
- const r = c.shift(), u = `set_${A(r.subject)}`, a = n[u];
465
- if (!a || i.has(u) || !r.actions.includes("manage") || r.inverted) continue;
466
- i.add(u);
467
- const l = oe(r);
468
- r.source && !r.source.trace && (r.source = { ...r.source, trace: l });
469
- const d = [...l, `${a.name} (system)`];
470
- for (const m of a.permissions ?? []) {
471
- const f = A(m.subject), p = B(f, m.actions);
472
- o.has(p) || s.has(f) || (o.add(p), t.push({
473
- ...m,
474
- // FdoPermissionRule.fields is string[] | null; RawRule expects string[] | undefined
475
- fields: m.fields ?? void 0,
476
- source: {
477
- type: "systemPermissionSet",
478
- permissionSetId: a.key,
479
- permissionSetName: a.name,
480
- trace: d
481
- }
482
- }));
483
- }
484
- for (const m of a.permissionSets ?? []) {
485
- const f = A(m), p = B(f, ["manage"]), g = {
486
- subject: f,
487
- actions: ["manage"],
488
- source: {
489
- type: "systemPermissionSet",
490
- permissionSetId: a.key,
491
- permissionSetName: a.name,
492
- trace: d
493
- }
494
- };
495
- o.has(p) || (o.add(p), t.push(g)), c.push(g);
496
- }
497
- }
498
- return [...t.filter((r) => !r.inverted), ...t.filter((r) => r.inverted)];
499
- }
500
- function oe(e) {
501
- if (!e.source) return [];
502
- const { type: n, trace: t, permissionSetName: o } = e.source;
503
- if (t && t.length > 0) return t;
504
- switch (n) {
505
- case "permissionSet":
506
- return o ? [o] : [];
507
- case "custom":
508
- return ["custom"];
509
- default:
510
- return [];
511
- }
512
- }
513
- function H(e, n, t = /* @__PURE__ */ new Set()) {
514
- var i;
515
- const o = [];
516
- for (const s of e) {
517
- if (t.has(s)) continue;
518
- t.add(s);
519
- const c = n.find((r) => r.id === s);
520
- c && (o.push(c), (i = c.permissionSetIds) != null && i.length && o.push(...H(c.permissionSetIds, n, t)));
521
- }
522
- return o;
523
- }
524
- function Ie(e) {
525
- const n = Q(e).map(
526
- ({ setNames: i, setId: s, ...c }) => c
527
- ), t = n.filter((i) => !i.inverted), o = n.filter((i) => i.inverted);
528
- return M(t, o);
529
- }
530
- function Ae(e, n, t) {
531
- const o = /* @__PURE__ */ new Map();
532
- return e.forEach(
533
- ({ name: i, permissions: s }) => s.forEach(({ conditions: c, actions: r }) => {
534
- var a, l;
535
- const u = JSON.parse(c || "{}");
536
- (a = u[n]) != null && a.$in ? (l = u[n]) == null || l.$in.forEach(
537
- (d) => (o.get(d) ?? o.set(d, /* @__PURE__ */ new Set()).get(d)).add(i)
538
- ) : r[0] === "manage" && t.forEach((d) => {
539
- (o.get(d) ?? o.set(d, /* @__PURE__ */ new Set()).get(d)).add(i);
540
- });
541
- })
542
- ), [...o].map(([i, s]) => ({
543
- id: i,
544
- setNames: [...s]
545
- }));
546
- }
547
- function Oe(e, n) {
548
- const t = (r, u) => {
549
- const a = { ...r }, l = JSON.parse(a.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 a.conditions;
556
- return {
557
- ...a,
558
- inverted: !0,
559
- ...a.conditions && { conditions: JSON.stringify(l) }
560
- };
561
- }, o = new Map(e.map((r) => [r.subject, r])), i = new Map(n.map((r) => [r.subject, r])), s = [], c = /* @__PURE__ */ new Set([...o.keys(), ...i.keys()]);
562
- for (const r of c) {
563
- const u = o.get(r), a = i.get(r);
564
- if (u && a) {
565
- if (u.conditions && a.conditions) {
566
- const l = JSON.parse(u.conditions), d = JSON.parse(a.conditions);
567
- if (!h(l) || !h(d)) {
568
- JSON.stringify(l) !== JSON.stringify(d) && s.push(a);
569
- continue;
570
- }
571
- const m = Object.keys(l)[0], f = l[m].$in.filter(
572
- (g) => !d[m].$in.includes(g)
573
- );
574
- f.length > 0 && s.push(t(u, f)), d[m].$in.filter(
575
- (g) => !l[m].$in.includes(g)
576
- ).length > 0 && s.push(a);
577
- } else if (!u.conditions && a.conditions)
578
- s.push(a);
579
- else if (u.conditions && !a.conditions)
580
- h(JSON.parse(u.conditions)) || s.push(a);
581
- else if (!u.conditions && !a.conditions) {
582
- const l = new Set(u.actions), d = new Set(a.actions), m = a.actions.some((p) => !l.has(p)), f = u.actions.filter((p) => !d.has(p));
583
- if (m) {
584
- const p = a.actions.filter((g) => !l.has(g));
585
- s.push({
586
- ...a,
587
- actions: p
588
- });
589
- }
590
- f.length > 0 && s.push({
591
- ...u,
592
- actions: f,
593
- inverted: !0
594
- });
595
- }
596
- continue;
597
- }
598
- if (u) {
599
- s.push(
600
- t(
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
- a && s.push(a);
610
- }
611
- return s;
612
- }
613
- function _e(e) {
614
- const n = G(
615
- e,
616
- V
617
- ), t = new Set(
618
- n.filter((i) => {
619
- var s;
620
- return ((s = i.source) == null ? void 0 : s.type) === "systemPermissionSet" && !i.inverted;
621
- }).map((i) => i.subject)
622
- ), o = new Set(
623
- n.filter(
624
- (i) => {
625
- var s;
626
- return ((s = i.source) == null ? void 0 : s.type) === "systemPermissionSet" && !i.inverted && i.actions.includes("manage");
627
- }
628
- ).map((i) => i.subject)
629
- );
630
- return e.filter((i) => i.inverted ? !(t.has(i.subject) && !o.has(i.subject)) : !t.has(i.subject));
631
- }
632
- const ie = "business::report::";
633
- function Ee(e, n) {
634
- const t = [], o = e.filter((i) => {
635
- const s = i.subject;
636
- return !s.startsWith(ie) || n.has(s) ? !0 : (t.push(s), !1);
637
- });
638
- return t.length > 0 && console.warn("[filterStalePermissions] dropped stale report permissions:", t), o;
639
- }
640
- const re = "business::report::reports::", ae = _.Subject.Business.report_reports_allDefaultReports, ce = _.Subject.Business.report_reports_allCustomReports;
641
- function ue(e, n) {
642
- return e.conditions ? !!n.conditions && e.conditions === n.conditions : !n.conditions;
643
- }
644
- function Ne(e, n) {
645
- const t = e.find(
646
- (c) => !c.inverted && c.subject === ae
647
- ), o = e.find(
648
- (c) => !c.inverted && c.subject === ce
649
- );
650
- if (!t && !o) return e;
651
- const i = t ? new Set(t.actions) : null, s = o ? new Set(o.actions) : null;
652
- return e.reduce((c, r) => {
653
- if (r.inverted)
654
- return c.push(r), c;
655
- const u = r.subject;
656
- if (!u.startsWith(re))
657
- return c.push(r), c;
658
- const a = n.has(u), l = a ? i : s, d = a ? t : o;
659
- if (!l || !d || !ue(d, r))
660
- return c.push(r), c;
661
- if (l.has("manage")) return c;
662
- const m = r.actions;
663
- if (m.includes("manage"))
664
- return c.push(r), c;
665
- const f = new Set(m);
666
- for (const p of l)
667
- f.delete(p);
668
- return f.size === 0 || c.push({ ...r, actions: Array.from(f) }), c;
669
- }, []);
670
- }
671
- function M(e, n) {
672
- var o, i;
673
- const t = new Map(e.map((s) => [s.subject, s]));
674
- for (const s of n) {
675
- if (s.inverted) {
676
- const r = t.get(s.subject);
677
- if (s.conditions) {
678
- if (r != null && r.conditions) {
679
- const u = JSON.parse(r.conditions), a = JSON.parse(s.conditions);
680
- if (!h(u) || !h(a)) {
681
- t.delete(s.subject);
682
- continue;
683
- }
684
- const l = Object.keys(a)[0], d = ((o = a[l]) == null ? void 0 : o.$in) ?? [], f = (((i = u[l]) == null ? void 0 : i.$in) ?? []).filter((p) => !d.includes(p));
685
- f.length > 0 ? t.set(s.subject, {
686
- ...r,
687
- conditions: JSON.stringify({ [l]: { $in: f } })
688
- }) : t.delete(s.subject);
689
- } else
690
- t.delete(s.subject);
691
- continue;
692
- }
693
- if (r) {
694
- const u = new Set(s.actions), a = r.actions.filter((l) => !u.has(l));
695
- a.length > 0 ? t.set(s.subject, { ...r, actions: a }) : t.delete(s.subject);
696
- continue;
697
- }
698
- continue;
699
- }
700
- if (s.conditions) {
701
- t.set(s.subject, s);
702
- continue;
703
- }
704
- const c = t.get(s.subject);
705
- if (c != null && c.conditions && !h(JSON.parse(c.conditions))) {
706
- t.set(s.subject, s);
707
- continue;
708
- }
709
- if (c) {
710
- const r = [
711
- .../* @__PURE__ */ new Set([
712
- ...c.actions,
713
- ...s.actions
714
- ])
715
- ];
716
- t.set(s.subject, { ...c, actions: r });
717
- } else
718
- t.set(s.subject, s);
719
- }
720
- return Array.from(t.values());
721
- }
722
- function le(e, n) {
723
- const t = M(e, n), o = new Set(e.map((s) => s.subject)), i = n.filter(
724
- (s) => s.inverted && !o.has(s.subject)
725
- );
726
- return [...t, ...i];
727
- }
728
- const P = "/permission-assignments", w = {
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, n) {
742
- return b(await v().put(`${P}/${e}`, n));
743
- },
744
- async delete(e) {
745
- return b(await v().delete(`${P}/${e}`));
746
- },
747
- async addReportManagePermission(e, n) {
748
- return b(
749
- await v().post("/my-permissions/report-manage", { permissionKey: e, label: n })
750
- );
751
- }
752
- }, de = z("permissionAssignment", () => {
753
- const e = S([]);
754
- async function n() {
755
- const r = await w.readAll();
756
- e.value = r;
757
- }
758
- async function t(r) {
759
- return await w.readByUserId(r);
760
- }
761
- async function o(r) {
762
- const u = await w.create(r);
763
- e.value = [...e.value, u];
764
- }
765
- async function i(r, u) {
766
- const a = await w.update(r, u);
767
- e.value = e.value.map((l) => l.id === r ? a : l);
768
- }
769
- async function s(r) {
770
- await w.delete(r), e.value = e.value.filter((u) => u.id !== r);
771
- }
772
- function c(r) {
773
- return e.value.find((u) => u.userId === r);
774
- }
775
- return {
776
- permissionAssignments: e,
777
- readPermissionAssignments: n,
778
- readPermissionAssignmentByUserId: t,
779
- createPermissionAssignment: o,
780
- updatePermissionAssignment: i,
781
- deletePermissionAssignment: s,
782
- getPermissionAssignmentByUserId: c
783
- };
784
- }), me = () => {
785
- const e = de();
786
- return {
787
- ...e,
788
- ...K(e)
789
- };
790
- }, fe = {
791
- async fetchReportPermissions(e, n) {
792
- const t = n ? { lang: n } : {};
793
- return b(
794
- await k().get(`/report-query/hrm/${e}/reports`, { params: t })
795
- );
796
- },
797
- async fetchReportPermissionsForPortal(e, n) {
798
- const t = n ? { isSupportPos: !1, lang: n } : { isSupportPos: !1 };
799
- return b(
800
- await k().get(`/report-query/hrm/${e}/reports`, { params: t })
801
- );
802
- }
803
- }, C = S([]), T = S(!1), R = S(!1), $ = S(null), x = S(null), J = S(!1);
804
- function pe() {
805
- const e = X();
806
- async function n() {
807
- var s;
808
- const o = (s = e.currentBusiness.value) == null ? void 0 : s.id;
809
- if (!o) return;
810
- const i = localStorage.getItem("locale");
811
- if ($.value !== o && (C.value = [], T.value = !1, R.value = !1, $.value = o, J.value = !1), !(T.value && x.value === i)) {
812
- if (R.value) {
813
- J.value = !0;
814
- return;
815
- }
816
- R.value = !0;
817
- try {
818
- const c = await fe.fetchReportPermissionsForPortal(o, i);
819
- if ($.value !== o) return;
820
- C.value = c, T.value = !0, x.value = i;
821
- } catch (c) {
822
- if ($.value !== o) return;
823
- console.warn("Failed to fetch custom report permissions:", c), C.value = [];
824
- } finally {
825
- $.value === o && (R.value = !1, J.value && (J.value = !1, await n()));
826
- }
827
- }
828
- }
829
- const t = U(() => C.value.map(
830
- (o) => o.isDefault ? {
831
- label: o.name,
832
- subject: `business::report::reports::${o.permissionKey}`,
833
- actions: [j.manage, j.read, j.create],
834
- category: F.reports
835
- } : {
836
- label: o.name,
837
- subject: `business::report::reports::${o.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: n,
850
- customReportPermissions: t,
851
- isLoading: U(() => R.value),
852
- isLoaded: U(() => T.value)
853
- };
854
- }
855
- function I(e) {
856
- const n = te(), t = me(), o = ne().restaurants, { customReportPermissions: i } = pe(), s = t.getPermissionAssignmentByUserId(e.id), c = H(
857
- (s == null ? void 0 : s.permissionSetIds) ?? [],
858
- n.permissionSets.value
859
- ), r = Q(c).map(
860
- ({ setNames: p, ...g }) => g
861
- ), u = s == null ? void 0 : s.customPermissions, a = u ?? e.permissions.map((p) => ({
862
- ...p,
863
- subject: A(p.subject)
864
- })), l = M(r, a), d = G(
865
- le(r, a),
866
- V
867
- ).filter((p) => !p.inverted), m = ve(d), f = m ?? o.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
- f.map((p) => {
876
- var g;
877
- return ((g = o.value.find((Y) => Y._id === p)) == null ? void 0 : g.profile.name) ?? "";
878
- })
879
- ),
880
- managableRestaurantIds: m,
881
- permissionLabels: Se(d, i.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(I);
892
- },
893
- async readTeamMembersPage(e) {
894
- var t, o, i;
895
- const n = b(
896
- await v().get("/portal-users/paged", {
897
- params: {
898
- limit: e.limit,
899
- offset: e.offset,
900
- search: e.search,
901
- restaurantIds: (t = e.restaurantIds) != null && t.length ? e.restaurantIds : void 0,
902
- permissionSubjects: (o = e.permissionSubjects) != null && o.length ? e.permissionSubjects : void 0,
903
- permissionSetIds: (i = e.permissionSetIds) != null && i.length ? e.permissionSetIds : void 0
904
- }
905
- })
906
- );
907
- return {
908
- items: n.items.map(I),
909
- total: n.total
910
- };
911
- },
912
- async readTeamMember(e) {
913
- return I(
914
- b(await v().get(`/portal-users/${e}`))
915
- );
916
- },
917
- async createTeamMember(e) {
918
- return I(
919
- b(await v().post("/portal-users", e))
920
- );
921
- },
922
- async updateTeamMember(e, n) {
923
- return I(
924
- b(await v().put(`/portal-users/${e}`, n))
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((n) => n.posUserId);
932
- }
933
- };
934
- function Te(e, n, t) {
935
- if (e.some((c) => c.subject === "all")) return "All";
936
- const o = (t ?? L).filter(
937
- (c) => c.subject === n
938
- ), i = new Set(o.map((c) => O(c).value)), s = e.filter((c) => c.subject === n).filter((c) => i.has(O(c).value));
939
- return s.length === o.length ? "All" : s.length === 0 ? "-" : `${s.length} permission allow`;
940
- }
941
- function O(e) {
942
- const n = Z(e), t = n.subject;
943
- return {
944
- ...n,
945
- get conditions() {
946
- return typeof n.conditions == "string" ? JSON.parse(n.conditions) : n.conditions;
947
- },
948
- get isDiscountOperation() {
949
- var o;
950
- return t === y.F_RULE_SUBJECT.enum.order && ((o = this.conditions) == null ? void 0 : o.operation) === y.F_RULE_ORDER_OPERATION.enum.discount;
951
- },
952
- get isOrderOperation() {
953
- return t === y.F_RULE_SUBJECT.enum.order;
954
- },
955
- get isReportPermission() {
956
- return t === y.F_RULE_SUBJECT.enum.report;
957
- },
958
- get formatted() {
959
- const o = (i) => i.endsWith("_") ? i.slice(0, i.length - 1) : i;
960
- return this.isOrderOperation ? o(this.conditions.operation) : this.isReportPermission ? o(this.conditions.name) : t.toString();
961
- },
962
- get label() {
963
- return n.label || ee(this.formatted);
964
- },
965
- get value() {
966
- return this.isOrderOperation ? `${t}:${this.conditions.operation}` : this.isReportPermission ? `${t}:${this.conditions.name}` : t.toString();
967
- }
968
- };
969
- }
970
- function Je(e) {
971
- const n = e.map((t) => O(t)).find((t) => t.isDiscountOperation);
972
- return n ? parseInt((n.conditions.adjustment.$lte * 100).toFixed(0)) : 100;
973
- }
974
- function ve(e) {
975
- const n = e.find(
976
- (t) => t.subject === _.Subject.Restaurant.restaurant
977
- );
978
- return n ? n.conditions ? JSON.parse(n.conditions).restaurantId.$in : null : [];
979
- }
980
- function Ue(e) {
981
- return (e == null ? void 0 : e.some((n) => n.subject === "all")) ?? !1;
982
- }
983
- function Be(e) {
984
- const n = e.find((t) => t.subject === _.Subject.Business.role);
985
- return n ? n.conditions ? JSON.parse(n.conditions).roleId.$in : null : [];
986
- }
987
- function Le(e) {
988
- const n = O(e);
989
- if (!n.isReportPermission) return;
990
- const { name: t, ...o } = n.conditions ?? {};
991
- return Object.keys(o).length > 0 ? o : void 0;
992
- }
993
- function Me(e, n, t) {
994
- return e.map((o) => {
995
- const i = ge(o), s = i.isReportPermission ? t == null ? void 0 : t.get(o) : void 0;
996
- return {
997
- subject: i.subject,
998
- actions: i.actions,
999
- conditions: {
1000
- ...i.conditions,
1001
- ...s ?? {},
1002
- adjustment: i.isDiscountOperation ? { $lte: parseFloat((n / 100).toFixed(2)) } : void 0
1003
- }
1004
- };
1005
- });
1006
- }
1007
- function ge(e) {
1008
- const [n, t] = e.split(":");
1009
- let o;
1010
- return t ? (o = L.find(
1011
- (i) => i.subject === n && [
1012
- (typeof i.conditions == "object" ? i.conditions : JSON.parse(i.conditions)).operation,
1013
- i.conditions.name
1014
- ].includes(t)
1015
- ), !o && n === y.F_RULE_SUBJECT.enum.report && (o = {
1016
- label: "",
1017
- subject: y.F_RULE_SUBJECT.enum.report,
1018
- actions: ["read"],
1019
- conditions: { name: t },
1020
- inverted: !1,
1021
- reason: ""
1022
- })) : o = L.find((i) => i.subject === n), O(o || { subject: y.F_RULE_SUBJECT.enum.order, actions: [], label: "" });
1023
- }
1024
- function Se(e, n = []) {
1025
- return W(
1026
- e.reduce((t, o) => {
1027
- const i = be.find(
1028
- (s) => s.subject === o.subject && o.actions.includes("manage")
1029
- ) || n.find((s) => s.subject === o.subject);
1030
- if (i) {
1031
- const s = i.subject === _.Subject.Business.inventory_stock ? "Warehouse Management" : i.label;
1032
- t.push(s);
1033
- }
1034
- return t;
1035
- }, [])
1036
- );
1037
- }
1038
- export {
1039
- G as N,
1040
- Q as P,
1041
- fe as R,
1042
- Le as a,
1043
- Te as b,
1044
- H as c,
1045
- le as d,
1046
- L as e,
1047
- Me as f,
1048
- Je as g,
1049
- Ue as h,
1050
- pe as i,
1051
- ie as j,
1052
- Be as k,
1053
- ve as l,
1054
- Ie as m,
1055
- Oe as n,
1056
- Ee as o,
1057
- be as p,
1058
- Ne as q,
1059
- O as r,
1060
- _e as s,
1061
- Ce as t,
1062
- te as u,
1063
- me as v,
1064
- Se as w,
1065
- Ae as x
1066
- };