@orunelle/theme-runtime 0.0.0-stage → 2.0.0-alpha.14
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/application.d.ts +7 -0
- package/dist/application.d.ts.map +1 -0
- package/dist/application.js +58 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +429 -0
- package/dist/commerce.d.ts +235 -0
- package/dist/commerce.d.ts.map +1 -0
- package/dist/commerce.js +316 -0
- package/dist/credentials.d.ts +11 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +79 -0
- package/dist/fixtures.d.ts +23 -0
- package/dist/fixtures.d.ts.map +1 -0
- package/dist/fixtures.js +131 -0
- package/dist/host/package.json +1 -0
- package/dist/host/preview/editor.css +116 -0
- package/dist/host/preview/editor.tsx +193 -0
- package/dist/host/preview/src/bridge.tsx +371 -0
- package/dist/host/preview/src/client.tsx +15 -0
- package/dist/host/preview/src/env.d.ts +5 -0
- package/dist/host/preview/src/preview.css +40 -0
- package/dist/host/preview/src/server.tsx +95 -0
- package/dist/host/preview/src/surface.tsx +264 -0
- package/dist/host/serve-node.mjs +133 -0
- package/dist/host/storefront/public/fonts/9da48a48bf6500f8-s.p.woff2 +0 -0
- package/dist/host/storefront/public/fonts/e4af272ccee01ff0-s.p.woff2 +0 -0
- package/dist/host/storefront/public/fonts/e4efb0298547fad0-s.p.woff2 +0 -0
- package/dist/host/storefront/public/fonts/f022b1629605b85c-s.p.woff2 +0 -0
- package/dist/host/storefront/public/fonts/fb66eb17bf011c3b-s.p.woff2 +0 -0
- package/dist/host/storefront/public/fonts.css +7 -0
- package/dist/host/storefront/public/samples/pouch-navy.svg +4 -0
- package/dist/host/storefront/public/samples/throw-oat.svg +2 -0
- package/dist/host/storefront/public/samples/throw-sage.svg +2 -0
- package/dist/host/storefront/public/samples/tote-charcoal.svg +5 -0
- package/dist/host/storefront/public/samples/tote-detail.svg +1 -0
- package/dist/host/storefront/public/samples/tote-sand.svg +5 -0
- package/dist/host/storefront/src/binding.server.ts +1 -0
- package/dist/host/storefront/src/data.ts +2 -0
- package/dist/host/storefront/src/env.d.ts +5 -0
- package/dist/host/storefront/src/queries.ts +1 -0
- package/dist/host/storefront/src/routeTree.gen.ts +155 -0
- package/dist/host/storefront/src/router.tsx +31 -0
- package/dist/host/storefront/src/routes/$locale.$.tsx +135 -0
- package/dist/host/storefront/src/routes/$locale.index.tsx +19 -0
- package/dist/host/storefront/src/routes/$locale.products.$handle.tsx +57 -0
- package/dist/host/storefront/src/routes/$locale.tsx +36 -0
- package/dist/host/storefront/src/routes/__root.tsx +103 -0
- package/dist/host/storefront/src/routes/index.tsx +6 -0
- package/dist/host/storefront/src/server.ts +1 -0
- package/dist/host.d.ts +45 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +380 -0
- package/dist/local-editor.d.ts +2 -0
- package/dist/local-editor.d.ts.map +1 -0
- package/dist/local-editor.js +111 -0
- package/dist/managed-worker.d.ts +2 -0
- package/dist/managed-worker.d.ts.map +1 -0
- package/dist/managed-worker.js +22 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +98 -0
- package/dist/source.d.ts +19 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +131 -0
- package/dist/tanstack/binding.server.d.ts +4 -0
- package/dist/tanstack/binding.server.d.ts.map +1 -0
- package/dist/tanstack/binding.server.js +9 -0
- package/dist/tanstack/data.d.ts +44 -0
- package/dist/tanstack/data.d.ts.map +1 -0
- package/dist/tanstack/data.js +320 -0
- package/dist/tanstack/index.d.ts +4 -0
- package/dist/tanstack/index.d.ts.map +1 -0
- package/dist/tanstack/index.js +2 -0
- package/dist/tanstack/queries.d.ts +6 -0
- package/dist/tanstack/queries.d.ts.map +1 -0
- package/dist/tanstack/queries.js +5 -0
- package/dist/template/app/client.tsx +3 -0
- package/dist/template/app/env.d.ts +1 -0
- package/dist/template/app/router.tsx +40 -0
- package/dist/template/app/routes/$locale.$.tsx +135 -0
- package/dist/template/app/routes/$locale.index.tsx +19 -0
- package/dist/template/app/routes/$locale.products.$handle.tsx +57 -0
- package/dist/template/app/routes/$locale.tsx +46 -0
- package/dist/template/app/routes/__root.tsx +103 -0
- package/dist/template/app/routes/index.tsx +6 -0
- package/dist/template/app/server.ts +1 -0
- package/dist/template/app/start.ts +2 -0
- package/dist/template/app/theme.ts +12 -0
- package/dist/template/tests/router-isolation.test.ts +14 -0
- package/dist/template/vite.config.ts +5 -0
- package/dist/template/vitest.config.ts +9 -0
- package/dist/vite.d.ts +7 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +22 -0
- package/package.json +88 -3
- package/README.md +0 -3
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { StorefrontContext } from "@orunelle/theme-contract";
|
|
3
|
+
declare const bindingSchema: z.ZodObject<{
|
|
4
|
+
origin: z.ZodString;
|
|
5
|
+
apiOrigin: z.ZodString;
|
|
6
|
+
store: z.ZodObject<{
|
|
7
|
+
id: z.ZodString;
|
|
8
|
+
slug: z.ZodString;
|
|
9
|
+
name: z.ZodObject<{
|
|
10
|
+
en: z.ZodString;
|
|
11
|
+
ar: z.ZodString;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
en: string;
|
|
14
|
+
ar: string;
|
|
15
|
+
}, {
|
|
16
|
+
en: string;
|
|
17
|
+
ar: string;
|
|
18
|
+
}>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
id: string;
|
|
21
|
+
name: {
|
|
22
|
+
en: string;
|
|
23
|
+
ar: string;
|
|
24
|
+
};
|
|
25
|
+
slug: string;
|
|
26
|
+
}, {
|
|
27
|
+
id: string;
|
|
28
|
+
name: {
|
|
29
|
+
en: string;
|
|
30
|
+
ar: string;
|
|
31
|
+
};
|
|
32
|
+
slug: string;
|
|
33
|
+
}>;
|
|
34
|
+
release: z.ZodString;
|
|
35
|
+
configurationRevision: z.ZodNumber;
|
|
36
|
+
currency: z.ZodString;
|
|
37
|
+
market: z.ZodLiteral<"EG">;
|
|
38
|
+
indexable: z.ZodDefault<z.ZodBoolean>;
|
|
39
|
+
media: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
40
|
+
id: z.ZodString;
|
|
41
|
+
url: z.ZodString;
|
|
42
|
+
alt: z.ZodString;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
id: string;
|
|
45
|
+
url: string;
|
|
46
|
+
alt: string;
|
|
47
|
+
}, {
|
|
48
|
+
id: string;
|
|
49
|
+
url: string;
|
|
50
|
+
alt: string;
|
|
51
|
+
}>, "many">>;
|
|
52
|
+
configuration: z.ZodOptional<z.ZodType<import("@orunelle/theme-contract").ThemeConfiguration, z.ZodTypeDef, import("@orunelle/theme-contract").ThemeConfiguration>>;
|
|
53
|
+
/** Short-lived, render-scoped data capability (server-side only). */
|
|
54
|
+
brokerToken: z.ZodOptional<z.ZodString>;
|
|
55
|
+
/** Merchant branding added by the platform at render time. */
|
|
56
|
+
brand: z.ZodOptional<z.ZodObject<{
|
|
57
|
+
logo: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, "strict", z.ZodTypeAny, {
|
|
59
|
+
logo?: string | undefined;
|
|
60
|
+
}, {
|
|
61
|
+
logo?: string | undefined;
|
|
62
|
+
}>>;
|
|
63
|
+
pages: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
64
|
+
slug: z.ZodString;
|
|
65
|
+
title: z.ZodObject<{
|
|
66
|
+
en: z.ZodString;
|
|
67
|
+
ar: z.ZodString;
|
|
68
|
+
}, "strip", z.ZodTypeAny, {
|
|
69
|
+
en: string;
|
|
70
|
+
ar: string;
|
|
71
|
+
}, {
|
|
72
|
+
en: string;
|
|
73
|
+
ar: string;
|
|
74
|
+
}>;
|
|
75
|
+
paragraphs: z.ZodObject<{
|
|
76
|
+
en: z.ZodArray<z.ZodString, "many">;
|
|
77
|
+
ar: z.ZodArray<z.ZodString, "many">;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
en: string[];
|
|
80
|
+
ar: string[];
|
|
81
|
+
}, {
|
|
82
|
+
en: string[];
|
|
83
|
+
ar: string[];
|
|
84
|
+
}>;
|
|
85
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
|
+
title: {
|
|
87
|
+
en: string;
|
|
88
|
+
ar: string;
|
|
89
|
+
};
|
|
90
|
+
slug: string;
|
|
91
|
+
paragraphs: {
|
|
92
|
+
en: string[];
|
|
93
|
+
ar: string[];
|
|
94
|
+
};
|
|
95
|
+
}, {
|
|
96
|
+
title: {
|
|
97
|
+
en: string;
|
|
98
|
+
ar: string;
|
|
99
|
+
};
|
|
100
|
+
slug: string;
|
|
101
|
+
paragraphs: {
|
|
102
|
+
en: string[];
|
|
103
|
+
ar: string[];
|
|
104
|
+
};
|
|
105
|
+
}>, "many">>;
|
|
106
|
+
}, "strict", z.ZodTypeAny, {
|
|
107
|
+
pages: {
|
|
108
|
+
title: {
|
|
109
|
+
en: string;
|
|
110
|
+
ar: string;
|
|
111
|
+
};
|
|
112
|
+
slug: string;
|
|
113
|
+
paragraphs: {
|
|
114
|
+
en: string[];
|
|
115
|
+
ar: string[];
|
|
116
|
+
};
|
|
117
|
+
}[];
|
|
118
|
+
origin: string;
|
|
119
|
+
release: string;
|
|
120
|
+
currency: string;
|
|
121
|
+
apiOrigin: string;
|
|
122
|
+
store: {
|
|
123
|
+
id: string;
|
|
124
|
+
name: {
|
|
125
|
+
en: string;
|
|
126
|
+
ar: string;
|
|
127
|
+
};
|
|
128
|
+
slug: string;
|
|
129
|
+
};
|
|
130
|
+
configurationRevision: number;
|
|
131
|
+
market: "EG";
|
|
132
|
+
indexable: boolean;
|
|
133
|
+
media: {
|
|
134
|
+
id: string;
|
|
135
|
+
url: string;
|
|
136
|
+
alt: string;
|
|
137
|
+
}[];
|
|
138
|
+
configuration?: import("@orunelle/theme-contract").ThemeConfiguration | undefined;
|
|
139
|
+
brokerToken?: string | undefined;
|
|
140
|
+
brand?: {
|
|
141
|
+
logo?: string | undefined;
|
|
142
|
+
} | undefined;
|
|
143
|
+
}, {
|
|
144
|
+
origin: string;
|
|
145
|
+
release: string;
|
|
146
|
+
currency: string;
|
|
147
|
+
apiOrigin: string;
|
|
148
|
+
store: {
|
|
149
|
+
id: string;
|
|
150
|
+
name: {
|
|
151
|
+
en: string;
|
|
152
|
+
ar: string;
|
|
153
|
+
};
|
|
154
|
+
slug: string;
|
|
155
|
+
};
|
|
156
|
+
configurationRevision: number;
|
|
157
|
+
market: "EG";
|
|
158
|
+
pages?: {
|
|
159
|
+
title: {
|
|
160
|
+
en: string;
|
|
161
|
+
ar: string;
|
|
162
|
+
};
|
|
163
|
+
slug: string;
|
|
164
|
+
paragraphs: {
|
|
165
|
+
en: string[];
|
|
166
|
+
ar: string[];
|
|
167
|
+
};
|
|
168
|
+
}[] | undefined;
|
|
169
|
+
indexable?: boolean | undefined;
|
|
170
|
+
media?: {
|
|
171
|
+
id: string;
|
|
172
|
+
url: string;
|
|
173
|
+
alt: string;
|
|
174
|
+
}[] | undefined;
|
|
175
|
+
configuration?: import("@orunelle/theme-contract").ThemeConfiguration | undefined;
|
|
176
|
+
brokerToken?: string | undefined;
|
|
177
|
+
brand?: {
|
|
178
|
+
logo?: string | undefined;
|
|
179
|
+
} | undefined;
|
|
180
|
+
}>;
|
|
181
|
+
export type StoreBinding = z.infer<typeof bindingSchema>;
|
|
182
|
+
/**
|
|
183
|
+
* Branding the platform sends beside the binding. Older runtimes ignore it,
|
|
184
|
+
* and an invalid value is dropped here rather than failing the render.
|
|
185
|
+
*/
|
|
186
|
+
export declare const renderBrandSchema: z.ZodObject<{
|
|
187
|
+
logo: z.ZodOptional<z.ZodObject<{
|
|
188
|
+
id: z.ZodString;
|
|
189
|
+
url: z.ZodString;
|
|
190
|
+
alt: z.ZodString;
|
|
191
|
+
}, "strict", z.ZodTypeAny, {
|
|
192
|
+
id: string;
|
|
193
|
+
url: string;
|
|
194
|
+
alt: string;
|
|
195
|
+
}, {
|
|
196
|
+
id: string;
|
|
197
|
+
url: string;
|
|
198
|
+
alt: string;
|
|
199
|
+
}>>;
|
|
200
|
+
}, "strict", z.ZodTypeAny, {
|
|
201
|
+
logo?: {
|
|
202
|
+
id: string;
|
|
203
|
+
url: string;
|
|
204
|
+
alt: string;
|
|
205
|
+
} | undefined;
|
|
206
|
+
}, {
|
|
207
|
+
logo?: {
|
|
208
|
+
id: string;
|
|
209
|
+
url: string;
|
|
210
|
+
alt: string;
|
|
211
|
+
} | undefined;
|
|
212
|
+
}>;
|
|
213
|
+
/** Adds the merchant's branding to a render binding. */
|
|
214
|
+
export declare function brandBinding<T extends {
|
|
215
|
+
media?: {
|
|
216
|
+
id: string;
|
|
217
|
+
url: string;
|
|
218
|
+
alt: string;
|
|
219
|
+
}[];
|
|
220
|
+
}>(binding: T, brand: unknown): T;
|
|
221
|
+
export interface CommerceEnvironment {
|
|
222
|
+
ORUNELLE_STOREFRONT_BINDINGS?: string;
|
|
223
|
+
ORUNELLE_PREVIEW_TOKEN?: string;
|
|
224
|
+
}
|
|
225
|
+
/** Operator-owned configuration only. Never read a store/API target from query or forwarding headers. */
|
|
226
|
+
export declare function resolveCommerceBinding(request: Request, env: CommerceEnvironment): {
|
|
227
|
+
context: StorefrontContext;
|
|
228
|
+
binding?: StoreBinding;
|
|
229
|
+
} | null;
|
|
230
|
+
export declare function commerceEndpointAllowed(method: string, path: string): boolean;
|
|
231
|
+
export declare function apiStoreUrl(binding: StoreBinding, path: string): string;
|
|
232
|
+
/** Private same-origin transport; future execution admission is a separate gateway concern. */
|
|
233
|
+
export declare function proxyCommerce(request: Request, env: CommerceEnvironment, fetcher?: typeof fetch): Promise<Response>;
|
|
234
|
+
export {};
|
|
235
|
+
//# sourceMappingURL=commerce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commerce.d.ts","sourceRoot":"","sources":["../src/commerce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2Bf,qEAAqE;;IAErE,8DAA8D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBvD,CAAC;AACZ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;EAWnB,CAAC;AAEZ,wDAAwD;AACxD,wBAAgB,YAAY,CAC1B,CAAC,SAAS;IAAE,KAAK,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,EAChE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAO/B;AACD,MAAM,WAAW,mBAAmB;IAClC,4BAA4B,CAAC,EAAE,MAAM,CAAC;IACtC,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,yGAAyG;AACzG,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,mBAAmB,GACvB;IAAE,OAAO,EAAE,iBAAiB,CAAC;IAAC,OAAO,CAAC,EAAE,YAAY,CAAA;CAAE,GAAG,IAAI,CAuE/D;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAiC7E;AACD,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvE;AAYD,+FAA+F;AAC/F,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,mBAAmB,EACxB,OAAO,GAAE,OAAO,KAAa,GAC5B,OAAO,CAAC,QAAQ,CAAC,CA+InB"}
|
package/dist/commerce.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { resolveFixtureContext } from "./fixtures.js";
|
|
3
|
+
const bindingSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
origin: z.string().url(),
|
|
6
|
+
apiOrigin: z.string().url(),
|
|
7
|
+
store: z.object({
|
|
8
|
+
id: z.string().uuid(),
|
|
9
|
+
slug: z.string().regex(/^[a-z0-9][a-z0-9-]*$/),
|
|
10
|
+
name: z.object({ en: z.string(), ar: z.string() }),
|
|
11
|
+
}),
|
|
12
|
+
release: z.string().min(1),
|
|
13
|
+
configurationRevision: z.number().int().nonnegative(),
|
|
14
|
+
currency: z.string().regex(/^[A-Z]{3}$/),
|
|
15
|
+
market: z.literal("EG"),
|
|
16
|
+
indexable: z.boolean().default(false),
|
|
17
|
+
media: z
|
|
18
|
+
.array(z.object({
|
|
19
|
+
id: z.string().uuid(),
|
|
20
|
+
url: z.string().regex(/^\/__theme-media\/[a-f0-9-]+$/),
|
|
21
|
+
alt: z.string().max(300),
|
|
22
|
+
}))
|
|
23
|
+
.max(1000)
|
|
24
|
+
.default([]),
|
|
25
|
+
configuration: z
|
|
26
|
+
.custom()
|
|
27
|
+
.optional(),
|
|
28
|
+
/** Short-lived, render-scoped data capability (server-side only). */
|
|
29
|
+
brokerToken: z.string().min(16).max(4096).optional(),
|
|
30
|
+
/** Merchant branding added by the platform at render time. */
|
|
31
|
+
brand: z
|
|
32
|
+
.object({ logo: z.string().uuid().optional() })
|
|
33
|
+
.strict()
|
|
34
|
+
.optional(),
|
|
35
|
+
pages: z
|
|
36
|
+
.array(z.object({
|
|
37
|
+
slug: z.string().regex(/^[a-z0-9-]+$/),
|
|
38
|
+
title: z.object({ en: z.string(), ar: z.string() }),
|
|
39
|
+
paragraphs: z.object({
|
|
40
|
+
en: z.array(z.string()),
|
|
41
|
+
ar: z.array(z.string()),
|
|
42
|
+
}),
|
|
43
|
+
}))
|
|
44
|
+
.max(100)
|
|
45
|
+
.default([]),
|
|
46
|
+
})
|
|
47
|
+
.strict();
|
|
48
|
+
/**
|
|
49
|
+
* Branding the platform sends beside the binding. Older runtimes ignore it,
|
|
50
|
+
* and an invalid value is dropped here rather than failing the render.
|
|
51
|
+
*/
|
|
52
|
+
export const renderBrandSchema = z
|
|
53
|
+
.object({
|
|
54
|
+
logo: z
|
|
55
|
+
.object({
|
|
56
|
+
id: z.string().uuid(),
|
|
57
|
+
url: z.string().regex(/^\/__theme-media\/[a-f0-9-]+$/),
|
|
58
|
+
alt: z.string().max(300),
|
|
59
|
+
})
|
|
60
|
+
.strict()
|
|
61
|
+
.optional(),
|
|
62
|
+
})
|
|
63
|
+
.strict();
|
|
64
|
+
/** Adds the merchant's branding to a render binding. */
|
|
65
|
+
export function brandBinding(binding, brand) {
|
|
66
|
+
const parsed = renderBrandSchema.safeParse(brand);
|
|
67
|
+
const logo = parsed.success ? parsed.data.logo : undefined;
|
|
68
|
+
if (!logo)
|
|
69
|
+
return binding;
|
|
70
|
+
const media = (binding.media ?? []).filter((item) => item.id !== logo.id);
|
|
71
|
+
if (media.length >= 1000)
|
|
72
|
+
return binding;
|
|
73
|
+
return { ...binding, media: [...media, logo], brand: { logo: logo.id } };
|
|
74
|
+
}
|
|
75
|
+
/** Operator-owned configuration only. Never read a store/API target from query or forwarding headers. */
|
|
76
|
+
export function resolveCommerceBinding(request, env) {
|
|
77
|
+
const url = new URL(request.url);
|
|
78
|
+
if (env.ORUNELLE_STOREFRONT_BINDINGS !== undefined) {
|
|
79
|
+
let bindings;
|
|
80
|
+
try {
|
|
81
|
+
bindings = z
|
|
82
|
+
.array(bindingSchema)
|
|
83
|
+
.max(100)
|
|
84
|
+
.parse(JSON.parse(env.ORUNELLE_STOREFRONT_BINDINGS));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
if (new Set(bindings.map((b) => b.origin)).size !== bindings.length)
|
|
90
|
+
return null;
|
|
91
|
+
const binding = bindings.find((b) => b.origin === url.origin);
|
|
92
|
+
if (!binding)
|
|
93
|
+
return null;
|
|
94
|
+
const api = new URL(binding.apiOrigin);
|
|
95
|
+
if (api.origin !== binding.apiOrigin ||
|
|
96
|
+
api.username ||
|
|
97
|
+
api.password ||
|
|
98
|
+
(api.protocol !== "https:" &&
|
|
99
|
+
!(api.protocol === "http:" &&
|
|
100
|
+
["localhost", "127.0.0.1", "[::1]"].includes(api.hostname))))
|
|
101
|
+
return null;
|
|
102
|
+
return {
|
|
103
|
+
binding,
|
|
104
|
+
context: {
|
|
105
|
+
store: binding.brand?.logo &&
|
|
106
|
+
binding.media.some((item) => item.id === binding.brand?.logo)
|
|
107
|
+
? {
|
|
108
|
+
...binding.store,
|
|
109
|
+
logo: { assetId: binding.brand.logo, alt: binding.store.name },
|
|
110
|
+
}
|
|
111
|
+
: binding.store,
|
|
112
|
+
origin: binding.origin,
|
|
113
|
+
locale: "en",
|
|
114
|
+
release: binding.release,
|
|
115
|
+
mode: "public",
|
|
116
|
+
currency: binding.currency,
|
|
117
|
+
market: binding.market,
|
|
118
|
+
configurationRevision: binding.configurationRevision,
|
|
119
|
+
indexable: binding.indexable,
|
|
120
|
+
media: binding.media,
|
|
121
|
+
...(binding.configuration
|
|
122
|
+
? { configuration: binding.configuration }
|
|
123
|
+
: {}),
|
|
124
|
+
commerce: "api",
|
|
125
|
+
navigation: binding.pages.map((page) => ({
|
|
126
|
+
path: `pages/${page.slug}`,
|
|
127
|
+
label: page.title,
|
|
128
|
+
})),
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const context = resolveFixtureContext(request, env.ORUNELLE_PREVIEW_TOKEN);
|
|
133
|
+
return context
|
|
134
|
+
? {
|
|
135
|
+
context: {
|
|
136
|
+
...context,
|
|
137
|
+
currency: "EGP",
|
|
138
|
+
market: "EG",
|
|
139
|
+
configurationRevision: 0,
|
|
140
|
+
commerce: "fixture",
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
: null;
|
|
144
|
+
}
|
|
145
|
+
export function commerceEndpointAllowed(method, path) {
|
|
146
|
+
if (/[\\%\u0000-\u001f]/u.test(path) ||
|
|
147
|
+
path.includes("..") ||
|
|
148
|
+
path.includes("//"))
|
|
149
|
+
return false;
|
|
150
|
+
const part = "[^/]+";
|
|
151
|
+
const rules = {
|
|
152
|
+
GET: [
|
|
153
|
+
/^\/(products|categories|collections|settings|cart|addresses|wishlist|orders)$/,
|
|
154
|
+
new RegExp(`^/(products|categories|collections|addresses|orders)/${part}$`),
|
|
155
|
+
new RegExp(`^/products/${part}/variants$`),
|
|
156
|
+
/^\/geo\/(governorates|cities)$/,
|
|
157
|
+
/^\/auth\/(me|providers)$/,
|
|
158
|
+
/^\/payments\/methods$/,
|
|
159
|
+
],
|
|
160
|
+
POST: [
|
|
161
|
+
/^\/auth\/(login|register|refresh|logout|forgot-password|reset-password|verify-otp|google)$/,
|
|
162
|
+
/^\/cart\/(items|merge|summary)$/,
|
|
163
|
+
/^\/(addresses|wishlist)$/,
|
|
164
|
+
/^\/orders\/checkout$/,
|
|
165
|
+
/^\/payments\/(paymob|xpay)\/intent$/,
|
|
166
|
+
],
|
|
167
|
+
PATCH: [
|
|
168
|
+
/^\/auth\/me$/,
|
|
169
|
+
new RegExp(`^/(addresses|wishlist|cart/items)/${part}$`),
|
|
170
|
+
],
|
|
171
|
+
DELETE: [new RegExp(`^/(addresses|wishlist|cart/items)/${part}$`)],
|
|
172
|
+
};
|
|
173
|
+
return rules[method]?.some((rule) => rule.test(path)) ?? false;
|
|
174
|
+
}
|
|
175
|
+
export function apiStoreUrl(binding, path) {
|
|
176
|
+
return `${binding.apiOrigin}/api/storefront/${encodeURIComponent(binding.store.slug)}${path}`;
|
|
177
|
+
}
|
|
178
|
+
const fail = (status, code) => Response.json({
|
|
179
|
+
success: false,
|
|
180
|
+
data: null,
|
|
181
|
+
error: { code },
|
|
182
|
+
meta: { requestId: crypto.randomUUID() },
|
|
183
|
+
}, { status, headers: { "cache-control": "private, no-store" } });
|
|
184
|
+
/** Private same-origin transport; future execution admission is a separate gateway concern. */
|
|
185
|
+
export async function proxyCommerce(request, env, fetcher = fetch) {
|
|
186
|
+
const resolved = resolveCommerceBinding(request, env);
|
|
187
|
+
if (!resolved)
|
|
188
|
+
return fail(404, "NOT_FOUND");
|
|
189
|
+
const { binding, context } = resolved;
|
|
190
|
+
if (!binding || context.mode === "preview")
|
|
191
|
+
return fail(403, "PREVIEW_COMMERCE_DISABLED");
|
|
192
|
+
const url = new URL(request.url);
|
|
193
|
+
let path;
|
|
194
|
+
try {
|
|
195
|
+
path = decodeURIComponent(url.pathname.slice("/__commerce".length));
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return fail(400, "INVALID_PATH");
|
|
199
|
+
}
|
|
200
|
+
if (!commerceEndpointAllowed(request.method, path))
|
|
201
|
+
return fail(404, "NOT_FOUND");
|
|
202
|
+
if (request.method !== "GET" &&
|
|
203
|
+
(request.headers.get("origin") !== context.origin ||
|
|
204
|
+
request.headers.get("sec-fetch-site") === "cross-site"))
|
|
205
|
+
return fail(403, "ORIGIN_NOT_ALLOWED");
|
|
206
|
+
const headers = new Headers({ accept: "application/json" });
|
|
207
|
+
if (path.startsWith("/payments/") && request.method === "POST")
|
|
208
|
+
headers.set("origin", context.origin);
|
|
209
|
+
for (const name of [
|
|
210
|
+
"authorization",
|
|
211
|
+
"content-type",
|
|
212
|
+
"idempotency-key",
|
|
213
|
+
"accept-language",
|
|
214
|
+
]) {
|
|
215
|
+
const value = request.headers.get(name);
|
|
216
|
+
if (value)
|
|
217
|
+
headers.set(name, value);
|
|
218
|
+
}
|
|
219
|
+
// Storefront credential cookies: __Host- names (Path=/) and, during the migration, the
|
|
220
|
+
// legacy names (Path=/__commerce).
|
|
221
|
+
const cookiePrefixes = [
|
|
222
|
+
"__Host-orunelle_cart_",
|
|
223
|
+
"__Host-orunelle_customer_refresh_",
|
|
224
|
+
"orunelle_cart_",
|
|
225
|
+
"orunelle_customer_refresh_",
|
|
226
|
+
];
|
|
227
|
+
const cookies = (request.headers.get("cookie") ?? "")
|
|
228
|
+
.split(";")
|
|
229
|
+
.map((c) => c.trim())
|
|
230
|
+
.filter((c) => cookiePrefixes.some((prefix) => c.startsWith(prefix + context.store.id + "=")));
|
|
231
|
+
if (cookies.length)
|
|
232
|
+
headers.set("cookie", cookies.join("; "));
|
|
233
|
+
let body;
|
|
234
|
+
if (request.method !== "GET") {
|
|
235
|
+
if (!request.headers.get("content-type")?.startsWith("application/json") &&
|
|
236
|
+
!["DELETE"].includes(request.method))
|
|
237
|
+
return fail(415, "JSON_REQUIRED");
|
|
238
|
+
const reader = request.body?.getReader();
|
|
239
|
+
const chunks = [];
|
|
240
|
+
let size = 0;
|
|
241
|
+
if (reader) {
|
|
242
|
+
for (;;) {
|
|
243
|
+
const item = await reader.read();
|
|
244
|
+
if (item.done)
|
|
245
|
+
break;
|
|
246
|
+
size += item.value.length;
|
|
247
|
+
if (size > 262144) {
|
|
248
|
+
await reader.cancel();
|
|
249
|
+
return fail(413, "BODY_TOO_LARGE");
|
|
250
|
+
}
|
|
251
|
+
chunks.push(item.value);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (size) {
|
|
255
|
+
const bytes = new Uint8Array(size);
|
|
256
|
+
let offset = 0;
|
|
257
|
+
for (const chunk of chunks) {
|
|
258
|
+
bytes.set(chunk, offset);
|
|
259
|
+
offset += chunk.length;
|
|
260
|
+
}
|
|
261
|
+
body = new TextDecoder().decode(bytes);
|
|
262
|
+
}
|
|
263
|
+
if (path === "/cart/merge") {
|
|
264
|
+
const cartValue = (prefix) => cookies
|
|
265
|
+
.find((c) => c.startsWith(prefix))
|
|
266
|
+
?.split("=")
|
|
267
|
+
.slice(1)
|
|
268
|
+
.join("=");
|
|
269
|
+
const guest = cartValue("__Host-orunelle_cart_") || cartValue("orunelle_cart_");
|
|
270
|
+
if (!guest)
|
|
271
|
+
return fail(409, "NO_GUEST_CART");
|
|
272
|
+
body = JSON.stringify({ sessionToken: guest });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const target = new URL(apiStoreUrl(binding, path));
|
|
276
|
+
for (const [key, value] of url.searchParams) {
|
|
277
|
+
if (!["locale", "page", "limit", "q", "categoryId"].includes(key) && !(path.startsWith("/geo/") && ["country", "governorate"].includes(key)))
|
|
278
|
+
return fail(422, "INVALID_QUERY");
|
|
279
|
+
target.searchParams.append(key, value);
|
|
280
|
+
}
|
|
281
|
+
let upstream;
|
|
282
|
+
try {
|
|
283
|
+
upstream = await fetcher(target, {
|
|
284
|
+
method: request.method,
|
|
285
|
+
headers,
|
|
286
|
+
body: body ?? null,
|
|
287
|
+
redirect: "error",
|
|
288
|
+
cache: "no-store",
|
|
289
|
+
signal: AbortSignal.any([request.signal, AbortSignal.timeout(15000)]),
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
return fail(502, request.method === "GET" ? "UPSTREAM_UNAVAILABLE" : "UNCERTAIN_WRITE");
|
|
294
|
+
}
|
|
295
|
+
const responseHeaders = new Headers({
|
|
296
|
+
"content-type": "application/json",
|
|
297
|
+
"cache-control": "private, no-store",
|
|
298
|
+
"x-content-type-options": "nosniff",
|
|
299
|
+
});
|
|
300
|
+
const requestId = upstream.headers.get("x-request-id");
|
|
301
|
+
if (requestId)
|
|
302
|
+
responseHeaders.set("x-request-id", requestId);
|
|
303
|
+
for (const cookie of upstream.headers.getSetCookie()) {
|
|
304
|
+
if (!cookiePrefixes.some((prefix) => cookie.startsWith(prefix + context.store.id + "=")))
|
|
305
|
+
continue;
|
|
306
|
+
// Browsers only accept __Host- cookies that are Secure with Path=/ and no Domain.
|
|
307
|
+
const path = cookie.startsWith("__Host-") ? "/" : "/__commerce";
|
|
308
|
+
responseHeaders.append("set-cookie", cookie
|
|
309
|
+
.replace(/;\s*Path=[^;]*/i, "; Path=" + path)
|
|
310
|
+
.replace(/;\s*Domain=[^;]*/i, ""));
|
|
311
|
+
}
|
|
312
|
+
return new Response(upstream.body, {
|
|
313
|
+
status: upstream.status,
|
|
314
|
+
headers: responseHeaders,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface AuthorCredential {
|
|
2
|
+
apiOrigin: string;
|
|
3
|
+
token: string;
|
|
4
|
+
developerId: string;
|
|
5
|
+
expiresAt: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function apiOrigin(value: string): string;
|
|
8
|
+
export declare function saveCredential(value: AuthorCredential): Promise<void>;
|
|
9
|
+
export declare function loadCredential(origin: string): Promise<AuthorCredential>;
|
|
10
|
+
export declare function clearCredential(origin: string): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AACD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgB/C;AAqBD,wBAAsB,cAAc,CAAC,KAAK,EAAE,gBAAgB,iBAiB3D;AACD,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,gBAAgB,CAAC,CAiC3B;AACD,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,iBAMnD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { lstat, mkdir, open, realpath, rename, unlink } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { sha256 } from "./source.js";
|
|
7
|
+
export function apiOrigin(value) {
|
|
8
|
+
const url = new URL(value);
|
|
9
|
+
if ((url.origin !== value && url.origin + "/" !== value) ||
|
|
10
|
+
url.username ||
|
|
11
|
+
url.password ||
|
|
12
|
+
(url.protocol !== "https:" &&
|
|
13
|
+
!(url.protocol === "http:" &&
|
|
14
|
+
["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))))
|
|
15
|
+
throw new Error("Use an exact HTTPS API origin (an optional trailing / is allowed); HTTP is supported only on loopback.");
|
|
16
|
+
return url.origin;
|
|
17
|
+
}
|
|
18
|
+
async function credentialPath(origin) {
|
|
19
|
+
apiOrigin(origin);
|
|
20
|
+
const directory = resolve(process.env.ORUNELLE_CONFIG_DIR ??
|
|
21
|
+
join(homedir(), ".config/orunelle-theme"));
|
|
22
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
23
|
+
const info = await lstat(directory);
|
|
24
|
+
if (!info.isDirectory() ||
|
|
25
|
+
info.isSymbolicLink() ||
|
|
26
|
+
(await realpath(directory)) !== directory ||
|
|
27
|
+
(info.mode & 0o077) !== 0 ||
|
|
28
|
+
(process.getuid && info.uid !== process.getuid()))
|
|
29
|
+
throw new Error("Credential directory must be owned by you, private (0700), and free of symlinks.");
|
|
30
|
+
return join(directory, sha256(origin) + ".json");
|
|
31
|
+
}
|
|
32
|
+
export async function saveCredential(value) {
|
|
33
|
+
const path = await credentialPath(value.apiOrigin), temporary = path + "." + randomUUID();
|
|
34
|
+
const existing = await lstat(path).catch(() => null);
|
|
35
|
+
if (existing &&
|
|
36
|
+
(!existing.isFile() || existing.isSymbolicLink() || existing.nlink !== 1))
|
|
37
|
+
throw new Error("Unsafe credential file.");
|
|
38
|
+
const file = await open(temporary, "wx", 0o600);
|
|
39
|
+
try {
|
|
40
|
+
await file.writeFile(JSON.stringify(value));
|
|
41
|
+
await file.sync();
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
await file.close();
|
|
45
|
+
}
|
|
46
|
+
await rename(temporary, path);
|
|
47
|
+
}
|
|
48
|
+
export async function loadCredential(origin) {
|
|
49
|
+
const path = await credentialPath(origin);
|
|
50
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK).catch(() => {
|
|
51
|
+
throw new Error("Run orunelle-theme login for this API origin first.");
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
const info = await file.stat();
|
|
55
|
+
if (!info.isFile() ||
|
|
56
|
+
info.nlink !== 1 ||
|
|
57
|
+
info.size > 4096 ||
|
|
58
|
+
(info.mode & 0o077) !== 0 ||
|
|
59
|
+
(process.getuid && info.uid !== process.getuid()))
|
|
60
|
+
throw new Error("Credential file must be private (0600) and owned by you.");
|
|
61
|
+
const value = JSON.parse(await file.readFile("utf8"));
|
|
62
|
+
if (value.apiOrigin !== origin ||
|
|
63
|
+
!/^[\w-]{43}$/.test(value.token) ||
|
|
64
|
+
!/^[0-9a-f-]{36}$/.test(value.developerId) ||
|
|
65
|
+
!Number.isFinite(Date.parse(value.expiresAt)) ||
|
|
66
|
+
Date.parse(value.expiresAt) <= Date.now())
|
|
67
|
+
throw new Error("Author login expired. Run orunelle-theme login again.");
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
await file.close();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export async function clearCredential(origin) {
|
|
75
|
+
await unlink(await credentialPath(origin)).catch((error) => {
|
|
76
|
+
if (error.code !== "ENOENT")
|
|
77
|
+
throw error;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PublicProduct, StorefrontContext } from "@orunelle/theme-contract";
|
|
2
|
+
import type { Variant } from "@orunelle/theme-sdk/commerce";
|
|
3
|
+
export declare function resolveFixtureContext(request: Request, previewToken?: string): StorefrontContext | null;
|
|
4
|
+
export declare function fixtureProducts(context: StorefrontContext): readonly PublicProduct[];
|
|
5
|
+
/** Sample variants with colors, sizes and one sold-out combination. */
|
|
6
|
+
export declare function fixtureVariants(product: PublicProduct): Variant[];
|
|
7
|
+
export declare const fixtureOptionVisuals: {
|
|
8
|
+
readonly Color: {
|
|
9
|
+
readonly Sand: {
|
|
10
|
+
readonly color: "#d8c3a0";
|
|
11
|
+
};
|
|
12
|
+
readonly Charcoal: {
|
|
13
|
+
readonly color: "#3b3d42";
|
|
14
|
+
};
|
|
15
|
+
readonly Oat: {
|
|
16
|
+
readonly color: "#e3d6bf";
|
|
17
|
+
};
|
|
18
|
+
readonly Sage: {
|
|
19
|
+
readonly color: "#a9b8a0";
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../src/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAwB5D,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,GAAG,IAAI,CAiB1B;AA4BD,wBAAgB,eAAe,CAC7B,OAAO,EAAE,iBAAiB,GACzB,SAAS,aAAa,EAAE,CAoC1B;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,EAAE,CA8BjE;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;CAOvB,CAAC"}
|