@orunelle/theme-runtime 0.0.0-stage → 2.0.0-alpha.13

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.
Files changed (97) hide show
  1. package/dist/application.d.ts +7 -0
  2. package/dist/application.d.ts.map +1 -0
  3. package/dist/application.js +58 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +429 -0
  7. package/dist/commerce.d.ts +235 -0
  8. package/dist/commerce.d.ts.map +1 -0
  9. package/dist/commerce.js +316 -0
  10. package/dist/credentials.d.ts +11 -0
  11. package/dist/credentials.d.ts.map +1 -0
  12. package/dist/credentials.js +79 -0
  13. package/dist/fixtures.d.ts +23 -0
  14. package/dist/fixtures.d.ts.map +1 -0
  15. package/dist/fixtures.js +131 -0
  16. package/dist/host/package.json +1 -0
  17. package/dist/host/preview/editor.css +116 -0
  18. package/dist/host/preview/editor.tsx +193 -0
  19. package/dist/host/preview/src/bridge.tsx +371 -0
  20. package/dist/host/preview/src/client.tsx +15 -0
  21. package/dist/host/preview/src/env.d.ts +5 -0
  22. package/dist/host/preview/src/preview.css +40 -0
  23. package/dist/host/preview/src/server.tsx +95 -0
  24. package/dist/host/preview/src/surface.tsx +264 -0
  25. package/dist/host/serve-node.mjs +133 -0
  26. package/dist/host/storefront/public/fonts/9da48a48bf6500f8-s.p.woff2 +0 -0
  27. package/dist/host/storefront/public/fonts/e4af272ccee01ff0-s.p.woff2 +0 -0
  28. package/dist/host/storefront/public/fonts/e4efb0298547fad0-s.p.woff2 +0 -0
  29. package/dist/host/storefront/public/fonts/f022b1629605b85c-s.p.woff2 +0 -0
  30. package/dist/host/storefront/public/fonts/fb66eb17bf011c3b-s.p.woff2 +0 -0
  31. package/dist/host/storefront/public/fonts.css +7 -0
  32. package/dist/host/storefront/public/samples/pouch-navy.svg +4 -0
  33. package/dist/host/storefront/public/samples/throw-oat.svg +2 -0
  34. package/dist/host/storefront/public/samples/throw-sage.svg +2 -0
  35. package/dist/host/storefront/public/samples/tote-charcoal.svg +5 -0
  36. package/dist/host/storefront/public/samples/tote-detail.svg +1 -0
  37. package/dist/host/storefront/public/samples/tote-sand.svg +5 -0
  38. package/dist/host/storefront/src/binding.server.ts +1 -0
  39. package/dist/host/storefront/src/data.ts +2 -0
  40. package/dist/host/storefront/src/env.d.ts +5 -0
  41. package/dist/host/storefront/src/queries.ts +1 -0
  42. package/dist/host/storefront/src/routeTree.gen.ts +155 -0
  43. package/dist/host/storefront/src/router.tsx +31 -0
  44. package/dist/host/storefront/src/routes/$locale.$.tsx +135 -0
  45. package/dist/host/storefront/src/routes/$locale.index.tsx +19 -0
  46. package/dist/host/storefront/src/routes/$locale.products.$handle.tsx +57 -0
  47. package/dist/host/storefront/src/routes/$locale.tsx +36 -0
  48. package/dist/host/storefront/src/routes/__root.tsx +103 -0
  49. package/dist/host/storefront/src/routes/index.tsx +6 -0
  50. package/dist/host/storefront/src/server.ts +1 -0
  51. package/dist/host.d.ts +45 -0
  52. package/dist/host.d.ts.map +1 -0
  53. package/dist/host.js +380 -0
  54. package/dist/local-editor.d.ts +2 -0
  55. package/dist/local-editor.d.ts.map +1 -0
  56. package/dist/local-editor.js +111 -0
  57. package/dist/managed-worker.d.ts +2 -0
  58. package/dist/managed-worker.d.ts.map +1 -0
  59. package/dist/managed-worker.js +22 -0
  60. package/dist/server.d.ts +5 -0
  61. package/dist/server.d.ts.map +1 -0
  62. package/dist/server.js +98 -0
  63. package/dist/source.d.ts +19 -0
  64. package/dist/source.d.ts.map +1 -0
  65. package/dist/source.js +131 -0
  66. package/dist/tanstack/binding.server.d.ts +4 -0
  67. package/dist/tanstack/binding.server.d.ts.map +1 -0
  68. package/dist/tanstack/binding.server.js +9 -0
  69. package/dist/tanstack/data.d.ts +44 -0
  70. package/dist/tanstack/data.d.ts.map +1 -0
  71. package/dist/tanstack/data.js +320 -0
  72. package/dist/tanstack/index.d.ts +4 -0
  73. package/dist/tanstack/index.d.ts.map +1 -0
  74. package/dist/tanstack/index.js +2 -0
  75. package/dist/tanstack/queries.d.ts +6 -0
  76. package/dist/tanstack/queries.d.ts.map +1 -0
  77. package/dist/tanstack/queries.js +5 -0
  78. package/dist/template/app/client.tsx +3 -0
  79. package/dist/template/app/env.d.ts +1 -0
  80. package/dist/template/app/router.tsx +40 -0
  81. package/dist/template/app/routes/$locale.$.tsx +135 -0
  82. package/dist/template/app/routes/$locale.index.tsx +19 -0
  83. package/dist/template/app/routes/$locale.products.$handle.tsx +57 -0
  84. package/dist/template/app/routes/$locale.tsx +46 -0
  85. package/dist/template/app/routes/__root.tsx +103 -0
  86. package/dist/template/app/routes/index.tsx +6 -0
  87. package/dist/template/app/server.ts +1 -0
  88. package/dist/template/app/start.ts +2 -0
  89. package/dist/template/app/theme.ts +12 -0
  90. package/dist/template/tests/router-isolation.test.ts +14 -0
  91. package/dist/template/vite.config.ts +5 -0
  92. package/dist/template/vitest.config.ts +9 -0
  93. package/dist/vite.d.ts +7 -0
  94. package/dist/vite.d.ts.map +1 -0
  95. package/dist/vite.js +22 -0
  96. package/package.json +88 -3
  97. package/README.md +0 -3
@@ -0,0 +1,31 @@
1
+ import { createRouter } from "@tanstack/react-router";
2
+ import { routeTree } from "./routeTree.gen";
3
+ import { QueryClient } from "@tanstack/react-query";
4
+ import { setupRouterSsrQueryIntegration } from "@tanstack/react-router-ssr-query";
5
+
6
+ export function getRouter() {
7
+ const queryClient = new QueryClient({
8
+ defaultOptions: { queries: { retry: false, staleTime: 30_000 } },
9
+ });
10
+ const router = createRouter({
11
+ routeTree,
12
+ context: { queryClient },
13
+ scrollRestoration: true,
14
+ defaultPreload: "intent",
15
+ defaultPreloadStaleTime: 0,
16
+ });
17
+ setupRouterSsrQueryIntegration({
18
+ router,
19
+ queryClient,
20
+ dehydrateOptions: {
21
+ shouldDehydrateQuery: (query) =>
22
+ query.meta?.visibility === "public" && query.state.status === "success",
23
+ },
24
+ });
25
+ return router;
26
+ }
27
+ declare module "@tanstack/react-router" {
28
+ interface Register {
29
+ router: ReturnType<typeof getRouter>;
30
+ }
31
+ }
@@ -0,0 +1,135 @@
1
+ import { createFileRoute, notFound, redirect } from "@tanstack/react-router";
2
+ import { useThemeComponents } from "@orunelle/theme-sdk";
3
+ import {
4
+ DefaultCheckoutPage,
5
+ DefaultPaymentCallback,
6
+ } from "@orunelle/theme-engine";
7
+ import { pageQuery } from "../queries";
8
+ import type { PublicInput } from "../data";
9
+
10
+ function match(
11
+ path: string,
12
+ ): { kind: "private"; path: string } | Pick<PublicInput, "kind" | "slug"> {
13
+ if (
14
+ [
15
+ "cart",
16
+ "checkout",
17
+ "checkout/paymob-callback",
18
+ "checkout/xpay-callback",
19
+ "login",
20
+ "register",
21
+ "forgot-password",
22
+ "reset-password",
23
+ "verify-email",
24
+ "account",
25
+ "account/addresses",
26
+ "account/orders",
27
+ "account/wishlist",
28
+ "tracking",
29
+ ].includes(path) ||
30
+ /^account\/orders\/[^/]+$/.test(path)
31
+ )
32
+ return { kind: "private", path };
33
+ if (path === "products") return { kind: "catalog" };
34
+ if (path === "search") return { kind: "search" };
35
+ if (path === "collections") return { kind: "collections" };
36
+ if (path === "categories") return { kind: "categories" };
37
+ const item = /^(categories|collections|pages)\/([^/]+)$/.exec(path);
38
+ if (item)
39
+ return {
40
+ kind:
41
+ item[1] === "categories"
42
+ ? "category"
43
+ : item[1] === "collections"
44
+ ? "collection"
45
+ : "content",
46
+ slug: item[2],
47
+ };
48
+ throw notFound();
49
+ }
50
+ export const Route = createFileRoute("/$locale/$")({
51
+ validateSearch: (input: Record<string, unknown>) => {
52
+ const page = input.page === undefined ? 1 : Number(input.page);
53
+ if (
54
+ !Number.isSafeInteger(page) ||
55
+ page < 1 ||
56
+ page > 10000 ||
57
+ (input.q !== undefined &&
58
+ (typeof input.q !== "string" || input.q.length > 200))
59
+ )
60
+ throw notFound();
61
+ return {
62
+ ...(input.page !== undefined ? { page } : {}),
63
+ ...(typeof input.q === "string" ? { q: input.q } : {}),
64
+ ...(typeof input.token === "string" && input.token.length <= 200
65
+ ? { token: input.token }
66
+ : {}),
67
+ ...(typeof input.order === "string" && input.order.length <= 80
68
+ ? { order: input.order }
69
+ : {}),
70
+ };
71
+ },
72
+ loaderDeps: ({ search }) => ({
73
+ ...search,
74
+ page: search.page ?? 1,
75
+ q: search.q ?? "",
76
+ }),
77
+ loader: ({ params, context, deps, location }) => {
78
+ const path = params._splat ?? "";
79
+ const aliases: Record<string, string> = {
80
+ "account/profile": "account",
81
+ "track-order": "tracking",
82
+ "checkout/success": "account/orders",
83
+ "auth/login": "login",
84
+ "auth/register": "register",
85
+ "auth/verify": "verify-email",
86
+ "auth/forgot-password": "forgot-password",
87
+ "auth/reset-password": "reset-password",
88
+ "legal/privacy": "pages/privacy",
89
+ "legal/terms": "pages/terms",
90
+ drops: "collections",
91
+ };
92
+ const target =
93
+ aliases[path] ??
94
+ (path.startsWith("drops/")
95
+ ? path.replace(/^drops\//, "collections/")
96
+ : path.startsWith("category/")
97
+ ? path.replace(/^category\//, "categories/")
98
+ : undefined);
99
+ if (target)
100
+ throw redirect({
101
+ href: `/${params.locale}/${target}${location.searchStr}`,
102
+ statusCode: 301,
103
+ });
104
+ const route = match(params._splat ?? "");
105
+ if (route.kind === "private") return route;
106
+ return context.queryClient.ensureQueryData(
107
+ pageQuery(context.storefront, {
108
+ ...route,
109
+ locale: context.storefront.locale,
110
+ page: deps.page,
111
+ q: deps.q,
112
+ }),
113
+ );
114
+ },
115
+ head: ({ loaderData }) =>
116
+ loaderData && "title" in loaderData
117
+ ? { meta: [{ title: loaderData.title }] }
118
+ : {},
119
+ component: Page,
120
+ });
121
+ function Page() {
122
+ const data = Route.useLoaderData();
123
+ const { CatalogPage, CollectionsPage, ContentPage, AccountPage, CartPage } =
124
+ useThemeComponents();
125
+ if (data.kind === "private") {
126
+ if (data.path === "cart") return <CartPage />;
127
+ if (data.path === "checkout") return <DefaultCheckoutPage />;
128
+ if (data.path.startsWith("checkout/")) return <DefaultPaymentCallback />;
129
+ return <AccountPage path={data.path} />;
130
+ }
131
+ if (data.kind === "catalog") return <CatalogPage data={data} />;
132
+ if (data.kind === "collections") return <CollectionsPage data={data} />;
133
+ if (data.kind === "content") return <ContentPage data={data} />;
134
+ return null;
135
+ }
@@ -0,0 +1,19 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import { useThemeComponents } from "@orunelle/theme-sdk";
3
+ import { pageQuery } from "../queries";
4
+
5
+ export const Route = createFileRoute("/$locale/")({
6
+ loader: ({ context }) =>
7
+ context.queryClient.ensureQueryData(
8
+ pageQuery(context.storefront, {
9
+ kind: "home",
10
+ locale: context.storefront.locale,
11
+ }),
12
+ ),
13
+ component: Catalog,
14
+ });
15
+ function Catalog() {
16
+ const { HomePage } = useThemeComponents();
17
+ const data = Route.useLoaderData();
18
+ return data.kind === "catalog" ? <HomePage products={data.products} resources={data.resources} /> : null;
19
+ }
@@ -0,0 +1,57 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import {
3
+ useThemeComponents,
4
+ useStorefront,
5
+ ThemePageData,
6
+ ThemeComposition,
7
+ } from "@orunelle/theme-sdk";
8
+ import { pageQuery } from "../queries";
9
+
10
+ export const Route = createFileRoute("/$locale/products/$handle")({
11
+ loader: ({ params, context }) =>
12
+ context.queryClient.ensureQueryData(
13
+ pageQuery(context.storefront, {
14
+ kind: "product",
15
+ locale: context.storefront.locale,
16
+ slug: params.handle,
17
+ }),
18
+ ),
19
+ head: ({ loaderData, params }) =>
20
+ loaderData
21
+ ? {
22
+ meta: [{ title: loaderData.title }],
23
+ }
24
+ : {},
25
+ component: Product,
26
+ });
27
+ function Product() {
28
+ const { configuration } = useStorefront();
29
+ const { ProductPage } = useThemeComponents();
30
+ const data = Route.useLoaderData();
31
+ return data.kind === "product" ? (
32
+ <ThemePageData
33
+ products={[data.product]}
34
+ variants={data.variants}
35
+ related={data.related}
36
+ optionVisuals={data.optionVisuals}
37
+ >
38
+ <ThemeComposition
39
+ scope="template"
40
+ name={
41
+ configuration?.assignments.find(
42
+ (assignment) => assignment.resource.id === data.product.id,
43
+ )?.template ?? "product.default"
44
+ }
45
+ productId={data.product.id}
46
+ fallback={
47
+ <ProductPage
48
+ product={data.product}
49
+ variants={data.variants}
50
+ related={data.related ?? []}
51
+ optionVisuals={data.optionVisuals ?? {}}
52
+ />
53
+ }
54
+ />
55
+ </ThemePageData>
56
+ ) : null;
57
+ }
@@ -0,0 +1,36 @@
1
+ import { createFileRoute, notFound, Outlet } from "@tanstack/react-router";
2
+ import {
3
+ StorefrontProvider,
4
+ type StorefrontContext,
5
+ } from "@orunelle/theme-sdk";
6
+ import { resolveTheme } from "@orunelle/theme-engine";
7
+ import definition from "virtual:orunelle/theme";
8
+
9
+ const theme = resolveTheme(definition);
10
+ export const Route = createFileRoute("/$locale")({
11
+ beforeLoad: ({ params, context }) => {
12
+ if (params.locale !== "en" && params.locale !== "ar") throw notFound();
13
+ const storefront: StorefrontContext = {
14
+ ...context.storefront,
15
+ locale: params.locale,
16
+ };
17
+ return { storefront };
18
+ },
19
+ component: LocalizedStorefront,
20
+ });
21
+ function LocalizedStorefront() {
22
+ const { storefront } = Route.useRouteContext();
23
+ const { Layout } = theme.components;
24
+ return (
25
+ <StorefrontProvider
26
+ theme={theme}
27
+ storefront={storefront}
28
+ configuration={storefront.configuration}
29
+ media={storefront.media}
30
+ >
31
+ <Layout>
32
+ <Outlet />
33
+ </Layout>
34
+ </StorefrontProvider>
35
+ );
36
+ }
@@ -0,0 +1,103 @@
1
+ import {
2
+ createRootRouteWithContext,
3
+ HeadContent,
4
+ Link,
5
+ Outlet,
6
+ Scripts,
7
+ useRouterState,
8
+ } from "@tanstack/react-router";
9
+ import { getStorefront } from "../data";
10
+ import styles from "@orunelle/theme-engine/styles.css?url";
11
+ import type { QueryClient } from "@tanstack/react-query";
12
+
13
+ export const Route = createRootRouteWithContext<{ queryClient: QueryClient }>()(
14
+ {
15
+ beforeLoad: async () => ({ storefront: await getStorefront() }),
16
+ head: ({ matches }) => {
17
+ const storefront = matches[0]?.context.storefront;
18
+ const last = matches.at(-1);
19
+ const path = last?.pathname ?? "/";
20
+ const publicPage =
21
+ last?.status === "success" &&
22
+ /^\/(en|ar)(\/?$|\/(products|categories|collections|pages)(\/[^/]+)?\/?$)/.test(
23
+ path,
24
+ );
25
+ return {
26
+ meta: [
27
+ { charSet: "utf-8" },
28
+ { name: "viewport", content: "width=device-width, initial-scale=1" },
29
+ { title: "Orunelle reference store" },
30
+ {
31
+ name: "robots",
32
+ content:
33
+ storefront?.indexable && publicPage
34
+ ? "index, follow"
35
+ : "noindex, nofollow",
36
+ },
37
+ ],
38
+ links: [
39
+ ...(storefront?.indexable && publicPage
40
+ ? [
41
+ { rel: "canonical", href: storefront.origin + path },
42
+ ...(["en", "ar"] as const).map((locale) => ({
43
+ rel: "alternate",
44
+ hrefLang: locale,
45
+ href:
46
+ storefront.origin +
47
+ path.replace(/^\/(en|ar)/, "/" + locale),
48
+ })),
49
+ ]
50
+ : []),
51
+ { rel: "stylesheet", href: styles },
52
+ { rel: "stylesheet", href: "/fonts.css" },
53
+ ],
54
+ };
55
+ },
56
+ component: Document,
57
+ notFoundComponent: NotFound,
58
+ errorComponent: () => (
59
+ <section className="error-page">
60
+ <h1>Store unavailable / المتجر غير متاح</h1>
61
+ <p>
62
+ Please refresh to try again. / أعد تحميل الصفحة للمحاولة مرة أخرى.
63
+ </p>
64
+ </section>
65
+ ),
66
+ },
67
+ );
68
+ function Document() {
69
+ const locale = useRouterState({
70
+ select: (state) =>
71
+ state.location.pathname.split("/")[1] === "ar" ? "ar" : "en",
72
+ });
73
+ return (
74
+ <html lang={locale} dir={locale === "ar" ? "rtl" : "ltr"}>
75
+ <head>
76
+ <HeadContent />
77
+ </head>
78
+ <body>
79
+ <Outlet />
80
+ <Scripts />
81
+ </body>
82
+ </html>
83
+ );
84
+ }
85
+ function NotFound() {
86
+ const locale = useRouterState({
87
+ select: (state) =>
88
+ state.location.pathname.split("/")[1] === "ar" ? "ar" : "en",
89
+ });
90
+ return (
91
+ <section className="storefront-shell error-page">
92
+ <h1>{locale === "ar" ? "الصفحة غير موجودة" : "Page not found"}</h1>
93
+ <p>
94
+ {locale === "ar"
95
+ ? "قد تكون الصفحة نُقلت أو لم تعد متاحة."
96
+ : "This page may have moved or is no longer available."}
97
+ </p>
98
+ <Link to="/$locale" params={{ locale }}>
99
+ {locale === "ar" ? "العودة إلى المنتجات" : "Back to products"}
100
+ </Link>
101
+ </section>
102
+ );
103
+ }
@@ -0,0 +1,6 @@
1
+ import { createFileRoute, redirect } from "@tanstack/react-router";
2
+ export const Route = createFileRoute("/")({
3
+ beforeLoad: () => {
4
+ throw redirect({ to: "/$locale", params: { locale: "en" } });
5
+ },
6
+ });
@@ -0,0 +1 @@
1
+ export { default } from "@orunelle/theme-runtime/server";
package/dist/host.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { type InlineConfig } from "vite";
2
+ import { type ThemeSource } from "./source.js";
3
+ export declare function toolchainIdentity(): Promise<{
4
+ toolchainDigest: string;
5
+ policy: string;
6
+ node: string;
7
+ vite: string;
8
+ start: string;
9
+ react: string;
10
+ runtimeAbi: string;
11
+ }>;
12
+ export declare function prepare(project: string, source: ThemeSource, work: string): Promise<{
13
+ sourceRoot: string;
14
+ entry: string;
15
+ work: string;
16
+ project: string;
17
+ themeEntry: string;
18
+ serverEntry: string;
19
+ applicationRoot: string;
20
+ manifest: import("@orunelle/theme-contract").MerchantManifest;
21
+ defaults: any;
22
+ sourceDigest: string;
23
+ files: Map<string, Buffer<ArrayBufferLike>>;
24
+ application: boolean;
25
+ }>;
26
+ export declare function managedConfig(state: Awaited<ReturnType<typeof prepare>>, preview: boolean, output?: string): InlineConfig;
27
+ export declare function buildTheme(project: string, output: string, supplied?: ThemeSource): Promise<{
28
+ artifactDigest: string;
29
+ sha256: Record<string, string>;
30
+ schemaVersion: number;
31
+ runtimeAbi: string;
32
+ manifest: import("@orunelle/theme-contract").MerchantManifest;
33
+ defaults: any;
34
+ sourceDigest: string;
35
+ toolchainDigest: string;
36
+ entry: string;
37
+ styles: string[];
38
+ assets: string[];
39
+ }>;
40
+ export declare function devTheme(project: string, port: number): Promise<{
41
+ server: import("vite").ViteDevServer;
42
+ origin: string;
43
+ }>;
44
+ export declare function useLocalAuthorSource(state: Awaited<ReturnType<typeof prepare>>): Promise<void>;
45
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAYA,OAAO,EAKL,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;AAId,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;AA2CrB,wBAAsB,iBAAiB;;;;;;;;GAgCtC;AAkGD,wBAAsB,OAAO,CAC3B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,MAAM;;;;;;;;;;;;;GAqDb;AACD,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,EAC1C,OAAO,EAAE,OAAO,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,YAAY,CAwHd;AACD,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,WAAW;;;;;;;;;;;;GAiFvB;AACD,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;;;GAiB3D;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,iBAgB3C"}