@techzunction/sdk 0.1.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,2038 @@
1
+ // src/query.ts
2
+ var TZQuery = class _TZQuery {
3
+ constructor(executor) {
4
+ this._executor = executor;
5
+ this.controller = new AbortController();
6
+ this._promise = executor(this.controller.signal);
7
+ }
8
+ /** Thenable — `await query` resolves directly to T */
9
+ then(onFulfilled, onRejected) {
10
+ return this._promise.then((r) => r.data).then(onFulfilled, onRejected);
11
+ }
12
+ /** Catch errors */
13
+ catch(onRejected) {
14
+ return this.then(void 0, onRejected);
15
+ }
16
+ /** Get the unwrapped data */
17
+ async data() {
18
+ return (await this._promise).data;
19
+ }
20
+ /** Get the raw JSON (before envelope unwrap) */
21
+ async raw() {
22
+ return (await this._promise).raw;
23
+ }
24
+ /** Get the HTTP status code */
25
+ async status() {
26
+ return (await this._promise).status;
27
+ }
28
+ /** Get the response headers */
29
+ async headers() {
30
+ return (await this._promise).headers;
31
+ }
32
+ /** Abort the in-flight request */
33
+ cancel() {
34
+ this.controller.abort();
35
+ }
36
+ /** Re-execute the same request (returns a new TZQuery) */
37
+ refetch() {
38
+ return new _TZQuery(this._executor);
39
+ }
40
+ };
41
+ var TZPaginatedQuery = class extends TZQuery {
42
+ constructor(executor, page, limit, pageFactory) {
43
+ super(executor);
44
+ this._page = page;
45
+ this._limit = limit;
46
+ this._pageFactory = pageFactory;
47
+ }
48
+ /** Current page number */
49
+ get page() {
50
+ return this._page;
51
+ }
52
+ /** Current page size */
53
+ get limit() {
54
+ return this._limit;
55
+ }
56
+ /** Fetch the next page (returns a new TZPaginatedQuery) */
57
+ next() {
58
+ return this._pageFactory(this._page + 1, this._limit);
59
+ }
60
+ /** Fetch the previous page (returns a new TZPaginatedQuery, clamped to page 1) */
61
+ prev() {
62
+ return this._pageFactory(Math.max(1, this._page - 1), this._limit);
63
+ }
64
+ /** Jump to a specific page */
65
+ goTo(page) {
66
+ return this._pageFactory(Math.max(1, page), this._limit);
67
+ }
68
+ /** Check if there's a next page (must await first) */
69
+ async hasNext() {
70
+ const result = await this.data();
71
+ return this._page < result.totalPages;
72
+ }
73
+ /** Check if there's a previous page */
74
+ hasPrev() {
75
+ return this._page > 1;
76
+ }
77
+ /** Re-execute the same page */
78
+ refetch() {
79
+ return this._pageFactory(this._page, this._limit);
80
+ }
81
+ };
82
+
83
+ // src/client.ts
84
+ var noopStore = {
85
+ get: () => null,
86
+ set: () => {
87
+ },
88
+ remove: () => {
89
+ }
90
+ };
91
+ function createLocalStorageStore() {
92
+ if (typeof globalThis !== "undefined" && "localStorage" in globalThis) {
93
+ return {
94
+ get: (key) => localStorage.getItem(key),
95
+ set: (key, value) => localStorage.setItem(key, value),
96
+ remove: (key) => localStorage.removeItem(key)
97
+ };
98
+ }
99
+ return noopStore;
100
+ }
101
+ function makeKeys(prefix) {
102
+ return {
103
+ access: `${prefix}-access-token`,
104
+ refresh: `${prefix}-refresh-token`,
105
+ staffAccess: `${prefix}-staff-access-token`,
106
+ staffRefresh: `${prefix}-staff-refresh-token`,
107
+ superAdminAccess: `${prefix}-sa-access-token`
108
+ };
109
+ }
110
+ function toQs(params) {
111
+ if (!params) return "";
112
+ const entries = Object.entries(params).filter(([, v]) => v !== void 0 && v !== null && v !== "").map(([k, v]) => [k, String(v)]);
113
+ return entries.length ? "?" + new URLSearchParams(entries).toString() : "";
114
+ }
115
+ var TZClient = class {
116
+ constructor(config) {
117
+ this.enduserRefreshPromise = null;
118
+ this.staffRefreshPromise = null;
119
+ this.baseUrl = config.baseUrl.replace(/\/+$/, "");
120
+ this.orgSlug = config.orgSlug;
121
+ this.orgKey = config.orgKey;
122
+ this.store = config.tokenStore ?? createLocalStorageStore();
123
+ this.keys = makeKeys(config.keyPrefix ?? "tz");
124
+ this.onAuthExpired = config.onAuthExpired;
125
+ }
126
+ // ─── Token Accessors ───────────────────────────────────────────────────
127
+ getEndUserToken() {
128
+ return this.store.get(this.keys.access);
129
+ }
130
+ getEndUserRefreshToken() {
131
+ return this.store.get(this.keys.refresh);
132
+ }
133
+ saveEndUserTokens(access, refresh) {
134
+ this.store.set(this.keys.access, access);
135
+ this.store.set(this.keys.refresh, refresh);
136
+ }
137
+ clearEndUserTokens() {
138
+ this.store.remove(this.keys.access);
139
+ this.store.remove(this.keys.refresh);
140
+ }
141
+ getStaffToken() {
142
+ return this.store.get(this.keys.staffAccess);
143
+ }
144
+ getStaffRefreshToken() {
145
+ return this.store.get(this.keys.staffRefresh);
146
+ }
147
+ saveStaffTokens(access, refresh) {
148
+ this.store.set(this.keys.staffAccess, access);
149
+ this.store.set(this.keys.staffRefresh, refresh);
150
+ }
151
+ clearStaffTokens() {
152
+ this.store.remove(this.keys.staffAccess);
153
+ this.store.remove(this.keys.staffRefresh);
154
+ }
155
+ getSuperAdminToken() {
156
+ return this.store.get(this.keys.superAdminAccess);
157
+ }
158
+ saveSuperAdminToken(token) {
159
+ this.store.set(this.keys.superAdminAccess, token);
160
+ }
161
+ clearSuperAdminToken() {
162
+ this.store.remove(this.keys.superAdminAccess);
163
+ }
164
+ isEndUserAuthenticated() {
165
+ return !!this.getEndUserToken();
166
+ }
167
+ isStaffAuthenticated() {
168
+ return !!this.getStaffToken();
169
+ }
170
+ // ─── Token Refresh (singleton to prevent stampede) ─────────────────────
171
+ async doRefreshEndUser() {
172
+ const rt = this.getEndUserRefreshToken();
173
+ if (!rt) return null;
174
+ try {
175
+ const res = await fetch(`${this.baseUrl}/api/v1/storefront/auth/refresh`, {
176
+ method: "POST",
177
+ headers: {
178
+ "Content-Type": "application/json",
179
+ "X-Org-Slug": this.orgSlug,
180
+ ...this.orgKey ? { "X-Org-Key": this.orgKey } : {}
181
+ },
182
+ body: JSON.stringify({ refreshToken: rt })
183
+ });
184
+ if (!res.ok) {
185
+ this.clearEndUserTokens();
186
+ this.onAuthExpired?.();
187
+ return null;
188
+ }
189
+ const json = await res.json();
190
+ const access = json.accessToken ?? json.data?.accessToken;
191
+ const refresh = json.refreshToken ?? json.data?.refreshToken;
192
+ if (access) {
193
+ this.saveEndUserTokens(access, refresh || rt);
194
+ return access;
195
+ }
196
+ this.clearEndUserTokens();
197
+ this.onAuthExpired?.();
198
+ return null;
199
+ } catch {
200
+ this.clearEndUserTokens();
201
+ this.onAuthExpired?.();
202
+ return null;
203
+ }
204
+ }
205
+ async doRefreshStaff() {
206
+ const rt = this.getStaffRefreshToken();
207
+ if (!rt) return null;
208
+ try {
209
+ const res = await fetch(`${this.baseUrl}/api/v1/auth/refresh`, {
210
+ method: "POST",
211
+ headers: { "Content-Type": "application/json", "X-Org-Slug": this.orgSlug },
212
+ body: JSON.stringify({ refreshToken: rt })
213
+ });
214
+ if (!res.ok) {
215
+ this.clearStaffTokens();
216
+ return null;
217
+ }
218
+ const json = await res.json();
219
+ const access = json.accessToken ?? json.data?.accessToken;
220
+ const refresh = json.refreshToken ?? json.data?.refreshToken;
221
+ if (access) {
222
+ this.saveStaffTokens(access, refresh || rt);
223
+ return access;
224
+ }
225
+ this.clearStaffTokens();
226
+ return null;
227
+ } catch {
228
+ this.clearStaffTokens();
229
+ return null;
230
+ }
231
+ }
232
+ refreshEndUser() {
233
+ if (!this.enduserRefreshPromise) {
234
+ this.enduserRefreshPromise = this.doRefreshEndUser().finally(() => {
235
+ this.enduserRefreshPromise = null;
236
+ });
237
+ }
238
+ return this.enduserRefreshPromise;
239
+ }
240
+ refreshStaff() {
241
+ if (!this.staffRefreshPromise) {
242
+ this.staffRefreshPromise = this.doRefreshStaff().finally(() => {
243
+ this.staffRefreshPromise = null;
244
+ });
245
+ }
246
+ return this.staffRefreshPromise;
247
+ }
248
+ // ─── Core Raw Request ──────────────────────────────────────────────────
249
+ async rawRequest(method, fullPath, opts) {
250
+ const { body, scope, signal, sendOrgKey } = opts;
251
+ try {
252
+ const token = this.resolveToken(scope);
253
+ const headers = {
254
+ "X-Org-Slug": this.orgSlug,
255
+ ...sendOrgKey && this.orgKey ? { "X-Org-Key": this.orgKey } : {},
256
+ ...body !== void 0 && !(body instanceof FormData) ? { "Content-Type": "application/json" } : {},
257
+ ...token ? { Authorization: `Bearer ${token}` } : {}
258
+ };
259
+ const init = {
260
+ method,
261
+ headers,
262
+ ...body !== void 0 ? { body: body instanceof FormData ? body : JSON.stringify(body) } : {},
263
+ ...signal ? { signal } : {}
264
+ };
265
+ let res = await fetch(`${this.baseUrl}/api/v1${fullPath}`, init);
266
+ if (res.status === 401 && token && !fullPath.includes("/auth/")) {
267
+ const newToken = await this.tryRefresh(scope);
268
+ if (newToken) {
269
+ init.headers["Authorization"] = `Bearer ${newToken}`;
270
+ res = await fetch(`${this.baseUrl}/api/v1${fullPath}`, init);
271
+ }
272
+ }
273
+ const json = await res.json().catch(() => ({}));
274
+ if (!res.ok) {
275
+ const msg = res.status === 403 ? "You do not have permission to perform this action" : res.status === 429 ? "Too many requests \u2014 please try again later" : json.message || (typeof json.error === "string" ? json.error : json.error?.message) || `Request failed (${res.status})`;
276
+ const err = new Error(msg);
277
+ err.status = res.status;
278
+ err.data = json;
279
+ throw err;
280
+ }
281
+ const data = json && typeof json === "object" && "success" in json && "data" in json ? json.data : json;
282
+ return { data, raw: json, status: res.status, headers: res.headers };
283
+ } catch (err) {
284
+ if (err && typeof err === "object" && "status" in err) throw err;
285
+ const error = new Error(err instanceof Error ? err.message : "Network error \u2014 check your connection");
286
+ error.status = 0;
287
+ throw error;
288
+ }
289
+ }
290
+ resolveToken(scope) {
291
+ switch (scope) {
292
+ case "enduser":
293
+ return this.getEndUserToken();
294
+ case "staff":
295
+ return this.getStaffToken();
296
+ case "superadmin":
297
+ return this.getSuperAdminToken();
298
+ case "public":
299
+ return null;
300
+ }
301
+ }
302
+ async tryRefresh(scope) {
303
+ switch (scope) {
304
+ case "enduser":
305
+ return this.refreshEndUser();
306
+ case "staff":
307
+ return this.refreshStaff();
308
+ default:
309
+ return null;
310
+ }
311
+ }
312
+ // ─── Scoped Client Factory ─────────────────────────────────────────────
313
+ scoped(pathPrefix, defaultScope, sendOrgKey) {
314
+ return new ScopedClient(this, pathPrefix, defaultScope, sendOrgKey);
315
+ }
316
+ };
317
+ var ScopedClient = class {
318
+ constructor(root, prefix, defaultScope, sendOrgKey) {
319
+ this.root = root;
320
+ this.prefix = prefix;
321
+ this.defaultScope = defaultScope;
322
+ this.sendOrgKey = sendOrgKey;
323
+ }
324
+ fullPath(path) {
325
+ return `${this.prefix}${path}`;
326
+ }
327
+ // ─── TZQuery builders (return rich query objects) ──────────────────────
328
+ /** GET → TZQuery<T> with .cancel(), .refetch(), .raw(), .status() */
329
+ get(path, scope) {
330
+ const s = scope ?? this.defaultScope;
331
+ const fp = this.fullPath(path);
332
+ return new TZQuery((signal) => this.root.rawRequest("GET", fp, { scope: s, signal, sendOrgKey: this.sendOrgKey }));
333
+ }
334
+ /** POST → TZQuery<T> */
335
+ post(path, body, scope) {
336
+ const s = scope ?? this.defaultScope;
337
+ const fp = this.fullPath(path);
338
+ return new TZQuery((signal) => this.root.rawRequest("POST", fp, { body, scope: s, signal, sendOrgKey: this.sendOrgKey }));
339
+ }
340
+ /** PATCH → TZQuery<T> */
341
+ patch(path, body, scope) {
342
+ const s = scope ?? this.defaultScope;
343
+ const fp = this.fullPath(path);
344
+ return new TZQuery((signal) => this.root.rawRequest("PATCH", fp, { body, scope: s, signal, sendOrgKey: this.sendOrgKey }));
345
+ }
346
+ /** PUT → TZQuery<T> */
347
+ put(path, body, scope) {
348
+ const s = scope ?? this.defaultScope;
349
+ const fp = this.fullPath(path);
350
+ return new TZQuery((signal) => this.root.rawRequest("PUT", fp, { body, scope: s, signal, sendOrgKey: this.sendOrgKey }));
351
+ }
352
+ /** DELETE → TZQuery<T> */
353
+ del(path, scope) {
354
+ const s = scope ?? this.defaultScope;
355
+ const fp = this.fullPath(path);
356
+ return new TZQuery((signal) => this.root.rawRequest("DELETE", fp, { scope: s, signal, sendOrgKey: this.sendOrgKey }));
357
+ }
358
+ /** Upload (multipart/form-data) → TZQuery<T> */
359
+ upload(path, formData, scope) {
360
+ const s = scope ?? this.defaultScope;
361
+ const fp = this.fullPath(path);
362
+ return new TZQuery((signal) => this.root.rawRequest("POST", fp, { body: formData, scope: s, signal, sendOrgKey: this.sendOrgKey }));
363
+ }
364
+ /** Paginated GET → TZPaginatedQuery<T> with .next(), .prev(), .goTo() */
365
+ paginated(path, params = {}) {
366
+ const page = params.page ?? 1;
367
+ const limit = params.limit ?? 20;
368
+ const scope = this.defaultScope;
369
+ const factory = (p, l) => {
370
+ const merged = { ...params, page: p, limit: l };
371
+ const qs = toQs(merged);
372
+ const fp = this.fullPath(`${path}${qs}`);
373
+ return new TZPaginatedQuery(
374
+ (signal) => this.root.rawRequest("GET", fp, { scope, signal, sendOrgKey: this.sendOrgKey }),
375
+ p,
376
+ l,
377
+ factory
378
+ );
379
+ };
380
+ return factory(page, limit);
381
+ }
382
+ // ─── Direct await methods (for auth flows that need immediate token save) ─
383
+ async postDirect(path, body, scope) {
384
+ return (await this.root.rawRequest("POST", this.fullPath(path), {
385
+ body,
386
+ scope: scope ?? this.defaultScope,
387
+ sendOrgKey: this.sendOrgKey
388
+ })).data;
389
+ }
390
+ async getDirect(path, scope) {
391
+ return (await this.root.rawRequest("GET", this.fullPath(path), {
392
+ scope: scope ?? this.defaultScope,
393
+ sendOrgKey: this.sendOrgKey
394
+ })).data;
395
+ }
396
+ async patchDirect(path, body, scope) {
397
+ return (await this.root.rawRequest("PATCH", this.fullPath(path), {
398
+ body,
399
+ scope: scope ?? this.defaultScope,
400
+ sendOrgKey: this.sendOrgKey
401
+ })).data;
402
+ }
403
+ async delDirect(path, scope) {
404
+ return (await this.root.rawRequest("DELETE", this.fullPath(path), {
405
+ scope: scope ?? this.defaultScope,
406
+ sendOrgKey: this.sendOrgKey
407
+ })).data;
408
+ }
409
+ };
410
+
411
+ // src/storefront/auth.ts
412
+ function createStorefrontAuth(c) {
413
+ const orgSlug = c.root.orgSlug;
414
+ return {
415
+ // ─── Pre-Login (PUBLIC) ───────────────────────────────────────────
416
+ register(data) {
417
+ return c.postDirect("/auth/register", { ...data, orgSlug }).then((r) => {
418
+ c.root.saveEndUserTokens(r.accessToken, r.refreshToken);
419
+ return r;
420
+ });
421
+ },
422
+ login(data) {
423
+ return c.postDirect("/auth/login", { ...data, orgSlug }).then((r) => {
424
+ c.root.saveEndUserTokens(r.accessToken, r.refreshToken);
425
+ return r;
426
+ });
427
+ },
428
+ sendOtp(data) {
429
+ return c.post("/auth/send-otp", { ...data, orgSlug });
430
+ },
431
+ verifyOtp(data) {
432
+ return c.postDirect("/auth/verify-otp", { ...data, orgSlug }).then((r) => {
433
+ c.root.saveEndUserTokens(r.accessToken, r.refreshToken);
434
+ return r;
435
+ });
436
+ },
437
+ startSignup(data) {
438
+ return c.post("/auth/start-signup", { ...data, orgSlug });
439
+ },
440
+ verifySignupOtp(data) {
441
+ return c.postDirect("/auth/verify-signup-otp", { ...data, orgSlug }).then((r) => {
442
+ c.root.saveEndUserTokens(r.accessToken, r.refreshToken);
443
+ return r;
444
+ });
445
+ },
446
+ requestPasswordReset(data) {
447
+ return c.post("/auth/request-reset", { ...data, orgSlug });
448
+ },
449
+ forgotPassword(data) {
450
+ return c.post("/auth/forgot-password", { ...data, orgSlug });
451
+ },
452
+ resetPassword(data) {
453
+ return c.post("/auth/reset-password", data);
454
+ },
455
+ getGoogleOAuthUrl() {
456
+ return `${c.root.baseUrl}/api/v1/storefront/auth/google?orgSlug=${orgSlug}`;
457
+ },
458
+ getFacebookOAuthUrl() {
459
+ return `${c.root.baseUrl}/api/v1/storefront/auth/facebook?orgSlug=${orgSlug}`;
460
+ },
461
+ // ─── Post-Login (ENDUSER) ─────────────────────────────────────────
462
+ completeSignup(data) {
463
+ return c.postDirect("/auth/complete-signup", data, "enduser").then((r) => {
464
+ c.root.saveEndUserTokens(r.accessToken, r.refreshToken);
465
+ return r;
466
+ });
467
+ },
468
+ me() {
469
+ return c.get("/auth/me", "enduser");
470
+ },
471
+ updateProfile(data) {
472
+ return c.patch("/auth/profile", data, "enduser");
473
+ },
474
+ changePassword(data) {
475
+ return c.post("/auth/change-password", data, "enduser");
476
+ },
477
+ logout() {
478
+ const refreshToken = c.root.getEndUserRefreshToken();
479
+ return c.postDirect("/auth/logout", { refreshToken }, "enduser").finally(() => c.root.clearEndUserTokens());
480
+ },
481
+ refresh() {
482
+ const refreshToken = c.root.getEndUserRefreshToken();
483
+ return c.postDirect("/auth/refresh", { refreshToken }).then((r) => {
484
+ c.root.saveEndUserTokens(r.accessToken, r.refreshToken);
485
+ return r;
486
+ });
487
+ },
488
+ // ─── Helpers ──────────────────────────────────────────────────────
489
+ isAuthenticated: () => c.root.isEndUserAuthenticated(),
490
+ getToken: () => c.root.getEndUserToken(),
491
+ clearTokens: () => c.root.clearEndUserTokens()
492
+ };
493
+ }
494
+
495
+ // src/storefront/catalog.ts
496
+ function createStorefrontCatalog(c) {
497
+ return {
498
+ getCategories() {
499
+ return c.get("/catalog/categories");
500
+ },
501
+ getItems(params) {
502
+ return c.paginated("/catalog/items", params);
503
+ },
504
+ getItem(id) {
505
+ return c.get(`/catalog/items/${id}`);
506
+ }
507
+ };
508
+ }
509
+
510
+ // src/storefront/cart.ts
511
+ function createStorefrontCart(c) {
512
+ return {
513
+ get() {
514
+ return c.get("/cart", "enduser");
515
+ },
516
+ addItem(data) {
517
+ return c.post("/cart/items", data, "enduser");
518
+ },
519
+ updateItem(itemId, data) {
520
+ return c.patch(`/cart/items/${itemId}`, data, "enduser");
521
+ },
522
+ removeItem(itemId) {
523
+ return c.del(`/cart/items/${itemId}`, "enduser");
524
+ },
525
+ validate() {
526
+ return c.post("/cart/validate", void 0, "enduser");
527
+ },
528
+ clear() {
529
+ return c.del("/cart", "enduser");
530
+ }
531
+ };
532
+ }
533
+
534
+ // src/storefront/orders.ts
535
+ function createStorefrontOrders(c) {
536
+ return {
537
+ create(data) {
538
+ return c.post("/orders", data, "enduser");
539
+ },
540
+ list(params) {
541
+ return c.paginated("/orders", params);
542
+ },
543
+ get(id) {
544
+ return c.get(`/orders/${id}`, "enduser");
545
+ },
546
+ reorder(data) {
547
+ return c.post("/orders/reorder", data, "enduser");
548
+ },
549
+ reportIssue(orderId, data) {
550
+ return c.post(`/orders/${orderId}/issue`, data, "enduser");
551
+ }
552
+ };
553
+ }
554
+
555
+ // src/storefront/payments.ts
556
+ function createStorefrontPayments(c) {
557
+ return {
558
+ createOrder(data) {
559
+ return c.post("/payments/create-order", data, "enduser");
560
+ },
561
+ verify(data) {
562
+ return c.post("/payments/verify", data, "enduser");
563
+ }
564
+ };
565
+ }
566
+
567
+ // src/storefront/delivery.ts
568
+ function createStorefrontDelivery(c) {
569
+ return {
570
+ calculate(data) {
571
+ return c.post("/delivery/calculate", data);
572
+ },
573
+ fee(data) {
574
+ return c.post("/delivery/fee", data);
575
+ },
576
+ tracking(orderId) {
577
+ return c.get(`/delivery/orders/${orderId}/tracking`, "enduser");
578
+ }
579
+ };
580
+ }
581
+
582
+ // src/storefront/locations.ts
583
+ function createStorefrontLocations(c) {
584
+ return {
585
+ list() {
586
+ return c.get("/locations");
587
+ },
588
+ get(id) {
589
+ return c.get(`/locations/${id}`);
590
+ }
591
+ };
592
+ }
593
+
594
+ // src/storefront/loyalty.ts
595
+ function createStorefrontLoyalty(c) {
596
+ return {
597
+ getAccount() {
598
+ return c.get("/loyalty", "enduser");
599
+ },
600
+ getTransactions() {
601
+ return c.get("/loyalty/transactions", "enduser");
602
+ },
603
+ getRewards() {
604
+ return c.get("/loyalty/rewards", "enduser");
605
+ },
606
+ getRedemptions() {
607
+ return c.get("/loyalty/redeem", "enduser");
608
+ },
609
+ redeem(data) {
610
+ return c.post("/loyalty/redeem", data, "enduser");
611
+ }
612
+ };
613
+ }
614
+
615
+ // src/storefront/coupons.ts
616
+ function createStorefrontCoupons(c) {
617
+ return {
618
+ validate(data) {
619
+ return c.post("/coupons/validate", data);
620
+ }
621
+ };
622
+ }
623
+
624
+ // src/storefront/promotions.ts
625
+ function createStorefrontPromotions(c) {
626
+ return {
627
+ list() {
628
+ return c.get("/promotions");
629
+ }
630
+ };
631
+ }
632
+
633
+ // src/storefront/referrals.ts
634
+ function createStorefrontReferrals(c) {
635
+ return {
636
+ getMyCode() {
637
+ return c.get("/referral", "enduser");
638
+ },
639
+ validate(data) {
640
+ return c.post("/referral/validate", data);
641
+ }
642
+ };
643
+ }
644
+
645
+ // src/storefront/reviews.ts
646
+ function createStorefrontReviews(c) {
647
+ return {
648
+ list(params) {
649
+ return c.paginated("/reviews", params);
650
+ },
651
+ myReviews() {
652
+ return c.get("/reviews/my", "enduser");
653
+ },
654
+ create(data) {
655
+ return c.post("/reviews", data, "enduser");
656
+ },
657
+ toggleHelpful(reviewId) {
658
+ return c.post(`/reviews/${reviewId}/helpful`, void 0, "enduser");
659
+ }
660
+ };
661
+ }
662
+
663
+ // src/storefront/gift-cards.ts
664
+ function createStorefrontGiftCards(c) {
665
+ return {
666
+ purchase(data) {
667
+ return c.post("/gift-cards/purchase", data, "enduser");
668
+ },
669
+ redeem(data) {
670
+ return c.post("/gift-cards/redeem", data, "enduser");
671
+ },
672
+ checkBalance(code) {
673
+ return c.get(`/gift-cards/balance?code=${encodeURIComponent(code)}`);
674
+ }
675
+ };
676
+ }
677
+
678
+ // src/storefront/reservations.ts
679
+ function createStorefrontReservations(c) {
680
+ return {
681
+ checkAvailability(params) {
682
+ return c.get(`/reservations/availability?date=${params.date}${params.partySize ? `&partySize=${params.partySize}` : ""}`);
683
+ },
684
+ create(data) {
685
+ return c.post("/reservations", data, "enduser");
686
+ },
687
+ list(params) {
688
+ return c.paginated("/reservations", params);
689
+ },
690
+ cancel(id) {
691
+ return c.post(`/reservations/${id}/cancel`, void 0, "enduser");
692
+ }
693
+ };
694
+ }
695
+
696
+ // src/storefront/support.ts
697
+ function createStorefrontSupport(c) {
698
+ return {
699
+ create(data) {
700
+ return c.post("/support", data, "enduser");
701
+ },
702
+ list(params) {
703
+ return c.paginated("/support", params);
704
+ },
705
+ reply(ticketId, data) {
706
+ return c.post(`/support/${ticketId}/reply`, data, "enduser");
707
+ }
708
+ };
709
+ }
710
+
711
+ // src/storefront/content.ts
712
+ function createStorefrontContent(c) {
713
+ return {
714
+ list(params) {
715
+ return c.paginated("/content", params);
716
+ },
717
+ getBySlug(slug) {
718
+ return c.get(`/content/${slug}`);
719
+ }
720
+ };
721
+ }
722
+
723
+ // src/storefront/notifications.ts
724
+ function createStorefrontNotifications(c) {
725
+ return {
726
+ list(params) {
727
+ return c.paginated("/notifications", params);
728
+ },
729
+ markRead(id) {
730
+ return c.post(`/notifications/${id}/read`, void 0, "enduser");
731
+ },
732
+ markAllRead() {
733
+ return c.post("/notifications/read-all", void 0, "enduser");
734
+ }
735
+ };
736
+ }
737
+
738
+ // src/storefront/addresses.ts
739
+ function createStorefrontAddresses(c) {
740
+ return {
741
+ list() {
742
+ return c.get("/addresses", "enduser");
743
+ },
744
+ get(id) {
745
+ return c.get(`/addresses/${id}`, "enduser");
746
+ },
747
+ create(data) {
748
+ return c.post("/addresses", data, "enduser");
749
+ },
750
+ update(id, data) {
751
+ return c.patch(`/addresses/${id}`, data, "enduser");
752
+ },
753
+ remove(id) {
754
+ return c.del(`/addresses/${id}`, "enduser");
755
+ }
756
+ };
757
+ }
758
+
759
+ // src/storefront/upload.ts
760
+ function createStorefrontUpload(c) {
761
+ return {
762
+ upload(file, folder) {
763
+ const formData = new FormData();
764
+ formData.append("file", file);
765
+ if (folder) formData.append("folder", folder);
766
+ return c.upload("/upload", formData, "enduser");
767
+ }
768
+ };
769
+ }
770
+
771
+ // src/storefront/contact.ts
772
+ function createStorefrontContact(c) {
773
+ return {
774
+ submit(data) {
775
+ return c.post("/contact", data);
776
+ },
777
+ subscribe(data) {
778
+ return c.post("/contact/subscribe", data);
779
+ }
780
+ };
781
+ }
782
+
783
+ // src/storefront/config.ts
784
+ function createStorefrontConfig(c) {
785
+ return {
786
+ get() {
787
+ return c.get("/config");
788
+ }
789
+ };
790
+ }
791
+
792
+ // src/storefront/property.ts
793
+ function createStorefrontProperty(c) {
794
+ return {
795
+ getTypes() {
796
+ return c.get("/property/types");
797
+ },
798
+ getType(id) {
799
+ return c.get(`/property/types/${id}`);
800
+ },
801
+ createBooking(data) {
802
+ return c.post("/property/bookings", data, "enduser");
803
+ },
804
+ listBookings(params) {
805
+ return c.paginated("/property/bookings", params);
806
+ },
807
+ getBooking(id) {
808
+ return c.get(`/property/bookings/${id}`, "enduser");
809
+ },
810
+ cancelBooking(id, data) {
811
+ return c.post(`/property/bookings/${id}/cancel`, data, "enduser");
812
+ },
813
+ createPaymentOrder(bookingId, data) {
814
+ return c.post(`/property/bookings/${bookingId}/payment-order`, data, "enduser");
815
+ },
816
+ verifyPayment(data) {
817
+ return c.post("/property/bookings/verify-payment", data, "enduser");
818
+ },
819
+ lookupBooking(reference) {
820
+ return c.get(`/property/bookings/lookup?reference=${encodeURIComponent(reference)}`);
821
+ },
822
+ checkAvailability(params) {
823
+ return c.get(`/property/availability?propertyTypeId=${params.propertyTypeId}&checkIn=${params.checkIn}&checkOut=${params.checkOut}`);
824
+ },
825
+ resolvePrice(data) {
826
+ return c.post("/property/pricing/resolve", data);
827
+ }
828
+ };
829
+ }
830
+
831
+ // src/storefront/movies.ts
832
+ function createStorefrontMovies(c) {
833
+ return {
834
+ list(params) {
835
+ return c.paginated("/movies", params);
836
+ },
837
+ heroBanners() {
838
+ return c.get("/movies/hero-banners");
839
+ },
840
+ genres() {
841
+ return c.get("/movies/genres");
842
+ },
843
+ getBySlug(slug) {
844
+ return c.get(`/movies/${slug}`);
845
+ },
846
+ library() {
847
+ return c.get("/movies/library", "enduser");
848
+ },
849
+ getStreamUrl(id) {
850
+ return c.get(`/movies/${id}/stream`, "enduser");
851
+ },
852
+ updateProgress(id, data) {
853
+ return c.post(`/movies/${id}/progress`, data, "enduser");
854
+ },
855
+ rent(id) {
856
+ return c.post(`/movies/${id}/rent`, void 0, "enduser");
857
+ },
858
+ buy(id) {
859
+ return c.post(`/movies/${id}/buy`, void 0, "enduser");
860
+ },
861
+ getWatchlist() {
862
+ return c.get("/watchlist", "enduser");
863
+ },
864
+ addToWatchlist(catalogItemId) {
865
+ return c.post(`/watchlist/${catalogItemId}`, void 0, "enduser");
866
+ },
867
+ removeFromWatchlist(catalogItemId) {
868
+ return c.del(`/watchlist/${catalogItemId}`, "enduser");
869
+ }
870
+ };
871
+ }
872
+
873
+ // src/storefront/tmdb.ts
874
+ function createStorefrontTmdb(c) {
875
+ return {
876
+ popular(page) {
877
+ return c.get(`/tmdb/popular${page ? `?page=${page}` : ""}`);
878
+ },
879
+ trending() {
880
+ return c.get("/tmdb/trending");
881
+ },
882
+ bollywood(page) {
883
+ return c.get(`/tmdb/bollywood${page ? `?page=${page}` : ""}`);
884
+ },
885
+ hollywood(page) {
886
+ return c.get(`/tmdb/hollywood${page ? `?page=${page}` : ""}`);
887
+ },
888
+ tamil(page) {
889
+ return c.get(`/tmdb/tamil${page ? `?page=${page}` : ""}`);
890
+ },
891
+ telugu(page) {
892
+ return c.get(`/tmdb/telugu${page ? `?page=${page}` : ""}`);
893
+ },
894
+ search(query, page) {
895
+ return c.get(`/tmdb/search?query=${encodeURIComponent(query)}${page ? `&page=${page}` : ""}`);
896
+ },
897
+ genres() {
898
+ return c.get("/tmdb/genres");
899
+ },
900
+ getStreamUrl(tmdbId) {
901
+ return c.get(`/tmdb/stream/${tmdbId}`);
902
+ },
903
+ getPlayUrl(tmdbId) {
904
+ return `${c.root.baseUrl}/api/v1/storefront/tmdb/play/${tmdbId}`;
905
+ },
906
+ getDetail(tmdbId) {
907
+ return c.get(`/tmdb/${tmdbId}`);
908
+ }
909
+ };
910
+ }
911
+
912
+ // src/storefront/wallet.ts
913
+ function createStorefrontWallet(c) {
914
+ return {
915
+ getPacks() {
916
+ return c.get("/wallet/packs");
917
+ }
918
+ };
919
+ }
920
+
921
+ // src/storefront/index.ts
922
+ function createStorefront(c) {
923
+ return {
924
+ auth: createStorefrontAuth(c),
925
+ catalog: createStorefrontCatalog(c),
926
+ cart: createStorefrontCart(c),
927
+ orders: createStorefrontOrders(c),
928
+ payments: createStorefrontPayments(c),
929
+ delivery: createStorefrontDelivery(c),
930
+ locations: createStorefrontLocations(c),
931
+ loyalty: createStorefrontLoyalty(c),
932
+ coupons: createStorefrontCoupons(c),
933
+ promotions: createStorefrontPromotions(c),
934
+ referrals: createStorefrontReferrals(c),
935
+ reviews: createStorefrontReviews(c),
936
+ giftCards: createStorefrontGiftCards(c),
937
+ reservations: createStorefrontReservations(c),
938
+ support: createStorefrontSupport(c),
939
+ content: createStorefrontContent(c),
940
+ notifications: createStorefrontNotifications(c),
941
+ addresses: createStorefrontAddresses(c),
942
+ upload: createStorefrontUpload(c),
943
+ contact: createStorefrontContact(c),
944
+ config: createStorefrontConfig(c),
945
+ property: createStorefrontProperty(c),
946
+ movies: createStorefrontMovies(c),
947
+ tmdb: createStorefrontTmdb(c),
948
+ wallet: createStorefrontWallet(c)
949
+ };
950
+ }
951
+
952
+ // src/admin/index.ts
953
+ function createAdmin(root, c) {
954
+ const orgSlug = root.orgSlug;
955
+ return {
956
+ // ─── Auth (Staff) ────────────────────────────────────────────────
957
+ auth: {
958
+ register(data) {
959
+ return root.rawRequest("POST", "/auth/register", { body: { ...data, orgSlug }, scope: "public", sendOrgKey: false }).then((r) => {
960
+ root.saveStaffTokens(r.data.accessToken, r.data.refreshToken);
961
+ return r.data;
962
+ });
963
+ },
964
+ login(data) {
965
+ return root.rawRequest("POST", "/auth/login", { body: { ...data, orgSlug }, scope: "public", sendOrgKey: false }).then((r) => {
966
+ root.saveStaffTokens(r.data.accessToken, r.data.refreshToken);
967
+ return r.data;
968
+ });
969
+ },
970
+ logout() {
971
+ const refreshToken = root.getStaffRefreshToken();
972
+ return root.rawRequest("POST", "/auth/logout", { body: { refreshToken }, scope: "staff", sendOrgKey: false }).then((r) => r.data).finally(() => root.clearStaffTokens());
973
+ },
974
+ me() {
975
+ return c.get("/users/me");
976
+ },
977
+ sendOtp(data) {
978
+ return root.rawRequest("POST", "/auth/otp/send", { body: { ...data, orgSlug }, scope: "public", sendOrgKey: false }).then((r) => r.data);
979
+ },
980
+ verifyOtp(data) {
981
+ return root.rawRequest("POST", "/auth/otp/verify", { body: { ...data, orgSlug }, scope: "public", sendOrgKey: false }).then((r) => {
982
+ root.saveStaffTokens(r.data.accessToken, r.data.refreshToken);
983
+ return r.data;
984
+ });
985
+ },
986
+ refresh() {
987
+ const refreshToken = root.getStaffRefreshToken();
988
+ return root.rawRequest("POST", "/auth/refresh", { body: { refreshToken }, scope: "public", sendOrgKey: false }).then((r) => {
989
+ root.saveStaffTokens(r.data.accessToken, r.data.refreshToken);
990
+ return r.data;
991
+ });
992
+ },
993
+ requestMagicLink(data) {
994
+ return root.rawRequest("POST", "/auth/magic-link", { body: { ...data, orgSlug }, scope: "public", sendOrgKey: false }).then((r) => r.data);
995
+ },
996
+ verifyMagicLink(params) {
997
+ return root.rawRequest("GET", `/auth/magic-link/verify?token=${encodeURIComponent(params.token)}&orgSlug=${orgSlug}`, { scope: "public", sendOrgKey: false }).then((r) => {
998
+ root.saveStaffTokens(r.data.accessToken, r.data.refreshToken);
999
+ return r.data;
1000
+ });
1001
+ },
1002
+ changePassword(data) {
1003
+ return c.post("/auth/password/change", data);
1004
+ },
1005
+ requestPasswordReset(data) {
1006
+ return root.rawRequest("POST", "/auth/password/reset-request", { body: { ...data, orgSlug }, scope: "public", sendOrgKey: false }).then((r) => r.data);
1007
+ },
1008
+ resetPassword(data) {
1009
+ return root.rawRequest("POST", "/auth/password/reset", { body: data, scope: "public", sendOrgKey: false }).then((r) => r.data);
1010
+ },
1011
+ isAuthenticated: () => root.isStaffAuthenticated(),
1012
+ getToken: () => root.getStaffToken(),
1013
+ clearTokens: () => root.clearStaffTokens()
1014
+ },
1015
+ // ─── Users ───────────────────────────────────────────────────────
1016
+ users: {
1017
+ list(params) {
1018
+ return c.paginated("/users", params);
1019
+ },
1020
+ get(id) {
1021
+ return c.get(`/users/${id}`);
1022
+ },
1023
+ invite(data) {
1024
+ return c.post("/users/invite", data);
1025
+ },
1026
+ update(id, data) {
1027
+ return c.patch(`/users/${id}`, data);
1028
+ },
1029
+ remove(id) {
1030
+ return c.del(`/users/${id}`);
1031
+ },
1032
+ suspend(id) {
1033
+ return c.post(`/users/${id}/suspend`);
1034
+ },
1035
+ reinstate(id) {
1036
+ return c.post(`/users/${id}/reinstate`);
1037
+ },
1038
+ assignRoles(id, data) {
1039
+ return c.post(`/users/${id}/roles`, data);
1040
+ }
1041
+ },
1042
+ // ─── Organization (Self) ─────────────────────────────────────────
1043
+ org: {
1044
+ me() {
1045
+ return c.get("/org/me");
1046
+ },
1047
+ update(data) {
1048
+ return c.patch("/org/me", data);
1049
+ }
1050
+ },
1051
+ // ─── Roles ───────────────────────────────────────────────────────
1052
+ roles: {
1053
+ list() {
1054
+ return c.get("/roles");
1055
+ },
1056
+ permissions() {
1057
+ return c.get("/roles/permissions");
1058
+ },
1059
+ get(id) {
1060
+ return c.get(`/roles/${id}`);
1061
+ },
1062
+ create(data) {
1063
+ return c.post("/roles", data);
1064
+ },
1065
+ update(id, data) {
1066
+ return c.patch(`/roles/${id}`, data);
1067
+ },
1068
+ remove(id) {
1069
+ return c.del(`/roles/${id}`);
1070
+ }
1071
+ },
1072
+ // ─── Catalog ─────────────────────────────────────────────────────
1073
+ catalog: {
1074
+ getCategories(params) {
1075
+ return c.paginated("/catalog/categories", params);
1076
+ },
1077
+ createCategory(data) {
1078
+ return c.post("/catalog/categories", data);
1079
+ },
1080
+ updateCategory(id, data) {
1081
+ return c.patch(`/catalog/categories/${id}`, data);
1082
+ },
1083
+ removeCategory(id) {
1084
+ return c.del(`/catalog/categories/${id}`);
1085
+ },
1086
+ getItems(params) {
1087
+ return c.paginated("/catalog/items", params);
1088
+ },
1089
+ getItem(id) {
1090
+ return c.get(`/catalog/items/${id}`);
1091
+ },
1092
+ createItem(data) {
1093
+ return c.post("/catalog/items", data);
1094
+ },
1095
+ updateItem(id, data) {
1096
+ return c.patch(`/catalog/items/${id}`, data);
1097
+ },
1098
+ removeItem(id) {
1099
+ return c.del(`/catalog/items/${id}`);
1100
+ },
1101
+ createVariant(itemId, data) {
1102
+ return c.post(`/catalog/items/${itemId}/variants`, data);
1103
+ },
1104
+ updateVariant(variantId, data) {
1105
+ return c.patch(`/catalog/variants/${variantId}`, data);
1106
+ },
1107
+ removeVariant(variantId) {
1108
+ return c.del(`/catalog/variants/${variantId}`);
1109
+ },
1110
+ createOptionGroup(itemId, data) {
1111
+ return c.post(`/catalog/items/${itemId}/option-groups`, data);
1112
+ },
1113
+ updateOptionGroup(groupId, data) {
1114
+ return c.patch(`/catalog/option-groups/${groupId}`, data);
1115
+ },
1116
+ removeOptionGroup(groupId) {
1117
+ return c.del(`/catalog/option-groups/${groupId}`);
1118
+ },
1119
+ createOption(groupId, data) {
1120
+ return c.post(`/catalog/option-groups/${groupId}/options`, data);
1121
+ },
1122
+ updateOption(optionId, data) {
1123
+ return c.patch(`/catalog/options/${optionId}`, data);
1124
+ },
1125
+ removeOption(optionId) {
1126
+ return c.del(`/catalog/options/${optionId}`);
1127
+ }
1128
+ },
1129
+ // ─── Commerce Orders ─────────────────────────────────────────────
1130
+ orders: {
1131
+ list(params) {
1132
+ return c.paginated("/commerce/orders", params);
1133
+ },
1134
+ stats() {
1135
+ return c.get("/commerce/orders/stats");
1136
+ },
1137
+ get(id) {
1138
+ return c.get(`/commerce/orders/${id}`);
1139
+ },
1140
+ updateStatus(id, data) {
1141
+ return c.patch(`/commerce/orders/${id}/status`, data);
1142
+ }
1143
+ },
1144
+ // ─── Locations ───────────────────────────────────────────────────
1145
+ locations: {
1146
+ list() {
1147
+ return c.get("/locations");
1148
+ },
1149
+ get(id) {
1150
+ return c.get(`/locations/${id}`);
1151
+ },
1152
+ create(data) {
1153
+ return c.post("/locations", data);
1154
+ },
1155
+ update(id, data) {
1156
+ return c.patch(`/locations/${id}`, data);
1157
+ },
1158
+ remove(id) {
1159
+ return c.del(`/locations/${id}`);
1160
+ },
1161
+ setHours(id, data) {
1162
+ return c.put(`/locations/${id}/hours`, data);
1163
+ },
1164
+ getDeliveryZones(id) {
1165
+ return c.get(`/locations/${id}/delivery-zones`);
1166
+ },
1167
+ createDeliveryZone(id, data) {
1168
+ return c.post(`/locations/${id}/delivery-zones`, data);
1169
+ },
1170
+ updateDeliveryZone(zoneId, data) {
1171
+ return c.patch(`/locations/delivery-zones/${zoneId}`, data);
1172
+ },
1173
+ removeDeliveryZone(zoneId) {
1174
+ return c.del(`/locations/delivery-zones/${zoneId}`);
1175
+ }
1176
+ },
1177
+ // ─── End Users (Admin) ───────────────────────────────────────────
1178
+ endUsers: {
1179
+ list(params) {
1180
+ return c.paginated("/end-users", params);
1181
+ },
1182
+ get(id) {
1183
+ return c.get(`/end-users/${id}`);
1184
+ },
1185
+ create(data) {
1186
+ return c.post("/end-users", data);
1187
+ },
1188
+ bulkUpsert(data) {
1189
+ return c.post("/end-users/bulk", data);
1190
+ },
1191
+ update(id, data) {
1192
+ return c.patch(`/end-users/${id}`, data);
1193
+ },
1194
+ remove(id) {
1195
+ return c.del(`/end-users/${id}`);
1196
+ },
1197
+ block(id) {
1198
+ return c.post(`/end-users/${id}/block`);
1199
+ },
1200
+ unblock(id) {
1201
+ return c.post(`/end-users/${id}/unblock`);
1202
+ },
1203
+ updateAttributes(id, data) {
1204
+ return c.patch(`/end-users/${id}/attributes`, data);
1205
+ },
1206
+ addTags(id, data) {
1207
+ return c.post(`/end-users/${id}/tags`, data);
1208
+ },
1209
+ removeTags(id, data) {
1210
+ return c.del(`/end-users/${id}/tags`);
1211
+ }
1212
+ },
1213
+ // ─── Audit ───────────────────────────────────────────────────────
1214
+ audit: {
1215
+ list(params) {
1216
+ return c.paginated("/audit", params);
1217
+ }
1218
+ },
1219
+ // ─── API Keys ────────────────────────────────────────────────────
1220
+ apiKeys: {
1221
+ list() {
1222
+ return c.get("/api-keys");
1223
+ },
1224
+ get(id) {
1225
+ return c.get(`/api-keys/${id}`);
1226
+ },
1227
+ create(data) {
1228
+ return c.post("/api-keys", data);
1229
+ },
1230
+ update(id, data) {
1231
+ return c.patch(`/api-keys/${id}`, data);
1232
+ },
1233
+ remove(id) {
1234
+ return c.del(`/api-keys/${id}`);
1235
+ },
1236
+ rotate(id) {
1237
+ return c.post(`/api-keys/${id}/rotate`);
1238
+ }
1239
+ },
1240
+ // ─── Settings ────────────────────────────────────────────────────
1241
+ settings: {
1242
+ getAll() {
1243
+ return c.get("/settings");
1244
+ },
1245
+ getGroup(group) {
1246
+ return c.get(`/settings/${group}`);
1247
+ },
1248
+ set(group, key, data) {
1249
+ return c.put(`/settings/${group}/${key}`, data);
1250
+ },
1251
+ bulkUpdate(data) {
1252
+ return c.put("/settings", data);
1253
+ },
1254
+ remove(group, key) {
1255
+ return c.del(`/settings/${group}/${key}`);
1256
+ }
1257
+ },
1258
+ // ─── Billing ─────────────────────────────────────────────────────
1259
+ billing: {
1260
+ currentPlan() {
1261
+ return c.get("/billing/plan");
1262
+ },
1263
+ plans() {
1264
+ return c.get("/billing/plans");
1265
+ },
1266
+ subscribe(data) {
1267
+ return c.post("/billing/subscribe", data);
1268
+ },
1269
+ cancel() {
1270
+ return c.post("/billing/cancel");
1271
+ },
1272
+ invoices(params) {
1273
+ return c.paginated("/billing/invoices", params);
1274
+ },
1275
+ invoice(id) {
1276
+ return c.get(`/billing/invoices/${id}`);
1277
+ },
1278
+ usage() {
1279
+ return c.get("/billing/usage");
1280
+ }
1281
+ },
1282
+ // ─── Usage ───────────────────────────────────────────────────────
1283
+ usage: {
1284
+ current() {
1285
+ return c.get("/usage");
1286
+ },
1287
+ history(params) {
1288
+ return c.paginated("/usage/history", params);
1289
+ },
1290
+ breakdown(params) {
1291
+ return c.paginated("/usage/breakdown", params);
1292
+ }
1293
+ },
1294
+ // ─── Contact Messages ────────────────────────────────────────────
1295
+ contactMessages: {
1296
+ list(params) {
1297
+ return c.paginated("/contact-messages", params);
1298
+ },
1299
+ get(id) {
1300
+ return c.get(`/contact-messages/${id}`);
1301
+ },
1302
+ markRead(id) {
1303
+ return c.patch(`/contact-messages/${id}/read`);
1304
+ },
1305
+ markUnread(id) {
1306
+ return c.patch(`/contact-messages/${id}/unread`);
1307
+ },
1308
+ remove(id) {
1309
+ return c.del(`/contact-messages/${id}`);
1310
+ }
1311
+ },
1312
+ // ─── Notifications ───────────────────────────────────────────────
1313
+ notifications: {
1314
+ list(params) {
1315
+ return c.paginated("/notifications", params);
1316
+ },
1317
+ send(data) {
1318
+ return c.post("/notifications/send", data);
1319
+ },
1320
+ sendBulk(data) {
1321
+ return c.post("/notifications/send-bulk", data);
1322
+ },
1323
+ inApp(params) {
1324
+ return c.paginated("/notifications/in-app", params);
1325
+ },
1326
+ unreadCount() {
1327
+ return c.get("/notifications/unread-count");
1328
+ },
1329
+ get(id) {
1330
+ return c.get(`/notifications/${id}`);
1331
+ },
1332
+ resend(id) {
1333
+ return c.post(`/notifications/${id}/resend`);
1334
+ },
1335
+ markRead(id) {
1336
+ return c.patch(`/notifications/${id}/read`);
1337
+ },
1338
+ markAllRead() {
1339
+ return c.post("/notifications/read-all");
1340
+ }
1341
+ },
1342
+ // ─── Templates ───────────────────────────────────────────────────
1343
+ templates: {
1344
+ list(params) {
1345
+ return c.paginated("/templates", params);
1346
+ },
1347
+ get(id) {
1348
+ return c.get(`/templates/${id}`);
1349
+ },
1350
+ create(data) {
1351
+ return c.post("/templates", data);
1352
+ },
1353
+ update(id, data) {
1354
+ return c.patch(`/templates/${id}`, data);
1355
+ },
1356
+ remove(id) {
1357
+ return c.del(`/templates/${id}`);
1358
+ },
1359
+ preview(id, data) {
1360
+ return c.post(`/templates/${id}/preview`, data);
1361
+ }
1362
+ },
1363
+ // ─── Segments ────────────────────────────────────────────────────
1364
+ segments: {
1365
+ list(params) {
1366
+ return c.paginated("/segments", params);
1367
+ },
1368
+ get(id) {
1369
+ return c.get(`/segments/${id}`);
1370
+ },
1371
+ create(data) {
1372
+ return c.post("/segments", data);
1373
+ },
1374
+ update(id, data) {
1375
+ return c.patch(`/segments/${id}`, data);
1376
+ },
1377
+ remove(id) {
1378
+ return c.del(`/segments/${id}`);
1379
+ },
1380
+ preview(id) {
1381
+ return c.post(`/segments/${id}/preview`);
1382
+ },
1383
+ members(id, params) {
1384
+ return c.paginated(`/segments/${id}/members`, params);
1385
+ },
1386
+ addMembers(id, data) {
1387
+ return c.post(`/segments/${id}/members`, data);
1388
+ },
1389
+ removeMember(segmentId, userId) {
1390
+ return c.del(`/segments/${segmentId}/members/${userId}`);
1391
+ }
1392
+ },
1393
+ // ─── Campaigns ───────────────────────────────────────────────────
1394
+ campaigns: {
1395
+ list(params) {
1396
+ return c.paginated("/campaigns", params);
1397
+ },
1398
+ get(id) {
1399
+ return c.get(`/campaigns/${id}`);
1400
+ },
1401
+ create(data) {
1402
+ return c.post("/campaigns", data);
1403
+ },
1404
+ update(id, data) {
1405
+ return c.patch(`/campaigns/${id}`, data);
1406
+ },
1407
+ remove(id) {
1408
+ return c.del(`/campaigns/${id}`);
1409
+ },
1410
+ launch(id) {
1411
+ return c.post(`/campaigns/${id}/launch`);
1412
+ },
1413
+ schedule(id, data) {
1414
+ return c.post(`/campaigns/${id}/schedule`, data);
1415
+ },
1416
+ pause(id) {
1417
+ return c.post(`/campaigns/${id}/pause`);
1418
+ },
1419
+ resume(id) {
1420
+ return c.post(`/campaigns/${id}/resume`);
1421
+ },
1422
+ cancel(id) {
1423
+ return c.post(`/campaigns/${id}/cancel`);
1424
+ },
1425
+ logs(id, params) {
1426
+ return c.paginated(`/campaigns/${id}/logs`, params);
1427
+ },
1428
+ analytics(id) {
1429
+ return c.get(`/campaigns/${id}/analytics`);
1430
+ }
1431
+ },
1432
+ // ─── Webhooks ────────────────────────────────────────────────────
1433
+ webhooks: {
1434
+ list() {
1435
+ return c.get("/webhooks");
1436
+ },
1437
+ get(id) {
1438
+ return c.get(`/webhooks/${id}`);
1439
+ },
1440
+ create(data) {
1441
+ return c.post("/webhooks", data);
1442
+ },
1443
+ update(id, data) {
1444
+ return c.patch(`/webhooks/${id}`, data);
1445
+ },
1446
+ remove(id) {
1447
+ return c.del(`/webhooks/${id}`);
1448
+ },
1449
+ test(id) {
1450
+ return c.post(`/webhooks/${id}/test`);
1451
+ },
1452
+ logs(id, params) {
1453
+ return c.paginated(`/webhooks/${id}/logs`, params);
1454
+ },
1455
+ retryLog(webhookId, logId) {
1456
+ return c.post(`/webhooks/${webhookId}/retry/${logId}`);
1457
+ }
1458
+ },
1459
+ // ─── Loyalty (Admin) ─────────────────────────────────────────────
1460
+ loyalty: {
1461
+ accounts(params) {
1462
+ return c.paginated("/loyalty/accounts", params);
1463
+ },
1464
+ getAccount(id) {
1465
+ return c.get(`/loyalty/accounts/${id}`);
1466
+ },
1467
+ adjustPoints(id, data) {
1468
+ return c.post(`/loyalty/accounts/${id}/adjust`, data);
1469
+ },
1470
+ rewards() {
1471
+ return c.get("/loyalty/rewards");
1472
+ },
1473
+ getReward(id) {
1474
+ return c.get(`/loyalty/rewards/${id}`);
1475
+ },
1476
+ createReward(data) {
1477
+ return c.post("/loyalty/rewards", data);
1478
+ },
1479
+ updateReward(id, data) {
1480
+ return c.patch(`/loyalty/rewards/${id}`, data);
1481
+ },
1482
+ removeReward(id) {
1483
+ return c.del(`/loyalty/rewards/${id}`);
1484
+ }
1485
+ },
1486
+ // ─── Coupons (Admin) ─────────────────────────────────────────────
1487
+ coupons: {
1488
+ list(params) {
1489
+ return c.paginated("/coupons", params);
1490
+ },
1491
+ get(id) {
1492
+ return c.get(`/coupons/${id}`);
1493
+ },
1494
+ create(data) {
1495
+ return c.post("/coupons", data);
1496
+ },
1497
+ update(id, data) {
1498
+ return c.patch(`/coupons/${id}`, data);
1499
+ },
1500
+ remove(id) {
1501
+ return c.del(`/coupons/${id}`);
1502
+ }
1503
+ },
1504
+ // ─── Promotions (Admin) ──────────────────────────────────────────
1505
+ promotions: {
1506
+ list(params) {
1507
+ return c.paginated("/promotions", params);
1508
+ },
1509
+ get(id) {
1510
+ return c.get(`/promotions/${id}`);
1511
+ },
1512
+ create(data) {
1513
+ return c.post("/promotions", data);
1514
+ },
1515
+ update(id, data) {
1516
+ return c.patch(`/promotions/${id}`, data);
1517
+ },
1518
+ remove(id) {
1519
+ return c.del(`/promotions/${id}`);
1520
+ }
1521
+ },
1522
+ // ─── Reviews (Admin) ─────────────────────────────────────────────
1523
+ reviews: {
1524
+ list(params) {
1525
+ return c.paginated("/reviews", params);
1526
+ },
1527
+ updateStatus(id, data) {
1528
+ return c.patch(`/reviews/${id}/status`, data);
1529
+ }
1530
+ },
1531
+ // ─── Gift Cards (Admin) ──────────────────────────────────────────
1532
+ giftCards: {
1533
+ list(params) {
1534
+ return c.paginated("/gift-cards", params);
1535
+ },
1536
+ get(id) {
1537
+ return c.get(`/gift-cards/${id}`);
1538
+ },
1539
+ create(data) {
1540
+ return c.post("/gift-cards", data);
1541
+ }
1542
+ },
1543
+ // ─── Reservations (Admin) ────────────────────────────────────────
1544
+ reservations: {
1545
+ list(params) {
1546
+ return c.paginated("/reservations", params);
1547
+ },
1548
+ updateStatus(id, data) {
1549
+ return c.patch(`/reservations/${id}/status`, data);
1550
+ },
1551
+ resources() {
1552
+ return c.get("/reservations/resources");
1553
+ },
1554
+ createResource(data) {
1555
+ return c.post("/reservations/resources", data);
1556
+ },
1557
+ updateResource(id, data) {
1558
+ return c.patch(`/reservations/resources/${id}`, data);
1559
+ },
1560
+ removeResource(id) {
1561
+ return c.del(`/reservations/resources/${id}`);
1562
+ }
1563
+ },
1564
+ // ─── Support (Admin) ─────────────────────────────────────────────
1565
+ support: {
1566
+ list(params) {
1567
+ return c.paginated("/support", params);
1568
+ },
1569
+ get(id) {
1570
+ return c.get(`/support/${id}`);
1571
+ },
1572
+ update(id, data) {
1573
+ return c.patch(`/support/${id}`, data);
1574
+ }
1575
+ },
1576
+ // ─── Content (Admin) ─────────────────────────────────────────────
1577
+ content: {
1578
+ list(params) {
1579
+ return c.paginated("/content", params);
1580
+ },
1581
+ get(id) {
1582
+ return c.get(`/content/${id}`);
1583
+ },
1584
+ create(data) {
1585
+ return c.post("/content", data);
1586
+ },
1587
+ update(id, data) {
1588
+ return c.patch(`/content/${id}`, data);
1589
+ },
1590
+ remove(id) {
1591
+ return c.del(`/content/${id}`);
1592
+ }
1593
+ },
1594
+ // ─── Payments (Admin) ────────────────────────────────────────────
1595
+ payments: {
1596
+ list(params) {
1597
+ return c.paginated("/payments", params);
1598
+ },
1599
+ get(id) {
1600
+ return c.get(`/payments/${id}`);
1601
+ },
1602
+ createOrder(data) {
1603
+ return c.post("/payments/orders", data);
1604
+ },
1605
+ verifyOrder(orderId, data) {
1606
+ return c.post(`/payments/orders/${orderId}/verify`, data);
1607
+ },
1608
+ listOrders(params) {
1609
+ return c.paginated("/payments/orders", params);
1610
+ },
1611
+ getOrder(id) {
1612
+ return c.get(`/payments/orders/${id}`);
1613
+ },
1614
+ createRefund(paymentId, data) {
1615
+ return c.post(`/payments/${paymentId}/refunds`, data);
1616
+ },
1617
+ listRefunds(paymentId) {
1618
+ return c.get(`/payments/${paymentId}/refunds`);
1619
+ },
1620
+ createSubscription(data) {
1621
+ return c.post("/payments/subscriptions", data);
1622
+ },
1623
+ listSubscriptions(params) {
1624
+ return c.paginated("/payments/subscriptions", params);
1625
+ },
1626
+ getSubscription(id) {
1627
+ return c.get(`/payments/subscriptions/${id}`);
1628
+ },
1629
+ pauseSubscription(id) {
1630
+ return c.post(`/payments/subscriptions/${id}/pause`);
1631
+ },
1632
+ resumeSubscription(id) {
1633
+ return c.post(`/payments/subscriptions/${id}/resume`);
1634
+ },
1635
+ cancelSubscription(id) {
1636
+ return c.post(`/payments/subscriptions/${id}/cancel`);
1637
+ },
1638
+ createLink(data) {
1639
+ return c.post("/payments/links", data);
1640
+ },
1641
+ listLinks(params) {
1642
+ return c.paginated("/payments/links", params);
1643
+ },
1644
+ getLink(id) {
1645
+ return c.get(`/payments/links/${id}`);
1646
+ },
1647
+ deactivateLink(id) {
1648
+ return c.post(`/payments/links/${id}/deactivate`);
1649
+ },
1650
+ removeLink(id) {
1651
+ return c.del(`/payments/links/${id}`);
1652
+ },
1653
+ createProduct(data) {
1654
+ return c.post("/payments/products", data);
1655
+ },
1656
+ listProducts(params) {
1657
+ return c.paginated("/payments/products", params);
1658
+ },
1659
+ getProduct(id) {
1660
+ return c.get(`/payments/products/${id}`);
1661
+ },
1662
+ updateProduct(id, data) {
1663
+ return c.patch(`/payments/products/${id}`, data);
1664
+ },
1665
+ removeProduct(id) {
1666
+ return c.del(`/payments/products/${id}`);
1667
+ }
1668
+ },
1669
+ // ─── Property (Admin) ────────────────────────────────────────────
1670
+ property: {
1671
+ getTypes() {
1672
+ return c.get("/property/types");
1673
+ },
1674
+ getType(id) {
1675
+ return c.get(`/property/types/${id}`);
1676
+ },
1677
+ createType(data) {
1678
+ return c.post("/property/types", data);
1679
+ },
1680
+ updateType(id, data) {
1681
+ return c.patch(`/property/types/${id}`, data);
1682
+ },
1683
+ removeType(id) {
1684
+ return c.del(`/property/types/${id}`);
1685
+ },
1686
+ setAmenities(typeId, data) {
1687
+ return c.put(`/property/types/${typeId}/amenities`, data);
1688
+ },
1689
+ getUnits() {
1690
+ return c.get("/property/units");
1691
+ },
1692
+ createUnit(data) {
1693
+ return c.post("/property/units", data);
1694
+ },
1695
+ updateUnit(id, data) {
1696
+ return c.patch(`/property/units/${id}`, data);
1697
+ },
1698
+ updateHousekeeping(id, data) {
1699
+ return c.patch(`/property/units/${id}/housekeeping`, data);
1700
+ },
1701
+ getAmenities() {
1702
+ return c.get("/property/amenities");
1703
+ },
1704
+ createAmenity(data) {
1705
+ return c.post("/property/amenities", data);
1706
+ },
1707
+ listBookings(params) {
1708
+ return c.paginated("/property/bookings", params);
1709
+ },
1710
+ getBooking(id) {
1711
+ return c.get(`/property/bookings/${id}`);
1712
+ },
1713
+ updateBooking(id, data) {
1714
+ return c.patch(`/property/bookings/${id}`, data);
1715
+ },
1716
+ checkIn(id) {
1717
+ return c.post(`/property/bookings/${id}/check-in`);
1718
+ },
1719
+ checkOut(id) {
1720
+ return c.post(`/property/bookings/${id}/check-out`);
1721
+ },
1722
+ cancelBooking(id, data) {
1723
+ return c.post(`/property/bookings/${id}/cancel`, data);
1724
+ },
1725
+ assignUnits(id, data) {
1726
+ return c.post(`/property/bookings/${id}/assign-units`, data);
1727
+ },
1728
+ availability(params) {
1729
+ return c.get(`/property/inventory/availability${toQsInline(params)}`);
1730
+ },
1731
+ calendar(params) {
1732
+ return c.get(`/property/inventory/calendar${toQsInline(params)}`);
1733
+ },
1734
+ blockDates(data) {
1735
+ return c.post("/property/inventory/block", data);
1736
+ },
1737
+ createHold(data) {
1738
+ return c.post("/property/inventory/hold", data);
1739
+ },
1740
+ listPricingRules() {
1741
+ return c.get("/property/pricing");
1742
+ },
1743
+ createPricingRule(data) {
1744
+ return c.post("/property/pricing", data);
1745
+ },
1746
+ updatePricingRule(id, data) {
1747
+ return c.patch(`/property/pricing/${id}`, data);
1748
+ },
1749
+ removePricingRule(id) {
1750
+ return c.del(`/property/pricing/${id}`);
1751
+ },
1752
+ resolvePrice(data) {
1753
+ return c.post("/property/pricing/resolve", data);
1754
+ }
1755
+ },
1756
+ // ─── POS ─────────────────────────────────────────────────────────
1757
+ pos: {
1758
+ sync() {
1759
+ return c.post("/pos/sync");
1760
+ },
1761
+ logs(params) {
1762
+ return c.paginated("/pos/logs", params);
1763
+ }
1764
+ },
1765
+ // ─── Upload ──────────────────────────────────────────────────────
1766
+ upload(file, folder) {
1767
+ const formData = new FormData();
1768
+ formData.append("file", file);
1769
+ if (folder) formData.append("folder", folder);
1770
+ return c.upload("/upload", formData);
1771
+ }
1772
+ };
1773
+ }
1774
+ function toQsInline(params) {
1775
+ const entries = Object.entries(params).filter(([, v]) => v !== void 0 && v !== null).map(([k, v]) => [k, String(v)]);
1776
+ return entries.length ? "?" + new URLSearchParams(entries).toString() : "";
1777
+ }
1778
+
1779
+ // src/super-admin/index.ts
1780
+ function createSuperAdmin(root, c) {
1781
+ return {
1782
+ // ─── Auth ────────────────────────────────────────────────────────
1783
+ auth: {
1784
+ login(data) {
1785
+ return root.rawRequest("POST", "/admin/login", { body: data, scope: "public", sendOrgKey: false }).then((r) => {
1786
+ root.saveSuperAdminToken(r.data.accessToken);
1787
+ return r.data;
1788
+ });
1789
+ },
1790
+ getToken: () => root.getSuperAdminToken(),
1791
+ clearToken: () => root.clearSuperAdminToken()
1792
+ },
1793
+ // ─── Dashboard ───────────────────────────────────────────────────
1794
+ stats() {
1795
+ return c.get("/admin/stats");
1796
+ },
1797
+ // ─── Super Admins ────────────────────────────────────────────────
1798
+ admins: {
1799
+ list(params) {
1800
+ return c.paginated("/admin/super-admins", params);
1801
+ },
1802
+ create(data) {
1803
+ return c.post("/admin/super-admins", data);
1804
+ }
1805
+ },
1806
+ // ─── Organizations ───────────────────────────────────────────────
1807
+ orgs: {
1808
+ list(params) {
1809
+ return c.paginated("/admin/orgs", params);
1810
+ },
1811
+ get(id) {
1812
+ return c.get(`/admin/orgs/${id}`);
1813
+ },
1814
+ getBySlug(slug) {
1815
+ return c.get(`/admin/orgs/slug/${slug}`);
1816
+ },
1817
+ create(data) {
1818
+ return c.post("/admin/orgs", data);
1819
+ },
1820
+ update(id, data) {
1821
+ return c.patch(`/admin/orgs/${id}`, data);
1822
+ },
1823
+ remove(id) {
1824
+ return c.del(`/admin/orgs/${id}`);
1825
+ },
1826
+ suspend(id) {
1827
+ return c.post(`/admin/orgs/${id}/suspend`);
1828
+ },
1829
+ reinstate(id) {
1830
+ return c.post(`/admin/orgs/${id}/reinstate`);
1831
+ },
1832
+ regenerateKey(id) {
1833
+ return c.post(`/admin/orgs/${id}/regenerate-key`);
1834
+ },
1835
+ impersonate(id) {
1836
+ return c.post(`/admin/orgs/${id}/impersonate`);
1837
+ }
1838
+ },
1839
+ // ─── Org Config ──────────────────────────────────────────────────
1840
+ orgConfig: {
1841
+ get(orgId) {
1842
+ return c.get(`/admin/orgs/${orgId}/config`);
1843
+ },
1844
+ update(orgId, data) {
1845
+ return c.patch(`/admin/orgs/${orgId}/config`, data);
1846
+ },
1847
+ test(orgId, group) {
1848
+ return c.post(`/admin/orgs/${orgId}/config/test/${group}`);
1849
+ },
1850
+ reset(orgId, group) {
1851
+ return c.post(`/admin/orgs/${orgId}/config/reset/${group}`);
1852
+ }
1853
+ },
1854
+ // ─── Platform Config ─────────────────────────────────────────────
1855
+ platformConfig: {
1856
+ get() {
1857
+ return c.get("/admin/platform-config");
1858
+ },
1859
+ update(data) {
1860
+ return c.patch("/admin/platform-config", data);
1861
+ },
1862
+ test(group) {
1863
+ return c.post(`/admin/platform-config/test/${group}`);
1864
+ }
1865
+ },
1866
+ // ─── Plans ───────────────────────────────────────────────────────
1867
+ plans: {
1868
+ create(data) {
1869
+ return c.post("/admin/plans", data);
1870
+ },
1871
+ update(id, data) {
1872
+ return c.patch(`/admin/plans/${id}`, data);
1873
+ }
1874
+ },
1875
+ // ─── Invoices ────────────────────────────────────────────────────
1876
+ invoices: {
1877
+ list(params) {
1878
+ return c.paginated("/admin/invoices", params);
1879
+ },
1880
+ markPaid(id) {
1881
+ return c.patch(`/admin/invoices/${id}`);
1882
+ }
1883
+ },
1884
+ // ─── Usage ───────────────────────────────────────────────────────
1885
+ usage() {
1886
+ return c.get("/admin/usage");
1887
+ },
1888
+ // ─── Audit ───────────────────────────────────────────────────────
1889
+ audit(params) {
1890
+ return c.paginated("/admin/audit", params);
1891
+ },
1892
+ // ─── Movies (Super Admin) ────────────────────────────────────────
1893
+ movies: {
1894
+ create(data) {
1895
+ return c.post("/admin/movies", data);
1896
+ },
1897
+ listStreamMappings() {
1898
+ return c.get("/admin/movies/stream-mappings");
1899
+ },
1900
+ upsertStreamMapping(data) {
1901
+ return c.post("/admin/movies/stream-mappings", data);
1902
+ },
1903
+ removeStreamMapping(tmdbId) {
1904
+ return c.del(`/admin/movies/stream-mappings/${tmdbId}`);
1905
+ }
1906
+ }
1907
+ };
1908
+ }
1909
+
1910
+ // src/index.ts
1911
+ var PROD_URL = "https://api.techzunction.com";
1912
+ var DEV_URL = "https://dev-api.techzunction.com";
1913
+ function resolveBaseUrl(env, customUrl) {
1914
+ if (env === "production") return PROD_URL;
1915
+ return DEV_URL;
1916
+ }
1917
+ function readEnv(key) {
1918
+ if (typeof process !== "undefined" && process.env) {
1919
+ return process.env[key] ?? process.env[`NEXT_PUBLIC_${key}`] ?? process.env[`VITE_${key}`] ?? process.env[`EXPO_PUBLIC_${key}`];
1920
+ }
1921
+ if (typeof import.meta !== "undefined" && import.meta.env) {
1922
+ const env = import.meta.env;
1923
+ return env[key] ?? env[`VITE_${key}`];
1924
+ }
1925
+ return void 0;
1926
+ }
1927
+ function detectEnv() {
1928
+ const nodeEnv = readEnv("NODE_ENV");
1929
+ if (nodeEnv === "production") return "production";
1930
+ return "dev";
1931
+ }
1932
+ var _client = null;
1933
+ var _sf = null;
1934
+ var _admin = null;
1935
+ var _sa = null;
1936
+ var _storefront = null;
1937
+ var _adminNs = null;
1938
+ var _superAdmin = null;
1939
+ function ensureInit() {
1940
+ if (!_client) throw new Error("TZ.init() must be called before using the SDK.");
1941
+ }
1942
+ var TZ = {
1943
+ /**
1944
+ * Initialize the SDK. Call once at app startup.
1945
+ *
1946
+ * Auto-reads env vars:
1947
+ * TZ_ORG_ID / NEXT_PUBLIC_TZ_ORG_ID → orgSlug
1948
+ * TZ_ORG_KEY / NEXT_PUBLIC_TZ_ORG_KEY → orgKey (storefront publishable key)
1949
+ * TZ_API_URL / NEXT_PUBLIC_TZ_API_URL → custom backend URL
1950
+ * NODE_ENV → 'production' uses api.techzunction.com, else dev-api
1951
+ */
1952
+ init(options = {}) {
1953
+ const orgSlug = options.orgSlug ?? readEnv("TZ_ORG_ID") ?? "";
1954
+ const orgKey = options.orgKey ?? readEnv("TZ_ORG_KEY");
1955
+ const env = options.env ?? detectEnv();
1956
+ const baseUrl = options.baseUrl ?? readEnv("TZ_API_URL") ?? resolveBaseUrl(env);
1957
+ if (!orgSlug) {
1958
+ console.warn("[TZ SDK] No orgSlug provided and TZ_ORG_ID env var not found. Set it in .env or pass to TZ.init().");
1959
+ }
1960
+ const config = {
1961
+ baseUrl,
1962
+ orgSlug,
1963
+ orgKey,
1964
+ keyPrefix: options.keyPrefix ?? "tz",
1965
+ tokenStore: options.tokenStore,
1966
+ onAuthExpired: options.onAuthExpired
1967
+ };
1968
+ _client = new TZClient(config);
1969
+ _sf = _client.scoped("/storefront", "public", true);
1970
+ _admin = _client.scoped("", "staff", false);
1971
+ _sa = _client.scoped("", "superadmin", false);
1972
+ _storefront = null;
1973
+ _adminNs = null;
1974
+ _superAdmin = null;
1975
+ },
1976
+ /** The raw TZClient instance (for advanced use) */
1977
+ get client() {
1978
+ ensureInit();
1979
+ return _client;
1980
+ },
1981
+ /** Storefront namespace — all end-user-facing APIs */
1982
+ get storefront() {
1983
+ ensureInit();
1984
+ if (!_storefront) _storefront = createStorefront(_sf);
1985
+ return _storefront;
1986
+ },
1987
+ /** Admin namespace — all staff/org-admin APIs */
1988
+ get admin() {
1989
+ ensureInit();
1990
+ if (!_adminNs) _adminNs = createAdmin(_client, _admin);
1991
+ return _adminNs;
1992
+ },
1993
+ /** Super Admin namespace — platform-wide management APIs */
1994
+ get superAdmin() {
1995
+ ensureInit();
1996
+ if (!_superAdmin) _superAdmin = createSuperAdmin(_client, _sa);
1997
+ return _superAdmin;
1998
+ },
1999
+ /** GET /health — Basic health check (PUBLIC) */
2000
+ health() {
2001
+ ensureInit();
2002
+ return _admin.get("/health", "public");
2003
+ },
2004
+ /** GET /health/detailed — Detailed health check with dependency status (USER) */
2005
+ healthDetailed() {
2006
+ ensureInit();
2007
+ return _admin.get("/health/detailed");
2008
+ }
2009
+ };
2010
+ function createTZ(options = {}) {
2011
+ const orgSlug = options.orgSlug ?? readEnv("TZ_ORG_ID") ?? "";
2012
+ const orgKey = options.orgKey ?? readEnv("TZ_ORG_KEY");
2013
+ const env = options.env ?? detectEnv();
2014
+ const baseUrl = options.baseUrl ?? readEnv("TZ_API_URL") ?? resolveBaseUrl(env);
2015
+ const client = new TZClient({
2016
+ baseUrl,
2017
+ orgSlug,
2018
+ orgKey,
2019
+ keyPrefix: options.keyPrefix ?? "tz",
2020
+ tokenStore: options.tokenStore,
2021
+ onAuthExpired: options.onAuthExpired
2022
+ });
2023
+ const sf = client.scoped("/storefront", "public", true);
2024
+ const admin = client.scoped("", "staff", false);
2025
+ const sa = client.scoped("", "superadmin", false);
2026
+ return {
2027
+ client,
2028
+ storefront: createStorefront(sf),
2029
+ admin: createAdmin(client, admin),
2030
+ superAdmin: createSuperAdmin(client, sa),
2031
+ health: () => admin.get("/health", "public"),
2032
+ healthDetailed: () => admin.get("/health/detailed")
2033
+ };
2034
+ }
2035
+
2036
+ export { ScopedClient, TZ, TZClient, TZPaginatedQuery, TZQuery, createTZ };
2037
+ //# sourceMappingURL=index.js.map
2038
+ //# sourceMappingURL=index.js.map