@zeyolabs/shopping 2026.11.39 → 2026.11.41

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.
@@ -3,6 +3,8 @@
3
3
  import { resolve } from '$app/paths';
4
4
  import { CheckboxField, Form, MessageField, NumberField, TextField } from '@zeyolabs/ui/form';
5
5
  import Button from '@zeyolabs/ui/form/Button.svelte';
6
+ import Cluster from '@zeyolabs/ui/layout/Cluster.svelte';
7
+ import Span from '@zeyolabs/ui/text/Span.svelte';
6
8
  import Text from '@zeyolabs/ui/text/Text.svelte';
7
9
  import Title from '@zeyolabs/ui/text/Title.svelte';
8
10
 
@@ -106,34 +108,36 @@
106
108
  </div>
107
109
  <ul class="space-y-3">
108
110
  {#each imageRows as row, i (i)}
109
- <li class="flex flex-wrap items-center gap-3">
110
- {#if row.src}
111
- <img
112
- class="size-14 rounded-md border border-[var(--bd)] object-cover"
113
- alt=""
114
- src={Images.url(context.imageBaseUrl, row.src)}
111
+ <li>
112
+ <Cluster gap="sm">
113
+ {#if row.src}
114
+ <img
115
+ class="size-14 rounded-md border border-[var(--bd)] object-cover"
116
+ alt=""
117
+ src={Images.url(context.imageBaseUrl, row.src)}
118
+ />
119
+ {/if}
120
+ <input
121
+ {...images[i].src.as('text')}
122
+ class="{input} w-56"
123
+ aria-label="Image {i + 1} file name"
124
+ placeholder="file.avif"
115
125
  />
116
- {/if}
117
- <input
118
- {...images[i].src.as('text')}
119
- class="{input} w-56"
120
- aria-label="Image {i + 1} file name"
121
- placeholder="file.avif"
122
- />
123
- <input
124
- {...images[i].alt.as('text')}
125
- class="{input} flex-1"
126
- aria-label="Image {i + 1} alt text"
127
- placeholder="Alt text"
128
- />
129
- <Button onclick={() => images.set(up(imageRows, i))} size="sm" variant="secondary"
130
- >Up</Button
131
- >
132
- <Button
133
- onclick={() => images.set(imageRows.filter((_: unknown, j: number) => j !== i))}
134
- size="sm"
135
- variant="secondary">Remove</Button
136
- >
126
+ <input
127
+ {...images[i].alt.as('text')}
128
+ class="{input} flex-1"
129
+ aria-label="Image {i + 1} alt text"
130
+ placeholder="Alt text"
131
+ />
132
+ <Button onclick={() => images.set(up(imageRows, i))} size="sm" variant="secondary"
133
+ >Up</Button
134
+ >
135
+ <Button
136
+ onclick={() => images.set(imageRows.filter((_: unknown, j: number) => j !== i))}
137
+ size="sm"
138
+ variant="secondary">Remove</Button
139
+ >
140
+ </Cluster>
137
141
  </li>
138
142
  {/each}
139
143
  </ul>
@@ -148,10 +152,13 @@
148
152
  <Title level={2} size="sm">Categories</Title>
149
153
  <div class="grid gap-2 sm:grid-cols-2">
150
154
  {#each options.categories as category (category.id)}
151
- <label class="flex items-center gap-2 text-sm">
152
- <input {...form.fields.categoryIds.as('checkbox', String(category.id))} />
153
- {category.name}
154
- </label>
155
+ <Cluster gap="xs" nowrap>
156
+ <input
157
+ id="category-{category.id}"
158
+ {...form.fields.categoryIds.as('checkbox', String(category.id))}
159
+ />
160
+ <label for="category-{category.id}"><Span size="sm">{category.name}</Span></label>
161
+ </Cluster>
155
162
  {:else}
156
163
  <Text color="secondary">No categories yet.</Text>
157
164
  {/each}
@@ -167,14 +174,15 @@
167
174
  </Text>
168
175
  </div>
169
176
  <div class="grid gap-4 sm:grid-cols-2">
170
- <label class="text-sm font-medium">
171
- Group
177
+ <div>
178
+ <label class="form-label" for="variation-group">Group</label>
172
179
  <input
180
+ id="variation-group"
173
181
  {...form.fields.variationGroup.as('text')}
174
- class="{input} mt-1"
182
+ class={input}
175
183
  list="variation-groups"
176
184
  />
177
- </label>
185
+ </div>
178
186
  <datalist id="variation-groups">
179
187
  {#each options.variationGroups as group (group)}<option value={group}></option>{/each}
180
188
  </datalist>
@@ -210,24 +218,27 @@
210
218
  </div>
211
219
  <ul class="space-y-2">
212
220
  {#each componentRows as _, i (i)}
213
- <li class="flex items-center gap-3">
214
- <input
215
- {...components[i].sku.as('text')}
216
- class="{input} w-56"
217
- aria-label="Part {i + 1} SKU"
218
- placeholder="SKU"
219
- />
220
- <input
221
- {...components[i].quantity.as('number')}
222
- class="{input} w-24"
223
- aria-label="Part {i + 1} quantity"
224
- min="1"
225
- />
226
- <Button
227
- onclick={() => components.set(componentRows.filter((_: unknown, j: number) => j !== i))}
228
- size="sm"
229
- variant="secondary">Remove</Button
230
- >
221
+ <li>
222
+ <Cluster gap="sm">
223
+ <input
224
+ {...components[i].sku.as('text')}
225
+ class="{input} w-56"
226
+ aria-label="Part {i + 1} SKU"
227
+ placeholder="SKU"
228
+ />
229
+ <input
230
+ {...components[i].quantity.as('number')}
231
+ class="{input} w-24"
232
+ aria-label="Part {i + 1} quantity"
233
+ min="1"
234
+ />
235
+ <Button
236
+ onclick={() =>
237
+ components.set(componentRows.filter((_: unknown, j: number) => j !== i))}
238
+ size="sm"
239
+ variant="secondary">Remove</Button
240
+ >
241
+ </Cluster>
231
242
  </li>
232
243
  {/each}
233
244
  </ul>
@@ -241,11 +252,11 @@
241
252
  {/if}
242
253
  </section>
243
254
 
244
- <div class="flex items-center gap-4">
255
+ <Cluster gap="md">
245
256
  <Button {form} loadingMessage="Saving…">Save product</Button>
246
257
  {#if p?.active}
247
258
  <!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- the shop's own domain -->
248
259
  <a href="{context.siteUrl}/product/{p.slug}" rel="noopener" target="_blank">View in shop</a>
249
260
  {/if}
250
- </div>
261
+ </Cluster>
251
262
  </Form>
@@ -4,6 +4,9 @@
4
4
  import { page } from '$app/state';
5
5
  import Badge from '@zeyolabs/ui/badge/Badge.svelte';
6
6
  import Boundary from '@zeyolabs/ui/boundary/Boundary.svelte';
7
+ import Button from '@zeyolabs/ui/form/Button.svelte';
8
+ import Cluster from '@zeyolabs/ui/layout/Cluster.svelte';
9
+ import Span from '@zeyolabs/ui/text/Span.svelte';
7
10
  import Text from '@zeyolabs/ui/text/Text.svelte';
8
11
  import Title from '@zeyolabs/ui/text/Title.svelte';
9
12
 
@@ -15,22 +18,14 @@
15
18
 
16
19
  <svelte:head><title>Products · Admin</title></svelte:head>
17
20
 
18
- <div class="flex flex-wrap items-center justify-between gap-3">
21
+ <Cluster gap="sm" justify="between">
19
22
  <Title level={1} size="md">Products</Title>
20
- <div class="flex gap-2 text-sm">
21
- <a
22
- class="rounded-md border border-[var(--bd)] bg-white px-3 py-1.5"
23
- href={resolve('/categories')}>Categories</a
24
- >
25
- <a class="rounded-md border border-[var(--bd)] bg-white px-3 py-1.5" href={resolve('/bundles')}
26
- >Bundles</a
27
- >
28
- <a
29
- class="rounded-md bg-[var(--acc)] px-3 py-1.5 text-white no-underline"
30
- href={resolve('/products/new')}>New product</a
31
- >
32
- </div>
33
- </div>
23
+ <Cluster gap="xs">
24
+ <Button href={resolve('/categories')} variant="secondary">Categories</Button>
25
+ <Button href={resolve('/bundles')} variant="secondary">Bundles</Button>
26
+ <Button href={resolve('/products/new')}>New product</Button>
27
+ </Cluster>
28
+ </Cluster>
34
29
 
35
30
  <form
36
31
  class="mt-4"
@@ -56,30 +51,37 @@
56
51
  <Boundary message="Could not load products.">
57
52
  {let rows = $derived(await getAdminProducts(q))}
58
53
  <div class="mt-4 overflow-x-auto rounded-xl border border-[var(--bd)] bg-white">
59
- <table class="w-full text-left text-sm">
54
+ <table class="w-full text-left">
60
55
  <thead class="border-b border-[var(--bd)] text-[var(--txs)]">
61
56
  <tr>
62
- <th class="px-4 py-2 font-medium">Product</th>
63
- <th class="px-4 py-2 font-medium">SKU</th>
64
- <th class="px-4 py-2 text-right font-medium">Price</th>
65
- <th class="px-4 py-2 text-right font-medium">Stock</th>
57
+ <th class="px-4 py-2"><Span bold size="sm">Product</Span></th>
58
+ <th class="px-4 py-2"><Span bold size="sm">SKU</Span></th>
59
+ <th class="px-4 py-2 text-right"><Span bold size="sm">Price</Span></th>
60
+ <th class="px-4 py-2 text-right"><Span bold size="sm">Stock</Span></th>
66
61
  </tr>
67
62
  </thead>
68
63
  <tbody class="divide-y divide-[var(--bd)]">
69
64
  {#each rows as row (row.id)}
70
65
  <tr>
71
66
  <td class="px-4 py-2">
72
- <a class="font-medium" href={resolve('/products/[id]', { id: String(row.id) })}
73
- >{row.name}{row.variationLabel ? ` · ${row.variationLabel}` : ''}</a
67
+ <a href={resolve('/products/[id]', { id: String(row.id) })}
68
+ ><Span bold size="sm"
69
+ >{row.name}{row.variationLabel ? ` · ${row.variationLabel}` : ''}</Span
70
+ ></a
74
71
  >
75
72
  {#if !row.active}<Badge color="neutral">inactive</Badge>{/if}
76
73
  </td>
77
- <td class="px-4 py-2 whitespace-nowrap">{row.sku}</td>
78
- <td class="px-4 py-2 text-right">{Money.format(row.pricePence)}</td>
79
- <td class="px-4 py-2 text-right">{row.stock}</td>
74
+ <td class="px-4 py-2 whitespace-nowrap"><Span size="sm">{row.sku}</Span></td>
75
+ <td class="px-4 py-2 text-right"
76
+ ><Span size="sm">{Money.format(row.pricePence)}</Span></td
77
+ >
78
+ <td class="px-4 py-2 text-right"><Span size="sm">{row.stock}</Span></td>
80
79
  </tr>
81
80
  {:else}
82
- <tr><td class="px-4 py-6 text-[var(--txs)]" colspan="4">No products found.</td></tr>
81
+ <tr
82
+ ><td class="px-4 py-6" colspan="4"><Text color="secondary">No products found.</Text></td
83
+ ></tr
84
+ >
83
85
  {/each}
84
86
  </tbody>
85
87
  </table>
@@ -25,8 +25,11 @@ export const getAdminProduct = Remote.Query(Schema.Id, async (id) => {
25
25
  /** Categories and variation groups, for the product editor's pickers. */
26
26
  export const getProductOptions = Remote.Query(async () => {
27
27
  const service = admin();
28
- const [categories, groups] = await Promise.all([service.categories(), service.variationGroups()]);
29
- return { categories, variationGroups: groups.map((g) => g.name) };
28
+ const [categories, variationGroups] = await Promise.all([
29
+ service.categories(),
30
+ service.variationGroups(),
31
+ ]);
32
+ return { categories, variationGroups };
30
33
  });
31
34
 
32
35
  /** Saves a product; `data.id` is its id (new products get one here). */
@@ -222,8 +222,12 @@ export class CatalogueAdminService {
222
222
  }
223
223
 
224
224
  /** Names of the existing variation groups, for the editor's suggestions. */
225
- async variationGroups() {
226
- return this.db.select().from(variationGroups).orderBy(asc(variationGroups.name));
225
+ async variationGroups(): Promise<string[]> {
226
+ const rows = await this.db
227
+ .selectDistinct({ name: variationGroups.name })
228
+ .from(variationGroups)
229
+ .orderBy(asc(variationGroups.name));
230
+ return rows.map((row) => row.name);
227
231
  }
228
232
 
229
233
  private async variationGroupId(name: null | string): Promise<null | number> {
@@ -54,20 +54,20 @@
54
54
  class="absolute top-2 left-2 rounded-full bg-white/95 px-2.5 py-1 shadow-sm"
55
55
  bold
56
56
  color="secondary"
57
- size="sm">Out of stock</Span
57
+ size="xs">Out of stock</Span
58
58
  >
59
59
  {:else if badge.kind === 'low'}
60
60
  <Span
61
61
  class="absolute top-2 left-2 rounded-full bg-white/95 px-2.5 py-1 shadow-sm"
62
62
  bold
63
63
  color="secondary"
64
- size="sm">Only {badge.count} left</Span
64
+ size="xs">Only {badge.count} left</Span
65
65
  >
66
66
  {:else if onSale}
67
67
  <Span
68
68
  class="absolute top-2 left-2 rounded-full bg-[var(--primary-strong)] px-2.5 py-1 text-white"
69
69
  bold
70
- size="sm">Sale</Span
70
+ size="xs">Sale</Span
71
71
  >
72
72
  {/if}
73
73
  </div>
@@ -76,7 +76,7 @@
76
76
  <Text class="mt-1" color="secondary">
77
77
  <Span bold>{Money.format(product.pricePence)}</Span>
78
78
  {#if onSale}
79
- <s class="ml-1 text-sm">{Money.format(product.comparePricePence!)}</s>
79
+ <Span class="ml-1" size="sm"><s>{Money.format(product.comparePricePence!)}</s></Span>
80
80
  {/if}
81
81
  </Text>
82
82
  </div>
@@ -6,6 +6,7 @@
6
6
  import { Form } from '@zeyolabs/ui/form';
7
7
  import Button from '@zeyolabs/ui/form/Button.svelte';
8
8
  import ImageGallery from '@zeyolabs/ui/gallery/ImageGallery.svelte';
9
+ import Cluster from '@zeyolabs/ui/layout/Cluster.svelte';
9
10
  import Span from '@zeyolabs/ui/text/Span.svelte';
10
11
  import Text from '@zeyolabs/ui/text/Text.svelte';
11
12
  import Title from '@zeyolabs/ui/text/Title.svelte';
@@ -71,21 +72,22 @@
71
72
  <Title level={1} size="lg">{product.name}</Title>
72
73
 
73
74
  {#if data.reviews.average !== null}
74
- <a
75
- class="mt-3 flex w-fit items-center gap-2 text-sm text-[var(--txs)] no-underline hover:text-[var(--tx)]"
76
- href="#reviews"
77
- >
78
- <Stars rating={data.reviews.average} size="text-sm" />
79
- {data.reviews.count}
80
- {data.reviews.count === 1 ? 'review' : 'reviews'}
75
+ <a class="mt-3 w-fit no-underline" href="#reviews">
76
+ <Cluster gap="xs">
77
+ <Stars rating={data.reviews.average} size="sm" />
78
+ <Span color="secondary" size="sm">
79
+ {data.reviews.count}
80
+ {data.reviews.count === 1 ? 'review' : 'reviews'}
81
+ </Span>
82
+ </Cluster>
81
83
  </a>
82
84
  {/if}
83
85
 
84
- <div class="mt-5 flex flex-wrap items-baseline gap-x-3 gap-y-1">
85
- <!-- eslint-disable-next-line svelte/no-restricted-html-elements -- the price is display-sized, bigger than any Span size -->
86
+ <Cluster class="mt-5" gap="sm">
87
+ <!-- eslint-disable-next-line svelte/no-restricted-html-elements, no-restricted-syntax -- the price is display-sized, bigger than any Span size -->
86
88
  <span class="text-3xl font-semibold">{Money.format(product.pricePence)}</span>
87
89
  {#if saving > 0}
88
- <s class="text-lg text-[var(--txt)]">{Money.format(product.comparePricePence!)}</s>
90
+ <Span color="tertiary" size="lg"><s>{Money.format(product.comparePricePence!)}</s></Span>
89
91
  <Span
90
92
  class="rounded-full bg-[var(--primary-soft)] px-2.5 py-0.5 text-[var(--primary-strong)]"
91
93
  bold
@@ -93,7 +95,7 @@
93
95
  Save {saving}%
94
96
  </Span>
95
97
  {/if}
96
- </div>
98
+ </Cluster>
97
99
  {#if product.packSize > 1}
98
100
  <Text class="mt-1" color="secondary">Pack of {product.packSize}</Text>
99
101
  {/if}
@@ -105,36 +107,35 @@
105
107
  {#if data.options.length > 1}
106
108
  <div class="mt-6">
107
109
  <Text bold>{data.variationName}</Text>
108
- <ul class="mt-2 flex flex-wrap gap-2">
110
+ <Cluster class="mt-2" gap="xs">
109
111
  {#each data.options as option (option.slug)}
110
- <li>
111
- {#if option.slug === product.slug}
112
- <div
113
- class="inline-flex rounded-full border-2 border-[var(--primary-strong)] bg-[var(--primary-soft)] px-4 py-1.5 text-sm font-medium text-[var(--primary-strong)]"
114
- aria-current="true"
115
- >
116
- {option.label}
117
- </div>
118
- {:else}
119
- <a
120
- class="inline-flex rounded-full border-2 border-[var(--bd)] px-4 py-1.5 text-sm text-[var(--tx)] no-underline transition hover:border-[var(--primary-strong)] hover:text-[var(--tx)]"
121
- href={resolve('/product/[slug]', { slug: option.slug })}
122
- >
123
- {option.label}
124
- </a>
125
- {/if}
126
- </li>
112
+ {#if option.slug === product.slug}
113
+ <div
114
+ class="inline-flex rounded-full border-2 border-[var(--primary-strong)] bg-[var(--primary-soft)] px-4 py-1.5 text-[var(--primary-strong)]"
115
+ aria-current="true"
116
+ >
117
+ <Span bold size="sm">{option.label}</Span>
118
+ </div>
119
+ {:else}
120
+ <a
121
+ class="inline-flex rounded-full border-2 border-[var(--bd)] px-4 py-1.5 text-[var(--tx)] no-underline transition hover:border-[var(--primary-strong)] hover:text-[var(--tx)]"
122
+ href={resolve('/product/[slug]', { slug: option.slug })}
123
+ >
124
+ <Span size="sm">{option.label}</Span>
125
+ </a>
126
+ {/if}
127
127
  {/each}
128
- </ul>
128
+ </Cluster>
129
129
  </div>
130
130
  {/if}
131
131
 
132
- <Text class="mt-6 flex items-center gap-2" bold>
133
- <!-- eslint-disable-next-line svelte/no-restricted-html-elements -- a colour dot inside the line of text -->
134
- <span class="size-2.5 rounded-full {STOCK_DOT[stockBadge.kind]}" aria-hidden="true"></span>
135
- {#if stockBadge.kind === 'out'}Out of stock{:else if stockBadge.kind === 'low'}Only {stockBadge.count}
136
- left{:else}In stock{/if}
137
- </Text>
132
+ <Cluster class="mt-6" gap="xs">
133
+ <div class="size-2.5 rounded-full {STOCK_DOT[stockBadge.kind]}" aria-hidden="true"></div>
134
+ <Text bold>
135
+ {#if stockBadge.kind === 'out'}Out of stock{:else if stockBadge.kind === 'low'}Only {stockBadge.count}
136
+ left{:else}In stock{/if}
137
+ </Text>
138
+ </Cluster>
138
139
 
139
140
  {#if product.stock > 0}
140
141
  {const form = addToBasketForm.for(product.id)}
@@ -160,8 +161,8 @@
160
161
  >
161
162
  {#each text.specs.slice(0, 4) as spec (spec.label)}
162
163
  <div class="bg-[var(--sf)] px-4 py-3">
163
- <dt class="text-xs text-[var(--txs)]">{spec.label}</dt>
164
- <dd class="mt-0.5 font-medium text-[var(--tx)]">{spec.value}</dd>
164
+ <dt><Span color="secondary" size="xs">{spec.label}</Span></dt>
165
+ <dd class="mt-0.5"><Span bold>{spec.value}</Span></dd>
165
166
  </div>
166
167
  {/each}
167
168
  </dl>
@@ -195,9 +196,9 @@
195
196
  {#if visible < text.paragraphs.length}
196
197
  <details class="group mt-5">
197
198
  <summary
198
- class="cursor-pointer list-none font-medium text-[var(--primary-strong)] group-open:hidden"
199
+ class="cursor-pointer list-none text-[var(--primary-strong)] group-open:hidden"
199
200
  >
200
- Read more
201
+ <Span bold>Read more</Span>
201
202
  </summary>
202
203
  {#each text.paragraphs.slice(visible) as p, i (i)}
203
204
  {@render paragraph(p)}
@@ -209,12 +210,12 @@
209
210
  {#if text.specs.length > 4}
210
211
  <div>
211
212
  <Title level={2} size="md">Specifications</Title>
212
- <dl class="mt-5 divide-y divide-[var(--bd)] border-y border-[var(--bd)] text-sm">
213
+ <dl class="mt-5 divide-y divide-[var(--bd)] border-y border-[var(--bd)]">
213
214
  {#each text.specs as spec (spec.label)}
214
- <div class="flex justify-between gap-6 py-2.5">
215
- <dt class="text-[var(--txs)]">{spec.label}</dt>
216
- <dd class="text-right font-medium text-[var(--tx)]">{spec.value}</dd>
217
- </div>
215
+ <Cluster class="py-2.5" gap="md" justify="between" nowrap>
216
+ <dt><Span color="secondary" size="sm">{spec.label}</Span></dt>
217
+ <dd class="text-right"><Span bold size="sm">{spec.value}</Span></dd>
218
+ </Cluster>
218
219
  {/each}
219
220
  </dl>
220
221
  </div>
@@ -1,4 +1,6 @@
1
1
  <script lang="ts">
2
+ import Cluster from '@zeyolabs/ui/layout/Cluster.svelte';
3
+ import Span from '@zeyolabs/ui/text/Span.svelte';
2
4
  import Text from '@zeyolabs/ui/text/Text.svelte';
3
5
 
4
6
  import type { searchShop } from '../client.remote';
@@ -20,22 +22,24 @@
20
22
  <meta name="robots" content="noindex, follow" />
21
23
  </svelte:head>
22
24
 
23
- <form class="mb-8 flex max-w-xl gap-2" action="/search" method="get" role="search">
24
- <label class="sr-only" for="shop-search">Search products</label>
25
- <input
26
- id="shop-search"
27
- name="q"
28
- class="h-[var(--control-h)] min-w-0 flex-1 rounded-md border border-[var(--bd)] bg-white px-3"
29
- autocomplete="off"
30
- maxlength="100"
31
- placeholder="Search products"
32
- type="search"
33
- value={search.query}
34
- />
35
- <button
36
- class="h-[var(--control-h)] rounded-md bg-[var(--primary-strong)] px-4 font-medium text-white"
37
- type="submit">Search</button
38
- >
25
+ <form class="mb-8 max-w-xl" action="/search" method="get" role="search">
26
+ <Cluster gap="xs" nowrap>
27
+ <label class="sr-only" for="shop-search">Search products</label>
28
+ <input
29
+ id="shop-search"
30
+ name="q"
31
+ class="h-[var(--control-h)] min-w-0 flex-1 rounded-md border border-[var(--bd)] bg-white px-3"
32
+ autocomplete="off"
33
+ maxlength="100"
34
+ placeholder="Search products"
35
+ type="search"
36
+ value={search.query}
37
+ />
38
+ <button
39
+ class="h-[var(--control-h)] rounded-md bg-[var(--primary-strong)] px-4 text-white"
40
+ type="submit"><Span bold>Search</Span></button
41
+ >
42
+ </Cluster>
39
43
  </form>
40
44
 
41
45
  {#if search.query === ''}
@@ -1,5 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { resolve } from '$app/paths';
3
+ import Cluster from '@zeyolabs/ui/layout/Cluster.svelte';
4
+ import Span from '@zeyolabs/ui/text/Span.svelte';
3
5
  import Text from '@zeyolabs/ui/text/Text.svelte';
4
6
 
5
7
  import type { getShop } from '../client.remote';
@@ -29,16 +31,15 @@
29
31
  {/if}
30
32
 
31
33
  <nav class="mb-8" aria-label="Categories">
32
- <ul class="flex flex-wrap gap-2">
34
+ <Cluster gap="xs">
33
35
  {#each shop.categories as category (category.id)}
34
- <li>
35
- <a
36
- class="inline-block rounded-full border border-[var(--bd)] px-3.5 py-1.5 text-sm hover:border-[var(--primary-strong)] hover:bg-[var(--primary-soft)]"
37
- href={resolve('/category/[slug]', { slug: category.slug })}>{category.name}</a
38
- >
39
- </li>
36
+ <a
37
+ class="inline-block rounded-full border border-[var(--bd)] px-3.5 py-1.5 hover:border-[var(--primary-strong)] hover:bg-[var(--primary-soft)]"
38
+ href={resolve('/category/[slug]', { slug: category.slug })}
39
+ ><Span size="sm">{category.name}</Span></a
40
+ >
40
41
  {/each}
41
- </ul>
42
+ </Cluster>
42
43
  </nav>
43
44
 
44
45
  <!-- In stock first (the query sorts by it, then sort order and name), one page at a time. -->
@@ -0,0 +1,16 @@
1
+ import { WorkerRouter } from '@zeyolabs/kit/cloudflare/workers';
2
+
3
+ import { StripeWebhook } from './webhook';
4
+
5
+ /**
6
+ * A Worker that only takes Stripe's webhook (`POST /stripe/webhook`), on a host of its own, so
7
+ * the URL Stripe calls never moves when the shop's domain or deploys do. The app's Worker imports
8
+ * its shopping config first (which registers it) and passes the secret names it reads.
9
+ */
10
+ export const PaymentsWorker = {
11
+ create(secretNames: ReadonlySet<string>): ExportedHandler<{ SENTRY_DSN: string }> {
12
+ return WorkerRouter.withSentry(secretNames)
13
+ .post('/stripe/webhook', ({ req }) => StripeWebhook.handle(req))
14
+ .build();
15
+ },
16
+ };
@@ -1,42 +1,6 @@
1
1
  import type { RequestHandler } from '@sveltejs/kit';
2
2
 
3
- import { error } from '@sveltejs/kit';
4
- import { logger } from '@zeyolabs/kit/server/logger';
3
+ import { StripeWebhook } from './webhook';
5
4
 
6
- import { ShopClients } from '../clients/shop.server';
7
- import { StripeClient } from '../clients/stripe';
8
- import { secret } from '../config';
9
- import { OrderManager } from '../orders/manager.server';
10
-
11
- /** Stripe calls this after payment. Unsigned or mis-signed requests are rejected before any work. */
12
- export const POST: RequestHandler = async ({ request }) => {
13
- const signature = request.headers.get('stripe-signature');
14
- if (!signature) error(400, 'Missing signature');
15
-
16
- let event;
17
- try {
18
- event = await ShopClients.stripe().webhooks.constructEventAsync(
19
- await request.text(),
20
- signature,
21
- secret('stripeWebhookSecret'),
22
- undefined,
23
- StripeClient.webhookCrypto
24
- );
25
- } catch {
26
- error(400, 'Invalid signature');
27
- }
28
-
29
- if (
30
- event.type === 'checkout.session.completed' ||
31
- event.type === 'checkout.session.async_payment_succeeded'
32
- ) {
33
- try {
34
- await OrderManager.fulfil(event.data.object.id);
35
- } catch (err) {
36
- logger.error(err, { eventId: event.id, op: 'stripeWebhook' });
37
- // 500 makes Stripe retry; fulfilment is idempotent.
38
- error(500, 'Fulfilment failed');
39
- }
40
- }
41
- return Response.json({ received: true });
42
- };
5
+ /** Stripe's webhook as a SvelteKit route: `export { POST } from` this in the app. */
6
+ export const POST: RequestHandler = ({ request }) => StripeWebhook.handle(request);