@cloudexp-io/laudro-sdk 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 +56 -2
- package/dist/chunk-5H4Y5WKX.js +850 -0
- package/dist/chunk-6LTB3GRQ.js +357 -0
- package/dist/chunk-LSPODMW7.js +18 -0
- package/dist/core.d.ts +1699 -0
- package/dist/core.js +180 -0
- package/dist/forms.d.ts +37 -0
- package/dist/forms.js +62 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +182 -0
- package/dist/next.d.ts +263 -0
- package/dist/next.js +182 -0
- package/dist/retry-BnQHOsTh.d.ts +409 -0
- package/package.json +52 -3
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
// ../contracts/src/common.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var Uuid = z.uuid();
|
|
4
|
+
var IsoDateTime = z.iso.datetime({ offset: true });
|
|
5
|
+
var IsoDate = z.iso.date();
|
|
6
|
+
var Lang = z.enum(["et", "en"]);
|
|
7
|
+
var DEFAULT_LANG = "et";
|
|
8
|
+
var Currency = z.literal("EUR");
|
|
9
|
+
var Money = z.object({
|
|
10
|
+
cents: z.int(),
|
|
11
|
+
currency: Currency
|
|
12
|
+
});
|
|
13
|
+
function eur(cents) {
|
|
14
|
+
if (!Number.isInteger(cents)) throw new TypeError(`Money cents must be an integer, got ${cents}`);
|
|
15
|
+
return { cents, currency: "EUR" };
|
|
16
|
+
}
|
|
17
|
+
var ProblemFieldError = z.object({
|
|
18
|
+
path: z.string(),
|
|
19
|
+
code: z.string(),
|
|
20
|
+
message: z.string()
|
|
21
|
+
});
|
|
22
|
+
var Problem = z.object({
|
|
23
|
+
type: z.string(),
|
|
24
|
+
title: z.string(),
|
|
25
|
+
status: z.int().min(400).max(599),
|
|
26
|
+
detail: z.string().optional(),
|
|
27
|
+
instance: z.string().optional(),
|
|
28
|
+
errors: z.array(ProblemFieldError).optional()
|
|
29
|
+
});
|
|
30
|
+
var PROBLEM_CONTENT_TYPE = "application/problem+json";
|
|
31
|
+
var LocalTime = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "Use HH:MM (24 h)");
|
|
32
|
+
var IsoWeek = z.string().regex(/^\d{4}-W(0[1-9]|[1-4]\d|5[0-3])$/, "Use YYYY-Www");
|
|
33
|
+
var LangQuery = z.object({
|
|
34
|
+
lang: Lang.default(DEFAULT_LANG).describe("Language of the text.")
|
|
35
|
+
});
|
|
36
|
+
var LangFallback = z.boolean().describe("True when some text came in Estonian because it has no translation yet.");
|
|
37
|
+
var Media = z.object({
|
|
38
|
+
id: Uuid,
|
|
39
|
+
url: z.url(),
|
|
40
|
+
width: z.int().nullable(),
|
|
41
|
+
height: z.int().nullable(),
|
|
42
|
+
alt: z.string().nullable(),
|
|
43
|
+
blurhash: z.string().nullable(),
|
|
44
|
+
lang_fallback: LangFallback
|
|
45
|
+
});
|
|
46
|
+
var AllergenCode = z.enum([
|
|
47
|
+
"gluten",
|
|
48
|
+
"crustaceans",
|
|
49
|
+
"eggs",
|
|
50
|
+
"fish",
|
|
51
|
+
"peanuts",
|
|
52
|
+
"soybeans",
|
|
53
|
+
"milk",
|
|
54
|
+
"nuts",
|
|
55
|
+
"celery",
|
|
56
|
+
"mustard",
|
|
57
|
+
"sesame",
|
|
58
|
+
"sulphites",
|
|
59
|
+
"lupin",
|
|
60
|
+
"molluscs"
|
|
61
|
+
]);
|
|
62
|
+
var Allergen = z.object({
|
|
63
|
+
code: AllergenCode,
|
|
64
|
+
name: z.string(),
|
|
65
|
+
icon: z.string().nullable(),
|
|
66
|
+
state: z.enum(["contains", "may_contain"])
|
|
67
|
+
});
|
|
68
|
+
var DietTag = z.enum([
|
|
69
|
+
"vegan",
|
|
70
|
+
"vegetarian",
|
|
71
|
+
"gluten_free",
|
|
72
|
+
"lactose_free",
|
|
73
|
+
"spicy",
|
|
74
|
+
"new",
|
|
75
|
+
"popular",
|
|
76
|
+
"chef_choice",
|
|
77
|
+
"kids"
|
|
78
|
+
]);
|
|
79
|
+
var Honeypot = z.string().max(500).optional();
|
|
80
|
+
var FormToken = z.string().max(200);
|
|
81
|
+
var TurnstileToken = z.string().max(4096).optional();
|
|
82
|
+
var Email = z.email().max(254);
|
|
83
|
+
var PhoneInput = z.string().min(5).max(40);
|
|
84
|
+
|
|
85
|
+
// ../contracts/src/site.ts
|
|
86
|
+
import { z as z2 } from "zod";
|
|
87
|
+
var RestaurantStatus = z2.enum(["demo", "live", "paused"]);
|
|
88
|
+
var BookingMode = z2.enum(["provider", "request", "both", "phone_only"]);
|
|
89
|
+
var Site = z2.object({
|
|
90
|
+
id: Uuid.describe("Restaurant id."),
|
|
91
|
+
site_id: Uuid.describe("Id of the site you call from."),
|
|
92
|
+
name: z2.string().describe("Restaurant name."),
|
|
93
|
+
short_name: z2.string().nullable().describe("Short name, or null."),
|
|
94
|
+
/** `demo` sites must be served with noindex. */
|
|
95
|
+
status: RestaurantStatus.describe("Restaurant state: demo, live or paused."),
|
|
96
|
+
timezone: z2.string().describe("IANA time zone of the restaurant."),
|
|
97
|
+
/** Only while `status` is `paused`: the day the restaurant reopens, `YYYY-MM-DD`, or null. */
|
|
98
|
+
reopen_on: z2.iso.date().nullish().describe("Day the paused restaurant reopens, or null."),
|
|
99
|
+
default_lang: Lang.describe("Language used when none is asked for."),
|
|
100
|
+
languages: z2.array(Lang).describe("Languages the restaurant offers."),
|
|
101
|
+
logo: Media.nullable().describe("Logo image, or null."),
|
|
102
|
+
/** Brand colours, e.g. { "primary": "#1f6f5c" }. */
|
|
103
|
+
brand: z2.record(z2.string(), z2.string()).describe("Brand colours by name."),
|
|
104
|
+
/** Social links, e.g. { "instagram": "https://instagram.com/example" }. */
|
|
105
|
+
social_links: z2.record(z2.string(), z2.string()).describe("Social links by network."),
|
|
106
|
+
/** Booking mode of the main location, or null when booking is not set up. */
|
|
107
|
+
booking_mode: BookingMode.nullable().describe("How guests book, or null."),
|
|
108
|
+
/** Contact of the main location. */
|
|
109
|
+
contact: z2.object({
|
|
110
|
+
phone: z2.string().nullable(),
|
|
111
|
+
email: z2.string().nullable(),
|
|
112
|
+
address: z2.string().nullable()
|
|
113
|
+
}).describe("Phone, email and address of the main location."),
|
|
114
|
+
lang: Lang.describe("Language of the text in this response."),
|
|
115
|
+
lang_fallback: LangFallback
|
|
116
|
+
});
|
|
117
|
+
var Location = z2.object({
|
|
118
|
+
id: Uuid,
|
|
119
|
+
name: z2.string(),
|
|
120
|
+
address: z2.string().nullable(),
|
|
121
|
+
city: z2.string().nullable(),
|
|
122
|
+
postcode: z2.string().nullable(),
|
|
123
|
+
country: z2.string(),
|
|
124
|
+
geo: z2.object({ lat: z2.number(), lng: z2.number() }).nullable(),
|
|
125
|
+
phone: z2.string().nullable(),
|
|
126
|
+
email: z2.string().nullable(),
|
|
127
|
+
google_maps_url: z2.string().nullable(),
|
|
128
|
+
timezone: z2.string(),
|
|
129
|
+
lang_fallback: LangFallback
|
|
130
|
+
});
|
|
131
|
+
var LocationsResponse = z2.object({
|
|
132
|
+
locations: z2.array(Location).describe("All locations. The first is the main one."),
|
|
133
|
+
lang: Lang.describe("Language of the text in this response.")
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// ../contracts/src/events.ts
|
|
137
|
+
import { z as z3 } from "zod";
|
|
138
|
+
var EventPackage = z3.object({
|
|
139
|
+
id: Uuid,
|
|
140
|
+
name: z3.string(),
|
|
141
|
+
description: z3.string().nullable(),
|
|
142
|
+
min_guests: z3.int().nullable(),
|
|
143
|
+
max_guests: z3.int().nullable(),
|
|
144
|
+
price: Money.nullable(),
|
|
145
|
+
price_unit: z3.enum(["per_person", "total"]),
|
|
146
|
+
lang_fallback: LangFallback
|
|
147
|
+
});
|
|
148
|
+
var EventPackagesResponse = z3.object({
|
|
149
|
+
packages: z3.array(EventPackage).describe("Published event packages."),
|
|
150
|
+
lang: Lang.describe("Language of the text in this response.")
|
|
151
|
+
});
|
|
152
|
+
var EventKind = z3.enum(["company", "birthday", "wedding", "other"]);
|
|
153
|
+
var EventRequestCreate = z3.object({
|
|
154
|
+
location_id: Uuid.optional().describe("Location for the event. Default: the main location."),
|
|
155
|
+
event_date: IsoDate.describe("Date of the event."),
|
|
156
|
+
guests: z3.int().min(1).max(5e3).describe("Number of guests."),
|
|
157
|
+
kind: EventKind.describe("Kind of event."),
|
|
158
|
+
/** Budget in cents (EUR). */
|
|
159
|
+
budget: z3.int().min(0).max(1e8).optional().describe("Budget in cents (EUR)."),
|
|
160
|
+
package_id: Uuid.optional().describe("Event package the guest picked."),
|
|
161
|
+
name: z3.string().trim().min(1).max(200).describe("Name of the guest."),
|
|
162
|
+
company: z3.string().trim().max(200).optional().describe("Company name."),
|
|
163
|
+
phone: PhoneInput.describe("Phone number of the guest."),
|
|
164
|
+
email: Email.describe("Email of the guest."),
|
|
165
|
+
message: z3.string().trim().min(1).max(5e3).describe("Message from the guest."),
|
|
166
|
+
lang: Lang.default("et").describe("Language of the text."),
|
|
167
|
+
hp: Honeypot.describe("Hidden honeypot field. Leave it empty."),
|
|
168
|
+
t: FormToken.describe("Signed form time stamp from signFormToken."),
|
|
169
|
+
turnstile_token: TurnstileToken.describe(
|
|
170
|
+
"Turnstile token. Needed only when the site uses Turnstile."
|
|
171
|
+
)
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// ../contracts/src/booking.ts
|
|
175
|
+
import { z as z4 } from "zod";
|
|
176
|
+
var BookingProvider = z4.enum(["tableonline", "zenchef", "quandoo"]);
|
|
177
|
+
var WeeklyHours = z4.object({
|
|
178
|
+
/** ISO weekday, 1 = Monday. */
|
|
179
|
+
weekday: z4.int().min(1).max(7),
|
|
180
|
+
opens: LocalTime,
|
|
181
|
+
closes: LocalTime
|
|
182
|
+
});
|
|
183
|
+
var BookingLocation = z4.object({
|
|
184
|
+
location_id: Uuid,
|
|
185
|
+
mode: BookingMode,
|
|
186
|
+
provider: BookingProvider.nullable(),
|
|
187
|
+
/** Link out to the booking provider. Never an embedded widget. */
|
|
188
|
+
provider_url: z4.string().nullable(),
|
|
189
|
+
min_party: z4.int(),
|
|
190
|
+
max_party: z4.int(),
|
|
191
|
+
min_lead_minutes: z4.int(),
|
|
192
|
+
max_days_ahead: z4.int(),
|
|
193
|
+
/** Text shown after a request is sent. */
|
|
194
|
+
confirm_text: z4.string().nullable(),
|
|
195
|
+
/** Phone for `phone_only`, and to show when a request is refused. */
|
|
196
|
+
phone: z4.string().nullable(),
|
|
197
|
+
/** Weekly booking hours. Uses opening hours when no booking hours are set. */
|
|
198
|
+
booking_hours: z4.array(WeeklyHours),
|
|
199
|
+
booking_hours_kind: z4.enum(["booking", "open"]),
|
|
200
|
+
lang_fallback: LangFallback
|
|
201
|
+
});
|
|
202
|
+
var BookingResponse = z4.object({
|
|
203
|
+
/** Mode of the main location, or null when booking is not set up. */
|
|
204
|
+
mode: BookingMode.nullable().describe("Booking mode of the main location, or null."),
|
|
205
|
+
locations: z4.array(BookingLocation).describe("Booking settings per location."),
|
|
206
|
+
lang: Lang.describe("Language of the text in this response.")
|
|
207
|
+
});
|
|
208
|
+
var BookingRequestCreate = z4.object({
|
|
209
|
+
/** Defaults to the main location that takes requests. */
|
|
210
|
+
location_id: Uuid.optional().describe(
|
|
211
|
+
"Location to book. Default: the main location that takes requests."
|
|
212
|
+
),
|
|
213
|
+
date: IsoDate.describe("Date of the booking."),
|
|
214
|
+
time: LocalTime.describe("Time of the booking, HH:MM."),
|
|
215
|
+
party_size: z4.int().min(1).max(500).describe("Number of guests."),
|
|
216
|
+
name: z4.string().trim().min(1).max(200).describe("Name of the guest."),
|
|
217
|
+
phone: PhoneInput.describe("Phone number of the guest."),
|
|
218
|
+
email: Email.optional().describe("Email of the guest."),
|
|
219
|
+
note: z4.string().trim().max(2e3).optional().describe("Note from the guest."),
|
|
220
|
+
lang: Lang.default("et").describe("Language of the text."),
|
|
221
|
+
hp: Honeypot.describe("Hidden honeypot field. Leave it empty."),
|
|
222
|
+
t: FormToken.describe("Signed form time stamp from signFormToken."),
|
|
223
|
+
turnstile_token: TurnstileToken.describe(
|
|
224
|
+
"Turnstile token. Needed only when the site uses Turnstile."
|
|
225
|
+
)
|
|
226
|
+
});
|
|
227
|
+
var RequestCreated = z4.object({
|
|
228
|
+
id: Uuid.describe("Id of the new request."),
|
|
229
|
+
status: z4.literal("new").describe("Always new.")
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// ../contracts/src/contact.ts
|
|
233
|
+
import { z as z5 } from "zod";
|
|
234
|
+
var ContactCreate = z5.object({
|
|
235
|
+
name: z5.string().trim().min(1).max(200).describe("Name of the sender."),
|
|
236
|
+
email: Email.describe("Email of the sender."),
|
|
237
|
+
phone: PhoneInput.optional().describe("Phone number of the sender."),
|
|
238
|
+
message: z5.string().trim().min(1).max(5e3).describe("The message."),
|
|
239
|
+
lang: Lang.default("et").describe("Language of the text."),
|
|
240
|
+
hp: Honeypot.describe("Hidden honeypot field. Leave it empty."),
|
|
241
|
+
t: FormToken.describe("Signed form time stamp from signFormToken."),
|
|
242
|
+
turnstile_token: TurnstileToken.describe(
|
|
243
|
+
"Turnstile token. Needed only when the site uses Turnstile."
|
|
244
|
+
)
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// ../contracts/src/track.ts
|
|
248
|
+
import { z as z6 } from "zod";
|
|
249
|
+
var TrackName = z6.enum([
|
|
250
|
+
"page_view",
|
|
251
|
+
"visit",
|
|
252
|
+
"menu_view",
|
|
253
|
+
"lunch_view",
|
|
254
|
+
"item_view",
|
|
255
|
+
"call_tap",
|
|
256
|
+
"map_tap",
|
|
257
|
+
"booking_open",
|
|
258
|
+
"booking_provider_tap",
|
|
259
|
+
"form_submit"
|
|
260
|
+
]);
|
|
261
|
+
var TrackEvent = z6.object({
|
|
262
|
+
name: TrackName.describe("Which event happened."),
|
|
263
|
+
/** Path only, no query string. */
|
|
264
|
+
path: z6.string().startsWith("/").max(300).describe("Page path, no query string."),
|
|
265
|
+
lang: Lang.default("et").describe("Language of the text."),
|
|
266
|
+
/** Referrer URL or host. Only the host is kept. */
|
|
267
|
+
ref: z6.string().max(500).optional().describe("Referrer URL or host."),
|
|
268
|
+
device: z6.enum(["mobile", "desktop"]).optional().describe("Device type.")
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// src/retry.ts
|
|
272
|
+
var DEFAULT_RETRIES = 2;
|
|
273
|
+
var defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
274
|
+
function parseRetryAfter(value, now = Date.now()) {
|
|
275
|
+
if (!value) return null;
|
|
276
|
+
const v = value.trim();
|
|
277
|
+
if (/^\d+$/.test(v)) return Number(v) * 1e3;
|
|
278
|
+
const at = Date.parse(v);
|
|
279
|
+
return Number.isNaN(at) ? null : Math.max(0, at - now);
|
|
280
|
+
}
|
|
281
|
+
function backoffMs(attempt, base, max, random = Math.random) {
|
|
282
|
+
const exp = base * 2 ** attempt;
|
|
283
|
+
return Math.min(max, Math.round(exp / 2 + random() * (exp / 2)));
|
|
284
|
+
}
|
|
285
|
+
async function withRetry(send, opts) {
|
|
286
|
+
const retries = Math.max(0, opts.retries ?? DEFAULT_RETRIES);
|
|
287
|
+
const base = opts.baseDelayMs ?? 250;
|
|
288
|
+
const max = opts.maxDelayMs ?? 5e3;
|
|
289
|
+
const sleep = opts.sleep ?? defaultSleep;
|
|
290
|
+
for (let attempt = 0; ; attempt++) {
|
|
291
|
+
let res;
|
|
292
|
+
try {
|
|
293
|
+
res = await send();
|
|
294
|
+
} catch (err) {
|
|
295
|
+
if (!opts.retryNetwork || attempt >= retries) throw err;
|
|
296
|
+
await sleep(backoffMs(attempt, base, max));
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (attempt >= retries || !opts.retryable(res.status, res)) return res;
|
|
300
|
+
const after = parseRetryAfter(res.headers.get("retry-after"));
|
|
301
|
+
res.body?.cancel().catch(() => void 0);
|
|
302
|
+
await sleep(Math.min(max, after ?? backoffMs(attempt, base, max)));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
var isRetryableRead = (status) => status === 429 || status >= 500;
|
|
306
|
+
var isRetryableWrite = (status) => status === 429;
|
|
307
|
+
var isRetryableIdempotentWrite = (status, res) => isRetryableRead(status) || status === 409 && res.headers.has("retry-after");
|
|
308
|
+
|
|
309
|
+
export {
|
|
310
|
+
Uuid,
|
|
311
|
+
IsoDateTime,
|
|
312
|
+
IsoDate,
|
|
313
|
+
Lang,
|
|
314
|
+
DEFAULT_LANG,
|
|
315
|
+
Currency,
|
|
316
|
+
Money,
|
|
317
|
+
eur,
|
|
318
|
+
ProblemFieldError,
|
|
319
|
+
Problem,
|
|
320
|
+
PROBLEM_CONTENT_TYPE,
|
|
321
|
+
LocalTime,
|
|
322
|
+
IsoWeek,
|
|
323
|
+
LangQuery,
|
|
324
|
+
LangFallback,
|
|
325
|
+
Media,
|
|
326
|
+
AllergenCode,
|
|
327
|
+
Allergen,
|
|
328
|
+
DietTag,
|
|
329
|
+
Honeypot,
|
|
330
|
+
FormToken,
|
|
331
|
+
TurnstileToken,
|
|
332
|
+
Email,
|
|
333
|
+
PhoneInput,
|
|
334
|
+
RestaurantStatus,
|
|
335
|
+
BookingMode,
|
|
336
|
+
Site,
|
|
337
|
+
Location,
|
|
338
|
+
LocationsResponse,
|
|
339
|
+
EventPackage,
|
|
340
|
+
EventPackagesResponse,
|
|
341
|
+
EventKind,
|
|
342
|
+
EventRequestCreate,
|
|
343
|
+
BookingProvider,
|
|
344
|
+
WeeklyHours,
|
|
345
|
+
BookingLocation,
|
|
346
|
+
BookingResponse,
|
|
347
|
+
BookingRequestCreate,
|
|
348
|
+
RequestCreated,
|
|
349
|
+
ContactCreate,
|
|
350
|
+
TrackName,
|
|
351
|
+
TrackEvent,
|
|
352
|
+
parseRetryAfter,
|
|
353
|
+
withRetry,
|
|
354
|
+
isRetryableRead,
|
|
355
|
+
isRetryableWrite,
|
|
356
|
+
isRetryableIdempotentWrite
|
|
357
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createClient
|
|
3
|
+
} from "./chunk-5H4Y5WKX.js";
|
|
4
|
+
|
|
5
|
+
// src/next.ts
|
|
6
|
+
import "server-only";
|
|
7
|
+
function createClient2(options) {
|
|
8
|
+
return createClient({
|
|
9
|
+
readInit: ({ tags, revalidate }) => ({
|
|
10
|
+
next: { tags, revalidate }
|
|
11
|
+
}),
|
|
12
|
+
...options
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
createClient2 as createClient
|
|
18
|
+
};
|