@joai/sdk 14.0.0 → 14.0.2
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.d.mts +6 -1
- package/dist/index.mjs +25 -5
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -299,7 +299,10 @@ declare function createGuestCommerceStorage(options: GuestCommerceStorageOptions
|
|
|
299
299
|
accessToken
|
|
300
300
|
}: GuestOrderAccess): void;
|
|
301
301
|
readOrderAccess(orderId: string): string | null;
|
|
302
|
-
listOrderAccess(): GuestOrderAccess[]; /**
|
|
302
|
+
listOrderAccess(): GuestOrderAccess[]; /** Remember the order being paid so a gateway return without `?order=` can reopen it. */
|
|
303
|
+
savePendingOrderReturn(orderId: string): void;
|
|
304
|
+
readPendingOrderReturn(): string | null;
|
|
305
|
+
clearPendingOrderReturn(): void; /** Absolute shop URL from a path or full URL (e.g. orders page). */
|
|
303
306
|
shopUrl(ordersPage: string): string; /** Thank-you → shop handoff URL with capability token query params. */
|
|
304
307
|
orderReturnUrl(ordersPage: string, orderId: string, accessToken: string): string; /** Persist `order` + `orderAccessToken` from the shop handoff query, then strip the token. */
|
|
305
308
|
claimOrderReturn(): GuestOrderAccess | null;
|
|
@@ -821,6 +824,8 @@ declare class BillingResource {
|
|
|
821
824
|
orders(team: TeamPrivate | null, page?: number, filters?: {
|
|
822
825
|
contactId?: string;
|
|
823
826
|
couponId?: string;
|
|
827
|
+
search?: string;
|
|
828
|
+
status?: OrderStatus$1[];
|
|
824
829
|
}, perPage?: number): Promise<_$_joai_core0.IAppResponse<Order$1[]>>;
|
|
825
830
|
orderStats(team: string): Promise<_$_joai_core0.IAppResponse<TeamOrderStats>>;
|
|
826
831
|
payOrder(id: string, provider?: PaymentProvider, accessToken?: string): Promise<_$_joai_core0.IAppResponse<{
|
package/dist/index.mjs
CHANGED
|
@@ -286,6 +286,7 @@ const orderAccessPrefix = "joai:order-access:";
|
|
|
286
286
|
const checkoutKey = (namespace) => `joai:guest-checkout:${namespace}`;
|
|
287
287
|
const ordersKey = (namespace) => `joai:guest-orders:${namespace}`;
|
|
288
288
|
const orderAccessKey = (namespace, orderId) => `${orderAccessPrefix}${namespace}:${orderId}`;
|
|
289
|
+
const pendingOrderReturnKey = (namespace) => `joai:guest-pending-order-return:${namespace}`;
|
|
289
290
|
const safeGet$1 = (key) => {
|
|
290
291
|
if (typeof localStorage === "undefined") return null;
|
|
291
292
|
try {
|
|
@@ -397,6 +398,16 @@ function createGuestCommerceStorage(options) {
|
|
|
397
398
|
accessToken: entry.accessToken || safeGet$1(orderAccessKey(options.namespace, entry.orderId))
|
|
398
399
|
}));
|
|
399
400
|
},
|
|
401
|
+
/** Remember the order being paid so a gateway return without `?order=` can reopen it. */
|
|
402
|
+
savePendingOrderReturn(orderId) {
|
|
403
|
+
safeSet$1(pendingOrderReturnKey(options.namespace), orderId);
|
|
404
|
+
},
|
|
405
|
+
readPendingOrderReturn() {
|
|
406
|
+
return safeGet$1(pendingOrderReturnKey(options.namespace));
|
|
407
|
+
},
|
|
408
|
+
clearPendingOrderReturn() {
|
|
409
|
+
safeRemove$1(pendingOrderReturnKey(options.namespace));
|
|
410
|
+
},
|
|
400
411
|
/** Absolute shop URL from a path or full URL (e.g. orders page). */
|
|
401
412
|
shopUrl(ordersPage) {
|
|
402
413
|
return absoluteOrdersPageUrl(ordersPage);
|
|
@@ -1163,6 +1174,8 @@ var BillingResource = class {
|
|
|
1163
1174
|
let params = `orders?page=${page}&perPage=${perPage}`;
|
|
1164
1175
|
if (filters.contactId) params += `&contactId=${encodeURIComponent(filters.contactId)}`;
|
|
1165
1176
|
if (filters.couponId) params += `&couponId=${encodeURIComponent(filters.couponId)}`;
|
|
1177
|
+
if (filters.search) params += `&search=${encodeURIComponent(filters.search)}`;
|
|
1178
|
+
if (filters.status?.length) params += `&status=${encodeURIComponent(filters.status.join(","))}`;
|
|
1166
1179
|
return this.http.get(params, team ? { headers: { "X-Team": team.slug } } : void 0);
|
|
1167
1180
|
}
|
|
1168
1181
|
orderStats(team) {
|
|
@@ -3719,14 +3732,15 @@ const RELATED_PREFIXES = {
|
|
|
3719
3732
|
returns: ["orders"],
|
|
3720
3733
|
orders: ["returns"]
|
|
3721
3734
|
};
|
|
3735
|
+
const prefixVersions = /* @__PURE__ */ new Map();
|
|
3722
3736
|
function getTtl(url, ttlMap, defaultTtl) {
|
|
3723
3737
|
for (const [prefix, ttl] of Object.entries(ttlMap)) if (url.startsWith(prefix) || url.startsWith(`/${prefix}`)) return ttl;
|
|
3724
3738
|
return defaultTtl;
|
|
3725
3739
|
}
|
|
3726
3740
|
function getUrlPrefix(url) {
|
|
3727
3741
|
const clean = url.startsWith("/") ? url.slice(1) : url;
|
|
3728
|
-
const
|
|
3729
|
-
return
|
|
3742
|
+
const end = clean.search(/[/?]/);
|
|
3743
|
+
return end > 0 ? clean.slice(0, end) : clean;
|
|
3730
3744
|
}
|
|
3731
3745
|
var CachedHttpService = class {
|
|
3732
3746
|
constructor(inner, overrides, defaultTtl) {
|
|
@@ -3776,11 +3790,13 @@ var CachedHttpService = class {
|
|
|
3776
3790
|
this.cache.clear();
|
|
3777
3791
|
}
|
|
3778
3792
|
async get(url, options) {
|
|
3779
|
-
const
|
|
3793
|
+
const key = `${url}#${prefixVersions.get(getUrlPrefix(url)) ?? 0}`;
|
|
3794
|
+
const cached = this.cache.get(key);
|
|
3780
3795
|
if (cached !== void 0) return cached;
|
|
3796
|
+
this.cache.bust(`${url}#`);
|
|
3781
3797
|
const cacheVersion = this.cacheVersion;
|
|
3782
3798
|
const response = await this.inner.get(url, options);
|
|
3783
|
-
if (response.ok && cacheVersion === this.cacheVersion) this.cache.set(
|
|
3799
|
+
if (response.ok && cacheVersion === this.cacheVersion) this.cache.set(key, response, getTtl(url, this.ttlMap, this.defaultTtl));
|
|
3784
3800
|
return response;
|
|
3785
3801
|
}
|
|
3786
3802
|
async post(url, data, options) {
|
|
@@ -3809,7 +3825,11 @@ var CachedHttpService = class {
|
|
|
3809
3825
|
bust(prefix) {
|
|
3810
3826
|
this.cacheVersion++;
|
|
3811
3827
|
this.cache.bust(prefix);
|
|
3812
|
-
|
|
3828
|
+
prefixVersions.set(prefix, (prefixVersions.get(prefix) ?? 0) + 1);
|
|
3829
|
+
for (const relatedPrefix of RELATED_PREFIXES[prefix] ?? []) {
|
|
3830
|
+
this.cache.bust(relatedPrefix);
|
|
3831
|
+
prefixVersions.set(relatedPrefix, (prefixVersions.get(relatedPrefix) ?? 0) + 1);
|
|
3832
|
+
}
|
|
3813
3833
|
}
|
|
3814
3834
|
};
|
|
3815
3835
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joai/sdk",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.2",
|
|
4
4
|
"description": "JoAi public API SDK — build with your AI agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"test": "jest --config jest.config.js"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@joai/core": "^5.4.
|
|
38
|
+
"@joai/core": "^5.4.7",
|
|
39
39
|
"@joai/warps": "*"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@joai/core": "^5.4.
|
|
42
|
+
"@joai/core": "^5.4.7"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsdown": "^0.21.0",
|