@replohq/sdk 2.20.2 → 2.20.3
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/cart/checkout-restart.d.ts +8 -0
- package/cart/checkout-restart.js +23 -0
- package/cart/checkout.js +19 -3
- package/lib/buildMetadata.js +3 -3
- package/package.json +4 -4
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const CHECKOUT_RESTART_STORAGE_KEY = "replo-checkout-restarted-at";
|
|
2
|
+
type RestartStorage = Pick<Storage, "getItem" | "setItem">;
|
|
3
|
+
/** True when the page should restart checkout now, recording that it did. */
|
|
4
|
+
export declare function claimCheckoutRestart({ getStorage, now, }: {
|
|
5
|
+
getStorage: () => RestartStorage;
|
|
6
|
+
now: number;
|
|
7
|
+
}): boolean;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const CHECKOUT_RESTART_STORAGE_KEY = "replo-checkout-restarted-at";
|
|
2
|
+
const RESTART_WINDOW_MS = 3e4;
|
|
3
|
+
function claimCheckoutRestart({
|
|
4
|
+
getStorage,
|
|
5
|
+
now
|
|
6
|
+
}) {
|
|
7
|
+
try {
|
|
8
|
+
const storage = getStorage();
|
|
9
|
+
const restartedAt = Number(storage.getItem(CHECKOUT_RESTART_STORAGE_KEY));
|
|
10
|
+
if (restartedAt > 0 && now - restartedAt < RESTART_WINDOW_MS) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
storage.setItem(CHECKOUT_RESTART_STORAGE_KEY, String(now));
|
|
14
|
+
return storage.getItem(CHECKOUT_RESTART_STORAGE_KEY) === String(now);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.warn("[Replo] Session storage is unavailable", error);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
CHECKOUT_RESTART_STORAGE_KEY,
|
|
22
|
+
claimCheckoutRestart
|
|
23
|
+
};
|
package/cart/checkout.js
CHANGED
|
@@ -14,6 +14,10 @@ import { CanopyError } from "../lib/canopy-error";
|
|
|
14
14
|
import { formatAmount } from "../money";
|
|
15
15
|
import { getCrossSellsAction } from "./checkout-actions";
|
|
16
16
|
import { readSiteCheckoutAppearance } from "./checkout-appearance";
|
|
17
|
+
import {
|
|
18
|
+
CHECKOUT_RESTART_STORAGE_KEY,
|
|
19
|
+
claimCheckoutRestart
|
|
20
|
+
} from "./checkout-restart";
|
|
17
21
|
import {
|
|
18
22
|
addCrossSellAction,
|
|
19
23
|
updateCheckoutShippingAction
|
|
@@ -75,6 +79,7 @@ function readCheckoutConfig() {
|
|
|
75
79
|
writeStorage(CONFIG_STORAGE_KEY, null);
|
|
76
80
|
} else if (fragment) {
|
|
77
81
|
writeStorage(CONFIG_STORAGE_KEY, fragment);
|
|
82
|
+
writeStorage(CHECKOUT_RESTART_STORAGE_KEY, null);
|
|
78
83
|
}
|
|
79
84
|
if (fragment) {
|
|
80
85
|
window.history.replaceState(
|
|
@@ -98,14 +103,22 @@ function readCheckoutConfig() {
|
|
|
98
103
|
return parsed.success ? parsed.output : "missing";
|
|
99
104
|
}
|
|
100
105
|
let loadedCheckout = null;
|
|
101
|
-
function getLoadedCheckout() {
|
|
106
|
+
function getLoadedCheckout(startCheckoutPath) {
|
|
102
107
|
const fragment = window.location.hash;
|
|
103
108
|
if (!loadedCheckout || fragment && fragment !== loadedCheckout.fragment) {
|
|
104
109
|
const config = readCheckoutConfig();
|
|
110
|
+
const shouldRestartCheckout = config === "missing" && claimCheckoutRestart({
|
|
111
|
+
getStorage: () => sessionStorage,
|
|
112
|
+
now: Date.now()
|
|
113
|
+
});
|
|
114
|
+
if (shouldRestartCheckout) {
|
|
115
|
+
window.location.assign(startCheckoutPath);
|
|
116
|
+
}
|
|
105
117
|
loadedCheckout = {
|
|
106
118
|
fragment,
|
|
107
119
|
value: {
|
|
108
120
|
config,
|
|
121
|
+
shouldRestartCheckout,
|
|
109
122
|
stripe: typeof config === "string" ? null : loadStripe(config.publishableKey, {
|
|
110
123
|
stripeAccount: config.stripeAccountId
|
|
111
124
|
}),
|
|
@@ -341,7 +354,7 @@ function CheckoutSessionProvider({
|
|
|
341
354
|
}) {
|
|
342
355
|
const loaded = React.useSyncExternalStore(
|
|
343
356
|
subscribeToNothing,
|
|
344
|
-
getLoadedCheckout,
|
|
357
|
+
() => getLoadedCheckout(startCheckoutPath),
|
|
345
358
|
() => null
|
|
346
359
|
);
|
|
347
360
|
const retry = () => {
|
|
@@ -356,7 +369,10 @@ function CheckoutSessionProvider({
|
|
|
356
369
|
return /* @__PURE__ */ jsx(
|
|
357
370
|
CheckoutSessionContext.Provider,
|
|
358
371
|
{
|
|
359
|
-
value: {
|
|
372
|
+
value: {
|
|
373
|
+
state: loaded && !loaded.shouldRestartCheckout ? state : { status: "loading" },
|
|
374
|
+
form: null
|
|
375
|
+
},
|
|
360
376
|
children
|
|
361
377
|
}
|
|
362
378
|
);
|
package/lib/buildMetadata.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const BUILD_METADATA = {
|
|
2
2
|
"packageName": "@replohq/sdk",
|
|
3
|
-
"version": "2.20.
|
|
3
|
+
"version": "2.20.3",
|
|
4
4
|
"branch": "HEAD",
|
|
5
|
-
"commit": "
|
|
6
|
-
"builtAt": "2026-11-
|
|
5
|
+
"commit": "f4d42a40b0c8d0a03eb9e295f7c8aa0ae2ed6512",
|
|
6
|
+
"builtAt": "2026-11-08T00:27:06.748Z"
|
|
7
7
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replohq/sdk",
|
|
3
|
-
"version": "2.20.
|
|
3
|
+
"version": "2.20.3",
|
|
4
4
|
"reploBuild": {
|
|
5
5
|
"packageName": "@replohq/sdk",
|
|
6
|
-
"version": "2.20.
|
|
6
|
+
"version": "2.20.3",
|
|
7
7
|
"branch": "HEAD",
|
|
8
|
-
"commit": "
|
|
9
|
-
"builtAt": "2026-11-
|
|
8
|
+
"commit": "f4d42a40b0c8d0a03eb9e295f7c8aa0ae2ed6512",
|
|
9
|
+
"builtAt": "2026-11-08T00:27:06.748Z"
|
|
10
10
|
},
|
|
11
11
|
"description": "Replo SDK — cart, analytics, and data loaders for agent-built Next.js sites.",
|
|
12
12
|
"license": "SEE LICENSE IN LICENSE",
|