@eetech-commerce/cart-react 0.4.2 → 0.4.4
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.ts +56 -8
- package/dist/index.js +40 -45
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { loadStripe } from '@stripe/stripe-js';
|
|
3
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
5
|
import react from 'react';
|
|
5
6
|
|
|
@@ -22,6 +23,48 @@ interface CartContextValue {
|
|
|
22
23
|
}
|
|
23
24
|
declare function useCartContext(): CartContextValue;
|
|
24
25
|
|
|
26
|
+
type ShippingSelection = {
|
|
27
|
+
/**
|
|
28
|
+
* Seller UUID this selection applies to
|
|
29
|
+
*/
|
|
30
|
+
sellerId: string;
|
|
31
|
+
/**
|
|
32
|
+
* Selected delivery method UUID from MarketPush
|
|
33
|
+
*/
|
|
34
|
+
deliveryMethodId: string;
|
|
35
|
+
/**
|
|
36
|
+
* Delivery method display name
|
|
37
|
+
*/
|
|
38
|
+
deliveryMethodName: string;
|
|
39
|
+
/**
|
|
40
|
+
* Selected carrier UUID from MarketPush
|
|
41
|
+
*/
|
|
42
|
+
carrierId: string;
|
|
43
|
+
/**
|
|
44
|
+
* Carrier display name
|
|
45
|
+
*/
|
|
46
|
+
carrierName: string;
|
|
47
|
+
/**
|
|
48
|
+
* Carrier API key for order submission
|
|
49
|
+
*/
|
|
50
|
+
carrierKey: string;
|
|
51
|
+
/**
|
|
52
|
+
* MarketPush shipping rate ID used for this selection
|
|
53
|
+
*/
|
|
54
|
+
shippingRateId: string;
|
|
55
|
+
/**
|
|
56
|
+
* Calculated shipping cost in cents (integer)
|
|
57
|
+
*/
|
|
58
|
+
shippingCostCents: number;
|
|
59
|
+
/**
|
|
60
|
+
* Optional carrier account identifier (max 50 chars)
|
|
61
|
+
*/
|
|
62
|
+
carrierAccount?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Timestamp when selection was made (ISO 8601)
|
|
65
|
+
*/
|
|
66
|
+
selectedAt: string;
|
|
67
|
+
};
|
|
25
68
|
type TaxJurisdictionDto = {
|
|
26
69
|
/**
|
|
27
70
|
* ISO 3166-1 alpha-2 country code
|
|
@@ -267,9 +310,7 @@ type CartResponseDto = {
|
|
|
267
310
|
* Shipping selections by seller ID - present when shipping methods selected
|
|
268
311
|
*/
|
|
269
312
|
shippingSelections?: {
|
|
270
|
-
[key: string]:
|
|
271
|
-
[key: string]: unknown;
|
|
272
|
-
};
|
|
313
|
+
[key: string]: ShippingSelection;
|
|
273
314
|
} | null;
|
|
274
315
|
/**
|
|
275
316
|
* Purchase order number
|
|
@@ -489,9 +530,7 @@ type ShippingSelectionsResponseDto = {
|
|
|
489
530
|
* Shipping selections by seller ID
|
|
490
531
|
*/
|
|
491
532
|
shippingSelections: {
|
|
492
|
-
[key: string]:
|
|
493
|
-
[key: string]: unknown;
|
|
494
|
-
};
|
|
533
|
+
[key: string]: ShippingSelection;
|
|
495
534
|
};
|
|
496
535
|
};
|
|
497
536
|
type PaymentSessionResponseDto = {
|
|
@@ -624,7 +663,16 @@ declare function useUpdateShippingSelections(): {
|
|
|
624
663
|
error: Error | null;
|
|
625
664
|
};
|
|
626
665
|
|
|
627
|
-
|
|
666
|
+
/**
|
|
667
|
+
* Type for the loadStripe function from @stripe/stripe-js
|
|
668
|
+
*/
|
|
669
|
+
type LoadStripeFn = typeof loadStripe;
|
|
670
|
+
/**
|
|
671
|
+
* Hook to initialize Stripe with the tenant's publishable key.
|
|
672
|
+
* @param loadStripe - The loadStripe function from @stripe/stripe-js
|
|
673
|
+
* @returns A promise that resolves to the Stripe instance, or null if not ready
|
|
674
|
+
*/
|
|
675
|
+
declare function useStripePromise(loadStripe: LoadStripeFn): ReturnType<LoadStripeFn> | null;
|
|
628
676
|
declare function useCreateEmbeddedCheckoutSession(): {
|
|
629
677
|
createEmbeddedCheckoutSession: (params: CreateEmbeddedPaymentSessionDto, callbacks?: MutationCallbacks<EmbeddedPaymentSessionResponseDto>) => void;
|
|
630
678
|
isPending: boolean;
|
|
@@ -660,4 +708,4 @@ interface CartProviderProps {
|
|
|
660
708
|
}
|
|
661
709
|
declare function CartProvider({ children, tenantSlug, cartApiUrl, storageAdapter, autoInitialize, queryClient, }: CartProviderProps): react_jsx_runtime.JSX.Element;
|
|
662
710
|
|
|
663
|
-
export { type CartContextValue, CartProvider, type CartProviderProps, type CartResponseDto, type CreateCheckoutDto, type CreateEmbeddedPaymentSessionDto, type EmbeddedPaymentSessionResponseDto, type LineItemResponseDto, type MutationCallbacks, type ShippingOptionDto, type ShippingSelectionDto, type StorageAdapter, type VerificationResultDto, cartKeys, localStorageAdapter, paymentKeys, shippingKeys, useAddToCart, useCart, useCartContext, useClearCart, useCreateCart, useCreateCheckoutSession, useCreateEmbeddedCheckoutSession, useInitializeCart, usePaymentSession, useRemoveItem, useShippingOptions, useStripePromise, useUpdateItemQty, useUpdateShippingSelections, useVerifyCart };
|
|
711
|
+
export { type CartContextValue, CartProvider, type CartProviderProps, type CartResponseDto, type CreateCheckoutDto, type CreateEmbeddedPaymentSessionDto, type EmbeddedPaymentSessionResponseDto, type LineItemResponseDto, type LoadStripeFn, type MutationCallbacks, type ShippingOptionDto, type ShippingSelectionDto, type StorageAdapter, type VerificationResultDto, cartKeys, localStorageAdapter, paymentKeys, shippingKeys, useAddToCart, useCart, useCartContext, useClearCart, useCreateCart, useCreateCheckoutSession, useCreateEmbeddedCheckoutSession, useInitializeCart, usePaymentSession, useRemoveItem, useShippingOptions, useStripePromise, useUpdateItemQty, useUpdateShippingSelections, useVerifyCart };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
1
|
// src/adapters/localStorage.ts
|
|
9
2
|
var localStorageAdapter = {
|
|
10
3
|
get(key) {
|
|
@@ -41,7 +34,10 @@ import { queryOptions } from "@tanstack/react-query";
|
|
|
41
34
|
|
|
42
35
|
// src/generated/core/bodySerializer.gen.ts
|
|
43
36
|
var jsonBodySerializer = {
|
|
44
|
-
bodySerializer: (body) => JSON.stringify(
|
|
37
|
+
bodySerializer: (body) => JSON.stringify(
|
|
38
|
+
body,
|
|
39
|
+
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
40
|
+
)
|
|
45
41
|
};
|
|
46
42
|
|
|
47
43
|
// src/generated/core/params.gen.ts
|
|
@@ -94,7 +90,10 @@ var createSseClient = ({
|
|
|
94
90
|
}
|
|
95
91
|
const _fetch = options.fetch ?? globalThis.fetch;
|
|
96
92
|
const response = await _fetch(request);
|
|
97
|
-
if (!response.ok)
|
|
93
|
+
if (!response.ok)
|
|
94
|
+
throw new Error(
|
|
95
|
+
`SSE failed: ${response.status} ${response.statusText}`
|
|
96
|
+
);
|
|
98
97
|
if (!response.body) throw new Error("No body in SSE response");
|
|
99
98
|
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
100
99
|
let buffer = "";
|
|
@@ -124,7 +123,10 @@ var createSseClient = ({
|
|
|
124
123
|
} else if (line.startsWith("id:")) {
|
|
125
124
|
lastEventId = line.replace(/^id:\s*/, "");
|
|
126
125
|
} else if (line.startsWith("retry:")) {
|
|
127
|
-
const parsed = Number.parseInt(
|
|
126
|
+
const parsed = Number.parseInt(
|
|
127
|
+
line.replace(/^retry:\s*/, ""),
|
|
128
|
+
10
|
|
129
|
+
);
|
|
128
130
|
if (!Number.isNaN(parsed)) {
|
|
129
131
|
retryDelay = parsed;
|
|
130
132
|
}
|
|
@@ -170,7 +172,10 @@ var createSseClient = ({
|
|
|
170
172
|
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
171
173
|
break;
|
|
172
174
|
}
|
|
173
|
-
const backoff = Math.min(
|
|
175
|
+
const backoff = Math.min(
|
|
176
|
+
retryDelay * 2 ** (attempt - 1),
|
|
177
|
+
sseMaxRetryDelay ?? 3e4
|
|
178
|
+
);
|
|
174
179
|
await sleep(backoff);
|
|
175
180
|
}
|
|
176
181
|
}
|
|
@@ -278,7 +283,11 @@ var serializeObjectParam = ({
|
|
|
278
283
|
if (style !== "deepObject" && !explode) {
|
|
279
284
|
let values = [];
|
|
280
285
|
Object.entries(value).forEach(([key, v]) => {
|
|
281
|
-
values = [
|
|
286
|
+
values = [
|
|
287
|
+
...values,
|
|
288
|
+
key,
|
|
289
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
290
|
+
];
|
|
282
291
|
});
|
|
283
292
|
const joinedValues2 = values.join(",");
|
|
284
293
|
switch (style) {
|
|
@@ -329,7 +338,10 @@ var defaultPathSerializer = ({ path, url: _url }) => {
|
|
|
329
338
|
continue;
|
|
330
339
|
}
|
|
331
340
|
if (Array.isArray(value)) {
|
|
332
|
-
url = url.replace(
|
|
341
|
+
url = url.replace(
|
|
342
|
+
match,
|
|
343
|
+
serializeArrayParam({ explode, name, style, value })
|
|
344
|
+
);
|
|
333
345
|
continue;
|
|
334
346
|
}
|
|
335
347
|
if (typeof value === "object") {
|
|
@@ -477,7 +489,9 @@ var getParseAs = (contentType) => {
|
|
|
477
489
|
if (cleanContent === "multipart/form-data") {
|
|
478
490
|
return "formData";
|
|
479
491
|
}
|
|
480
|
-
if (["application/", "audio/", "image/", "video/"].some(
|
|
492
|
+
if (["application/", "audio/", "image/", "video/"].some(
|
|
493
|
+
(type) => cleanContent.startsWith(type)
|
|
494
|
+
)) {
|
|
481
495
|
return "blob";
|
|
482
496
|
}
|
|
483
497
|
if (cleanContent.startsWith("text/")) {
|
|
@@ -689,7 +703,12 @@ var createClient = (config = {}) => {
|
|
|
689
703
|
let finalError2 = error2;
|
|
690
704
|
for (const fn of interceptors.error.fns) {
|
|
691
705
|
if (fn) {
|
|
692
|
-
finalError2 = await fn(
|
|
706
|
+
finalError2 = await fn(
|
|
707
|
+
error2,
|
|
708
|
+
void 0,
|
|
709
|
+
request2,
|
|
710
|
+
opts
|
|
711
|
+
);
|
|
693
712
|
}
|
|
694
713
|
}
|
|
695
714
|
finalError2 = finalError2 || {};
|
|
@@ -949,10 +968,7 @@ var paymentControllerGetPaymentSessionV1 = (options) => {
|
|
|
949
968
|
|
|
950
969
|
// src/generated/@tanstack/react-query.gen.ts
|
|
951
970
|
var createQueryKey = (id, options, infinite, tags) => {
|
|
952
|
-
const params = {
|
|
953
|
-
_id: id,
|
|
954
|
-
baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl
|
|
955
|
-
};
|
|
971
|
+
const params = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl };
|
|
956
972
|
if (infinite) {
|
|
957
973
|
params._infinite = infinite;
|
|
958
974
|
}
|
|
@@ -971,7 +987,9 @@ var createQueryKey = (id, options, infinite, tags) => {
|
|
|
971
987
|
if (options?.query) {
|
|
972
988
|
params.query = options.query;
|
|
973
989
|
}
|
|
974
|
-
return [
|
|
990
|
+
return [
|
|
991
|
+
params
|
|
992
|
+
];
|
|
975
993
|
};
|
|
976
994
|
var cartControllerCreateCartV1Mutation = (options) => {
|
|
977
995
|
const mutationOptions = {
|
|
@@ -1495,23 +1513,7 @@ function useUpdateShippingSelections() {
|
|
|
1495
1513
|
// src/hooks/payment.ts
|
|
1496
1514
|
import { useMutation as useMutation3, useQuery as useQuery3 } from "@tanstack/react-query";
|
|
1497
1515
|
import { useCallback as useCallback3, useMemo } from "react";
|
|
1498
|
-
|
|
1499
|
-
var _stripeLoadAttempted = false;
|
|
1500
|
-
function getStripeLoader() {
|
|
1501
|
-
if (_stripeLoadAttempted) {
|
|
1502
|
-
return _loadStripe;
|
|
1503
|
-
}
|
|
1504
|
-
_stripeLoadAttempted = true;
|
|
1505
|
-
try {
|
|
1506
|
-
const { loadStripe } = __require("@stripe/stripe-js");
|
|
1507
|
-
_loadStripe = loadStripe;
|
|
1508
|
-
return _loadStripe;
|
|
1509
|
-
} catch {
|
|
1510
|
-
_loadStripe = null;
|
|
1511
|
-
return null;
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
function useStripePromise() {
|
|
1516
|
+
function useStripePromise(loadStripe) {
|
|
1515
1517
|
const { tenantSlug, cartApiUrl } = useCartContext();
|
|
1516
1518
|
const { data: tenantPublicKey } = useQuery3({
|
|
1517
1519
|
...tenantPublicControllerGetPublicKeyV1Options({
|
|
@@ -1526,15 +1528,8 @@ function useStripePromise() {
|
|
|
1526
1528
|
const stripePromise = useMemo(() => {
|
|
1527
1529
|
const publishableKey = tenantPublicKey?.value;
|
|
1528
1530
|
if (!publishableKey) return null;
|
|
1529
|
-
const loadStripe = getStripeLoader();
|
|
1530
|
-
if (!loadStripe) {
|
|
1531
|
-
console.error(
|
|
1532
|
-
"useStripePromise: @stripe/stripe-js is not installed. Install it with: npm install @stripe/stripe-js"
|
|
1533
|
-
);
|
|
1534
|
-
return null;
|
|
1535
|
-
}
|
|
1536
1531
|
return loadStripe(publishableKey);
|
|
1537
|
-
}, [tenantPublicKey?.value]);
|
|
1532
|
+
}, [tenantPublicKey?.value, loadStripe]);
|
|
1538
1533
|
return stripePromise;
|
|
1539
1534
|
}
|
|
1540
1535
|
function useCreateEmbeddedCheckoutSession() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eetech-commerce/cart-react",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@hey-api/client-fetch": "^0.13.0",
|
|
42
42
|
"@hey-api/openapi-ts": "0.87.5",
|
|
43
|
+
"@stripe/stripe-js": ">=2.0.0",
|
|
43
44
|
"@testing-library/react": "^16.0.0",
|
|
44
45
|
"@types/react": "^18.0.0",
|
|
45
46
|
"@types/react-dom": "^18.0.0",
|