@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/newsletter.js
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
newsletterSubscribe(input: $input) {
|
|
6
|
-
subscribed
|
|
7
|
-
userErrors {
|
|
8
|
-
code
|
|
9
|
-
field
|
|
10
|
-
message
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
`);
|
|
15
|
-
/** Subscribe `email`. A refusal comes back as the API's first user error; a
|
|
16
|
-
* transport or GraphQL failure throws. */
|
|
1
|
+
import { errorCode, invalidField, storefront } from "./storefront.js";
|
|
2
|
+
// src/newsletter.ts
|
|
3
|
+
/** Subscribe `email`. The token goes only when the form has one: a shop
|
|
4
|
+
* without a widget asks for none. Any other failure throws. */
|
|
17
5
|
async function subscribeNewsletter(input) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
try {
|
|
7
|
+
await storefront().newsletter.subscribe({
|
|
8
|
+
email: input.email,
|
|
9
|
+
...input.turnstileToken ? { turnstileToken: input.turnstileToken } : {}
|
|
10
|
+
});
|
|
11
|
+
return { ok: true };
|
|
12
|
+
} catch (error) {
|
|
13
|
+
const code = errorCode(error);
|
|
14
|
+
if (code === "RATE_LIMITED") {
|
|
15
|
+
const { retryAfterSeconds } = error.data;
|
|
16
|
+
return {
|
|
17
|
+
ok: false,
|
|
18
|
+
code,
|
|
19
|
+
retryAfterSeconds
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (code === "VALIDATION_FAILED") return {
|
|
23
|
+
ok: false,
|
|
24
|
+
code,
|
|
25
|
+
field: invalidField(error)
|
|
26
|
+
};
|
|
27
|
+
if (code === "TURNSTILE_FAILED") return {
|
|
28
|
+
ok: false,
|
|
29
|
+
code
|
|
30
|
+
};
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
|
-
//#endregion
|
|
28
34
|
export { subscribeNewsletter };
|
package/dist/page.d.ts
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
1
|
import { MetafieldMap } from "./metafields.js";
|
|
2
|
-
//#region src/page.d.ts
|
|
3
2
|
export type PageData = {
|
|
4
3
|
id: string;
|
|
5
4
|
handle: string;
|
|
6
5
|
title: string;
|
|
7
6
|
bodyHtml: string;
|
|
8
7
|
bodyPlain: string;
|
|
8
|
+
/** `page.<suffix>`; null for the default template (`page`). */
|
|
9
9
|
themeTemplate: string | null;
|
|
10
|
-
|
|
11
|
-
publishedAt: string | null;
|
|
10
|
+
publishedAt: string;
|
|
12
11
|
updatedAt: string;
|
|
13
12
|
seo: {
|
|
14
13
|
title: string;
|
|
15
14
|
description: string;
|
|
16
15
|
};
|
|
17
16
|
};
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
export declare
|
|
17
|
+
/** A page by handle or id. Null when it is missing, not visible to a buyer,
|
|
18
|
+
* or the read failed: the route loader maps that to a 404. */
|
|
19
|
+
export declare function fetchPage(ref: string, locale?: string): Promise<PageData | null>;
|
|
21
20
|
export type PageRef = {
|
|
22
21
|
title: string;
|
|
23
22
|
bodyHtml: string;
|
|
24
23
|
};
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
* a failure, so the literal renders. */
|
|
33
|
-
export declare const fetchPageMetafields: (ref: string, locale?: string) => Promise<MetafieldMap>;
|
|
24
|
+
/** A page by its id (a page metafield's value), as a reference renders it;
|
|
25
|
+
* null when a buyer may not see it, and the caller falls back. */
|
|
26
|
+
export declare function fetchPageById(id: string, locale?: string): Promise<PageRef | null>;
|
|
27
|
+
/** The page's storefront metafields keyed `"namespace.key"`: the
|
|
28
|
+
* `page_metafield` dynamic source, off the same read as the page. `{}` on a
|
|
29
|
+
* miss or a failure, so the literal renders. */
|
|
30
|
+
export declare function fetchPageMetafields(ref: string, locale?: string): Promise<MetafieldMap>;
|
|
34
31
|
/** The route CMS page as the theme loader's dynamic sources read it
|
|
35
32
|
* (`DynamicSourcePage` in `@shop-on/theme-loader`): the title off the page
|
|
36
33
|
* read the theme already made, and a lazy provider the loader calls only when
|
|
@@ -39,5 +36,4 @@ export declare const fetchPageMetafields: (ref: string, locale?: string) => Prom
|
|
|
39
36
|
export declare function routePageSource(page: Pick<PageData, "handle" | "title">, locale?: string): {
|
|
40
37
|
title: string;
|
|
41
38
|
getMetafields: () => Promise<MetafieldMap>;
|
|
42
|
-
};
|
|
43
|
-
//#endregion
|
|
39
|
+
};
|
package/dist/page.js
CHANGED
|
@@ -1,118 +1,63 @@
|
|
|
1
|
+
import { liteId } from "./api-contract/src/ids.js";
|
|
1
2
|
import { memoTTL } from "./cache.js";
|
|
2
|
-
import { graphql, request } from "./graphql.js";
|
|
3
3
|
import { getContentVersion } from "./content-version.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { customDataMap } from "./metafields.js";
|
|
5
|
+
import { orFallback, orNotFound, storefront } from "./storefront.js";
|
|
6
|
+
// src/page.ts
|
|
7
|
+
/** A page by handle, or by id when the ref is a page id (a `page` setting
|
|
8
|
+
* bound to a page metafield holds a `page_…` TypeID). */
|
|
9
|
+
function pageRef(ref) {
|
|
10
|
+
const id = liteId("page").safeParse(ref);
|
|
11
|
+
return id.success ? { pageId: id.data } : { handle: ref };
|
|
8
12
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
title
|
|
15
|
-
bodyHtml
|
|
16
|
-
# Plain-text body capped at the meta-description storage cap —
|
|
17
|
-
# Rails strip_tags + entity decode + word-boundary truncate.
|
|
18
|
-
bodyPlain: body(truncateAt: 320)
|
|
19
|
-
themeTemplate
|
|
20
|
-
storefrontThemeTemplate
|
|
21
|
-
publishedAt
|
|
22
|
-
updatedAt
|
|
23
|
-
seo {
|
|
24
|
-
title
|
|
25
|
-
description
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
`);
|
|
30
|
-
const fetchPageCached = memoTTL(async (handle, locale) => {
|
|
31
|
-
const p = (await request(FetchPageQuery, parseRef(handle), locale ? { acceptLanguage: locale } : void 0)).page;
|
|
13
|
+
/** One `pages.get` behind every read of a page: the route's page, a page
|
|
14
|
+
* setting's, and the page's metafields. Null while a buyer may not see it
|
|
15
|
+
* (NOT_FOUND) and on a failed read, which is not cached. */
|
|
16
|
+
const fetchPageRecord = memoTTL(async (ref, locale) => {
|
|
17
|
+
const p = await orFallback(orNotFound(storefront(locale).pages.get(pageRef(ref))), null, "fetchPage");
|
|
32
18
|
if (!p) return null;
|
|
33
19
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
20
|
+
page: {
|
|
21
|
+
id: p.id,
|
|
22
|
+
handle: p.handle,
|
|
23
|
+
title: p.title,
|
|
24
|
+
bodyHtml: p.bodyHtml,
|
|
25
|
+
bodyPlain: p.bodyText,
|
|
26
|
+
themeTemplate: p.themeTemplate,
|
|
27
|
+
publishedAt: p.publishedAt,
|
|
28
|
+
updatedAt: p.updatedAt,
|
|
29
|
+
seo: {
|
|
30
|
+
title: p.seoTitle,
|
|
31
|
+
description: p.seoDescription
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
metafields: customDataMap(p.metafields)
|
|
47
35
|
};
|
|
48
36
|
}, {
|
|
49
|
-
key: (
|
|
37
|
+
key: (ref, locale) => `page|${ref}|${locale ?? ""}`,
|
|
50
38
|
shouldCache: (v) => v !== null,
|
|
51
39
|
version: getContentVersion
|
|
52
40
|
});
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
page(id: $id) {
|
|
66
|
-
title
|
|
67
|
-
bodyHtml
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
`);
|
|
71
|
-
const fetchPageByIdCached = memoTTL(async (id, locale) => {
|
|
72
|
-
const p = (await request(FetchPageByIdQuery, { id }, locale ? { acceptLanguage: locale } : void 0)).page;
|
|
73
|
-
if (!p) return null;
|
|
74
|
-
return {
|
|
75
|
-
title: p.title,
|
|
76
|
-
bodyHtml: p.bodyHtml
|
|
41
|
+
/** A page by handle or id. Null when it is missing, not visible to a buyer,
|
|
42
|
+
* or the read failed: the route loader maps that to a 404. */
|
|
43
|
+
async function fetchPage(ref, locale) {
|
|
44
|
+
return (await fetchPageRecord(ref, locale))?.page ?? null;
|
|
45
|
+
}
|
|
46
|
+
/** A page by its id (a page metafield's value), as a reference renders it;
|
|
47
|
+
* null when a buyer may not see it, and the caller falls back. */
|
|
48
|
+
async function fetchPageById(id, locale) {
|
|
49
|
+
const page = await fetchPage(id, locale);
|
|
50
|
+
return page && {
|
|
51
|
+
title: page.title,
|
|
52
|
+
bodyHtml: page.bodyHtml
|
|
77
53
|
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* missing/draft/cross-shop page returns null — the caller falls back. */
|
|
86
|
-
const fetchPageById = async (id, locale) => {
|
|
87
|
-
try {
|
|
88
|
-
return await fetchPageByIdCached(id, locale);
|
|
89
|
-
} catch (err) {
|
|
90
|
-
console.warn("[fetchPageById] failed:", err);
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
const FetchPageMetafieldsQuery = graphql(`
|
|
95
|
-
query FetchPageMetafields($handle: String, $id: ID) {
|
|
96
|
-
page(handle: $handle, id: $id) {
|
|
97
|
-
# Storefront-visible only (the API gates on the storefront scope).
|
|
98
|
-
metafields(first: 50) {
|
|
99
|
-
nodes {
|
|
100
|
-
namespace
|
|
101
|
-
key
|
|
102
|
-
type
|
|
103
|
-
value
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
`);
|
|
109
|
-
/** The page's storefront metafields keyed `"namespace.key"` — the
|
|
110
|
-
* `page_metafield` dynamic source. Its own read, not a field on `fetchPage`,
|
|
111
|
-
* so a page whose template binds none never asks for them. `{}` on a miss or
|
|
112
|
-
* a failure, so the literal renders. */
|
|
113
|
-
const fetchPageMetafields = metafieldsReader("fetchPageMetafields", async (handle, locale) => {
|
|
114
|
-
return (await request(FetchPageMetafieldsQuery, parseRef(handle), locale ? { acceptLanguage: locale } : void 0)).page?.metafields.nodes ?? null;
|
|
115
|
-
});
|
|
54
|
+
}
|
|
55
|
+
/** The page's storefront metafields keyed `"namespace.key"`: the
|
|
56
|
+
* `page_metafield` dynamic source, off the same read as the page. `{}` on a
|
|
57
|
+
* miss or a failure, so the literal renders. */
|
|
58
|
+
async function fetchPageMetafields(ref, locale) {
|
|
59
|
+
return (await fetchPageRecord(ref, locale))?.metafields ?? {};
|
|
60
|
+
}
|
|
116
61
|
/** The route CMS page as the theme loader's dynamic sources read it
|
|
117
62
|
* (`DynamicSourcePage` in `@shop-on/theme-loader`): the title off the page
|
|
118
63
|
* read the theme already made, and a lazy provider the loader calls only when
|
|
@@ -124,5 +69,4 @@ function routePageSource(page, locale) {
|
|
|
124
69
|
getMetafields: () => fetchPageMetafields(page.handle, locale)
|
|
125
70
|
};
|
|
126
71
|
}
|
|
127
|
-
//#endregion
|
|
128
72
|
export { fetchPage, fetchPageById, fetchPageMetafields, routePageSource };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/password-session.d.ts
|
|
2
1
|
export interface PasswordSessionData {
|
|
3
2
|
v?: string;
|
|
4
3
|
}
|
|
@@ -6,5 +5,4 @@ export declare const readPasswordSession: () => Promise<PasswordSessionData | un
|
|
|
6
5
|
export declare const writePasswordSession: (data: {
|
|
7
6
|
v: string;
|
|
8
7
|
}) => Promise<void>;
|
|
9
|
-
export declare const clearPasswordSession: () => Promise<void>;
|
|
10
|
-
//#endregion
|
|
8
|
+
export declare const clearPasswordSession: () => Promise<void>;
|
package/dist/password-session.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { derivedCookieSecret } from "./cookie-secret.js";
|
|
2
2
|
import { createServerOnlyFn } from "@tanstack/react-start";
|
|
3
|
-
|
|
3
|
+
// src/password-session.ts
|
|
4
4
|
const TTL_SECONDS = 2592e3;
|
|
5
5
|
const DOMAIN_LABEL = "password";
|
|
6
6
|
const sessionConfig = createServerOnlyFn(async () => {
|
|
@@ -36,5 +36,4 @@ const writePasswordSession = createServerOnlyFn(async (data) => {
|
|
|
36
36
|
const clearPasswordSession = createServerOnlyFn(async () => {
|
|
37
37
|
await (await loadSession()).clear();
|
|
38
38
|
});
|
|
39
|
-
//#endregion
|
|
40
39
|
export { clearPasswordSession, readPasswordSession, writePasswordSession };
|
package/dist/password.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
//#region src/password.d.ts
|
|
2
1
|
/** Whether this visitor is locked out: protection is on and their cookie does
|
|
3
|
-
* not carry the current `
|
|
2
|
+
* not carry the current password `version`, so changing the password
|
|
4
3
|
* invalidates every outstanding unlock with no server-side state. A matching
|
|
5
4
|
* `?key=` (the admin's "View shop" links, the screenshot job) mints the cookie
|
|
6
5
|
* as a successful unlock does; `keyConsumed` tells the caller to strip it from
|
|
@@ -10,29 +9,37 @@ export declare function readPasswordGate(key: string | undefined): Promise<{
|
|
|
10
9
|
locked: boolean;
|
|
11
10
|
keyConsumed: boolean;
|
|
12
11
|
}>;
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
/** Why the api kept the store locked, as the password pages word it:
|
|
13
|
+
* `INVALID_PASSWORD` (not the store's password), `TURNSTILE_FAILED` (the bot
|
|
14
|
+
* check did not pass), `RATE_LIMITED` (too many attempts: from this buyer's
|
|
15
|
+
* address, or at this shop; `retryAfterSeconds` until the next is counted),
|
|
16
|
+
* `NOT_ENABLED` (the merchant opened the store meanwhile: nothing left to
|
|
17
|
+
* unlock, so the page reloads into the store). */
|
|
17
18
|
export type UnlockStorefrontResult = {
|
|
18
19
|
ok: true;
|
|
19
20
|
} | {
|
|
20
21
|
ok: false;
|
|
21
|
-
code:
|
|
22
|
-
|
|
22
|
+
code: "INVALID_PASSWORD" | "TURNSTILE_FAILED" | "NOT_ENABLED";
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
code: "RATE_LIMITED";
|
|
26
|
+
retryAfterSeconds: number;
|
|
23
27
|
};
|
|
24
|
-
/** Check the password
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
/** Check the password with the api (`passwordProtection.unlock`: Turnstile,
|
|
29
|
+
* then the gate, then the password; wrong guesses counted per buyer address
|
|
30
|
+
* and per shop) and, when it is right, write the unlock cookie with the
|
|
31
|
+
* version the api answered: the current one, so a buyer entering a
|
|
32
|
+
* just-changed password is never stamped a stale one and bounced back to the
|
|
33
|
+
* gate. The token goes only when the form has one: a shop without a widget
|
|
34
|
+
* asks for none. Any other failure throws. */
|
|
29
35
|
export declare function unlockStorefront(input: {
|
|
30
36
|
password: string;
|
|
31
37
|
turnstileToken: string;
|
|
32
38
|
}): Promise<UnlockStorefrontResult>;
|
|
33
|
-
/** The merchant's coming-soon message (Preferences)
|
|
34
|
-
*
|
|
39
|
+
/** The merchant's coming-soon message (Preferences) — Liquid's
|
|
40
|
+
* `shop.password_message`; in `locale`'s language when the merchant translated
|
|
41
|
+
* it, else the shop's primary language (the api's translation overlay). Read uncached, so a just-edited message
|
|
35
42
|
* shows at once; the password page is rare and cheap. `null` when unset or
|
|
36
|
-
* unreadable: the page must render without it
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
* unreadable: the page must render without it (a refused storefront key still
|
|
44
|
+
* throws, as every loader does). */
|
|
45
|
+
export declare function fetchPasswordMessage(locale?: string): Promise<string | null>;
|
package/dist/password.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { graphql, request } from "./graphql.js";
|
|
2
|
-
import { fetchPasswordProtection } from "./shop.js";
|
|
3
1
|
import { readPasswordSession, writePasswordSession } from "./password-session.js";
|
|
4
|
-
|
|
2
|
+
import { fetchPasswordProtection } from "./shop.js";
|
|
3
|
+
import { errorCode, orFallback, storefront } from "./storefront.js";
|
|
4
|
+
// src/password.ts
|
|
5
5
|
/** Whether this visitor is locked out: protection is on and their cookie does
|
|
6
|
-
* not carry the current `
|
|
6
|
+
* not carry the current password `version`, so changing the password
|
|
7
7
|
* invalidates every outstanding unlock with no server-side state. A matching
|
|
8
8
|
* `?key=` (the admin's "View shop" links, the screenshot job) mints the cookie
|
|
9
9
|
* as a successful unlock does; `keyConsumed` tells the caller to strip it from
|
|
@@ -11,81 +11,63 @@ import { readPasswordSession, writePasswordSession } from "./password-session.js
|
|
|
11
11
|
* `fetchPasswordProtection` is memoised, so the per-request cost is near-free. */
|
|
12
12
|
async function readPasswordGate(key) {
|
|
13
13
|
const protection = await fetchPasswordProtection();
|
|
14
|
-
if (!protection
|
|
14
|
+
if (!protection.enabled || !protection.version) return {
|
|
15
15
|
locked: false,
|
|
16
16
|
keyConsumed: false
|
|
17
17
|
};
|
|
18
18
|
if (key && protection.bypassToken && key === protection.bypassToken) {
|
|
19
|
-
await writePasswordSession({ v: protection.
|
|
19
|
+
await writePasswordSession({ v: protection.version });
|
|
20
20
|
return {
|
|
21
21
|
locked: false,
|
|
22
22
|
keyConsumed: true
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
|
-
locked: (await readPasswordSession())?.v !== protection.
|
|
26
|
+
locked: (await readPasswordSession())?.v !== protection.version,
|
|
27
27
|
keyConsumed: false
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
`);
|
|
41
|
-
const VersionQuery = graphql(`
|
|
42
|
-
query StorefrontPasswordVersion {
|
|
43
|
-
shop {
|
|
44
|
-
passwordProtection {
|
|
45
|
-
passwordUpdatedAt
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
`);
|
|
50
|
-
/** Check the password (Turnstile and a per-IP rate limit live in the API) and,
|
|
51
|
-
* when it is right, write the unlock cookie. The version is re-read UNCACHED
|
|
52
|
-
* first: a buyer entering a just-changed password must never get a stale one
|
|
53
|
-
* stamped, which would bounce them straight back to the gate. A transport or
|
|
54
|
-
* GraphQL failure throws. */
|
|
30
|
+
/** Check the password with the api (`passwordProtection.unlock`: Turnstile,
|
|
31
|
+
* then the gate, then the password; wrong guesses counted per buyer address
|
|
32
|
+
* and per shop) and, when it is right, write the unlock cookie with the
|
|
33
|
+
* version the api answered: the current one, so a buyer entering a
|
|
34
|
+
* just-changed password is never stamped a stale one and bounced back to the
|
|
35
|
+
* gate. The token goes only when the form has one: a shop without a widget
|
|
36
|
+
* asks for none. Any other failure throws. */
|
|
55
37
|
async function unlockStorefront(input) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
38
|
+
let version;
|
|
39
|
+
try {
|
|
40
|
+
({version} = await storefront().passwordProtection.unlock({
|
|
41
|
+
password: input.password,
|
|
42
|
+
...input.turnstileToken ? { turnstileToken: input.turnstileToken } : {}
|
|
43
|
+
}));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const code = errorCode(error);
|
|
46
|
+
if (code === "RATE_LIMITED") {
|
|
47
|
+
const { retryAfterSeconds } = error.data;
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
code,
|
|
51
|
+
retryAfterSeconds
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (code === "INVALID_PASSWORD" || code === "TURNSTILE_FAILED" || code === "NOT_ENABLED") return {
|
|
60
55
|
ok: false,
|
|
61
|
-
code
|
|
62
|
-
message: error?.message ?? null
|
|
56
|
+
code
|
|
63
57
|
};
|
|
58
|
+
throw error;
|
|
64
59
|
}
|
|
65
|
-
|
|
66
|
-
if (version) await writePasswordSession({ v: version });
|
|
60
|
+
await writePasswordSession({ v: version });
|
|
67
61
|
return { ok: true };
|
|
68
62
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
passwordProtection {
|
|
73
|
-
message
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
`);
|
|
78
|
-
/** The merchant's coming-soon message (Preferences), translated for `locale`
|
|
79
|
-
* — Liquid's `shop.password_message`. Read uncached, so a just-edited message
|
|
63
|
+
/** The merchant's coming-soon message (Preferences) — Liquid's
|
|
64
|
+
* `shop.password_message`; in `locale`'s language when the merchant translated
|
|
65
|
+
* it, else the shop's primary language (the api's translation overlay). Read uncached, so a just-edited message
|
|
80
66
|
* shows at once; the password page is rare and cheap. `null` when unset or
|
|
81
|
-
* unreadable: the page must render without it
|
|
67
|
+
* unreadable: the page must render without it (a refused storefront key still
|
|
68
|
+
* throws, as every loader does). */
|
|
82
69
|
async function fetchPasswordMessage(locale) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} catch (err) {
|
|
86
|
-
console.warn("[fetchPasswordMessage] failed:", err);
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
70
|
+
const { message } = await orFallback(storefront(locale).passwordProtection.message({}), { message: null }, "fetchPasswordMessage");
|
|
71
|
+
return message;
|
|
89
72
|
}
|
|
90
|
-
//#endregion
|
|
91
73
|
export { fetchPasswordMessage, readPasswordGate, unlockStorefront };
|
package/dist/policy.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/policy.d.ts
|
|
2
1
|
export type PolicyData = {
|
|
3
2
|
handle: string;
|
|
4
3
|
title: string;
|
|
@@ -6,15 +5,16 @@ export type PolicyData = {
|
|
|
6
5
|
url: string;
|
|
7
6
|
updatedAt: string;
|
|
8
7
|
};
|
|
9
|
-
/** Single-policy fetch keyed by handle (the URL slug).
|
|
10
|
-
*
|
|
8
|
+
/** Single-policy fetch keyed by handle (the URL slug). Null when the shop has
|
|
9
|
+
* not written that policy — the route loader maps that to a 404. Any other
|
|
10
|
+
* failure is thrown: the route's error, never a 404 a crawler would keep. */
|
|
11
11
|
export declare const fetchPolicy: (handle: string, locale?: string) => Promise<PolicyData | null>;
|
|
12
12
|
export type PolicyLink = {
|
|
13
13
|
handle: string;
|
|
14
14
|
title: string;
|
|
15
15
|
url: string;
|
|
16
16
|
};
|
|
17
|
-
/** Every
|
|
18
|
-
* returns `[]`, which the consuming block renders as nothing at all
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/** Every policy the shop has written, for a footer link list. A shop with none
|
|
18
|
+
* returns `[]`, which the consuming block renders as nothing at all; so does
|
|
19
|
+
* a failed read, since the page renders without it. */
|
|
20
|
+
export declare const fetchShopPolicies: (locale?: string) => Promise<PolicyLink[]>;
|
package/dist/policy.js
CHANGED
|
@@ -1,58 +1,29 @@
|
|
|
1
1
|
import { memoTTL } from "./cache.js";
|
|
2
|
-
import { graphql, request } from "./graphql.js";
|
|
3
2
|
import { getContentVersion } from "./content-version.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
query FetchPolicy($handle: String!) {
|
|
7
|
-
shop {
|
|
8
|
-
shopPolicy(handle: $handle) {
|
|
9
|
-
handle
|
|
10
|
-
title
|
|
11
|
-
bodyHtml
|
|
12
|
-
url
|
|
13
|
-
updatedAt
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
`);
|
|
3
|
+
import { orFallback, orNotFound, storefront } from "./storefront.js";
|
|
4
|
+
// src/policy.ts
|
|
18
5
|
const fetchPolicyCached = memoTTL(async (handle, locale) => {
|
|
19
|
-
const
|
|
20
|
-
if (!
|
|
6
|
+
const policy = await orNotFound(storefront(locale).policies.get({ handle }));
|
|
7
|
+
if (!policy) return null;
|
|
21
8
|
return {
|
|
22
|
-
handle:
|
|
23
|
-
title:
|
|
24
|
-
bodyHtml:
|
|
25
|
-
url:
|
|
26
|
-
updatedAt:
|
|
9
|
+
handle: policy.handle,
|
|
10
|
+
title: policy.title,
|
|
11
|
+
bodyHtml: policy.bodyHtml,
|
|
12
|
+
url: policy.url,
|
|
13
|
+
updatedAt: policy.updatedAt
|
|
27
14
|
};
|
|
28
15
|
}, {
|
|
29
16
|
key: (handle, locale) => `policy|${handle}|${locale ?? ""}`,
|
|
30
17
|
shouldCache: (v) => v !== null,
|
|
31
18
|
version: getContentVersion
|
|
32
19
|
});
|
|
33
|
-
/** Single-policy fetch keyed by handle (the URL slug).
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return await fetchPolicyCached(handle, locale);
|
|
38
|
-
} catch (err) {
|
|
39
|
-
console.warn("[fetchPolicy] failed:", err);
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const FetchShopPoliciesQuery = graphql(`
|
|
44
|
-
query FetchShopPolicies {
|
|
45
|
-
shop {
|
|
46
|
-
shopPolicies {
|
|
47
|
-
handle
|
|
48
|
-
title
|
|
49
|
-
url
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
`);
|
|
20
|
+
/** Single-policy fetch keyed by handle (the URL slug). Null when the shop has
|
|
21
|
+
* not written that policy — the route loader maps that to a 404. Any other
|
|
22
|
+
* failure is thrown: the route's error, never a 404 a crawler would keep. */
|
|
23
|
+
const fetchPolicy = (handle, locale) => fetchPolicyCached(handle, locale);
|
|
54
24
|
const fetchShopPoliciesCached = memoTTL(async (locale) => {
|
|
55
|
-
|
|
25
|
+
const { items } = await storefront(locale).policies.list({});
|
|
26
|
+
return items.map((p) => ({
|
|
56
27
|
handle: p.handle,
|
|
57
28
|
title: p.title,
|
|
58
29
|
url: p.url
|
|
@@ -61,15 +32,8 @@ const fetchShopPoliciesCached = memoTTL(async (locale) => {
|
|
|
61
32
|
key: (locale) => `shop-policies|${locale ?? ""}`,
|
|
62
33
|
version: getContentVersion
|
|
63
34
|
});
|
|
64
|
-
/** Every
|
|
65
|
-
* returns `[]`, which the consuming block renders as nothing at all
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return await fetchShopPoliciesCached(locale);
|
|
69
|
-
} catch (err) {
|
|
70
|
-
console.warn("[fetchShopPolicies] failed:", err);
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
//#endregion
|
|
35
|
+
/** Every policy the shop has written, for a footer link list. A shop with none
|
|
36
|
+
* returns `[]`, which the consuming block renders as nothing at all; so does
|
|
37
|
+
* a failed read, since the page renders without it. */
|
|
38
|
+
const fetchShopPolicies = (locale) => orFallback(fetchShopPoliciesCached(locale), [], "fetchShopPolicies");
|
|
75
39
|
export { fetchPolicy, fetchShopPolicies };
|