@shop-on/theme-server 0.10.0 → 0.11.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/dist/account-state.js +1 -2
- package/dist/account.d.ts +1 -3
- package/dist/account.js +1 -3
- package/dist/activity.d.ts +1 -3
- package/dist/activity.js +1 -2
- package/dist/analytics-proxy.d.ts +8 -14
- package/dist/analytics-proxy.js +111 -28
- package/dist/analytics-script-proxy.d.ts +1 -5
- package/dist/analytics-script-proxy.js +4 -14
- package/dist/api-contract/src/addresses.js +32 -0
- package/dist/api-contract/src/areas.js +49 -0
- package/dist/api-contract/src/custom-data.d.ts +31 -0
- package/dist/api-contract/src/custom-data.js +303 -0
- package/dist/api-contract/src/ids.js +110 -0
- package/dist/api-contract/src/image.js +65 -0
- package/dist/api-contract/src/limits.js +44 -0
- package/dist/api-contract/src/media.js +13 -0
- package/dist/api-contract/src/pickup.js +11 -0
- package/dist/api-contract/src/recommendations.js +4 -0
- package/dist/api-contract/src/shops.js +27 -0
- package/dist/api-contract/src/storefront/analytics.d.ts +100 -0
- package/dist/api-contract/src/storefront/analytics.js +138 -0
- package/dist/api-contract/src/storefront/areas.d.ts +2 -0
- package/dist/api-contract/src/storefront/cart.d.ts +132 -0
- package/dist/api-contract/src/storefront/cart.js +248 -0
- package/dist/api-contract/src/storefront/catalog.d.ts +3 -0
- package/dist/api-contract/src/storefront/checkout-analytics.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.js +624 -0
- package/dist/api-contract/src/storefront/client.d.ts +3 -0
- package/dist/api-contract/src/storefront/client.js +6 -0
- package/dist/api-contract/src/storefront/content.d.ts +3 -0
- package/dist/api-contract/src/storefront/custom-data.d.ts +2 -0
- package/dist/api-contract/src/storefront/custom-data.js +27 -0
- package/dist/api-contract/src/storefront/customer.d.ts +2 -0
- package/dist/api-contract/src/storefront/customer.js +261 -0
- package/dist/api-contract/src/storefront/downloads.d.ts +2 -0
- package/dist/api-contract/src/storefront/draft-order-invoice.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.js +82 -0
- package/dist/api-contract/src/storefront/index.d.ts +20956 -0
- package/dist/api-contract/src/storefront/orders.d.ts +2 -0
- package/dist/api-contract/src/storefront/policies.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.js +29 -0
- package/dist/api-contract/src/storefront/reviews.d.ts +20 -0
- package/dist/api-contract/src/storefront/search.d.ts +3 -0
- package/dist/api-contract/src/storefront/seo.d.ts +2 -0
- package/dist/api-contract/src/storefront/seo.js +132 -0
- package/dist/api-contract/src/storefront/shop.d.ts +2 -0
- package/dist/api-contract/src/storefront/shop.js +101 -0
- package/dist/api-contract/src/taxonomy.js +5 -0
- package/dist/api-contract/src/text.js +15 -0
- package/dist/api-contract/src/theme-documents.js +13 -0
- package/dist/api-contract/src/theme-translations.d.ts +14 -0
- package/dist/api-contract/src/theme-translations.js +30 -0
- package/dist/api-contract/src/video.js +19 -0
- package/dist/availability.d.ts +6 -3
- package/dist/availability.js +11 -5
- package/dist/blog.d.ts +53 -59
- package/dist/blog.js +197 -497
- package/dist/cache.d.ts +5 -6
- package/dist/cache.js +1 -2
- package/dist/canonical-host.d.ts +4 -6
- package/dist/canonical-host.js +5 -6
- package/dist/card.js +159 -0
- package/dist/cart-customer.d.ts +1 -3
- package/dist/cart-customer.js +64 -105
- package/dist/cart-mutations.d.ts +43 -77
- package/dist/cart-mutations.js +106 -232
- package/dist/cart-recommendations.d.ts +1 -3
- package/dist/cart-recommendations.js +1 -2
- package/dist/cart-session.d.ts +1 -3
- package/dist/cart-session.js +1 -2
- package/dist/cart.d.ts +63 -224
- package/dist/cart.js +70 -197
- package/dist/checkout.d.ts +13 -17
- package/dist/checkout.js +75 -101
- package/dist/coalesce.js +57 -0
- package/dist/collection.d.ts +89 -298
- package/dist/collection.js +210 -656
- package/dist/contact.d.ts +20 -10
- package/dist/contact.js +36 -30
- package/dist/content-version.d.ts +37 -21
- package/dist/content-version.js +64 -42
- package/dist/contract-kit/src/client.d.ts +12 -0
- package/dist/contract-kit/src/client.js +156 -0
- package/dist/contract-kit/src/errors.d.ts +1 -0
- package/dist/contract-kit/src/errors.js +81 -0
- package/dist/contract-kit/src/ids.d.ts +1 -0
- package/dist/contract-kit/src/ids.js +118 -0
- package/dist/contract-kit/src/index.d.ts +7 -0
- package/dist/contract-kit/src/money.d.ts +1 -0
- package/dist/contract-kit/src/money.js +10 -0
- package/dist/contract-kit/src/pagination.d.ts +1 -0
- package/dist/contract-kit/src/procedure.d.ts +69 -0
- package/dist/contract-kit/src/procedure.js +16 -0
- package/dist/contract-kit/src/realtime.d.ts +1 -0
- package/dist/cookie-secret.js +1 -2
- package/dist/csrf.js +1 -2
- package/dist/customer-handoff.d.ts +1 -3
- package/dist/customer-handoff.js +10 -25
- package/dist/customer-session.d.ts +1 -3
- package/dist/customer-session.js +1 -2
- package/dist/customer.d.ts +2 -3
- package/dist/customer.js +27 -44
- package/dist/files.d.ts +49 -10
- package/dist/files.js +106 -89
- package/dist/fonts.d.ts +3 -5
- package/dist/fonts.js +16 -35
- package/dist/html.d.ts +1 -3
- package/dist/html.js +1 -2
- package/dist/liquid.d.ts +4 -10
- package/dist/liquid.js +25 -32
- package/dist/listing.js +79 -0
- package/dist/marketing-cookies.d.ts +1 -3
- package/dist/marketing-cookies.js +1 -2
- package/dist/menu.d.ts +46 -155
- package/dist/menu.js +51 -61
- package/dist/metafields.d.ts +9 -5
- package/dist/metafields.js +10 -38
- package/dist/metaobject.d.ts +10 -5
- package/dist/metaobject.js +43 -66
- package/dist/money.d.ts +7 -0
- package/dist/money.js +18 -0
- package/dist/newsletter.d.ts +19 -10
- package/dist/newsletter.js +31 -25
- package/dist/page.d.ts +13 -17
- package/dist/page.js +49 -105
- package/dist/password-session.d.ts +1 -3
- package/dist/password-session.js +1 -2
- package/dist/password.d.ts +25 -18
- package/dist/password.js +41 -59
- package/dist/policy.d.ts +7 -7
- package/dist/policy.js +19 -55
- package/dist/product.d.ts +42 -67
- package/dist/product.js +144 -644
- package/dist/read-ahead.d.ts +18 -0
- package/dist/read-ahead.js +32 -0
- package/dist/recommendations.d.ts +6 -12
- package/dist/recommendations.js +36 -60
- package/dist/review.d.ts +134 -94
- package/dist/review.js +257 -469
- package/dist/search.d.ts +59 -64
- package/dist/search.js +170 -469
- package/dist/seo-context.d.ts +1 -3
- package/dist/seo-context.js +4 -5
- package/dist/seo-documents.d.ts +50 -0
- package/dist/seo-documents.js +149 -0
- package/dist/shop-seo.d.ts +3 -5
- package/dist/shop-seo.js +7 -26
- package/dist/shop.d.ts +38 -42
- package/dist/shop.js +37 -51
- package/dist/store-availability.d.ts +12 -14
- package/dist/store-availability.js +18 -56
- package/dist/storefront.js +199 -0
- package/dist/structured-data.d.ts +3 -28
- package/dist/structured-data.js +19 -49
- package/dist/trace.js +1 -2
- package/dist/translations.d.ts +26 -31
- package/dist/translations.js +55 -28
- package/package.json +16 -14
- package/dist/graphql-env.d.ts +0 -22778
- package/dist/graphql.d.ts +0 -64
- package/dist/graphql.js +0 -344
- package/dist/schema.storefront.graphql +0 -10483
- package/dist/seo-proxy.d.ts +0 -11
- package/dist/seo-proxy.js +0 -26
package/dist/checkout.js
CHANGED
|
@@ -1,119 +1,93 @@
|
|
|
1
|
-
import { graphql, request } from "./graphql.js";
|
|
2
|
-
import { fetchShopInfo } from "./shop.js";
|
|
3
1
|
import { useCartSession } from "./cart-session.js";
|
|
2
|
+
import { readCustomerSession } from "./customer-session.js";
|
|
3
|
+
import { escapeHtmlAttr } from "./html.js";
|
|
4
4
|
import { parseMarketingCookies } from "./marketing-cookies.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
cartCheckout(input: $input) {
|
|
11
|
-
checkoutUrl
|
|
12
|
-
userErrors {
|
|
13
|
-
code
|
|
14
|
-
field
|
|
15
|
-
message
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
`);
|
|
20
|
-
const readMarketingAttribution = createServerOnlyFn(async () => {
|
|
21
|
-
try {
|
|
22
|
-
const { getRequest } = await import("@tanstack/react-start/server");
|
|
23
|
-
const cookies = parseMarketingCookies(getRequest().headers.get("cookie"));
|
|
24
|
-
return Object.keys(cookies).length > 0 ? cookies : null;
|
|
25
|
-
} catch (err) {
|
|
26
|
-
console.warn("[checkout] marketing attribution unavailable:", err);
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
function publicCheckoutUrl(origin) {
|
|
31
|
-
const url = new URL("/checkout", origin);
|
|
32
|
-
if (!isLoopback(url.hostname)) url.protocol = "https:";
|
|
33
|
-
return url.toString();
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* The theme's `/checkout`, both passes. `state` is the URL's `checkout_state`,
|
|
37
|
-
* a REQUIRED key even when `undefined`: a caller that never passed it would
|
|
38
|
-
* bounce theme ↔ `/begin` forever, and this way that is a compile error.
|
|
39
|
-
*
|
|
40
|
-
* - No state: the URL of checkout's `/begin`, which binds this browser and
|
|
41
|
-
* returns the buyer here with one. Mints nothing.
|
|
42
|
-
* - A state: mint the cart handoff with it (`mintCheckoutHandoff`).
|
|
43
|
-
*
|
|
44
|
-
* The customer-session token is injected: forwarded as `X-Customer-Session` on
|
|
45
|
-
* the mint so Rails folds the buyer into the handoff payload in one trip.
|
|
46
|
-
*/
|
|
47
|
-
function startCheckoutHandoff(opts) {
|
|
48
|
-
return opts.state === void 0 ? beginCheckoutUrl() : mintCheckoutHandoff({
|
|
49
|
-
state: opts.state,
|
|
50
|
-
customerToken: opts.customerToken
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
async function beginCheckoutUrl() {
|
|
5
|
+
import { fetchShopInfo } from "./shop.js";
|
|
6
|
+
import { buyerStorefront, errorCode, storefront } from "./storefront.js";
|
|
7
|
+
// src/checkout.ts
|
|
8
|
+
/** Whether this buyer has a cart to check out, and where to go with it: the theme's `/checkout`. */
|
|
9
|
+
async function checkoutEntry() {
|
|
54
10
|
if (!(await useCartSession()).data.token) return {
|
|
55
11
|
ok: false,
|
|
56
12
|
reason: "no_cart"
|
|
57
13
|
};
|
|
58
|
-
await markResponsePrivate();
|
|
59
|
-
const shop = await fetchShopInfo();
|
|
60
|
-
if (!shop) throw new Error("[checkout] shop info unavailable from Rails");
|
|
61
14
|
const { getPublicOrigin } = await import("./seo-context.js");
|
|
62
|
-
const url = new URL(`${shop.checkoutUrl}/begin`);
|
|
63
|
-
url.searchParams.set("return_to", publicCheckoutUrl(getPublicOrigin()));
|
|
64
15
|
return {
|
|
65
16
|
ok: true,
|
|
66
|
-
redirectTo:
|
|
17
|
+
redirectTo: new URL("/checkout", getPublicOrigin()).toString()
|
|
67
18
|
};
|
|
68
19
|
}
|
|
20
|
+
const PRIVATE_HEADERS = {
|
|
21
|
+
"Cache-Control": "no-store",
|
|
22
|
+
"Referrer-Policy": "no-referrer"
|
|
23
|
+
};
|
|
24
|
+
function redirectTo(location) {
|
|
25
|
+
return new Response(null, {
|
|
26
|
+
status: 303,
|
|
27
|
+
headers: {
|
|
28
|
+
Location: location,
|
|
29
|
+
...PRIVATE_HEADERS
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
69
33
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* bounced to `/begin` again, so it can't loop). Any other userError code is
|
|
76
|
-
* unexpected and throws (matching `request`'s retry-once-then-throw contract
|
|
77
|
-
* for top-level GraphQL errors); the calling route sends the buyer home rather
|
|
78
|
-
* than render on a URL holding a state.
|
|
34
|
+
* The theme's `GET /{-$locale}/checkout`. A preview (`?preview`) is a 404;
|
|
35
|
+
* a buyer with no cart, an unknown or expired one, or an empty one goes to
|
|
36
|
+
* the storefront's home; a cart already being paid goes to the checkout
|
|
37
|
+
* app, whose cookie still opens its checkout. Anything else the api refuses
|
|
38
|
+
* is thrown (the theme's 500).
|
|
79
39
|
*/
|
|
80
|
-
async function
|
|
40
|
+
async function handleCheckoutGet(request, { locale }) {
|
|
41
|
+
if (new URL(request.url).searchParams.has("preview")) return new Response("Not Found", { status: 404 });
|
|
42
|
+
const home = locale ? `/${locale}` : "/";
|
|
81
43
|
const cartToken = (await useCartSession()).data.token;
|
|
82
|
-
if (!cartToken) return
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
ts: Date.now()
|
|
44
|
+
if (!cartToken) return redirectTo(home);
|
|
45
|
+
const shop = await fetchShopInfo();
|
|
46
|
+
const attribution = parseMarketingCookies(request.headers.get("cookie"));
|
|
47
|
+
let token;
|
|
48
|
+
try {
|
|
49
|
+
({token} = await storefront(locale).checkout.start({
|
|
50
|
+
cartToken,
|
|
51
|
+
...Object.keys(attribution).length > 0 ? { attribution } : {}
|
|
91
52
|
}));
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
53
|
+
} catch (error) {
|
|
54
|
+
const code = errorCode(error);
|
|
55
|
+
const condition = error.data?.condition;
|
|
56
|
+
if (code === "NOT_FOUND" || condition === "sales.cart_empty") return redirectTo(home);
|
|
57
|
+
if (condition === "sales.cart_paying") return redirectTo(shop.checkoutUrl);
|
|
58
|
+
throw error;
|
|
96
59
|
}
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
60
|
+
const handoff = await customerHandoff();
|
|
61
|
+
return new Response(renderCheckoutHandoffForm(`${shop.checkoutUrl}/begin`, token, handoff), {
|
|
62
|
+
status: 200,
|
|
63
|
+
headers: {
|
|
64
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
65
|
+
"Cache-Control": "no-store",
|
|
66
|
+
"Referrer-Policy": "strict-origin"
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** A handoff token for the signed-in buyer's session, or null for a guest or a session the api refuses. */
|
|
71
|
+
async function customerHandoff() {
|
|
72
|
+
const session = await readCustomerSession();
|
|
73
|
+
if (!session?.token) return null;
|
|
74
|
+
try {
|
|
75
|
+
return (await buyerStorefront(session.token).customer.handoff.create({})).token;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (errorCode(error) === "UNAUTHENTICATED") return null;
|
|
78
|
+
throw error;
|
|
110
79
|
}
|
|
111
|
-
const bound = new URL(checkoutUrl);
|
|
112
|
-
bound.searchParams.set("checkout_state", opts.state);
|
|
113
|
-
return {
|
|
114
|
-
ok: true,
|
|
115
|
-
redirectTo: bound.toString()
|
|
116
|
-
};
|
|
117
80
|
}
|
|
118
|
-
|
|
119
|
-
|
|
81
|
+
/** The page that POSTs the checkout token, and a signed-in buyer's handoff token, to the checkout app's `/begin`. Pure. */
|
|
82
|
+
function renderCheckoutHandoffForm(beginUrl, token, customerHandoff) {
|
|
83
|
+
const handoff = customerHandoff ? `\n <input type="hidden" name="customer_handoff" value="${escapeHtmlAttr(customerHandoff)}">` : "";
|
|
84
|
+
return `<!DOCTYPE html>
|
|
85
|
+
<html><body>
|
|
86
|
+
<form action="${escapeHtmlAttr(beginUrl)}" method="POST">
|
|
87
|
+
<input type="hidden" name="token" value="${escapeHtmlAttr(token)}">${handoff}
|
|
88
|
+
<noscript><button type="submit">Continue</button></noscript>
|
|
89
|
+
</form>
|
|
90
|
+
<script>document.forms[0].submit()<\/script>
|
|
91
|
+
</body></html>`;
|
|
92
|
+
}
|
|
93
|
+
export { checkoutEntry, handleCheckoutGet, renderCheckoutHandoffForm };
|
package/dist/coalesce.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { requestSlot } from "./request-scope.js";
|
|
2
|
+
// src/coalesce.ts
|
|
3
|
+
/**
|
|
4
|
+
* A reader that coalesces same-tick reads into calls of `send`, matching
|
|
5
|
+
* each caller's item in the answer with `matches`. The first read of a group
|
|
6
|
+
* schedules its flush; every read of that group until then joins it, and the
|
|
7
|
+
* group's first `send` is the one used (a group names one question).
|
|
8
|
+
*/
|
|
9
|
+
function coalescedReads(opts) {
|
|
10
|
+
const slot = Symbol("coalesced reads");
|
|
11
|
+
return (group, ref, send) => {
|
|
12
|
+
const pick = (items) => items.find((item) => opts.matches(item, ref)) ?? null;
|
|
13
|
+
const groups = requestSlot(slot, () => /* @__PURE__ */ new Map());
|
|
14
|
+
if (!groups) return send([ref]).then(pick);
|
|
15
|
+
let pending = groups.get(group);
|
|
16
|
+
if (!pending) {
|
|
17
|
+
const scheduled = {
|
|
18
|
+
send,
|
|
19
|
+
refs: /* @__PURE__ */ new Map()
|
|
20
|
+
};
|
|
21
|
+
pending = scheduled;
|
|
22
|
+
groups.set(group, scheduled);
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
groups.delete(group);
|
|
25
|
+
flush(scheduled, opts.max);
|
|
26
|
+
}, 0);
|
|
27
|
+
}
|
|
28
|
+
let entry = pending.refs.get(ref);
|
|
29
|
+
if (!entry) {
|
|
30
|
+
let resolve;
|
|
31
|
+
let reject;
|
|
32
|
+
const answer = new Promise((res, rej) => {
|
|
33
|
+
resolve = res;
|
|
34
|
+
reject = rej;
|
|
35
|
+
});
|
|
36
|
+
entry = {
|
|
37
|
+
resolve,
|
|
38
|
+
reject,
|
|
39
|
+
answer
|
|
40
|
+
};
|
|
41
|
+
pending.refs.set(ref, entry);
|
|
42
|
+
}
|
|
43
|
+
return entry.answer.then(pick);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function flush(pending, max) {
|
|
47
|
+
const refs = [...pending.refs.keys()];
|
|
48
|
+
for (let i = 0; i < refs.length; i += max) {
|
|
49
|
+
const chunk = refs.slice(i, i + max);
|
|
50
|
+
new Promise((res) => res(pending.send(chunk))).then((items) => {
|
|
51
|
+
for (const ref of chunk) pending.refs.get(ref).resolve(items);
|
|
52
|
+
}, (error) => {
|
|
53
|
+
for (const ref of chunk) pending.refs.get(ref).reject(error);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export { coalescedReads };
|