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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
import { z } from "zod";
import { zCursorV2 } from "./pagination";
import { zBookmarkTagSchema } from "./tags";
export const MAX_BOOKMARK_TITLE_LENGTH = 1000;
export const enum BookmarkTypes {
LINK = "link",
TEXT = "text",
ASSET = "asset",
UNKNOWN = "unknown",
}
export const zSortOrder = z.enum(["asc", "desc", "relevance"]);
export type ZSortOrder = z.infer<typeof zSortOrder>;
export const zAssetTypesSchema = z.enum([
"linkHtmlContent",
"screenshot",
"assetScreenshot",
"bannerImage",
"fullPageArchive",
"video",
"bookmarkAsset",
"precrawledArchive",
"userUploaded",
"unknown",
]);
export type ZAssetType = z.infer<typeof zAssetTypesSchema>;
export const zAssetSchema = z.object({
id: z.string(),
assetType: zAssetTypesSchema,
fileName: z.string().nullish(),
});
export const zBookmarkedLinkSchema = z.object({
type: z.literal(BookmarkTypes.LINK),
url: z.string(),
title: z.string().nullish(),
description: z.string().nullish(),
imageUrl: z.string().nullish(),
imageAssetId: z.string().nullish(),
screenshotAssetId: z.string().nullish(),
fullPageArchiveAssetId: z.string().nullish(),
precrawledArchiveAssetId: z.string().nullish(),
videoAssetId: z.string().nullish(),
favicon: z.string().nullish(),
htmlContent: z.string().nullish(),
contentAssetId: z.string().nullish(),
crawledAt: z.date().nullish(),
author: z.string().nullish(),
publisher: z.string().nullish(),
datePublished: z.date().nullish(),
dateModified: z.date().nullish(),
});
export type ZBookmarkedLink = z.infer<typeof zBookmarkedLinkSchema>;
export const zBookmarkedTextSchema = z.object({
type: z.literal(BookmarkTypes.TEXT),
text: z.string(),
sourceUrl: z.string().nullish(),
});
export type ZBookmarkedText = z.infer<typeof zBookmarkedTextSchema>;
export const zBookmarkedAssetSchema = z.object({
type: z.literal(BookmarkTypes.ASSET),
assetType: z.enum(["image", "pdf"]),
assetId: z.string(),
fileName: z.string().nullish(),
sourceUrl: z.string().nullish(),
size: z.number().nullish(),
content: z.string().nullish(),
});
export type ZBookmarkedAsset = z.infer<typeof zBookmarkedAssetSchema>;
export const zBookmarkContentSchema = z.discriminatedUnion("type", [
zBookmarkedLinkSchema,
zBookmarkedTextSchema,
zBookmarkedAssetSchema,
z.object({ type: z.literal(BookmarkTypes.UNKNOWN) }),
]);
export type ZBookmarkContent = z.infer<typeof zBookmarkContentSchema>;
export const zBookmarkSourceSchema = z.enum([
"api",
"web",
"cli",
"mobile",
"extension",
"singlefile",
"rss",
"import",
]);
export type ZBookmarkSource = z.infer<typeof zBookmarkSourceSchema>;
export const zBareBookmarkSchema = z.object({
id: z.string(),
createdAt: z.date(),
modifiedAt: z.date().nullable(),
title: z.string().nullish(),
archived: z.boolean(),
favourited: z.boolean(),
taggingStatus: z.enum(["success", "failure", "pending"]).nullable(),
summarizationStatus: z.enum(["success", "failure", "pending"]).nullable(),
note: z.string().nullish(),
summary: z.string().nullish(),
source: zBookmarkSourceSchema.nullish(),
userId: z.string(),
});
export type ZBareBookmark = z.infer<typeof zBareBookmarkSchema>;
export const zBookmarkSchema = zBareBookmarkSchema.merge(
z.object({
tags: z.array(zBookmarkTagSchema),
content: zBookmarkContentSchema,
assets: z.array(zAssetSchema),
}),
);
export type ZBookmark = z.infer<typeof zBookmarkSchema>;
const zBookmarkTypeLinkSchema = zBareBookmarkSchema.merge(
z.object({
tags: z.array(zBookmarkTagSchema),
content: zBookmarkedLinkSchema,
assets: z.array(zAssetSchema),
}),
);
export type ZBookmarkTypeLink = z.infer<typeof zBookmarkTypeLinkSchema>;
const zBookmarkTypeTextSchema = zBareBookmarkSchema.merge(
z.object({
tags: z.array(zBookmarkTagSchema),
content: zBookmarkedTextSchema,
assets: z.array(zAssetSchema),
}),
);
export type ZBookmarkTypeText = z.infer<typeof zBookmarkTypeTextSchema>;
const zBookmarkTypeAssetSchema = zBareBookmarkSchema.merge(
z.object({
tags: z.array(zBookmarkTagSchema),
content: zBookmarkedAssetSchema,
assets: z.array(zAssetSchema),
}),
);
export type ZBookmarkTypeAsset = z.infer<typeof zBookmarkTypeAssetSchema>;
// POST /v1/bookmarks
export const zNewBookmarkRequestSchema = z
.object({
title: z.string().max(MAX_BOOKMARK_TITLE_LENGTH).nullish(),
archived: z.boolean().optional(),
favourited: z.boolean().optional(),
note: z.string().optional(),
summary: z.string().optional(),
createdAt: z.coerce.date().optional(),
// A mechanism to prioritize crawling of bookmarks depending on whether
// they were created by a user interaction or by a bulk import.
crawlPriority: z.enum(["low", "normal"]).optional(),
importSessionId: z.string().optional(),
source: zBookmarkSourceSchema.optional(),
})
.and(
z.discriminatedUnion("type", [
z.object({
type: z.literal(BookmarkTypes.LINK),
url: z.string().url(),
precrawledArchiveId: z.string().optional(),
}),
z.object({
type: z.literal(BookmarkTypes.TEXT),
text: z.string(),
sourceUrl: z.string().optional(),
}),
z.object({
type: z.literal(BookmarkTypes.ASSET),
assetType: z.enum(["image", "pdf"]),
assetId: z.string(),
fileName: z.string().optional(),
sourceUrl: z.string().optional(),
}),
]),
);
export type ZNewBookmarkRequest = z.infer<typeof zNewBookmarkRequestSchema>;
// GET /v1/bookmarks
export const DEFAULT_NUM_BOOKMARKS_PER_PAGE = 20;
export const MAX_NUM_BOOKMARKS_PER_PAGE = 100;
export const zGetBookmarksRequestSchema = z.object({
ids: z.array(z.string()).optional(),
archived: z.boolean().optional(),
favourited: z.boolean().optional(),
tagId: z.string().optional(),
listId: z.string().optional(),
rssFeedId: z.string().optional(),
limit: z.number().max(MAX_NUM_BOOKMARKS_PER_PAGE).optional(),
cursor: zCursorV2.nullish(),
// TODO: This was done for backward comptability. At this point, all clients should be settings this to true.
// The value is currently not being used, but keeping it so that client can still set it to true for older
// servers.
useCursorV2: z.boolean().optional(),
sortOrder: zSortOrder.exclude(["relevance"]).optional().default("desc"),
includeContent: z.boolean().optional().default(false),
});
export type ZGetBookmarksRequest = z.infer<typeof zGetBookmarksRequestSchema>;
export const zGetBookmarksResponseSchema = z.object({
bookmarks: z.array(zBookmarkSchema),
nextCursor: zCursorV2.nullable(),
});
export type ZGetBookmarksResponse = z.infer<typeof zGetBookmarksResponseSchema>;
// PATCH /v1/bookmarks/[bookmarkId]
export const zUpdateBookmarksRequestSchema = z.object({
bookmarkId: z.string(),
archived: z.boolean().optional(),
favourited: z.boolean().optional(),
summary: z.string().nullish(),
note: z.string().optional(),
title: z.string().max(MAX_BOOKMARK_TITLE_LENGTH).nullish(),
createdAt: z.coerce.date().optional(),
// Link specific fields (optional)
url: z.string().url().optional(),
description: z.string().nullish(),
author: z.string().nullish(),
publisher: z.string().nullish(),
datePublished: z.coerce.date().nullish(),
dateModified: z.coerce.date().nullish(),
// Text specific fields (optional)
text: z.string().nullish(),
// Asset specific fields (optional)
assetContent: z.string().nullish(),
});
export type ZUpdateBookmarksRequest = z.infer<
typeof zUpdateBookmarksRequestSchema
>;
// The schema that's used to for attachig/detaching tags
export const zManipulatedTagSchema = z
.object({
// At least one of the two must be set
tagId: z.string().optional(), // If the tag already exists and we know its id we should pass it
tagName: z.string().optional(),
})
.refine((val) => !!val.tagId || !!val.tagName, {
message: "You must provide either a tagId or a tagName",
path: ["tagId", "tagName"],
});
export const zSearchBookmarksCursor = z.discriminatedUnion("ver", [
z.object({
ver: z.literal(1),
offset: z.number(),
}),
]);
export const zSearchBookmarksRequestSchema = z.object({
text: z.string(),
limit: z.number().max(MAX_NUM_BOOKMARKS_PER_PAGE).optional(),
cursor: zSearchBookmarksCursor.nullish(),
sortOrder: zSortOrder.optional().default("relevance"),
includeContent: z.boolean().optional().default(false),
});
export const zPublicBookmarkSchema = z.object({
id: z.string(),
createdAt: z.date(),
modifiedAt: z.date().nullable(),
title: z.string().nullish(),
tags: z.array(z.string()),
description: z.string().nullish(),
bannerImageUrl: z.string().nullable(),
content: z.discriminatedUnion("type", [
z.object({
type: z.literal(BookmarkTypes.LINK),
url: z.string(),
author: z.string().nullish(),
}),
z.object({
type: z.literal(BookmarkTypes.TEXT),
text: z.string(),
}),
z.object({
type: z.literal(BookmarkTypes.ASSET),
assetType: z.enum(["image", "pdf"]),
assetId: z.string(),
assetUrl: z.string(),
fileName: z.string().nullish(),
sourceUrl: z.string().nullish(),
}),
]),
});
export type ZPublicBookmark = z.infer<typeof zPublicBookmarkSchema>;
|