@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.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// src/query.ts
|
|
2
2
|
var TZQuery = class _TZQuery {
|
|
3
|
+
controller;
|
|
4
|
+
_promise;
|
|
5
|
+
_executor;
|
|
3
6
|
constructor(executor) {
|
|
4
7
|
this._executor = executor;
|
|
5
8
|
this.controller = new AbortController();
|
|
@@ -39,6 +42,9 @@ var TZQuery = class _TZQuery {
|
|
|
39
42
|
}
|
|
40
43
|
};
|
|
41
44
|
var TZPaginatedQuery = class extends TZQuery {
|
|
45
|
+
_page;
|
|
46
|
+
_limit;
|
|
47
|
+
_pageFactory;
|
|
42
48
|
constructor(executor, page, limit, pageFactory) {
|
|
43
49
|
super(executor);
|
|
44
50
|
this._page = page;
|
|
@@ -68,7 +74,7 @@ var TZPaginatedQuery = class extends TZQuery {
|
|
|
68
74
|
/** Check if there's a next page (must await first) */
|
|
69
75
|
async hasNext() {
|
|
70
76
|
const result = await this.data();
|
|
71
|
-
return
|
|
77
|
+
return result.pagination.hasNextPage;
|
|
72
78
|
}
|
|
73
79
|
/** Check if there's a previous page */
|
|
74
80
|
hasPrev() {
|
|
@@ -113,9 +119,15 @@ function toQs(params) {
|
|
|
113
119
|
return entries.length ? "?" + new URLSearchParams(entries).toString() : "";
|
|
114
120
|
}
|
|
115
121
|
var TZClient = class {
|
|
122
|
+
baseUrl;
|
|
123
|
+
orgSlug;
|
|
124
|
+
orgKey;
|
|
125
|
+
store;
|
|
126
|
+
keys;
|
|
127
|
+
onAuthExpired;
|
|
128
|
+
enduserRefreshPromise = null;
|
|
129
|
+
staffRefreshPromise = null;
|
|
116
130
|
constructor(config) {
|
|
117
|
-
this.enduserRefreshPromise = null;
|
|
118
|
-
this.staffRefreshPromise = null;
|
|
119
131
|
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
120
132
|
this.orgSlug = config.orgSlug;
|
|
121
133
|
this.orgKey = config.orgKey;
|
|
@@ -370,12 +382,18 @@ var ScopedClient = class {
|
|
|
370
382
|
const merged = { ...params, page: p, limit: l };
|
|
371
383
|
const qs = toQs(merged);
|
|
372
384
|
const fp = this.fullPath(`${path}${qs}`);
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
l,
|
|
377
|
-
|
|
378
|
-
|
|
385
|
+
const executor = async (signal) => {
|
|
386
|
+
const rawRes = await this.root.rawRequest("GET", fp, { scope, signal, sendOrgKey: this.sendOrgKey });
|
|
387
|
+
const envelope = rawRes.raw;
|
|
388
|
+
const pagination = envelope["pagination"] ?? { page: p, limit: l, total: 0, totalPages: 0, hasNextPage: false, hasPrevPage: false };
|
|
389
|
+
return {
|
|
390
|
+
data: { data: rawRes.data, pagination },
|
|
391
|
+
raw: rawRes.raw,
|
|
392
|
+
status: rawRes.status,
|
|
393
|
+
headers: rawRes.headers
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
return new TZPaginatedQuery(executor, p, l, factory);
|
|
379
397
|
};
|
|
380
398
|
return factory(page, limit);
|
|
381
399
|
}
|
|
@@ -2447,10 +2465,10 @@ var TZ = {
|
|
|
2447
2465
|
const config = {
|
|
2448
2466
|
baseUrl,
|
|
2449
2467
|
orgSlug,
|
|
2450
|
-
orgKey,
|
|
2451
2468
|
keyPrefix: options.keyPrefix ?? "tz",
|
|
2452
|
-
|
|
2453
|
-
|
|
2469
|
+
...orgKey != null ? { orgKey } : {},
|
|
2470
|
+
...options.tokenStore != null ? { tokenStore: options.tokenStore } : {},
|
|
2471
|
+
...options.onAuthExpired != null ? { onAuthExpired: options.onAuthExpired } : {}
|
|
2454
2472
|
};
|
|
2455
2473
|
_client = new TZClient(config);
|
|
2456
2474
|
_sf = _client.scoped("/storefront", "public", true);
|
|
@@ -2502,10 +2520,10 @@ function createTZ(options = {}) {
|
|
|
2502
2520
|
const client = new TZClient({
|
|
2503
2521
|
baseUrl,
|
|
2504
2522
|
orgSlug,
|
|
2505
|
-
orgKey,
|
|
2506
2523
|
keyPrefix: options.keyPrefix ?? "tz",
|
|
2507
|
-
|
|
2508
|
-
|
|
2524
|
+
...orgKey != null ? { orgKey } : {},
|
|
2525
|
+
...options.tokenStore != null ? { tokenStore: options.tokenStore } : {},
|
|
2526
|
+
...options.onAuthExpired != null ? { onAuthExpired: options.onAuthExpired } : {}
|
|
2509
2527
|
});
|
|
2510
2528
|
const sf = client.scoped("/storefront", "public", true);
|
|
2511
2529
|
const admin = client.scoped("", "staff", false);
|