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