@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.5
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/LICENSE +21 -0
- package/README.md +98 -10
- package/dist/abi/canvas-live.d.ts +49 -0
- package/dist/abi/canvas-live.js +88 -0
- package/dist/abi/cart.d.ts +48 -0
- package/dist/abi/cart.js +321 -0
- package/dist/abi/convert.d.ts +192 -0
- package/dist/abi/convert.js +670 -0
- package/dist/abi/data-api.d.ts +15 -0
- package/dist/abi/data-api.js +198 -0
- package/dist/abi/jcs.d.ts +6 -0
- package/dist/abi/jcs.js +28 -0
- package/dist/abi/page-data.d.ts +209 -0
- package/dist/abi/page-data.js +583 -0
- package/dist/abi/page.d.ts +23 -0
- package/dist/abi/page.js +46 -0
- package/dist/abi/referrals.d.ts +23 -0
- package/dist/abi/referrals.js +89 -0
- package/dist/abi/rewards.d.ts +27 -0
- package/dist/abi/rewards.js +82 -0
- package/dist/abi/seo.d.ts +47 -0
- package/dist/abi/seo.js +68 -0
- package/dist/abi/shell.d.ts +22 -0
- package/dist/abi/shell.js +10 -0
- package/dist/abi/wire.d.ts +38 -0
- package/dist/abi/wire.js +84 -0
- package/dist/build.d.ts +113 -0
- package/dist/build.js +294 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.js +76 -0
- package/dist/contract.d.ts +6 -0
- package/dist/contract.js +6 -0
- package/dist/headless/ai.d.ts +132 -0
- package/dist/headless/ai.js +99 -0
- package/dist/headless/hooks.d.ts +273 -0
- package/dist/headless/hooks.js +533 -0
- package/dist/headless/i18n.d.ts +13 -0
- package/dist/headless/i18n.js +45 -0
- package/dist/headless/index.d.ts +36 -0
- package/dist/headless/index.js +38 -0
- package/dist/headless/money.d.ts +25 -0
- package/dist/headless/money.js +61 -0
- package/dist/headless/page.d.ts +43 -0
- package/dist/headless/page.js +53 -0
- package/dist/headless/platform.d.ts +55 -0
- package/dist/headless/platform.js +77 -0
- package/dist/headless/primitives/cart.d.ts +90 -0
- package/dist/headless/primitives/cart.js +153 -0
- package/dist/headless/primitives/collection.d.ts +68 -0
- package/dist/headless/primitives/collection.js +80 -0
- package/dist/headless/primitives/product.d.ts +101 -0
- package/dist/headless/primitives/product.js +117 -0
- package/dist/headless/primitives/storefront.d.ts +106 -0
- package/dist/headless/primitives/storefront.js +186 -0
- package/dist/headless/primitives/util.d.ts +19 -0
- package/dist/headless/primitives/util.js +42 -0
- package/dist/headless/strings.d.ts +9 -0
- package/dist/headless/strings.js +186 -0
- package/dist/headless/structured-data.d.ts +31 -0
- package/dist/headless/structured-data.js +57 -0
- package/dist/headless/theme.d.ts +99 -0
- package/dist/headless/theme.js +54 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +18 -553
- package/dist/runtime/data/StoreProvider.d.ts +56 -0
- package/dist/runtime/data/StoreProvider.js +308 -0
- package/dist/runtime/data/handle.d.ts +14 -0
- package/dist/runtime/data/handle.js +16 -0
- package/dist/runtime/data/routes.d.ts +87 -0
- package/dist/runtime/data/routes.js +154 -0
- package/dist/runtime/data/to-ui.d.ts +258 -0
- package/dist/runtime/data/to-ui.js +820 -0
- package/dist/runtime/entries/register.d.ts +9 -0
- package/dist/runtime/entries/register.js +9 -0
- package/dist/runtime/entries/sections.d.ts +16 -0
- package/dist/runtime/entries/sections.js +19 -0
- package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
- package/dist/runtime/kit/SectionTree.js +100 -0
- package/dist/runtime/kit/analytics.d.ts +63 -0
- package/dist/runtime/kit/analytics.js +233 -0
- package/dist/runtime/kit/cart.d.ts +186 -0
- package/dist/runtime/kit/cart.js +545 -0
- package/dist/{types → runtime/kit}/composition.d.ts +1 -1
- package/dist/runtime/kit/composition.js +3 -0
- package/dist/{types → runtime/kit}/config.d.ts +2 -2
- package/dist/runtime/kit/config.js +6 -0
- package/dist/runtime/kit/consent.d.ts +29 -0
- package/dist/runtime/kit/consent.js +159 -0
- package/dist/runtime/kit/contract/content.d.ts +164 -0
- package/dist/runtime/kit/contract/content.js +83 -0
- package/dist/runtime/kit/contract/field-types.d.ts +290 -0
- package/dist/runtime/kit/contract/field-types.js +129 -0
- package/dist/runtime/kit/contract/groups.d.ts +230 -0
- package/dist/runtime/kit/contract/groups.js +402 -0
- package/dist/runtime/kit/contract/index.d.ts +33 -0
- package/dist/runtime/kit/contract/index.js +33 -0
- package/dist/runtime/kit/contract/transform.d.ts +82 -0
- package/dist/runtime/kit/contract/transform.js +133 -0
- package/dist/runtime/kit/contract/validate.d.ts +67 -0
- package/dist/runtime/kit/contract/validate.js +388 -0
- package/dist/runtime/kit/data.d.ts +636 -0
- package/dist/runtime/kit/data.js +1117 -0
- package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
- package/dist/runtime/kit/defineSection.js +10 -0
- package/dist/{types → runtime/kit}/dynamic-source.d.ts +4 -4
- package/dist/runtime/kit/dynamic-source.js +143 -0
- package/dist/runtime/kit/index.d.ts +24 -0
- package/dist/runtime/kit/index.js +24 -0
- package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
- package/dist/runtime/kit/jsx-to-json.js +28 -0
- package/dist/{types → runtime/kit}/mount.d.ts +25 -4
- package/dist/runtime/kit/mount.js +124 -0
- package/dist/{types → runtime/kit}/registry.d.ts +1 -1
- package/dist/runtime/kit/registry.js +12 -0
- package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
- package/dist/runtime/kit/ssg.js +56 -0
- package/dist/runtime/kit/storefront.d.ts +566 -0
- package/dist/runtime/kit/storefront.js +723 -0
- package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
- package/dist/runtime/kit/theme-context.js +25 -0
- package/dist/runtime/kit/types.d.ts +142 -0
- package/dist/runtime/kit/types.js +1 -0
- package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
- package/dist/runtime/platform/TrackingPixels.js +63 -0
- package/dist/runtime/platform/environment.d.ts +68 -0
- package/dist/runtime/platform/environment.js +85 -0
- package/dist/runtime/platform/locale.d.ts +27 -0
- package/dist/runtime/platform/locale.js +42 -0
- package/dist/runtime/platform/route-analytics.d.ts +15 -0
- package/dist/runtime/platform/route-analytics.js +72 -0
- package/dist/runtime/platform/safe-href.d.ts +25 -0
- package/dist/runtime/platform/safe-href.js +69 -0
- package/dist/runtime/platform/safe-values.d.ts +37 -0
- package/dist/runtime/platform/safe-values.js +140 -0
- package/dist/runtime/render/SectionRenderer.d.ts +4 -0
- package/dist/runtime/render/SectionRenderer.js +111 -0
- package/dist/runtime/render/listing-query.d.ts +47 -0
- package/dist/runtime/render/listing-query.js +114 -0
- package/dist/runtime/render/localized-copy.d.ts +86 -0
- package/dist/runtime/render/localized-copy.js +129 -0
- package/dist/runtime/render/product-listing.d.ts +11 -0
- package/dist/runtime/render/product-listing.js +240 -0
- package/dist/runtime/render/section-actions.d.ts +48 -0
- package/dist/runtime/render/section-actions.js +170 -0
- package/dist/runtime/render/starter.d.ts +11 -0
- package/dist/runtime/render/starter.js +81 -0
- package/dist/runtime/seo/head.d.ts +87 -0
- package/dist/runtime/seo/head.js +224 -0
- package/dist/runtime/seo/structured-data.d.ts +22 -0
- package/dist/runtime/seo/structured-data.js +115 -0
- package/dist/runtime/shell/PageShell.d.ts +18 -0
- package/dist/runtime/shell/PageShell.js +113 -0
- package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
- package/dist/runtime/shell/RuntimeBridge.js +85 -0
- package/dist/runtime/shell/overlay-state.d.ts +31 -0
- package/dist/runtime/shell/overlay-state.js +59 -0
- package/dist/runtime/shell/preview-mode.d.ts +2 -0
- package/dist/runtime/shell/preview-mode.js +11 -0
- package/dist/runtime/shell/spa-router.d.ts +14 -0
- package/dist/runtime/shell/spa-router.js +76 -0
- package/dist/runtime/shell/url-redirects.d.ts +6 -0
- package/dist/runtime/shell/url-redirects.js +37 -0
- package/dist/runtime/slots.d.ts +74 -0
- package/dist/runtime/slots.js +16 -0
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.js +40 -0
- package/dist/sdk/index.d.ts +24 -0
- package/dist/sdk/index.js +24 -0
- package/dist/sdk/referrals.d.ts +62 -0
- package/dist/sdk/referrals.js +20 -0
- package/dist/sdk/rewards.d.ts +85 -0
- package/dist/sdk/rewards.js +29 -0
- package/dist/sdk/runtime-context.d.ts +135 -0
- package/dist/sdk/runtime-context.js +73 -0
- package/dist/sdk/schema.d.ts +197 -0
- package/dist/sdk/schema.js +121 -0
- package/dist/sdk/server-render.d.ts +8 -0
- package/dist/sdk/server-render.js +12 -0
- package/dist/sdk/store-lookup.d.ts +27 -0
- package/dist/sdk/store-lookup.js +29 -0
- package/dist/sdk/store.d.ts +115 -0
- package/dist/sdk/store.js +1 -0
- package/dist/sdk/sx.d.ts +40 -0
- package/dist/sdk/sx.js +112 -0
- package/dist/sdk/theme.d.ts +152 -0
- package/dist/sdk/theme.js +10 -0
- package/dist/sdk/types.d.ts +470 -0
- package/dist/sdk/types.js +7 -0
- package/dist/server.d.ts +65 -0
- package/dist/server.js +370 -0
- package/docs/headless-api.md +220 -0
- package/package.json +77 -23
- package/dist/index.js.map +0 -1
- package/dist/ssg-BZ5FYTw7.js +0 -1802
- package/dist/ssg-BZ5FYTw7.js.map +0 -1
- package/dist/ssg.js +0 -8
- package/dist/ssg.js.map +0 -1
- package/dist/types/cart.d.ts +0 -86
- package/dist/types/data.d.ts +0 -357
- package/dist/types/editor.d.ts +0 -5
- package/dist/types/index.d.ts +0 -20
- package/dist/types/preview-bridge.d.ts +0 -9
- package/dist/types/storefront.d.ts +0 -333
- package/dist/types/types.d.ts +0 -44
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The referral program over Theme ABI v2 (army #7751): `useReferrals()` driven by the data ops `referral.state` and
|
|
3
|
+
* `referral.offer` (the `?ref=` code) and the actions `referral.claim` and `referral.invite`, which the host answers
|
|
4
|
+
* from studio-accounts (`/account/referrals/*`) with the shopper's session. A `?ref=CODE` visit keeps the code for
|
|
5
|
+
* the session (sessionStorage) and in the first-party session cookie `tanqory_ref`, a claimed friend code in
|
|
6
|
+
* `tanqory_ref_claim`; studio-checkouts reads both (the `ref` attribute, the friend's code applied). Browser only;
|
|
7
|
+
* a host without the ops, or referrals off, is the same as off.
|
|
8
|
+
*/
|
|
9
|
+
import { type ReactNode } from 'react';
|
|
10
|
+
import { type FriendOffer, type ReferralState } from '../sdk/referrals.js';
|
|
11
|
+
import type { AbiRemote } from './wire.js';
|
|
12
|
+
export declare const REF_COOKIE = "tanqory_ref";
|
|
13
|
+
export declare const CLAIM_COOKIE = "tanqory_ref_claim";
|
|
14
|
+
/** The `?ref=` code of this visit, else the one kept earlier this session; kept for the session either way. */
|
|
15
|
+
export declare function keepRefCode(search: string): string | null;
|
|
16
|
+
/** The `referral.state` answer when it is the shopper's own link, else null. */
|
|
17
|
+
export declare function referralStateOf(data: unknown): ReferralState | null;
|
|
18
|
+
/** The `referral.offer` answer when it is an offer for this shopper, else null. */
|
|
19
|
+
export declare function friendOfferOf(data: unknown, claimedCode: string | null): FriendOffer | null;
|
|
20
|
+
export declare function AbiReferralsProvider({ remote, children }: {
|
|
21
|
+
remote: AbiRemote | null;
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The referral program over Theme ABI v2 (army #7751): `useReferrals()` driven by the data ops `referral.state` and
|
|
4
|
+
* `referral.offer` (the `?ref=` code) and the actions `referral.claim` and `referral.invite`, which the host answers
|
|
5
|
+
* from studio-accounts (`/account/referrals/*`) with the shopper's session. A `?ref=CODE` visit keeps the code for
|
|
6
|
+
* the session (sessionStorage) and in the first-party session cookie `tanqory_ref`, a claimed friend code in
|
|
7
|
+
* `tanqory_ref_claim`; studio-checkouts reads both (the `ref` attribute, the friend's code applied). Browser only;
|
|
8
|
+
* a host without the ops, or referrals off, is the same as off.
|
|
9
|
+
*/
|
|
10
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
11
|
+
import { ReferralsContext } from '../sdk/referrals.js';
|
|
12
|
+
export const REF_COOKIE = 'tanqory_ref';
|
|
13
|
+
export const CLAIM_COOKIE = 'tanqory_ref_claim';
|
|
14
|
+
const REF_KEY = 'nova:ref';
|
|
15
|
+
const CLAIMED_KEY = 'nova:ref-claimed';
|
|
16
|
+
// store-api's link and claim codes: letters, digits and dashes.
|
|
17
|
+
const CODE = /^[A-Za-z0-9-]{3,40}$/;
|
|
18
|
+
function session(key, value) {
|
|
19
|
+
try {
|
|
20
|
+
if (value !== undefined)
|
|
21
|
+
sessionStorage.setItem(key, value);
|
|
22
|
+
return sessionStorage.getItem(key);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function setSessionCookie(name, value) {
|
|
29
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; SameSite=Lax${location.protocol === 'https:' ? '; Secure' : ''}`;
|
|
30
|
+
}
|
|
31
|
+
/** The `?ref=` code of this visit, else the one kept earlier this session; kept for the session either way. */
|
|
32
|
+
export function keepRefCode(search) {
|
|
33
|
+
const fromUrl = new URLSearchParams(search).get('ref')?.trim() ?? '';
|
|
34
|
+
const code = CODE.test(fromUrl) ? fromUrl : session(REF_KEY) ?? '';
|
|
35
|
+
if (!CODE.test(code))
|
|
36
|
+
return null;
|
|
37
|
+
session(REF_KEY, code);
|
|
38
|
+
setSessionCookie(REF_COOKIE, code);
|
|
39
|
+
return code;
|
|
40
|
+
}
|
|
41
|
+
/** The `referral.state` answer when it is the shopper's own link, else null. */
|
|
42
|
+
export function referralStateOf(data) {
|
|
43
|
+
const s = data;
|
|
44
|
+
return s && s.enabled === true && typeof s.shareUrl === 'string' && s.shareUrl && s.offer && s.stats ? s : null;
|
|
45
|
+
}
|
|
46
|
+
/** The `referral.offer` answer when it is an offer for this shopper, else null. */
|
|
47
|
+
export function friendOfferOf(data, claimedCode) {
|
|
48
|
+
const o = data;
|
|
49
|
+
return o && o.enabled === true && typeof o.code === 'string' && o.offer ? { ...o, claimedCode } : null;
|
|
50
|
+
}
|
|
51
|
+
const claimError = (code) => code === 'self' || code === 'referral_self_claim' ? 'self' : code === 'email' || code === 'referral_email_invalid' ? 'email' : 'failed';
|
|
52
|
+
export function AbiReferralsProvider({ remote, children }) {
|
|
53
|
+
const [state, setState] = useState(null);
|
|
54
|
+
const [friend, setFriend] = useState(null);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!remote)
|
|
57
|
+
return;
|
|
58
|
+
let cancelled = false;
|
|
59
|
+
remote
|
|
60
|
+
.data('referral.state', [])
|
|
61
|
+
.then((d) => !cancelled && setState(referralStateOf(d)))
|
|
62
|
+
.catch(() => { });
|
|
63
|
+
const code = keepRefCode(window.location.search);
|
|
64
|
+
if (code) {
|
|
65
|
+
remote
|
|
66
|
+
.data('referral.offer', [code])
|
|
67
|
+
.then((d) => !cancelled && setFriend(friendOfferOf(d, session(CLAIMED_KEY))))
|
|
68
|
+
.catch(() => { });
|
|
69
|
+
}
|
|
70
|
+
return () => {
|
|
71
|
+
cancelled = true;
|
|
72
|
+
};
|
|
73
|
+
}, [remote]);
|
|
74
|
+
const claim = useCallback(async (email) => {
|
|
75
|
+
if (!remote || !friend)
|
|
76
|
+
return { ok: false, error: 'failed' };
|
|
77
|
+
const env = await remote.action('referral.claim', [{ code: friend.code, email: email.trim() }]).catch(() => null);
|
|
78
|
+
const code = env?.ok ? env.data?.code : null;
|
|
79
|
+
if (typeof code !== 'string' || !CODE.test(code))
|
|
80
|
+
return { ok: false, error: env && !env.ok ? claimError(env.error.code) : 'failed' };
|
|
81
|
+
session(CLAIMED_KEY, code);
|
|
82
|
+
setSessionCookie(CLAIM_COOKIE, code);
|
|
83
|
+
setFriend((f) => f && { ...f, claimedCode: code });
|
|
84
|
+
return { ok: true, code };
|
|
85
|
+
}, [remote, friend]);
|
|
86
|
+
const invite = useCallback(async (email) => !!remote && remote.action('referral.invite', [{ email: email.trim() }]).then((env) => env.ok, () => false), [remote]);
|
|
87
|
+
const value = useMemo(() => ({ state, friend, claim, invite }), [state, friend, claim, invite]);
|
|
88
|
+
return _jsx(ReferralsContext.Provider, { value: value, children: children });
|
|
89
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The loyalty program over Theme ABI v2 (army #7749): `useRewards()` driven by
|
|
3
|
+
* `GET /_tq/data/loyalty.state`, `POST /_tq/actions/loyalty.redeem` and `POST /_tq/actions/loyalty.join`.
|
|
4
|
+
*
|
|
5
|
+
* - The host answers them from studio-accounts (`/account/rewards/state`, `/redeem`, `/join`) with
|
|
6
|
+
* the shopper's session, which the theme never sees.
|
|
7
|
+
* - Browser only: the server render and the editor canvas pass `remote` null, so the state stays
|
|
8
|
+
* null there and the launcher and hints render nothing (SSR and hydration agree).
|
|
9
|
+
* - A host that does not offer `loyalty.state` yet, or a store with loyalty off, is the same as off.
|
|
10
|
+
*/
|
|
11
|
+
import { type ReactNode } from 'react';
|
|
12
|
+
import { type RewardsState } from '../sdk/rewards.js';
|
|
13
|
+
import type { AbiRemote } from './wire.js';
|
|
14
|
+
/**
|
|
15
|
+
* Whether the storefront host answers the `loyalty.*` and `referral.*` ops. It does not yet: Theme ABI v2
|
|
16
|
+
* (2.0.0-alpha.11) has no loyalty or referral capability, and the edge answers those ops 404. Asking on every page
|
|
17
|
+
* would log a failed request in every shopper's console, and conformance fails the build on that (§10.5). Until
|
|
18
|
+
* the ABI and the edge offer them, the browser entry never asks (main.abi.tsx). The launcher, the earn hints and the
|
|
19
|
+
* share panel stay hidden, the same as for a store with the program off. A `?ref=` code is still kept for checkout.
|
|
20
|
+
*/
|
|
21
|
+
export declare const HOST_OFFERS_LOYALTY = false;
|
|
22
|
+
/** The `loyalty.state` answer when it is a program the shopper can see, else null. */
|
|
23
|
+
export declare function rewardsStateOf(data: unknown): RewardsState | null;
|
|
24
|
+
export declare function AbiRewardsProvider({ remote, children }: {
|
|
25
|
+
remote: AbiRemote | null;
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The loyalty program over Theme ABI v2 (army #7749): `useRewards()` driven by
|
|
4
|
+
* `GET /_tq/data/loyalty.state`, `POST /_tq/actions/loyalty.redeem` and `POST /_tq/actions/loyalty.join`.
|
|
5
|
+
*
|
|
6
|
+
* - The host answers them from studio-accounts (`/account/rewards/state`, `/redeem`, `/join`) with
|
|
7
|
+
* the shopper's session, which the theme never sees.
|
|
8
|
+
* - Browser only: the server render and the editor canvas pass `remote` null, so the state stays
|
|
9
|
+
* null there and the launcher and hints render nothing (SSR and hydration agree).
|
|
10
|
+
* - A host that does not offer `loyalty.state` yet, or a store with loyalty off, is the same as off.
|
|
11
|
+
*/
|
|
12
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
13
|
+
import { RewardsContext } from '../sdk/rewards.js';
|
|
14
|
+
import { AbiReferralsProvider } from './referrals.js';
|
|
15
|
+
/**
|
|
16
|
+
* Whether the storefront host answers the `loyalty.*` and `referral.*` ops. It does not yet: Theme ABI v2
|
|
17
|
+
* (2.0.0-alpha.11) has no loyalty or referral capability, and the edge answers those ops 404. Asking on every page
|
|
18
|
+
* would log a failed request in every shopper's console, and conformance fails the build on that (§10.5). Until
|
|
19
|
+
* the ABI and the edge offer them, the browser entry never asks (main.abi.tsx). The launcher, the earn hints and the
|
|
20
|
+
* share panel stay hidden, the same as for a store with the program off. A `?ref=` code is still kept for checkout.
|
|
21
|
+
*/
|
|
22
|
+
export const HOST_OFFERS_LOYALTY = false;
|
|
23
|
+
/** The `loyalty.state` answer when it is a program the shopper can see, else null. */
|
|
24
|
+
export function rewardsStateOf(data) {
|
|
25
|
+
const s = data;
|
|
26
|
+
return s && s.enabled === true && s.program && typeof s.program === 'object' ? { ...s, ways: Array.isArray(s.ways) ? s.ways : [] } : null;
|
|
27
|
+
}
|
|
28
|
+
/** A fresh idempotency key per redeem tap: a retried request never spends the points twice. */
|
|
29
|
+
function redeemKey() {
|
|
30
|
+
const c = globalThis.crypto;
|
|
31
|
+
return c && typeof c.randomUUID === 'function' ? c.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
|
|
32
|
+
}
|
|
33
|
+
export function AbiRewardsProvider({ remote, children }) {
|
|
34
|
+
const [state, setState] = useState(null);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!remote)
|
|
37
|
+
return;
|
|
38
|
+
let cancelled = false;
|
|
39
|
+
remote
|
|
40
|
+
.data('loyalty.state', [])
|
|
41
|
+
.then((d) => !cancelled && setState(rewardsStateOf(d)))
|
|
42
|
+
.catch(() => { });
|
|
43
|
+
return () => {
|
|
44
|
+
cancelled = true;
|
|
45
|
+
};
|
|
46
|
+
}, [remote]);
|
|
47
|
+
const redeem = useCallback(async (rewardId) => {
|
|
48
|
+
if (!remote)
|
|
49
|
+
return { ok: false, error: 'failed' };
|
|
50
|
+
try {
|
|
51
|
+
const env = await remote.action('loyalty.redeem', [{ rewardId, key: redeemKey() }]);
|
|
52
|
+
const data = (env.ok ? env.data : null);
|
|
53
|
+
if (env.ok && data?.redemption?.code) {
|
|
54
|
+
const next = rewardsStateOf(data.state);
|
|
55
|
+
if (next)
|
|
56
|
+
setState(next);
|
|
57
|
+
return { ok: true, code: data.redemption.code };
|
|
58
|
+
}
|
|
59
|
+
return { ok: false, error: !env.ok && env.error.code === 'loyalty_insufficient_points' ? 'insufficient' : 'failed' };
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return { ok: false, error: 'failed' };
|
|
63
|
+
}
|
|
64
|
+
}, [remote]);
|
|
65
|
+
const join = useCallback(async () => {
|
|
66
|
+
if (!remote)
|
|
67
|
+
return false;
|
|
68
|
+
try {
|
|
69
|
+
const env = await remote.action('loyalty.join', []);
|
|
70
|
+
const next = env.ok ? rewardsStateOf(env.data?.state) : null;
|
|
71
|
+
if (next)
|
|
72
|
+
setState(next);
|
|
73
|
+
return env.ok;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}, [remote]);
|
|
79
|
+
const value = useMemo(() => ({ state, redeem, join }), [state, redeem, join]);
|
|
80
|
+
// The referral program (army #7751) rides on the same remote, so the editor canvas has neither.
|
|
81
|
+
return _jsx(RewardsContext.Provider, { value: value, children: _jsx(AbiReferralsProvider, { remote: remote, children: children }) });
|
|
82
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The home page's head under Theme ABI v2: what a search result and a shared link show for the store.
|
|
3
|
+
*
|
|
4
|
+
* Source order, each field on its own:
|
|
5
|
+
* title the store's home page title (`Shop.seo.title`) → the shop name (computeHead)
|
|
6
|
+
* description `Shop.seo.description` → `Shop.description` → one sentence from the shop name
|
|
7
|
+
* image `Shop.seo.image` → the brand's square logo → its logo → the home hero's image,
|
|
8
|
+
* only an absolute https: URL (a scraper cannot resolve anything else)
|
|
9
|
+
*
|
|
10
|
+
* `Shop.seo` is an optional ABI field the platform may not send yet; lib/abi/convert.ts `shopSeo`
|
|
11
|
+
* reads it defensively, so its absence leaves the fallbacks.
|
|
12
|
+
*/
|
|
13
|
+
import type { Shop } from '../runtime/kit/storefront.js';
|
|
14
|
+
export interface HomeHead {
|
|
15
|
+
title?: string;
|
|
16
|
+
description: string;
|
|
17
|
+
image: string;
|
|
18
|
+
imageAlt?: string;
|
|
19
|
+
imageWidth?: number;
|
|
20
|
+
imageHeight?: number;
|
|
21
|
+
}
|
|
22
|
+
interface Node {
|
|
23
|
+
type?: string;
|
|
24
|
+
settings?: Record<string, unknown>;
|
|
25
|
+
blocks?: readonly Node[];
|
|
26
|
+
}
|
|
27
|
+
/** The first hero's image on the page (its background image setting), when it is an absolute https: URL. */
|
|
28
|
+
export declare function heroImageOf(nodes: readonly Node[]): string;
|
|
29
|
+
export declare function homeHead(shop: Shop, shopName: string, nodes: readonly Node[], sentence: string): HomeHead;
|
|
30
|
+
/** One `<link rel="alternate" hreflang>` of a page. */
|
|
31
|
+
export interface HreflangAlternate {
|
|
32
|
+
hreflang: string;
|
|
33
|
+
href: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The language alternates of a page (Theme ABI v2 §2, "Market and language selection"): the platform serves every
|
|
37
|
+
* published language on the same URL and picks one from `?locale=<language>`, so the alternate for a language is
|
|
38
|
+
* the page's canonical URL with that parameter. `x-default` is the canonical URL itself, where the gateway applies
|
|
39
|
+
* the shopper's remembered choice, else the store's default language.
|
|
40
|
+
*
|
|
41
|
+
* `canonical` is `ctx.route.canonical` (absolute, same origin, no query: ABI §2.4); `languages` is
|
|
42
|
+
* `ctx.locale.availableLanguages`. A store that publishes fewer than two languages has no alternates.
|
|
43
|
+
* Markets are not alternates here: a market changes prices and currency, not the page's language, and the ABI
|
|
44
|
+
* defines no per-market URL other than the shopper's `?country=` choice.
|
|
45
|
+
*/
|
|
46
|
+
export declare function hreflangAlternates(canonical: string, languages: readonly string[]): HreflangAlternate[];
|
|
47
|
+
export {};
|
package/dist/abi/seo.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const https = (url) => {
|
|
2
|
+
if (typeof url !== 'string' || !url.trim())
|
|
3
|
+
return '';
|
|
4
|
+
try {
|
|
5
|
+
const u = new URL(url.trim());
|
|
6
|
+
return u.protocol === 'https:' && u.hostname ? u.href : '';
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/** The first hero's image on the page (its background image setting), when it is an absolute https: URL. */
|
|
13
|
+
export function heroImageOf(nodes) {
|
|
14
|
+
for (const n of nodes) {
|
|
15
|
+
if (n.type === 'hero') {
|
|
16
|
+
const url = https(n.settings?.backgroundImage);
|
|
17
|
+
if (url)
|
|
18
|
+
return url;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
export function homeHead(shop, shopName, nodes, sentence) {
|
|
24
|
+
const seo = shop.seo;
|
|
25
|
+
const description = seo?.description || (shop.description ?? '').trim() || (sentence ? sentence.split('{name}').join(shopName) : '');
|
|
26
|
+
const own = https(seo?.image?.url);
|
|
27
|
+
const image = own || https(shop.brand?.squareLogo?.url) || https(shop.brand?.logo?.url) || heroImageOf(nodes);
|
|
28
|
+
return {
|
|
29
|
+
...(seo?.title ? { title: seo.title } : {}),
|
|
30
|
+
description,
|
|
31
|
+
image,
|
|
32
|
+
...(own && seo?.image?.altText ? { imageAlt: seo.image.altText } : {}),
|
|
33
|
+
...(own && seo?.image?.width ? { imageWidth: seo.image.width } : {}),
|
|
34
|
+
...(own && seo?.image?.height ? { imageHeight: seo.image.height } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The language alternates of a page (Theme ABI v2 §2, "Market and language selection"): the platform serves every
|
|
39
|
+
* published language on the same URL and picks one from `?locale=<language>`, so the alternate for a language is
|
|
40
|
+
* the page's canonical URL with that parameter. `x-default` is the canonical URL itself, where the gateway applies
|
|
41
|
+
* the shopper's remembered choice, else the store's default language.
|
|
42
|
+
*
|
|
43
|
+
* `canonical` is `ctx.route.canonical` (absolute, same origin, no query: ABI §2.4); `languages` is
|
|
44
|
+
* `ctx.locale.availableLanguages`. A store that publishes fewer than two languages has no alternates.
|
|
45
|
+
* Markets are not alternates here: a market changes prices and currency, not the page's language, and the ABI
|
|
46
|
+
* defines no per-market URL other than the shopper's `?country=` choice.
|
|
47
|
+
*/
|
|
48
|
+
export function hreflangAlternates(canonical, languages) {
|
|
49
|
+
const seen = new Set();
|
|
50
|
+
const langs = [];
|
|
51
|
+
for (const l of languages) {
|
|
52
|
+
if (typeof l !== 'string' || !/^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(l))
|
|
53
|
+
continue;
|
|
54
|
+
const k = l.toLowerCase();
|
|
55
|
+
if (seen.has(k))
|
|
56
|
+
continue;
|
|
57
|
+
seen.add(k);
|
|
58
|
+
langs.push(l);
|
|
59
|
+
}
|
|
60
|
+
if (langs.length < 2 || !/^https?:\/\//.test(canonical))
|
|
61
|
+
return [];
|
|
62
|
+
const base = canonical.split('#')[0];
|
|
63
|
+
const sep = base.includes('?') ? '&' : '?';
|
|
64
|
+
return [
|
|
65
|
+
...langs.map((l) => ({ hreflang: l, href: `${base}${sep}locale=${encodeURIComponent(l)}` })),
|
|
66
|
+
{ hreflang: 'x-default', href: base },
|
|
67
|
+
];
|
|
68
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page shell under Theme ABI v2 — what platform/runtime/shell/PageShell.tsx is for the
|
|
3
|
+
* redesign, minus everything the ABI gives to the platform:
|
|
4
|
+
*
|
|
5
|
+
* - no soft navigation: under ABI v2 every navigation is a full page load, because a template's
|
|
6
|
+
* content is the store's revision, which only the server has (the theme's own starter
|
|
7
|
+
* templates would render the wrong page);
|
|
8
|
+
* - no tracking pixels and no analytics beacons: the platform owns both (§4, §10.5);
|
|
9
|
+
* - the plane (preview vs live) is `ctx.mode`, handed in by the entry — never read from the URL.
|
|
10
|
+
*
|
|
11
|
+
* Provider order is the redesign's: theme Provider → StoreProvider → OverlayProvider →
|
|
12
|
+
* RuntimeBridge → theme Layout → the page's sections.
|
|
13
|
+
*/
|
|
14
|
+
import type { ReactNode } from 'react';
|
|
15
|
+
export declare function AbiShell({ location, locale, contentLanguage, settings, preview, children }: {
|
|
16
|
+
location: string;
|
|
17
|
+
locale: string;
|
|
18
|
+
contentLanguage?: string;
|
|
19
|
+
settings: Record<string, unknown>;
|
|
20
|
+
preview: boolean;
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getThemeBundle } from '../runtime/slots.js';
|
|
3
|
+
import { StoreProvider } from '../runtime/data/StoreProvider.js';
|
|
4
|
+
import { OverlayProvider } from '../runtime/shell/overlay-state.js';
|
|
5
|
+
import { RuntimeBridge } from '../runtime/shell/RuntimeBridge.js';
|
|
6
|
+
export function AbiShell({ location, locale, contentLanguage, settings, preview, children }) {
|
|
7
|
+
const { Provider, Layout } = getThemeBundle().theme;
|
|
8
|
+
const mode = preview ? 'editor' : 'storefront';
|
|
9
|
+
return (_jsx(Provider, { mode: mode, locale: locale, contentLanguage: contentLanguage, settings: settings, children: _jsx(StoreProvider, { location: location, locale: locale, settings: settings, children: _jsx(OverlayProvider, { children: _jsx(RuntimeBridge, { mode: mode, locale: locale, settings: settings, children: _jsx(Layout, { children: children }) }) }) }) }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Mirrors render-context.v2.d.ts `WireEnvelope` (not yet in theme-abi 2.0.0-alpha.2). */
|
|
2
|
+
export type WireEnvelope<T> = {
|
|
3
|
+
ok: true;
|
|
4
|
+
data: T;
|
|
5
|
+
dataVersion: string;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
error: {
|
|
9
|
+
code: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
requestId: string;
|
|
12
|
+
refusal?: unknown;
|
|
13
|
+
};
|
|
14
|
+
data?: T;
|
|
15
|
+
};
|
|
16
|
+
export interface AbiRemote {
|
|
17
|
+
/** Resolves with `data` of an ok envelope; rejects with AbiWireError otherwise. */
|
|
18
|
+
data(op: string, args: readonly unknown[]): Promise<unknown>;
|
|
19
|
+
/** Resolves with the full envelope, so a caller can read `data` on a conflict. */
|
|
20
|
+
action(name: `${string}.${string}`, args: readonly unknown[]): Promise<WireEnvelope<unknown>>;
|
|
21
|
+
}
|
|
22
|
+
export declare class AbiWireError extends Error {
|
|
23
|
+
readonly status: number;
|
|
24
|
+
readonly code: string | null;
|
|
25
|
+
/** The server's `Retry-After`, in ms from now; null when it sent none (or one we cannot read). */
|
|
26
|
+
readonly retryAfterMs: number | null;
|
|
27
|
+
constructor(status: number, code: string | null,
|
|
28
|
+
/** The server's `Retry-After`, in ms from now; null when it sent none (or one we cannot read). */
|
|
29
|
+
retryAfterMs?: number | null);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `Retry-After` (RFC 9110 §10.2.3) as ms from `now`: delay-seconds or an HTTP-date. A rate-limited
|
|
33
|
+
* `/_tq/data` answers `429` with `retry-after: 30`; the cart waits that long rather than hammering
|
|
34
|
+
* the same budget (QA test-2 F1).
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseRetryAfter(value: string | null, now?: number): number | null;
|
|
37
|
+
/** Browser-only; the routes are relative to the page's own origin. */
|
|
38
|
+
export declare function createAbiRemote(): AbiRemote;
|
package/dist/abi/wire.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { canonicalize } from './jcs.js';
|
|
2
|
+
/** `PLATFORM_ROUTES` values (the type pins them to the contract; scripts/abi/build.mjs re-checks at build). */
|
|
3
|
+
const DATA = '/_tq/data/';
|
|
4
|
+
const ACTIONS = '/_tq/actions/';
|
|
5
|
+
const MAX_ACTION_BYTES = 8 * 1024;
|
|
6
|
+
export class AbiWireError extends Error {
|
|
7
|
+
constructor(status, code,
|
|
8
|
+
/** The server's `Retry-After`, in ms from now; null when it sent none (or one we cannot read). */
|
|
9
|
+
retryAfterMs = null) {
|
|
10
|
+
super(`[nova] /_tq request failed: HTTP ${status}${code ? ` ${code}` : ''}`);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.retryAfterMs = retryAfterMs;
|
|
14
|
+
this.name = 'AbiWireError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `Retry-After` (RFC 9110 §10.2.3) as ms from `now`: delay-seconds or an HTTP-date. A rate-limited
|
|
19
|
+
* `/_tq/data` answers `429` with `retry-after: 30`; the cart waits that long rather than hammering
|
|
20
|
+
* the same budget (QA test-2 F1).
|
|
21
|
+
*/
|
|
22
|
+
export function parseRetryAfter(value, now = Date.now()) {
|
|
23
|
+
if (value === null)
|
|
24
|
+
return null;
|
|
25
|
+
const v = value.trim();
|
|
26
|
+
if (/^\d+$/.test(v))
|
|
27
|
+
return Number(v) * 1000;
|
|
28
|
+
const at = Date.parse(v);
|
|
29
|
+
return Number.isNaN(at) ? null : Math.max(0, at - now);
|
|
30
|
+
}
|
|
31
|
+
function base64url(text) {
|
|
32
|
+
const bytes = new TextEncoder().encode(text);
|
|
33
|
+
let bin = '';
|
|
34
|
+
for (const b of bytes)
|
|
35
|
+
bin += String.fromCharCode(b);
|
|
36
|
+
return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
37
|
+
}
|
|
38
|
+
function csrfToken() {
|
|
39
|
+
return document.querySelector('meta[name="tq-csrf"]')?.content || null;
|
|
40
|
+
}
|
|
41
|
+
async function envelope(res) {
|
|
42
|
+
let body = null;
|
|
43
|
+
try {
|
|
44
|
+
body = await res.json();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
body = null;
|
|
48
|
+
}
|
|
49
|
+
if (body && typeof body === 'object' && 'ok' in body)
|
|
50
|
+
return body;
|
|
51
|
+
return { ok: false, error: { code: res.ok ? 'invalid_envelope' : 'unavailable', requestId: '' } };
|
|
52
|
+
}
|
|
53
|
+
/** Browser-only; the routes are relative to the page's own origin. */
|
|
54
|
+
export function createAbiRemote() {
|
|
55
|
+
return {
|
|
56
|
+
async data(op, args) {
|
|
57
|
+
const qs = args.length ? `?a=${base64url(canonicalize(args))}` : '';
|
|
58
|
+
const res = await fetch(`${DATA}${op}${qs}`, { method: 'GET', credentials: 'same-origin', headers: { accept: 'application/json' } });
|
|
59
|
+
const env = await envelope(res);
|
|
60
|
+
if (!env.ok)
|
|
61
|
+
throw new AbiWireError(res.status, env.error.code, parseRetryAfter(res.headers.get('retry-after')));
|
|
62
|
+
return env.data;
|
|
63
|
+
},
|
|
64
|
+
async action(name, args) {
|
|
65
|
+
const body = JSON.stringify({ v: 2, args });
|
|
66
|
+
if (new TextEncoder().encode(body).length > MAX_ACTION_BYTES)
|
|
67
|
+
throw new AbiWireError(413, 'invalid_argument');
|
|
68
|
+
const post = async () => {
|
|
69
|
+
const token = csrfToken();
|
|
70
|
+
return fetch(`${ACTIONS}${name}`, {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
credentials: 'same-origin',
|
|
73
|
+
headers: { 'content-type': 'application/json', accept: 'application/json', ...(token ? { 'x-tq-csrf': token } : {}) },
|
|
74
|
+
body,
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
let env = await envelope(await post());
|
|
78
|
+
// §4.1: a first visit has no CSRF cookie yet — the token is re-read once and the call retried.
|
|
79
|
+
if (!env.ok && env.error.code === 'csrf_failed')
|
|
80
|
+
env = await envelope(await post());
|
|
81
|
+
return env;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@tanqory/theme-kit/build` — derive a theme's ABI v2 manifest from what the theme already declares: its
|
|
3
|
+
* `defineSection` / `defineBlock` schemas, its theme settings, its templates, and the `ai` roles of its sections
|
|
4
|
+
* (printed as `x-tanqory-ai`). Pure (no file system, no React): a theme's build script loads the theme, calls
|
|
5
|
+
* `buildManifest`, validates the result with `@tanqory/theme-abi` `validateManifest`, and writes the files.
|
|
6
|
+
*
|
|
7
|
+
* const { manifest, problems } = buildManifest({ name, version, theme, settings, templates, forms: { newsletter: true } })
|
|
8
|
+
*
|
|
9
|
+
* Capabilities: the kit's runtime needs the defaults below. `data:shop` is always declared (decision D6: the
|
|
10
|
+
* platform hands shop data to the browser snapshot only to a theme that declares it). Add more with
|
|
11
|
+
* `capabilities` (e.g. `data:inventory` to show stock counts).
|
|
12
|
+
*/
|
|
13
|
+
import type { Field } from './sdk/schema.js';
|
|
14
|
+
import type { SettingSpec, ThemeDefinition } from './sdk/theme.js';
|
|
15
|
+
import { type AiProfile } from './headless/ai.js';
|
|
16
|
+
import { type Strings } from './headless/strings.js';
|
|
17
|
+
export { aiProfileOf, checkAiProfile, type AiProfile, type AiRole } from './headless/ai.js';
|
|
18
|
+
export { KIT_STRINGS, kitStrings } from './headless/strings.js';
|
|
19
|
+
/** RFC 8785 JSON canonicalization: `manifest.json` is its JCS bytes plus one trailing LF. */
|
|
20
|
+
export { canonicalize } from './abi/jcs.js';
|
|
21
|
+
/** What the kit's server render reads (`ctx.data`, `ctx.actions`). `data:shop` is always declared (D6). */
|
|
22
|
+
export declare const SERVER_CAPABILITIES: readonly string[];
|
|
23
|
+
/** What the kit's browser runtime calls over `/_tq/data` and `/_tq/actions`. `data:shop` is always declared (D6). */
|
|
24
|
+
export declare const BROWSER_CAPABILITIES: readonly string[];
|
|
25
|
+
/** The fields each platform form posts (`forms.<id>.fields`); `website` is the honeypot. */
|
|
26
|
+
export declare const FORM_FIELDS: Readonly<Record<'newsletter' | 'contact', readonly string[]>>;
|
|
27
|
+
export interface RegionSpec {
|
|
28
|
+
title: string;
|
|
29
|
+
scope: 'shared' | 'template';
|
|
30
|
+
accepts?: readonly string[];
|
|
31
|
+
min?: number;
|
|
32
|
+
max?: number;
|
|
33
|
+
}
|
|
34
|
+
/** Header (shared), the template's body, footer (shared): where `zone` header / main / footer place a section. */
|
|
35
|
+
export declare const DEFAULT_REGIONS: Readonly<Record<string, RegionSpec>>;
|
|
36
|
+
/** A value check for stored values (`@tanqory/theme-abi` `validateFieldValue`, or the registry-2 wrapper a theme uses). */
|
|
37
|
+
export type ValueCheck = (type: string, value: unknown, spec: Record<string, unknown>) => {
|
|
38
|
+
ok: boolean;
|
|
39
|
+
errors?: readonly {
|
|
40
|
+
message: string;
|
|
41
|
+
code?: string;
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
export interface BuildManifestInput {
|
|
45
|
+
/** Package-style theme name (`@scope/name`). */
|
|
46
|
+
name: string;
|
|
47
|
+
version: string;
|
|
48
|
+
theme: ThemeDefinition;
|
|
49
|
+
/** Theme settings (`defineSettings`), grouped by each setting's `group`. */
|
|
50
|
+
settings?: Readonly<Record<string, SettingSpec>>;
|
|
51
|
+
/** Template name → its route kind (`home`, `product`, …, `not_found`, `custom:<id>`) and regions in order. */
|
|
52
|
+
templates: Readonly<Record<string, {
|
|
53
|
+
route: string;
|
|
54
|
+
title?: string;
|
|
55
|
+
regions?: readonly string[];
|
|
56
|
+
}>>;
|
|
57
|
+
regions?: Readonly<Record<string, RegionSpec>>;
|
|
58
|
+
/** `custom:<id>` route paths. */
|
|
59
|
+
customRoutes?: Readonly<Record<string, {
|
|
60
|
+
path: string;
|
|
61
|
+
}>>;
|
|
62
|
+
/** Added to the kit's defaults. */
|
|
63
|
+
capabilities?: {
|
|
64
|
+
server?: readonly string[];
|
|
65
|
+
browser?: readonly string[];
|
|
66
|
+
};
|
|
67
|
+
/** Platform forms the theme renders (`<NewsletterForm>`, `<ContactForm>`). */
|
|
68
|
+
forms?: {
|
|
69
|
+
newsletter?: boolean | {
|
|
70
|
+
title: string;
|
|
71
|
+
};
|
|
72
|
+
contact?: boolean | {
|
|
73
|
+
title: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/** The theme's content document version (default 1). */
|
|
77
|
+
contentVersion?: number;
|
|
78
|
+
/** `engines["tanqory-field-types"]` (default "2": `asset:client/…` image values in defaults and presets). */
|
|
79
|
+
fieldTypes?: '1' | '2';
|
|
80
|
+
/** The AI-compat profile; from the sections' `ai` roles by default, `false` for none. */
|
|
81
|
+
aiProfile?: AiProfile | false;
|
|
82
|
+
/** Checks every default and preset value (e.g. `validateFieldValue` from `@tanqory/theme-abi`). */
|
|
83
|
+
checkValue?: ValueCheck;
|
|
84
|
+
/** Extra top-level `x-*` members. */
|
|
85
|
+
extensions?: Readonly<Record<`x-${string}`, unknown>>;
|
|
86
|
+
}
|
|
87
|
+
export interface BuiltManifest {
|
|
88
|
+
manifest: Record<string, unknown>;
|
|
89
|
+
/** Contract problems found while deriving it; a build should refuse to ship with any. */
|
|
90
|
+
problems: string[];
|
|
91
|
+
}
|
|
92
|
+
/** "buttonLabel" → "Button label". */
|
|
93
|
+
export declare function humanize(key: string): string;
|
|
94
|
+
/** A settings-DSL field as a manifest attribute (registry field spec). */
|
|
95
|
+
export declare function fieldSpecOf(key: string, f: Field): Record<string, unknown>;
|
|
96
|
+
/** The manifest of a headless theme. */
|
|
97
|
+
export declare function buildManifest(input: BuildManifestInput): BuiltManifest;
|
|
98
|
+
interface Node {
|
|
99
|
+
id?: string;
|
|
100
|
+
type?: string;
|
|
101
|
+
settings?: Record<string, unknown>;
|
|
102
|
+
blocks?: readonly Node[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Problems in starter content (a template's or region's sections): every node names a declared component, has an
|
|
106
|
+
* ABI node id, and holds only its component's attributes (each value through `checkValue` when given).
|
|
107
|
+
*/
|
|
108
|
+
export declare function checkContent(where: string, nodes: readonly Node[], manifest: Record<string, unknown>, checkValue?: ValueCheck): string[];
|
|
109
|
+
/**
|
|
110
|
+
* The theme's locale files with the kit's words underneath: every key the kit's primitives use exists in every
|
|
111
|
+
* language the kit has words for, and the theme's own values win.
|
|
112
|
+
*/
|
|
113
|
+
export declare function withKitStrings(locales: Readonly<Record<string, Strings>>): Record<string, Record<string, string>>;
|