@shop-on/theme-routes 0.2.0 → 0.4.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/adapter.d.ts +16 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/routes/checkout.d.ts +25 -0
- package/dist/routes/checkout.js +34 -0
- package/package.json +3 -3
package/dist/adapter.d.ts
CHANGED
|
@@ -195,6 +195,21 @@ export interface AccountSeam {
|
|
|
195
195
|
url: string;
|
|
196
196
|
}>;
|
|
197
197
|
}
|
|
198
|
+
export interface CheckoutSeam {
|
|
199
|
+
/** The theme's cart → checkout server fn: without `state`, checkout's
|
|
200
|
+
* `/begin` URL; with the `checkout_state` it sent back, a minted handoff. */
|
|
201
|
+
startCheckoutFn(opts: {
|
|
202
|
+
data: {
|
|
203
|
+
state?: string;
|
|
204
|
+
};
|
|
205
|
+
}): Promise<{
|
|
206
|
+
ok: true;
|
|
207
|
+
redirectTo: string;
|
|
208
|
+
} | {
|
|
209
|
+
ok: false;
|
|
210
|
+
reason: string;
|
|
211
|
+
}>;
|
|
212
|
+
}
|
|
198
213
|
export interface PreviewSeam {
|
|
199
214
|
/** Rendered when there is nothing to preview, or when the section throws. */
|
|
200
215
|
Unavailable: ComponentType;
|
|
@@ -211,6 +226,7 @@ export interface ThemeRouteAdapter extends RendererSeam, I18nSeam {
|
|
|
211
226
|
fns: TemplateFns;
|
|
212
227
|
parsers: SearchParsers;
|
|
213
228
|
account: AccountSeam;
|
|
229
|
+
checkout: CheckoutSeam;
|
|
214
230
|
preview: PreviewSeam;
|
|
215
231
|
}
|
|
216
232
|
//#endregion
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DepsArg, HeadArg, LoaderArg, NullableHeadArg, NullableTemplateRouteOptions, ParsedBlogSearch, ParsedListingSearch, PreviewDeps, SeoHeadResult, ServerRouteHandler, TemplateRouteOptions } from "./types.js";
|
|
2
|
-
import { AccountSeam, ArticleTemplateArgs, BlogPageTemplateArgs, BlogSearchSeam, CollectionPageTemplateArgs, CollectionSearchSeam, CollectionsTemplateArgs, HomeTemplateArgs, I18nSeam, PageTemplateArgs, PasswordTemplateArgs, PolicyTemplateArgs, PreviewSeam, ProductSearchSeam, ProductTemplateArgs, RendererSeam, SearchPageTemplateArgs, SearchParsers, SectionPreviewArgs, SeoSeam, TemplateByIdArgs, TemplateFn, TemplateFns, ThemeRouteAdapter } from "./adapter.js";
|
|
2
|
+
import { AccountSeam, ArticleTemplateArgs, BlogPageTemplateArgs, BlogSearchSeam, CheckoutSeam, CollectionPageTemplateArgs, CollectionSearchSeam, CollectionsTemplateArgs, HomeTemplateArgs, I18nSeam, PageTemplateArgs, PasswordTemplateArgs, PolicyTemplateArgs, PreviewSeam, ProductSearchSeam, ProductTemplateArgs, RendererSeam, SearchPageTemplateArgs, SearchParsers, SectionPreviewArgs, SeoSeam, TemplateByIdArgs, TemplateFn, TemplateFns, ThemeRouteAdapter } from "./adapter.js";
|
|
3
3
|
import { templatePreloadLinks } from "./preload-links.js";
|
|
4
4
|
import { SeoHelpers, SeoHelpersOptions, createSeoHelpers, isPreviewSearch, paginatedPath } from "./seo-head.js";
|
|
5
5
|
import { ThemeRouterOptions, createThemeRouter } from "./router.js";
|
|
@@ -7,6 +7,7 @@ import { useOptionalTemplate, useTemplate } from "./use-template.js";
|
|
|
7
7
|
import { accountBounceOptions, accountIndexRouteOptions } from "./routes/account.js";
|
|
8
8
|
import { articleRouteOptions, blogRouteOptions } from "./routes/blog.js";
|
|
9
9
|
import { cartRouteOptions } from "./routes/cart.js";
|
|
10
|
+
import { checkoutRouteOptions } from "./routes/checkout.js";
|
|
10
11
|
import { collectionRouteOptions, collectionsIndexRouteOptions } from "./routes/collection.js";
|
|
11
12
|
import { homeRouteOptions } from "./routes/home.js";
|
|
12
13
|
import { localeLayoutRouteOptions } from "./routes/locale-layout.js";
|
|
@@ -26,4 +27,4 @@ import { analyticsEventsHandler, analyticsVisitsHandler } from "./routes/server/
|
|
|
26
27
|
import { analyticsScriptHandler } from "./routes/server/analytics-script.js";
|
|
27
28
|
import { customerLogoutHandler } from "./routes/server/customer-logout.js";
|
|
28
29
|
import { robotsHandler, sitemapHandler } from "./routes/server/seo-proxy.js";
|
|
29
|
-
export { type AccountSeam, type ArticleTemplateArgs, type BlogPageTemplateArgs, type BlogSearchSeam, type CollectionPageTemplateArgs, type CollectionSearchSeam, type CollectionsTemplateArgs, type DepsArg, type HeadArg, type HomeTemplateArgs, type I18nSeam, type LoaderArg, type NullableHeadArg, type NullableTemplateRouteOptions, type PageTemplateArgs, type ParsedBlogSearch, type ParsedListingSearch, type PasswordTemplateArgs, type PolicyTemplateArgs, type PreviewDeps, type PreviewSeam, type ProductSearchSeam, type ProductTemplateArgs, type RendererSeam, type SearchPageTemplateArgs, type SearchParsers, type SectionPreviewArgs, type SeoHeadResult, type SeoHelpers, type SeoHelpersOptions, type SeoSeam, type ServerRouteHandler, type TemplateByIdArgs, type TemplateFn, type TemplateFns, type TemplateRouteOptions, type ThemeRouteAdapter, type ThemeRouterOptions, accountBounceOptions, accountIndexRouteOptions, analyticsEventsHandler, analyticsScriptHandler, analyticsVisitsHandler, articleRouteComponent, articleRouteOptions, blogRouteOptions, cartRouteOptions, collectionProductRouteOptions, collectionRouteOptions, collectionsIndexRouteOptions, createSeoHelpers, createThemeRouter, customerLogoutHandler, homeRouteComponent, homeRouteOptions, isPreviewSearch, localeLayoutComponent, localeLayoutRouteOptions, notFoundRouteOptions, optionalTemplatePageComponent, pageRouteOptions, paginatedPath, passwordRouteOptions, policyRouteOptions, productRouteComponent, productRouteOptions, robotsHandler, searchRouteOptions, sectionPreviewErrorComponent, sectionPreviewRouteComponent, sectionPreviewRouteOptions, sitemapHandler, templatePageComponent, templatePreloadLinks, useOptionalTemplate, useTemplate };
|
|
30
|
+
export { type AccountSeam, type ArticleTemplateArgs, type BlogPageTemplateArgs, type BlogSearchSeam, type CheckoutSeam, type CollectionPageTemplateArgs, type CollectionSearchSeam, type CollectionsTemplateArgs, type DepsArg, type HeadArg, type HomeTemplateArgs, type I18nSeam, type LoaderArg, type NullableHeadArg, type NullableTemplateRouteOptions, type PageTemplateArgs, type ParsedBlogSearch, type ParsedListingSearch, type PasswordTemplateArgs, type PolicyTemplateArgs, type PreviewDeps, type PreviewSeam, type ProductSearchSeam, type ProductTemplateArgs, type RendererSeam, type SearchPageTemplateArgs, type SearchParsers, type SectionPreviewArgs, type SeoHeadResult, type SeoHelpers, type SeoHelpersOptions, type SeoSeam, type ServerRouteHandler, type TemplateByIdArgs, type TemplateFn, type TemplateFns, type TemplateRouteOptions, type ThemeRouteAdapter, type ThemeRouterOptions, accountBounceOptions, accountIndexRouteOptions, analyticsEventsHandler, analyticsScriptHandler, analyticsVisitsHandler, articleRouteComponent, articleRouteOptions, blogRouteOptions, cartRouteOptions, checkoutRouteOptions, collectionProductRouteOptions, collectionRouteOptions, collectionsIndexRouteOptions, createSeoHelpers, createThemeRouter, customerLogoutHandler, homeRouteComponent, homeRouteOptions, isPreviewSearch, localeLayoutComponent, localeLayoutRouteOptions, notFoundRouteOptions, optionalTemplatePageComponent, pageRouteOptions, paginatedPath, passwordRouteOptions, policyRouteOptions, productRouteComponent, productRouteOptions, robotsHandler, searchRouteOptions, sectionPreviewErrorComponent, sectionPreviewRouteComponent, sectionPreviewRouteOptions, sitemapHandler, templatePageComponent, templatePreloadLinks, useOptionalTemplate, useTemplate };
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { useOptionalTemplate, useTemplate } from "./use-template.js";
|
|
|
5
5
|
import { accountBounceOptions, accountIndexRouteOptions } from "./routes/account.js";
|
|
6
6
|
import { articleRouteOptions, blogRouteOptions } from "./routes/blog.js";
|
|
7
7
|
import { cartRouteOptions } from "./routes/cart.js";
|
|
8
|
+
import { checkoutRouteOptions } from "./routes/checkout.js";
|
|
8
9
|
import { collectionRouteOptions, collectionsIndexRouteOptions } from "./routes/collection.js";
|
|
9
10
|
import { homeRouteOptions } from "./routes/home.js";
|
|
10
11
|
import { localeLayoutRouteOptions } from "./routes/locale-layout.js";
|
|
@@ -24,4 +25,4 @@ import { analyticsEventsHandler, analyticsVisitsHandler } from "./routes/server/
|
|
|
24
25
|
import { analyticsScriptHandler } from "./routes/server/analytics-script.js";
|
|
25
26
|
import { customerLogoutHandler } from "./routes/server/customer-logout.js";
|
|
26
27
|
import { robotsHandler, sitemapHandler } from "./routes/server/seo-proxy.js";
|
|
27
|
-
export { accountBounceOptions, accountIndexRouteOptions, analyticsEventsHandler, analyticsScriptHandler, analyticsVisitsHandler, articleRouteComponent, articleRouteOptions, blogRouteOptions, cartRouteOptions, collectionProductRouteOptions, collectionRouteOptions, collectionsIndexRouteOptions, createSeoHelpers, createThemeRouter, customerLogoutHandler, homeRouteComponent, homeRouteOptions, isPreviewSearch, localeLayoutComponent, localeLayoutRouteOptions, notFoundRouteOptions, optionalTemplatePageComponent, pageRouteOptions, paginatedPath, passwordRouteOptions, policyRouteOptions, productRouteComponent, productRouteOptions, robotsHandler, searchRouteOptions, sectionPreviewErrorComponent, sectionPreviewRouteComponent, sectionPreviewRouteOptions, sitemapHandler, templatePageComponent, templatePreloadLinks, useOptionalTemplate, useTemplate };
|
|
28
|
+
export { accountBounceOptions, accountIndexRouteOptions, analyticsEventsHandler, analyticsScriptHandler, analyticsVisitsHandler, articleRouteComponent, articleRouteOptions, blogRouteOptions, cartRouteOptions, checkoutRouteOptions, collectionProductRouteOptions, collectionRouteOptions, collectionsIndexRouteOptions, createSeoHelpers, createThemeRouter, customerLogoutHandler, homeRouteComponent, homeRouteOptions, isPreviewSearch, localeLayoutComponent, localeLayoutRouteOptions, notFoundRouteOptions, optionalTemplatePageComponent, pageRouteOptions, paginatedPath, passwordRouteOptions, policyRouteOptions, productRouteComponent, productRouteOptions, robotsHandler, searchRouteOptions, sectionPreviewErrorComponent, sectionPreviewRouteComponent, sectionPreviewRouteOptions, sitemapHandler, templatePageComponent, templatePreloadLinks, useOptionalTemplate, useTemplate };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CheckoutSeam } from "../adapter.js";
|
|
2
|
+
import { PreviewSearch } from "@shop-on/theme-react/preview-guard";
|
|
3
|
+
//#region src/routes/checkout.d.ts
|
|
4
|
+
interface CheckoutSearch extends PreviewSearch {
|
|
5
|
+
checkout_state?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* `/checkout`: a server-side bounce, twice. First visit (no `checkout_state`):
|
|
9
|
+
* off to the central checkout's `/begin`, which binds this browser and sends
|
|
10
|
+
* the buyer back here with a state. Second visit: mint the cart handoff with
|
|
11
|
+
* that state and go to checkout. Never renders, and never on a URL holding a
|
|
12
|
+
* state: any failure goes home. From `beforeLoad`, like the account bouncers,
|
|
13
|
+
* so the root loader's fan-out never runs for a redirect.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkoutRouteOptions(adapter: CheckoutSeam): {
|
|
16
|
+
validateSearch: (search: Record<string, unknown>) => CheckoutSearch;
|
|
17
|
+
beforeLoad: ({ params, search }: {
|
|
18
|
+
params: {
|
|
19
|
+
locale?: string;
|
|
20
|
+
};
|
|
21
|
+
search: CheckoutSearch;
|
|
22
|
+
}) => Promise<never>;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { redirect } from "@tanstack/react-router";
|
|
2
|
+
import { bouncePreviewToNotFound } from "@shop-on/theme-react/preview-guard";
|
|
3
|
+
//#region src/routes/checkout.ts
|
|
4
|
+
/**
|
|
5
|
+
* `/checkout`: a server-side bounce, twice. First visit (no `checkout_state`):
|
|
6
|
+
* off to the central checkout's `/begin`, which binds this browser and sends
|
|
7
|
+
* the buyer back here with a state. Second visit: mint the cart handoff with
|
|
8
|
+
* that state and go to checkout. Never renders, and never on a URL holding a
|
|
9
|
+
* state: any failure goes home. From `beforeLoad`, like the account bouncers,
|
|
10
|
+
* so the root loader's fan-out never runs for a redirect.
|
|
11
|
+
*/
|
|
12
|
+
function checkoutRouteOptions(adapter) {
|
|
13
|
+
return {
|
|
14
|
+
validateSearch: (search) => ({
|
|
15
|
+
preview: typeof search.preview === "string" ? search.preview : void 0,
|
|
16
|
+
checkout_state: typeof search.checkout_state === "string" ? search.checkout_state : void 0
|
|
17
|
+
}),
|
|
18
|
+
beforeLoad: async ({ params, search }) => {
|
|
19
|
+
bouncePreviewToNotFound(search);
|
|
20
|
+
const result = await adapter.startCheckoutFn({ data: { state: search.checkout_state } }).catch((err) => {
|
|
21
|
+
console.warn("[checkout] handoff failed:", err);
|
|
22
|
+
return null;
|
|
23
|
+
});
|
|
24
|
+
if (!result?.ok) throw redirect({
|
|
25
|
+
to: "/{-$locale}",
|
|
26
|
+
params: { locale: params.locale },
|
|
27
|
+
search: { preview: void 0 }
|
|
28
|
+
});
|
|
29
|
+
throw redirect({ href: result.redirectTo });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { checkoutRouteOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shop-on/theme-routes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "SEE LICENSE IN dist/LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"./package.json": "./package.json"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@shop-on/theme-react": "0.
|
|
21
|
-
"@shop-on/theme-runtime": "0.
|
|
20
|
+
"@shop-on/theme-react": "0.4.0",
|
|
21
|
+
"@shop-on/theme-runtime": "0.4.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@bprogress/core": "1.3.4",
|