1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { fetch } from "https://esm.town/v/std/fetch";
export const bookReservationOnResy = async ({
reservation,
venue,
auth,
}: {
reservation: {
// How many seats to book
seats: number;
// e.g. 2023-05-01 (interpreted as May 05, 2023)
date: string;
// e.g. [17:00, 22:00]
timeRange: [string, string];
};
venue:
| {
type: "id";
id: string;
}
| {
type: "slug";
slug: string;
city: string;
};
auth: {
email: string;
password: string;
};
}) => {
const { z } = await import("npm:zod");
const RESY_API_URL = "https://api.resy.com";
const RESY_DEFAULT_HEADERS = {
accept: "application/json, text/plain, */*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
authorization: 'ResyAPI api_key="VbWk7s3L4KiK5fzlO7JD3Q5EYolJI7n5"',
"x-origin": "https://resy.com",
origin: "https://resy.com/",
dnt: "1",
referer: "https://resy.com/",
"content-type": "application/json",
};
const BookedReservationResponseSchema = z.object({
resy_token: z.string(),
reservation_id: z.number(),
});
const SlotDetailsResponseSchema = z.object({
book_token: z.object({
value: z.string(),
date_expires: z.string(),
}),
});
const FindResponseSchema = z.object({
results: z.object({
venues: z
.object({
venue: z.object({
id: z.object({
resy: z.number(),
}),
name: z.string(),
location: z.object({
time_zone: z.string(),
}),
}),
slots: z
.object({
availability: z.object({
id: z.number(),
}),
config: z.object({
id: z.number(),
// Reservations are booked with the token
token: z.string(),
type: z.string(),
}),
date: z.object({
start: z.string(),
end: z.string(),
}),
payment: z.object({
cancellation_fee: z.number().nullish(),
deposit_fee: z.number().nullish(),
is_paid: z.boolean(),
}),
})
.array(),
})
.array()
.default([]),
}),
});
const PaymentMethodSchema = z.object({
id: z.number(),
type: z.string(),
});
const AuthenticationResponseSchema = z.object({
id: z.number(),
token: z.string(),
๐Ÿ‘† This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data โ€” all from the browser.