@cloudexp-io/laudro-site-kit 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +55 -2
- package/dist/chunk-YCELGJAT.js +35 -0
- package/dist/client.d.ts +222 -0
- package/dist/client.js +433 -0
- package/dist/index.d.ts +1106 -0
- package/dist/index.js +1017 -0
- package/dist/server.d.ts +90 -0
- package/dist/server.js +225 -0
- package/package.json +57 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cloudexp-io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cloudexp-io/laudro-site-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Logic and route handlers for a restaurant website on Next.js and the Laudro API. It has no components and no CSS: the design is yours.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @cloudexp-io/laudro-site-kit @cloudexp-io/laudro-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The package is public on npmjs.com. No token is needed.
|
|
12
|
+
|
|
13
|
+
## Entries
|
|
14
|
+
|
|
15
|
+
| Import | What is in it |
|
|
16
|
+
| ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `@cloudexp-io/laudro-site-kit` | Plain functions: hours (`openStatus`, `groupWeekly`, `specialDays`), menus and allergens, lunch, prices (`formatMoney`), languages (`localePath`), booking helpers, JSON-LD, sitemap, robots and `buildLlmsTxt`. |
|
|
18
|
+
| `@cloudexp-io/laudro-site-kit/server` | Route handler factories: `createFormHandler`, `createFormTokenHandler`, `createTrackHandler`, `createRevalidateHandler`, `createPreviewHandler`. Imports `server-only`. |
|
|
19
|
+
| `@cloudexp-io/laudro-site-kit/client` | Hooks for client components: `useLaudroForm`, `useFormToken`, `usePageView`. `useRbForm` still works but is deprecated. |
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
A form route that keeps the site secret on the server:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// app/api/booking/route.ts
|
|
27
|
+
import { createClient } from "@cloudexp-io/laudro-sdk/next";
|
|
28
|
+
import { createFormHandler } from "@cloudexp-io/laudro-site-kit/server";
|
|
29
|
+
|
|
30
|
+
const client = () =>
|
|
31
|
+
process.env.LAUDRO_API_URL && process.env.LAUDRO_SITE_SECRET
|
|
32
|
+
? createClient({ apiUrl: process.env.LAUDRO_API_URL, secret: process.env.LAUDRO_SITE_SECRET })
|
|
33
|
+
: null;
|
|
34
|
+
|
|
35
|
+
export const dynamic = "force-dynamic";
|
|
36
|
+
export const POST = createFormHandler({ client, kind: "booking" });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
A data helper in a page:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { describeOpenStatus, openStatus } from "@cloudexp-io/laudro-site-kit";
|
|
43
|
+
|
|
44
|
+
const status = openStatus(hours.locations[0]!);
|
|
45
|
+
const text = describeOpenStatus(status, "en", hours.locations[0]!.timezone);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## More
|
|
49
|
+
|
|
50
|
+
- Docs: `https://developers.example.com/docs/site-starter` (use the address of your Laudro developers site).
|
|
51
|
+
- Agent skill and references: `https://developers.example.com/docs/skill.md`, or `laudro init` writes it into a new site.
|
|
52
|
+
- The API client: `@cloudexp-io/laudro-sdk`.
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/lang.ts
|
|
2
|
+
var SITE_LANGS = ["et", "en"];
|
|
3
|
+
var DEFAULT_SITE_LANG = "et";
|
|
4
|
+
function isSiteLang(value) {
|
|
5
|
+
return value === "et" || value === "en";
|
|
6
|
+
}
|
|
7
|
+
function localePath(lang, path) {
|
|
8
|
+
const clean = path.startsWith("/") ? path : `/${path}`;
|
|
9
|
+
if (lang === "et") return clean;
|
|
10
|
+
return clean === "/" ? "/en" : `/en${clean}`;
|
|
11
|
+
}
|
|
12
|
+
function splitLocale(pathname) {
|
|
13
|
+
if (pathname === "/en") return { lang: "en", path: "/" };
|
|
14
|
+
if (pathname.startsWith("/en/")) return { lang: "en", path: pathname.slice(3) };
|
|
15
|
+
return { lang: "et", path: pathname || "/" };
|
|
16
|
+
}
|
|
17
|
+
function absoluteUrl(baseUrl, path) {
|
|
18
|
+
return new URL(path, baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`).toString();
|
|
19
|
+
}
|
|
20
|
+
function safePath(value, fallback = "/") {
|
|
21
|
+
if (typeof value !== "string" || value.length > 500) return fallback;
|
|
22
|
+
if (!value.startsWith("/") || value.startsWith("//")) return fallback;
|
|
23
|
+
if (/[\\\u0000-\u001f]/.test(value)) return fallback;
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
SITE_LANGS,
|
|
29
|
+
DEFAULT_SITE_LANG,
|
|
30
|
+
isSiteLang,
|
|
31
|
+
localePath,
|
|
32
|
+
splitLocale,
|
|
33
|
+
absoluteUrl,
|
|
34
|
+
safePath
|
|
35
|
+
};
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { FormEvent } from 'react';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { SubmitResult } from '@cloudexp-io/laudro-sdk/forms';
|
|
5
|
+
|
|
6
|
+
/** Allergen codes (EU 1169/2011, the 14). Names come from the API in the asked language. */
|
|
7
|
+
declare const AllergenCode: z.ZodEnum<{
|
|
8
|
+
gluten: "gluten";
|
|
9
|
+
crustaceans: "crustaceans";
|
|
10
|
+
eggs: "eggs";
|
|
11
|
+
fish: "fish";
|
|
12
|
+
peanuts: "peanuts";
|
|
13
|
+
soybeans: "soybeans";
|
|
14
|
+
milk: "milk";
|
|
15
|
+
nuts: "nuts";
|
|
16
|
+
celery: "celery";
|
|
17
|
+
mustard: "mustard";
|
|
18
|
+
sesame: "sesame";
|
|
19
|
+
sulphites: "sulphites";
|
|
20
|
+
lupin: "lupin";
|
|
21
|
+
molluscs: "molluscs";
|
|
22
|
+
}>;
|
|
23
|
+
type AllergenCode = z.infer<typeof AllergenCode>;
|
|
24
|
+
declare const DietTag: z.ZodEnum<{
|
|
25
|
+
vegan: "vegan";
|
|
26
|
+
vegetarian: "vegetarian";
|
|
27
|
+
gluten_free: "gluten_free";
|
|
28
|
+
lactose_free: "lactose_free";
|
|
29
|
+
spicy: "spicy";
|
|
30
|
+
new: "new";
|
|
31
|
+
popular: "popular";
|
|
32
|
+
chef_choice: "chef_choice";
|
|
33
|
+
kids: "kids";
|
|
34
|
+
}>;
|
|
35
|
+
type DietTag = z.infer<typeof DietTag>;
|
|
36
|
+
|
|
37
|
+
declare const EventKind: z.ZodEnum<{
|
|
38
|
+
company: "company";
|
|
39
|
+
birthday: "birthday";
|
|
40
|
+
wedding: "wedding";
|
|
41
|
+
other: "other";
|
|
42
|
+
}>;
|
|
43
|
+
type EventKind = z.infer<typeof EventKind>;
|
|
44
|
+
|
|
45
|
+
declare const TrackName: z.ZodEnum<{
|
|
46
|
+
page_view: "page_view";
|
|
47
|
+
visit: "visit";
|
|
48
|
+
menu_view: "menu_view";
|
|
49
|
+
lunch_view: "lunch_view";
|
|
50
|
+
item_view: "item_view";
|
|
51
|
+
call_tap: "call_tap";
|
|
52
|
+
map_tap: "map_tap";
|
|
53
|
+
booking_open: "booking_open";
|
|
54
|
+
booking_provider_tap: "booking_provider_tap";
|
|
55
|
+
form_submit: "form_submit";
|
|
56
|
+
}>;
|
|
57
|
+
type TrackName = z.infer<typeof TrackName>;
|
|
58
|
+
|
|
59
|
+
declare const SITE_LANGS: readonly ["et", "en"];
|
|
60
|
+
type SiteLang = (typeof SITE_LANGS)[number];
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Fixed UI words. These never go through AI translation (technical brief, section 11).
|
|
64
|
+
* Sites can pass their own labels to any component to override a word.
|
|
65
|
+
*/
|
|
66
|
+
interface Dictionary {
|
|
67
|
+
langName: string;
|
|
68
|
+
weekdays: [string, string, string, string, string, string, string];
|
|
69
|
+
weekdaysShort: [string, string, string, string, string, string, string];
|
|
70
|
+
today: string;
|
|
71
|
+
tomorrow: string;
|
|
72
|
+
openNow: string;
|
|
73
|
+
closedNow: string;
|
|
74
|
+
closesAt: (time: string) => string;
|
|
75
|
+
opensAt: (when: string) => string;
|
|
76
|
+
closed: string;
|
|
77
|
+
openingHours: string;
|
|
78
|
+
kitchen: string;
|
|
79
|
+
holiday: string;
|
|
80
|
+
specialDay: string;
|
|
81
|
+
lunch: string;
|
|
82
|
+
lunchToday: string;
|
|
83
|
+
noLunch: string;
|
|
84
|
+
nextLunch: (date: string) => string;
|
|
85
|
+
servedBetween: (from: string, to: string) => string;
|
|
86
|
+
setPrice: string;
|
|
87
|
+
/** Between two times or days in the table format: "11:00 kuni 22:00". */
|
|
88
|
+
to: string;
|
|
89
|
+
language: string;
|
|
90
|
+
/** "24.12 ja 25.12 on suletud". Dates are `dd.mm`. */
|
|
91
|
+
closedOn: (dates: string[]) => string;
|
|
92
|
+
visit: string;
|
|
93
|
+
pages: string;
|
|
94
|
+
menu: string;
|
|
95
|
+
/** Header: accessible name of the phone menu button. */
|
|
96
|
+
openMenu: string;
|
|
97
|
+
/** Header: short book label on phone. */
|
|
98
|
+
bookShort: string;
|
|
99
|
+
/** Header: accessible name of the main navigation. */
|
|
100
|
+
mainNav: string;
|
|
101
|
+
soldOut: string;
|
|
102
|
+
allergens: string;
|
|
103
|
+
mayContain: string;
|
|
104
|
+
ingredients: string;
|
|
105
|
+
tags: Record<DietTag, string>;
|
|
106
|
+
allergenNames: Record<AllergenCode, string>;
|
|
107
|
+
booking: {
|
|
108
|
+
title: string;
|
|
109
|
+
note: string;
|
|
110
|
+
fewer: string;
|
|
111
|
+
more: string;
|
|
112
|
+
fullHint: string;
|
|
113
|
+
today: string;
|
|
114
|
+
tomorrow: string;
|
|
115
|
+
submit: string;
|
|
116
|
+
};
|
|
117
|
+
events: {
|
|
118
|
+
seatsLeft: (n: number) => string;
|
|
119
|
+
soldOut: string;
|
|
120
|
+
};
|
|
121
|
+
form: {
|
|
122
|
+
date: string;
|
|
123
|
+
time: string;
|
|
124
|
+
partySize: string;
|
|
125
|
+
name: string;
|
|
126
|
+
phone: string;
|
|
127
|
+
email: string;
|
|
128
|
+
emailOptional: string;
|
|
129
|
+
note: string;
|
|
130
|
+
send: string;
|
|
131
|
+
sending: string;
|
|
132
|
+
sent: string;
|
|
133
|
+
bookingSent: string;
|
|
134
|
+
eventSent: string;
|
|
135
|
+
contactSent: string;
|
|
136
|
+
required: string;
|
|
137
|
+
/** Field-specific text when a value is too short. */
|
|
138
|
+
tooShort: {
|
|
139
|
+
phone: string;
|
|
140
|
+
};
|
|
141
|
+
invalid: string;
|
|
142
|
+
/** An email field that is not a valid address. */
|
|
143
|
+
invalidEmail: string;
|
|
144
|
+
rateLimited: string;
|
|
145
|
+
failed: string;
|
|
146
|
+
failedCall: (phone: string) => string;
|
|
147
|
+
eventDate: string;
|
|
148
|
+
guests: string;
|
|
149
|
+
kind: string;
|
|
150
|
+
kinds: Record<EventKind, string>;
|
|
151
|
+
budget: string;
|
|
152
|
+
package: string;
|
|
153
|
+
noPackage: string;
|
|
154
|
+
/** After a package price: "45 € / in". */
|
|
155
|
+
perPerson: string;
|
|
156
|
+
company: string;
|
|
157
|
+
message: string;
|
|
158
|
+
sendAnother: string;
|
|
159
|
+
/** "Send another" after a contact message. */
|
|
160
|
+
sendAnotherMessage: string;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The signed form token `t`, fetched from the site's own route when the form mounts. The page
|
|
166
|
+
* may be cached HTML hours old, so the token is never baked into the page.
|
|
167
|
+
*/
|
|
168
|
+
declare function useFormToken(url: string): () => Promise<string | null>;
|
|
169
|
+
type FormStatus = "idle" | "sending" | "sent" | "error";
|
|
170
|
+
/** A zod-like schema: only `safeParse` is used, so the form stays decoupled from zod itself. */
|
|
171
|
+
interface ParseSchema {
|
|
172
|
+
safeParse(v: unknown): {
|
|
173
|
+
success: true;
|
|
174
|
+
} | {
|
|
175
|
+
success: false;
|
|
176
|
+
error: {
|
|
177
|
+
issues: {
|
|
178
|
+
path: PropertyKey[];
|
|
179
|
+
code: string;
|
|
180
|
+
input?: unknown;
|
|
181
|
+
}[];
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
interface UseLaudroFormOptions {
|
|
186
|
+
action: string;
|
|
187
|
+
tokenUrl: string;
|
|
188
|
+
lang: SiteLang;
|
|
189
|
+
schema: ParseSchema;
|
|
190
|
+
/** FormData to the API body. `t` and `hp` are added. */
|
|
191
|
+
build: (fd: FormData) => Record<string, unknown>;
|
|
192
|
+
onSent?: (result: Extract<SubmitResult, {
|
|
193
|
+
ok: true;
|
|
194
|
+
}>["data"]) => void;
|
|
195
|
+
phone?: string | null;
|
|
196
|
+
}
|
|
197
|
+
declare function useLaudroForm(o: UseLaudroFormOptions): {
|
|
198
|
+
d: Dictionary;
|
|
199
|
+
status: FormStatus;
|
|
200
|
+
errors: Record<string, string>;
|
|
201
|
+
message: string | null;
|
|
202
|
+
onSubmit: (e: FormEvent<HTMLFormElement>) => Promise<void>;
|
|
203
|
+
reset: () => void;
|
|
204
|
+
formRef: react.RefObject<HTMLFormElement | null>;
|
|
205
|
+
};
|
|
206
|
+
/** @deprecated Use useLaudroForm. */
|
|
207
|
+
declare const useRbForm: typeof useLaudroForm;
|
|
208
|
+
|
|
209
|
+
/** Fire-and-forget counter to the site's own track route. No cookies, no ids. */
|
|
210
|
+
declare function sendTrack(name: TrackName, lang: SiteLang, opts?: {
|
|
211
|
+
url?: string;
|
|
212
|
+
path?: string;
|
|
213
|
+
}): void;
|
|
214
|
+
/** Counts a `page_view` on every client navigation. Call it once in the layout. */
|
|
215
|
+
declare function usePageView({ lang, url, name, }: {
|
|
216
|
+
lang: SiteLang;
|
|
217
|
+
url?: string;
|
|
218
|
+
name?: TrackName;
|
|
219
|
+
}): void;
|
|
220
|
+
|
|
221
|
+
export { sendTrack, useFormToken, useLaudroForm, usePageView, useRbForm };
|
|
222
|
+
export type { FormStatus };
|