@growflowstudio/growflowbilling-admin-core 2.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.
@@ -0,0 +1,447 @@
1
+ import * as react from 'react';
2
+ import * as _tanstack_react_query from '@tanstack/react-query';
3
+
4
+ type AdminPlanPricingModel = 'flat' | 'tiered' | 'per_unit' | 'usage_based';
5
+ interface AdminPlan {
6
+ id: string;
7
+ client_id: string;
8
+ slug: string;
9
+ name: string;
10
+ description: string | null;
11
+ pricing_model: AdminPlanPricingModel;
12
+ price_monthly: number | null;
13
+ price_yearly: number | null;
14
+ currency: string;
15
+ stripe_price_id_monthly: string | null;
16
+ stripe_price_id_yearly: string | null;
17
+ limits: Record<string, number> | null;
18
+ features: string[] | null;
19
+ trial_days: number;
20
+ is_active: boolean;
21
+ contact_sales: boolean;
22
+ color: string;
23
+ sort_order: number;
24
+ created_at: string;
25
+ updated_at: string;
26
+ }
27
+ interface AdminPlanCreate {
28
+ slug: string;
29
+ name: string;
30
+ description?: string;
31
+ pricing_model?: AdminPlanPricingModel;
32
+ price_monthly?: number;
33
+ price_yearly?: number;
34
+ currency?: string;
35
+ limits?: Record<string, number>;
36
+ features?: string[];
37
+ trial_days?: number;
38
+ is_active?: boolean;
39
+ contact_sales?: boolean;
40
+ color?: string;
41
+ sort_order?: number;
42
+ }
43
+ interface AdminPlanUpdate {
44
+ name?: string;
45
+ description?: string;
46
+ pricing_model?: AdminPlanPricingModel;
47
+ price_monthly?: number;
48
+ price_yearly?: number;
49
+ limits?: Record<string, number>;
50
+ features?: string[];
51
+ trial_days?: number;
52
+ is_active?: boolean;
53
+ contact_sales?: boolean;
54
+ color?: string;
55
+ sort_order?: number;
56
+ }
57
+
58
+ type AdminSubscriptionStatus = 'active' | 'trialing' | 'past_due' | 'canceled' | 'unpaid' | 'incomplete';
59
+ interface AdminSubscription {
60
+ id: string;
61
+ subscriber_id: string;
62
+ subscriber_external_id: string;
63
+ subscriber_email: string;
64
+ subscriber_name: string | null;
65
+ plan_id: string;
66
+ plan_slug: string;
67
+ plan_name: string;
68
+ stripe_subscription_id: string | null;
69
+ status: AdminSubscriptionStatus;
70
+ billing_cycle: 'monthly' | 'yearly';
71
+ current_period_start: string | null;
72
+ current_period_end: string | null;
73
+ trial_start: string | null;
74
+ trial_end: string | null;
75
+ canceled_at: string | null;
76
+ cancel_at: string | null;
77
+ created_at: string;
78
+ updated_at: string;
79
+ }
80
+ interface AdminSubscriptionCreate {
81
+ subscriber_external_id: string;
82
+ subscriber_email: string;
83
+ subscriber_name?: string;
84
+ plan_slug: string;
85
+ billing_cycle?: 'monthly' | 'yearly';
86
+ }
87
+
88
+ interface PaginatedResponse<T> {
89
+ items: T[];
90
+ total: number;
91
+ }
92
+ interface CursorPaginatedResponse<T> {
93
+ data: T[];
94
+ has_more: boolean;
95
+ }
96
+ /** Represents any valid JSON primitive value */
97
+ type JsonPrimitive = string | number | boolean | null;
98
+ /** Represents a valid JSON object */
99
+ type JsonObject = {
100
+ [key: string]: JsonValue;
101
+ };
102
+ /** Represents a valid JSON array */
103
+ type JsonArray = JsonValue[];
104
+ /** Represents any valid JSON value (recursive) */
105
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
106
+ /** Billing recurring interval */
107
+ type RecurringInterval = 'month' | 'year' | 'week' | 'day';
108
+ /** Refund status from Stripe */
109
+ type RefundStatus = 'pending' | 'succeeded' | 'failed' | 'canceled';
110
+
111
+ type AdminPaymentStatus = 'succeeded' | 'pending' | 'failed' | 'canceled' | 'requires_payment_method';
112
+ interface AdminPayment {
113
+ id: string;
114
+ amount: number;
115
+ currency: string;
116
+ status: AdminPaymentStatus;
117
+ created: number;
118
+ customer_id: string | null;
119
+ customer_email: string | null;
120
+ description: string | null;
121
+ metadata: Record<string, string>;
122
+ }
123
+ interface AdminPaymentRefund {
124
+ id: string;
125
+ amount: number;
126
+ status: RefundStatus;
127
+ reason: string | null;
128
+ created: number;
129
+ }
130
+
131
+ type AdminInvoiceStatus = 'draft' | 'open' | 'paid' | 'void' | 'uncollectible';
132
+ interface AdminInvoice {
133
+ id: string;
134
+ number: string | null;
135
+ status: AdminInvoiceStatus;
136
+ amount_due: number;
137
+ amount_paid: number;
138
+ amount_remaining: number;
139
+ currency: string;
140
+ created: number;
141
+ due_date: number | null;
142
+ customer_id: string | null;
143
+ customer_email: string | null;
144
+ customer_name: string | null;
145
+ subscription_id: string | null;
146
+ invoice_pdf: string | null;
147
+ hosted_invoice_url: string | null;
148
+ lines: AdminInvoiceLineItem[];
149
+ }
150
+ interface AdminInvoiceLineItem {
151
+ id: string;
152
+ description: string;
153
+ amount: number;
154
+ quantity: number;
155
+ currency: string;
156
+ }
157
+
158
+ /** Known fields in product extra_data. Extends index signature to allow additional project-specific fields. */
159
+ interface ProductExtraData {
160
+ feature_slug?: string;
161
+ [key: string]: JsonValue | undefined;
162
+ }
163
+ interface AdminProduct {
164
+ id: string;
165
+ client_id: string;
166
+ stripe_product_id: string | null;
167
+ stripe_price_id: string | null;
168
+ name: string;
169
+ description: string | null;
170
+ price_cents: number;
171
+ currency: string;
172
+ recurring_interval: RecurringInterval | null;
173
+ category: string | null;
174
+ is_active: boolean;
175
+ extra_data: ProductExtraData | null;
176
+ created_at: string | null;
177
+ updated_at: string | null;
178
+ }
179
+ interface AdminProductCreate {
180
+ client_id?: string;
181
+ name: string;
182
+ description?: string;
183
+ price_cents: number;
184
+ currency?: string;
185
+ recurring_interval?: RecurringInterval;
186
+ category?: string;
187
+ is_active?: boolean;
188
+ sync_stripe?: boolean;
189
+ extra_data?: ProductExtraData;
190
+ }
191
+ interface AdminProductUpdate {
192
+ name?: string;
193
+ description?: string;
194
+ price_cents?: number;
195
+ currency?: string;
196
+ recurring_interval?: RecurringInterval;
197
+ category?: string;
198
+ is_active?: boolean;
199
+ extra_data?: ProductExtraData;
200
+ }
201
+
202
+ /** Admin Feature — corresponds to the Feature entity in the billing system */
203
+ interface AdminFeature {
204
+ id: string;
205
+ slug: string;
206
+ name: string;
207
+ description: string | null;
208
+ icon: string | null;
209
+ category: string | null;
210
+ is_available: boolean;
211
+ billing_product_id: string | null;
212
+ default_config: JsonObject;
213
+ created_at: string;
214
+ updated_at: string;
215
+ }
216
+ interface AdminFeatureCreate {
217
+ slug: string;
218
+ name: string;
219
+ description?: string;
220
+ icon?: string;
221
+ category?: string;
222
+ is_available?: boolean;
223
+ billing_product_id?: string;
224
+ default_config?: JsonObject;
225
+ }
226
+ interface AdminFeatureUpdate {
227
+ name?: string;
228
+ description?: string;
229
+ icon?: string;
230
+ category?: string;
231
+ is_available?: boolean;
232
+ billing_product_id?: string;
233
+ default_config?: JsonObject;
234
+ }
235
+ interface AdminFeatureListResponse {
236
+ features: AdminFeature[];
237
+ total: number;
238
+ }
239
+ interface AdminFeatureFilters {
240
+ available_only?: boolean;
241
+ category?: string;
242
+ }
243
+
244
+ /**
245
+ * A generic fetcher function that consumer projects provide.
246
+ * It handles auth tokens, refresh, and base URL internally.
247
+ */
248
+ type Fetcher = <T>(url: string, options?: RequestInit) => Promise<T>;
249
+ interface BillingAdminClientConfig {
250
+ /** Base path for billing admin API (e.g., '/api/v1/billing-admin') */
251
+ basePath: string;
252
+ /** HTTP fetcher function provided by the host application */
253
+ fetcher: Fetcher;
254
+ }
255
+ declare class BillingAdminApiClient {
256
+ private basePath;
257
+ private fetcher;
258
+ constructor(config: BillingAdminClientConfig);
259
+ private url;
260
+ getPlans(params?: {
261
+ is_active?: boolean;
262
+ }): Promise<PaginatedResponse<AdminPlan>>;
263
+ getPlan(planId: string): Promise<AdminPlan>;
264
+ createPlan(data: AdminPlanCreate): Promise<AdminPlan>;
265
+ updatePlan(planId: string, data: AdminPlanUpdate): Promise<AdminPlan>;
266
+ deletePlan(planId: string): Promise<void>;
267
+ syncPlanToStripe(planId: string): Promise<AdminPlan>;
268
+ getSubscriptions(params?: {
269
+ status?: AdminSubscriptionStatus;
270
+ search?: string;
271
+ limit?: number;
272
+ offset?: number;
273
+ }): Promise<PaginatedResponse<AdminSubscription>>;
274
+ getSubscription(subscriptionId: string): Promise<AdminSubscription>;
275
+ cancelSubscription(subscriptionId: string, atPeriodEnd?: boolean): Promise<AdminSubscription>;
276
+ createSubscription(data: AdminSubscriptionCreate): Promise<AdminSubscription>;
277
+ changeSubscriptionPlan(subscriptionId: string, newPlanSlug: string): Promise<void>;
278
+ getPayments(params?: {
279
+ status?: AdminPaymentStatus | string;
280
+ search?: string;
281
+ limit?: number;
282
+ starting_after?: string;
283
+ }): Promise<CursorPaginatedResponse<AdminPayment>>;
284
+ getPayment(paymentId: string): Promise<AdminPayment>;
285
+ refundPayment(paymentId: string, params?: {
286
+ amount?: number;
287
+ reason?: 'duplicate' | 'fraudulent' | 'requested_by_customer';
288
+ }): Promise<AdminPaymentRefund>;
289
+ getInvoices(params?: {
290
+ status?: string;
291
+ search?: string;
292
+ store_id?: string;
293
+ limit?: number;
294
+ starting_after?: string;
295
+ }): Promise<CursorPaginatedResponse<AdminInvoice>>;
296
+ getInvoice(invoiceId: string): Promise<AdminInvoice>;
297
+ sendInvoice(invoiceId: string): Promise<AdminInvoice>;
298
+ voidInvoice(invoiceId: string): Promise<AdminInvoice>;
299
+ getProducts(params?: {
300
+ is_active?: boolean;
301
+ }): Promise<PaginatedResponse<AdminProduct>>;
302
+ getProduct(productId: string): Promise<AdminProduct>;
303
+ createProduct(data: AdminProductCreate): Promise<AdminProduct>;
304
+ updateProduct(productId: string, data: AdminProductUpdate): Promise<AdminProduct>;
305
+ deleteProduct(productId: string): Promise<void>;
306
+ syncProductToStripe(productId: string): Promise<AdminProduct>;
307
+ getFeatures(params?: AdminFeatureFilters): Promise<AdminFeatureListResponse>;
308
+ getAvailableFeatures(category?: string): Promise<AdminFeatureListResponse>;
309
+ getFeature(featureId: string): Promise<AdminFeature>;
310
+ createFeature(data: AdminFeatureCreate): Promise<AdminFeature>;
311
+ updateFeature(featureId: string, data: AdminFeatureUpdate): Promise<AdminFeature>;
312
+ deleteFeature(featureId: string): Promise<void>;
313
+ getClientInfo(): Promise<{
314
+ client_id: string | null;
315
+ }>;
316
+ }
317
+ /**
318
+ * Factory function to create a BillingAdminApiClient instance.
319
+ */
320
+ declare function createBillingAdminClient(config: BillingAdminClientConfig): BillingAdminApiClient;
321
+
322
+ declare const BillingAdminClientContext: react.Context<BillingAdminApiClient | null>;
323
+ declare function useBillingAdminClient(): BillingAdminApiClient;
324
+
325
+ /**
326
+ * Generic hook for managing dialog state with optional associated data.
327
+ */
328
+ declare function useDialogState<T = undefined>(): {
329
+ isOpen: boolean;
330
+ data: T | undefined;
331
+ open: (initialData?: T) => void;
332
+ close: () => void;
333
+ toggle: () => void;
334
+ setData: react.Dispatch<react.SetStateAction<T | undefined>>;
335
+ };
336
+
337
+ declare function useAdminPlans(params?: {
338
+ is_active?: boolean;
339
+ }): _tanstack_react_query.UseQueryResult<PaginatedResponse<AdminPlan>, Error>;
340
+ declare function useCreatePlan(): _tanstack_react_query.UseMutationResult<AdminPlan, Error, AdminPlanCreate, unknown>;
341
+ declare function useUpdatePlan(): _tanstack_react_query.UseMutationResult<AdminPlan, Error, {
342
+ id: string;
343
+ data: AdminPlanUpdate;
344
+ }, unknown>;
345
+ declare function useDeletePlan(): _tanstack_react_query.UseMutationResult<void, Error, string, unknown>;
346
+ declare function useSyncPlanToStripe(): _tanstack_react_query.UseMutationResult<AdminPlan, Error, string, unknown>;
347
+
348
+ declare function useAdminSubscriptions(params?: {
349
+ status?: AdminSubscriptionStatus;
350
+ search?: string;
351
+ limit?: number;
352
+ offset?: number;
353
+ }): _tanstack_react_query.UseQueryResult<PaginatedResponse<AdminSubscription>, Error>;
354
+ declare function useCreateSubscription(): _tanstack_react_query.UseMutationResult<AdminSubscription, Error, AdminSubscriptionCreate, unknown>;
355
+ declare function useCancelSubscription(): _tanstack_react_query.UseMutationResult<AdminSubscription, Error, {
356
+ id: string;
357
+ atPeriodEnd: boolean;
358
+ }, unknown>;
359
+ declare function useChangeSubscriptionPlan(): _tanstack_react_query.UseMutationResult<void, Error, {
360
+ id: string;
361
+ newPlanSlug: string;
362
+ }, unknown>;
363
+
364
+ declare function useAdminPayments(params?: {
365
+ status?: string;
366
+ search?: string;
367
+ limit?: number;
368
+ starting_after?: string;
369
+ }): _tanstack_react_query.UseQueryResult<CursorPaginatedResponse<AdminPayment>, Error>;
370
+ declare function useRefundPayment(): _tanstack_react_query.UseMutationResult<AdminPaymentRefund, Error, {
371
+ id: string;
372
+ amount?: number;
373
+ reason?: "duplicate" | "fraudulent" | "requested_by_customer";
374
+ }, unknown>;
375
+
376
+ declare function useAdminInvoices(params?: {
377
+ status?: string;
378
+ search?: string;
379
+ store_id?: string;
380
+ limit?: number;
381
+ starting_after?: string;
382
+ }): _tanstack_react_query.UseQueryResult<CursorPaginatedResponse<AdminInvoice>, Error>;
383
+ declare function useSendInvoice(): _tanstack_react_query.UseMutationResult<AdminInvoice, Error, string, unknown>;
384
+ declare function useVoidInvoice(): _tanstack_react_query.UseMutationResult<AdminInvoice, Error, string, unknown>;
385
+
386
+ declare function useAdminProducts(params?: {
387
+ is_active?: boolean;
388
+ }): _tanstack_react_query.UseQueryResult<PaginatedResponse<AdminProduct>, Error>;
389
+ declare function useCreateProduct(): _tanstack_react_query.UseMutationResult<AdminProduct, Error, AdminProductCreate, unknown>;
390
+ declare function useUpdateProduct(): _tanstack_react_query.UseMutationResult<AdminProduct, Error, {
391
+ id: string;
392
+ data: AdminProductUpdate;
393
+ }, unknown>;
394
+ declare function useDeleteProduct(): _tanstack_react_query.UseMutationResult<void, Error, string, unknown>;
395
+ declare function useSyncProductToStripe(): _tanstack_react_query.UseMutationResult<AdminProduct, Error, string, unknown>;
396
+
397
+ declare function useAdminFeatures(params?: AdminFeatureFilters): _tanstack_react_query.UseQueryResult<AdminFeatureListResponse, Error>;
398
+ declare function useAvailableFeatures(category?: string): _tanstack_react_query.UseQueryResult<AdminFeatureListResponse, Error>;
399
+ declare function useCreateFeature(): _tanstack_react_query.UseMutationResult<AdminFeature, Error, AdminFeatureCreate, unknown>;
400
+ declare function useUpdateFeature(): _tanstack_react_query.UseMutationResult<AdminFeature, Error, {
401
+ id: string;
402
+ data: AdminFeatureUpdate;
403
+ }, unknown>;
404
+ declare function useDeleteFeature(): _tanstack_react_query.UseMutationResult<void, Error, string, unknown>;
405
+
406
+ /**
407
+ * Format a currency amount using Intl.NumberFormat.
408
+ */
409
+ declare function formatCurrency(amount: number, currency?: string, locale?: string): string;
410
+ /**
411
+ * Format amount in cents to currency string.
412
+ */
413
+ declare function formatCurrencyFromCents(amountCents: number, currency?: string, locale?: string): string;
414
+ /**
415
+ * Format a price, returning "Contattaci" for null values.
416
+ */
417
+ declare function formatPrice(price: number | null, currency?: string, locale?: string): string;
418
+ /**
419
+ * Format a date string or Date object.
420
+ */
421
+ declare function formatDate(date: Date | string | undefined | null, locale?: string): string;
422
+ /**
423
+ * Format a Unix timestamp (seconds) to date string.
424
+ */
425
+ declare function formatTimestamp(timestamp: number | null, includeTime?: boolean, locale?: string): string;
426
+ /**
427
+ * Truncate long IDs for display.
428
+ */
429
+ declare function truncateId(id: string, maxLength?: number): string;
430
+
431
+ declare const subscriptionStatusColors: Record<AdminSubscriptionStatus, string>;
432
+ declare const subscriptionStatusLabels: Record<AdminSubscriptionStatus, string>;
433
+ declare const paymentStatusColors: Record<AdminPaymentStatus, string>;
434
+ declare const paymentStatusLabels: Record<AdminPaymentStatus, string>;
435
+ declare const invoiceStatusColors: Record<AdminInvoiceStatus, string>;
436
+ declare const invoiceStatusLabels: Record<AdminInvoiceStatus, string>;
437
+
438
+ /**
439
+ * Validate a plan slug format.
440
+ */
441
+ declare function validateSlug(slug: string): string | null;
442
+ /**
443
+ * Validate required string field.
444
+ */
445
+ declare function validateRequired(value: string, fieldName: string): string | null;
446
+
447
+ export { type AdminFeature, type AdminFeatureCreate, type AdminFeatureFilters, type AdminFeatureListResponse, type AdminFeatureUpdate, type AdminInvoice, type AdminInvoiceLineItem, type AdminInvoiceStatus, type AdminPayment, type AdminPaymentRefund, type AdminPaymentStatus, type AdminPlan, type AdminPlanCreate, type AdminPlanPricingModel, type AdminPlanUpdate, type AdminProduct, type AdminProductCreate, type AdminProductUpdate, type AdminSubscription, type AdminSubscriptionCreate, type AdminSubscriptionStatus, BillingAdminApiClient, type BillingAdminClientConfig, BillingAdminClientContext, type CursorPaginatedResponse, type Fetcher, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type PaginatedResponse, type ProductExtraData, type RecurringInterval, type RefundStatus, createBillingAdminClient, formatCurrency, formatCurrencyFromCents, formatDate, formatPrice, formatTimestamp, invoiceStatusColors, invoiceStatusLabels, paymentStatusColors, paymentStatusLabels, subscriptionStatusColors, subscriptionStatusLabels, truncateId, useAdminFeatures, useAdminInvoices, useAdminPayments, useAdminPlans, useAdminProducts, useAdminSubscriptions, useAvailableFeatures, useBillingAdminClient, useCancelSubscription, useChangeSubscriptionPlan, useCreateFeature, useCreatePlan, useCreateProduct, useCreateSubscription, useDeleteFeature, useDeletePlan, useDeleteProduct, useDialogState, useRefundPayment, useSendInvoice, useSyncPlanToStripe, useSyncProductToStripe, useUpdateFeature, useUpdatePlan, useUpdateProduct, useVoidInvoice, validateRequired, validateSlug };