@lelap/sdk 0.0.0-stage → 0.2.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 +110 -2
- package/dist/addon.d.ts +44 -0
- package/dist/addon.js +103 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/paths.d.ts +22 -0
- package/dist/paths.js +63 -0
- package/dist/protocol.d.ts +338 -0
- package/dist/protocol.js +160 -0
- package/dist/protocol.schema.json +571 -0
- package/package.json +50 -3
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The protocol version this SDK speaks; manifests declare it as `protocol`. */
|
|
3
|
+
export declare const PROTOCOL_VERSION = 1;
|
|
4
|
+
export declare const CONTENT_TYPES: readonly ["audiobook", "podcast", "episode"];
|
|
5
|
+
export declare const ContentType: z.ZodEnum<{
|
|
6
|
+
audiobook: "audiobook";
|
|
7
|
+
podcast: "podcast";
|
|
8
|
+
episode: "episode";
|
|
9
|
+
}>;
|
|
10
|
+
export type ContentType = z.infer<typeof ContentType>;
|
|
11
|
+
export declare const RESOURCES: readonly ["catalog", "meta", "stream"];
|
|
12
|
+
export declare const ResourceName: z.ZodEnum<{
|
|
13
|
+
catalog: "catalog";
|
|
14
|
+
meta: "meta";
|
|
15
|
+
stream: "stream";
|
|
16
|
+
}>;
|
|
17
|
+
export type ResourceName = z.infer<typeof ResourceName>;
|
|
18
|
+
/** `prefix:value`, such as `ol:OL69612W` or `librivox:secret_garden_librivox`. */
|
|
19
|
+
export declare const ItemId: z.ZodString;
|
|
20
|
+
export declare const CatalogExtra: z.ZodObject<{
|
|
21
|
+
name: z.ZodString;
|
|
22
|
+
isRequired: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export type CatalogExtra = z.infer<typeof CatalogExtra>;
|
|
26
|
+
export declare const CatalogDefinition: z.ZodObject<{
|
|
27
|
+
type: z.ZodEnum<{
|
|
28
|
+
audiobook: "audiobook";
|
|
29
|
+
podcast: "podcast";
|
|
30
|
+
episode: "episode";
|
|
31
|
+
}>;
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
extra: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
35
|
+
name: z.ZodString;
|
|
36
|
+
isRequired: z.ZodOptional<z.ZodBoolean>;
|
|
37
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
38
|
+
}, z.core.$strip>>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
export type CatalogDefinition = z.infer<typeof CatalogDefinition>;
|
|
41
|
+
export declare const ResourceDefinition: z.ZodUnion<readonly [z.ZodEnum<{
|
|
42
|
+
catalog: "catalog";
|
|
43
|
+
meta: "meta";
|
|
44
|
+
stream: "stream";
|
|
45
|
+
}>, z.ZodObject<{
|
|
46
|
+
name: z.ZodEnum<{
|
|
47
|
+
catalog: "catalog";
|
|
48
|
+
meta: "meta";
|
|
49
|
+
stream: "stream";
|
|
50
|
+
}>;
|
|
51
|
+
types: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
52
|
+
audiobook: "audiobook";
|
|
53
|
+
podcast: "podcast";
|
|
54
|
+
episode: "episode";
|
|
55
|
+
}>>>;
|
|
56
|
+
idPrefixes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
57
|
+
}, z.core.$strip>]>;
|
|
58
|
+
export type ResourceDefinition = z.infer<typeof ResourceDefinition>;
|
|
59
|
+
export declare const Manifest: z.ZodObject<{
|
|
60
|
+
id: z.ZodString;
|
|
61
|
+
version: z.ZodString;
|
|
62
|
+
protocol: z.ZodLiteral<1>;
|
|
63
|
+
name: z.ZodString;
|
|
64
|
+
description: z.ZodString;
|
|
65
|
+
logo: z.ZodOptional<z.ZodURL>;
|
|
66
|
+
types: z.ZodArray<z.ZodEnum<{
|
|
67
|
+
audiobook: "audiobook";
|
|
68
|
+
podcast: "podcast";
|
|
69
|
+
episode: "episode";
|
|
70
|
+
}>>;
|
|
71
|
+
resources: z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
72
|
+
catalog: "catalog";
|
|
73
|
+
meta: "meta";
|
|
74
|
+
stream: "stream";
|
|
75
|
+
}>, z.ZodObject<{
|
|
76
|
+
name: z.ZodEnum<{
|
|
77
|
+
catalog: "catalog";
|
|
78
|
+
meta: "meta";
|
|
79
|
+
stream: "stream";
|
|
80
|
+
}>;
|
|
81
|
+
types: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
82
|
+
audiobook: "audiobook";
|
|
83
|
+
podcast: "podcast";
|
|
84
|
+
episode: "episode";
|
|
85
|
+
}>>>;
|
|
86
|
+
idPrefixes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
87
|
+
}, z.core.$strip>]>>;
|
|
88
|
+
idPrefixes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
89
|
+
catalogs: z.ZodArray<z.ZodObject<{
|
|
90
|
+
type: z.ZodEnum<{
|
|
91
|
+
audiobook: "audiobook";
|
|
92
|
+
podcast: "podcast";
|
|
93
|
+
episode: "episode";
|
|
94
|
+
}>;
|
|
95
|
+
id: z.ZodString;
|
|
96
|
+
name: z.ZodString;
|
|
97
|
+
extra: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
98
|
+
name: z.ZodString;
|
|
99
|
+
isRequired: z.ZodOptional<z.ZodBoolean>;
|
|
100
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
101
|
+
}, z.core.$strip>>>;
|
|
102
|
+
}, z.core.$strip>>;
|
|
103
|
+
configurable: z.ZodOptional<z.ZodBoolean>;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
export type Manifest = z.infer<typeof Manifest>;
|
|
106
|
+
export declare const MetaPreview: z.ZodObject<{
|
|
107
|
+
id: z.ZodString;
|
|
108
|
+
type: z.ZodEnum<{
|
|
109
|
+
audiobook: "audiobook";
|
|
110
|
+
podcast: "podcast";
|
|
111
|
+
episode: "episode";
|
|
112
|
+
}>;
|
|
113
|
+
name: z.ZodString;
|
|
114
|
+
author: z.ZodOptional<z.ZodString>;
|
|
115
|
+
cover: z.ZodOptional<z.ZodURL>;
|
|
116
|
+
description: z.ZodOptional<z.ZodString>;
|
|
117
|
+
year: z.ZodOptional<z.ZodNumber>;
|
|
118
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
119
|
+
}, z.core.$strip>;
|
|
120
|
+
export type MetaPreview = z.infer<typeof MetaPreview>;
|
|
121
|
+
export declare const Chapter: z.ZodObject<{
|
|
122
|
+
title: z.ZodString;
|
|
123
|
+
startMs: z.ZodNumber;
|
|
124
|
+
}, z.core.$strip>;
|
|
125
|
+
export type Chapter = z.infer<typeof Chapter>;
|
|
126
|
+
export declare const Episode: z.ZodObject<{
|
|
127
|
+
id: z.ZodString;
|
|
128
|
+
title: z.ZodString;
|
|
129
|
+
released: z.ZodOptional<z.ZodString>;
|
|
130
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
131
|
+
description: z.ZodOptional<z.ZodString>;
|
|
132
|
+
}, z.core.$strip>;
|
|
133
|
+
export type Episode = z.infer<typeof Episode>;
|
|
134
|
+
/** A series the work belongs to; `position` is a label such as `1` or `2.5`. */
|
|
135
|
+
export declare const Series: z.ZodObject<{
|
|
136
|
+
name: z.ZodString;
|
|
137
|
+
position: z.ZodOptional<z.ZodString>;
|
|
138
|
+
}, z.core.$strip>;
|
|
139
|
+
export type Series = z.infer<typeof Series>;
|
|
140
|
+
export declare const Meta: z.ZodObject<{
|
|
141
|
+
id: z.ZodString;
|
|
142
|
+
type: z.ZodEnum<{
|
|
143
|
+
audiobook: "audiobook";
|
|
144
|
+
podcast: "podcast";
|
|
145
|
+
episode: "episode";
|
|
146
|
+
}>;
|
|
147
|
+
name: z.ZodString;
|
|
148
|
+
author: z.ZodOptional<z.ZodString>;
|
|
149
|
+
cover: z.ZodOptional<z.ZodURL>;
|
|
150
|
+
description: z.ZodOptional<z.ZodString>;
|
|
151
|
+
year: z.ZodOptional<z.ZodNumber>;
|
|
152
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
153
|
+
narrators: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
154
|
+
series: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
155
|
+
name: z.ZodString;
|
|
156
|
+
position: z.ZodOptional<z.ZodString>;
|
|
157
|
+
}, z.core.$strip>>>;
|
|
158
|
+
language: z.ZodOptional<z.ZodString>;
|
|
159
|
+
genres: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
160
|
+
chapters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
161
|
+
title: z.ZodString;
|
|
162
|
+
startMs: z.ZodNumber;
|
|
163
|
+
}, z.core.$strip>>>;
|
|
164
|
+
externalIds: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
165
|
+
episodes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
166
|
+
id: z.ZodString;
|
|
167
|
+
title: z.ZodString;
|
|
168
|
+
released: z.ZodOptional<z.ZodString>;
|
|
169
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
170
|
+
description: z.ZodOptional<z.ZodString>;
|
|
171
|
+
}, z.core.$strip>>>;
|
|
172
|
+
link: z.ZodOptional<z.ZodURL>;
|
|
173
|
+
feed: z.ZodOptional<z.ZodURL>;
|
|
174
|
+
}, z.core.$strip>;
|
|
175
|
+
export type Meta = z.infer<typeof Meta>;
|
|
176
|
+
export declare const StreamPart: z.ZodObject<{
|
|
177
|
+
url: z.ZodURL;
|
|
178
|
+
title: z.ZodOptional<z.ZodString>;
|
|
179
|
+
durationMs: z.ZodNumber;
|
|
180
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
181
|
+
}, z.core.$strip>;
|
|
182
|
+
export type StreamPart = z.infer<typeof StreamPart>;
|
|
183
|
+
export declare const SingleFileStream: z.ZodObject<{
|
|
184
|
+
sourceKey: z.ZodString;
|
|
185
|
+
name: z.ZodString;
|
|
186
|
+
title: z.ZodOptional<z.ZodString>;
|
|
187
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
188
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
189
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
190
|
+
downloadable: z.ZodOptional<z.ZodBoolean>;
|
|
191
|
+
url: z.ZodURL;
|
|
192
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
193
|
+
chapters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
194
|
+
title: z.ZodString;
|
|
195
|
+
startMs: z.ZodNumber;
|
|
196
|
+
}, z.core.$strip>>>;
|
|
197
|
+
}, z.core.$strip>;
|
|
198
|
+
export declare const MultiPartStream: z.ZodObject<{
|
|
199
|
+
sourceKey: z.ZodString;
|
|
200
|
+
name: z.ZodString;
|
|
201
|
+
title: z.ZodOptional<z.ZodString>;
|
|
202
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
203
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
204
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
205
|
+
downloadable: z.ZodOptional<z.ZodBoolean>;
|
|
206
|
+
parts: z.ZodArray<z.ZodObject<{
|
|
207
|
+
url: z.ZodURL;
|
|
208
|
+
title: z.ZodOptional<z.ZodString>;
|
|
209
|
+
durationMs: z.ZodNumber;
|
|
210
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
211
|
+
}, z.core.$strip>>;
|
|
212
|
+
}, z.core.$strip>;
|
|
213
|
+
export declare const Stream: z.ZodUnion<readonly [z.ZodObject<{
|
|
214
|
+
sourceKey: z.ZodString;
|
|
215
|
+
name: z.ZodString;
|
|
216
|
+
title: z.ZodOptional<z.ZodString>;
|
|
217
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
218
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
219
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
220
|
+
downloadable: z.ZodOptional<z.ZodBoolean>;
|
|
221
|
+
parts: z.ZodArray<z.ZodObject<{
|
|
222
|
+
url: z.ZodURL;
|
|
223
|
+
title: z.ZodOptional<z.ZodString>;
|
|
224
|
+
durationMs: z.ZodNumber;
|
|
225
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
226
|
+
}, z.core.$strip>>;
|
|
227
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
228
|
+
sourceKey: z.ZodString;
|
|
229
|
+
name: z.ZodString;
|
|
230
|
+
title: z.ZodOptional<z.ZodString>;
|
|
231
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
232
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
233
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
234
|
+
downloadable: z.ZodOptional<z.ZodBoolean>;
|
|
235
|
+
url: z.ZodURL;
|
|
236
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
237
|
+
chapters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
238
|
+
title: z.ZodString;
|
|
239
|
+
startMs: z.ZodNumber;
|
|
240
|
+
}, z.core.$strip>>>;
|
|
241
|
+
}, z.core.$strip>]>;
|
|
242
|
+
export type Stream = z.infer<typeof Stream>;
|
|
243
|
+
export declare const CatalogResponse: z.ZodObject<{
|
|
244
|
+
metas: z.ZodArray<z.ZodObject<{
|
|
245
|
+
id: z.ZodString;
|
|
246
|
+
type: z.ZodEnum<{
|
|
247
|
+
audiobook: "audiobook";
|
|
248
|
+
podcast: "podcast";
|
|
249
|
+
episode: "episode";
|
|
250
|
+
}>;
|
|
251
|
+
name: z.ZodString;
|
|
252
|
+
author: z.ZodOptional<z.ZodString>;
|
|
253
|
+
cover: z.ZodOptional<z.ZodURL>;
|
|
254
|
+
description: z.ZodOptional<z.ZodString>;
|
|
255
|
+
year: z.ZodOptional<z.ZodNumber>;
|
|
256
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
257
|
+
}, z.core.$strip>>;
|
|
258
|
+
cacheMaxAge: z.ZodOptional<z.ZodNumber>;
|
|
259
|
+
}, z.core.$strip>;
|
|
260
|
+
export type CatalogResponse = z.infer<typeof CatalogResponse>;
|
|
261
|
+
export declare const MetaResponse: z.ZodObject<{
|
|
262
|
+
meta: z.ZodObject<{
|
|
263
|
+
id: z.ZodString;
|
|
264
|
+
type: z.ZodEnum<{
|
|
265
|
+
audiobook: "audiobook";
|
|
266
|
+
podcast: "podcast";
|
|
267
|
+
episode: "episode";
|
|
268
|
+
}>;
|
|
269
|
+
name: z.ZodString;
|
|
270
|
+
author: z.ZodOptional<z.ZodString>;
|
|
271
|
+
cover: z.ZodOptional<z.ZodURL>;
|
|
272
|
+
description: z.ZodOptional<z.ZodString>;
|
|
273
|
+
year: z.ZodOptional<z.ZodNumber>;
|
|
274
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
275
|
+
narrators: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
276
|
+
series: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
277
|
+
name: z.ZodString;
|
|
278
|
+
position: z.ZodOptional<z.ZodString>;
|
|
279
|
+
}, z.core.$strip>>>;
|
|
280
|
+
language: z.ZodOptional<z.ZodString>;
|
|
281
|
+
genres: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
282
|
+
chapters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
283
|
+
title: z.ZodString;
|
|
284
|
+
startMs: z.ZodNumber;
|
|
285
|
+
}, z.core.$strip>>>;
|
|
286
|
+
externalIds: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
287
|
+
episodes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
288
|
+
id: z.ZodString;
|
|
289
|
+
title: z.ZodString;
|
|
290
|
+
released: z.ZodOptional<z.ZodString>;
|
|
291
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
292
|
+
description: z.ZodOptional<z.ZodString>;
|
|
293
|
+
}, z.core.$strip>>>;
|
|
294
|
+
link: z.ZodOptional<z.ZodURL>;
|
|
295
|
+
feed: z.ZodOptional<z.ZodURL>;
|
|
296
|
+
}, z.core.$strip>;
|
|
297
|
+
cacheMaxAge: z.ZodOptional<z.ZodNumber>;
|
|
298
|
+
}, z.core.$strip>;
|
|
299
|
+
export type MetaResponse = z.infer<typeof MetaResponse>;
|
|
300
|
+
export declare const StreamResponse: z.ZodObject<{
|
|
301
|
+
streams: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
302
|
+
sourceKey: z.ZodString;
|
|
303
|
+
name: z.ZodString;
|
|
304
|
+
title: z.ZodOptional<z.ZodString>;
|
|
305
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
306
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
307
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
308
|
+
downloadable: z.ZodOptional<z.ZodBoolean>;
|
|
309
|
+
parts: z.ZodArray<z.ZodObject<{
|
|
310
|
+
url: z.ZodURL;
|
|
311
|
+
title: z.ZodOptional<z.ZodString>;
|
|
312
|
+
durationMs: z.ZodNumber;
|
|
313
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
314
|
+
}, z.core.$strip>>;
|
|
315
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
316
|
+
sourceKey: z.ZodString;
|
|
317
|
+
name: z.ZodString;
|
|
318
|
+
title: z.ZodOptional<z.ZodString>;
|
|
319
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
320
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
321
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
322
|
+
downloadable: z.ZodOptional<z.ZodBoolean>;
|
|
323
|
+
url: z.ZodURL;
|
|
324
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
325
|
+
chapters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
326
|
+
title: z.ZodString;
|
|
327
|
+
startMs: z.ZodNumber;
|
|
328
|
+
}, z.core.$strip>>>;
|
|
329
|
+
}, z.core.$strip>]>>;
|
|
330
|
+
cacheMaxAge: z.ZodOptional<z.ZodNumber>;
|
|
331
|
+
}, z.core.$strip>;
|
|
332
|
+
export type StreamResponse = z.infer<typeof StreamResponse>;
|
|
333
|
+
/** Whether a stream has parts rather than one URL. */
|
|
334
|
+
export declare function hasParts(stream: Stream): stream is z.infer<typeof MultiPartStream>;
|
|
335
|
+
/** The `idPrefixes` an add-on declares for a resource, or `null` when it takes any ID. */
|
|
336
|
+
export declare function prefixesFor(manifest: Manifest, resource: ResourceName): string[] | null;
|
|
337
|
+
/** Whether the add-on answers `resource` for this type and ID. */
|
|
338
|
+
export declare function supports(manifest: Manifest, resource: ResourceName, type: ContentType, id: string): boolean;
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The protocol version this SDK speaks; manifests declare it as `protocol`. */
|
|
3
|
+
export const PROTOCOL_VERSION = 1;
|
|
4
|
+
export const CONTENT_TYPES = ['audiobook', 'podcast', 'episode'];
|
|
5
|
+
export const ContentType = z.enum(CONTENT_TYPES);
|
|
6
|
+
export const RESOURCES = ['catalog', 'meta', 'stream'];
|
|
7
|
+
export const ResourceName = z.enum(RESOURCES);
|
|
8
|
+
/** `prefix:value`, such as `ol:OL69612W` or `librivox:secret_garden_librivox`. */
|
|
9
|
+
export const ItemId = z
|
|
10
|
+
.string()
|
|
11
|
+
.min(3)
|
|
12
|
+
.max(512)
|
|
13
|
+
.regex(/^[a-z][a-z0-9_-]*:.+$/, 'IDs look like prefix:value');
|
|
14
|
+
const Url = z.url({ protocol: /^https?$/ });
|
|
15
|
+
const Duration = z.number().int().nonnegative();
|
|
16
|
+
export const CatalogExtra = z.object({
|
|
17
|
+
/** `search`, `genre` and `skip` are the extras the app understands. */
|
|
18
|
+
name: z.string().min(1),
|
|
19
|
+
isRequired: z.boolean().optional(),
|
|
20
|
+
/** Allowed values, for `genre`. */
|
|
21
|
+
options: z.array(z.string()).optional(),
|
|
22
|
+
});
|
|
23
|
+
export const CatalogDefinition = z.object({
|
|
24
|
+
type: ContentType,
|
|
25
|
+
id: z.string().min(1),
|
|
26
|
+
name: z.string().min(1),
|
|
27
|
+
extra: z.array(CatalogExtra).optional(),
|
|
28
|
+
});
|
|
29
|
+
export const ResourceDefinition = z.union([
|
|
30
|
+
ResourceName,
|
|
31
|
+
z.object({
|
|
32
|
+
name: ResourceName,
|
|
33
|
+
types: z.array(ContentType).optional(),
|
|
34
|
+
idPrefixes: z.array(z.string().min(1)).optional(),
|
|
35
|
+
}),
|
|
36
|
+
]);
|
|
37
|
+
export const Manifest = z.object({
|
|
38
|
+
/** Reverse DNS, such as `org.example.myaddon`. */
|
|
39
|
+
id: z.string().min(3),
|
|
40
|
+
version: z.string().regex(/^\d+\.\d+\.\d+/, 'Use semantic versioning'),
|
|
41
|
+
protocol: z.literal(PROTOCOL_VERSION),
|
|
42
|
+
name: z.string().min(1),
|
|
43
|
+
description: z.string(),
|
|
44
|
+
logo: Url.optional(),
|
|
45
|
+
types: z.array(ContentType).min(1),
|
|
46
|
+
resources: z.array(ResourceDefinition).min(1),
|
|
47
|
+
/** Prefixes of the IDs this add-on answers `meta` and `stream` for. */
|
|
48
|
+
idPrefixes: z.array(z.string().min(1)).optional(),
|
|
49
|
+
catalogs: z.array(CatalogDefinition),
|
|
50
|
+
/** The add-on has a `/configure` page. */
|
|
51
|
+
configurable: z.boolean().optional(),
|
|
52
|
+
});
|
|
53
|
+
export const MetaPreview = z.object({
|
|
54
|
+
id: ItemId,
|
|
55
|
+
type: ContentType,
|
|
56
|
+
name: z.string().min(1),
|
|
57
|
+
author: z.string().optional(),
|
|
58
|
+
cover: Url.optional(),
|
|
59
|
+
description: z.string().optional(),
|
|
60
|
+
year: z.number().int().optional(),
|
|
61
|
+
durationMs: Duration.optional(),
|
|
62
|
+
});
|
|
63
|
+
export const Chapter = z.object({ title: z.string(), startMs: Duration });
|
|
64
|
+
export const Episode = z.object({
|
|
65
|
+
id: ItemId,
|
|
66
|
+
title: z.string(),
|
|
67
|
+
/** ISO 8601. */
|
|
68
|
+
released: z.string().optional(),
|
|
69
|
+
durationMs: Duration.optional(),
|
|
70
|
+
description: z.string().optional(),
|
|
71
|
+
});
|
|
72
|
+
/** A series the work belongs to; `position` is a label such as `1` or `2.5`. */
|
|
73
|
+
export const Series = z.object({ name: z.string().min(1), position: z.string().optional() });
|
|
74
|
+
export const Meta = MetaPreview.extend({
|
|
75
|
+
narrators: z.array(z.string()).optional(),
|
|
76
|
+
/** Main series first. */
|
|
77
|
+
series: z.array(Series).optional(),
|
|
78
|
+
/** BCP 47 or ISO 639 code. */
|
|
79
|
+
language: z.string().optional(),
|
|
80
|
+
genres: z.array(z.string()).optional(),
|
|
81
|
+
/**
|
|
82
|
+
* On the whole-book timeline. The app uses them for a stream without its own chapters when the
|
|
83
|
+
* stream's length matches `durationMs`.
|
|
84
|
+
*/
|
|
85
|
+
chapters: z.array(Chapter).optional(),
|
|
86
|
+
/** The same work under other prefixes, such as `{ ol: 'OL69612W', asin: 'B002UZMLXM' }`. */
|
|
87
|
+
externalIds: z.record(z.string(), z.string()).optional(),
|
|
88
|
+
episodes: z.array(Episode).optional(),
|
|
89
|
+
/** A page about the item on the source's own site. */
|
|
90
|
+
link: Url.optional(),
|
|
91
|
+
/** A podcast's RSS feed. The app subscribes to it and reads it directly. */
|
|
92
|
+
feed: Url.optional(),
|
|
93
|
+
});
|
|
94
|
+
export const StreamPart = z.object({
|
|
95
|
+
url: Url,
|
|
96
|
+
title: z.string().optional(),
|
|
97
|
+
durationMs: Duration,
|
|
98
|
+
size: z.number().int().nonnegative().optional(),
|
|
99
|
+
});
|
|
100
|
+
const StreamBase = z.object({
|
|
101
|
+
/** Stable for this source and item; the app keys saved places on it. */
|
|
102
|
+
sourceKey: z.string().min(1).max(256),
|
|
103
|
+
/** Who provides it, such as `LibriVox`. */
|
|
104
|
+
name: z.string().min(1),
|
|
105
|
+
/** What makes it different from other streams, such as the reader. */
|
|
106
|
+
title: z.string().optional(),
|
|
107
|
+
mime: z.string().optional(),
|
|
108
|
+
/** Bits per second, such as `64000`. */
|
|
109
|
+
bitrate: z.number().int().positive().optional(),
|
|
110
|
+
size: z.number().int().nonnegative().optional(),
|
|
111
|
+
downloadable: z.boolean().optional(),
|
|
112
|
+
});
|
|
113
|
+
export const SingleFileStream = StreamBase.extend({
|
|
114
|
+
url: Url,
|
|
115
|
+
durationMs: Duration.optional(),
|
|
116
|
+
chapters: z.array(Chapter).optional(),
|
|
117
|
+
});
|
|
118
|
+
export const MultiPartStream = StreamBase.extend({
|
|
119
|
+
parts: z.array(StreamPart).min(1),
|
|
120
|
+
});
|
|
121
|
+
// Parts first: a stream that wrongly sends both `parts` and `url` plays its parts.
|
|
122
|
+
export const Stream = z.union([MultiPartStream, SingleFileStream]);
|
|
123
|
+
const CacheMaxAge = z.number().int().nonnegative().optional();
|
|
124
|
+
export const CatalogResponse = z.object({
|
|
125
|
+
metas: z.array(MetaPreview),
|
|
126
|
+
cacheMaxAge: CacheMaxAge,
|
|
127
|
+
});
|
|
128
|
+
export const MetaResponse = z.object({ meta: Meta, cacheMaxAge: CacheMaxAge });
|
|
129
|
+
export const StreamResponse = z.object({
|
|
130
|
+
streams: z.array(Stream),
|
|
131
|
+
cacheMaxAge: CacheMaxAge,
|
|
132
|
+
});
|
|
133
|
+
/** Whether a stream has parts rather than one URL. */
|
|
134
|
+
export function hasParts(stream) {
|
|
135
|
+
return 'parts' in stream;
|
|
136
|
+
}
|
|
137
|
+
/** The `idPrefixes` an add-on declares for a resource, or `null` when it takes any ID. */
|
|
138
|
+
export function prefixesFor(manifest, resource) {
|
|
139
|
+
for (const definition of manifest.resources) {
|
|
140
|
+
if (typeof definition === 'string') {
|
|
141
|
+
if (definition === resource)
|
|
142
|
+
return manifest.idPrefixes ?? null;
|
|
143
|
+
}
|
|
144
|
+
else if (definition.name === resource) {
|
|
145
|
+
return definition.idPrefixes ?? manifest.idPrefixes ?? null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
/** Whether the add-on answers `resource` for this type and ID. */
|
|
151
|
+
export function supports(manifest, resource, type, id) {
|
|
152
|
+
const definition = manifest.resources.find((r) => (typeof r === 'string' ? r : r.name) === resource);
|
|
153
|
+
if (!definition)
|
|
154
|
+
return false;
|
|
155
|
+
const types = typeof definition === 'string' ? manifest.types : (definition.types ?? manifest.types);
|
|
156
|
+
if (!types.includes(type))
|
|
157
|
+
return false;
|
|
158
|
+
const prefixes = prefixesFor(manifest, resource);
|
|
159
|
+
return prefixes === null || prefixes.some((prefix) => id.startsWith(prefix));
|
|
160
|
+
}
|