@feedmepos/mf-hrm-portal 2.3.2-dev.5 → 2.3.2-dev.7

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 (55) hide show
  1. package/dist/{ApprovalCodeList-NYJNwdDZ.js → ApprovalCodeList-Bw0E-hZl.js} +7 -7
  2. package/dist/{AuditLogList-Ghn4aBnn.js → AuditLogList-CA-_t77n.js} +5 -5
  3. package/dist/{ConditionBuilderForm.vue_vue_type_script_setup_true_lang-BxZ9t3MZ.js → ConditionBuilderForm.vue_vue_type_script_setup_true_lang-LtjNCAFN.js} +10 -10
  4. package/dist/{EmployeeList-jc8LTznV.js → EmployeeList-D_bX0EhQ.js} +8 -8
  5. package/dist/{FormSection.vue_vue_type_script_setup_true_lang-DLgm6oCz.js → FormSection.vue_vue_type_script_setup_true_lang-CyZxQa-b.js} +1 -1
  6. package/dist/{GrantUserList-BtPTpypR.js → GrantUserList-Cg7ITk_M.js} +8 -8
  7. package/dist/{Main-BizCV-_x.js → Main-BaB4vgI5.js} +11 -11
  8. package/dist/{Main-McMZU_cR.js → Main-Bl-Ocx1G.js} +5 -5
  9. package/dist/{Main-BF8hlYeV.js → Main-D5wi42fp.js} +10 -10
  10. package/dist/{MyPosProfile-BjeCnBvL.js → MyPosProfile-CUG_201f.js} +1 -1
  11. package/dist/{PermissionSetList-NWLoqFHC.js → PermissionSetList-kgG9H3DX.js} +66 -66
  12. package/dist/PortalPermissionEditor.vue_vue_type_script_setup_true_lang-y1YcZpGA.js +4207 -0
  13. package/dist/{PortalUserSearcher.vue_vue_type_style_index_0_scoped_827dfd60_lang-nwpdr7T7.js → PortalUserSearcher.vue_vue_type_style_index_0_scoped_827dfd60_lang-fQyCtDXM.js} +19 -19
  14. package/dist/{RoleForm.vue_vue_type_script_setup_true_lang-eT-dPsOX.js → RoleForm.vue_vue_type_script_setup_true_lang-3Q8udk43.js} +30 -30
  15. package/dist/{RoleList-CIfN10zu.js → RoleList-Cmz97HHP.js} +96 -105
  16. package/dist/{ScheduleAddPositionModal.vue_vue_type_script_setup_true_lang-CMTXC_UR.js → ScheduleAddPositionModal.vue_vue_type_script_setup_true_lang-CggEy3OI.js} +1 -1
  17. package/dist/{ScheduleGeneralPage-8vS1DUrk.js → ScheduleGeneralPage-B39k3SQH.js} +2 -2
  18. package/dist/{ScheduleModal.vue_vue_type_script_setup_true_lang-Br4AcF1g.js → ScheduleModal.vue_vue_type_script_setup_true_lang-C5j3D4eF.js} +4 -4
  19. package/dist/{SchedulePage-DqbE1PoV.js → SchedulePage-AVmRkFi1.js} +9 -9
  20. package/dist/{SchedulePositionPage-DUnkT0Tp.js → SchedulePositionPage-3rE-O8CG.js} +3 -3
  21. package/dist/{SelectFilter-voMj4_j1.js → SelectFilter-R7ry_GEg.js} +2 -3
  22. package/dist/{TeamMemberList-DoEOWNDC.js → TeamMemberList-CvDnIILn.js} +184 -184
  23. package/dist/TimesheetList-DYoglTi8.js +401 -0
  24. package/dist/TimesheetList.vue_vue_type_style_index_0_scoped_d0c6fd51_lang-DBpzyQ17.js +63 -0
  25. package/dist/{app-CDCO87ji.js → app-DKUCzcrc.js} +5444 -4624
  26. package/dist/app.js +1 -1
  27. package/dist/{approval-code-CLE9s5dL.js → approval-code-nsETgIry.js} +1 -1
  28. package/dist/{dayjs.min-BW6-XAUB.js → dayjs.min-CtULWW1N.js} +1 -1
  29. package/dist/{employee-BaCU-FLC.js → employee-DlsSqR3i.js} +5 -5
  30. package/dist/{grant-user-DMtilLJx.js → grant-user-Dpa_Rl6j.js} +1 -1
  31. package/dist/{iteration-CPLGGFBb.js → iteration-DpHBtiyr.js} +1 -1
  32. package/dist/{lodash-snXoiw60.js → lodash-YaHCUo_F.js} +1 -1
  33. package/dist/member-grant-CEokFI3_.js +54 -0
  34. package/dist/restaurant-CDFKqEFm.js +52 -0
  35. package/dist/role-DyBVVlEA.js +97 -0
  36. package/dist/rule-xErZqYmH.js +842 -0
  37. package/dist/src/api/timesheet/index.d.ts +1 -1
  38. package/dist/src/helpers/permission-set.d.ts +1 -102
  39. package/dist/src/helpers/rule.d.ts +2 -2
  40. package/dist/src/stores/restaurant.d.ts +61 -1
  41. package/dist/src/stores/timesheet.d.ts +6 -6
  42. package/dist/src/views/audit-log/locales/index.d.ts +12 -0
  43. package/dist/style.css +1 -1
  44. package/dist/tsconfig.app.tsbuildinfo +1 -1
  45. package/dist/{useAppStore-pKAGQL6q.js → useAppStore-BqsvPsPB.js} +1 -1
  46. package/dist/{useLoading-D67DIqfk.js → useLoading-BS1bnZg1.js} +1 -1
  47. package/dist/{useReportPermissions-CfgnE0NY.js → useReportPermissions-DJEhkyGc.js} +5 -5
  48. package/package.json +3 -3
  49. package/dist/PortalPermissionEditor.vue_vue_type_script_setup_true_lang-UPcpeVD5.js +0 -4243
  50. package/dist/TimesheetList-BBv2SV96.js +0 -402
  51. package/dist/TimesheetList.vue_vue_type_style_index_0_scoped_63294af2_lang-h-bWBmpI.js +0 -58
  52. package/dist/member-grant-CJyOr-q0.js +0 -55
  53. package/dist/restaurant-BMlLIUqe.js +0 -51
  54. package/dist/role-DqcBOWHL.js +0 -93
  55. package/dist/rule-B5YNhGJ4.js +0 -788
@@ -0,0 +1,842 @@
1
+ import { s as W, c as ne, e as j } from "./iteration-DpHBtiyr.js";
2
+ import { y as N, m as h, k as z, z as re, P as K, g, b, B as L, v as x, C as y, s as F } from "./app-DKUCzcrc.js";
3
+ import { s as ie } from "./utils-BZkjJbju.js";
4
+ import { defineStore as V, storeToRefs as H } from "pinia";
5
+ import { ref as v, computed as E } from "vue";
6
+ import { useCoreStore as Q } from "@feedmepos/mf-common";
7
+ import { u as oe } from "./restaurant-CDFKqEFm.js";
8
+ function k(e) {
9
+ if (e) {
10
+ if (typeof e == "string") {
11
+ if (e === "{}") return;
12
+ try {
13
+ return JSON.parse(e);
14
+ } catch {
15
+ return;
16
+ }
17
+ }
18
+ if (typeof e == "object")
19
+ return Object.keys(e).length > 0 ? e : void 0;
20
+ }
21
+ }
22
+ function w(e) {
23
+ return e ? Object.values(e).every(
24
+ (t) => t !== null && typeof t == "object" && !Array.isArray(t) && Object.keys(t).length === 1 && Array.isArray(t.$in)
25
+ ) : !0;
26
+ }
27
+ function G(e) {
28
+ const t = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), n = (r, s, o) => {
29
+ var a, c;
30
+ const u = k(s.conditions);
31
+ let l = `${s.subject}::${JSON.stringify([...s.actions].sort())}`;
32
+ w(u) || (l += `::${JSON.stringify(u)}`);
33
+ const m = r.get(l);
34
+ if (!m) {
35
+ r.set(l, { ...s, setNames: [o.name], setId: o._id });
36
+ return;
37
+ }
38
+ m.setNames.push(o.name);
39
+ const d = k(m.conditions);
40
+ if (!d || !u) {
41
+ m.conditions = void 0;
42
+ return;
43
+ }
44
+ for (const f in u)
45
+ (a = d[f]) != null && a.$in && (c = u[f]) != null && c.$in ? d[f].$in = Array.from(
46
+ /* @__PURE__ */ new Set([...d[f].$in, ...u[f].$in])
47
+ ) : d[f] || (d[f] = u[f]);
48
+ m.conditions = JSON.stringify(d);
49
+ };
50
+ for (const r of e)
51
+ for (const s of r.permissions)
52
+ n(s.inverted ? i : t, s, r);
53
+ return [...Array.from(t.values()), ...Array.from(i.values())];
54
+ }
55
+ function C(e, t) {
56
+ return `${e}::${[...t].sort().join(",")}`;
57
+ }
58
+ function X(e, t) {
59
+ const i = [...e], n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
60
+ for (const a of e) {
61
+ const c = N(a.subject);
62
+ n.add(C(c, a.actions)), a.inverted && a.actions.includes("manage") && r.add(`set_${c}`), !a.inverted && a.actions.includes("manage") && s.add(c);
63
+ }
64
+ const o = [...e];
65
+ for (; o.length > 0; ) {
66
+ const a = o.shift(), c = `set_${N(a.subject)}`, u = t[c];
67
+ if (!u || r.has(c) || !a.actions.includes("manage") || a.inverted) continue;
68
+ r.add(c);
69
+ const l = ae(a);
70
+ a.source && !a.source.trace && (a.source = { ...a.source, trace: l });
71
+ const m = [...l, `${u.name} (system)`];
72
+ for (const d of u.permissions ?? []) {
73
+ const f = N(d.subject), p = C(f, d.actions);
74
+ n.has(p) || s.has(f) || (n.add(p), i.push({
75
+ ...d,
76
+ // FdoPermissionRule.fields is string[] | null; RawRule expects string[] | undefined
77
+ fields: d.fields ?? void 0,
78
+ source: {
79
+ type: "systemPermissionSet",
80
+ permissionSetId: u.key,
81
+ permissionSetName: u.name,
82
+ trace: m
83
+ }
84
+ }));
85
+ }
86
+ for (const d of u.permissionSets ?? []) {
87
+ const f = N(d), p = C(f, ["manage"]), S = {
88
+ subject: f,
89
+ actions: ["manage"],
90
+ source: {
91
+ type: "systemPermissionSet",
92
+ permissionSetId: u.key,
93
+ permissionSetName: u.name,
94
+ trace: m
95
+ }
96
+ };
97
+ n.has(p) || (n.add(p), i.push(S)), o.push(S);
98
+ }
99
+ }
100
+ return [...i.filter((a) => !a.inverted), ...i.filter((a) => a.inverted)];
101
+ }
102
+ function ae(e) {
103
+ if (!e.source) return [];
104
+ const { type: t, trace: i, permissionSetName: n } = e.source;
105
+ if (i && i.length > 0) return i;
106
+ switch (t) {
107
+ case "permissionSet":
108
+ return n ? [n] : [];
109
+ case "custom":
110
+ return ["custom"];
111
+ default:
112
+ return [];
113
+ }
114
+ }
115
+ function Y(e, t) {
116
+ return Array.isArray(e) ? e.includes(t) : e === t;
117
+ }
118
+ function ue(e) {
119
+ return Array.isArray(e) ? e[0] : e;
120
+ }
121
+ function Fe(e, t) {
122
+ const i = t.find((r) => Y(r.subject, e));
123
+ if (!(i != null && i.category) || i.isCategoryCover) return;
124
+ const n = t.find((r) => r.category === i.category && r.isCategoryCover);
125
+ if (n)
126
+ return ue(n.subject);
127
+ }
128
+ function Te(e, t) {
129
+ const i = t.find((n) => Y(n.subject, e));
130
+ return !!(i != null && i.isCategoryCover);
131
+ }
132
+ function Z(e, t, i = /* @__PURE__ */ new Set()) {
133
+ var n;
134
+ const r = [];
135
+ for (const s of e) {
136
+ if (i.has(s)) continue;
137
+ i.add(s);
138
+ const o = t.find((a) => a.id === s);
139
+ o && (r.push(o), (n = o.permissionSetIds) != null && n.length && r.push(...Z(o.permissionSetIds, t, i)));
140
+ }
141
+ return r;
142
+ }
143
+ function ce(e) {
144
+ const t = G(e).map(
145
+ ({ setNames: r, setId: s, ...o }) => o
146
+ ), i = t.filter((r) => !r.inverted), n = t.filter((r) => r.inverted);
147
+ return T(i, n);
148
+ }
149
+ function le(e, t) {
150
+ const i = (a, c) => {
151
+ const u = { ...a }, l = JSON.parse(u.conditions || "{}");
152
+ if (c)
153
+ if (c.length > 0) {
154
+ const m = Object.keys(l)[0];
155
+ l[m].$in = c;
156
+ } else
157
+ delete u.conditions;
158
+ return {
159
+ ...u,
160
+ inverted: !0,
161
+ ...u.conditions && { conditions: JSON.stringify(l) }
162
+ };
163
+ }, n = new Map(e.map((a) => [a.subject, a])), r = new Map(t.map((a) => [a.subject, a])), s = [], o = /* @__PURE__ */ new Set([...n.keys(), ...r.keys()]);
164
+ for (const a of o) {
165
+ const c = n.get(a), u = r.get(a);
166
+ if (c && u) {
167
+ if (c.conditions && u.conditions) {
168
+ const l = JSON.parse(c.conditions), m = JSON.parse(u.conditions);
169
+ if (!w(l) || !w(m)) {
170
+ JSON.stringify(l) !== JSON.stringify(m) && s.push(u);
171
+ continue;
172
+ }
173
+ const d = Object.keys(l)[0], f = l[d].$in.filter(
174
+ (p) => !m[d].$in.includes(p)
175
+ );
176
+ f.length > 0 && s.push(i(c, f)), m[d].$in.filter(
177
+ (p) => !l[d].$in.includes(p)
178
+ ).length > 0 && s.push(u);
179
+ } else if (!c.conditions && u.conditions)
180
+ s.push(u);
181
+ else if (c.conditions && !u.conditions)
182
+ w(JSON.parse(c.conditions)) || s.push(u);
183
+ else if (!c.conditions && !u.conditions) {
184
+ const l = new Set(c.actions), m = new Set(u.actions), d = u.actions.some((p) => !l.has(p)), f = c.actions.filter((p) => !m.has(p));
185
+ if (d) {
186
+ const p = u.actions.filter((S) => !l.has(S));
187
+ s.push({
188
+ ...u,
189
+ actions: p
190
+ });
191
+ }
192
+ f.length > 0 && s.push({
193
+ ...c,
194
+ actions: f,
195
+ inverted: !0
196
+ });
197
+ }
198
+ continue;
199
+ }
200
+ if (c) {
201
+ s.push(
202
+ i(
203
+ c,
204
+ // If base has conditions, set diffIds to empty array, disallow all access to collection
205
+ // otherwise, invert directly
206
+ c.conditions && []
207
+ )
208
+ );
209
+ continue;
210
+ }
211
+ u && s.push(u);
212
+ }
213
+ return s;
214
+ }
215
+ function de(e) {
216
+ const t = X(
217
+ e,
218
+ K
219
+ ), i = new Set(
220
+ t.filter((r) => {
221
+ var s;
222
+ return ((s = r.source) == null ? void 0 : s.type) === "systemPermissionSet" && !r.inverted;
223
+ }).map((r) => r.subject)
224
+ ), n = new Set(
225
+ t.filter(
226
+ (r) => {
227
+ var s;
228
+ return ((s = r.source) == null ? void 0 : s.type) === "systemPermissionSet" && !r.inverted && r.actions.includes("manage");
229
+ }
230
+ ).map((r) => r.subject)
231
+ );
232
+ return e.filter((r) => r.inverted ? !(i.has(r.subject) && !n.has(r.subject)) : !i.has(r.subject));
233
+ }
234
+ const me = "business::report::";
235
+ function fe(e, t) {
236
+ const i = [], n = e.filter((r) => {
237
+ const s = r.subject;
238
+ return !s.startsWith(me) || t.has(s) ? !0 : (i.push(s), !1);
239
+ });
240
+ return i.length > 0 && console.warn("[filterStalePermissions] dropped stale report permissions:", i), n;
241
+ }
242
+ const pe = "business::report::reports::", ge = h.Subject.Business.report_reports_allDefaultReports, be = h.Subject.Business.report_reports_allCustomReports;
243
+ function he(e, t) {
244
+ return e.conditions ? !!t.conditions && e.conditions === t.conditions : !t.conditions;
245
+ }
246
+ function ve(e, t) {
247
+ const i = e.find(
248
+ (o) => !o.inverted && o.subject === ge
249
+ ), n = e.find(
250
+ (o) => !o.inverted && o.subject === be
251
+ );
252
+ if (!i && !n) return e;
253
+ const r = i ? new Set(i.actions) : null, s = n ? new Set(n.actions) : null;
254
+ return e.reduce((o, a) => {
255
+ if (a.inverted)
256
+ return o.push(a), o;
257
+ const c = a.subject;
258
+ if (!c.startsWith(pe))
259
+ return o.push(a), o;
260
+ const u = t.has(c), l = u ? r : s, m = u ? i : n;
261
+ if (!l || !m || !he(m, a))
262
+ return o.push(a), o;
263
+ if (l.has("manage")) return o;
264
+ const d = a.actions;
265
+ if (d.includes("manage"))
266
+ return o.push(a), o;
267
+ const f = new Set(d);
268
+ for (const p of l)
269
+ f.delete(p);
270
+ return f.size === 0 || o.push({ ...a, actions: Array.from(f) }), o;
271
+ }, []);
272
+ }
273
+ function T(e, t) {
274
+ var i, n;
275
+ const r = new Map(e.map((s) => [s.subject, s]));
276
+ for (const s of t) {
277
+ if (s.inverted) {
278
+ const a = r.get(s.subject);
279
+ if (s.conditions) {
280
+ if (a != null && a.conditions) {
281
+ const c = JSON.parse(a.conditions), u = JSON.parse(s.conditions);
282
+ if (!w(c) || !w(u)) {
283
+ r.delete(s.subject);
284
+ continue;
285
+ }
286
+ const l = Object.keys(u)[0], m = ((i = u[l]) == null ? void 0 : i.$in) ?? [], d = (((n = c[l]) == null ? void 0 : n.$in) ?? []).filter((f) => !m.includes(f));
287
+ d.length > 0 ? r.set(s.subject, {
288
+ ...a,
289
+ conditions: JSON.stringify({ [l]: { $in: d } })
290
+ }) : r.delete(s.subject);
291
+ } else
292
+ r.delete(s.subject);
293
+ continue;
294
+ }
295
+ if (a) {
296
+ const c = new Set(s.actions), u = a.actions.filter((l) => !c.has(l));
297
+ u.length > 0 ? r.set(s.subject, { ...a, actions: u }) : r.delete(s.subject);
298
+ continue;
299
+ }
300
+ continue;
301
+ }
302
+ if (s.conditions) {
303
+ r.set(s.subject, s);
304
+ continue;
305
+ }
306
+ const o = r.get(s.subject);
307
+ if (o != null && o.conditions && !w(JSON.parse(o.conditions))) {
308
+ r.set(s.subject, s);
309
+ continue;
310
+ }
311
+ if (o) {
312
+ const a = [
313
+ .../* @__PURE__ */ new Set([...o.actions, ...s.actions])
314
+ ];
315
+ r.set(s.subject, {
316
+ ...o,
317
+ actions: a
318
+ });
319
+ } else
320
+ r.set(s.subject, s);
321
+ }
322
+ return Array.from(r.values());
323
+ }
324
+ function Se(e, t) {
325
+ const i = T(e, t), n = new Set(e.map((s) => s.subject)), r = t.filter(
326
+ (s) => s.inverted && !n.has(s.subject)
327
+ );
328
+ return [...i, ...r];
329
+ }
330
+ const q = (e) => JSON.parse(JSON.stringify(e));
331
+ function ee(e) {
332
+ const t = e.find(
333
+ (i) => i.subject === h.Subject.Restaurant.restaurant
334
+ );
335
+ return t ? t.conditions ? JSON.parse(t.conditions).restaurantId.$in : null : [];
336
+ }
337
+ function te(e) {
338
+ const t = e.find((i) => i.subject === h.Subject.Business.role);
339
+ return t ? t.conditions ? JSON.parse(t.conditions).roleId.$in : null : [];
340
+ }
341
+ function ye(e, t) {
342
+ const i = q(
343
+ e.filter((n) => n.subject !== h.Subject.Business.role)
344
+ );
345
+ return t && t.length > 0 && i.push({
346
+ actions: [h.Action.manage],
347
+ subject: h.Subject.Business.role,
348
+ conditions: JSON.stringify({ roleId: { $in: t } })
349
+ }), i;
350
+ }
351
+ function Le(e, t, { restaurantRoles: i, allRoleIds: n }) {
352
+ let r = q(
353
+ e.filter(
354
+ (s) => s.subject !== h.Subject.Business.restaurant && s.subject !== h.Subject.Restaurant.restaurant
355
+ )
356
+ );
357
+ if (!t || t.length > 0) {
358
+ const {
359
+ category: s,
360
+ showByFeatureFlag: o,
361
+ ...a
362
+ } = z.restaurant;
363
+ r.push(a);
364
+ const c = {
365
+ actions: [h.Action.manage],
366
+ subject: h.Subject.Restaurant.restaurant
367
+ };
368
+ t && (c.conditions = JSON.stringify({ restaurantId: { $in: t } })), r.push(c);
369
+ }
370
+ if (t) {
371
+ const s = [
372
+ ...new Set(t.map((o) => i[o] ?? []).flatMap((o) => o))
373
+ ];
374
+ s.length !== n.length && (r = ye(
375
+ r,
376
+ (te(e) || n).filter((o) => s.includes(o))
377
+ ));
378
+ }
379
+ return r;
380
+ }
381
+ function xe(e) {
382
+ let t = e.userPermissions;
383
+ return e.reportSubjects && (t = fe(t, e.reportSubjects)), e.defaultReportSubjects && (t = ve(t, e.defaultReportSubjects)), {
384
+ customPermissions: le(
385
+ ce(e.inheritedPermissions),
386
+ de(t)
387
+ ),
388
+ permissions: t.filter((i) => !i.inverted).map((i) => ({ ...i, subject: re(i.subject) }))
389
+ };
390
+ }
391
+ const _ = "/permission-sets", J = {
392
+ async read() {
393
+ return g(await b().get(_));
394
+ },
395
+ async create(e) {
396
+ return g(await b().post(_, e));
397
+ },
398
+ async update(e, t) {
399
+ return g(await b().put(`${_}/${e}`, t));
400
+ },
401
+ async delete(e) {
402
+ return g(await b().delete(`${_}/${e}`));
403
+ }
404
+ }, je = V("permissionSet", () => {
405
+ const { currentBusiness: e } = Q(), t = v([]), i = v(!1), n = v(null);
406
+ async function r() {
407
+ var l;
408
+ const u = ((l = e.value) == null ? void 0 : l._id) ?? null;
409
+ if (n.value !== u)
410
+ try {
411
+ i.value = !0;
412
+ const m = await J.read();
413
+ t.value = c(m), n.value = u;
414
+ } finally {
415
+ i.value = !1;
416
+ }
417
+ }
418
+ async function s(u) {
419
+ const l = await J.create(u);
420
+ t.value = c([...t.value, l]);
421
+ }
422
+ async function o(u, l) {
423
+ const m = await J.update(u, l);
424
+ t.value = c(t.value.map((d) => d.id === u ? m : d));
425
+ }
426
+ async function a(u) {
427
+ await J.delete(u), t.value = c(t.value.filter((l) => l.id !== u));
428
+ }
429
+ function c(u) {
430
+ return u.sort((l, m) => l.name.localeCompare(m.name));
431
+ }
432
+ return {
433
+ permissionSets: t,
434
+ isLoading: i,
435
+ readPermissionSets: r,
436
+ createPermissionSet: s,
437
+ updatePermissionSet: o,
438
+ deletePermissionSet: a
439
+ };
440
+ }), we = () => {
441
+ const e = je();
442
+ return {
443
+ ...e,
444
+ ...H(e)
445
+ };
446
+ }, P = "/permission-assignments", I = {
447
+ async readAll() {
448
+ return g(await b().get(P));
449
+ },
450
+ async readByUserId(e) {
451
+ return g(await b().get(`${P}/user/${e}`));
452
+ },
453
+ async readById(e) {
454
+ return g(await b().get(`${P}/${e}`));
455
+ },
456
+ async create(e) {
457
+ return g(await b().post(P, e));
458
+ },
459
+ async update(e, t) {
460
+ return g(await b().put(`${P}/${e}`, t));
461
+ },
462
+ async delete(e) {
463
+ return g(await b().delete(`${P}/${e}`));
464
+ },
465
+ async addReportManagePermission(e, t) {
466
+ return g(
467
+ await b().post("/my-permissions/report-manage", { permissionKey: e, label: t })
468
+ );
469
+ }
470
+ }, Pe = V("permissionAssignment", () => {
471
+ const e = v([]);
472
+ async function t() {
473
+ const a = await I.readAll();
474
+ e.value = a;
475
+ }
476
+ async function i(a) {
477
+ return await I.readByUserId(a);
478
+ }
479
+ async function n(a) {
480
+ const c = await I.create(a);
481
+ e.value = [...e.value, c];
482
+ }
483
+ async function r(a, c) {
484
+ const u = await I.update(a, c);
485
+ e.value = e.value.map((l) => l.id === a ? u : l);
486
+ }
487
+ async function s(a) {
488
+ await I.delete(a), e.value = e.value.filter((c) => c.id !== a);
489
+ }
490
+ function o(a) {
491
+ return e.value.find((c) => c.userId === a);
492
+ }
493
+ return {
494
+ permissionAssignments: e,
495
+ readPermissionAssignments: t,
496
+ readPermissionAssignmentByUserId: i,
497
+ createPermissionAssignment: n,
498
+ updatePermissionAssignment: r,
499
+ deletePermissionAssignment: s,
500
+ getPermissionAssignmentByUserId: o
501
+ };
502
+ }), $e = () => {
503
+ const e = Pe();
504
+ return {
505
+ ...e,
506
+ ...H(e)
507
+ };
508
+ }, Ie = {
509
+ async fetchReportPermissions(e, t) {
510
+ const i = t ? { lang: t } : {};
511
+ return g(
512
+ await L().get(`/report-query/hrm/${e}/reports`, { params: i })
513
+ );
514
+ },
515
+ async fetchReportPermissionsForPortal(e, t) {
516
+ const i = t ? { isSupportPos: !1, lang: t } : { isSupportPos: !1 };
517
+ return g(
518
+ await L().get(`/report-query/hrm/${e}/reports`, { params: i })
519
+ );
520
+ }
521
+ }, B = v([]), U = v(!1), R = v(!1), O = v(null), D = v(null), M = v(!1);
522
+ function Re() {
523
+ const e = Q();
524
+ async function t() {
525
+ var s;
526
+ const n = (s = e.currentBusiness.value) == null ? void 0 : s.id;
527
+ if (!n) return;
528
+ const r = localStorage.getItem("locale");
529
+ if (O.value !== n && (B.value = [], U.value = !1, R.value = !1, O.value = n, M.value = !1), !(U.value && D.value === r)) {
530
+ if (R.value) {
531
+ M.value = !0;
532
+ return;
533
+ }
534
+ R.value = !0;
535
+ try {
536
+ const o = await Ie.fetchReportPermissionsForPortal(n, r);
537
+ if (O.value !== n) return;
538
+ B.value = o, U.value = !0, D.value = r;
539
+ } catch (o) {
540
+ if (O.value !== n) return;
541
+ console.warn("Failed to fetch custom report permissions:", o), B.value = [];
542
+ } finally {
543
+ O.value === n && (R.value = !1, M.value && (M.value = !1, await t()));
544
+ }
545
+ }
546
+ }
547
+ const i = E(() => B.value.map(
548
+ (n) => n.isDefault ? {
549
+ label: n.name,
550
+ subject: `business::report::reports::${n.permissionKey}`,
551
+ actions: [y.manage, y.read, y.create],
552
+ category: x.reports
553
+ } : {
554
+ label: n.name,
555
+ subject: `business::report::reports::${n.permissionKey}`,
556
+ actions: [
557
+ y.manage,
558
+ y.read,
559
+ y.create,
560
+ y.update,
561
+ y.delete
562
+ ],
563
+ category: x.customReports
564
+ }
565
+ ));
566
+ return {
567
+ fetchCustomReportPermissions: t,
568
+ customReportPermissions: i,
569
+ isLoading: E(() => R.value),
570
+ isLoaded: E(() => U.value)
571
+ };
572
+ }
573
+ function A(e) {
574
+ const t = we(), i = $e(), n = oe().restaurants, { customReportPermissions: r } = Re(), s = i.getPermissionAssignmentByUserId(e.id), o = Z(
575
+ (s == null ? void 0 : s.permissionSetIds) ?? e.permissionSetIds ?? [],
576
+ t.permissionSets.value
577
+ ), a = G(o).map(
578
+ ({ setNames: p, ...S }) => S
579
+ ), c = s == null ? void 0 : s.customPermissions, u = c ?? e.permissions.map((p) => ({
580
+ ...p,
581
+ subject: N(p.subject)
582
+ })), l = T(a, u), m = X(
583
+ Se(a, u),
584
+ K
585
+ ).filter((p) => !p.inverted), d = ee(m), f = d ?? n.value.map((p) => p._id);
586
+ return {
587
+ doc: e,
588
+ id: e.id,
589
+ // An invite's name is the admin's, or its sign-in key when it has none.
590
+ name: e.status === "invited" ? e.name || "-" : e.name && e.name !== e.email && e.name !== e.phoneNumber ? e.name : "-",
591
+ phoneNumber: e.phoneNumber,
592
+ email: e.email,
593
+ restaurants: W(
594
+ f.map((p) => {
595
+ var S;
596
+ return ((S = n.value.find((se) => se._id === p)) == null ? void 0 : S.profile.name) ?? "";
597
+ })
598
+ ),
599
+ managableRestaurantIds: d,
600
+ permissionLabels: Ne(m, r.value),
601
+ permissions: l,
602
+ status: e.status ?? "active",
603
+ loginMethod: e.loginMethod ?? "feedme"
604
+ };
605
+ }
606
+ const Oe = Object.freeze(
607
+ Object.values(z)
608
+ ), ke = {
609
+ async readTeamMembers() {
610
+ return g(
611
+ await b().get("/portal-users")
612
+ ).map(A);
613
+ },
614
+ async readTeamMembersPage(e) {
615
+ var i, n, r, s, o;
616
+ const t = g(
617
+ await b().get("/portal-users/paged", {
618
+ params: {
619
+ limit: e.limit,
620
+ offset: e.offset,
621
+ search: e.search,
622
+ restaurantIds: (i = e.restaurantIds) != null && i.length ? e.restaurantIds : void 0,
623
+ permissionSubjects: (n = e.permissionSubjects) != null && n.length ? e.permissionSubjects : void 0,
624
+ permissionSetIds: (r = e.permissionSetIds) != null && r.length ? e.permissionSetIds : void 0,
625
+ statuses: (s = e.statuses) != null && s.length ? e.statuses : void 0,
626
+ loginMethods: (o = e.loginMethods) != null && o.length ? e.loginMethods : void 0
627
+ }
628
+ })
629
+ );
630
+ return {
631
+ items: t.items.map(A),
632
+ total: t.total
633
+ };
634
+ },
635
+ async readTeamMember(e) {
636
+ return A(
637
+ g(await b().get(`/portal-users/${e}`))
638
+ );
639
+ },
640
+ async createTeamMember(e) {
641
+ return A(
642
+ g(await b().post("/portal-users", e))
643
+ );
644
+ },
645
+ async updateTeamMember(e, t) {
646
+ return A(
647
+ g(await b().put(`/portal-users/${e}`, t))
648
+ );
649
+ },
650
+ async deleteTeamMember(e) {
651
+ return g(await b().delete(`/portal-users/${e}`));
652
+ },
653
+ async readTeamMemberPosUserIds() {
654
+ return g(await b().get("/portal-users")).map((t) => t.posUserId);
655
+ },
656
+ async generateMasterUserPasscode(e) {
657
+ return `${g(
658
+ await b().post("/portal-users/generate-passcode", {
659
+ restaurantIds: e.restaurantIds,
660
+ excludePosUserId: e.excludePosUserId
661
+ })
662
+ )}`;
663
+ }
664
+ };
665
+ function De(e, t, i) {
666
+ if (e.some((o) => o.subject === "all")) return "All";
667
+ const n = (i ?? F).filter(
668
+ (o) => o.subject === t
669
+ ), r = new Set(n.map((o) => $(o).value)), s = e.filter((o) => o.subject === t).filter((o) => r.has($(o).value));
670
+ return s.length === n.length ? "All" : s.length === 0 ? "-" : `${s.length} permission allow`;
671
+ }
672
+ function $(e) {
673
+ const t = ne(e), i = t.subject;
674
+ return {
675
+ ...t,
676
+ get conditions() {
677
+ if (typeof t.conditions != "string") return t.conditions;
678
+ try {
679
+ return JSON.parse(t.conditions);
680
+ } catch {
681
+ return;
682
+ }
683
+ },
684
+ get isDiscountOperation() {
685
+ var n;
686
+ return i === j.F_RULE_SUBJECT.enum.order && ((n = this.conditions) == null ? void 0 : n.operation) === j.F_RULE_ORDER_OPERATION.enum.discount;
687
+ },
688
+ get isOrderOperation() {
689
+ return i === j.F_RULE_SUBJECT.enum.order;
690
+ },
691
+ get isReportPermission() {
692
+ return i === j.F_RULE_SUBJECT.enum.report;
693
+ },
694
+ /**
695
+ * Order and report rules are only meaningful together with the condition
696
+ * that names them. A rule missing it cannot be rendered or matched against
697
+ * the available permission list, so callers must preserve it verbatim —
698
+ * see `splitRoleFormPermissions`, which routes it to `passthrough`, not
699
+ * `dropped`. Dropping it would silently revoke a grant the portal cannot
700
+ * display (HRM-0027).
701
+ */
702
+ get isResolvable() {
703
+ return this.discriminator !== void 0;
704
+ },
705
+ /**
706
+ * The condition value that identifies this rule, if the subject needs one.
707
+ * An empty condition counts as missing: `{ name: '' }` is a known corrupted
708
+ * shape that used to resolve to the first hardcoded report permission on
709
+ * save (HRM-0027), so it must not look resolvable here either.
710
+ */
711
+ get discriminator() {
712
+ var n, r;
713
+ return this.isOrderOperation ? ((n = this.conditions) == null ? void 0 : n.operation) || void 0 : this.isReportPermission ? ((r = this.conditions) == null ? void 0 : r.name) || void 0 : i.toString();
714
+ },
715
+ get formatted() {
716
+ const n = this.discriminator;
717
+ return n === void 0 ? i.toString() : n.endsWith("_") ? n.slice(0, n.length - 1) : n;
718
+ },
719
+ get label() {
720
+ return t.label || ie(this.formatted);
721
+ },
722
+ get value() {
723
+ const n = this.discriminator;
724
+ return this.isOrderOperation || this.isReportPermission ? n === void 0 ? i.toString() : `${i}:${n}` : i.toString();
725
+ }
726
+ };
727
+ }
728
+ function We(e) {
729
+ var n, r;
730
+ const t = e.map((s) => $(s)).find((s) => s.isDiscountOperation);
731
+ if (!t) return 100;
732
+ const i = Number((r = (n = t.conditions) == null ? void 0 : n.adjustment) == null ? void 0 : r.$lte);
733
+ return Number.isFinite(i) ? parseInt((i * 100).toFixed(0)) : 0;
734
+ }
735
+ function ze(e, t) {
736
+ return t.isOwner ? { restaurantIds: null, roleIds: null } : { restaurantIds: ee(e), roleIds: te(e) };
737
+ }
738
+ function Ke(e) {
739
+ return (e == null ? void 0 : e.some((t) => t.subject === "all")) ?? !1;
740
+ }
741
+ function Ve(e) {
742
+ const t = $(e);
743
+ if (!t.isReportPermission) return;
744
+ const { name: i, ...n } = t.conditions ?? {};
745
+ return Object.keys(n).length > 0 ? n : void 0;
746
+ }
747
+ function He(e, t, i) {
748
+ return e.flatMap((n) => {
749
+ const r = Ae(n);
750
+ if (!r) return [];
751
+ const s = r.isReportPermission ? i == null ? void 0 : i.get(n) : void 0;
752
+ return [
753
+ {
754
+ subject: r.subject,
755
+ actions: r.actions,
756
+ conditions: {
757
+ ...r.conditions,
758
+ ...s ?? {},
759
+ adjustment: r.isDiscountOperation ? { $lte: parseFloat((t / 100).toFixed(2)) } : void 0
760
+ }
761
+ }
762
+ ];
763
+ });
764
+ }
765
+ function Ae(e) {
766
+ const t = e.indexOf(":"), i = t === -1 ? e : e.slice(0, t), n = t === -1 ? void 0 : e.slice(t + 1);
767
+ if (t !== -1 && !n) return;
768
+ let r;
769
+ return n ? (r = F.find((s) => {
770
+ if (s.subject !== i) return !1;
771
+ const o = typeof s.conditions == "string" ? JSON.parse(s.conditions) : s.conditions;
772
+ return [o == null ? void 0 : o.operation, o == null ? void 0 : o.name].includes(n);
773
+ }), !r && i === j.F_RULE_SUBJECT.enum.report && (r = {
774
+ label: "",
775
+ subject: j.F_RULE_SUBJECT.enum.report,
776
+ actions: ["read"],
777
+ conditions: { name: n },
778
+ inverted: !1,
779
+ reason: ""
780
+ })) : r = F.find((s) => s.subject === i), r ? $(r) : void 0;
781
+ }
782
+ function Qe(e, t) {
783
+ const i = { values: [], passthrough: [], dropped: [] };
784
+ for (const n of e) {
785
+ const r = n == null ? void 0 : n.actions;
786
+ if (typeof (n == null ? void 0 : n.subject) != "string" || n.subject.trim().length === 0 || !Array.isArray(r) || r.length === 0 || r.some((c) => typeof c != "string" || c.trim().length === 0)) {
787
+ i.dropped.push(n);
788
+ continue;
789
+ }
790
+ const s = $(n).value, o = `${j.F_RULE_SUBJECT.enum.report}:`, a = s.startsWith(o) ? s.slice(o.length) : "";
791
+ t.has(s) || a && a !== "undefined" ? i.values.push(s) : i.passthrough.push(n);
792
+ }
793
+ return i;
794
+ }
795
+ function Ne(e, t = []) {
796
+ return W(
797
+ e.reduce((i, n) => {
798
+ const r = Oe.find(
799
+ (s) => s.subject === n.subject && n.actions.includes("manage")
800
+ ) || t.find((s) => s.subject === n.subject);
801
+ if (r) {
802
+ const s = r.subject === h.Subject.Business.inventory_stock ? "Warehouse Management" : r.label;
803
+ i.push(s);
804
+ }
805
+ return i;
806
+ }, [])
807
+ );
808
+ }
809
+ export {
810
+ Le as D,
811
+ me as E,
812
+ ve as F,
813
+ ee as H,
814
+ de as I,
815
+ Fe as K,
816
+ te as L,
817
+ le as N,
818
+ ce as P,
819
+ Ie as R,
820
+ fe as T,
821
+ xe as U,
822
+ Te as V,
823
+ Re as a,
824
+ ze as b,
825
+ $e as c,
826
+ He as d,
827
+ Ve as e,
828
+ De as f,
829
+ We as g,
830
+ Ke as h,
831
+ X as i,
832
+ G as j,
833
+ Ne as m,
834
+ Oe as p,
835
+ Se as q,
836
+ $ as r,
837
+ Qe as s,
838
+ ke as t,
839
+ we as u,
840
+ ye as x,
841
+ Z as y
842
+ };