@01.software/sdk 0.41.1 → 0.43.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/CHANGELOG.md +246 -0
- package/README.md +88 -19
- package/dist/analytics/react.cjs +71 -3
- package/dist/analytics/react.cjs.map +1 -1
- package/dist/analytics/react.d.cts +18 -2
- package/dist/analytics/react.d.ts +18 -2
- package/dist/analytics/react.js +67 -3
- package/dist/analytics/react.js.map +1 -1
- package/dist/analytics.cjs +6 -2
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.d.cts +17 -4
- package/dist/analytics.d.ts +17 -4
- package/dist/analytics.js +6 -2
- package/dist/analytics.js.map +1 -1
- package/dist/client.cjs +233 -47
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +9 -6
- package/dist/client.d.ts +9 -6
- package/dist/client.js +233 -47
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-Bk--pNzW.d.cts → collection-client-U70KizLf.d.cts} +3 -3
- package/dist/{collection-client-BdcxkW7l.d.ts → collection-client-gWsA7BVP.d.ts} +3 -3
- package/dist/{const-qGGI7Uii.d.cts → const-BBynifk0.d.cts} +5 -5
- package/dist/{const-HwdntWtG.d.ts → const-_WWHU-gX.d.ts} +5 -5
- package/dist/{index-B1oW50RY.d.ts → index-DPi5NWU8.d.ts} +4 -4
- package/dist/{index-DiXtjVab.d.cts → index-Dg4Y6Aq7.d.cts} +4 -4
- package/dist/index.cjs +225 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -8
- package/dist/index.d.ts +41 -8
- package/dist/index.js +225 -358
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-CqJOgON7.d.cts → payload-types-DLxkB7Mv.d.cts} +561 -123
- package/dist/{payload-types-CqJOgON7.d.ts → payload-types-DLxkB7Mv.d.ts} +561 -123
- package/dist/query.cjs +59 -7
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +5 -5
- package/dist/query.d.ts +5 -5
- package/dist/query.js +59 -7
- package/dist/query.js.map +1 -1
- package/dist/realtime.cjs +1 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/realtime.js +1 -1
- package/dist/realtime.js.map +1 -1
- package/dist/server.cjs +318 -61
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +12 -7
- package/dist/server.d.ts +12 -7
- package/dist/server.js +318 -61
- package/dist/server.js.map +1 -1
- package/dist/{types-ByLSG-O3.d.cts → types-B1ngKbWI.d.cts} +1 -1
- package/dist/{types-BKa9z9s2.d.cts → types-B9lGhZlB.d.ts} +229 -15
- package/dist/{types-BMI3M0nb.d.ts → types-BiKNBwRA.d.ts} +1 -1
- package/dist/{types-DgfXb7iV.d.ts → types-Bpx5sYKo.d.cts} +229 -15
- package/dist/ui/canvas.cjs.map +1 -1
- package/dist/ui/canvas.js.map +1 -1
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/webhook.cjs +3 -1
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +4 -4
- package/dist/webhook.d.ts +4 -4
- package/dist/webhook.js +3 -1
- package/dist/webhook.js.map +1 -1
- package/package.json +1 -1
package/dist/client.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { R as ReadOnlyCollectionClient } from './collection-client-
|
|
2
|
-
import { C as CommerceClient, a as CommunityClient, b as ContentClient, E as EventsClient, c as CustomerNamespace, d as
|
|
3
|
-
export { A as AddItemParams,
|
|
4
|
-
import './payload-types-
|
|
5
|
-
export { C as Collection, P as PublicCollection } from './const-
|
|
1
|
+
import { R as ReadOnlyCollectionClient } from './collection-client-U70KizLf.cjs';
|
|
2
|
+
import { C as CommerceClient, a as CommunityClient, b as ContentClient, E as EventsClient, c as CustomerNamespace, d as CustomerMembershipView, e as ClientState, f as ClientConfig } from './types-Bpx5sYKo.cjs';
|
|
3
|
+
export { A as AddItemParams, g as ApiQueryOptions, h as ApplyDiscountParams, i as CheckoutParams, j as ClearCartParams, k as ClientMetadata, l as ContentClientOptions, D as DebugConfig, m as DeepPartial, n as ExtractArrayType, P as PayloadFindResponse, o as PayloadMutationResponse, p as PublicCart, q as PublicCartItem, r as PublicCartReference, s as PublicMediaAsset, t as PublicMediaSize, u as PublicOrder, v as PublicOrderItem, w as PublicOrderReference, R as RemoveDiscountParams, x as RemoveItemParams, y as RetryConfig, z as RootClient, z as RootClientType, B as RootCollectionClient, F as RootReadOnlyQueryBuilder, S as Sort, G as StorefrontContentListOptions, H as StorefrontContentReference, I as StorefrontGalleryItem, J as StorefrontGalleryItemsListOptions, K as StorefrontGalleryItemsSort, L as StorefrontLink, M as StorefrontLinksListOptions, N as StorefrontLinksSort, U as UpdateItemParams, W as Where } from './types-Bpx5sYKo.cjs';
|
|
4
|
+
import './payload-types-DLxkB7Mv.cjs';
|
|
5
|
+
export { C as Collection, P as PublicCollection } from './const-BBynifk0.cjs';
|
|
6
6
|
import './metadata.cjs';
|
|
7
|
-
import './types-
|
|
7
|
+
import './types-B1ngKbWI.cjs';
|
|
8
8
|
|
|
9
9
|
declare class Client {
|
|
10
10
|
commerce: CommerceClient;
|
|
@@ -13,6 +13,9 @@ declare class Client {
|
|
|
13
13
|
events: EventsClient;
|
|
14
14
|
customer: CustomerNamespace;
|
|
15
15
|
collections: ReadOnlyCollectionClient;
|
|
16
|
+
memberships: {
|
|
17
|
+
me: () => Promise<CustomerMembershipView | null>;
|
|
18
|
+
};
|
|
16
19
|
lastRequestId: string | null;
|
|
17
20
|
protected state: ClientState;
|
|
18
21
|
protected config: ClientConfig;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { R as ReadOnlyCollectionClient } from './collection-client-
|
|
2
|
-
import { C as CommerceClient, a as CommunityClient, b as ContentClient, E as EventsClient, c as CustomerNamespace, d as
|
|
3
|
-
export { A as AddItemParams,
|
|
4
|
-
import './payload-types-
|
|
5
|
-
export { C as Collection, P as PublicCollection } from './const-
|
|
1
|
+
import { R as ReadOnlyCollectionClient } from './collection-client-gWsA7BVP.js';
|
|
2
|
+
import { C as CommerceClient, a as CommunityClient, b as ContentClient, E as EventsClient, c as CustomerNamespace, d as CustomerMembershipView, e as ClientState, f as ClientConfig } from './types-B9lGhZlB.js';
|
|
3
|
+
export { A as AddItemParams, g as ApiQueryOptions, h as ApplyDiscountParams, i as CheckoutParams, j as ClearCartParams, k as ClientMetadata, l as ContentClientOptions, D as DebugConfig, m as DeepPartial, n as ExtractArrayType, P as PayloadFindResponse, o as PayloadMutationResponse, p as PublicCart, q as PublicCartItem, r as PublicCartReference, s as PublicMediaAsset, t as PublicMediaSize, u as PublicOrder, v as PublicOrderItem, w as PublicOrderReference, R as RemoveDiscountParams, x as RemoveItemParams, y as RetryConfig, z as RootClient, z as RootClientType, B as RootCollectionClient, F as RootReadOnlyQueryBuilder, S as Sort, G as StorefrontContentListOptions, H as StorefrontContentReference, I as StorefrontGalleryItem, J as StorefrontGalleryItemsListOptions, K as StorefrontGalleryItemsSort, L as StorefrontLink, M as StorefrontLinksListOptions, N as StorefrontLinksSort, U as UpdateItemParams, W as Where } from './types-B9lGhZlB.js';
|
|
4
|
+
import './payload-types-DLxkB7Mv.js';
|
|
5
|
+
export { C as Collection, P as PublicCollection } from './const-_WWHU-gX.js';
|
|
6
6
|
import './metadata.js';
|
|
7
|
-
import './types-
|
|
7
|
+
import './types-BiKNBwRA.js';
|
|
8
8
|
|
|
9
9
|
declare class Client {
|
|
10
10
|
commerce: CommerceClient;
|
|
@@ -13,6 +13,9 @@ declare class Client {
|
|
|
13
13
|
events: EventsClient;
|
|
14
14
|
customer: CustomerNamespace;
|
|
15
15
|
collections: ReadOnlyCollectionClient;
|
|
16
|
+
memberships: {
|
|
17
|
+
me: () => Promise<CustomerMembershipView | null>;
|
|
18
|
+
};
|
|
16
19
|
lastRequestId: string | null;
|
|
17
20
|
protected state: ClientState;
|
|
18
21
|
protected config: ClientConfig;
|
package/dist/client.js
CHANGED
|
@@ -70,6 +70,26 @@ var TimeoutError = class extends SDKError {
|
|
|
70
70
|
this.name = "TimeoutError";
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
+
var GoneError = class extends SDKError {
|
|
74
|
+
constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
|
|
75
|
+
super("GONE_ERROR", message, 410, details, userMessage, suggestion);
|
|
76
|
+
this.name = "GoneError";
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var ServiceUnavailableError = class extends SDKError {
|
|
80
|
+
constructor(message = "Service temporarily unavailable.", retryAfter, details, userMessage, suggestion) {
|
|
81
|
+
super(
|
|
82
|
+
"SERVICE_UNAVAILABLE_ERROR",
|
|
83
|
+
message,
|
|
84
|
+
503,
|
|
85
|
+
details,
|
|
86
|
+
userMessage,
|
|
87
|
+
suggestion
|
|
88
|
+
);
|
|
89
|
+
this.name = "ServiceUnavailableError";
|
|
90
|
+
this.retryAfter = retryAfter;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
73
93
|
var UsageLimitError = class extends SDKError {
|
|
74
94
|
constructor(message, usage, details, userMessage, suggestion) {
|
|
75
95
|
super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
|
|
@@ -151,6 +171,14 @@ var createValidationError = (message, details, userMessage, suggestion, status)
|
|
|
151
171
|
var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
|
|
152
172
|
var createConfigError = (message, details, userMessage, suggestion) => new ConfigError(message, details, userMessage, suggestion);
|
|
153
173
|
var createTimeoutError = (message, details, userMessage, suggestion) => new TimeoutError(message, details, userMessage, suggestion);
|
|
174
|
+
var createGoneError = (message, details, userMessage, suggestion) => new GoneError(message, details, userMessage, suggestion);
|
|
175
|
+
var createServiceUnavailableError = (message, retryAfter, details, userMessage, suggestion) => new ServiceUnavailableError(
|
|
176
|
+
message,
|
|
177
|
+
retryAfter,
|
|
178
|
+
details,
|
|
179
|
+
userMessage,
|
|
180
|
+
suggestion
|
|
181
|
+
);
|
|
154
182
|
var createUsageLimitError = (message, usage, details, userMessage, suggestion) => new UsageLimitError(message, usage, details, userMessage, suggestion);
|
|
155
183
|
var createAuthError = (message, details, userMessage, suggestion, requestId) => new AuthError(message, details, userMessage, suggestion, requestId);
|
|
156
184
|
var createPermissionError = (message, details, userMessage, suggestion, requestId) => new PermissionError(message, details, userMessage, suggestion, requestId);
|
|
@@ -175,7 +203,7 @@ function requirePublishableKeyForSecret(apiName, publishableKey, secretKey) {
|
|
|
175
203
|
return publishableKey ?? "";
|
|
176
204
|
}
|
|
177
205
|
|
|
178
|
-
// src/core/
|
|
206
|
+
// src/core/internal/utils/api-url.ts
|
|
179
207
|
function resolveApiUrl(apiUrl) {
|
|
180
208
|
if (apiUrl) {
|
|
181
209
|
return apiUrl.replace(/\/$/, "");
|
|
@@ -192,7 +220,7 @@ function resolveApiUrl(apiUrl) {
|
|
|
192
220
|
// src/core/internal/utils/http.ts
|
|
193
221
|
var DEFAULT_TIMEOUT = 3e4;
|
|
194
222
|
var STOREFRONT_BROWSER_TIMEOUT = 15e3;
|
|
195
|
-
var DEFAULT_RETRYABLE_STATUSES = [408,
|
|
223
|
+
var DEFAULT_RETRYABLE_STATUSES = [408, 500, 502, 503, 504];
|
|
196
224
|
var NON_RETRYABLE_STATUSES = [400, 401, 403, 404, 409, 422];
|
|
197
225
|
var SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
|
|
198
226
|
var DEFAULT_MAX_RETRIES = 3;
|
|
@@ -309,7 +337,12 @@ function attachRequestId(err, id) {
|
|
|
309
337
|
if (id) err.requestId = id;
|
|
310
338
|
return err;
|
|
311
339
|
}
|
|
312
|
-
function
|
|
340
|
+
function parseRetryAfter(response) {
|
|
341
|
+
const raw = response.headers.get("Retry-After");
|
|
342
|
+
if (!raw) return void 0;
|
|
343
|
+
return parseInt(raw, 10) || void 0;
|
|
344
|
+
}
|
|
345
|
+
function mapResponseToError(status, parsed, details, requestId, retryAfter) {
|
|
313
346
|
const errorDetails = {
|
|
314
347
|
...details,
|
|
315
348
|
...parsed.errors && { errors: parsed.errors },
|
|
@@ -372,6 +405,41 @@ function createHttpStatusError(status, parsed, details, requestId) {
|
|
|
372
405
|
requestId
|
|
373
406
|
);
|
|
374
407
|
}
|
|
408
|
+
if (status === 410) {
|
|
409
|
+
return attachRequestId(
|
|
410
|
+
createGoneError(
|
|
411
|
+
parsed.errorMessage,
|
|
412
|
+
errorDetails,
|
|
413
|
+
parsed.userMessage,
|
|
414
|
+
suggestion
|
|
415
|
+
),
|
|
416
|
+
requestId
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
if (status === 429) {
|
|
420
|
+
return attachRequestId(
|
|
421
|
+
createRateLimitError(
|
|
422
|
+
parsed.errorMessage,
|
|
423
|
+
retryAfter,
|
|
424
|
+
errorDetails,
|
|
425
|
+
parsed.userMessage,
|
|
426
|
+
suggestion
|
|
427
|
+
),
|
|
428
|
+
requestId
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
if (status === 503) {
|
|
432
|
+
return attachRequestId(
|
|
433
|
+
createServiceUnavailableError(
|
|
434
|
+
parsed.errorMessage,
|
|
435
|
+
retryAfter,
|
|
436
|
+
errorDetails,
|
|
437
|
+
parsed.userMessage,
|
|
438
|
+
suggestion
|
|
439
|
+
),
|
|
440
|
+
requestId
|
|
441
|
+
);
|
|
442
|
+
}
|
|
375
443
|
return attachRequestId(
|
|
376
444
|
createNetworkError(
|
|
377
445
|
parsed.errorMessage,
|
|
@@ -490,26 +558,17 @@ async function httpFetch(url, options) {
|
|
|
490
558
|
method: requestInit.method || "GET",
|
|
491
559
|
attempt: attempt + 1
|
|
492
560
|
};
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
const error = attachRequestId(
|
|
502
|
-
createNetworkError(
|
|
503
|
-
parsed.errorMessage,
|
|
504
|
-
response.status,
|
|
505
|
-
details,
|
|
506
|
-
parsed.userMessage,
|
|
507
|
-
getErrorSuggestion(response.status)
|
|
508
|
-
),
|
|
509
|
-
requestId
|
|
561
|
+
const retryAfter = parseRetryAfter(response);
|
|
562
|
+
const error = mapResponseToError(
|
|
563
|
+
response.status,
|
|
564
|
+
parsed,
|
|
565
|
+
details,
|
|
566
|
+
requestId,
|
|
567
|
+
retryAfter
|
|
510
568
|
);
|
|
511
569
|
const method2 = (requestInit.method || "GET").toUpperCase();
|
|
512
|
-
|
|
570
|
+
const isTerminal = error instanceof RateLimitError || error instanceof UsageLimitError;
|
|
571
|
+
if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && !isTerminal && !NON_RETRYABLE_STATUSES.includes(response.status) && retryConfig.retryableStatuses.includes(response.status)) {
|
|
513
572
|
lastError = error;
|
|
514
573
|
const retryDelay = retryConfig.retryDelay(attempt);
|
|
515
574
|
debugLog(debug, "error", `Retrying in ${retryDelay}ms...`, error);
|
|
@@ -581,6 +640,64 @@ async function httpFetch(url, options) {
|
|
|
581
640
|
throw lastError ?? new NetworkError("Request failed after retries");
|
|
582
641
|
}
|
|
583
642
|
|
|
643
|
+
// src/core/api/endpoints.ts
|
|
644
|
+
var COMMERCE_ENDPOINTS = {
|
|
645
|
+
orders: {
|
|
646
|
+
create: "/api/orders/create",
|
|
647
|
+
update: "/api/orders/update",
|
|
648
|
+
confirmPayment: "/api/orders/confirm-payment",
|
|
649
|
+
byPayment: "/api/orders/by-payment",
|
|
650
|
+
cancel: "/api/orders/cancel",
|
|
651
|
+
resolveCancelRefund: "/api/orders/resolve-cancel-refund",
|
|
652
|
+
checkout: "/api/orders/checkout",
|
|
653
|
+
createFulfillment: "/api/orders/create-fulfillment",
|
|
654
|
+
updateFulfillment: "/api/orders/update-fulfillment"
|
|
655
|
+
},
|
|
656
|
+
transactions: {
|
|
657
|
+
update: "/api/transactions/update"
|
|
658
|
+
},
|
|
659
|
+
returns: {
|
|
660
|
+
create: "/api/returns/create",
|
|
661
|
+
update: "/api/returns/update",
|
|
662
|
+
returnRefund: "/api/returns/return-refund"
|
|
663
|
+
},
|
|
664
|
+
fulfillmentOrders: {
|
|
665
|
+
prepare: "/api/fulfillment-orders/prepare-fulfillment-order"
|
|
666
|
+
},
|
|
667
|
+
fulfillments: {
|
|
668
|
+
bulkImport: "/api/fulfillments/bulk-import"
|
|
669
|
+
},
|
|
670
|
+
carts: {
|
|
671
|
+
mine: "/api/carts/mine",
|
|
672
|
+
merge: "/api/carts/merge",
|
|
673
|
+
addItem: "/api/carts/add-item",
|
|
674
|
+
updateItem: "/api/carts/update-item",
|
|
675
|
+
removeItem: "/api/carts/remove-item",
|
|
676
|
+
applyDiscount: "/api/carts/apply-discount",
|
|
677
|
+
removeDiscount: "/api/carts/remove-discount",
|
|
678
|
+
clear: "/api/carts/clear"
|
|
679
|
+
},
|
|
680
|
+
products: {
|
|
681
|
+
stockCheck: "/api/products/stock-check",
|
|
682
|
+
stockSnapshot: "/api/products/stock",
|
|
683
|
+
listingGroups: "/api/products/listing-groups",
|
|
684
|
+
listingGroupsCatalog: "/api/products/listing-groups/catalog",
|
|
685
|
+
listingGroupsQuery: "/api/products/listing-groups/query",
|
|
686
|
+
listingGroupsQueryCatalog: "/api/products/listing-groups/query/catalog",
|
|
687
|
+
detail: "/api/products/detail",
|
|
688
|
+
detailCatalog: "/api/products/detail/catalog",
|
|
689
|
+
upsert: "/api/products/upsert"
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
var COMMERCE_ENDPOINT_PATHS = Object.values(
|
|
693
|
+
COMMERCE_ENDPOINTS
|
|
694
|
+
).flatMap((group) => Object.values(group));
|
|
695
|
+
var MEMBERSHIP_ENDPOINTS = {
|
|
696
|
+
subscribe: "/api/memberships/subscribe",
|
|
697
|
+
cancel: (id) => `/api/memberships/${id}/cancel`,
|
|
698
|
+
me: "/api/memberships/me"
|
|
699
|
+
};
|
|
700
|
+
|
|
584
701
|
// src/core/internal/utils/query-string.ts
|
|
585
702
|
function productDetailQuery(params) {
|
|
586
703
|
const search = new URLSearchParams();
|
|
@@ -589,7 +706,7 @@ function productDetailQuery(params) {
|
|
|
589
706
|
} else {
|
|
590
707
|
search.set("id", params.id);
|
|
591
708
|
}
|
|
592
|
-
return
|
|
709
|
+
return `${COMMERCE_ENDPOINTS.products.detail}?${search}`;
|
|
593
710
|
}
|
|
594
711
|
function productDetailCatalogQuery(params) {
|
|
595
712
|
const search = new URLSearchParams();
|
|
@@ -598,20 +715,17 @@ function productDetailCatalogQuery(params) {
|
|
|
598
715
|
} else {
|
|
599
716
|
search.set("id", params.id);
|
|
600
717
|
}
|
|
601
|
-
return
|
|
718
|
+
return `${COMMERCE_ENDPOINTS.products.detailCatalog}?${search}`;
|
|
602
719
|
}
|
|
603
720
|
function listingGroupsCatalogQuery(params) {
|
|
604
|
-
return
|
|
721
|
+
return `${COMMERCE_ENDPOINTS.products.listingGroupsCatalog}?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
|
|
605
722
|
}
|
|
606
723
|
function appendListingGroupsQuerySearchParams(search, options) {
|
|
607
724
|
if (options?.page != null) search.set("page", String(options.page));
|
|
608
725
|
if (options?.limit != null) search.set("limit", String(options.limit));
|
|
609
726
|
if (options?.sort != null) {
|
|
610
727
|
const sort = options.sort;
|
|
611
|
-
search.set(
|
|
612
|
-
"sort",
|
|
613
|
-
Array.isArray(sort) ? sort.join(",") : sort
|
|
614
|
-
);
|
|
728
|
+
search.set("sort", Array.isArray(sort) ? sort.join(",") : sort);
|
|
615
729
|
}
|
|
616
730
|
if (options?.where != null) {
|
|
617
731
|
search.set("whereJson", JSON.stringify(options.where));
|
|
@@ -621,16 +735,16 @@ function listingGroupsQueryUrl(options) {
|
|
|
621
735
|
const search = new URLSearchParams();
|
|
622
736
|
appendListingGroupsQuerySearchParams(search, options);
|
|
623
737
|
const query = search.toString();
|
|
624
|
-
return
|
|
738
|
+
return `${COMMERCE_ENDPOINTS.products.listingGroupsQuery}${query ? `?${query}` : ""}`;
|
|
625
739
|
}
|
|
626
740
|
function listingGroupsQueryCatalogUrl(options) {
|
|
627
741
|
const search = new URLSearchParams();
|
|
628
742
|
appendListingGroupsQuerySearchParams(search, options);
|
|
629
743
|
const query = search.toString();
|
|
630
|
-
return
|
|
744
|
+
return `${COMMERCE_ENDPOINTS.products.listingGroupsQueryCatalog}${query ? `?${query}` : ""}`;
|
|
631
745
|
}
|
|
632
746
|
function stockSnapshotQuery(params) {
|
|
633
|
-
return
|
|
747
|
+
return `${COMMERCE_ENDPOINTS.products.stockSnapshot}?variantIds=${params.variantIds.map(encodeURIComponent).join(",")}`;
|
|
634
748
|
}
|
|
635
749
|
|
|
636
750
|
// src/core/collection/http-client.ts
|
|
@@ -1522,39 +1636,78 @@ var CustomerNamespace = class {
|
|
|
1522
1636
|
// src/core/api/cart-api.ts
|
|
1523
1637
|
var CartApi = class extends CustomerScopedApi {
|
|
1524
1638
|
constructor(options) {
|
|
1525
|
-
super("CartApi", options);
|
|
1639
|
+
super("CartApi", { ...options, requiresCredential: false });
|
|
1526
1640
|
}
|
|
1527
1641
|
async execute(endpoint, method, body) {
|
|
1528
1642
|
return this.request(endpoint, { method, body });
|
|
1529
1643
|
}
|
|
1530
|
-
|
|
1644
|
+
/**
|
|
1645
|
+
* Create a cart and receive its `cartToken`. Store the token and pass it to
|
|
1646
|
+
* every subsequent cart operation.
|
|
1647
|
+
*/
|
|
1648
|
+
createCart(params = {}) {
|
|
1649
|
+
return this.execute("/api/carts/create", "POST", params);
|
|
1650
|
+
}
|
|
1651
|
+
getCart(cartToken) {
|
|
1652
|
+
return this.execute("/api/carts/get", "POST", { cartToken });
|
|
1653
|
+
}
|
|
1654
|
+
merge(params) {
|
|
1531
1655
|
return this.execute(
|
|
1532
|
-
|
|
1533
|
-
"
|
|
1656
|
+
COMMERCE_ENDPOINTS.carts.merge,
|
|
1657
|
+
"POST",
|
|
1658
|
+
params
|
|
1659
|
+
);
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Resolve the authenticated customer's active cart by JWT (no `cartToken`
|
|
1663
|
+
* required). Returns the cart and its capability handle, or both `null` when
|
|
1664
|
+
* the customer has no active cart. Requires a customer token.
|
|
1665
|
+
*/
|
|
1666
|
+
mine() {
|
|
1667
|
+
return this.execute(
|
|
1668
|
+
COMMERCE_ENDPOINTS.carts.mine,
|
|
1669
|
+
"POST",
|
|
1670
|
+
{}
|
|
1534
1671
|
);
|
|
1535
1672
|
}
|
|
1536
1673
|
addItem(params) {
|
|
1537
|
-
return this.execute(
|
|
1674
|
+
return this.execute(
|
|
1675
|
+
COMMERCE_ENDPOINTS.carts.addItem,
|
|
1676
|
+
"POST",
|
|
1677
|
+
params
|
|
1678
|
+
);
|
|
1538
1679
|
}
|
|
1539
1680
|
updateItem(params) {
|
|
1540
|
-
return this.execute(
|
|
1681
|
+
return this.execute(
|
|
1682
|
+
COMMERCE_ENDPOINTS.carts.updateItem,
|
|
1683
|
+
"POST",
|
|
1684
|
+
params
|
|
1685
|
+
);
|
|
1541
1686
|
}
|
|
1542
1687
|
removeItem(params) {
|
|
1543
1688
|
return this.execute(
|
|
1544
|
-
|
|
1689
|
+
COMMERCE_ENDPOINTS.carts.removeItem,
|
|
1545
1690
|
"POST",
|
|
1546
1691
|
params
|
|
1547
1692
|
);
|
|
1548
1693
|
}
|
|
1549
1694
|
applyDiscount(params) {
|
|
1550
|
-
return this.execute(
|
|
1695
|
+
return this.execute(
|
|
1696
|
+
COMMERCE_ENDPOINTS.carts.applyDiscount,
|
|
1697
|
+
"POST",
|
|
1698
|
+
params
|
|
1699
|
+
);
|
|
1551
1700
|
}
|
|
1552
1701
|
removeDiscount(params) {
|
|
1553
|
-
return this.execute(
|
|
1702
|
+
return this.execute(
|
|
1703
|
+
COMMERCE_ENDPOINTS.carts.removeDiscount,
|
|
1704
|
+
"POST",
|
|
1705
|
+
params
|
|
1706
|
+
);
|
|
1554
1707
|
}
|
|
1555
1708
|
clearCart(params) {
|
|
1556
1709
|
return this.execute(
|
|
1557
|
-
|
|
1710
|
+
COMMERCE_ENDPOINTS.carts.clear,
|
|
1558
1711
|
"POST",
|
|
1559
1712
|
params
|
|
1560
1713
|
);
|
|
@@ -2365,6 +2518,7 @@ function compareVariantOrder(a, b) {
|
|
|
2365
2518
|
function getVariantAvailableForSale(variant) {
|
|
2366
2519
|
if (variant.isActive === false) return false;
|
|
2367
2520
|
if (variant.isUnlimited) return true;
|
|
2521
|
+
if (variant.inventoryPolicy === "continue") return true;
|
|
2368
2522
|
return (variant.stock ?? 0) - (variant.reservedStock ?? 0) > 0;
|
|
2369
2523
|
}
|
|
2370
2524
|
function isVariantAvailableForSale(variant) {
|
|
@@ -2702,7 +2856,10 @@ var CommerceClient = class {
|
|
|
2702
2856
|
onRequestId: options.onRequestId
|
|
2703
2857
|
});
|
|
2704
2858
|
this.product = {
|
|
2705
|
-
stockCheck: (params) => api.post(
|
|
2859
|
+
stockCheck: (params) => api.post(
|
|
2860
|
+
COMMERCE_ENDPOINTS.products.stockCheck,
|
|
2861
|
+
params
|
|
2862
|
+
),
|
|
2706
2863
|
stockSnapshot: (params) => api.get(stockSnapshotQuery(params)),
|
|
2707
2864
|
listingGroups: (params) => api.get(
|
|
2708
2865
|
listingGroupsCatalogQuery(params)
|
|
@@ -2720,7 +2877,9 @@ var CommerceClient = class {
|
|
|
2720
2877
|
},
|
|
2721
2878
|
detail: async (params) => {
|
|
2722
2879
|
try {
|
|
2723
|
-
const product = await api.get(
|
|
2880
|
+
const product = await api.get(
|
|
2881
|
+
productDetailQuery(params)
|
|
2882
|
+
);
|
|
2724
2883
|
return { found: true, product };
|
|
2725
2884
|
} catch (err) {
|
|
2726
2885
|
const notFoundResult = productDetailResultFromError(err);
|
|
@@ -2742,13 +2901,16 @@ var CommerceClient = class {
|
|
|
2742
2901
|
}
|
|
2743
2902
|
};
|
|
2744
2903
|
this.cart = {
|
|
2904
|
+
create: cartApi.createCart.bind(cartApi),
|
|
2745
2905
|
get: cartApi.getCart.bind(cartApi),
|
|
2746
2906
|
addItem: cartApi.addItem.bind(cartApi),
|
|
2747
2907
|
updateItem: cartApi.updateItem.bind(cartApi),
|
|
2748
2908
|
removeItem: cartApi.removeItem.bind(cartApi),
|
|
2749
2909
|
applyDiscount: cartApi.applyDiscount.bind(cartApi),
|
|
2750
2910
|
removeDiscount: cartApi.removeDiscount.bind(cartApi),
|
|
2751
|
-
clear: cartApi.clearCart.bind(cartApi)
|
|
2911
|
+
clear: cartApi.clearCart.bind(cartApi),
|
|
2912
|
+
merge: cartApi.merge.bind(cartApi),
|
|
2913
|
+
mine: cartApi.mine.bind(cartApi)
|
|
2752
2914
|
};
|
|
2753
2915
|
this.orders = {
|
|
2754
2916
|
checkout: (params) => {
|
|
@@ -2765,7 +2927,10 @@ var CommerceClient = class {
|
|
|
2765
2927
|
validate: (params) => api.post("/api/discounts/validate", params)
|
|
2766
2928
|
};
|
|
2767
2929
|
this.shipping = {
|
|
2768
|
-
calculate: (params) => api.post(
|
|
2930
|
+
calculate: (params) => api.post(
|
|
2931
|
+
"/api/shipping-policies/calculate",
|
|
2932
|
+
params
|
|
2933
|
+
)
|
|
2769
2934
|
};
|
|
2770
2935
|
}
|
|
2771
2936
|
};
|
|
@@ -2854,8 +3019,12 @@ function buildGuestCancelRequestBody(token, params) {
|
|
|
2854
3019
|
}
|
|
2855
3020
|
function buildRangeEndpoint(params) {
|
|
2856
3021
|
const urlParams = new URLSearchParams();
|
|
2857
|
-
|
|
2858
|
-
|
|
3022
|
+
if (params.start !== void 0) {
|
|
3023
|
+
urlParams.set("start", formatDateParam(params.start));
|
|
3024
|
+
}
|
|
3025
|
+
if (params.end !== void 0) {
|
|
3026
|
+
urlParams.set("end", formatDateParam(params.end));
|
|
3027
|
+
}
|
|
2859
3028
|
if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
|
|
2860
3029
|
if (params.page !== void 0) urlParams.set("page", String(params.page));
|
|
2861
3030
|
appendValues(urlParams, "calendar", params.calendar);
|
|
@@ -2878,6 +3047,13 @@ function appendValues(params, key, value) {
|
|
|
2878
3047
|
}
|
|
2879
3048
|
|
|
2880
3049
|
// src/core/client/client.ts
|
|
3050
|
+
var BrowserMembershipApi = class extends CustomerScopedApi {
|
|
3051
|
+
me() {
|
|
3052
|
+
return this.request(MEMBERSHIP_ENDPOINTS.me, {
|
|
3053
|
+
method: "GET"
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3056
|
+
};
|
|
2881
3057
|
var Client = class {
|
|
2882
3058
|
constructor(options) {
|
|
2883
3059
|
this.lastRequestId = null;
|
|
@@ -2942,6 +3118,16 @@ var Client = class {
|
|
|
2942
3118
|
onRequestId,
|
|
2943
3119
|
this.config.apiUrl
|
|
2944
3120
|
);
|
|
3121
|
+
const membershipApi = new BrowserMembershipApi("MembershipApi", {
|
|
3122
|
+
publishableKey: this.config.publishableKey,
|
|
3123
|
+
apiUrl: this.config.apiUrl,
|
|
3124
|
+
customerToken: () => this.customer.auth.getToken(),
|
|
3125
|
+
onUnauthorized,
|
|
3126
|
+
onRequestId
|
|
3127
|
+
});
|
|
3128
|
+
this.memberships = {
|
|
3129
|
+
me: membershipApi.me.bind(membershipApi)
|
|
3130
|
+
};
|
|
2945
3131
|
}
|
|
2946
3132
|
getState() {
|
|
2947
3133
|
return { ...this.state };
|