@oneclick.dev/cms-core-modules 0.0.114 → 0.0.116

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 (87) hide show
  1. package/dist/{ContentEditor-MctMvN7D.js → ContentEditor-CsbOFg3a.js} +52 -52
  2. package/dist/{ContentEditor-C5yNNLeV.mjs → ContentEditor-Df5uWpVC.mjs} +10337 -8677
  3. package/dist/EditLayout.vue_vue_type_script_setup_true_lang-gozJKXvM.js +1 -0
  4. package/dist/EditLayout.vue_vue_type_script_setup_true_lang-pDO9b4Pv.mjs +77 -0
  5. package/dist/NewReservationDialog.vue_vue_type_script_setup_true_lang-BHeMJ6nr.mjs +1476 -0
  6. package/dist/NewReservationDialog.vue_vue_type_script_setup_true_lang-C2zwt5UF.js +1 -0
  7. package/dist/OrderDetailDialog.vue_vue_type_script_setup_true_lang-BYSeUW_V.js +925 -0
  8. package/dist/OrderDetailDialog.vue_vue_type_script_setup_true_lang-DwAUYR8p.mjs +5021 -0
  9. package/dist/Overview-CBahJviK.js +1 -0
  10. package/dist/Overview-CVQ1pkuD.mjs +527 -0
  11. package/dist/TableView-Csv5Lycy.mjs +6234 -0
  12. package/dist/TableView-Cwal0BPW.js +4 -0
  13. package/dist/agenda-BSdlrfxv.mjs +1253 -0
  14. package/dist/agenda-Bev1mO7E.js +1 -0
  15. package/dist/availability-ClBGVgE9.js +1 -0
  16. package/dist/availability-D8JdA4rP.mjs +274 -0
  17. package/dist/booking-data-Px7XCIfU.mjs +1024 -0
  18. package/dist/booking-data-aMS1p_3g.js +1 -0
  19. package/dist/cms-core-modules.css +1 -1
  20. package/dist/exceptions-CqityDo9.mjs +651 -0
  21. package/dist/exceptions-DXqc0Nza.js +1 -0
  22. package/dist/index-CM4eaK5T.mjs +1245 -0
  23. package/dist/index-DliTZzwI.js +35 -0
  24. package/dist/index.cjs.js +1 -1
  25. package/dist/index.mjs +12 -11
  26. package/dist/orders-1swJVKw2.js +1 -0
  27. package/dist/orders-D41GbzIa.mjs +624 -0
  28. package/dist/payment-BJHgpaeT.js +1 -0
  29. package/dist/payment-D5j-68Ig.mjs +1278 -0
  30. package/dist/refunds-D9nTeD2d.mjs +436 -0
  31. package/dist/refunds-oVB2Opib.js +1 -0
  32. package/dist/resources-8WouFvJe.js +1 -0
  33. package/dist/resources-B-D5MUhV.mjs +975 -0
  34. package/dist/server-handlers.cjs.js +1 -1
  35. package/dist/server-handlers.mjs +626 -515
  36. package/dist/src/appointments/components/edit/EventDialog/BookingsList.vue.d.ts +146 -5
  37. package/dist/src/appointments/components/edit/EventDialog/CancelRefundReservationDialog.vue.d.ts +33 -0
  38. package/dist/src/appointments/components/edit/EventDialog/OrderDetailDialog.vue.d.ts +26 -8
  39. package/dist/src/appointments/components/edit/EventDialog/RefundDetailsDisplay.vue.d.ts +8 -0
  40. package/dist/src/appointments/components/edit/EventDialog/ReservationDetailDialog.vue.d.ts +91 -5
  41. package/dist/src/appointments/components/edit/EventDialog/TransferReservationDialog.vue.d.ts +20 -3
  42. package/dist/src/appointments/components/edit/NewReservationDialog/ReservationLines.vue.d.ts +5 -0
  43. package/dist/src/appointments/components/edit/OrderMetadataDisplay.vue.d.ts +20 -2
  44. package/dist/src/appointments/components/edit/dashboard/BookingsList.vue.d.ts +240 -0
  45. package/dist/src/appointments/composables/useAgendaMetadataSchema.d.ts +37 -0
  46. package/dist/src/appointments/pages/edit/orders.vue.d.ts +225 -0
  47. package/dist/src/appointments/pages/edit/refunds.vue.d.ts +2 -0
  48. package/dist/src/appointments/server.d.ts +2 -0
  49. package/dist/src/appointments/types.d.ts +6 -0
  50. package/dist/src/appointments/utils/printReservation.d.ts +65 -3
  51. package/dist/src/contentManager/components/content-editor/tiptap-extensions/table/Table.d.ts +36 -0
  52. package/dist/src/contentManager/components/content-editor/tiptap-extensions/table/Table.vue.d.ts +95 -0
  53. package/dist/src/contentManager/components/content-editor/tiptap-extensions/table/TableCell.d.ts +13 -0
  54. package/dist/src/contentManager/components/content-editor/tiptap-extensions/table/TableHeader.d.ts +6 -0
  55. package/dist/src/contentManager/components/content-editor/tiptap-extensions/table/TableRow.d.ts +6 -0
  56. package/dist/src/contentManager/components/content-editor/tiptap-extensions/table/index.d.ts +4 -0
  57. package/dist/src/contentManager/components/content-editor/tiptap-menus/element-editor-views/TableMenu.vue.d.ts +13 -0
  58. package/dist/src/contentManager/components/content-editor/tiptap-menus/element-editor-views/index.d.ts +14 -0
  59. package/package.json +2 -2
  60. package/dist/EditLayout.vue_vue_type_script_setup_true_lang-DWMqQvHl.mjs +0 -76
  61. package/dist/EditLayout.vue_vue_type_script_setup_true_lang-kpjbVSXg.js +0 -1
  62. package/dist/NewReservationDialog.vue_vue_type_script_setup_true_lang-Baqy-rTT.js +0 -1
  63. package/dist/NewReservationDialog.vue_vue_type_script_setup_true_lang-Dx4Bpa2m.mjs +0 -1263
  64. package/dist/OrderDetailDialog.vue_vue_type_script_setup_true_lang-COrK1j0S.js +0 -1
  65. package/dist/OrderDetailDialog.vue_vue_type_script_setup_true_lang-Vb3q8EVv.mjs +0 -330
  66. package/dist/Overview-98nkJUWN.mjs +0 -481
  67. package/dist/Overview-Dl8cMlsr.js +0 -1
  68. package/dist/ReservationDetailDialog.vue_vue_type_script_setup_true_lang-CuwREvXD.js +0 -349
  69. package/dist/ReservationDetailDialog.vue_vue_type_script_setup_true_lang-GYNZ_yhD.mjs +0 -3077
  70. package/dist/TableView-CVfkyj1k.js +0 -4
  71. package/dist/TableView-zDx0IegJ.mjs +0 -6096
  72. package/dist/agenda-BaJu3-1c.js +0 -1
  73. package/dist/agenda-BwVY_8oM.mjs +0 -1165
  74. package/dist/availability-CMrRa5y2.mjs +0 -269
  75. package/dist/availability-Cf2YfMwM.js +0 -1
  76. package/dist/booking-data-DgJd0BcM.mjs +0 -889
  77. package/dist/booking-data-Di5GmH_8.js +0 -1
  78. package/dist/exceptions-B6P9UiCj.js +0 -1
  79. package/dist/exceptions-De9-FvdP.mjs +0 -646
  80. package/dist/index-DL6orwdK.js +0 -35
  81. package/dist/index-hH3e-IYz.mjs +0 -1187
  82. package/dist/orders-C65SlpJy.mjs +0 -618
  83. package/dist/orders-XVzWAgG1.js +0 -1
  84. package/dist/payment-C3ohkehF.mjs +0 -1080
  85. package/dist/payment-Dfr-Ro-a.js +0 -1
  86. package/dist/resources-CxeFd57z.js +0 -1
  87. package/dist/resources-DwYxn2Vi.mjs +0 -811
@@ -1,289 +1,400 @@
1
- import { createRouter as v, defineEventHandler as w, createError as y, getRouterParam as q, getQuery as C } from "h3";
1
+ import { createRouter as E, defineEventHandler as h, createError as p, getRouterParam as F, getQuery as I, readBody as O } from "h3";
2
2
  import "vue";
3
- function $(h) {
4
- const { initFirebase: P, normalizeTimestamps: A } = h, g = v();
5
- async function m(u) {
6
- const { supabase: i, instanceId: d } = u.context.module, { data: e, error: o } = await i.from("project_modules").select("config").eq("id", d).single();
7
- if (o || !e?.config)
8
- throw y({ statusCode: 500, statusMessage: "Failed to load module config." });
9
- const s = e.config, t = s.project, a = s.productCollection || "products";
10
- if (!t)
11
- throw y({ statusCode: 400, statusMessage: "Products module has no Firebase integration configured." });
12
- return { firebase: await P(u, t), collection: a };
3
+ function z(A) {
4
+ const { initFirebase: P, normalizeTimestamps: S } = A, f = E();
5
+ async function u(l) {
6
+ const { supabase: y, instanceId: D } = l.context.module, { data: t, error: c } = await y.from("project_modules").select("config").eq("id", D).single();
7
+ if (c || !t?.config)
8
+ throw p({ statusCode: 500, statusMessage: "Failed to load module config." });
9
+ const i = t.config, s = i.project, a = i.productCollection || "products";
10
+ if (!s)
11
+ throw p({ statusCode: 400, statusMessage: "Products module has no Firebase integration configured." });
12
+ return { firebase: await P(l, s), collection: a };
13
13
  }
14
- return g.get("/products", w(async (u) => {
14
+ return f.get("/products", h(async (l) => {
15
15
  try {
16
- const { firebase: i, collection: d } = await m(u);
17
- return (await i.firestore().collection(d).get()).docs.map((o) => A({
18
- id: o.id,
19
- ...o.data()
16
+ const { firebase: y, collection: D } = await u(l);
17
+ return (await y.firestore().collection(D).get()).docs.map((c) => S({
18
+ id: c.id,
19
+ ...c.data()
20
20
  }));
21
- } catch (i) {
22
- throw console.error("Products handler — list error:", i), y({
23
- statusCode: i.statusCode || 500,
24
- statusMessage: i.statusMessage || "Failed to list products"
21
+ } catch (y) {
22
+ throw console.error("Products handler — list error:", y), p({
23
+ statusCode: y.statusCode || 500,
24
+ statusMessage: y.statusMessage || "Failed to list products"
25
25
  });
26
26
  }
27
- })), g.get("/products/:productId", w(async (u) => {
28
- const i = q(u, "productId");
29
- if (!i)
30
- throw y({ statusCode: 400, statusMessage: "Product ID is required." });
27
+ })), f.get("/products/:productId", h(async (l) => {
28
+ const y = F(l, "productId");
29
+ if (!y)
30
+ throw p({ statusCode: 400, statusMessage: "Product ID is required." });
31
31
  try {
32
- const { firebase: d, collection: e } = await m(u), o = await d.firestore().collection(e).doc(i).get();
33
- if (!o.exists)
34
- throw y({ statusCode: 404, statusMessage: "Product not found." });
35
- return A({
36
- id: o.id,
37
- ...o.data()
38
- });
39
- } catch (d) {
40
- throw console.error("Products handler — get error:", d), y({
41
- statusCode: d.statusCode || 500,
42
- statusMessage: d.statusMessage || "Failed to get product"
32
+ const { firebase: D, collection: t } = await u(l), c = await D.firestore().collection(t).doc(y).get();
33
+ if (!c.exists)
34
+ throw p({ statusCode: 404, statusMessage: "Product not found." });
35
+ return S({
36
+ id: c.id,
37
+ ...c.data()
38
+ });
39
+ } catch (D) {
40
+ throw console.error("Products handler — get error:", D), p({
41
+ statusCode: D.statusCode || 500,
42
+ statusMessage: D.statusMessage || "Failed to get product"
43
43
  });
44
44
  }
45
- })), g.get("/empty-stock", w(async (u) => {
46
- const d = C(u).category;
45
+ })), f.get("/empty-stock", h(async (l) => {
46
+ const D = I(l).category;
47
47
  try {
48
- const { firebase: e, collection: o } = await m(u);
49
- let s = e.firestore().collection(o).where("stock", "==", 0);
50
- d && (s = s.where("collections", "array-contains", d));
51
- const a = (await s.get()).docs.map((n) => A({
52
- id: n.id,
53
- ...n.data()
48
+ const { firebase: t, collection: c } = await u(l);
49
+ let i = t.firestore().collection(c).where("stock", "==", 0);
50
+ D && (i = i.where("collections", "array-contains", D));
51
+ const a = (await i.get()).docs.map((r) => S({
52
+ id: r.id,
53
+ ...r.data()
54
54
  }));
55
55
  return {
56
56
  count: a.length,
57
- products: a.map((n) => ({
58
- id: n.id,
59
- title: n.title,
60
- slug: n.slug,
61
- stock: n.stock,
62
- price: n.price,
63
- currency: n.currency,
64
- status: n.status
57
+ products: a.map((r) => ({
58
+ id: r.id,
59
+ title: r.title,
60
+ slug: r.slug,
61
+ stock: r.stock,
62
+ price: r.price,
63
+ currency: r.currency,
64
+ status: r.status
65
65
  }))
66
66
  };
67
- } catch (e) {
68
- throw console.error("Products handler — empty-stock error:", e), y({
69
- statusCode: e.statusCode || 500,
70
- statusMessage: e.statusMessage || "Failed to query empty stock"
67
+ } catch (t) {
68
+ throw console.error("Products handler — empty-stock error:", t), p({
69
+ statusCode: t.statusCode || 500,
70
+ statusMessage: t.statusMessage || "Failed to query empty stock"
71
71
  });
72
72
  }
73
- })), g.handler;
73
+ })), f.handler;
74
74
  }
75
- function x(h) {
76
- const { initFirebase: P, normalizeTimestamps: A } = h, g = v();
77
- async function m(i) {
78
- const { supabase: d, instanceId: e } = i.context.module, { data: o, error: s } = await d.from("project_modules").select("config").eq("id", e).single();
79
- if (s || !o?.config)
80
- throw y({ statusCode: 500, statusMessage: "Failed to load module config." });
81
- const t = o.config, a = t.project, n = t.reservationsCollection || "bookings_orders", r = t.agendaCollection || "agendas";
82
- if (!a)
83
- throw y({ statusCode: 400, statusMessage: "Appointments module has no Firebase integration configured." });
84
- return { firebase: await P(i, a), reservationsCollection: n, agendaCollection: r };
75
+ function J(A) {
76
+ const { initFirebase: P, normalizeTimestamps: S, deleteField: f } = A, u = E(), l = "privateSettings", y = "refundFlow", D = "metadataSchema";
77
+ async function t(e) {
78
+ const { supabase: n, instanceId: o } = e.context.module, { data: d, error: g } = await n.from("project_modules").select("config").eq("id", o).single();
79
+ if (g || !d?.config)
80
+ throw p({ statusCode: 500, statusMessage: "Failed to load module config." });
81
+ const m = d.config, w = m.project, C = m.reservationsCollection || "bookings_orders", R = m.agendaCollection || "agendas";
82
+ if (!w)
83
+ throw p({ statusCode: 400, statusMessage: "Appointments module has no Firebase integration configured." });
84
+ return { firebase: await P(e, w), reservationsCollection: C, agendaCollection: R };
85
85
  }
86
- function u(i) {
87
- return (i.reservations || []).map((e) => ({
88
- orderId: i.id,
89
- reservationId: e.id,
90
- customerInfo: i.customerInfo,
91
- date: e.date,
92
- startTime: e.timeslot?.startTime,
93
- endTime: e.timeslot?.endTime,
94
- spots: e.spots,
95
- status: i.status,
96
- reservationStatus: e.status,
97
- resourceId: e.resourceId,
98
- reservationPrice: e.totalPrice,
99
- reservationBasePrice: e.basePrice,
100
- reservationAddOnsPrice: e.addOnsPrice,
101
- pricingOption: e.pricingOption,
102
- amountDue: i.amountDue,
103
- amountPaid: i.amountPaid,
104
- createdAt: i.createdAt,
105
- metadata: i.metadata || {},
106
- reservationMetadata: e.metadata || {}
86
+ function c(e) {
87
+ return (e.reservations || []).map((o) => ({
88
+ orderId: e.id,
89
+ reservationId: o.id,
90
+ customerInfo: e.customerInfo,
91
+ date: o.date,
92
+ startTime: o.timeslot?.startTime,
93
+ endTime: o.timeslot?.endTime,
94
+ spots: o.spots,
95
+ status: e.status,
96
+ reservationStatus: o.status,
97
+ resourceId: o.resourceId,
98
+ reservationPrice: o.totalPrice,
99
+ reservationBasePrice: o.basePrice,
100
+ reservationAddOnsPrice: o.addOnsPrice,
101
+ pricingOption: o.pricingOption,
102
+ amountDue: e.amountDue,
103
+ amountPaid: e.amountPaid,
104
+ createdAt: e.createdAt,
105
+ metadata: e.metadata || {},
106
+ reservationMetadata: o.metadata || {}
107
107
  }));
108
108
  }
109
- return g.get("/agendas", w(async (i) => {
109
+ function i(e) {
110
+ return {
111
+ showAmount: e?.showAmount !== !1,
112
+ fields: Array.isArray(e?.fields) ? e.fields : []
113
+ };
114
+ }
115
+ function s() {
116
+ return f ? {
117
+ refundFlow: f(),
118
+ refundFlowEnabled: f(),
119
+ refundDialog: f()
120
+ } : {
121
+ refundFlow: null,
122
+ refundFlowEnabled: null,
123
+ refundDialog: null
124
+ };
125
+ }
126
+ function a(e) {
127
+ return Array.isArray(e) ? e : [];
128
+ }
129
+ function r() {
130
+ return f ? {
131
+ metadataSchema: f()
132
+ } : {
133
+ metadataSchema: null
134
+ };
135
+ }
136
+ return u.get("/agendas", h(async (e) => {
110
137
  try {
111
- const { firebase: d, agendaCollection: e } = await m(i), s = (await d.firestore().collection(e).get()).docs.map((t) => {
112
- const a = t.data();
138
+ const { firebase: n, agendaCollection: o } = await t(e), g = (await n.firestore().collection(o).get()).docs.map((m) => {
139
+ const w = m.data();
113
140
  return {
114
- id: t.id,
115
- serviceName: a.serviceName || "",
116
- type: a.type || "regular"
141
+ id: m.id,
142
+ serviceName: w.serviceName || "",
143
+ type: w.type || "regular"
117
144
  };
118
145
  });
119
146
  return {
120
- count: s.length,
121
- agendas: s
147
+ count: g.length,
148
+ agendas: g
122
149
  };
123
- } catch (d) {
124
- throw console.error("Appointments handler — list agendas error:", d), y({
125
- statusCode: d.statusCode || 500,
126
- statusMessage: d.statusMessage || "Failed to list agendas"
150
+ } catch (n) {
151
+ throw console.error("Appointments handler — list agendas error:", n), p({
152
+ statusCode: n.statusCode || 500,
153
+ statusMessage: n.statusMessage || "Failed to list agendas"
127
154
  });
128
155
  }
129
- })), g.get("/agendas/:agendaId/opening-hours", w(async (i) => {
130
- const d = q(i, "agendaId"), o = C(i).date;
156
+ })), u.get("/agendas/:agendaId/opening-hours", h(async (e) => {
157
+ const n = F(e, "agendaId"), d = I(e).date;
158
+ if (!n)
159
+ throw p({ statusCode: 400, statusMessage: "Agenda ID is required." });
131
160
  if (!d)
132
- throw y({ statusCode: 400, statusMessage: "Agenda ID is required." });
133
- if (!o)
134
- throw y({ statusCode: 400, statusMessage: "Date is required (YYYY-MM-DD)." });
161
+ throw p({ statusCode: 400, statusMessage: "Date is required (YYYY-MM-DD)." });
135
162
  try {
136
- const { firebase: s, agendaCollection: t } = await m(i), a = await s.firestore().collection(t).doc(d).get();
137
- if (!a.exists)
138
- throw y({ statusCode: 404, statusMessage: "Agenda not found." });
139
- const n = a.data(), r = (n.resources || []).filter((f) => f.isActive), c = n.exceptions || [], p = (/* @__PURE__ */ new Date(o + "T00:00:00")).getDay(), D = r.map((f) => {
140
- const R = f.openingHours?.[p] || [], I = c.find((S) => {
141
- const b = o >= S.startDate && o <= S.endDate, M = !S.resourceIds || S.resourceIds.length === 0 || S.resourceIds.includes(f.id);
142
- return b && M;
163
+ const { firebase: g, agendaCollection: m } = await t(e), w = await g.firestore().collection(m).doc(n).get();
164
+ if (!w.exists)
165
+ throw p({ statusCode: 404, statusMessage: "Agenda not found." });
166
+ const C = w.data(), R = (C.resources || []).filter((v) => v.isActive), M = C.exceptions || [], q = (/* @__PURE__ */ new Date(d + "T00:00:00")).getDay(), N = R.map((v) => {
167
+ const V = v.openingHours?.[q] || [], U = M.find((T) => {
168
+ const G = d >= T.startDate && d <= T.endDate, j = !T.resourceIds || T.resourceIds.length === 0 || T.resourceIds.includes(v.id);
169
+ return G && j;
143
170
  });
144
- return I ? {
145
- resourceId: f.id,
146
- resourceName: f.name,
147
- date: o,
148
- dayOfWeek: p,
149
- isClosed: I.isClosed,
150
- hours: I.isClosed ? [] : (I.timeslots || []).map((S) => ({
151
- start: S.startTime,
152
- end: S.endTime
171
+ return U ? {
172
+ resourceId: v.id,
173
+ resourceName: v.name,
174
+ date: d,
175
+ dayOfWeek: q,
176
+ isClosed: U.isClosed,
177
+ hours: U.isClosed ? [] : (U.timeslots || []).map((T) => ({
178
+ start: T.startTime,
179
+ end: T.endTime
153
180
  })),
154
181
  isException: !0
155
182
  } : {
156
- resourceId: f.id,
157
- resourceName: f.name,
158
- date: o,
159
- dayOfWeek: p,
160
- isClosed: R.length === 0,
161
- hours: R,
183
+ resourceId: v.id,
184
+ resourceName: v.name,
185
+ date: d,
186
+ dayOfWeek: q,
187
+ isClosed: V.length === 0,
188
+ hours: V,
162
189
  isException: !1
163
190
  };
164
191
  });
165
192
  return {
166
- agendaId: d,
167
- serviceName: n.serviceName || "",
168
- date: o,
169
- resources: D
193
+ agendaId: n,
194
+ serviceName: C.serviceName || "",
195
+ date: d,
196
+ resources: N
197
+ };
198
+ } catch (g) {
199
+ throw console.error("Appointments handler — opening hours error:", g), p({
200
+ statusCode: g.statusCode || 500,
201
+ statusMessage: g.statusMessage || "Failed to get opening hours"
202
+ });
203
+ }
204
+ })), u.get("/agendas/:agendaId/refund-flow", h(async (e) => {
205
+ const n = F(e, "agendaId");
206
+ if (!n)
207
+ throw p({ statusCode: 400, statusMessage: "Agenda ID is required." });
208
+ try {
209
+ const { firebase: o, agendaCollection: d } = await t(e), m = o.firestore().collection(d).doc(n), w = m.collection(l).doc(y), [C, R] = await Promise.all([
210
+ m.get(),
211
+ w.get()
212
+ ]);
213
+ if (!C.exists)
214
+ throw p({ statusCode: 404, statusMessage: "Agenda not found." });
215
+ const M = R.exists ? R.data() || {} : {};
216
+ return {
217
+ refundFlow: M.flow || {},
218
+ refundFlowEnabled: M.enabled !== !1,
219
+ refundDialog: i(M.dialog)
170
220
  };
171
- } catch (s) {
172
- throw console.error("Appointments handler — opening hours error:", s), y({
173
- statusCode: s.statusCode || 500,
174
- statusMessage: s.statusMessage || "Failed to get opening hours"
221
+ } catch (o) {
222
+ throw console.error("Appointments handler — refund flow load error:", o), p({
223
+ statusCode: o.statusCode || 500,
224
+ statusMessage: o.statusMessage || "Failed to load refund flow"
175
225
  });
176
226
  }
177
- })), g.get("/appointments", w(async (i) => {
178
- const d = C(i), e = Math.min(Number(d.quantity) || 20, 100), o = d.status || "confirmed";
227
+ })), u.patch("/agendas/:agendaId/refund-flow", h(async (e) => {
228
+ const n = F(e, "agendaId");
229
+ if (!n)
230
+ throw p({ statusCode: 400, statusMessage: "Agenda ID is required." });
179
231
  try {
180
- const { firebase: s, reservationsCollection: t } = await m(i), n = (await s.firestore().collection(t).orderBy("createdAt", "desc").where("status", "==", o).limit(e).get()).docs.flatMap(
181
- (r) => u(A({ id: r.id, ...r.data() }))
232
+ const o = await O(e), { firebase: d, agendaCollection: g } = await t(e), m = d.firestore(), w = m.collection(g).doc(n), C = w.collection(l).doc(y), R = i(o?.refundDialog);
233
+ if (!(await w.get()).exists)
234
+ throw p({ statusCode: 404, statusMessage: "Agenda not found." });
235
+ const k = m.batch();
236
+ return k.set(C, {
237
+ flow: o?.refundFlow || {},
238
+ enabled: o?.refundFlowEnabled !== !1,
239
+ dialog: R,
240
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
241
+ }, { merge: !0 }), k.set(w, s(), { merge: !0 }), await k.commit(), { success: !0 };
242
+ } catch (o) {
243
+ throw console.error("Appointments handler — refund flow save error:", o), p({
244
+ statusCode: o.statusCode || 500,
245
+ statusMessage: o.statusMessage || "Failed to save refund flow"
246
+ });
247
+ }
248
+ })), u.get("/agendas/:agendaId/metadata-schema", h(async (e) => {
249
+ const n = F(e, "agendaId");
250
+ if (!n)
251
+ throw p({ statusCode: 400, statusMessage: "Agenda ID is required." });
252
+ try {
253
+ const { firebase: o, agendaCollection: d } = await t(e), m = o.firestore().collection(d).doc(n), w = m.collection(l).doc(D), [C, R] = await Promise.all([
254
+ m.get(),
255
+ w.get()
256
+ ]);
257
+ if (!C.exists)
258
+ throw p({ statusCode: 404, statusMessage: "Agenda not found." });
259
+ const M = R.exists ? R.data() || {} : {};
260
+ return {
261
+ metadataSchema: a(M.schema)
262
+ };
263
+ } catch (o) {
264
+ throw console.error("Appointments handler — metadata schema load error:", o), p({
265
+ statusCode: o.statusCode || 500,
266
+ statusMessage: o.statusMessage || "Failed to load metadata schema"
267
+ });
268
+ }
269
+ })), u.patch("/agendas/:agendaId/metadata-schema", h(async (e) => {
270
+ const n = F(e, "agendaId");
271
+ if (!n)
272
+ throw p({ statusCode: 400, statusMessage: "Agenda ID is required." });
273
+ try {
274
+ const o = await O(e), { firebase: d, agendaCollection: g } = await t(e), m = d.firestore(), w = m.collection(g).doc(n), C = w.collection(l).doc(D);
275
+ if (!(await w.get()).exists)
276
+ throw p({ statusCode: 404, statusMessage: "Agenda not found." });
277
+ const M = m.batch();
278
+ return M.set(C, {
279
+ schema: a(o?.metadataSchema),
280
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
281
+ }, { merge: !0 }), M.set(w, r(), { merge: !0 }), await M.commit(), { success: !0 };
282
+ } catch (o) {
283
+ throw console.error("Appointments handler — metadata schema save error:", o), p({
284
+ statusCode: o.statusCode || 500,
285
+ statusMessage: o.statusMessage || "Failed to save metadata schema"
286
+ });
287
+ }
288
+ })), u.get("/appointments", h(async (e) => {
289
+ const n = I(e), o = Math.min(Number(n.quantity) || 20, 100), d = n.status || "confirmed";
290
+ try {
291
+ const { firebase: g, reservationsCollection: m } = await t(e), C = (await g.firestore().collection(m).orderBy("createdAt", "desc").where("status", "==", d).limit(o).get()).docs.flatMap(
292
+ (R) => c(S({ id: R.id, ...R.data() }))
182
293
  );
183
294
  return {
184
- count: n.length,
185
- appointments: n
295
+ count: C.length,
296
+ appointments: C
186
297
  };
187
- } catch (s) {
188
- throw console.error("Appointments handler — list error:", s), y({
189
- statusCode: s.statusCode || 500,
190
- statusMessage: s.statusMessage || "Failed to list appointments"
298
+ } catch (g) {
299
+ throw console.error("Appointments handler — list error:", g), p({
300
+ statusCode: g.statusCode || 500,
301
+ statusMessage: g.statusMessage || "Failed to list appointments"
191
302
  });
192
303
  }
193
- })), g.get("/appointments/find", w(async (i) => {
194
- const d = C(i), e = (d.name || "").toLowerCase().trim(), o = (d.email || "").toLowerCase().trim(), s = d.date;
304
+ })), u.get("/appointments/find", h(async (e) => {
305
+ const n = I(e), o = (n.name || "").toLowerCase().trim(), d = (n.email || "").toLowerCase().trim(), g = n.date;
195
306
  try {
196
- const { firebase: t, reservationsCollection: a } = await m(i);
197
- let n = t.firestore().collection(a);
198
- o && (n = n.where("customerInfo.email", "==", o));
199
- let c = (await n.orderBy("createdAt", "desc").limit(200).get()).docs.flatMap(
200
- (l) => u(A({ id: l.id, ...l.data() }))
307
+ const { firebase: m, reservationsCollection: w } = await t(e);
308
+ let C = m.firestore().collection(w);
309
+ d && (C = C.where("customerInfo.email", "==", d));
310
+ let M = (await C.orderBy("createdAt", "desc").limit(200).get()).docs.flatMap(
311
+ (k) => c(S({ id: k.id, ...k.data() }))
201
312
  );
202
- return s && (c = c.filter((l) => l.date === s)), e && (c = c.filter((l) => {
203
- const p = (l.customerInfo?.firstName || "").toLowerCase(), D = (l.customerInfo?.lastName || "").toLowerCase();
204
- return p.includes(e) || D.includes(e) || `${p} ${D}`.includes(e);
313
+ return g && (M = M.filter((k) => k.date === g)), o && (M = M.filter((k) => {
314
+ const q = (k.customerInfo?.firstName || "").toLowerCase(), N = (k.customerInfo?.lastName || "").toLowerCase();
315
+ return q.includes(o) || N.includes(o) || `${q} ${N}`.includes(o);
205
316
  })), {
206
- count: c.length,
207
- appointments: c
317
+ count: M.length,
318
+ appointments: M
208
319
  };
209
- } catch (t) {
210
- throw console.error("Appointments handler — find error:", t), y({
211
- statusCode: t.statusCode || 500,
212
- statusMessage: t.statusMessage || "Failed to find appointments"
320
+ } catch (m) {
321
+ throw console.error("Appointments handler — find error:", m), p({
322
+ statusCode: m.statusCode || 500,
323
+ statusMessage: m.statusMessage || "Failed to find appointments"
213
324
  });
214
325
  }
215
- })), g.get("/appointments/:appointmentId", w(async (i) => {
216
- const d = q(i, "appointmentId");
217
- if (!d)
218
- throw y({ statusCode: 400, statusMessage: "Appointment ID is required." });
326
+ })), u.get("/appointments/:appointmentId", h(async (e) => {
327
+ const n = F(e, "appointmentId");
328
+ if (!n)
329
+ throw p({ statusCode: 400, statusMessage: "Appointment ID is required." });
219
330
  try {
220
- const { firebase: e, reservationsCollection: o } = await m(i), s = await e.firestore().collection(o).doc(d).get();
221
- if (!s.exists)
222
- throw y({ statusCode: 404, statusMessage: "Appointment not found." });
223
- const t = A({ id: s.id, ...s.data() });
331
+ const { firebase: o, reservationsCollection: d } = await t(e), g = await o.firestore().collection(d).doc(n).get();
332
+ if (!g.exists)
333
+ throw p({ statusCode: 404, statusMessage: "Appointment not found." });
334
+ const m = S({ id: g.id, ...g.data() });
224
335
  return {
225
- ...t,
226
- reservations: u(t)
336
+ ...m,
337
+ reservations: c(m)
227
338
  };
228
- } catch (e) {
229
- throw console.error("Appointments handler — get error:", e), y({
230
- statusCode: e.statusCode || 500,
231
- statusMessage: e.statusMessage || "Failed to get appointment"
339
+ } catch (o) {
340
+ throw console.error("Appointments handler — get error:", o), p({
341
+ statusCode: o.statusCode || 500,
342
+ statusMessage: o.statusMessage || "Failed to get appointment"
232
343
  });
233
344
  }
234
- })), g.handler;
345
+ })), u.handler;
235
346
  }
236
- const T = "https://analyticsdata.googleapis.com/v1beta", V = [
347
+ const x = "https://analyticsdata.googleapis.com/v1beta", H = [
237
348
  "https://www.googleapis.com/auth/analytics.readonly",
238
349
  "https://www.googleapis.com/auth/webmasters.readonly"
239
- ], N = "https://searchconsole.googleapis.com/webmasters/v3";
240
- function G(h) {
241
- const { decrypt: P, getGoogleAccessToken: A } = h, g = v();
242
- async function m(e) {
243
- const { supabase: o, instanceId: s } = e.context.module, { data: t, error: a } = await o.from("project_modules").select("config").eq("id", s).single();
244
- if (a || !t?.config)
245
- throw y({ statusCode: 500, statusMessage: "Failed to load module config." });
246
- const n = t.config, r = n.propertyId, c = n.serviceAccount, l = n.siteUrl || "";
247
- if (!c)
248
- throw y({ statusCode: 400, statusMessage: "No Google Service Account configured for this module." });
249
- if (!r)
250
- throw y({ statusCode: 400, statusMessage: "No GA4 Property ID configured for this module." });
251
- const { data: p, error: D } = await o.from("integrations").select("config").eq("id", c).single();
252
- let f = p?.config;
253
- if (D || !f) {
254
- const { data: M, error: F } = await o.from("agency_integrations").select("config").eq("id", c).single();
255
- if (F || !M?.config)
256
- throw y({ statusCode: 500, statusMessage: "Failed to load Google Service Account credentials." });
257
- f = M.config;
350
+ ], B = "https://searchconsole.googleapis.com/webmasters/v3";
351
+ function W(A) {
352
+ const { decrypt: P, getGoogleAccessToken: S } = A, f = E();
353
+ async function u(t) {
354
+ const { supabase: c, instanceId: i } = t.context.module, { data: s, error: a } = await c.from("project_modules").select("config").eq("id", i).single();
355
+ if (a || !s?.config)
356
+ throw p({ statusCode: 500, statusMessage: "Failed to load module config." });
357
+ const r = s.config, e = r.propertyId, n = r.serviceAccount, o = r.siteUrl || "";
358
+ if (!n)
359
+ throw p({ statusCode: 400, statusMessage: "No Google Service Account configured for this module." });
360
+ if (!e)
361
+ throw p({ statusCode: 400, statusMessage: "No GA4 Property ID configured for this module." });
362
+ const { data: d, error: g } = await c.from("integrations").select("config").eq("id", n).single();
363
+ let m = d?.config;
364
+ if (g || !m) {
365
+ const { data: k, error: q } = await c.from("agency_integrations").select("config").eq("id", n).single();
366
+ if (q || !k?.config)
367
+ throw p({ statusCode: 500, statusMessage: "Failed to load Google Service Account credentials." });
368
+ m = k.config;
258
369
  }
259
- const R = P(f.clientEmail), I = P(f.privateKey), S = P(f.projectId);
260
- return { accessToken: await A(
261
- { clientEmail: R, privateKey: I, projectId: S },
262
- V
263
- ), propertyId: r, siteUrl: l };
370
+ const w = P(m.clientEmail), C = P(m.privateKey), R = P(m.projectId);
371
+ return { accessToken: await S(
372
+ { clientEmail: w, privateKey: C, projectId: R },
373
+ H
374
+ ), propertyId: e, siteUrl: o };
264
375
  }
265
- async function u(e, o, s) {
266
- const t = await fetch(`${T}/properties/${o}:runReport`, {
376
+ async function l(t, c, i) {
377
+ const s = await fetch(`${x}/properties/${c}:runReport`, {
267
378
  method: "POST",
268
379
  headers: {
269
- Authorization: `Bearer ${e}`,
380
+ Authorization: `Bearer ${t}`,
270
381
  "Content-Type": "application/json"
271
382
  },
272
- body: JSON.stringify(s)
383
+ body: JSON.stringify(i)
273
384
  });
274
- if (!t.ok) {
275
- const a = await t.json().catch(() => ({}));
276
- throw console.error("GA4 runReport failed:", a), y({
277
- statusCode: t.status,
385
+ if (!s.ok) {
386
+ const a = await s.json().catch(() => ({}));
387
+ throw console.error("GA4 runReport failed:", a), p({
388
+ statusCode: s.status,
278
389
  statusMessage: a?.error?.message || "GA4 API request failed"
279
390
  });
280
391
  }
281
- return t.json();
392
+ return s.json();
282
393
  }
283
- g.get(
394
+ f.get(
284
395
  "/report",
285
- w(async (e) => {
286
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = a.match(/^(\d+)daysAgo$/), c = r ? parseInt(r[1], 10) : 30, l = `${c * 2}daysAgo`, p = `${c + 1}daysAgo`, D = [
396
+ h(async (t) => {
397
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = a.match(/^(\d+)daysAgo$/), n = e ? parseInt(e[1], 10) : 30, o = `${n * 2}daysAgo`, d = `${n + 1}daysAgo`, g = [
287
398
  { name: "sessions" },
288
399
  { name: "totalUsers" },
289
400
  { name: "screenPageViews" },
@@ -294,38 +405,38 @@ function G(h) {
294
405
  { name: "sessionsPerUser" },
295
406
  { name: "screenPageViewsPerSession" }
296
407
  ];
297
- let f, R = !0;
408
+ let m, w = !0;
298
409
  try {
299
- f = await u(o, s, {
410
+ m = await l(c, i, {
300
411
  dateRanges: [
301
- { startDate: a, endDate: n, name: "current" },
302
- { startDate: l, endDate: p, name: "previous" }
412
+ { startDate: a, endDate: r, name: "current" },
413
+ { startDate: o, endDate: d, name: "previous" }
303
414
  ],
304
415
  dimensions: [{ name: "date" }],
305
- metrics: D,
416
+ metrics: g,
306
417
  metricAggregations: ["TOTAL"],
307
418
  orderBys: [{ dimension: { dimensionName: "date" } }]
308
419
  });
309
420
  } catch {
310
- R = !1, f = await u(o, s, {
311
- dateRanges: [{ startDate: a, endDate: n }],
421
+ w = !1, m = await l(c, i, {
422
+ dateRanges: [{ startDate: a, endDate: r }],
312
423
  dimensions: [{ name: "date" }],
313
- metrics: D,
424
+ metrics: g,
314
425
  metricAggregations: ["TOTAL"],
315
426
  orderBys: [{ dimension: { dimensionName: "date" } }]
316
427
  });
317
428
  }
318
- return E(f, R);
429
+ return L(m, w);
319
430
  })
320
- ), g.get(
431
+ ), f.get(
321
432
  "/realtime",
322
- w(async (e) => {
323
- const { accessToken: o, propertyId: s } = await m(e), t = await fetch(
324
- `${T}/properties/${s}:runRealtimeReport`,
433
+ h(async (t) => {
434
+ const { accessToken: c, propertyId: i } = await u(t), s = await fetch(
435
+ `${x}/properties/${i}:runRealtimeReport`,
325
436
  {
326
437
  method: "POST",
327
438
  headers: {
328
- Authorization: `Bearer ${o}`,
439
+ Authorization: `Bearer ${c}`,
329
440
  "Content-Type": "application/json"
330
441
  },
331
442
  body: JSON.stringify({
@@ -336,24 +447,24 @@ function G(h) {
336
447
  })
337
448
  }
338
449
  );
339
- if (!t.ok) {
340
- const c = await t.json().catch(() => ({}));
341
- throw y({ statusCode: t.status, statusMessage: c?.error?.message || "Realtime API failed" });
450
+ if (!s.ok) {
451
+ const n = await s.json().catch(() => ({}));
452
+ throw p({ statusCode: s.status, statusMessage: n?.error?.message || "Realtime API failed" });
342
453
  }
343
- const a = await t.json(), n = (a?.rows || []).reduce(
344
- (c, l) => c + parseInt(l.metricValues?.[0]?.value || "0", 10),
454
+ const a = await s.json(), r = (a?.rows || []).reduce(
455
+ (n, o) => n + parseInt(o.metricValues?.[0]?.value || "0", 10),
345
456
  0
346
- ), r = (a?.rows || []).map((c) => ({
347
- page: c.dimensionValues?.[0]?.value || "(not set)",
348
- activeUsers: parseInt(c.metricValues?.[0]?.value || "0", 10)
457
+ ), e = (a?.rows || []).map((n) => ({
458
+ page: n.dimensionValues?.[0]?.value || "(not set)",
459
+ activeUsers: parseInt(n.metricValues?.[0]?.value || "0", 10)
349
460
  }));
350
- return { activeUsers: n, activePages: r };
461
+ return { activeUsers: r, activePages: e };
351
462
  })
352
- ), g.get(
463
+ ), f.get(
353
464
  "/top-pages",
354
- w(async (e) => {
355
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = parseInt(t.limit || "10", 10), c = await u(o, s, {
356
- dateRanges: [{ startDate: a, endDate: n }],
465
+ h(async (t) => {
466
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = parseInt(s.limit || "10", 10), n = await l(c, i, {
467
+ dateRanges: [{ startDate: a, endDate: r }],
357
468
  dimensions: [{ name: "pagePath" }],
358
469
  metrics: [
359
470
  { name: "screenPageViews" },
@@ -361,25 +472,25 @@ function G(h) {
361
472
  { name: "averageSessionDuration" }
362
473
  ],
363
474
  orderBys: [{ metric: { metricName: "screenPageViews" }, desc: !0 }],
364
- limit: r * 2
475
+ limit: e * 2
365
476
  // fetch extra to account for duplicates before aggregation
366
- }), l = k(c, "pagePath"), p = /* @__PURE__ */ new Map();
367
- for (const f of l.rows) {
368
- const R = f.pagePath.toLowerCase().replace(/\/+$/, ""), I = p.get(R);
369
- if (I) {
370
- I.screenPageViews += f.screenPageViews || 0, I.totalUsers += f.totalUsers || 0;
371
- const S = I.screenPageViews;
372
- S > 0 && (I.averageSessionDuration = (I.averageSessionDuration * (S - (f.screenPageViews || 0)) + (f.averageSessionDuration || 0) * (f.screenPageViews || 0)) / S);
477
+ }), o = b(n, "pagePath"), d = /* @__PURE__ */ new Map();
478
+ for (const m of o.rows) {
479
+ const w = m.pagePath.toLowerCase().replace(/\/+$/, ""), C = d.get(w);
480
+ if (C) {
481
+ C.screenPageViews += m.screenPageViews || 0, C.totalUsers += m.totalUsers || 0;
482
+ const R = C.screenPageViews;
483
+ R > 0 && (C.averageSessionDuration = (C.averageSessionDuration * (R - (m.screenPageViews || 0)) + (m.averageSessionDuration || 0) * (m.screenPageViews || 0)) / R);
373
484
  } else
374
- p.set(R, { ...f });
485
+ d.set(w, { ...m });
375
486
  }
376
- return { rows: [...p.values()].sort((f, R) => (R.screenPageViews || 0) - (f.screenPageViews || 0)).slice(0, r), rowCount: l.rowCount };
487
+ return { rows: [...d.values()].sort((m, w) => (w.screenPageViews || 0) - (m.screenPageViews || 0)).slice(0, e), rowCount: o.rowCount };
377
488
  })
378
- ), g.get(
489
+ ), f.get(
379
490
  "/top-sources",
380
- w(async (e) => {
381
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
382
- dateRanges: [{ startDate: a, endDate: n }],
491
+ h(async (t) => {
492
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
493
+ dateRanges: [{ startDate: a, endDate: r }],
383
494
  dimensions: [{ name: "sessionSource" }],
384
495
  metrics: [
385
496
  { name: "sessions" },
@@ -388,13 +499,13 @@ function G(h) {
388
499
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }],
389
500
  limit: 10
390
501
  });
391
- return k(r, "sessionSource");
502
+ return b(e, "sessionSource");
392
503
  })
393
- ), g.get(
504
+ ), f.get(
394
505
  "/devices",
395
- w(async (e) => {
396
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
397
- dateRanges: [{ startDate: a, endDate: n }],
506
+ h(async (t) => {
507
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
508
+ dateRanges: [{ startDate: a, endDate: r }],
398
509
  dimensions: [{ name: "deviceCategory" }],
399
510
  metrics: [
400
511
  { name: "sessions" },
@@ -402,13 +513,13 @@ function G(h) {
402
513
  ],
403
514
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }]
404
515
  });
405
- return k(r, "deviceCategory");
516
+ return b(e, "deviceCategory");
406
517
  })
407
- ), g.get(
518
+ ), f.get(
408
519
  "/countries",
409
- w(async (e) => {
410
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
411
- dateRanges: [{ startDate: a, endDate: n }],
520
+ h(async (t) => {
521
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
522
+ dateRanges: [{ startDate: a, endDate: r }],
412
523
  dimensions: [{ name: "country" }],
413
524
  metrics: [
414
525
  { name: "sessions" },
@@ -417,13 +528,13 @@ function G(h) {
417
528
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }],
418
529
  limit: 10
419
530
  });
420
- return k(r, "country");
531
+ return b(e, "country");
421
532
  })
422
- ), g.get(
533
+ ), f.get(
423
534
  "/acquisition/channels",
424
- w(async (e) => {
425
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
426
- dateRanges: [{ startDate: a, endDate: n }],
535
+ h(async (t) => {
536
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
537
+ dateRanges: [{ startDate: a, endDate: r }],
427
538
  dimensions: [{ name: "sessionDefaultChannelGroup" }],
428
539
  metrics: [
429
540
  { name: "sessions" },
@@ -437,13 +548,13 @@ function G(h) {
437
548
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }],
438
549
  limit: 15
439
550
  });
440
- return k(r, "sessionDefaultChannelGroup");
551
+ return b(e, "sessionDefaultChannelGroup");
441
552
  })
442
- ), g.get(
553
+ ), f.get(
443
554
  "/acquisition/source-medium",
444
- w(async (e) => {
445
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
446
- dateRanges: [{ startDate: a, endDate: n }],
555
+ h(async (t) => {
556
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
557
+ dateRanges: [{ startDate: a, endDate: r }],
447
558
  dimensions: [{ name: "sessionSourceMedium" }],
448
559
  metrics: [
449
560
  { name: "sessions" },
@@ -456,13 +567,13 @@ function G(h) {
456
567
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }],
457
568
  limit: 20
458
569
  });
459
- return k(r, "sessionSourceMedium");
570
+ return b(e, "sessionSourceMedium");
460
571
  })
461
- ), g.get(
572
+ ), f.get(
462
573
  "/acquisition/referrals",
463
- w(async (e) => {
464
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
465
- dateRanges: [{ startDate: a, endDate: n }],
574
+ h(async (t) => {
575
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
576
+ dateRanges: [{ startDate: a, endDate: r }],
466
577
  dimensions: [{ name: "sessionSource" }],
467
578
  dimensionFilter: {
468
579
  filter: {
@@ -479,13 +590,13 @@ function G(h) {
479
590
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }],
480
591
  limit: 20
481
592
  });
482
- return k(r, "sessionSource");
593
+ return b(e, "sessionSource");
483
594
  })
484
- ), g.get(
595
+ ), f.get(
485
596
  "/acquisition/campaigns",
486
- w(async (e) => {
487
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
488
- dateRanges: [{ startDate: a, endDate: n }],
597
+ h(async (t) => {
598
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
599
+ dateRanges: [{ startDate: a, endDate: r }],
489
600
  dimensions: [{ name: "sessionCampaignName" }],
490
601
  dimensionFilter: {
491
602
  notExpression: {
@@ -504,13 +615,13 @@ function G(h) {
504
615
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }],
505
616
  limit: 20
506
617
  });
507
- return k(r, "sessionCampaignName");
618
+ return b(e, "sessionCampaignName");
508
619
  })
509
- ), g.get(
620
+ ), f.get(
510
621
  "/content/all-pages",
511
- w(async (e) => {
512
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = parseInt(t.limit || "50", 10), c = await u(o, s, {
513
- dateRanges: [{ startDate: a, endDate: n }],
622
+ h(async (t) => {
623
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = parseInt(s.limit || "50", 10), n = await l(c, i, {
624
+ dateRanges: [{ startDate: a, endDate: r }],
514
625
  dimensions: [{ name: "pagePath" }],
515
626
  metrics: [
516
627
  { name: "screenPageViews" },
@@ -522,15 +633,15 @@ function G(h) {
522
633
  { name: "userEngagementDuration" }
523
634
  ],
524
635
  orderBys: [{ metric: { metricName: "screenPageViews" }, desc: !0 }],
525
- limit: r
636
+ limit: e
526
637
  });
527
- return k(c, "pagePath");
638
+ return b(n, "pagePath");
528
639
  })
529
- ), g.get(
640
+ ), f.get(
530
641
  "/content/landing-pages",
531
- w(async (e) => {
532
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
533
- dateRanges: [{ startDate: a, endDate: n }],
642
+ h(async (t) => {
643
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
644
+ dateRanges: [{ startDate: a, endDate: r }],
534
645
  dimensions: [{ name: "landingPagePlusQueryString" }],
535
646
  metrics: [
536
647
  { name: "sessions" },
@@ -543,13 +654,13 @@ function G(h) {
543
654
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }],
544
655
  limit: 30
545
656
  });
546
- return k(r, "landingPagePlusQueryString");
657
+ return b(e, "landingPagePlusQueryString");
547
658
  })
548
- ), g.get(
659
+ ), f.get(
549
660
  "/content/exit-pages",
550
- w(async (e) => {
551
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
552
- dateRanges: [{ startDate: a, endDate: n }],
661
+ h(async (t) => {
662
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
663
+ dateRanges: [{ startDate: a, endDate: r }],
553
664
  dimensions: [{ name: "pagePath" }],
554
665
  metrics: [
555
666
  { name: "sessions" },
@@ -559,60 +670,60 @@ function G(h) {
559
670
  ],
560
671
  orderBys: [{ metric: { metricName: "screenPageViews" }, desc: !0 }],
561
672
  limit: 20
562
- }), c = k(r, "pagePath");
563
- return c.rows = c.rows.map((l) => ({
564
- ...l,
565
- exitRate: l.bounceRate || 0
566
- })), c;
673
+ }), n = b(e, "pagePath");
674
+ return n.rows = n.rows.map((o) => ({
675
+ ...o,
676
+ exitRate: o.bounceRate || 0
677
+ })), n;
567
678
  })
568
- ), g.get(
679
+ ), f.get(
569
680
  "/content/search-terms",
570
- w(async (e) => {
571
- const { accessToken: o, propertyId: s, siteUrl: t } = await m(e), a = C(e), n = a.startDate || "30daysAgo", r = a.endDate || "today";
572
- if (t)
681
+ h(async (t) => {
682
+ const { accessToken: c, propertyId: i, siteUrl: s } = await u(t), a = I(t), r = a.startDate || "30daysAgo", e = a.endDate || "today";
683
+ if (s)
573
684
  try {
574
- const p = `${N}/sites/${encodeURIComponent(t)}/searchAnalytics/query`, D = await fetch(
575
- p,
685
+ const d = `${B}/sites/${encodeURIComponent(s)}/searchAnalytics/query`, g = await fetch(
686
+ d,
576
687
  {
577
688
  method: "POST",
578
689
  headers: {
579
- Authorization: `Bearer ${o}`,
690
+ Authorization: `Bearer ${c}`,
580
691
  "Content-Type": "application/json"
581
692
  },
582
693
  body: JSON.stringify({
583
- startDate: i(n),
584
- endDate: i(r),
694
+ startDate: y(r),
695
+ endDate: y(e),
585
696
  dimensions: ["query"],
586
697
  rowLimit: 30
587
698
  })
588
699
  }
589
700
  );
590
- if (D.ok) {
591
- const R = ((await D.json()).rows || []).map((I) => ({
592
- query: I.keys[0],
593
- clicks: I.clicks,
594
- impressions: I.impressions,
595
- ctr: I.ctr,
596
- position: I.position
701
+ if (g.ok) {
702
+ const w = ((await g.json()).rows || []).map((C) => ({
703
+ query: C.keys[0],
704
+ clicks: C.clicks,
705
+ impressions: C.impressions,
706
+ ctr: C.ctr,
707
+ position: C.position
597
708
  }));
598
- if (R.length > 0)
709
+ if (w.length > 0)
599
710
  return {
600
- rows: R,
601
- rowCount: R.length,
711
+ rows: w,
712
+ rowCount: w.length,
602
713
  source: "search_console"
603
714
  };
604
715
  } else {
605
- const f = await D.text().catch(() => "");
606
- console.error(`[GA Module] Search Console API error (${D.status}):`, f);
716
+ const m = await g.text().catch(() => "");
717
+ console.error(`[GA Module] Search Console API error (${g.status}):`, m);
607
718
  }
608
- } catch (p) {
609
- console.error("[GA Module] Search Console request failed:", p?.message || p);
719
+ } catch (d) {
720
+ console.error("[GA Module] Search Console request failed:", d?.message || d);
610
721
  }
611
722
  else
612
723
  console.log("[GA Module] No siteUrl configured, skipping Search Console");
613
724
  try {
614
- const p = await u(o, s, {
615
- dateRanges: [{ startDate: n, endDate: r }],
725
+ const d = await l(c, i, {
726
+ dateRanges: [{ startDate: r, endDate: e }],
616
727
  dimensions: [{ name: "sessionGoogleAdsQuery" }],
617
728
  metrics: [
618
729
  { name: "sessions" },
@@ -643,13 +754,13 @@ function G(h) {
643
754
  },
644
755
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }],
645
756
  limit: 30
646
- }), D = k(p, "sessionGoogleAdsQuery");
647
- if (D.rows.length > 0)
648
- return { ...D, source: "google_ads" };
757
+ }), g = b(d, "sessionGoogleAdsQuery");
758
+ if (g.rows.length > 0)
759
+ return { ...g, source: "google_ads" };
649
760
  } catch {
650
761
  }
651
- const c = await u(o, s, {
652
- dateRanges: [{ startDate: n, endDate: r }],
762
+ const n = await l(c, i, {
763
+ dateRanges: [{ startDate: r, endDate: e }],
653
764
  dimensions: [{ name: "landingPagePlusQueryString" }],
654
765
  metrics: [
655
766
  { name: "sessions" },
@@ -682,13 +793,13 @@ function G(h) {
682
793
  orderBys: [{ metric: { metricName: "sessions" }, desc: !0 }],
683
794
  limit: 30
684
795
  });
685
- return { ...k(c, "landingPagePlusQueryString"), source: "organic_landing_pages" };
796
+ return { ...b(n, "landingPagePlusQueryString"), source: "organic_landing_pages" };
686
797
  })
687
- ), g.get(
798
+ ), f.get(
688
799
  "/audience/overview",
689
- w(async (e) => {
690
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
691
- dateRanges: [{ startDate: a, endDate: n }],
800
+ h(async (t) => {
801
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
802
+ dateRanges: [{ startDate: a, endDate: r }],
692
803
  dimensions: [{ name: "newVsReturning" }],
693
804
  metrics: [
694
805
  { name: "totalUsers" },
@@ -699,14 +810,14 @@ function G(h) {
699
810
  ],
700
811
  metricAggregations: ["TOTAL"]
701
812
  });
702
- return k(r, "newVsReturning");
813
+ return b(e, "newVsReturning");
703
814
  })
704
- ), g.get(
815
+ ), f.get(
705
816
  "/audience/technology",
706
- w(async (e) => {
707
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = t.dimension || "browser", l = ["browser", "operatingSystem", "screenResolution"].includes(r) ? r : "browser", p = await u(o, s, {
708
- dateRanges: [{ startDate: a, endDate: n }],
709
- dimensions: [{ name: l }],
817
+ h(async (t) => {
818
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = s.dimension || "browser", o = ["browser", "operatingSystem", "screenResolution"].includes(e) ? e : "browser", d = await l(c, i, {
819
+ dateRanges: [{ startDate: a, endDate: r }],
820
+ dimensions: [{ name: o }],
710
821
  metrics: [
711
822
  { name: "totalUsers" },
712
823
  { name: "sessions" },
@@ -715,13 +826,13 @@ function G(h) {
715
826
  orderBys: [{ metric: { metricName: "totalUsers" }, desc: !0 }],
716
827
  limit: 10
717
828
  });
718
- return k(p, l);
829
+ return b(d, o);
719
830
  })
720
- ), g.get(
831
+ ), f.get(
721
832
  "/audience/languages",
722
- w(async (e) => {
723
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
724
- dateRanges: [{ startDate: a, endDate: n }],
833
+ h(async (t) => {
834
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
835
+ dateRanges: [{ startDate: a, endDate: r }],
725
836
  dimensions: [{ name: "language" }],
726
837
  metrics: [
727
838
  { name: "totalUsers" },
@@ -730,13 +841,13 @@ function G(h) {
730
841
  orderBys: [{ metric: { metricName: "totalUsers" }, desc: !0 }],
731
842
  limit: 15
732
843
  });
733
- return k(r, "language");
844
+ return b(e, "language");
734
845
  })
735
- ), g.get(
846
+ ), f.get(
736
847
  "/audience/hours",
737
- w(async (e) => {
738
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
739
- dateRanges: [{ startDate: a, endDate: n }],
848
+ h(async (t) => {
849
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
850
+ dateRanges: [{ startDate: a, endDate: r }],
740
851
  dimensions: [{ name: "dayOfWeekName" }, { name: "hour" }],
741
852
  metrics: [{ name: "sessions" }],
742
853
  orderBys: [
@@ -746,13 +857,13 @@ function G(h) {
746
857
  limit: 168
747
858
  // 7 days × 24 hours
748
859
  });
749
- return U(r, ["dayOfWeekName", "hour"]);
860
+ return $(e, ["dayOfWeekName", "hour"]);
750
861
  })
751
- ), g.get(
862
+ ), f.get(
752
863
  "/audience/cities",
753
- w(async (e) => {
754
- const { accessToken: o, propertyId: s } = await m(e), t = C(e), a = t.startDate || "30daysAgo", n = t.endDate || "today", r = await u(o, s, {
755
- dateRanges: [{ startDate: a, endDate: n }],
864
+ h(async (t) => {
865
+ const { accessToken: c, propertyId: i } = await u(t), s = I(t), a = s.startDate || "30daysAgo", r = s.endDate || "today", e = await l(c, i, {
866
+ dateRanges: [{ startDate: a, endDate: r }],
756
867
  dimensions: [{ name: "city" }, { name: "country" }],
757
868
  metrics: [
758
869
  { name: "totalUsers" },
@@ -769,236 +880,236 @@ function G(h) {
769
880
  orderBys: [{ metric: { metricName: "totalUsers" }, desc: !0 }],
770
881
  limit: 20
771
882
  });
772
- return U(r, ["city", "country"]);
883
+ return $(e, ["city", "country"]);
773
884
  })
774
885
  );
775
- function i(e) {
776
- const o = e.match(/^(\d+)daysAgo$/);
777
- if (o) {
778
- const s = /* @__PURE__ */ new Date();
779
- return s.setDate(s.getDate() - parseInt(o[1], 10)), s.toISOString().slice(0, 10);
886
+ function y(t) {
887
+ const c = t.match(/^(\d+)daysAgo$/);
888
+ if (c) {
889
+ const i = /* @__PURE__ */ new Date();
890
+ return i.setDate(i.getDate() - parseInt(c[1], 10)), i.toISOString().slice(0, 10);
780
891
  }
781
- if (e === "today") return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
782
- if (e === "yesterday") {
783
- const s = /* @__PURE__ */ new Date();
784
- return s.setDate(s.getDate() - 1), s.toISOString().slice(0, 10);
892
+ if (t === "today") return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
893
+ if (t === "yesterday") {
894
+ const i = /* @__PURE__ */ new Date();
895
+ return i.setDate(i.getDate() - 1), i.toISOString().slice(0, 10);
785
896
  }
786
- return e;
897
+ return t;
787
898
  }
788
- async function d(e, o, s) {
789
- const t = `${N}/sites/${encodeURIComponent(o)}/searchAnalytics/query`, a = await fetch(t, {
899
+ async function D(t, c, i) {
900
+ const s = `${B}/sites/${encodeURIComponent(c)}/searchAnalytics/query`, a = await fetch(s, {
790
901
  method: "POST",
791
902
  headers: {
792
- Authorization: `Bearer ${e}`,
903
+ Authorization: `Bearer ${t}`,
793
904
  "Content-Type": "application/json"
794
905
  },
795
- body: JSON.stringify(s)
906
+ body: JSON.stringify(i)
796
907
  });
797
908
  if (!a.ok) {
798
- const n = await a.json().catch(() => ({}));
799
- throw y({
909
+ const r = await a.json().catch(() => ({}));
910
+ throw p({
800
911
  statusCode: a.status,
801
- statusMessage: n?.error?.message || "Search Console API request failed"
912
+ statusMessage: r?.error?.message || "Search Console API request failed"
802
913
  });
803
914
  }
804
915
  return a.json();
805
916
  }
806
- return g.get(
917
+ return f.get(
807
918
  "/seo/keywords",
808
- w(async (e) => {
809
- const { accessToken: o, siteUrl: s } = await m(e);
810
- if (!s)
811
- throw y({ statusCode: 400, statusMessage: "Search Console Site URL is not configured. Add it in module settings." });
812
- const t = C(e), a = i(t.startDate || "30daysAgo"), n = i(t.endDate || "today"), r = Math.min(parseInt(t.limit) || 50, 100), c = await d(o, s, {
919
+ h(async (t) => {
920
+ const { accessToken: c, siteUrl: i } = await u(t);
921
+ if (!i)
922
+ throw p({ statusCode: 400, statusMessage: "Search Console Site URL is not configured. Add it in module settings." });
923
+ const s = I(t), a = y(s.startDate || "30daysAgo"), r = y(s.endDate || "today"), e = Math.min(parseInt(s.limit) || 50, 100), n = await D(c, i, {
813
924
  startDate: a,
814
- endDate: n,
925
+ endDate: r,
815
926
  dimensions: ["query"],
816
- rowLimit: r
927
+ rowLimit: e
817
928
  });
818
929
  return {
819
- rows: (c.rows || []).map((l) => ({
820
- query: l.keys[0],
821
- clicks: l.clicks,
822
- impressions: l.impressions,
823
- ctr: l.ctr,
824
- position: l.position
930
+ rows: (n.rows || []).map((o) => ({
931
+ query: o.keys[0],
932
+ clicks: o.clicks,
933
+ impressions: o.impressions,
934
+ ctr: o.ctr,
935
+ position: o.position
825
936
  })),
826
- rowCount: c.rows?.length || 0
937
+ rowCount: n.rows?.length || 0
827
938
  };
828
939
  })
829
- ), g.get(
940
+ ), f.get(
830
941
  "/seo/pages",
831
- w(async (e) => {
832
- const { accessToken: o, siteUrl: s } = await m(e);
833
- if (!s)
834
- throw y({ statusCode: 400, statusMessage: "Search Console Site URL is not configured." });
835
- const t = C(e), a = i(t.startDate || "30daysAgo"), n = i(t.endDate || "today"), r = Math.min(parseInt(t.limit) || 50, 100), c = await d(o, s, {
942
+ h(async (t) => {
943
+ const { accessToken: c, siteUrl: i } = await u(t);
944
+ if (!i)
945
+ throw p({ statusCode: 400, statusMessage: "Search Console Site URL is not configured." });
946
+ const s = I(t), a = y(s.startDate || "30daysAgo"), r = y(s.endDate || "today"), e = Math.min(parseInt(s.limit) || 50, 100), n = await D(c, i, {
836
947
  startDate: a,
837
- endDate: n,
948
+ endDate: r,
838
949
  dimensions: ["page"],
839
- rowLimit: r
950
+ rowLimit: e
840
951
  });
841
952
  return {
842
- rows: (c.rows || []).map((l) => ({
843
- page: l.keys[0],
844
- clicks: l.clicks,
845
- impressions: l.impressions,
846
- ctr: l.ctr,
847
- position: l.position
953
+ rows: (n.rows || []).map((o) => ({
954
+ page: o.keys[0],
955
+ clicks: o.clicks,
956
+ impressions: o.impressions,
957
+ ctr: o.ctr,
958
+ position: o.position
848
959
  })),
849
- rowCount: c.rows?.length || 0
960
+ rowCount: n.rows?.length || 0
850
961
  };
851
962
  })
852
- ), g.get(
963
+ ), f.get(
853
964
  "/seo/trends",
854
- w(async (e) => {
855
- const { accessToken: o, siteUrl: s } = await m(e);
856
- if (!s)
857
- throw y({ statusCode: 400, statusMessage: "Search Console Site URL is not configured." });
858
- const t = C(e), a = i(t.startDate || "30daysAgo"), n = i(t.endDate || "today"), c = ((await d(o, s, {
965
+ h(async (t) => {
966
+ const { accessToken: c, siteUrl: i } = await u(t);
967
+ if (!i)
968
+ throw p({ statusCode: 400, statusMessage: "Search Console Site URL is not configured." });
969
+ const s = I(t), a = y(s.startDate || "30daysAgo"), r = y(s.endDate || "today"), n = ((await D(c, i, {
859
970
  startDate: a,
860
- endDate: n,
971
+ endDate: r,
861
972
  dimensions: ["date"],
862
973
  rowLimit: 500
863
- })).rows || []).map((p) => ({
864
- date: p.keys[0],
865
- clicks: p.clicks,
866
- impressions: p.impressions,
867
- ctr: p.ctr,
868
- position: p.position
869
- })).sort((p, D) => p.date.localeCompare(D.date)), l = c.reduce(
870
- (p, D) => ({
871
- clicks: p.clicks + D.clicks,
872
- impressions: p.impressions + D.impressions
974
+ })).rows || []).map((d) => ({
975
+ date: d.keys[0],
976
+ clicks: d.clicks,
977
+ impressions: d.impressions,
978
+ ctr: d.ctr,
979
+ position: d.position
980
+ })).sort((d, g) => d.date.localeCompare(g.date)), o = n.reduce(
981
+ (d, g) => ({
982
+ clicks: d.clicks + g.clicks,
983
+ impressions: d.impressions + g.impressions
873
984
  }),
874
985
  { clicks: 0, impressions: 0 }
875
986
  );
876
- return l.ctr = l.impressions > 0 ? l.clicks / l.impressions : 0, l.avgPosition = c.length > 0 ? c.reduce((p, D) => p + D.position, 0) / c.length : 0, { rows: c, totals: l, rowCount: c.length };
987
+ return o.ctr = o.impressions > 0 ? o.clicks / o.impressions : 0, o.avgPosition = n.length > 0 ? n.reduce((d, g) => d + g.position, 0) / n.length : 0, { rows: n, totals: o, rowCount: n.length };
877
988
  })
878
- ), g.get(
989
+ ), f.get(
879
990
  "/seo/query-pages",
880
- w(async (e) => {
881
- const { accessToken: o, siteUrl: s } = await m(e);
882
- if (!s)
883
- throw y({ statusCode: 400, statusMessage: "Search Console Site URL is not configured." });
884
- const t = C(e), a = i(t.startDate || "30daysAgo"), n = i(t.endDate || "today"), r = await d(o, s, {
991
+ h(async (t) => {
992
+ const { accessToken: c, siteUrl: i } = await u(t);
993
+ if (!i)
994
+ throw p({ statusCode: 400, statusMessage: "Search Console Site URL is not configured." });
995
+ const s = I(t), a = y(s.startDate || "30daysAgo"), r = y(s.endDate || "today"), e = await D(c, i, {
885
996
  startDate: a,
886
- endDate: n,
997
+ endDate: r,
887
998
  dimensions: ["query", "page"],
888
999
  rowLimit: 100
889
1000
  });
890
1001
  return {
891
- rows: (r.rows || []).map((c) => ({
892
- query: c.keys[0],
893
- page: c.keys[1],
894
- clicks: c.clicks,
895
- impressions: c.impressions,
896
- ctr: c.ctr,
897
- position: c.position
1002
+ rows: (e.rows || []).map((n) => ({
1003
+ query: n.keys[0],
1004
+ page: n.keys[1],
1005
+ clicks: n.clicks,
1006
+ impressions: n.impressions,
1007
+ ctr: n.ctr,
1008
+ position: n.position
898
1009
  })),
899
- rowCount: r.rows?.length || 0
1010
+ rowCount: e.rows?.length || 0
900
1011
  };
901
1012
  })
902
- ), g.handler;
1013
+ ), f.handler;
903
1014
  }
904
- function E(h, P = !0) {
905
- const A = (h.metricHeaders || []).map((a) => a.name), m = (h.dimensionHeaders || []).map((a) => a.name).indexOf("date"), u = [];
906
- (h.rows || []).forEach((a) => {
907
- const n = m >= 0 ? a.dimensionValues[m]?.value : a.dimensionValues[0]?.value;
908
- if (!n || n.length < 8) return;
909
- const c = { date: `${n.slice(0, 4)}-${n.slice(4, 6)}-${n.slice(6, 8)}` };
910
- A.forEach((l, p) => {
911
- c[l] = parseFloat(a.metricValues[p]?.value || "0");
912
- }), u.push(c);
1015
+ function L(A, P = !0) {
1016
+ const S = (A.metricHeaders || []).map((a) => a.name), u = (A.dimensionHeaders || []).map((a) => a.name).indexOf("date"), l = [];
1017
+ (A.rows || []).forEach((a) => {
1018
+ const r = u >= 0 ? a.dimensionValues[u]?.value : a.dimensionValues[0]?.value;
1019
+ if (!r || r.length < 8) return;
1020
+ const n = { date: `${r.slice(0, 4)}-${r.slice(4, 6)}-${r.slice(6, 8)}` };
1021
+ S.forEach((o, d) => {
1022
+ n[o] = parseFloat(a.metricValues[d]?.value || "0");
1023
+ }), l.push(n);
913
1024
  });
914
- const i = {}, d = {};
915
- h.totals && h.totals.length >= 2 ? A.forEach((a, n) => {
916
- i[a] = parseFloat(h.totals[0]?.metricValues?.[n]?.value || "0"), d[a] = parseFloat(h.totals[1]?.metricValues?.[n]?.value || "0");
917
- }) : h.totals && h.totals.length === 1 && A.forEach((a, n) => {
918
- i[a] = parseFloat(h.totals[0]?.metricValues?.[n]?.value || "0");
1025
+ const y = {}, D = {};
1026
+ A.totals && A.totals.length >= 2 ? S.forEach((a, r) => {
1027
+ y[a] = parseFloat(A.totals[0]?.metricValues?.[r]?.value || "0"), D[a] = parseFloat(A.totals[1]?.metricValues?.[r]?.value || "0");
1028
+ }) : A.totals && A.totals.length === 1 && S.forEach((a, r) => {
1029
+ y[a] = parseFloat(A.totals[0]?.metricValues?.[r]?.value || "0");
919
1030
  });
920
- const e = {};
921
- A.forEach((a) => {
922
- const n = i[a] || 0, r = d[a];
923
- r !== void 0 && r !== 0 ? e[a] = (n - r) / r * 100 : e[a] = null;
1031
+ const t = {};
1032
+ S.forEach((a) => {
1033
+ const r = y[a] || 0, e = D[a];
1034
+ e !== void 0 && e !== 0 ? t[a] = (r - e) / e * 100 : t[a] = null;
924
1035
  });
925
- const o = /* @__PURE__ */ new Map();
926
- for (const a of u)
927
- o.has(a.date) || o.set(a.date, a);
928
- const s = Array.from(o.values()).sort((a, n) => a.date.localeCompare(n.date)), t = P && h.totals && h.totals.length >= 2 ? s.slice(-Math.ceil(s.length / 2)) : s;
1036
+ const c = /* @__PURE__ */ new Map();
1037
+ for (const a of l)
1038
+ c.has(a.date) || c.set(a.date, a);
1039
+ const i = Array.from(c.values()).sort((a, r) => a.date.localeCompare(r.date)), s = P && A.totals && A.totals.length >= 2 ? i.slice(-Math.ceil(i.length / 2)) : i;
929
1040
  return {
930
- rows: t,
931
- totals: i,
932
- previousTotals: d,
933
- changes: e,
934
- rowCount: t.length
1041
+ rows: s,
1042
+ totals: y,
1043
+ previousTotals: D,
1044
+ changes: t,
1045
+ rowCount: s.length
935
1046
  };
936
1047
  }
937
- function k(h, P) {
938
- const A = (h.metricHeaders || []).map((m) => m.name), g = (h.rows || []).map((m) => {
939
- const u = {
940
- [P]: m.dimensionValues[0].value
1048
+ function b(A, P) {
1049
+ const S = (A.metricHeaders || []).map((u) => u.name), f = (A.rows || []).map((u) => {
1050
+ const l = {
1051
+ [P]: u.dimensionValues[0].value
941
1052
  };
942
- return A.forEach((i, d) => {
943
- u[i] = parseFloat(m.metricValues[d].value);
944
- }), u;
1053
+ return S.forEach((y, D) => {
1054
+ l[y] = parseFloat(u.metricValues[D].value);
1055
+ }), l;
945
1056
  });
946
- return { rows: g, rowCount: h.rowCount || g.length };
1057
+ return { rows: f, rowCount: A.rowCount || f.length };
947
1058
  }
948
- function U(h, P) {
949
- const A = (h.metricHeaders || []).map((m) => m.name), g = (h.rows || []).map((m) => {
950
- const u = {};
951
- return P.forEach((i, d) => {
952
- u[i] = m.dimensionValues[d]?.value || "";
953
- }), A.forEach((i, d) => {
954
- u[i] = parseFloat(m.metricValues[d].value);
955
- }), u;
1059
+ function $(A, P) {
1060
+ const S = (A.metricHeaders || []).map((u) => u.name), f = (A.rows || []).map((u) => {
1061
+ const l = {};
1062
+ return P.forEach((y, D) => {
1063
+ l[y] = u.dimensionValues[D]?.value || "";
1064
+ }), S.forEach((y, D) => {
1065
+ l[y] = parseFloat(u.metricValues[D].value);
1066
+ }), l;
956
1067
  });
957
- return { rows: g, rowCount: h.rowCount || g.length };
1068
+ return { rows: f, rowCount: A.rowCount || f.length };
958
1069
  }
959
- function j(h) {
960
- const { decrypt: P } = h, A = v();
961
- async function g(m) {
962
- const { supabase: u, instanceId: i } = m.context.module, { data: d, error: e } = await u.from("project_modules").select("config").eq("id", i).single();
963
- if (e || !d?.config)
964
- throw y({ statusCode: 500, statusMessage: "Failed to load module config." });
965
- const o = d.config, s = o.githubIntegration, t = o.githubRepo, a = o.githubOwner;
966
- if (!s || !t || !a)
967
- throw y({ statusCode: 400, statusMessage: "No GitHub integration configured for this module." });
968
- const { data: n, error: r } = await u.from("integrations").select("config").eq("id", s).single();
969
- let c = n?.config;
970
- if (r || !c) {
971
- const { data: p, error: D } = await u.from("agency_integrations").select("config").eq("id", s).single();
972
- if (D || !p?.config)
973
- throw y({ statusCode: 500, statusMessage: "Failed to load Github credentials." });
974
- c = p.config;
1070
+ function Y(A) {
1071
+ const { decrypt: P } = A, S = E();
1072
+ async function f(u) {
1073
+ const { supabase: l, instanceId: y } = u.context.module, { data: D, error: t } = await l.from("project_modules").select("config").eq("id", y).single();
1074
+ if (t || !D?.config)
1075
+ throw p({ statusCode: 500, statusMessage: "Failed to load module config." });
1076
+ const c = D.config, i = c.githubIntegration, s = c.githubRepo, a = c.githubOwner;
1077
+ if (!i || !s || !a)
1078
+ throw p({ statusCode: 400, statusMessage: "No GitHub integration configured for this module." });
1079
+ const { data: r, error: e } = await l.from("integrations").select("config").eq("id", i).single();
1080
+ let n = r?.config;
1081
+ if (e || !n) {
1082
+ const { data: d, error: g } = await l.from("agency_integrations").select("config").eq("id", i).single();
1083
+ if (g || !d?.config)
1084
+ throw p({ statusCode: 500, statusMessage: "Failed to load Github credentials." });
1085
+ n = d.config;
975
1086
  }
976
- return { token: P(c.token), repo: t, owner: a };
1087
+ return { token: P(n.token), repo: s, owner: a };
977
1088
  }
978
- return A.post(
1089
+ return S.post(
979
1090
  "/github/deploy",
980
- w(async (m) => {
1091
+ h(async (u) => {
981
1092
  try {
982
- const { token: u, repo: i, owner: d } = await g(m);
983
- await fetch(`https://api.github.com/repos/${d}/${i}/dispatches`, {
1093
+ const { token: l, repo: y, owner: D } = await f(u);
1094
+ await fetch(`https://api.github.com/repos/${D}/${y}/dispatches`, {
984
1095
  method: "POST",
985
1096
  headers: {
986
- Authorization: `Bearer ${u}`,
1097
+ Authorization: `Bearer ${l}`,
987
1098
  Accept: "application/vnd.github+json"
988
1099
  },
989
1100
  body: JSON.stringify({
990
1101
  event_type: "deploy-site"
991
1102
  })
992
1103
  });
993
- } catch (u) {
994
- throw console.error("Error triggering GitHub deployment:", u), y({ statusCode: 500, statusMessage: "Failed to trigger deployment." });
1104
+ } catch (l) {
1105
+ throw console.error("Error triggering GitHub deployment:", l), p({ statusCode: 500, statusMessage: "Failed to trigger deployment." });
995
1106
  }
996
1107
  })
997
- ), A.handler;
1108
+ ), S.handler;
998
1109
  }
999
1110
  export {
1000
- x as appointments,
1001
- j as contentManager,
1002
- G as googleAnalytics,
1003
- $ as products
1111
+ J as appointments,
1112
+ Y as contentManager,
1113
+ W as googleAnalytics,
1114
+ z as products
1004
1115
  };