@techzunction/sdk 0.6.6 → 0.8.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 +33 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +340 -41
- package/dist/index.d.ts +340 -41
- package/dist/index.js +33 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
4
4
|
// src/query.ts
|
|
5
5
|
var TZQuery = class _TZQuery {
|
|
6
|
+
controller;
|
|
7
|
+
_promise;
|
|
8
|
+
_executor;
|
|
6
9
|
constructor(executor) {
|
|
7
10
|
this._executor = executor;
|
|
8
11
|
this.controller = new AbortController();
|
|
@@ -42,6 +45,9 @@ var TZQuery = class _TZQuery {
|
|
|
42
45
|
}
|
|
43
46
|
};
|
|
44
47
|
var TZPaginatedQuery = class extends TZQuery {
|
|
48
|
+
_page;
|
|
49
|
+
_limit;
|
|
50
|
+
_pageFactory;
|
|
45
51
|
constructor(executor, page, limit, pageFactory) {
|
|
46
52
|
super(executor);
|
|
47
53
|
this._page = page;
|
|
@@ -71,7 +77,7 @@ var TZPaginatedQuery = class extends TZQuery {
|
|
|
71
77
|
/** Check if there's a next page (must await first) */
|
|
72
78
|
async hasNext() {
|
|
73
79
|
const result = await this.data();
|
|
74
|
-
return
|
|
80
|
+
return result.pagination.hasNextPage;
|
|
75
81
|
}
|
|
76
82
|
/** Check if there's a previous page */
|
|
77
83
|
hasPrev() {
|
|
@@ -116,9 +122,15 @@ function toQs(params) {
|
|
|
116
122
|
return entries.length ? "?" + new URLSearchParams(entries).toString() : "";
|
|
117
123
|
}
|
|
118
124
|
var TZClient = class {
|
|
125
|
+
baseUrl;
|
|
126
|
+
orgSlug;
|
|
127
|
+
orgKey;
|
|
128
|
+
store;
|
|
129
|
+
keys;
|
|
130
|
+
onAuthExpired;
|
|
131
|
+
enduserRefreshPromise = null;
|
|
132
|
+
staffRefreshPromise = null;
|
|
119
133
|
constructor(config) {
|
|
120
|
-
this.enduserRefreshPromise = null;
|
|
121
|
-
this.staffRefreshPromise = null;
|
|
122
134
|
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
123
135
|
this.orgSlug = config.orgSlug;
|
|
124
136
|
this.orgKey = config.orgKey;
|
|
@@ -373,12 +385,18 @@ var ScopedClient = class {
|
|
|
373
385
|
const merged = { ...params, page: p, limit: l };
|
|
374
386
|
const qs = toQs(merged);
|
|
375
387
|
const fp = this.fullPath(`${path}${qs}`);
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
l,
|
|
380
|
-
|
|
381
|
-
|
|
388
|
+
const executor = async (signal) => {
|
|
389
|
+
const rawRes = await this.root.rawRequest("GET", fp, { scope, signal, sendOrgKey: this.sendOrgKey });
|
|
390
|
+
const envelope = rawRes.raw;
|
|
391
|
+
const pagination = envelope["pagination"] ?? { page: p, limit: l, total: 0, totalPages: 0, hasNextPage: false, hasPrevPage: false };
|
|
392
|
+
return {
|
|
393
|
+
data: { data: rawRes.data, pagination },
|
|
394
|
+
raw: rawRes.raw,
|
|
395
|
+
status: rawRes.status,
|
|
396
|
+
headers: rawRes.headers
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
return new TZPaginatedQuery(executor, p, l, factory);
|
|
382
400
|
};
|
|
383
401
|
return factory(page, limit);
|
|
384
402
|
}
|
|
@@ -2450,10 +2468,10 @@ var TZ = {
|
|
|
2450
2468
|
const config = {
|
|
2451
2469
|
baseUrl,
|
|
2452
2470
|
orgSlug,
|
|
2453
|
-
orgKey,
|
|
2454
2471
|
keyPrefix: options.keyPrefix ?? "tz",
|
|
2455
|
-
|
|
2456
|
-
|
|
2472
|
+
...orgKey != null ? { orgKey } : {},
|
|
2473
|
+
...options.tokenStore != null ? { tokenStore: options.tokenStore } : {},
|
|
2474
|
+
...options.onAuthExpired != null ? { onAuthExpired: options.onAuthExpired } : {}
|
|
2457
2475
|
};
|
|
2458
2476
|
_client = new TZClient(config);
|
|
2459
2477
|
_sf = _client.scoped("/storefront", "public", true);
|
|
@@ -2505,10 +2523,10 @@ function createTZ(options = {}) {
|
|
|
2505
2523
|
const client = new TZClient({
|
|
2506
2524
|
baseUrl,
|
|
2507
2525
|
orgSlug,
|
|
2508
|
-
orgKey,
|
|
2509
2526
|
keyPrefix: options.keyPrefix ?? "tz",
|
|
2510
|
-
|
|
2511
|
-
|
|
2527
|
+
...orgKey != null ? { orgKey } : {},
|
|
2528
|
+
...options.tokenStore != null ? { tokenStore: options.tokenStore } : {},
|
|
2529
|
+
...options.onAuthExpired != null ? { onAuthExpired: options.onAuthExpired } : {}
|
|
2512
2530
|
});
|
|
2513
2531
|
const sf = client.scoped("/storefront", "public", true);
|
|
2514
2532
|
const admin = client.scoped("", "staff", false);
|