@neosianexus/super-tebex 2.0.2 → 3.0.2

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.d.ts CHANGED
@@ -1,126 +1,731 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- import { Basket, Category, InBasket, Package, PackageType, TebexHeadless } from 'tebex_headless';
3
+ import { QueryClient } from '@tanstack/react-query';
4
+ import { ReactNode } from 'react';
5
+ import { Basket, BasketPackage, Category, Code, GiftCardCode, Package, PackageType, TebexHeadless, Webstore } from 'tebex_headless';
4
6
 
5
- export interface GetShopUrlsResult {
6
- completeUrl: string;
7
- cancelUrl: string;
8
- }
9
- export declare const useCreateBasket: (username: string | null) => (() => Promise<Basket | null>);
10
- export declare let shopUrls: GetShopUrlsResult | null;
11
- export declare const initShopUrls: (baseUrl: string, paths?: {
12
- complete?: string;
13
- cancel?: string;
14
- }) => void;
15
- export declare let tebex: TebexHeadless | null;
16
- export declare const initTebex: (publicKey: string) => void;
17
- export declare const getTebex: () => TebexHeadless;
18
- export interface UseBasketResult {
19
- basket: Basket | null;
20
- loading: boolean;
21
- error: Error | null;
22
- addPackageToBasket: (packageId: Package["id"], quantity?: InBasket["quantity"], type?: PackageType, variableData?: Record<string, string>) => Promise<void>;
23
- removePackageFromBasket: (packageId: Package["id"]) => Promise<void>;
24
- updateManualBasket: (basket: Basket | null) => void;
25
- refetch: () => Promise<void>;
26
- }
27
- export declare const useBasket: (username: string | null) => UseBasketResult;
28
- export interface CreateBasketProps {
29
- username: string;
30
- completeUrl: string;
31
- cancelUrl: string;
32
- custom?: Record<string, any>;
33
- completeAutoRedirect?: boolean;
34
- ipAddress?: string;
35
- }
36
- export interface ShopBasketStore {
37
- basketIdent: string | null;
38
- setBasketIdent: (basketIdent: string) => void;
39
- clearBasketIdent: () => void;
40
- }
41
- export interface GetCategories {
42
- includePackages?: boolean;
43
- basketIdent?: string;
44
- ipAddress?: string;
45
- }
46
- export interface UseCategoriesResult {
47
- categories: Category[] | null;
48
- loading: boolean;
49
- error: Error | null;
50
- getByName: (name: string) => Category | undefined;
51
- refetch: () => Promise<void>;
52
- }
53
- export declare const useCategories: (options: GetCategories) => UseCategoriesResult;
54
- export declare const basketService: {
55
- createBasket: ({ username, completeUrl, cancelUrl, custom, completeAutoRedirect, ipAddress, }: CreateBasketProps) => Promise<Basket>;
56
- getBasket: (basketIdent: Basket["ident"]) => Promise<Basket>;
57
- addPackageToBasket: (basketIdent: Basket["ident"], packageId: Package["id"], quantity?: InBasket["quantity"], type?: PackageType, variableData?: Record<string, string>) => Promise<Basket>;
58
- removePackageFromBasket: (basketIdent: Basket["ident"], packageId: Package["id"], currentQuantity: InBasket["quantity"]) => Promise<Basket>;
59
- };
60
- export declare const categoriesService: {
61
- getCategories: ({ includePackages, basketIdent, ipAddress, }: GetCategories) => Promise<Category[]>;
62
- };
63
- export declare const useShopBasketStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<ShopBasketStore>, "subscribe"> & {
7
+ /**
8
+ * Enumeration of all possible Tebex error codes.
9
+ * Consumers can use these codes to provide localized error messages.
10
+ */
11
+ export declare enum TebexErrorCode {
12
+ PROVIDER_NOT_FOUND = "PROVIDER_NOT_FOUND",
13
+ INVALID_CONFIG = "INVALID_CONFIG",
14
+ NOT_AUTHENTICATED = "NOT_AUTHENTICATED",
15
+ INVALID_USERNAME = "INVALID_USERNAME",
16
+ BASKET_NOT_FOUND = "BASKET_NOT_FOUND",
17
+ BASKET_CREATION_FAILED = "BASKET_CREATION_FAILED",
18
+ BASKET_EXPIRED = "BASKET_EXPIRED",
19
+ BASKET_EMPTY = "BASKET_EMPTY",
20
+ PACKAGE_NOT_FOUND = "PACKAGE_NOT_FOUND",
21
+ PACKAGE_OUT_OF_STOCK = "PACKAGE_OUT_OF_STOCK",
22
+ PACKAGE_ALREADY_OWNED = "PACKAGE_ALREADY_OWNED",
23
+ INVALID_QUANTITY = "INVALID_QUANTITY",
24
+ CATEGORY_NOT_FOUND = "CATEGORY_NOT_FOUND",
25
+ COUPON_INVALID = "COUPON_INVALID",
26
+ COUPON_EXPIRED = "COUPON_EXPIRED",
27
+ COUPON_ALREADY_USED = "COUPON_ALREADY_USED",
28
+ GIFTCARD_INVALID = "GIFTCARD_INVALID",
29
+ GIFTCARD_INSUFFICIENT_BALANCE = "GIFTCARD_INSUFFICIENT_BALANCE",
30
+ CREATOR_CODE_INVALID = "CREATOR_CODE_INVALID",
31
+ CHECKOUT_FAILED = "CHECKOUT_FAILED",
32
+ CHECKOUT_CANCELLED = "CHECKOUT_CANCELLED",
33
+ TEBEX_JS_NOT_LOADED = "TEBEX_JS_NOT_LOADED",
34
+ NETWORK_ERROR = "NETWORK_ERROR",
35
+ TIMEOUT = "TIMEOUT",
36
+ RATE_LIMITED = "RATE_LIMITED",
37
+ UNKNOWN = "UNKNOWN"
38
+ }
39
+ /**
40
+ * Custom error class for Tebex SDK errors.
41
+ * Provides structured error handling with error codes.
42
+ */
43
+ export declare class TebexError extends Error {
44
+ readonly code: TebexErrorCode;
45
+ readonly cause?: unknown;
46
+ constructor(code: TebexErrorCode, message?: string, cause?: unknown);
47
+ /**
48
+ * Converts an unknown error to a TebexError.
49
+ * If the error is already a TebexError, it returns it as-is.
50
+ */
51
+ static fromUnknown(error: unknown): TebexError;
52
+ /**
53
+ * Returns a JSON representation of the error.
54
+ */
55
+ toJSON(): {
56
+ name: string;
57
+ code: TebexErrorCode;
58
+ message: string;
59
+ };
60
+ }
61
+ /**
62
+ * URL configuration for checkout redirects.
63
+ */
64
+ export interface TebexUrls {
65
+ /** URL to redirect after successful payment. Default: /shop/complete */
66
+ readonly complete?: string | undefined;
67
+ /** URL to redirect after cancelled payment. Default: /shop/cancel */
68
+ readonly cancel?: string | undefined;
69
+ }
70
+ /**
71
+ * Main configuration for TebexProvider.
72
+ */
73
+ export interface TebexConfig {
74
+ /** Your Tebex public/webstore key */
75
+ readonly publicKey: string;
76
+ /** Base URL of your site (e.g., https://mysite.com) */
77
+ readonly baseUrl: string;
78
+ /** Optional URL paths for checkout redirects */
79
+ readonly urls?: TebexUrls | undefined;
80
+ /** Global error handler callback */
81
+ readonly onError?: ((error: TebexError) => void) | undefined;
82
+ /** Enable React Query DevTools. Default: true in development */
83
+ readonly devtools?: boolean | undefined;
84
+ }
85
+ /**
86
+ * Internal resolved configuration with default values applied.
87
+ */
88
+ export interface ResolvedTebexConfig {
89
+ readonly publicKey: string;
90
+ readonly baseUrl: string;
91
+ readonly completeUrl: string;
92
+ readonly cancelUrl: string;
93
+ readonly onError?: ((error: TebexError) => void) | undefined;
94
+ readonly devtools: boolean;
95
+ }
96
+ /**
97
+ * Context value provided by TebexProvider.
98
+ */
99
+ export interface TebexContextValue {
100
+ readonly config: ResolvedTebexConfig;
101
+ readonly queryClient: QueryClient;
102
+ }
103
+ /**
104
+ * Props for TebexProvider component.
105
+ */
106
+ export interface TebexProviderProps {
107
+ readonly children: ReactNode;
108
+ readonly config: TebexConfig;
109
+ /** Optional custom QueryClient. If not provided, a default one will be created. */
110
+ readonly queryClient?: QueryClient | undefined;
111
+ }
112
+ /**
113
+ * TebexProvider - Main provider component for the Tebex SDK.
114
+ *
115
+ * This provider must wrap your application to use any Tebex hooks.
116
+ * It initializes the Tebex client, sets up React Query, and provides
117
+ * the configuration context.
118
+ *
119
+ * @example
120
+ * ```tsx
121
+ * <TebexProvider
122
+ * config={{
123
+ * publicKey: process.env.NEXT_PUBLIC_TEBEX_KEY!,
124
+ * baseUrl: 'https://mysite.com',
125
+ * onError: (error) => toast.error(t(`errors.${error.code}`)),
126
+ * }}
127
+ * >
128
+ * {children}
129
+ * </TebexProvider>
130
+ * ```
131
+ */
132
+ export declare function TebexProvider({ children, config, queryClient: externalQueryClient, }: TebexProviderProps): ReactNode;
133
+ /**
134
+ * Hook to access the Tebex context.
135
+ * Must be used within a TebexProvider.
136
+ *
137
+ * @throws TebexError if used outside of TebexProvider
138
+ */
139
+ export declare function useTebexContext(): TebexContextValue;
140
+ /**
141
+ * Hook to access just the Tebex configuration.
142
+ * Useful when you don't need the QueryClient.
143
+ */
144
+ export declare function useTebexConfig(): ResolvedTebexConfig;
145
+ /**
146
+ * Base return type for all query hooks.
147
+ */
148
+ export interface BaseQueryReturn<T> {
149
+ readonly data: T | null;
150
+ readonly isLoading: boolean;
151
+ readonly isFetching: boolean;
152
+ readonly error: TebexError | null;
153
+ readonly errorCode: TebexErrorCode | null;
154
+ readonly refetch: () => Promise<unknown>;
155
+ }
156
+ /**
157
+ * Base return type for mutation operations.
158
+ */
159
+ export interface BaseMutationReturn {
160
+ readonly isPending: boolean;
161
+ readonly error: TebexError | null;
162
+ readonly errorCode: TebexErrorCode | null;
163
+ }
164
+ export interface UseCategoriesOptions {
165
+ readonly includePackages?: boolean | undefined;
166
+ readonly enabled?: boolean | undefined;
167
+ }
168
+ export interface UseCategoriesReturn extends BaseQueryReturn<Category[]> {
169
+ readonly categories: Category[] | null;
170
+ readonly getByName: (name: string) => Category | undefined;
171
+ readonly getById: (id: number) => Category | undefined;
172
+ }
173
+ export interface UseCategoryOptions {
174
+ readonly id: number;
175
+ readonly enabled?: boolean | undefined;
176
+ }
177
+ export interface UseCategoryReturn extends BaseQueryReturn<Category> {
178
+ readonly category: Category | null;
179
+ }
180
+ export interface UsePackagesOptions {
181
+ readonly categoryId?: number | undefined;
182
+ readonly enabled?: boolean | undefined;
183
+ }
184
+ export interface UsePackagesReturn extends BaseQueryReturn<Package[]> {
185
+ readonly packages: Package[] | null;
186
+ readonly getById: (id: number) => Package | undefined;
187
+ readonly getByName: (name: string) => Package | undefined;
188
+ }
189
+ export interface UsePackageOptions {
190
+ readonly id: number;
191
+ readonly enabled?: boolean | undefined;
192
+ }
193
+ export interface UsePackageReturn extends BaseQueryReturn<Package> {
194
+ readonly package: Package | null;
195
+ }
196
+ export interface AddPackageParams {
197
+ readonly packageId: number;
198
+ readonly quantity?: number | undefined;
199
+ readonly type?: PackageType | undefined;
200
+ readonly variableData?: Record<string, string> | undefined;
201
+ }
202
+ export interface UpdateQuantityParams {
203
+ readonly packageId: number;
204
+ readonly quantity: number;
205
+ }
206
+ export interface UseBasketReturn extends BaseQueryReturn<Basket> {
207
+ readonly basket: Basket | null;
208
+ readonly basketIdent: string | null;
209
+ readonly packages: BasketPackage[];
210
+ readonly isAddingPackage: boolean;
211
+ readonly isRemovingPackage: boolean;
212
+ readonly isUpdatingQuantity: boolean;
213
+ readonly addPackage: (params: AddPackageParams) => Promise<void>;
214
+ readonly removePackage: (packageId: number) => Promise<void>;
215
+ readonly updateQuantity: (params: UpdateQuantityParams) => Promise<void>;
216
+ readonly clearBasket: () => void;
217
+ readonly itemCount: number;
218
+ readonly total: number;
219
+ readonly isEmpty: boolean;
220
+ }
221
+ export interface UseCheckoutOptions {
222
+ readonly onSuccess?: (() => void) | undefined;
223
+ readonly onError?: ((error: TebexError) => void) | undefined;
224
+ readonly onClose?: (() => void) | undefined;
225
+ }
226
+ export interface UseCheckoutReturn {
227
+ readonly launch: () => Promise<void>;
228
+ readonly isLaunching: boolean;
229
+ readonly error: TebexError | null;
230
+ readonly errorCode: TebexErrorCode | null;
231
+ readonly canCheckout: boolean;
232
+ readonly checkoutUrl: string | null;
233
+ }
234
+ export interface UseCouponsReturn {
235
+ readonly coupons: Code[];
236
+ readonly apply: (couponCode: string) => Promise<void>;
237
+ readonly remove: (couponCode: string) => Promise<void>;
238
+ readonly isApplying: boolean;
239
+ readonly isRemoving: boolean;
240
+ readonly error: TebexError | null;
241
+ readonly errorCode: TebexErrorCode | null;
242
+ }
243
+ export interface UseGiftCardsReturn {
244
+ readonly giftCards: GiftCardCode[];
245
+ readonly apply: (cardNumber: string) => Promise<void>;
246
+ readonly remove: (cardNumber: string) => Promise<void>;
247
+ readonly isApplying: boolean;
248
+ readonly isRemoving: boolean;
249
+ readonly error: TebexError | null;
250
+ readonly errorCode: TebexErrorCode | null;
251
+ }
252
+ export interface UseCreatorCodesReturn {
253
+ readonly creatorCode: string | null;
254
+ readonly apply: (code: string) => Promise<void>;
255
+ readonly remove: () => Promise<void>;
256
+ readonly isApplying: boolean;
257
+ readonly isRemoving: boolean;
258
+ readonly error: TebexError | null;
259
+ readonly errorCode: TebexErrorCode | null;
260
+ }
261
+ export interface WebstoreData {
262
+ readonly id: number;
263
+ readonly name: string;
264
+ readonly description: string;
265
+ readonly currency: string;
266
+ readonly domain: string;
267
+ readonly logo: string | null;
268
+ }
269
+ export interface UseWebstoreReturn extends BaseQueryReturn<WebstoreData> {
270
+ readonly webstore: WebstoreData | null;
271
+ readonly name: string | null;
272
+ readonly currency: string | null;
273
+ readonly domain: string | null;
274
+ }
275
+ export interface UseUserReturn {
276
+ readonly username: string | null;
277
+ readonly setUsername: (username: string) => void;
278
+ readonly clearUsername: () => void;
279
+ readonly isAuthenticated: boolean;
280
+ }
281
+ export interface GiftPackageParams {
282
+ readonly packageId: number;
283
+ readonly targetUsername: string;
284
+ readonly quantity?: number | undefined;
285
+ }
286
+ export interface UseGiftPackageReturn {
287
+ readonly gift: (params: GiftPackageParams) => Promise<void>;
288
+ readonly isGifting: boolean;
289
+ readonly error: TebexError | null;
290
+ readonly errorCode: TebexErrorCode | null;
291
+ }
292
+ /**
293
+ * Hook to manage the shopping basket with optimistic updates.
294
+ *
295
+ * @returns Basket data, actions, and computed values
296
+ *
297
+ * @example
298
+ * ```tsx
299
+ * const {
300
+ * basket,
301
+ * packages,
302
+ * addPackage,
303
+ * removePackage,
304
+ * itemCount,
305
+ * total,
306
+ * isAddingPackage,
307
+ * } = useBasket();
308
+ *
309
+ * const handleAddToCart = async (packageId: number) => {
310
+ * await addPackage({ packageId, quantity: 1 });
311
+ * };
312
+ * ```
313
+ */
314
+ export declare function useBasket(): UseBasketReturn;
315
+ /**
316
+ * Hook to fetch all categories from the Tebex store.
317
+ *
318
+ * @param options - Configuration options
319
+ * @returns Categories data and helper methods
320
+ *
321
+ * @example
322
+ * ```tsx
323
+ * const { categories, isLoading, getByName } = useCategories();
324
+ *
325
+ * if (isLoading) return <Spinner />;
326
+ *
327
+ * const vipCategory = getByName('VIP');
328
+ * ```
329
+ */
330
+ export declare function useCategories(options?: UseCategoriesOptions): UseCategoriesReturn;
331
+ /**
332
+ * Hook to fetch a single category by ID.
333
+ *
334
+ * @param options - Configuration options including the category ID
335
+ * @returns Category data
336
+ *
337
+ * @example
338
+ * ```tsx
339
+ * const { category, isLoading } = useCategory({ id: 123 });
340
+ *
341
+ * if (isLoading) return <Spinner />;
342
+ * if (!category) return <NotFound />;
343
+ *
344
+ * return <CategoryDisplay category={category} />;
345
+ * ```
346
+ */
347
+ export declare function useCategory(options: UseCategoryOptions): UseCategoryReturn;
348
+ /**
349
+ * Hook to launch the Tebex checkout modal.
350
+ *
351
+ * @param options - Checkout callbacks
352
+ * @returns Checkout state and launch function
353
+ *
354
+ * @example
355
+ * ```tsx
356
+ * const { launch, canCheckout, isLaunching } = useCheckout({
357
+ * onSuccess: () => router.push('/thank-you'),
358
+ * onError: (error) => toast.error(error.message),
359
+ * });
360
+ *
361
+ * return (
362
+ * <button onClick={launch} disabled={!canCheckout || isLaunching}>
363
+ * Checkout
364
+ * </button>
365
+ * );
366
+ * ```
367
+ */
368
+ export declare function useCheckout(options?: UseCheckoutOptions): UseCheckoutReturn;
369
+ /**
370
+ * Hook to manage coupons on the basket.
371
+ *
372
+ * @returns Coupon state and actions
373
+ *
374
+ * @example
375
+ * ```tsx
376
+ * const { coupons, apply, remove, isApplying } = useCoupons();
377
+ *
378
+ * const handleApply = async (code: string) => {
379
+ * try {
380
+ * await apply(code);
381
+ * toast.success('Coupon applied!');
382
+ * } catch (error) {
383
+ * toast.error('Invalid coupon');
384
+ * }
385
+ * };
386
+ * ```
387
+ */
388
+ export declare function useCoupons(): UseCouponsReturn;
389
+ /**
390
+ * Hook to manage creator codes on the basket.
391
+ *
392
+ * @returns Creator code state and actions
393
+ *
394
+ * @example
395
+ * ```tsx
396
+ * const { creatorCode, apply, remove, isApplying } = useCreatorCodes();
397
+ *
398
+ * const handleApply = async (code: string) => {
399
+ * try {
400
+ * await apply(code);
401
+ * toast.success('Creator code applied!');
402
+ * } catch (error) {
403
+ * toast.error('Invalid creator code');
404
+ * }
405
+ * };
406
+ * ```
407
+ */
408
+ export declare function useCreatorCodes(): UseCreatorCodesReturn;
409
+ /**
410
+ * Hook to manage gift cards on the basket.
411
+ *
412
+ * @returns Gift card state and actions
413
+ *
414
+ * @example
415
+ * ```tsx
416
+ * const { giftCards, apply, remove, isApplying } = useGiftCards();
417
+ *
418
+ * const handleApply = async (cardNumber: string) => {
419
+ * try {
420
+ * await apply(cardNumber);
421
+ * toast.success('Gift card applied!');
422
+ * } catch (error) {
423
+ * toast.error('Invalid gift card');
424
+ * }
425
+ * };
426
+ * ```
427
+ */
428
+ export declare function useGiftCards(): UseGiftCardsReturn;
429
+ /**
430
+ * Hook to gift a package to another player.
431
+ *
432
+ * @returns Gift package state and action
433
+ *
434
+ * @example
435
+ * ```tsx
436
+ * const { gift, isGifting, error } = useGiftPackage();
437
+ *
438
+ * const handleGift = async () => {
439
+ * await gift({
440
+ * packageId: 123,
441
+ * targetUsername: 'FriendName',
442
+ * quantity: 1,
443
+ * });
444
+ * };
445
+ * ```
446
+ */
447
+ export declare function useGiftPackage(): UseGiftPackageReturn;
448
+ /**
449
+ * Hook to fetch a single package by ID.
450
+ *
451
+ * @param options - Configuration options including the package ID
452
+ * @returns Package data
453
+ *
454
+ * @example
455
+ * ```tsx
456
+ * const { package: pkg, isLoading } = usePackage({ id: 123 });
457
+ *
458
+ * if (isLoading) return <Spinner />;
459
+ * if (!pkg) return <NotFound />;
460
+ *
461
+ * return <PackageDisplay package={pkg} />;
462
+ * ```
463
+ */
464
+ export declare function usePackage(options: UsePackageOptions): UsePackageReturn;
465
+ /**
466
+ * Hook to fetch all packages from the Tebex store.
467
+ * Optionally filter by category.
468
+ *
469
+ * @param options - Configuration options
470
+ * @returns Packages data and helper methods
471
+ *
472
+ * @example
473
+ * ```tsx
474
+ * const { packages, isLoading, getById } = usePackages();
475
+ *
476
+ * // Or filter by category
477
+ * const { packages } = usePackages({ categoryId: 123 });
478
+ * ```
479
+ */
480
+ export declare function usePackages(options?: UsePackagesOptions): UsePackagesReturn;
481
+ /**
482
+ * Hook to manage the current user (Minecraft username).
483
+ * Username is persisted in localStorage.
484
+ *
485
+ * @returns User state and actions
486
+ *
487
+ * @example
488
+ * ```tsx
489
+ * const { username, setUsername, isAuthenticated } = useUser();
490
+ *
491
+ * if (!isAuthenticated) {
492
+ * return <UsernameForm onSubmit={setUsername} />;
493
+ * }
494
+ *
495
+ * return <p>Welcome, {username}!</p>;
496
+ * ```
497
+ */
498
+ export declare function useUser(): UseUserReturn;
499
+ /**
500
+ * Hook to fetch webstore information.
501
+ *
502
+ * @returns Webstore data including name, currency, and domain
503
+ *
504
+ * @example
505
+ * ```tsx
506
+ * const { webstore, currency, isLoading } = useWebstore();
507
+ *
508
+ * if (isLoading) return <Spinner />;
509
+ *
510
+ * return (
511
+ * <div>
512
+ * <h1>{webstore?.name}</h1>
513
+ * <p>Currency: {currency}</p>
514
+ * </div>
515
+ * );
516
+ * ```
517
+ */
518
+ export declare function useWebstore(): UseWebstoreReturn;
519
+ /**
520
+ * Basket store state interface.
521
+ */
522
+ export interface BasketStoreState {
523
+ readonly basketIdent: string | null;
524
+ }
525
+ /**
526
+ * Basket store actions interface.
527
+ */
528
+ export interface BasketStoreActions {
529
+ readonly setBasketIdent: (ident: string) => void;
530
+ readonly clearBasketIdent: () => void;
531
+ }
532
+ /**
533
+ * Complete basket store type.
534
+ */
535
+ export type BasketStore = BasketStoreState & BasketStoreActions;
536
+ /**
537
+ * Zustand store for basket ident persistence.
538
+ * Uses localStorage to persist the basket ident across sessions.
539
+ */
540
+ export declare const useBasketStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<BasketStore>, "subscribe"> & {
64
541
  subscribe: {
65
- (listener: (selectedState: ShopBasketStore, previousSelectedState: ShopBasketStore) => void): () => void;
66
- <U>(selector: (state: ShopBasketStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
67
- equalityFn?: ((a: U, b: U) => boolean) | undefined;
68
- fireImmediately?: boolean | undefined;
542
+ (listener: (selectedState: BasketStore, previousSelectedState: BasketStore) => void): () => void;
543
+ <U>(selector: (state: BasketStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
544
+ equalityFn?: (a: U, b: U) => boolean;
545
+ fireImmediately?: boolean;
69
546
  } | undefined): () => void;
70
547
  };
71
548
  }, "persist"> & {
72
549
  persist: {
73
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ShopBasketStore, ShopBasketStore>>) => void;
550
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<BasketStore, BasketStore>>) => void;
74
551
  clearStorage: () => void;
75
552
  rehydrate: () => void | Promise<void>;
76
553
  hasHydrated: () => boolean;
77
- onHydrate: (fn: (state: ShopBasketStore) => void) => () => void;
78
- onFinishHydration: (fn: (state: ShopBasketStore) => void) => () => void;
79
- getOptions: () => Partial<import("zustand/middleware").PersistOptions<ShopBasketStore, ShopBasketStore>>;
554
+ onHydrate: (fn: (state: BasketStore) => void) => () => void;
555
+ onFinishHydration: (fn: (state: BasketStore) => void) => () => void;
556
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<BasketStore, BasketStore>>;
80
557
  };
81
558
  }>;
82
- export interface ShopUiStore {
83
- isGlobalLoading: boolean;
84
- setIsGlobalLoading: (isGlobalLoading: boolean) => void;
85
- isCreatingBasket: boolean;
86
- setIsCreatingBasket: (isCreatingBasket: boolean) => void;
559
+ /**
560
+ * User store state interface.
561
+ */
562
+ export interface UserStoreState {
563
+ readonly username: string | null;
87
564
  }
88
- export declare const useShopUiStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<ShopUiStore>, "subscribe"> & {
89
- subscribe: {
90
- (listener: (selectedState: ShopUiStore, previousSelectedState: ShopUiStore) => void): () => void;
91
- <U>(selector: (state: ShopUiStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
92
- equalityFn?: ((a: U, b: U) => boolean) | undefined;
93
- fireImmediately?: boolean | undefined;
94
- } | undefined): () => void;
95
- };
96
- }>;
97
- export interface ShopUserStore {
98
- username: string;
99
- setUsername: (username: string) => void;
100
- clearUsername: () => void;
565
+ /**
566
+ * User store actions interface.
567
+ */
568
+ export interface UserStoreActions {
569
+ readonly setUsername: (username: string) => void;
570
+ readonly clearUsername: () => void;
101
571
  }
102
- declare const shopUserStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<ShopUserStore>, "subscribe"> & {
572
+ /**
573
+ * Complete user store type.
574
+ */
575
+ export type UserStore = UserStoreState & UserStoreActions;
576
+ /**
577
+ * Zustand store for user data persistence.
578
+ * Uses localStorage to persist the username (Minecraft username) across sessions.
579
+ */
580
+ export declare const useUserStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<UserStore>, "subscribe"> & {
103
581
  subscribe: {
104
- (listener: (selectedState: ShopUserStore, previousSelectedState: ShopUserStore) => void): () => void;
105
- <U>(selector: (state: ShopUserStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
106
- equalityFn?: ((a: U, b: U) => boolean) | undefined;
107
- fireImmediately?: boolean | undefined;
582
+ (listener: (selectedState: UserStore, previousSelectedState: UserStore) => void): () => void;
583
+ <U>(selector: (state: UserStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
584
+ equalityFn?: (a: U, b: U) => boolean;
585
+ fireImmediately?: boolean;
108
586
  } | undefined): () => void;
109
587
  };
110
588
  }, "persist"> & {
111
589
  persist: {
112
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ShopUserStore, ShopUserStore>>) => void;
590
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<UserStore, UserStore>>) => void;
113
591
  clearStorage: () => void;
114
592
  rehydrate: () => void | Promise<void>;
115
593
  hasHydrated: () => boolean;
116
- onHydrate: (fn: (state: ShopUserStore) => void) => () => void;
117
- onFinishHydration: (fn: (state: ShopUserStore) => void) => () => void;
118
- getOptions: () => Partial<import("zustand/middleware").PersistOptions<ShopUserStore, ShopUserStore>>;
594
+ onHydrate: (fn: (state: UserStore) => void) => () => void;
595
+ onFinishHydration: (fn: (state: UserStore) => void) => () => void;
596
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<UserStore, UserStore>>;
119
597
  };
120
598
  }>;
599
+ /**
600
+ * Query keys factory for TanStack Query.
601
+ * Follows the recommended pattern for granular cache invalidation.
602
+ *
603
+ * @see https://tkdodo.eu/blog/effective-react-query-keys
604
+ */
605
+ export declare const tebexKeys: {
606
+ /** Root key for all Tebex queries */
607
+ readonly all: readonly [
608
+ "tebex"
609
+ ];
610
+ /** All category-related queries */
611
+ readonly categories: () => readonly [
612
+ "tebex",
613
+ "categories"
614
+ ];
615
+ /** Categories list with include packages option */
616
+ readonly categoriesList: (includePackages: boolean) => readonly [
617
+ "tebex",
618
+ "categories",
619
+ "list",
620
+ {
621
+ readonly includePackages: boolean;
622
+ }
623
+ ];
624
+ /** Single category by ID */
625
+ readonly category: (id: number) => readonly [
626
+ "tebex",
627
+ "categories",
628
+ "detail",
629
+ number
630
+ ];
631
+ /** All package-related queries */
632
+ readonly packages: () => readonly [
633
+ "tebex",
634
+ "packages"
635
+ ];
636
+ /** Packages list, optionally filtered by category */
637
+ readonly packagesList: (categoryId?: number) => readonly [
638
+ "tebex",
639
+ "packages",
640
+ "list",
641
+ {
642
+ readonly categoryId: number | undefined;
643
+ }
644
+ ];
645
+ /** Single package by ID */
646
+ readonly package: (id: number) => readonly [
647
+ "tebex",
648
+ "packages",
649
+ "detail",
650
+ number
651
+ ];
652
+ /** All basket-related queries */
653
+ readonly baskets: () => readonly [
654
+ "tebex",
655
+ "baskets"
656
+ ];
657
+ /** Specific basket by ident */
658
+ readonly basket: (ident: string | null) => readonly [
659
+ "tebex",
660
+ "baskets",
661
+ string | null
662
+ ];
663
+ /** Webstore info query */
664
+ readonly webstore: () => readonly [
665
+ "tebex",
666
+ "webstore"
667
+ ];
668
+ };
669
+ /**
670
+ * Discriminated union for type-safe result handling.
671
+ * Use this for operations that can fail.
672
+ */
673
+ export type Result<T, E = TebexError> = {
674
+ readonly success: true;
675
+ readonly data: T;
676
+ } | {
677
+ readonly success: false;
678
+ readonly error: E;
679
+ };
680
+ /**
681
+ * Creates a successful result.
682
+ */
683
+ export declare function ok<T>(data: T): Result<T, never>;
684
+ /**
685
+ * Creates an error result.
686
+ */
687
+ export declare function err<E>(error: E): Result<never, E>;
688
+ /**
689
+ * Type guard to check if an error is a TebexError.
690
+ */
691
+ export declare function isTebexError(error: unknown): error is TebexError;
692
+ /**
693
+ * Type guard to check if a Result is successful.
694
+ */
695
+ export declare function isSuccess<T, E>(result: Result<T, E>): result is {
696
+ readonly success: true;
697
+ readonly data: T;
698
+ };
699
+ /**
700
+ * Type guard to check if a Result is an error.
701
+ */
702
+ export declare function isError<T, E>(result: Result<T, E>): result is {
703
+ readonly success: false;
704
+ readonly error: E;
705
+ };
706
+ /**
707
+ * Type guard to check if a value is defined (not null or undefined).
708
+ */
709
+ export declare function isDefined<T>(value: T | null | undefined): value is T;
710
+ /**
711
+ * Returns the initialized Tebex client.
712
+ * Throws if the client has not been initialized.
713
+ */
714
+ export declare function getTebexClient(): TebexHeadless;
715
+ /**
716
+ * Checks if the Tebex client is initialized.
717
+ */
718
+ export declare function isTebexClientInitialized(): boolean;
121
719
 
122
720
  export {
123
- shopUserStore as useShopUserStore,
721
+ Basket,
722
+ BasketPackage,
723
+ Category,
724
+ Code,
725
+ GiftCardCode,
726
+ Package,
727
+ PackageType,
728
+ Webstore,
124
729
  };
125
730
 
126
731
  export {};