@growflowstudio/growflowbooking-admin-core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,729 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BookingAdminApiClient: () => BookingAdminApiClient,
24
+ BookingAdminClientContext: () => BookingAdminClientContext,
25
+ billingSubscriptionStatusColors: () => billingSubscriptionStatusColors,
26
+ billingSubscriptionStatusLabels: () => billingSubscriptionStatusLabels,
27
+ createBookingAdminClient: () => createBookingAdminClient,
28
+ formatCurrency: () => formatCurrency,
29
+ formatCurrencyFromCents: () => formatCurrencyFromCents,
30
+ formatDate: () => formatDate,
31
+ formatPrice: () => formatPrice,
32
+ formatTimestamp: () => formatTimestamp,
33
+ tenantPlanColors: () => tenantPlanColors,
34
+ tenantPlanLabels: () => tenantPlanLabels,
35
+ tenantStatusColors: () => tenantStatusColors,
36
+ tenantStatusLabels: () => tenantStatusLabels,
37
+ truncateId: () => truncateId,
38
+ useAdminCustomers: () => useAdminCustomers,
39
+ useAdminTenant: () => useAdminTenant,
40
+ useAdminTenants: () => useAdminTenants,
41
+ useBillingPlans: () => useBillingPlans,
42
+ useBillingSettings: () => useBillingSettings,
43
+ useBillingSubscription: () => useBillingSubscription,
44
+ useBillingSubscriptions: () => useBillingSubscriptions,
45
+ useBookingAdminClient: () => useBookingAdminClient,
46
+ useCancelBillingSubscription: () => useCancelBillingSubscription,
47
+ useChangeBillingSubscriptionPlan: () => useChangeBillingSubscriptionPlan,
48
+ useCreateBillingPlan: () => useCreateBillingPlan,
49
+ useCreateBillingSubscription: () => useCreateBillingSubscription,
50
+ useCreateCustomer: () => useCreateCustomer,
51
+ useCreateSubscriptionPlan: () => useCreateSubscriptionPlan,
52
+ useCreateTenant: () => useCreateTenant,
53
+ useDeleteBillingPlan: () => useDeleteBillingPlan,
54
+ useDeleteCustomer: () => useDeleteCustomer,
55
+ useDeleteSubscriptionPlan: () => useDeleteSubscriptionPlan,
56
+ useDeleteTenant: () => useDeleteTenant,
57
+ useDialogState: () => useDialogState,
58
+ useSubscriptionPlan: () => useSubscriptionPlan,
59
+ useSubscriptionPlans: () => useSubscriptionPlans,
60
+ useSyncBillingPlanToStripe: () => useSyncBillingPlanToStripe,
61
+ useTenantLimits: () => useTenantLimits,
62
+ useTestBillingConnection: () => useTestBillingConnection,
63
+ useUpdateBillingPlan: () => useUpdateBillingPlan,
64
+ useUpdateBillingSettings: () => useUpdateBillingSettings,
65
+ useUpdateCustomer: () => useUpdateCustomer,
66
+ useUpdateSubscriptionPlan: () => useUpdateSubscriptionPlan,
67
+ useUpdateTenant: () => useUpdateTenant,
68
+ useUpdateTenantLimits: () => useUpdateTenantLimits,
69
+ useUpdateTenantPlan: () => useUpdateTenantPlan,
70
+ useUpdateTenantStatus: () => useUpdateTenantStatus,
71
+ validateEmail: () => validateEmail,
72
+ validateRequired: () => validateRequired,
73
+ validateSlug: () => validateSlug
74
+ });
75
+ module.exports = __toCommonJS(index_exports);
76
+
77
+ // src/api/client.ts
78
+ var BookingAdminApiClient = class {
79
+ constructor(options) {
80
+ this.basePath = options.basePath;
81
+ this.fetcher = options.fetcher;
82
+ }
83
+ async request(path, options) {
84
+ return this.fetcher(`${this.basePath}${path}`, options);
85
+ }
86
+ // =========================================================================
87
+ // Tenants
88
+ // =========================================================================
89
+ async getTenants(params) {
90
+ return this.request("/admin/tenants", { params });
91
+ }
92
+ async getTenant(id) {
93
+ return this.request(`/admin/tenants/${id}`);
94
+ }
95
+ async createTenant(data) {
96
+ return this.request("/admin/tenants", { method: "POST", body: data });
97
+ }
98
+ async updateTenant(id, data) {
99
+ return this.request(`/admin/tenants/${id}`, { method: "PATCH", body: data });
100
+ }
101
+ async deleteTenant(id) {
102
+ return this.request(`/admin/tenants/${id}`, { method: "DELETE" });
103
+ }
104
+ async updateTenantPlan(id, plan) {
105
+ return this.request(`/admin/tenants/${id}/plan`, { method: "PATCH", body: { plan } });
106
+ }
107
+ async updateTenantStatus(id, isActive) {
108
+ return this.request(`/admin/tenants/${id}/status`, { method: "PATCH", body: { is_active: isActive } });
109
+ }
110
+ async getTenantLimits(id) {
111
+ return this.request(`/admin/tenants/${id}/limits`);
112
+ }
113
+ async updateTenantLimits(id, limits) {
114
+ return this.request(`/admin/tenants/${id}/limits`, { method: "PATCH", body: limits });
115
+ }
116
+ // =========================================================================
117
+ // Customers
118
+ // =========================================================================
119
+ async getCustomers(params) {
120
+ return this.request("/admin/customers", { params });
121
+ }
122
+ async createCustomer(data) {
123
+ return this.request("/admin/customers", { method: "POST", body: data });
124
+ }
125
+ async updateCustomer(id, data) {
126
+ return this.request(`/admin/customers/${id}`, { method: "PATCH", body: data });
127
+ }
128
+ async deleteCustomer(id) {
129
+ return this.request(`/admin/customers/${id}`, { method: "DELETE" });
130
+ }
131
+ // =========================================================================
132
+ // Subscription Plans (local DB)
133
+ // =========================================================================
134
+ async getSubscriptionPlans(includeInactive) {
135
+ return this.request("/admin/subscription-plans", {
136
+ params: includeInactive !== void 0 ? { include_inactive: includeInactive } : void 0
137
+ });
138
+ }
139
+ async getSubscriptionPlan(id) {
140
+ return this.request(`/admin/subscription-plans/${id}`);
141
+ }
142
+ async createSubscriptionPlan(data) {
143
+ return this.request("/admin/subscription-plans", { method: "POST", body: data });
144
+ }
145
+ async updateSubscriptionPlan(id, data) {
146
+ return this.request(`/admin/subscription-plans/${id}`, { method: "PATCH", body: data });
147
+ }
148
+ async deleteSubscriptionPlan(id) {
149
+ return this.request(`/admin/subscription-plans/${id}`, { method: "DELETE" });
150
+ }
151
+ // =========================================================================
152
+ // Billing Plans (GrowFlow Billing proxy)
153
+ // =========================================================================
154
+ async getBillingPlans(isActive) {
155
+ return this.request("/admin/billing/plans", {
156
+ params: isActive !== void 0 ? { is_active: isActive } : void 0
157
+ });
158
+ }
159
+ async createBillingPlan(data) {
160
+ return this.request("/admin/billing/plans", { method: "POST", body: data });
161
+ }
162
+ async updateBillingPlan(id, data) {
163
+ return this.request(`/admin/billing/plans/${id}`, { method: "PATCH", body: data });
164
+ }
165
+ async deleteBillingPlan(id) {
166
+ return this.request(`/admin/billing/plans/${id}`, { method: "DELETE" });
167
+ }
168
+ async syncBillingPlanToStripe(id) {
169
+ return this.request(`/admin/billing/plans/${id}/sync-stripe`, { method: "POST" });
170
+ }
171
+ // =========================================================================
172
+ // Billing Subscriptions (GrowFlow Billing proxy)
173
+ // =========================================================================
174
+ async getBillingSubscriptions(params) {
175
+ return this.request("/admin/billing/subscriptions", { params });
176
+ }
177
+ async getBillingSubscription(id) {
178
+ return this.request(`/admin/billing/subscriptions/${id}`);
179
+ }
180
+ async createBillingSubscription(data) {
181
+ return this.request("/admin/billing/subscriptions", { method: "POST", body: data });
182
+ }
183
+ async cancelBillingSubscription(id, atPeriodEnd = true) {
184
+ return this.request(`/admin/billing/subscriptions/${id}/cancel`, {
185
+ method: "POST",
186
+ body: { at_period_end: atPeriodEnd }
187
+ });
188
+ }
189
+ async changeBillingSubscriptionPlan(id, newPlanSlug) {
190
+ return this.request(`/admin/billing/subscriptions/${id}/change-plan`, {
191
+ method: "POST",
192
+ body: { new_plan_slug: newPlanSlug }
193
+ });
194
+ }
195
+ // =========================================================================
196
+ // Settings
197
+ // =========================================================================
198
+ async getBillingSettings() {
199
+ return this.request("/admin/settings/billing");
200
+ }
201
+ async updateBillingSettings(data) {
202
+ return this.request("/admin/settings/billing", { method: "PUT", body: data });
203
+ }
204
+ async testBillingConnection() {
205
+ return this.request("/admin/settings/billing/test", { method: "POST" });
206
+ }
207
+ };
208
+ function createBookingAdminClient(options) {
209
+ return new BookingAdminApiClient(options);
210
+ }
211
+
212
+ // src/hooks/context.ts
213
+ var import_react = require("react");
214
+ var BookingAdminClientContext = (0, import_react.createContext)(null);
215
+ function useBookingAdminClient() {
216
+ const client = (0, import_react.useContext)(BookingAdminClientContext);
217
+ if (!client) {
218
+ throw new Error(
219
+ "useBookingAdminClient must be used within a BookingAdminProvider. Wrap your component tree with <BookingAdminProvider config={{...}}>."
220
+ );
221
+ }
222
+ return client;
223
+ }
224
+
225
+ // src/hooks/useDialogState.ts
226
+ var import_react2 = require("react");
227
+ function useDialogState() {
228
+ const [isOpen, setIsOpen] = (0, import_react2.useState)(false);
229
+ const [data, setData] = (0, import_react2.useState)(void 0);
230
+ const open = (0, import_react2.useCallback)((initialData) => {
231
+ setData(initialData);
232
+ setIsOpen(true);
233
+ }, []);
234
+ const close = (0, import_react2.useCallback)(() => {
235
+ setIsOpen(false);
236
+ setTimeout(() => setData(void 0), 150);
237
+ }, []);
238
+ const toggle = (0, import_react2.useCallback)(() => {
239
+ if (isOpen) {
240
+ close();
241
+ } else {
242
+ open();
243
+ }
244
+ }, [isOpen, open, close]);
245
+ return {
246
+ isOpen,
247
+ data,
248
+ open,
249
+ close,
250
+ toggle,
251
+ setData
252
+ };
253
+ }
254
+
255
+ // src/hooks/useTenants.ts
256
+ var import_react_query = require("@tanstack/react-query");
257
+ var TENANTS_KEY = "booking-admin-tenants";
258
+ function useAdminTenants(params) {
259
+ const client = useBookingAdminClient();
260
+ return (0, import_react_query.useQuery)({
261
+ queryKey: [TENANTS_KEY, params],
262
+ queryFn: () => client.getTenants(params)
263
+ });
264
+ }
265
+ function useAdminTenant(id) {
266
+ const client = useBookingAdminClient();
267
+ return (0, import_react_query.useQuery)({
268
+ queryKey: [TENANTS_KEY, id],
269
+ queryFn: () => client.getTenant(id),
270
+ enabled: !!id
271
+ });
272
+ }
273
+ function useCreateTenant() {
274
+ const client = useBookingAdminClient();
275
+ const queryClient = (0, import_react_query.useQueryClient)();
276
+ return (0, import_react_query.useMutation)({
277
+ mutationFn: (data) => client.createTenant(data),
278
+ onSuccess: () => {
279
+ queryClient.invalidateQueries({ queryKey: [TENANTS_KEY] });
280
+ }
281
+ });
282
+ }
283
+ function useUpdateTenant() {
284
+ const client = useBookingAdminClient();
285
+ const queryClient = (0, import_react_query.useQueryClient)();
286
+ return (0, import_react_query.useMutation)({
287
+ mutationFn: ({ id, data }) => client.updateTenant(id, data),
288
+ onSuccess: () => {
289
+ queryClient.invalidateQueries({ queryKey: [TENANTS_KEY] });
290
+ }
291
+ });
292
+ }
293
+ function useDeleteTenant() {
294
+ const client = useBookingAdminClient();
295
+ const queryClient = (0, import_react_query.useQueryClient)();
296
+ return (0, import_react_query.useMutation)({
297
+ mutationFn: (id) => client.deleteTenant(id),
298
+ onSuccess: () => {
299
+ queryClient.invalidateQueries({ queryKey: [TENANTS_KEY] });
300
+ }
301
+ });
302
+ }
303
+ function useUpdateTenantPlan() {
304
+ const client = useBookingAdminClient();
305
+ const queryClient = (0, import_react_query.useQueryClient)();
306
+ return (0, import_react_query.useMutation)({
307
+ mutationFn: ({ id, plan }) => client.updateTenantPlan(id, plan),
308
+ onSuccess: () => {
309
+ queryClient.invalidateQueries({ queryKey: [TENANTS_KEY] });
310
+ }
311
+ });
312
+ }
313
+ function useUpdateTenantStatus() {
314
+ const client = useBookingAdminClient();
315
+ const queryClient = (0, import_react_query.useQueryClient)();
316
+ return (0, import_react_query.useMutation)({
317
+ mutationFn: ({ id, isActive }) => client.updateTenantStatus(id, isActive),
318
+ onSuccess: () => {
319
+ queryClient.invalidateQueries({ queryKey: [TENANTS_KEY] });
320
+ }
321
+ });
322
+ }
323
+ function useTenantLimits(id) {
324
+ const client = useBookingAdminClient();
325
+ return (0, import_react_query.useQuery)({
326
+ queryKey: [TENANTS_KEY, id, "limits"],
327
+ queryFn: () => client.getTenantLimits(id),
328
+ enabled: !!id
329
+ });
330
+ }
331
+ function useUpdateTenantLimits() {
332
+ const client = useBookingAdminClient();
333
+ const queryClient = (0, import_react_query.useQueryClient)();
334
+ return (0, import_react_query.useMutation)({
335
+ mutationFn: ({ id, limits }) => client.updateTenantLimits(id, limits),
336
+ onSuccess: (_data, variables) => {
337
+ queryClient.invalidateQueries({ queryKey: [TENANTS_KEY, variables.id, "limits"] });
338
+ queryClient.invalidateQueries({ queryKey: [TENANTS_KEY] });
339
+ }
340
+ });
341
+ }
342
+
343
+ // src/hooks/useCustomers.ts
344
+ var import_react_query2 = require("@tanstack/react-query");
345
+ var CUSTOMERS_KEY = "booking-admin-customers";
346
+ function useAdminCustomers(params) {
347
+ const client = useBookingAdminClient();
348
+ return (0, import_react_query2.useQuery)({
349
+ queryKey: [CUSTOMERS_KEY, params],
350
+ queryFn: () => client.getCustomers(params)
351
+ });
352
+ }
353
+ function useCreateCustomer() {
354
+ const client = useBookingAdminClient();
355
+ const queryClient = (0, import_react_query2.useQueryClient)();
356
+ return (0, import_react_query2.useMutation)({
357
+ mutationFn: (data) => client.createCustomer(data),
358
+ onSuccess: () => {
359
+ queryClient.invalidateQueries({ queryKey: [CUSTOMERS_KEY] });
360
+ }
361
+ });
362
+ }
363
+ function useUpdateCustomer() {
364
+ const client = useBookingAdminClient();
365
+ const queryClient = (0, import_react_query2.useQueryClient)();
366
+ return (0, import_react_query2.useMutation)({
367
+ mutationFn: ({ id, data }) => client.updateCustomer(id, data),
368
+ onSuccess: () => {
369
+ queryClient.invalidateQueries({ queryKey: [CUSTOMERS_KEY] });
370
+ }
371
+ });
372
+ }
373
+ function useDeleteCustomer() {
374
+ const client = useBookingAdminClient();
375
+ const queryClient = (0, import_react_query2.useQueryClient)();
376
+ return (0, import_react_query2.useMutation)({
377
+ mutationFn: (id) => client.deleteCustomer(id),
378
+ onSuccess: () => {
379
+ queryClient.invalidateQueries({ queryKey: [CUSTOMERS_KEY] });
380
+ }
381
+ });
382
+ }
383
+
384
+ // src/hooks/useSubscriptionPlans.ts
385
+ var import_react_query3 = require("@tanstack/react-query");
386
+ var SUBSCRIPTION_PLANS_KEY = "booking-admin-subscription-plans";
387
+ function useSubscriptionPlans(includeInactive) {
388
+ const client = useBookingAdminClient();
389
+ return (0, import_react_query3.useQuery)({
390
+ queryKey: [SUBSCRIPTION_PLANS_KEY, includeInactive],
391
+ queryFn: () => client.getSubscriptionPlans(includeInactive)
392
+ });
393
+ }
394
+ function useSubscriptionPlan(id) {
395
+ const client = useBookingAdminClient();
396
+ return (0, import_react_query3.useQuery)({
397
+ queryKey: [SUBSCRIPTION_PLANS_KEY, id],
398
+ queryFn: () => client.getSubscriptionPlan(id),
399
+ enabled: !!id
400
+ });
401
+ }
402
+ function useCreateSubscriptionPlan() {
403
+ const client = useBookingAdminClient();
404
+ const queryClient = (0, import_react_query3.useQueryClient)();
405
+ return (0, import_react_query3.useMutation)({
406
+ mutationFn: (data) => client.createSubscriptionPlan(data),
407
+ onSuccess: () => {
408
+ queryClient.invalidateQueries({ queryKey: [SUBSCRIPTION_PLANS_KEY] });
409
+ }
410
+ });
411
+ }
412
+ function useUpdateSubscriptionPlan() {
413
+ const client = useBookingAdminClient();
414
+ const queryClient = (0, import_react_query3.useQueryClient)();
415
+ return (0, import_react_query3.useMutation)({
416
+ mutationFn: ({ id, data }) => client.updateSubscriptionPlan(id, data),
417
+ onSuccess: () => {
418
+ queryClient.invalidateQueries({ queryKey: [SUBSCRIPTION_PLANS_KEY] });
419
+ }
420
+ });
421
+ }
422
+ function useDeleteSubscriptionPlan() {
423
+ const client = useBookingAdminClient();
424
+ const queryClient = (0, import_react_query3.useQueryClient)();
425
+ return (0, import_react_query3.useMutation)({
426
+ mutationFn: (id) => client.deleteSubscriptionPlan(id),
427
+ onSuccess: () => {
428
+ queryClient.invalidateQueries({ queryKey: [SUBSCRIPTION_PLANS_KEY] });
429
+ }
430
+ });
431
+ }
432
+
433
+ // src/hooks/useBillingPlans.ts
434
+ var import_react_query4 = require("@tanstack/react-query");
435
+ var BILLING_PLANS_KEY = "booking-admin-billing-plans";
436
+ function useBillingPlans(isActive) {
437
+ const client = useBookingAdminClient();
438
+ return (0, import_react_query4.useQuery)({
439
+ queryKey: [BILLING_PLANS_KEY, isActive],
440
+ queryFn: () => client.getBillingPlans(isActive)
441
+ });
442
+ }
443
+ function useCreateBillingPlan() {
444
+ const client = useBookingAdminClient();
445
+ const queryClient = (0, import_react_query4.useQueryClient)();
446
+ return (0, import_react_query4.useMutation)({
447
+ mutationFn: (data) => client.createBillingPlan(data),
448
+ onSuccess: () => {
449
+ queryClient.invalidateQueries({ queryKey: [BILLING_PLANS_KEY] });
450
+ }
451
+ });
452
+ }
453
+ function useUpdateBillingPlan() {
454
+ const client = useBookingAdminClient();
455
+ const queryClient = (0, import_react_query4.useQueryClient)();
456
+ return (0, import_react_query4.useMutation)({
457
+ mutationFn: ({ id, data }) => client.updateBillingPlan(id, data),
458
+ onSuccess: () => {
459
+ queryClient.invalidateQueries({ queryKey: [BILLING_PLANS_KEY] });
460
+ }
461
+ });
462
+ }
463
+ function useDeleteBillingPlan() {
464
+ const client = useBookingAdminClient();
465
+ const queryClient = (0, import_react_query4.useQueryClient)();
466
+ return (0, import_react_query4.useMutation)({
467
+ mutationFn: (id) => client.deleteBillingPlan(id),
468
+ onSuccess: () => {
469
+ queryClient.invalidateQueries({ queryKey: [BILLING_PLANS_KEY] });
470
+ }
471
+ });
472
+ }
473
+ function useSyncBillingPlanToStripe() {
474
+ const client = useBookingAdminClient();
475
+ const queryClient = (0, import_react_query4.useQueryClient)();
476
+ return (0, import_react_query4.useMutation)({
477
+ mutationFn: (id) => client.syncBillingPlanToStripe(id),
478
+ onSuccess: () => {
479
+ queryClient.invalidateQueries({ queryKey: [BILLING_PLANS_KEY] });
480
+ }
481
+ });
482
+ }
483
+
484
+ // src/hooks/useBillingSubscriptions.ts
485
+ var import_react_query5 = require("@tanstack/react-query");
486
+ var BILLING_SUBSCRIPTIONS_KEY = "booking-admin-billing-subscriptions";
487
+ function useBillingSubscriptions(params) {
488
+ const client = useBookingAdminClient();
489
+ return (0, import_react_query5.useQuery)({
490
+ queryKey: [BILLING_SUBSCRIPTIONS_KEY, params],
491
+ queryFn: () => client.getBillingSubscriptions(params)
492
+ });
493
+ }
494
+ function useBillingSubscription(id) {
495
+ const client = useBookingAdminClient();
496
+ return (0, import_react_query5.useQuery)({
497
+ queryKey: [BILLING_SUBSCRIPTIONS_KEY, id],
498
+ queryFn: () => client.getBillingSubscription(id),
499
+ enabled: !!id
500
+ });
501
+ }
502
+ function useCreateBillingSubscription() {
503
+ const client = useBookingAdminClient();
504
+ const queryClient = (0, import_react_query5.useQueryClient)();
505
+ return (0, import_react_query5.useMutation)({
506
+ mutationFn: (data) => client.createBillingSubscription(data),
507
+ onSuccess: () => {
508
+ queryClient.invalidateQueries({ queryKey: [BILLING_SUBSCRIPTIONS_KEY] });
509
+ }
510
+ });
511
+ }
512
+ function useCancelBillingSubscription() {
513
+ const client = useBookingAdminClient();
514
+ const queryClient = (0, import_react_query5.useQueryClient)();
515
+ return (0, import_react_query5.useMutation)({
516
+ mutationFn: ({ id, atPeriodEnd }) => client.cancelBillingSubscription(id, atPeriodEnd),
517
+ onSuccess: () => {
518
+ queryClient.invalidateQueries({ queryKey: [BILLING_SUBSCRIPTIONS_KEY] });
519
+ }
520
+ });
521
+ }
522
+ function useChangeBillingSubscriptionPlan() {
523
+ const client = useBookingAdminClient();
524
+ const queryClient = (0, import_react_query5.useQueryClient)();
525
+ return (0, import_react_query5.useMutation)({
526
+ mutationFn: ({ id, newPlanSlug }) => client.changeBillingSubscriptionPlan(id, newPlanSlug),
527
+ onSuccess: () => {
528
+ queryClient.invalidateQueries({ queryKey: [BILLING_SUBSCRIPTIONS_KEY] });
529
+ }
530
+ });
531
+ }
532
+
533
+ // src/hooks/useSettings.ts
534
+ var import_react_query6 = require("@tanstack/react-query");
535
+ var SETTINGS_KEY = "booking-admin-billing-settings";
536
+ function useBillingSettings() {
537
+ const client = useBookingAdminClient();
538
+ return (0, import_react_query6.useQuery)({
539
+ queryKey: [SETTINGS_KEY],
540
+ queryFn: () => client.getBillingSettings()
541
+ });
542
+ }
543
+ function useUpdateBillingSettings() {
544
+ const client = useBookingAdminClient();
545
+ const queryClient = (0, import_react_query6.useQueryClient)();
546
+ return (0, import_react_query6.useMutation)({
547
+ mutationFn: (data) => client.updateBillingSettings(data),
548
+ onSuccess: () => {
549
+ queryClient.invalidateQueries({ queryKey: [SETTINGS_KEY] });
550
+ }
551
+ });
552
+ }
553
+ function useTestBillingConnection() {
554
+ const client = useBookingAdminClient();
555
+ return (0, import_react_query6.useMutation)({
556
+ mutationFn: () => client.testBillingConnection()
557
+ });
558
+ }
559
+
560
+ // src/utils/formatters.ts
561
+ function formatCurrency(amount, currency = "EUR", locale = "it-IT") {
562
+ return new Intl.NumberFormat(locale, {
563
+ style: "currency",
564
+ currency: currency.toUpperCase()
565
+ }).format(amount);
566
+ }
567
+ function formatCurrencyFromCents(amountCents, currency = "EUR", locale = "it-IT") {
568
+ return formatCurrency(amountCents / 100, currency, locale);
569
+ }
570
+ function formatPrice(price, currency = "EUR", locale = "it-IT") {
571
+ if (price === null) return "Contattaci";
572
+ return new Intl.NumberFormat(locale, {
573
+ style: "currency",
574
+ currency: currency.toUpperCase(),
575
+ minimumFractionDigits: 0,
576
+ maximumFractionDigits: 0
577
+ }).format(price);
578
+ }
579
+ function formatDate(date, locale = "it-IT") {
580
+ if (!date) return "N/A";
581
+ const d = typeof date === "string" ? new Date(date) : date;
582
+ if (isNaN(d.getTime())) return "N/A";
583
+ return new Intl.DateTimeFormat(locale, {
584
+ day: "numeric",
585
+ month: "short",
586
+ year: "numeric"
587
+ }).format(d);
588
+ }
589
+ function formatTimestamp(timestamp, includeTime = false, locale = "it-IT") {
590
+ if (!timestamp) return "-";
591
+ const date = new Date(timestamp * 1e3);
592
+ if (includeTime) {
593
+ return date.toLocaleDateString(locale, {
594
+ day: "2-digit",
595
+ month: "short",
596
+ year: "numeric",
597
+ hour: "2-digit",
598
+ minute: "2-digit"
599
+ });
600
+ }
601
+ return date.toLocaleDateString(locale, {
602
+ day: "2-digit",
603
+ month: "short",
604
+ year: "numeric"
605
+ });
606
+ }
607
+ function truncateId(id, maxLength = 20) {
608
+ if (id.length <= maxLength) return id;
609
+ return `${id.slice(0, 10)}...${id.slice(-6)}`;
610
+ }
611
+
612
+ // src/utils/status.ts
613
+ var tenantStatusColors = {
614
+ active: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
615
+ inactive: "bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400"
616
+ };
617
+ var tenantStatusLabels = {
618
+ active: "Attivo",
619
+ inactive: "Inattivo"
620
+ };
621
+ var tenantPlanColors = {
622
+ free: "bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400",
623
+ starter: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
624
+ professional: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
625
+ enterprise: "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"
626
+ };
627
+ var tenantPlanLabels = {
628
+ free: "Free",
629
+ starter: "Starter",
630
+ professional: "Professional",
631
+ enterprise: "Enterprise"
632
+ };
633
+ var billingSubscriptionStatusColors = {
634
+ active: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
635
+ trialing: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
636
+ past_due: "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",
637
+ canceled: "bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400",
638
+ unpaid: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
639
+ incomplete: "bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400"
640
+ };
641
+ var billingSubscriptionStatusLabels = {
642
+ active: "Attivo",
643
+ trialing: "In Prova",
644
+ past_due: "Scaduto",
645
+ canceled: "Cancellato",
646
+ unpaid: "Non Pagato",
647
+ incomplete: "Incompleto"
648
+ };
649
+
650
+ // src/utils/validators.ts
651
+ function validateSlug(slug) {
652
+ if (!slug.trim()) {
653
+ return "Lo slug \xE8 obbligatorio";
654
+ }
655
+ if (!/^[a-z0-9-]+$/.test(slug)) {
656
+ return "Lo slug pu\xF2 contenere solo lettere minuscole, numeri e trattini";
657
+ }
658
+ return null;
659
+ }
660
+ function validateRequired(value, fieldName) {
661
+ if (!value.trim()) {
662
+ return `${fieldName} \xE8 obbligatorio`;
663
+ }
664
+ return null;
665
+ }
666
+ function validateEmail(email) {
667
+ if (!email.trim()) {
668
+ return "L'email \xE8 obbligatoria";
669
+ }
670
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
671
+ return "Formato email non valido";
672
+ }
673
+ return null;
674
+ }
675
+ // Annotate the CommonJS export names for ESM import in node:
676
+ 0 && (module.exports = {
677
+ BookingAdminApiClient,
678
+ BookingAdminClientContext,
679
+ billingSubscriptionStatusColors,
680
+ billingSubscriptionStatusLabels,
681
+ createBookingAdminClient,
682
+ formatCurrency,
683
+ formatCurrencyFromCents,
684
+ formatDate,
685
+ formatPrice,
686
+ formatTimestamp,
687
+ tenantPlanColors,
688
+ tenantPlanLabels,
689
+ tenantStatusColors,
690
+ tenantStatusLabels,
691
+ truncateId,
692
+ useAdminCustomers,
693
+ useAdminTenant,
694
+ useAdminTenants,
695
+ useBillingPlans,
696
+ useBillingSettings,
697
+ useBillingSubscription,
698
+ useBillingSubscriptions,
699
+ useBookingAdminClient,
700
+ useCancelBillingSubscription,
701
+ useChangeBillingSubscriptionPlan,
702
+ useCreateBillingPlan,
703
+ useCreateBillingSubscription,
704
+ useCreateCustomer,
705
+ useCreateSubscriptionPlan,
706
+ useCreateTenant,
707
+ useDeleteBillingPlan,
708
+ useDeleteCustomer,
709
+ useDeleteSubscriptionPlan,
710
+ useDeleteTenant,
711
+ useDialogState,
712
+ useSubscriptionPlan,
713
+ useSubscriptionPlans,
714
+ useSyncBillingPlanToStripe,
715
+ useTenantLimits,
716
+ useTestBillingConnection,
717
+ useUpdateBillingPlan,
718
+ useUpdateBillingSettings,
719
+ useUpdateCustomer,
720
+ useUpdateSubscriptionPlan,
721
+ useUpdateTenant,
722
+ useUpdateTenantLimits,
723
+ useUpdateTenantPlan,
724
+ useUpdateTenantStatus,
725
+ validateEmail,
726
+ validateRequired,
727
+ validateSlug
728
+ });
729
+ //# sourceMappingURL=index.js.map