@01.software/sdk 0.41.0 → 0.42.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 +222 -0
- package/README.md +81 -18
- 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 +176 -32
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +6 -6
- package/dist/client.d.ts +6 -6
- package/dist/client.js +176 -32
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-Bymfni8u.d.cts → collection-client-B-qVIBnJ.d.cts} +5 -5
- package/dist/{collection-client-CN4lj6gi.d.ts → collection-client-BhCMwIus.d.ts} +5 -5
- package/dist/{const-4BUtUdGU.d.cts → const-BiDujixF.d.cts} +1 -1
- package/dist/{const-ymprfiPf.d.ts → const-pmHlwm3E.d.ts} +1 -1
- package/dist/{index-w36lpSkU.d.ts → index-B1UBDaKz.d.ts} +3 -3
- package/dist/{index-Dquv4xTL.d.cts → index-D78ki6Ij.d.cts} +3 -3
- package/dist/index.cjs +156 -339
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +156 -339
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-DC0xzR9i.d.cts → payload-types-C7Ul4ElL.d.cts} +181 -118
- package/dist/{payload-types-DC0xzR9i.d.ts → payload-types-C7Ul4ElL.d.ts} +181 -118
- package/dist/query.d.cts +5 -5
- package/dist/query.d.ts +5 -5
- 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 +236 -50
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +7 -7
- package/dist/server.d.ts +7 -7
- package/dist/server.js +236 -50
- package/dist/server.js.map +1 -1
- package/dist/{types-CHrzs2GB.d.ts → types-BL7M-EUV.d.cts} +140 -14
- package/dist/{types-Bh2p-EMc.d.ts → types-Bf2iCjy8.d.ts} +1 -1
- package/dist/{types-BvpjooU-.d.cts → types-ChV1t4ei.d.cts} +1 -1
- package/dist/{types-Bl-m9ttd.d.cts → types-D5dSNIGs.d.ts} +140 -14
- 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.d.cts +4 -4
- package/dist/webhook.d.ts +4 -4
- package/package.json +3 -3
package/dist/server.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { S as ServerCollectionClient } from './collection-client-
|
|
2
|
-
export { C as CollectionClient } from './collection-client-
|
|
3
|
-
import { N as BaseApi, O as ServerApiOptions, Q as ServerCommerceClient, T as TenantIntrospectionClient, a as CommunityClient, V as BanCustomerParams, X as CommunityBan, Y as UnbanCustomerParams, d as ClientState, Z as ClientServerConfig, E as EventsClient, _ as RootServerClientWithEvents } from './types-
|
|
4
|
-
export { A as AddItemParams, g as ApplyDiscountParams, h as CheckoutParams, i as ClearCartParams, $ as CollectionFieldSchema, a0 as CollectionSchemaResponse, a1 as EventGuestCancelParams, a2 as EventGuestRegistration, a3 as EventGuestRegistrationResponse, a4 as EventRegistrationAnswerInput, a5 as EventRegistrationAttendeeInput, a6 as EventRegistrationPublic, a7 as EventRegistrationRegisterParams, a8 as EventRegistrationRegisterResponse, a9 as EventsCalendarItem, aa as EventsClientOptions, ab as EventsDateParam, ac as EventsExternalSource, ad as EventsLocation, ae as EventsOccurrenceLocation, af as EventsRangeEvent, ag as EventsRangeOccurrence, ah as EventsRangeParams, ai as EventsRangeResponse, aj as EventsTaxonomyItem, ak as ModerationApi, o as PublicCart, p as PublicCartItem, q as PublicCartReference, r as PublicMediaAsset, s as PublicMediaSize, t as PublicOrder, u as PublicOrderItem, v as PublicOrderReference, R as RemoveDiscountParams, w as RemoveItemParams, al as RootServerClient, am as TenantFeatureProgressEvidenceValue, an as TenantFeatureProgressFeature, ao as TenantFeatureProgressGroup, ap as TenantFeatureProgressInput, aq as TenantFeatureProgressItem, ar as TenantFeatureProgressItemState, as as TenantFeatureProgressResponse, at as TenantFeatureProgressSeverity, au as TenantFeatureProgressStatus, av as TenantIntrospectionApi, aw as TenantIntrospectionApiOptions, U as UpdateItemParams } from './types-
|
|
5
|
-
import './payload-types-
|
|
1
|
+
import { S as ServerCollectionClient } from './collection-client-B-qVIBnJ.cjs';
|
|
2
|
+
export { C as CollectionClient } from './collection-client-B-qVIBnJ.cjs';
|
|
3
|
+
import { N as BaseApi, O as ServerApiOptions, Q as ServerCommerceClient, T as TenantIntrospectionClient, a as CommunityClient, V as BanCustomerParams, X as CommunityBan, Y as UnbanCustomerParams, d as ClientState, Z as ClientServerConfig, E as EventsClient, _ as RootServerClientWithEvents } from './types-BL7M-EUV.cjs';
|
|
4
|
+
export { A as AddItemParams, g as ApplyDiscountParams, h as CheckoutParams, i as ClearCartParams, $ as CollectionFieldSchema, a0 as CollectionSchemaResponse, a1 as EventGuestCancelParams, a2 as EventGuestRegistration, a3 as EventGuestRegistrationResponse, a4 as EventRegistrationAnswerInput, a5 as EventRegistrationAttendeeInput, a6 as EventRegistrationPublic, a7 as EventRegistrationRegisterParams, a8 as EventRegistrationRegisterResponse, a9 as EventsCalendarItem, aa as EventsClientOptions, ab as EventsDateParam, ac as EventsExternalSource, ad as EventsLocation, ae as EventsOccurrenceLocation, af as EventsRangeEvent, ag as EventsRangeOccurrence, ah as EventsRangeParams, ai as EventsRangeResponse, aj as EventsTaxonomyItem, ak as ModerationApi, o as PublicCart, p as PublicCartItem, q as PublicCartReference, r as PublicMediaAsset, s as PublicMediaSize, t as PublicOrder, u as PublicOrderItem, v as PublicOrderReference, R as RemoveDiscountParams, w as RemoveItemParams, al as RootServerClient, am as TenantFeatureProgressEvidenceValue, an as TenantFeatureProgressFeature, ao as TenantFeatureProgressGroup, ap as TenantFeatureProgressInput, aq as TenantFeatureProgressItem, ar as TenantFeatureProgressItemState, as as TenantFeatureProgressResponse, at as TenantFeatureProgressSeverity, au as TenantFeatureProgressStatus, av as TenantIntrospectionApi, aw as TenantIntrospectionApiOptions, U as UpdateItemParams } from './types-BL7M-EUV.cjs';
|
|
5
|
+
import './payload-types-C7Ul4ElL.cjs';
|
|
6
6
|
import './metadata.cjs';
|
|
7
|
-
import './const-
|
|
8
|
-
import './types-
|
|
7
|
+
import './const-BiDujixF.cjs';
|
|
8
|
+
import './types-ChV1t4ei.cjs';
|
|
9
9
|
|
|
10
10
|
type PreviewDetailParams = {
|
|
11
11
|
collection: string;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { S as ServerCollectionClient } from './collection-client-
|
|
2
|
-
export { C as CollectionClient } from './collection-client-
|
|
3
|
-
import { N as BaseApi, O as ServerApiOptions, Q as ServerCommerceClient, T as TenantIntrospectionClient, a as CommunityClient, V as BanCustomerParams, X as CommunityBan, Y as UnbanCustomerParams, d as ClientState, Z as ClientServerConfig, E as EventsClient, _ as RootServerClientWithEvents } from './types-
|
|
4
|
-
export { A as AddItemParams, g as ApplyDiscountParams, h as CheckoutParams, i as ClearCartParams, $ as CollectionFieldSchema, a0 as CollectionSchemaResponse, a1 as EventGuestCancelParams, a2 as EventGuestRegistration, a3 as EventGuestRegistrationResponse, a4 as EventRegistrationAnswerInput, a5 as EventRegistrationAttendeeInput, a6 as EventRegistrationPublic, a7 as EventRegistrationRegisterParams, a8 as EventRegistrationRegisterResponse, a9 as EventsCalendarItem, aa as EventsClientOptions, ab as EventsDateParam, ac as EventsExternalSource, ad as EventsLocation, ae as EventsOccurrenceLocation, af as EventsRangeEvent, ag as EventsRangeOccurrence, ah as EventsRangeParams, ai as EventsRangeResponse, aj as EventsTaxonomyItem, ak as ModerationApi, o as PublicCart, p as PublicCartItem, q as PublicCartReference, r as PublicMediaAsset, s as PublicMediaSize, t as PublicOrder, u as PublicOrderItem, v as PublicOrderReference, R as RemoveDiscountParams, w as RemoveItemParams, al as RootServerClient, am as TenantFeatureProgressEvidenceValue, an as TenantFeatureProgressFeature, ao as TenantFeatureProgressGroup, ap as TenantFeatureProgressInput, aq as TenantFeatureProgressItem, ar as TenantFeatureProgressItemState, as as TenantFeatureProgressResponse, at as TenantFeatureProgressSeverity, au as TenantFeatureProgressStatus, av as TenantIntrospectionApi, aw as TenantIntrospectionApiOptions, U as UpdateItemParams } from './types-
|
|
5
|
-
import './payload-types-
|
|
1
|
+
import { S as ServerCollectionClient } from './collection-client-BhCMwIus.js';
|
|
2
|
+
export { C as CollectionClient } from './collection-client-BhCMwIus.js';
|
|
3
|
+
import { N as BaseApi, O as ServerApiOptions, Q as ServerCommerceClient, T as TenantIntrospectionClient, a as CommunityClient, V as BanCustomerParams, X as CommunityBan, Y as UnbanCustomerParams, d as ClientState, Z as ClientServerConfig, E as EventsClient, _ as RootServerClientWithEvents } from './types-D5dSNIGs.js';
|
|
4
|
+
export { A as AddItemParams, g as ApplyDiscountParams, h as CheckoutParams, i as ClearCartParams, $ as CollectionFieldSchema, a0 as CollectionSchemaResponse, a1 as EventGuestCancelParams, a2 as EventGuestRegistration, a3 as EventGuestRegistrationResponse, a4 as EventRegistrationAnswerInput, a5 as EventRegistrationAttendeeInput, a6 as EventRegistrationPublic, a7 as EventRegistrationRegisterParams, a8 as EventRegistrationRegisterResponse, a9 as EventsCalendarItem, aa as EventsClientOptions, ab as EventsDateParam, ac as EventsExternalSource, ad as EventsLocation, ae as EventsOccurrenceLocation, af as EventsRangeEvent, ag as EventsRangeOccurrence, ah as EventsRangeParams, ai as EventsRangeResponse, aj as EventsTaxonomyItem, ak as ModerationApi, o as PublicCart, p as PublicCartItem, q as PublicCartReference, r as PublicMediaAsset, s as PublicMediaSize, t as PublicOrder, u as PublicOrderItem, v as PublicOrderReference, R as RemoveDiscountParams, w as RemoveItemParams, al as RootServerClient, am as TenantFeatureProgressEvidenceValue, an as TenantFeatureProgressFeature, ao as TenantFeatureProgressGroup, ap as TenantFeatureProgressInput, aq as TenantFeatureProgressItem, ar as TenantFeatureProgressItemState, as as TenantFeatureProgressResponse, at as TenantFeatureProgressSeverity, au as TenantFeatureProgressStatus, av as TenantIntrospectionApi, aw as TenantIntrospectionApiOptions, U as UpdateItemParams } from './types-D5dSNIGs.js';
|
|
5
|
+
import './payload-types-C7Ul4ElL.js';
|
|
6
6
|
import './metadata.js';
|
|
7
|
-
import './const-
|
|
8
|
-
import './types-
|
|
7
|
+
import './const-pmHlwm3E.js';
|
|
8
|
+
import './types-Bf2iCjy8.js';
|
|
9
9
|
|
|
10
10
|
type PreviewDetailParams = {
|
|
11
11
|
collection: string;
|
package/dist/server.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);
|
|
@@ -951,9 +1010,10 @@ var CollectionQueryBuilder = class {
|
|
|
951
1010
|
* DELETE /api/{collection}/{id}
|
|
952
1011
|
* @returns Deleted document object directly (no wrapper)
|
|
953
1012
|
*/
|
|
954
|
-
async remove(id) {
|
|
1013
|
+
async remove(id, options) {
|
|
955
1014
|
return this.api.requestDelete(
|
|
956
|
-
`/api/${String(this.collection)}/${String(id)}
|
|
1015
|
+
`/api/${String(this.collection)}/${String(id)}`,
|
|
1016
|
+
options
|
|
957
1017
|
);
|
|
958
1018
|
}
|
|
959
1019
|
/**
|
|
@@ -1085,8 +1145,9 @@ var CollectionClient = class extends HttpClient {
|
|
|
1085
1145
|
* Delete document
|
|
1086
1146
|
* DELETE /api/{collection}/{id}
|
|
1087
1147
|
*/
|
|
1088
|
-
async requestDelete(endpoint) {
|
|
1089
|
-
const
|
|
1148
|
+
async requestDelete(endpoint, options) {
|
|
1149
|
+
const url = this.buildUrl(endpoint, options);
|
|
1150
|
+
const response = await this.fetchWithTracking(url, {
|
|
1090
1151
|
...this.defaultOptions,
|
|
1091
1152
|
method: "DELETE"
|
|
1092
1153
|
});
|
|
@@ -1577,42 +1638,123 @@ var ModerationApi = class extends BaseApi {
|
|
|
1577
1638
|
}
|
|
1578
1639
|
};
|
|
1579
1640
|
|
|
1641
|
+
// src/core/api/endpoints.ts
|
|
1642
|
+
var COMMERCE_ENDPOINTS = {
|
|
1643
|
+
orders: {
|
|
1644
|
+
create: "/api/orders/create",
|
|
1645
|
+
update: "/api/orders/update",
|
|
1646
|
+
confirmPayment: "/api/orders/confirm-payment",
|
|
1647
|
+
byPayment: "/api/orders/by-payment",
|
|
1648
|
+
cancel: "/api/orders/cancel",
|
|
1649
|
+
resolveCancelRefund: "/api/orders/resolve-cancel-refund",
|
|
1650
|
+
checkout: "/api/orders/checkout",
|
|
1651
|
+
createFulfillment: "/api/orders/create-fulfillment",
|
|
1652
|
+
updateFulfillment: "/api/orders/update-fulfillment"
|
|
1653
|
+
},
|
|
1654
|
+
transactions: {
|
|
1655
|
+
update: "/api/transactions/update"
|
|
1656
|
+
},
|
|
1657
|
+
returns: {
|
|
1658
|
+
create: "/api/returns/create",
|
|
1659
|
+
update: "/api/returns/update",
|
|
1660
|
+
returnRefund: "/api/returns/return-refund"
|
|
1661
|
+
},
|
|
1662
|
+
fulfillmentOrders: {
|
|
1663
|
+
prepare: "/api/fulfillment-orders/prepare-fulfillment-order"
|
|
1664
|
+
},
|
|
1665
|
+
fulfillments: {
|
|
1666
|
+
bulkImport: "/api/fulfillments/bulk-import"
|
|
1667
|
+
},
|
|
1668
|
+
carts: {
|
|
1669
|
+
mine: "/api/carts/mine",
|
|
1670
|
+
merge: "/api/carts/merge",
|
|
1671
|
+
addItem: "/api/carts/add-item",
|
|
1672
|
+
updateItem: "/api/carts/update-item",
|
|
1673
|
+
removeItem: "/api/carts/remove-item",
|
|
1674
|
+
applyDiscount: "/api/carts/apply-discount",
|
|
1675
|
+
removeDiscount: "/api/carts/remove-discount",
|
|
1676
|
+
clear: "/api/carts/clear"
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
var COMMERCE_ENDPOINT_PATHS = Object.values(
|
|
1680
|
+
COMMERCE_ENDPOINTS
|
|
1681
|
+
).flatMap((group) => Object.values(group));
|
|
1682
|
+
|
|
1580
1683
|
// src/core/api/cart-api.ts
|
|
1581
1684
|
var CartApi = class extends CustomerScopedApi {
|
|
1582
1685
|
constructor(options) {
|
|
1583
|
-
super("CartApi", options);
|
|
1686
|
+
super("CartApi", { ...options, requiresCredential: false });
|
|
1584
1687
|
}
|
|
1585
1688
|
async execute(endpoint, method, body) {
|
|
1586
1689
|
return this.request(endpoint, { method, body });
|
|
1587
1690
|
}
|
|
1588
|
-
|
|
1691
|
+
/**
|
|
1692
|
+
* Create a cart and receive its `cartToken`. Store the token and pass it to
|
|
1693
|
+
* every subsequent cart operation.
|
|
1694
|
+
*/
|
|
1695
|
+
createCart(params = {}) {
|
|
1696
|
+
return this.execute("/api/carts/create", "POST", params);
|
|
1697
|
+
}
|
|
1698
|
+
getCart(cartToken) {
|
|
1699
|
+
return this.execute("/api/carts/get", "POST", { cartToken });
|
|
1700
|
+
}
|
|
1701
|
+
merge(params) {
|
|
1589
1702
|
return this.execute(
|
|
1590
|
-
|
|
1591
|
-
"
|
|
1703
|
+
COMMERCE_ENDPOINTS.carts.merge,
|
|
1704
|
+
"POST",
|
|
1705
|
+
params
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Resolve the authenticated customer's active cart by JWT (no `cartToken`
|
|
1710
|
+
* required). Returns the cart and its capability handle, or both `null` when
|
|
1711
|
+
* the customer has no active cart. Requires a customer token.
|
|
1712
|
+
*/
|
|
1713
|
+
mine() {
|
|
1714
|
+
return this.execute(
|
|
1715
|
+
COMMERCE_ENDPOINTS.carts.mine,
|
|
1716
|
+
"POST",
|
|
1717
|
+
{}
|
|
1592
1718
|
);
|
|
1593
1719
|
}
|
|
1594
1720
|
addItem(params) {
|
|
1595
|
-
return this.execute(
|
|
1721
|
+
return this.execute(
|
|
1722
|
+
COMMERCE_ENDPOINTS.carts.addItem,
|
|
1723
|
+
"POST",
|
|
1724
|
+
params
|
|
1725
|
+
);
|
|
1596
1726
|
}
|
|
1597
1727
|
updateItem(params) {
|
|
1598
|
-
return this.execute(
|
|
1728
|
+
return this.execute(
|
|
1729
|
+
COMMERCE_ENDPOINTS.carts.updateItem,
|
|
1730
|
+
"POST",
|
|
1731
|
+
params
|
|
1732
|
+
);
|
|
1599
1733
|
}
|
|
1600
1734
|
removeItem(params) {
|
|
1601
1735
|
return this.execute(
|
|
1602
|
-
|
|
1736
|
+
COMMERCE_ENDPOINTS.carts.removeItem,
|
|
1603
1737
|
"POST",
|
|
1604
1738
|
params
|
|
1605
1739
|
);
|
|
1606
1740
|
}
|
|
1607
1741
|
applyDiscount(params) {
|
|
1608
|
-
return this.execute(
|
|
1742
|
+
return this.execute(
|
|
1743
|
+
COMMERCE_ENDPOINTS.carts.applyDiscount,
|
|
1744
|
+
"POST",
|
|
1745
|
+
params
|
|
1746
|
+
);
|
|
1609
1747
|
}
|
|
1610
1748
|
removeDiscount(params) {
|
|
1611
|
-
return this.execute(
|
|
1749
|
+
return this.execute(
|
|
1750
|
+
COMMERCE_ENDPOINTS.carts.removeDiscount,
|
|
1751
|
+
"POST",
|
|
1752
|
+
params
|
|
1753
|
+
);
|
|
1612
1754
|
}
|
|
1613
1755
|
clearCart(params) {
|
|
1614
1756
|
return this.execute(
|
|
1615
|
-
|
|
1757
|
+
COMMERCE_ENDPOINTS.carts.clear,
|
|
1616
1758
|
"POST",
|
|
1617
1759
|
params
|
|
1618
1760
|
);
|
|
@@ -2423,6 +2565,7 @@ function compareVariantOrder(a, b) {
|
|
|
2423
2565
|
function getVariantAvailableForSale(variant) {
|
|
2424
2566
|
if (variant.isActive === false) return false;
|
|
2425
2567
|
if (variant.isUnlimited) return true;
|
|
2568
|
+
if (variant.inventoryPolicy === "continue") return true;
|
|
2426
2569
|
return (variant.stock ?? 0) - (variant.reservedStock ?? 0) > 0;
|
|
2427
2570
|
}
|
|
2428
2571
|
function isVariantAvailableForSale(variant) {
|
|
@@ -2888,26 +3031,61 @@ var OrderApi = class extends BaseApi {
|
|
|
2888
3031
|
const { idempotencyKey } = params;
|
|
2889
3032
|
const normalizedBody = normalizeCreateOrderBody(params);
|
|
2890
3033
|
return this.request(
|
|
2891
|
-
|
|
3034
|
+
COMMERCE_ENDPOINTS.orders.create,
|
|
2892
3035
|
normalizedBody,
|
|
2893
3036
|
idempotencyRequestOptions(idempotencyKey)
|
|
2894
3037
|
);
|
|
2895
3038
|
}
|
|
2896
3039
|
updateOrder(params) {
|
|
2897
|
-
return this.request(
|
|
3040
|
+
return this.request(COMMERCE_ENDPOINTS.orders.update, params);
|
|
2898
3041
|
}
|
|
2899
3042
|
updateTransaction(params) {
|
|
2900
|
-
return this.request(
|
|
3043
|
+
return this.request(
|
|
3044
|
+
COMMERCE_ENDPOINTS.transactions.update,
|
|
3045
|
+
params
|
|
3046
|
+
);
|
|
2901
3047
|
}
|
|
2902
3048
|
confirmPayment(params) {
|
|
2903
3049
|
const { body, idempotencyKey } = splitIdempotencyKey(params);
|
|
2904
3050
|
const headerKey = idempotencyKey ?? params.providerEventId;
|
|
2905
3051
|
return this.request(
|
|
2906
|
-
|
|
3052
|
+
COMMERCE_ENDPOINTS.orders.confirmPayment,
|
|
2907
3053
|
body,
|
|
2908
3054
|
idempotencyRequestOptions(headerKey)
|
|
2909
3055
|
);
|
|
2910
3056
|
}
|
|
3057
|
+
/**
|
|
3058
|
+
* Resolve an order + its payment transaction by PG payment id. Replaces raw
|
|
3059
|
+
* `transactions.find({ where: { pgPaymentId } })` + a local file index in
|
|
3060
|
+
* storefronts. Server-only (sk01_) read of the full populated Order.
|
|
3061
|
+
*/
|
|
3062
|
+
getByPaymentId(params) {
|
|
3063
|
+
const query = new URLSearchParams({
|
|
3064
|
+
pgProvider: params.pgProvider,
|
|
3065
|
+
pgPaymentId: params.pgPaymentId
|
|
3066
|
+
}).toString();
|
|
3067
|
+
return this.request(
|
|
3068
|
+
`${COMMERCE_ENDPOINTS.orders.byPayment}?${query}`,
|
|
3069
|
+
void 0,
|
|
3070
|
+
{ method: "GET" }
|
|
3071
|
+
);
|
|
3072
|
+
}
|
|
3073
|
+
/**
|
|
3074
|
+
* Composed facade: confirm a provider payment, then resolve the
|
|
3075
|
+
* depth-populated order/transaction by the same payment id. `confirmPayment`'s
|
|
3076
|
+
* wire response carries only IDs (its contract is `.strict()`); this returns
|
|
3077
|
+
* the populated `Order` so storefronts stop reconstructing order state
|
|
3078
|
+
* locally. Two round trips by design — the alternative (widening the strict
|
|
3079
|
+
* confirm-payment wire contract to embed a full Order) is rejected.
|
|
3080
|
+
*/
|
|
3081
|
+
async confirmPaymentReturningOrder(params) {
|
|
3082
|
+
const confirmation = await this.confirmPayment(params);
|
|
3083
|
+
const { order, transaction } = await this.getByPaymentId({
|
|
3084
|
+
pgProvider: params.pgProvider,
|
|
3085
|
+
pgPaymentId: params.pgPaymentId
|
|
3086
|
+
});
|
|
3087
|
+
return { ...confirmation, order, transaction };
|
|
3088
|
+
}
|
|
2911
3089
|
cancelOrder(params) {
|
|
2912
3090
|
const { idempotencyKey } = params;
|
|
2913
3091
|
const body = {
|
|
@@ -2916,14 +3094,14 @@ var OrderApi = class extends BaseApi {
|
|
|
2916
3094
|
reasonDetail: params.reasonDetail
|
|
2917
3095
|
};
|
|
2918
3096
|
return this.request(
|
|
2919
|
-
|
|
3097
|
+
COMMERCE_ENDPOINTS.orders.cancel,
|
|
2920
3098
|
body,
|
|
2921
3099
|
idempotencyKey ? { headers: { "X-Idempotency-Key": idempotencyKey } } : void 0
|
|
2922
3100
|
);
|
|
2923
3101
|
}
|
|
2924
3102
|
resolveCancelRefund(params) {
|
|
2925
3103
|
return this.request(
|
|
2926
|
-
|
|
3104
|
+
COMMERCE_ENDPOINTS.orders.resolveCancelRefund,
|
|
2927
3105
|
{
|
|
2928
3106
|
orderNumber: params.orderNumber,
|
|
2929
3107
|
idempotencyKey: params.idempotencyKey,
|
|
@@ -2944,7 +3122,7 @@ var OrderApi = class extends BaseApi {
|
|
|
2944
3122
|
checkout(params) {
|
|
2945
3123
|
const { body, idempotencyKey } = splitIdempotencyKey(params);
|
|
2946
3124
|
return this.request(
|
|
2947
|
-
|
|
3125
|
+
COMMERCE_ENDPOINTS.orders.checkout,
|
|
2948
3126
|
body,
|
|
2949
3127
|
idempotencyRequestOptions(idempotencyKey)
|
|
2950
3128
|
);
|
|
@@ -2952,30 +3130,33 @@ var OrderApi = class extends BaseApi {
|
|
|
2952
3130
|
createFulfillment(params) {
|
|
2953
3131
|
const { body, idempotencyKey } = splitIdempotencyKey(params);
|
|
2954
3132
|
return this.request(
|
|
2955
|
-
|
|
3133
|
+
COMMERCE_ENDPOINTS.orders.createFulfillment,
|
|
2956
3134
|
body,
|
|
2957
3135
|
idempotencyRequestOptions(idempotencyKey)
|
|
2958
3136
|
);
|
|
2959
3137
|
}
|
|
2960
3138
|
prepareFulfillmentOrder(params) {
|
|
2961
3139
|
return this.request(
|
|
2962
|
-
|
|
3140
|
+
COMMERCE_ENDPOINTS.fulfillmentOrders.prepare,
|
|
2963
3141
|
params
|
|
2964
3142
|
);
|
|
2965
3143
|
}
|
|
2966
3144
|
updateFulfillment(params) {
|
|
2967
|
-
return this.request(
|
|
3145
|
+
return this.request(
|
|
3146
|
+
COMMERCE_ENDPOINTS.orders.updateFulfillment,
|
|
3147
|
+
params
|
|
3148
|
+
);
|
|
2968
3149
|
}
|
|
2969
3150
|
bulkImportFulfillments(params) {
|
|
2970
3151
|
return this.request(
|
|
2971
|
-
|
|
3152
|
+
COMMERCE_ENDPOINTS.fulfillments.bulkImport,
|
|
2972
3153
|
params
|
|
2973
3154
|
);
|
|
2974
3155
|
}
|
|
2975
3156
|
returnWithRefund(params) {
|
|
2976
3157
|
const { body, idempotencyKey } = splitIdempotencyKey(params);
|
|
2977
3158
|
return this.request(
|
|
2978
|
-
|
|
3159
|
+
COMMERCE_ENDPOINTS.returns.returnRefund,
|
|
2979
3160
|
body,
|
|
2980
3161
|
idempotencyRequestOptions(idempotencyKey)
|
|
2981
3162
|
);
|
|
@@ -2983,13 +3164,13 @@ var OrderApi = class extends BaseApi {
|
|
|
2983
3164
|
createReturn(params) {
|
|
2984
3165
|
const { body, idempotencyKey } = splitIdempotencyKey(params);
|
|
2985
3166
|
return this.request(
|
|
2986
|
-
|
|
3167
|
+
COMMERCE_ENDPOINTS.returns.create,
|
|
2987
3168
|
body,
|
|
2988
3169
|
idempotencyRequestOptions(idempotencyKey)
|
|
2989
3170
|
);
|
|
2990
3171
|
}
|
|
2991
3172
|
updateReturn(params) {
|
|
2992
|
-
return this.request(
|
|
3173
|
+
return this.request(COMMERCE_ENDPOINTS.returns.update, params);
|
|
2993
3174
|
}
|
|
2994
3175
|
};
|
|
2995
3176
|
|
|
@@ -3075,13 +3256,16 @@ var ServerCommerceClient = class {
|
|
|
3075
3256
|
upsert: productApi.upsert.bind(productApi)
|
|
3076
3257
|
};
|
|
3077
3258
|
this.cart = {
|
|
3259
|
+
create: cartApi.createCart.bind(cartApi),
|
|
3078
3260
|
get: cartApi.getCart.bind(cartApi),
|
|
3079
3261
|
addItem: cartApi.addItem.bind(cartApi),
|
|
3080
3262
|
updateItem: cartApi.updateItem.bind(cartApi),
|
|
3081
3263
|
removeItem: cartApi.removeItem.bind(cartApi),
|
|
3082
3264
|
applyDiscount: cartApi.applyDiscount.bind(cartApi),
|
|
3083
3265
|
removeDiscount: cartApi.removeDiscount.bind(cartApi),
|
|
3084
|
-
clear: cartApi.clearCart.bind(cartApi)
|
|
3266
|
+
clear: cartApi.clearCart.bind(cartApi),
|
|
3267
|
+
merge: cartApi.merge.bind(cartApi),
|
|
3268
|
+
mine: cartApi.mine.bind(cartApi)
|
|
3085
3269
|
};
|
|
3086
3270
|
this.orders = {
|
|
3087
3271
|
checkout: orderApi.checkout.bind(orderApi),
|
|
@@ -3089,6 +3273,8 @@ var ServerCommerceClient = class {
|
|
|
3089
3273
|
update: orderApi.updateOrder.bind(orderApi),
|
|
3090
3274
|
updateTransaction: orderApi.updateTransaction.bind(orderApi),
|
|
3091
3275
|
confirmPayment: orderApi.confirmPayment.bind(orderApi),
|
|
3276
|
+
confirmPaymentReturningOrder: orderApi.confirmPaymentReturningOrder.bind(orderApi),
|
|
3277
|
+
getByPaymentId: orderApi.getByPaymentId.bind(orderApi),
|
|
3092
3278
|
cancelOrder: orderApi.cancelOrder.bind(orderApi),
|
|
3093
3279
|
resolveCancelRefund: orderApi.resolveCancelRefund.bind(orderApi),
|
|
3094
3280
|
createFulfillment: orderApi.createFulfillment.bind(orderApi),
|