@neosianexus/super-tebex 3.0.3 → 3.1.1

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 @@
1
+ var{defineProperty:E,getOwnPropertyNames:l,getOwnPropertyDescriptor:d}=Object,u=Object.prototype.hasOwnProperty;var q=new WeakMap,g=(A)=>{var F=q.get(A),L;if(F)return F;if(F=E({},"__esModule",{value:!0}),A&&typeof A==="object"||typeof A==="function")l(A).map((J)=>!u.call(F,J)&&E(F,J,{get:()=>A[J],enumerable:!(L=d(A,J))||L.enumerable}));return q.set(A,F),F};var k=(A,F)=>{for(var L in F)E(A,L,{get:F[L],enumerable:!0,configurable:!0,set:(J)=>F[L]=()=>J})};var s={};k(s,{useIsMockProvider:()=>C,mockData:()=>x,defaultMockWebstore:()=>Q,defaultMockPackages:()=>Y,defaultMockCategories:()=>R,defaultMockBasket:()=>N,createMockGiftCard:()=>w,createMockCoupon:()=>j,createMockBasket:()=>H,createBasketPackage:()=>S,TebexMockProvider:()=>p});module.exports=g(s);var v=require("@tanstack/react-query"),Z=require("react");var K=require("react");var h=K.createContext(null);var O={all:["tebex"],categories:()=>[...O.all,"categories"],categoriesList:(A)=>[...O.categories(),"list",{includePackages:A}],category:(A)=>[...O.categories(),"detail",A],packages:()=>[...O.all,"packages"],packagesList:(A)=>[...O.packages(),"list",{categoryId:A}],package:(A)=>[...O.packages(),"detail",A],baskets:()=>[...O.all,"baskets"],basket:(A)=>[...O.baskets(),A],webstore:()=>[...O.all,"webstore"]};var B=require("zustand"),V=require("zustand/middleware"),I=B.create()(V.subscribeWithSelector(V.persist((A)=>({basketIdent:null,setBasketIdent:(F)=>{A({basketIdent:F})},clearBasketIdent:()=>{A({basketIdent:null})}}),{name:"tebex-basket-store",skipHydration:typeof window>"u"})));var M=require("zustand"),W=require("zustand/middleware"),U=M.create()(W.subscribeWithSelector(W.persist((A)=>({username:null,setUsername:(F)=>{A({username:F})},clearUsername:()=>{A({username:null})}}),{name:"tebex-user-store",skipHydration:typeof window>"u"})));var Q={id:1,name:"Test Store",description:"A test Tebex store for development",currency:"EUR",domain:"test.tebex.io",logo:null},Y=[{id:101,name:"VIP Gold",description:"Gold VIP membership with exclusive perks",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:9.99,sales_tax:0,total_price:9.99,currency:"EUR",image:null,category:{id:1,name:"VIP Ranks"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:1},{id:102,name:"VIP Diamond",description:"Diamond VIP membership with all perks",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:19.99,sales_tax:0,total_price:19.99,currency:"EUR",image:null,category:{id:1,name:"VIP Ranks"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:2},{id:201,name:"Pet Pack",description:"Adorable pet companions",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:4.99,sales_tax:0,total_price:4.99,currency:"EUR",image:null,category:{id:2,name:"Cosmetics"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:1},{id:202,name:"Trail Effects",description:"Particle trail effects",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:2.99,sales_tax:0,total_price:2.99,currency:"EUR",image:null,category:{id:2,name:"Cosmetics"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:2},{id:301,name:"1000 Coins",description:"In-game currency pack",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:1.99,sales_tax:0,total_price:1.99,currency:"EUR",image:null,category:{id:3,name:"Currency"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:1}],R=[{id:1,name:"VIP Ranks",description:"Exclusive VIP memberships",parent:null,order:1,display_type:"grid",slug:"vip-ranks",packages:Y.filter((A)=>A.category.id===1)},{id:2,name:"Cosmetics",description:"Cosmetic items and effects",parent:null,order:2,display_type:"grid",slug:"cosmetics",packages:Y.filter((A)=>A.category.id===2)},{id:3,name:"Currency",description:"In-game currency packs",parent:null,order:3,display_type:"grid",slug:"currency",packages:Y.filter((A)=>A.category.id===3)}],N={ident:"mock-basket-001",complete:!1,id:1,country:"US",ip:"127.0.0.1",username_id:null,username:null,cancel_url:"https://example.com/cancel",complete_url:"https://example.com/complete",complete_auto_redirect:!1,base_price:0,sales_tax:0,total_price:0,email:"",currency:"EUR",packages:[],coupons:[],giftcards:[],creator_code:"",links:{checkout:"https://checkout.tebex.io/mock"},custom:{}};function S(A,F=1,L=null){return{id:A.id,name:A.name,description:A.description,image:A.image,in_basket:{quantity:F,price:A.base_price*F,gift_username_id:null,gift_username:L}}}function H(A,F){let L=A.map((X)=>S(X.package,X.quantity??1,X.giftUsername??null)),J=L.reduce((X,$)=>X+$.in_basket.price,0);return{...N,packages:L,total_price:J,base_price:J,...F}}function j(A){return{code:A}}function w(A){return{card_number:A}}var x={webstore:Q,categories:R,packages:Y,emptyBasket:N,basketWithOneItem:H([{package:Y[0],quantity:1}]),basketWithMultipleItems:H([{package:Y[0],quantity:1},{package:Y[2],quantity:2}]),basketWithCoupon:{...H([{package:Y[0],quantity:1}]),coupons:[j("SAVE10")]},basketWithGiftCard:{...H([{package:Y[0],quantity:1}]),giftcards:[w("GIFT-1234-5678")]},basketWithCreatorCode:{...H([{package:Y[0],quantity:1}]),creator_code:"STREAMER123"},helpers:{createBasketPackage:S,createMockBasket:H,createMockCoupon:j,createMockGiftCard:w},getPackageById:(A)=>{return Y.find((F)=>F.id===A)},getCategoryById:(A)=>{return R.find((F)=>F.id===A)}};var T=require("react/jsx-dev-runtime");function i(){return new v.QueryClient({defaultOptions:{queries:{staleTime:1/0,gcTime:1/0,retry:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1},mutations:{retry:!1}}})}function n(A,F){let L=A.replace(/\/$/,"");return{publicKey:"mock-public-key",baseUrl:L,completeUrl:`${L}/shop/complete`,cancelUrl:`${L}/shop/cancel`,onError:F,devtools:!1}}function c(A,F){A.setQueryData(O.webstore(),{id:F.webstore.id,name:F.webstore.name,description:F.webstore.description,currency:F.webstore.currency,domain:F.webstore.domain,logo:F.webstore.logo}),A.setQueryData(O.categoriesList(!0),F.categories),A.setQueryData(O.categoriesList(!1),F.categories.map((J)=>({...J,packages:[]})));for(let J of F.categories)A.setQueryData(O.category(J.id),J);A.setQueryData(O.packagesList(),F.packages);let L=new Map;for(let J of F.packages){let X=J.category.id,$=L.get(X)??[];L.set(X,[...$,J])}for(let[J,X]of L)A.setQueryData(O.packagesList(J),X);for(let J of F.packages)A.setQueryData(O.package(J.id),J);if(F.basket!==null&&F.basketIdent!==null)A.setQueryData(O.basket(F.basketIdent),F.basket)}function r({username:A,basketIdent:F}){let L=U((_)=>_.setUsername),J=U((_)=>_.clearUsername),X=I((_)=>_.setBasketIdent),$=I((_)=>_.clearBasketIdent);return Z.useEffect(()=>{if(A!==null)L(A);else J()},[A,L,J]),Z.useEffect(()=>{if(F!==null)X(F);else $()},[F,X,$]),null}function p({children:A,mockData:F,username:L="TestPlayer",withBasket:J=!0,baseUrl:X="https://mock.tebex.io",onError:$}){let _=Z.useMemo(()=>{let m={...Q,...F?.webstore},y=F?.categories??R,f=F?.packages??Y,G=null,D=null;if(J){if(G=F?.basket?{...N,...F.basket}:N,D=G.ident,L!==null)G={...G,username:L}}return{webstore:m,categories:y,packages:f,basket:G,basketIdent:D}},[F,J,L]),[z]=Z.useState(()=>i()),P=Z.useMemo(()=>n(X,$),[X,$]);Z.useEffect(()=>{c(z,_)},[z,_]);let b=Z.useMemo(()=>({config:P,queryClient:z}),[P,z]);return T.jsxDEV(h.Provider,{value:b,children:T.jsxDEV(v.QueryClientProvider,{client:z,children:[T.jsxDEV(r,{username:L,basketIdent:_.basketIdent},void 0,!1,void 0,this),A]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function C(){let A=Z.useContext(h);return A!==null&&A.config.publicKey==="mock-public-key"}
@@ -0,0 +1,329 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import { ReactNode } from 'react';
4
+ import { Basket, BasketPackage, Category, Code, GiftCardCode, Package } from 'tebex_headless';
5
+
6
+ declare enum TebexErrorCode {
7
+ PROVIDER_NOT_FOUND = "PROVIDER_NOT_FOUND",
8
+ INVALID_CONFIG = "INVALID_CONFIG",
9
+ NOT_AUTHENTICATED = "NOT_AUTHENTICATED",
10
+ INVALID_USERNAME = "INVALID_USERNAME",
11
+ BASKET_NOT_FOUND = "BASKET_NOT_FOUND",
12
+ BASKET_CREATION_FAILED = "BASKET_CREATION_FAILED",
13
+ BASKET_EXPIRED = "BASKET_EXPIRED",
14
+ BASKET_EMPTY = "BASKET_EMPTY",
15
+ PACKAGE_NOT_FOUND = "PACKAGE_NOT_FOUND",
16
+ PACKAGE_OUT_OF_STOCK = "PACKAGE_OUT_OF_STOCK",
17
+ PACKAGE_ALREADY_OWNED = "PACKAGE_ALREADY_OWNED",
18
+ INVALID_QUANTITY = "INVALID_QUANTITY",
19
+ CATEGORY_NOT_FOUND = "CATEGORY_NOT_FOUND",
20
+ COUPON_INVALID = "COUPON_INVALID",
21
+ COUPON_EXPIRED = "COUPON_EXPIRED",
22
+ COUPON_ALREADY_USED = "COUPON_ALREADY_USED",
23
+ GIFTCARD_INVALID = "GIFTCARD_INVALID",
24
+ GIFTCARD_INSUFFICIENT_BALANCE = "GIFTCARD_INSUFFICIENT_BALANCE",
25
+ CREATOR_CODE_INVALID = "CREATOR_CODE_INVALID",
26
+ CHECKOUT_FAILED = "CHECKOUT_FAILED",
27
+ CHECKOUT_CANCELLED = "CHECKOUT_CANCELLED",
28
+ TEBEX_JS_NOT_LOADED = "TEBEX_JS_NOT_LOADED",
29
+ NETWORK_ERROR = "NETWORK_ERROR",
30
+ TIMEOUT = "TIMEOUT",
31
+ RATE_LIMITED = "RATE_LIMITED",
32
+ UNKNOWN = "UNKNOWN"
33
+ }
34
+ declare class TebexError extends Error {
35
+ readonly code: TebexErrorCode;
36
+ readonly cause?: unknown;
37
+ constructor(code: TebexErrorCode, message?: string, cause?: unknown);
38
+ /**
39
+ * Converts an unknown error to a TebexError.
40
+ * If the error is already a TebexError, it returns it as-is.
41
+ */
42
+ static fromUnknown(error: unknown): TebexError;
43
+ /**
44
+ * Returns a JSON representation of the error.
45
+ */
46
+ toJSON(): {
47
+ name: string;
48
+ code: TebexErrorCode;
49
+ message: string;
50
+ };
51
+ }
52
+ export interface WebstoreData {
53
+ readonly id: number;
54
+ readonly name: string;
55
+ readonly description: string;
56
+ readonly currency: string;
57
+ readonly domain: string;
58
+ readonly logo: string | null;
59
+ }
60
+ /**
61
+ * Mock webstore data for testing.
62
+ */
63
+ export interface MockWebstoreData extends WebstoreData {
64
+ readonly id: number;
65
+ readonly name: string;
66
+ readonly description: string;
67
+ readonly currency: string;
68
+ readonly domain: string;
69
+ readonly logo: string | null;
70
+ }
71
+ /**
72
+ * Mock package data for testing.
73
+ * Extends the base Package type with required fields.
74
+ */
75
+ export type MockPackage = Package;
76
+ /**
77
+ * Mock category data for testing.
78
+ */
79
+ export type MockCategory = Category;
80
+ /**
81
+ * Mock basket data for testing.
82
+ */
83
+ export type MockBasket = Basket;
84
+ /**
85
+ * Configuration for mock data.
86
+ */
87
+ export interface MockDataConfig {
88
+ readonly webstore?: Partial<MockWebstoreData> | undefined;
89
+ readonly categories?: MockCategory[] | undefined;
90
+ readonly packages?: MockPackage[] | undefined;
91
+ readonly basket?: Partial<MockBasket> | undefined;
92
+ readonly username?: string | null | undefined;
93
+ }
94
+ /**
95
+ * Default mock webstore data.
96
+ */
97
+ export declare const defaultMockWebstore: MockWebstoreData;
98
+ /**
99
+ * Default mock packages organized by category.
100
+ */
101
+ export declare const defaultMockPackages: MockPackage[];
102
+ /**
103
+ * Default mock categories with packages.
104
+ */
105
+ export declare const defaultMockCategories: MockCategory[];
106
+ /**
107
+ * Default empty basket.
108
+ */
109
+ export declare const defaultMockBasket: MockBasket;
110
+ /**
111
+ * Create a basket package from a mock package.
112
+ */
113
+ export declare function createBasketPackage(pkg: MockPackage, quantity?: number, giftUsername?: string | null): BasketPackage;
114
+ /**
115
+ * Create a mock basket with items.
116
+ */
117
+ export declare function createMockBasket(items: {
118
+ package: MockPackage;
119
+ quantity?: number;
120
+ giftUsername?: string | null;
121
+ }[], overrides?: Partial<MockBasket>): MockBasket;
122
+ /**
123
+ * Create a mock coupon.
124
+ */
125
+ export declare function createMockCoupon(code: string): Code;
126
+ /**
127
+ * Create a mock gift card.
128
+ */
129
+ export declare function createMockGiftCard(cardNumber: string): GiftCardCode;
130
+ /**
131
+ * Pre-built mock data for common testing scenarios.
132
+ */
133
+ export declare const mockData: {
134
+ /** Default webstore */
135
+ readonly webstore: MockWebstoreData;
136
+ /** All categories with packages */
137
+ readonly categories: Category[];
138
+ /** All packages flat list */
139
+ readonly packages: Package[];
140
+ /** Empty basket */
141
+ readonly emptyBasket: Basket;
142
+ /** Basket with one VIP Gold item */
143
+ readonly basketWithOneItem: Basket;
144
+ /** Basket with multiple items */
145
+ readonly basketWithMultipleItems: Basket;
146
+ /** Basket with coupon applied */
147
+ readonly basketWithCoupon: {
148
+ readonly coupons: readonly [
149
+ Code
150
+ ];
151
+ readonly ident: string;
152
+ readonly complete: boolean;
153
+ readonly id: number;
154
+ readonly country: string;
155
+ readonly ip: string;
156
+ readonly username_id: string | null;
157
+ readonly username: string | null;
158
+ readonly cancel_url: string;
159
+ readonly complete_url: string;
160
+ readonly complete_auto_redirect: boolean;
161
+ readonly base_price: number;
162
+ readonly sales_tax: number;
163
+ readonly total_price: number;
164
+ readonly email: string;
165
+ readonly currency: string;
166
+ readonly packages: BasketPackage[];
167
+ readonly giftcards: GiftCardCode[];
168
+ readonly creator_code: string;
169
+ readonly links: import("tebex_headless").Links;
170
+ readonly custom: Record<string, any>;
171
+ };
172
+ /** Basket with gift card applied */
173
+ readonly basketWithGiftCard: {
174
+ readonly giftcards: readonly [
175
+ GiftCardCode
176
+ ];
177
+ readonly ident: string;
178
+ readonly complete: boolean;
179
+ readonly id: number;
180
+ readonly country: string;
181
+ readonly ip: string;
182
+ readonly username_id: string | null;
183
+ readonly username: string | null;
184
+ readonly cancel_url: string;
185
+ readonly complete_url: string;
186
+ readonly complete_auto_redirect: boolean;
187
+ readonly base_price: number;
188
+ readonly sales_tax: number;
189
+ readonly total_price: number;
190
+ readonly email: string;
191
+ readonly currency: string;
192
+ readonly packages: BasketPackage[];
193
+ readonly coupons: Code[];
194
+ readonly creator_code: string;
195
+ readonly links: import("tebex_headless").Links;
196
+ readonly custom: Record<string, any>;
197
+ };
198
+ /** Basket with creator code */
199
+ readonly basketWithCreatorCode: {
200
+ readonly creator_code: "STREAMER123";
201
+ readonly ident: string;
202
+ readonly complete: boolean;
203
+ readonly id: number;
204
+ readonly country: string;
205
+ readonly ip: string;
206
+ readonly username_id: string | null;
207
+ readonly username: string | null;
208
+ readonly cancel_url: string;
209
+ readonly complete_url: string;
210
+ readonly complete_auto_redirect: boolean;
211
+ readonly base_price: number;
212
+ readonly sales_tax: number;
213
+ readonly total_price: number;
214
+ readonly email: string;
215
+ readonly currency: string;
216
+ readonly packages: BasketPackage[];
217
+ readonly coupons: Code[];
218
+ readonly giftcards: GiftCardCode[];
219
+ readonly links: import("tebex_headless").Links;
220
+ readonly custom: Record<string, any>;
221
+ };
222
+ /** Helper functions */
223
+ readonly helpers: {
224
+ readonly createBasketPackage: typeof createBasketPackage;
225
+ readonly createMockBasket: typeof createMockBasket;
226
+ readonly createMockCoupon: typeof createMockCoupon;
227
+ readonly createMockGiftCard: typeof createMockGiftCard;
228
+ };
229
+ /** Get package by ID */
230
+ readonly getPackageById: (id: number) => MockPackage | undefined;
231
+ /** Get category by ID */
232
+ readonly getCategoryById: (id: number) => MockCategory | undefined;
233
+ };
234
+ /**
235
+ * Props for TebexMockProvider component.
236
+ */
237
+ export interface TebexMockProviderProps {
238
+ readonly children: ReactNode;
239
+ /**
240
+ * Mock data to use. If not provided, defaults will be used.
241
+ */
242
+ readonly mockData?: MockDataConfig | undefined;
243
+ /**
244
+ * Mock username to set in the user store.
245
+ * @default 'TestPlayer'
246
+ */
247
+ readonly username?: string | null | undefined;
248
+ /**
249
+ * Whether to initialize a basket.
250
+ * If true and mockData.basket is provided, that basket will be used.
251
+ * If true and no basket is provided, an empty basket will be created.
252
+ * @default true
253
+ */
254
+ readonly withBasket?: boolean | undefined;
255
+ /**
256
+ * Base URL for the mock store.
257
+ * @default 'https://mock.tebex.io'
258
+ */
259
+ readonly baseUrl?: string | undefined;
260
+ /**
261
+ * Callback when an error occurs.
262
+ */
263
+ readonly onError?: ((error: TebexError) => void) | undefined;
264
+ }
265
+ /**
266
+ * TebexMockProvider - A mock provider for testing and Storybook.
267
+ *
268
+ * This provider pre-populates TanStack Query with mock data, allowing
269
+ * you to render components that use Tebex hooks without making real API calls.
270
+ *
271
+ * **Features:**
272
+ * - Pre-populated categories, packages, and webstore data
273
+ * - Optional basket state
274
+ * - No network requests (queries have infinite staleTime)
275
+ * - Same context interface as TebexProvider
276
+ *
277
+ * **Limitations:**
278
+ * - Mutations (addPackage, removePackage, etc.) won't persist changes
279
+ * - For full mutation support, use MSW with the provided handlers
280
+ *
281
+ * @example Basic usage
282
+ * ```tsx
283
+ * import { TebexMockProvider, mockData } from '@neosianexus/super-tebex/testing';
284
+ *
285
+ * <TebexMockProvider>
286
+ * <ShopPage />
287
+ * </TebexMockProvider>
288
+ * ```
289
+ *
290
+ * @example Custom mock data
291
+ * ```tsx
292
+ * <TebexMockProvider
293
+ * mockData={{
294
+ * webstore: { name: 'My Custom Store', currency: 'USD' },
295
+ * basket: mockData.basketWithMultipleItems,
296
+ * }}
297
+ * username="CustomPlayer"
298
+ * >
299
+ * <CheckoutPage />
300
+ * </TebexMockProvider>
301
+ * ```
302
+ *
303
+ * @example Without basket (for category/package browsing)
304
+ * ```tsx
305
+ * <TebexMockProvider withBasket={false}>
306
+ * <CatalogPage />
307
+ * </TebexMockProvider>
308
+ * ```
309
+ */
310
+ export declare function TebexMockProvider({ children, mockData: mockDataConfig, username, withBasket, baseUrl, onError, }: TebexMockProviderProps): ReactNode;
311
+ /**
312
+ * Hook to check if we're inside a mock provider.
313
+ * Useful for conditional logic in components.
314
+ *
315
+ * Note: This hook checks for any Tebex provider (real or mock).
316
+ * The mock provider is identified by its configuration.
317
+ */
318
+ export declare function useIsMockProvider(): boolean;
319
+
320
+ export {
321
+ Basket,
322
+ BasketPackage,
323
+ Category,
324
+ Code,
325
+ GiftCardCode,
326
+ Package,
327
+ };
328
+
329
+ export {};
@@ -0,0 +1 @@
1
+ import{QueryClient as y,QueryClientProvider as f}from"@tanstack/react-query";import{useContext as l,useEffect as E,useMemo as T,useState as d}from"react";import{createContext as q,useContext as s}from"react";var Q=q(null);var O={all:["tebex"],categories:()=>[...O.all,"categories"],categoriesList:(A)=>[...O.categories(),"list",{includePackages:A}],category:(A)=>[...O.categories(),"detail",A],packages:()=>[...O.all,"packages"],packagesList:(A)=>[...O.packages(),"list",{categoryId:A}],package:(A)=>[...O.packages(),"detail",A],baskets:()=>[...O.all,"baskets"],basket:(A)=>[...O.baskets(),A],webstore:()=>[...O.all,"webstore"]};import{create as B}from"zustand";import{persist as M,subscribeWithSelector as x}from"zustand/middleware";var V=B()(x(M((A)=>({basketIdent:null,setBasketIdent:(F)=>{A({basketIdent:F})},clearBasketIdent:()=>{A({basketIdent:null})}}),{name:"tebex-basket-store",skipHydration:typeof window>"u"})));import{create as p}from"zustand";import{persist as C,subscribeWithSelector as b}from"zustand/middleware";var W=p()(b(C((A)=>({username:null,setUsername:(F)=>{A({username:F})},clearUsername:()=>{A({username:null})}}),{name:"tebex-user-store",skipHydration:typeof window>"u"})));var G={id:1,name:"Test Store",description:"A test Tebex store for development",currency:"EUR",domain:"test.tebex.io",logo:null},Y=[{id:101,name:"VIP Gold",description:"Gold VIP membership with exclusive perks",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:9.99,sales_tax:0,total_price:9.99,currency:"EUR",image:null,category:{id:1,name:"VIP Ranks"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:1},{id:102,name:"VIP Diamond",description:"Diamond VIP membership with all perks",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:19.99,sales_tax:0,total_price:19.99,currency:"EUR",image:null,category:{id:1,name:"VIP Ranks"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:2},{id:201,name:"Pet Pack",description:"Adorable pet companions",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:4.99,sales_tax:0,total_price:4.99,currency:"EUR",image:null,category:{id:2,name:"Cosmetics"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:1},{id:202,name:"Trail Effects",description:"Particle trail effects",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:2.99,sales_tax:0,total_price:2.99,currency:"EUR",image:null,category:{id:2,name:"Cosmetics"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:2},{id:301,name:"1000 Coins",description:"In-game currency pack",type:"single",disable_gifting:!1,disable_quantity:!1,expiration_date:null,base_price:1.99,sales_tax:0,total_price:1.99,currency:"EUR",image:null,category:{id:3,name:"Currency"},discount:0,created_at:"2024-01-01T00:00:00Z",updated_at:"2024-01-01T00:00:00Z",order:1}],z=[{id:1,name:"VIP Ranks",description:"Exclusive VIP memberships",parent:null,order:1,display_type:"grid",slug:"vip-ranks",packages:Y.filter((A)=>A.category.id===1)},{id:2,name:"Cosmetics",description:"Cosmetic items and effects",parent:null,order:2,display_type:"grid",slug:"cosmetics",packages:Y.filter((A)=>A.category.id===2)},{id:3,name:"Currency",description:"In-game currency packs",parent:null,order:3,display_type:"grid",slug:"currency",packages:Y.filter((A)=>A.category.id===3)}],H={ident:"mock-basket-001",complete:!1,id:1,country:"US",ip:"127.0.0.1",username_id:null,username:null,cancel_url:"https://example.com/cancel",complete_url:"https://example.com/complete",complete_auto_redirect:!1,base_price:0,sales_tax:0,total_price:0,email:"",currency:"EUR",packages:[],coupons:[],giftcards:[],creator_code:"",links:{checkout:"https://checkout.tebex.io/mock"},custom:{}};function S(A,F=1,L=null){return{id:A.id,name:A.name,description:A.description,image:A.image,in_basket:{quantity:F,price:A.base_price*F,gift_username_id:null,gift_username:L}}}function $(A,F){let L=A.map((X)=>S(X.package,X.quantity??1,X.giftUsername??null)),J=L.reduce((X,_)=>X+_.in_basket.price,0);return{...H,packages:L,total_price:J,base_price:J,...F}}function j(A){return{code:A}}function w(A){return{card_number:A}}var m={webstore:G,categories:z,packages:Y,emptyBasket:H,basketWithOneItem:$([{package:Y[0],quantity:1}]),basketWithMultipleItems:$([{package:Y[0],quantity:1},{package:Y[2],quantity:2}]),basketWithCoupon:{...$([{package:Y[0],quantity:1}]),coupons:[j("SAVE10")]},basketWithGiftCard:{...$([{package:Y[0],quantity:1}]),giftcards:[w("GIFT-1234-5678")]},basketWithCreatorCode:{...$([{package:Y[0],quantity:1}]),creator_code:"STREAMER123"},helpers:{createBasketPackage:S,createMockBasket:$,createMockCoupon:j,createMockGiftCard:w},getPackageById:(A)=>{return Y.find((F)=>F.id===A)},getCategoryById:(A)=>{return z.find((F)=>F.id===A)}};import{jsxDEV as v}from"react/jsx-dev-runtime";function u(){return new y({defaultOptions:{queries:{staleTime:1/0,gcTime:1/0,retry:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1},mutations:{retry:!1}}})}function g(A,F){let L=A.replace(/\/$/,"");return{publicKey:"mock-public-key",baseUrl:L,completeUrl:`${L}/shop/complete`,cancelUrl:`${L}/shop/cancel`,onError:F,devtools:!1}}function k(A,F){A.setQueryData(O.webstore(),{id:F.webstore.id,name:F.webstore.name,description:F.webstore.description,currency:F.webstore.currency,domain:F.webstore.domain,logo:F.webstore.logo}),A.setQueryData(O.categoriesList(!0),F.categories),A.setQueryData(O.categoriesList(!1),F.categories.map((J)=>({...J,packages:[]})));for(let J of F.categories)A.setQueryData(O.category(J.id),J);A.setQueryData(O.packagesList(),F.packages);let L=new Map;for(let J of F.packages){let X=J.category.id,_=L.get(X)??[];L.set(X,[..._,J])}for(let[J,X]of L)A.setQueryData(O.packagesList(J),X);for(let J of F.packages)A.setQueryData(O.package(J.id),J);if(F.basket!==null&&F.basketIdent!==null)A.setQueryData(O.basket(F.basketIdent),F.basket)}function i({username:A,basketIdent:F}){let L=W((Z)=>Z.setUsername),J=W((Z)=>Z.clearUsername),X=V((Z)=>Z.setBasketIdent),_=V((Z)=>Z.clearBasketIdent);return E(()=>{if(A!==null)L(A);else J()},[A,L,J]),E(()=>{if(F!==null)X(F);else _()},[F,X,_]),null}function n({children:A,mockData:F,username:L="TestPlayer",withBasket:J=!0,baseUrl:X="https://mock.tebex.io",onError:_}){let Z=T(()=>{let U={...G,...F?.webstore},P=F?.categories??z,D=F?.packages??Y,R=null,h=null;if(J){if(R=F?.basket?{...H,...F.basket}:H,h=R.ident,L!==null)R={...R,username:L}}return{webstore:U,categories:P,packages:D,basket:R,basketIdent:h}},[F,J,L]),[N]=d(()=>u()),K=T(()=>g(X,_),[X,_]);E(()=>{k(N,Z)},[N,Z]);let I=T(()=>({config:K,queryClient:N}),[K,N]);return v(Q.Provider,{value:I,children:v(f,{client:N,children:[v(i,{username:L,basketIdent:Z.basketIdent},void 0,!1,void 0,this),A]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function c(){let A=l(Q);return A!==null&&A.config.publicKey==="mock-public-key"}export{c as useIsMockProvider,m as mockData,G as defaultMockWebstore,Y as defaultMockPackages,z as defaultMockCategories,H as defaultMockBasket,w as createMockGiftCard,j as createMockCoupon,$ as createMockBasket,S as createBasketPackage,n as TebexMockProvider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neosianexus/super-tebex",
3
- "version": "3.0.3",
3
+ "version": "3.1.1",
4
4
  "description": "Tebex Headless SDK optimized for Next.js App Router with TanStack Query",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -11,6 +11,11 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js",
13
13
  "require": "./dist/index.cjs"
14
+ },
15
+ "./testing": {
16
+ "types": "./dist/testing/index.d.ts",
17
+ "import": "./dist/testing/index.js",
18
+ "require": "./dist/testing/index.cjs"
14
19
  }
15
20
  },
16
21
  "files": [