@syra.fm/sdk 0.8.0 → 0.10.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.
Files changed (56) hide show
  1. package/lib/commonjs/client.js +236 -7
  2. package/lib/commonjs/client.js.map +1 -1
  3. package/lib/commonjs/index.js +36 -0
  4. package/lib/commonjs/index.js.map +1 -1
  5. package/lib/commonjs/live/components/CreateRoomSheet.js +5 -5
  6. package/lib/commonjs/live/components/CreateRoomSheet.js.map +1 -1
  7. package/lib/commonjs/live/components/RecordingsPanel.js +9 -9
  8. package/lib/commonjs/live/components/RecordingsPanel.js.map +1 -1
  9. package/lib/commonjs/live/services/spaceSocketService.js +1 -1
  10. package/lib/commonjs/live/validation.js +44 -15
  11. package/lib/commonjs/live/validation.js.map +1 -1
  12. package/lib/commonjs/schema.js +80 -9
  13. package/lib/commonjs/schema.js.map +1 -1
  14. package/lib/module/client.js +237 -8
  15. package/lib/module/client.js.map +1 -1
  16. package/lib/module/index.js +1 -1
  17. package/lib/module/index.js.map +1 -1
  18. package/lib/module/live/components/CreateRoomSheet.js +5 -5
  19. package/lib/module/live/components/CreateRoomSheet.js.map +1 -1
  20. package/lib/module/live/components/RecordingsPanel.js +9 -9
  21. package/lib/module/live/components/RecordingsPanel.js.map +1 -1
  22. package/lib/module/live/services/spaceSocketService.js +1 -1
  23. package/lib/module/live/validation.js +44 -15
  24. package/lib/module/live/validation.js.map +1 -1
  25. package/lib/module/schema.js +79 -8
  26. package/lib/module/schema.js.map +1 -1
  27. package/lib/typescript/commonjs/client.d.ts +159 -2
  28. package/lib/typescript/commonjs/client.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/index.d.ts +3 -3
  30. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/live/components/RoomCard.d.ts +1 -1
  32. package/lib/typescript/commonjs/live/components/RoomCard.d.ts.map +1 -1
  33. package/lib/typescript/commonjs/live/validation.d.ts +17 -20
  34. package/lib/typescript/commonjs/live/validation.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/schema.d.ts +97 -7
  36. package/lib/typescript/commonjs/schema.d.ts.map +1 -1
  37. package/lib/typescript/module/client.d.ts +159 -2
  38. package/lib/typescript/module/client.d.ts.map +1 -1
  39. package/lib/typescript/module/index.d.ts +3 -3
  40. package/lib/typescript/module/index.d.ts.map +1 -1
  41. package/lib/typescript/module/live/components/RoomCard.d.ts +1 -1
  42. package/lib/typescript/module/live/components/RoomCard.d.ts.map +1 -1
  43. package/lib/typescript/module/live/validation.d.ts +17 -20
  44. package/lib/typescript/module/live/validation.d.ts.map +1 -1
  45. package/lib/typescript/module/schema.d.ts +97 -7
  46. package/lib/typescript/module/schema.d.ts.map +1 -1
  47. package/package.json +6 -4
  48. package/src/client.ts +418 -10
  49. package/src/index.ts +17 -0
  50. package/src/live/components/CreateRoomSheet.tsx +5 -5
  51. package/src/live/components/RecordingsPanel.tsx +9 -9
  52. package/src/live/components/RoomCard.tsx +1 -1
  53. package/src/live/services/spaceSocketService.ts +1 -1
  54. package/src/live/validation.ts +41 -15
  55. package/src/schema.ts +90 -7
  56. package/src/client.test.ts +0 -632
@@ -120,6 +120,12 @@ export type TrackSummary = z.infer<typeof trackSummarySchema>;
120
120
  * variant `url` is `/api/images/:id`); `imageSourceUrl` keeps the original
121
121
  * external artwork URL as an absolute fallback when re-hosting has not run yet.
122
122
  */
123
+ export declare const podcastVisibilitySchema: z.ZodEnum<{
124
+ private: "private";
125
+ unlisted: "unlisted";
126
+ public: "public";
127
+ }>;
128
+ export type PodcastVisibility = z.infer<typeof podcastVisibilitySchema>;
123
129
  export declare const podcastSummarySchema: z.ZodObject<{
124
130
  id: z.ZodString;
125
131
  title: z.ZodString;
@@ -165,6 +171,12 @@ export declare const podcastSummarySchema: z.ZodObject<{
165
171
  }, z.core.$strip>>;
166
172
  }, z.core.$strip>>;
167
173
  imageSourceUrl: z.ZodOptional<z.ZodString>;
174
+ visibility: z.ZodOptional<z.ZodEnum<{
175
+ private: "private";
176
+ unlisted: "unlisted";
177
+ public: "public";
178
+ }>>;
179
+ aiGenerated: z.ZodOptional<z.ZodBoolean>;
168
180
  }, z.core.$strip>;
169
181
  export type PodcastSummary = z.infer<typeof podcastSummarySchema>;
170
182
  /**
@@ -172,12 +184,28 @@ export type PodcastSummary = z.infer<typeof podcastSummarySchema>;
172
184
  * (`GET /api/podcasts/:id/episodes`, `GET /api/episodes/:id`) — just enough to
173
185
  * list an episode and stream its audio.
174
186
  *
175
- * `enclosureUrl` is the direct audio file URL (e.g.
176
- * `https://api.fastcast.ai/audio/<guid>.mp3`) and is REQUIRED: an episode with
177
- * no enclosure is unplayable, so a row missing it is treated as malformed and
178
- * dropped rather than surfaced as a dead entry. `enclosureType` /
179
- * `enclosureLength` describe that file (MIME type and byte length); `duration`
180
- * is the runtime in seconds and `pubDate` the ISO publish timestamp.
187
+ * ## `enclosureUrl` is OPTIONAL, and that is a bug fix rather than a loosening
188
+ *
189
+ * It used to be required, on the reasoning that "an episode with no enclosure is
190
+ * unplayable, so a row missing it is malformed". That reasoning holds only for
191
+ * RSS-mirrored episodes. A SYRA-HOSTED episode — everything created through
192
+ * `createPodcast`/`uploadEpisode`/the ingest ticket — has no enclosure at all:
193
+ * its audio lives at `audioSource.url`, a path on the Syra API. So the required
194
+ * field made this SDK silently DROP every Syra-hosted episode from
195
+ * `getPodcastEpisodes` and throw on one from `getEpisode` — the entire
196
+ * first-party catalogue, invisible, with no error to notice.
197
+ *
198
+ * The two are alternatives, not a required field and an optional one:
199
+ *
200
+ * enclosureUrl an ABSOLUTE external URL (RSS mirror)
201
+ * audioSource.url a PATH on the Syra API (Syra-hosted)
202
+ *
203
+ * `SyraClient.episodeAudioUrl` is the one place that resolves either into
204
+ * something playable, so no consumer has to know which kind it holds.
205
+ *
206
+ * `enclosureType` / `enclosureLength` describe the external file (MIME type and
207
+ * byte length); `duration` is the runtime in seconds and `pubDate` the ISO
208
+ * publish timestamp.
181
209
  *
182
210
  * Artwork mirrors the podcast SHOW: `image` is the re-hosted Syra image id
183
211
  * (resolved via `/api/images/:id`); `imageSizes` is the multi-resolution variant
@@ -185,16 +213,57 @@ export type PodcastSummary = z.infer<typeof podcastSummarySchema>;
185
213
  * original external artwork URL as an absolute fallback when re-hosting has not
186
214
  * run yet.
187
215
  */
216
+ /**
217
+ * Where a Syra-hosted episode's audio actually is.
218
+ *
219
+ * `url` is a PATH on the Syra API (`/api/podcasts/episodes/:id/audio`), not an
220
+ * absolute URL — resolve it with `SyraClient.episodeAudioUrl` rather than
221
+ * handing it to a player directly.
222
+ */
223
+ export declare const episodeAudioSourceSchema: z.ZodObject<{
224
+ url: z.ZodString;
225
+ format: z.ZodOptional<z.ZodString>;
226
+ bitrate: z.ZodOptional<z.ZodNumber>;
227
+ duration: z.ZodOptional<z.ZodNumber>;
228
+ }, z.core.$strip>;
229
+ export type EpisodeAudioSource = z.infer<typeof episodeAudioSourceSchema>;
230
+ /**
231
+ * An episode's processing state. `ready` is playable; `processing` is an episode
232
+ * whose audio is still being packaged (including one drafted but not yet
233
+ * ingested), and only its OWNER is shown those.
234
+ */
235
+ export declare const episodeStatusSchema: z.ZodEnum<{
236
+ ready: "ready";
237
+ processing: "processing";
238
+ failed: "failed";
239
+ unavailable: "unavailable";
240
+ }>;
241
+ export type EpisodeStatus = z.infer<typeof episodeStatusSchema>;
188
242
  export declare const episodeSummarySchema: z.ZodObject<{
189
243
  id: z.ZodString;
190
244
  podcastId: z.ZodString;
191
245
  title: z.ZodString;
192
246
  description: z.ZodOptional<z.ZodString>;
193
- enclosureUrl: z.ZodString;
247
+ enclosureUrl: z.ZodOptional<z.ZodString>;
194
248
  enclosureType: z.ZodOptional<z.ZodString>;
195
249
  enclosureLength: z.ZodOptional<z.ZodNumber>;
250
+ audioSource: z.ZodOptional<z.ZodObject<{
251
+ url: z.ZodString;
252
+ format: z.ZodOptional<z.ZodString>;
253
+ bitrate: z.ZodOptional<z.ZodNumber>;
254
+ duration: z.ZodOptional<z.ZodNumber>;
255
+ }, z.core.$strip>>;
196
256
  duration: z.ZodOptional<z.ZodNumber>;
197
257
  pubDate: z.ZodOptional<z.ZodString>;
258
+ season: z.ZodOptional<z.ZodNumber>;
259
+ episodeNumber: z.ZodOptional<z.ZodNumber>;
260
+ status: z.ZodOptional<z.ZodEnum<{
261
+ ready: "ready";
262
+ processing: "processing";
263
+ failed: "failed";
264
+ unavailable: "unavailable";
265
+ }>>;
266
+ aiGenerated: z.ZodOptional<z.ZodBoolean>;
198
267
  image: z.ZodOptional<z.ZodString>;
199
268
  imageSizes: z.ZodOptional<z.ZodObject<{
200
269
  small: z.ZodOptional<z.ZodObject<{
@@ -237,4 +306,25 @@ export declare const episodeSummarySchema: z.ZodObject<{
237
306
  imageSourceUrl: z.ZodOptional<z.ZodString>;
238
307
  }, z.core.$strip>;
239
308
  export type EpisodeSummary = z.infer<typeof episodeSummarySchema>;
309
+ /** What `createEpisodeDraft` hands back: the episode to fill, and the capability to fill it. */
310
+ export declare const episodeDraftSchema: z.ZodObject<{
311
+ episodeId: z.ZodString;
312
+ ingestTicket: z.ZodString;
313
+ expiresAt: z.ZodString;
314
+ }, z.core.$strip>;
315
+ export type EpisodeDraft = z.infer<typeof episodeDraftSchema>;
316
+ /** What `getEpisodeStream` hands back: a tokenized HLS URL with its own deadline. */
317
+ export declare const episodeStreamSchema: z.ZodObject<{
318
+ url: z.ZodString;
319
+ type: z.ZodString;
320
+ expiresAt: z.ZodOptional<z.ZodString>;
321
+ }, z.core.$strip>;
322
+ export type EpisodeStream = z.infer<typeof episodeStreamSchema>;
323
+ /** What the image upload endpoint hands back. */
324
+ export declare const uploadedImageSchema: z.ZodObject<{
325
+ id: z.ZodString;
326
+ primaryColor: z.ZodOptional<z.ZodString>;
327
+ secondaryColor: z.ZodOptional<z.ZodString>;
328
+ }, z.core.$strip>;
329
+ export type UploadedImage = z.infer<typeof uploadedImageSchema>;
240
330
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AAEH,mFAAmF;AACnF,eAAO,MAAM,qBAAqB;;;;;iBAKhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,4CAA4C;AAC5C,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAO9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,yBAAyB;AACzB,MAAM,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAW7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAQ/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAa/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AAEH,mFAAmF;AACnF,eAAO,MAAM,qBAAqB;;;;;iBAKhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,4CAA4C;AAC5C,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAO9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,yBAAyB;AACzB,MAAM,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAW7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB;;;;EAA4C,CAAC;AACjF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiB/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;iBAKnC,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;EAA2D,CAAC;AAC5F,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqB/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,gGAAgG;AAChG,eAAO,MAAM,kBAAkB;;;;iBAI7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,qFAAqF;AACrF,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,iDAAiD;AACjD,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syra.fm/sdk",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Syra SDK — headless, isomorphic catalog client (Node/React-free, public reads + 30s previews) that also ships the Syra live-rooms engine (audio rooms over LiveKit) on React Native and web.",
5
5
  "source": "src/index.ts",
6
6
  "main": "lib/commonjs/index.js",
@@ -34,7 +34,9 @@
34
34
  },
35
35
  "files": [
36
36
  "src",
37
- "lib"
37
+ "lib",
38
+ "!src/**/*.test.ts",
39
+ "!src/**/*.spec.ts"
38
40
  ],
39
41
  "keywords": [
40
42
  "syra",
@@ -90,7 +92,7 @@
90
92
  "react-native": "^0.85.3",
91
93
  "react-native-reanimated": "^4.3.1",
92
94
  "react-native-safe-area-context": "^5.7.0",
93
- "@oxyhq/services": "^22.1.0",
95
+ "@oxyhq/services": "^22.13.1 || ^23.0.0 || ^24.0.0 || ^25.0.0 || ^26.0.0 || ^27.0.0",
94
96
  "livekit-client": "^2.20.0",
95
97
  "@livekit/react-native": "^2.11.1",
96
98
  "expo-audio": "~56.0.12",
@@ -151,7 +153,7 @@
151
153
  "react-native": "^0.85.3",
152
154
  "react-native-reanimated": "^4.3.1",
153
155
  "react-native-safe-area-context": "^5.7.0",
154
- "@oxyhq/services": "^22.1.0",
156
+ "@oxyhq/services": "^27.1.1",
155
157
  "livekit-client": "^2.20.0",
156
158
  "@livekit/react-native": "^2.11.1",
157
159
  "expo-audio": "~56.0.12",
package/src/client.ts CHANGED
@@ -2,9 +2,16 @@ import {
2
2
  trackSummarySchema,
3
3
  podcastSummarySchema,
4
4
  episodeSummarySchema,
5
+ episodeDraftSchema,
6
+ episodeStreamSchema,
7
+ uploadedImageSchema,
5
8
  type TrackSummary,
6
9
  type PodcastSummary,
7
10
  type EpisodeSummary,
11
+ type EpisodeDraft,
12
+ type EpisodeStream,
13
+ type UploadedImage,
14
+ type PodcastVisibility,
8
15
  type CoverArtSizes,
9
16
  type ArtworkSize,
10
17
  } from './schema';
@@ -28,9 +35,24 @@ export interface SyraClientOptions {
28
35
  /**
29
36
  * `fetch` implementation. Defaults to the global `fetch` (Node 18+, browsers,
30
37
  * React Native). Inject one (e.g. `node-fetch`) when no global is available.
31
- * This is the seam where an authenticated transport can be layered in later.
32
38
  */
33
39
  fetch?: typeof fetch;
40
+ /**
41
+ * Supplies the caller's Oxy access token. Called BEFORE EVERY REQUEST, never
42
+ * cached here, because an access token is short-lived and the host
43
+ * application is the only thing that knows when it was refreshed — an SDK
44
+ * holding its own copy is an SDK that starts sending an expired one.
45
+ *
46
+ * Returning `null`/`undefined` means "no session right now", which is a normal
47
+ * state and not an error: every PUBLIC read below still works without a token,
48
+ * exactly as it did before this existed. Only the authenticated methods refuse,
49
+ * and they say so by name.
50
+ *
51
+ * The token IS sent on public reads when it is available, which is
52
+ * deliberate — it is what lets an owner see their own private show and their
53
+ * own unpublished episodes through the same methods everyone else uses.
54
+ */
55
+ getAccessToken?: () => string | null | undefined | Promise<string | null | undefined>;
34
56
  }
35
57
 
36
58
  export interface SearchTracksOptions {
@@ -94,6 +116,86 @@ export interface EpisodeArtworkSource {
94
116
  imageSourceUrl?: string | null;
95
117
  }
96
118
 
119
+ /** The fields `createPodcast` accepts. Mirrors `POST /api/podcasts`. */
120
+ export interface CreatePodcastInput {
121
+ title: string;
122
+ description?: string;
123
+ author?: string;
124
+ /** An image id from {@link SyraClient.uploadPodcastImage}, not a URL. */
125
+ image?: string;
126
+ language?: string;
127
+ categories?: string[];
128
+ explicit?: boolean;
129
+ link?: string;
130
+ type?: 'episodic' | 'serial';
131
+ visibility?: PodcastVisibility;
132
+ /** The Alia series this show was generated from; records `provider: 'alia'` provenance. */
133
+ aliaSeriesId?: string;
134
+ /** Disclosure. Independent of {@link CreatePodcastInput.aliaSeriesId} — neither implies the other. */
135
+ aiGenerated?: boolean;
136
+ /** Hosts & Guests as Oxy user ids. Validated server-side; free text is refused. */
137
+ hosts?: string[];
138
+ guests?: string[];
139
+ }
140
+
141
+ /** The fields `updatePodcast` accepts. Every one is optional; omitted means unchanged. */
142
+ export interface UpdatePodcastInput {
143
+ title?: string;
144
+ description?: string;
145
+ author?: string;
146
+ image?: string;
147
+ language?: string;
148
+ categories?: string[];
149
+ explicit?: boolean;
150
+ link?: string;
151
+ type?: 'episodic' | 'serial';
152
+ visibility?: PodcastVisibility;
153
+ aiGenerated?: boolean;
154
+ }
155
+
156
+ /** The metadata `createEpisodeDraft` accepts — everything except the audio. */
157
+ export interface CreateEpisodeDraftInput {
158
+ title: string;
159
+ description?: string;
160
+ summary?: string;
161
+ season?: number;
162
+ episodeNumber?: number;
163
+ episodeType?: 'full' | 'trailer' | 'bonus';
164
+ explicit?: boolean;
165
+ aiGenerated?: boolean;
166
+ hosts?: string[];
167
+ guests?: string[];
168
+ }
169
+
170
+ /**
171
+ * The metadata the ingest step may set.
172
+ *
173
+ * Deliberately SMALLER than {@link CreateEpisodeDraftInput}, and it is not an
174
+ * oversight: the ticket is redeemed by a process with no user session, so the
175
+ * server accepts only what such a process can know by having produced the audio.
176
+ * Title, artwork, `explicit`, `episodeType`, credits and the AI disclosure were
177
+ * fixed at draft time by the authenticated user and are refused here.
178
+ */
179
+ export interface IngestEpisodeInput {
180
+ duration?: number;
181
+ season?: number;
182
+ episodeNumber?: number;
183
+ description?: string;
184
+ summary?: string;
185
+ }
186
+
187
+ /**
188
+ * An audio or image payload, in the shapes the three supported runtimes give you.
189
+ *
190
+ * `Blob`/`File` covers browsers and Node 18+. React Native's `FormData` accepts
191
+ * a `{ uri, name, type }` descriptor instead, which is not a `Blob` at all — it
192
+ * is named here so an RN caller does not have to cast, and so this SDK never has
193
+ * to import anything from React Native to support it.
194
+ */
195
+ export type UploadPayload =
196
+ | Blob
197
+ | { uri: string; name?: string; type?: string };
198
+
97
199
  export interface SyraClient {
98
200
  /**
99
201
  * Search the public catalog for tracks. Returns one paginated page: rows are
@@ -156,6 +258,81 @@ export interface SyraClient {
156
258
  * external artwork URL. Returns `undefined` when no artwork can be derived.
157
259
  */
158
260
  episodeImageUrl(source: EpisodeArtworkSource, size?: ArtworkSize): string | undefined;
261
+ /**
262
+ * Resolve an episode's PLAYABLE audio URL, whichever kind of episode it is.
263
+ *
264
+ * An RSS-mirrored episode carries an absolute `enclosureUrl`; a Syra-hosted one
265
+ * carries `audioSource.url`, a path on the API. This is the one place that
266
+ * knows the difference, so no consumer has to.
267
+ *
268
+ * `undefined` when the episode has no audio yet — a drafted episode awaiting
269
+ * ingest is a real, listable episode with nothing to play, and answering with
270
+ * a broken URL would be worse than answering with nothing.
271
+ */
272
+ episodeAudioUrl(episode: {
273
+ enclosureUrl?: string | null;
274
+ audioSource?: { url?: string | null } | null;
275
+ }): string | undefined;
276
+
277
+ // ── Authenticated ──────────────────────────────────────────────────────────
278
+ //
279
+ // Every method below needs `getAccessToken` to return a token; without one they
280
+ // throw `SyraApiError(401)` from the CLIENT rather than making a request that
281
+ // was never going to be accepted.
282
+
283
+ /** `GET /api/podcasts/mine` — every show the caller owns, in every state. */
284
+ listMyPodcasts(): Promise<PodcastSummary[]>;
285
+ /** `POST /api/podcasts` — create a Syra-hosted show. */
286
+ createPodcast(input: CreatePodcastInput): Promise<PodcastSummary>;
287
+ /** `PATCH /api/podcasts/:id` — edit a Syra-hosted show you own. */
288
+ updatePodcast(podcastId: string, input: UpdatePodcastInput): Promise<PodcastSummary>;
289
+ /**
290
+ * Change who may see a show. A named affordance over
291
+ * {@link SyraClient.updatePodcast}, because it is the one field with
292
+ * consequences a caller should not discover by reading a diff: making a show
293
+ * `private` withdraws it from every listing AND stops its episodes being
294
+ * transcoded, and publishing it again enqueues the transcodes that were
295
+ * deferred.
296
+ */
297
+ setPodcastVisibility(podcastId: string, visibility: PodcastVisibility): Promise<PodcastSummary>;
298
+ /**
299
+ * `POST /api/images/upload` — store cover art and get the image id back.
300
+ *
301
+ * The id is what {@link CreatePodcastInput.image} wants; a URL is not accepted
302
+ * there, because the API re-hosts artwork rather than hotlinking it.
303
+ */
304
+ uploadPodcastImage(image: UploadPayload, filename?: string): Promise<UploadedImage>;
305
+ /**
306
+ * `POST /api/podcasts/:id/episodes/draft` — reserve an episode now and get a
307
+ * single-use ticket to attach its audio later, from a process with no session.
308
+ *
309
+ * The returned ticket is a bearer capability with a deadline: it is good for
310
+ * ONE redemption against THIS episode, and it stops working if the show
311
+ * changes hands. Treat it as a secret.
312
+ */
313
+ createEpisodeDraft(podcastId: string, input: CreateEpisodeDraftInput): Promise<EpisodeDraft>;
314
+ /**
315
+ * `POST /api/podcasts/episodes/:id/ingest` — redeem a draft's ticket by
316
+ * attaching the audio.
317
+ *
318
+ * Takes the whole {@link EpisodeDraft} rather than a loose id and token, so the
319
+ * two cannot be paired up wrongly by a caller holding several drafts.
320
+ *
321
+ * Authenticated by the TICKET, not by the session — this is the one method here
322
+ * that works with no `getAccessToken` at all, which is the entire point of it.
323
+ */
324
+ ingestEpisode(
325
+ draft: Pick<EpisodeDraft, 'episodeId' | 'ingestTicket'>,
326
+ audio: UploadPayload,
327
+ input?: IngestEpisodeInput,
328
+ filename?: string,
329
+ ): Promise<EpisodeSummary>;
330
+ /**
331
+ * `GET /api/podcasts/episodes/:id/stream` — a tokenized HLS URL for a
332
+ * Syra-hosted episode. Requires a session: the URL it returns embeds a stream
333
+ * token minted for the caller.
334
+ */
335
+ getEpisodeStream(episodeId: string): Promise<EpisodeStream>;
159
336
  }
160
337
 
161
338
  /** Order used to pick the best available artwork variant when none is named. */
@@ -232,20 +409,130 @@ export function createSyraClient(options: SyraClientOptions = {}): SyraClient {
232
409
  );
233
410
  }
234
411
 
235
- async function getJson(path: string): Promise<unknown> {
236
- const doFetch = resolveFetch();
237
- const response = await doFetch(`${baseURL}${path}`, {
238
- headers: { Accept: 'application/json' },
239
- });
240
- if (!response.ok) {
412
+ /**
413
+ * The caller's token for THIS request, or `undefined`.
414
+ *
415
+ * Asked every time rather than once at construction: an access token is
416
+ * short-lived, and the host application is the only thing that knows when it
417
+ * was refreshed.
418
+ */
419
+ async function currentToken(): Promise<string | undefined> {
420
+ if (!options.getAccessToken) return undefined;
421
+ const token = await options.getAccessToken();
422
+ return typeof token === 'string' && token.length > 0 ? token : undefined;
423
+ }
424
+
425
+ /**
426
+ * The token, or a refusal — for the methods that cannot work without one.
427
+ *
428
+ * Thrown from the CLIENT rather than sent and rejected, so a consumer with no
429
+ * session gets a message naming the method instead of a bare 401 from a
430
+ * request that was never going to be accepted.
431
+ */
432
+ async function requireToken(method: string): Promise<string> {
433
+ const token = await currentToken();
434
+ if (!token) {
241
435
  throw new SyraApiError(
242
- response.status,
243
- `Syra API request failed: ${response.status} ${response.statusText} (${path})`,
436
+ 401,
437
+ `@syra.fm/sdk: ${method}() needs a signed-in caller. Pass \`getAccessToken\` to ` +
438
+ 'createSyraClient, and make sure it returns a token for the current session.',
244
439
  );
245
440
  }
441
+ return token;
442
+ }
443
+
444
+ /** Raise the API's own error, preferring the message it sent over the status text. */
445
+ async function raiseFor(response: Response, path: string): Promise<never> {
446
+ let detail = `${response.status} ${response.statusText}`;
447
+ try {
448
+ const body: unknown = await response.json();
449
+ if (body && typeof body === 'object' && 'error' in body && typeof body.error === 'string') {
450
+ detail = `${response.status} ${body.error}`;
451
+ }
452
+ } catch {
453
+ // A non-JSON error body is not itself an error worth reporting; the status
454
+ // is what the caller acts on.
455
+ }
456
+ throw new SyraApiError(response.status, `Syra API request failed: ${detail} (${path})`);
457
+ }
458
+
459
+ interface RequestInit_ {
460
+ method?: string;
461
+ body?: BodyInit;
462
+ /** Extra headers. `Authorization` is added here, never by a caller. */
463
+ headers?: Record<string, string>;
464
+ /** Refuse before sending when there is no session. The value is the method name. */
465
+ requires?: string;
466
+ /**
467
+ * Never attach the session token, even when one is available.
468
+ *
469
+ * For a request that carries its OWN credential — the ingest ticket. Sending
470
+ * both would leave the server's answer ambiguous about which one authorized
471
+ * the write, and would mean a worker that happens to hold a user token
472
+ * behaves differently from one that does not. Exactly one credential per
473
+ * request.
474
+ */
475
+ anonymous?: boolean;
476
+ }
477
+
478
+ async function request(path: string, init: RequestInit_ = {}): Promise<unknown> {
479
+ const doFetch = resolveFetch();
480
+ const headers: Record<string, string> = { Accept: 'application/json', ...init.headers };
481
+
482
+ if (init.requires) {
483
+ headers.Authorization = `Bearer ${await requireToken(init.requires)}`;
484
+ } else if (!init.anonymous) {
485
+ // Sent when available even on public reads — it is what lets an owner see
486
+ // their own private show through the same method everyone else calls.
487
+ const token = await currentToken();
488
+ if (token) headers.Authorization = `Bearer ${token}`;
489
+ }
490
+
491
+ const response = await doFetch(`${baseURL}${path}`, {
492
+ method: init.method ?? 'GET',
493
+ headers,
494
+ ...(init.body === undefined ? {} : { body: init.body }),
495
+ });
496
+ if (!response.ok) return raiseFor(response, path);
246
497
  return response.json();
247
498
  }
248
499
 
500
+ async function getJson(path: string): Promise<unknown> {
501
+ return request(path);
502
+ }
503
+
504
+ async function postJson(path: string, body: unknown, requires: string): Promise<unknown> {
505
+ return request(path, {
506
+ method: 'POST',
507
+ requires,
508
+ headers: { 'Content-Type': 'application/json' },
509
+ body: JSON.stringify(body),
510
+ });
511
+ }
512
+
513
+ /**
514
+ * Append an upload to a `FormData`, in whichever shape the runtime gave us.
515
+ *
516
+ * The RN `{ uri, name, type }` descriptor is not a `Blob` and the DOM
517
+ * `FormData.append` signature does not admit it, so it goes through one cast
518
+ * confined to this function — rather than every call site, or a `declare
519
+ * module` shim that would shadow the real DOM types in every consumer.
520
+ */
521
+ function appendUpload(form: FormData, field: string, payload: UploadPayload, filename?: string): void {
522
+ if (typeof Blob !== 'undefined' && payload instanceof Blob) {
523
+ form.append(field, payload, filename);
524
+ return;
525
+ }
526
+ const descriptor = payload as { uri: string; name?: string; type?: string };
527
+ const name = filename ?? descriptor.name ?? field;
528
+ form.append(field, descriptor as unknown as Blob, name);
529
+ }
530
+
531
+ /** Drop `undefined` fields so a partial input never sends `"key": null`. */
532
+ function defined(input: Record<string, unknown>): Record<string, unknown> {
533
+ return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
534
+ }
535
+
249
536
  function resolveImageRef(ref: string | null | undefined): string | undefined {
250
537
  if (!ref) {
251
538
  return undefined;
@@ -418,7 +705,15 @@ export function createSyraClient(options: SyraClientOptions = {}): SyraClient {
418
705
 
419
706
  const items: EpisodeSummary[] = [];
420
707
  for (const raw of rawEpisodes) {
421
- // A single malformed episode row must not fail the whole listing.
708
+ /**
709
+ * A single malformed episode row must not fail the whole listing — but
710
+ * "has no enclosure" is no longer malformed. It used to be, and that is
711
+ * what made every SYRA-HOSTED episode disappear from this method: their
712
+ * audio is `audioSource.url`, not an enclosure. The schema now validates
713
+ * IDENTITY and leaves playability to `episodeAudioUrl`, which is also
714
+ * the only honest answer for a drafted episode whose audio has not
715
+ * arrived yet.
716
+ */
422
717
  const parsed = episodeSummarySchema.safeParse(raw);
423
718
  if (parsed.success) {
424
719
  items.push(parsed.data);
@@ -469,5 +764,118 @@ export function createSyraClient(options: SyraClientOptions = {}): SyraClient {
469
764
 
470
765
  return resolveImageRef(source.imageSourceUrl);
471
766
  },
767
+
768
+ episodeAudioUrl(episode) {
769
+ // An RSS mirror's enclosure is already absolute and points at somebody
770
+ // else's host, so it is returned untouched.
771
+ if (episode.enclosureUrl && /^https?:\/\//i.test(episode.enclosureUrl)) {
772
+ return episode.enclosureUrl;
773
+ }
774
+ const sourceUrl = episode.audioSource?.url;
775
+ if (sourceUrl) {
776
+ return /^https?:\/\//i.test(sourceUrl) ? sourceUrl : `${baseURL}${sourceUrl}`;
777
+ }
778
+ // A relative enclosure is unusual but representable; resolve it the same way.
779
+ if (episode.enclosureUrl) return `${baseURL}${episode.enclosureUrl}`;
780
+ return undefined;
781
+ },
782
+
783
+ async listMyPodcasts() {
784
+ const json = (await request('/api/podcasts/mine', {
785
+ requires: 'listMyPodcasts',
786
+ })) as PodcastSearchResponseShape;
787
+ const rows = Array.isArray(json?.data) ? json.data : [];
788
+
789
+ const items: PodcastSummary[] = [];
790
+ for (const raw of rows) {
791
+ const parsed = podcastSummarySchema.safeParse(raw);
792
+ if (parsed.success) items.push(parsed.data);
793
+ }
794
+ return items;
795
+ },
796
+
797
+ async createPodcast(input) {
798
+ const json = (await postJson(
799
+ '/api/podcasts',
800
+ defined({ ...input }),
801
+ 'createPodcast',
802
+ )) as { data?: unknown };
803
+ return podcastSummarySchema.parse(json?.data);
804
+ },
805
+
806
+ async updatePodcast(podcastId, input) {
807
+ const json = (await request(`/api/podcasts/${encodeURIComponent(podcastId)}`, {
808
+ method: 'PATCH',
809
+ requires: 'updatePodcast',
810
+ headers: { 'Content-Type': 'application/json' },
811
+ body: JSON.stringify(defined({ ...input })),
812
+ })) as { data?: unknown };
813
+ return podcastSummarySchema.parse(json?.data);
814
+ },
815
+
816
+ async setPodcastVisibility(podcastId, visibility) {
817
+ return this.updatePodcast(podcastId, { visibility });
818
+ },
819
+
820
+ async uploadPodcastImage(image, filename) {
821
+ const form = new FormData();
822
+ // `image` is the field name `POST /api/images/upload` reads.
823
+ appendUpload(form, 'image', image, filename);
824
+
825
+ // No `Content-Type`: the runtime sets it, INCLUDING the multipart boundary,
826
+ // which cannot be written by hand. Setting it here produces a body the
827
+ // server cannot parse.
828
+ const json = (await request('/api/images/upload', {
829
+ method: 'POST',
830
+ requires: 'uploadPodcastImage',
831
+ body: form,
832
+ })) as unknown;
833
+ return uploadedImageSchema.parse(json);
834
+ },
835
+
836
+ async createEpisodeDraft(podcastId, input) {
837
+ const json = (await postJson(
838
+ `/api/podcasts/${encodeURIComponent(podcastId)}/episodes/draft`,
839
+ defined({ ...input }),
840
+ 'createEpisodeDraft',
841
+ )) as { data?: unknown };
842
+ return episodeDraftSchema.parse(json?.data);
843
+ },
844
+
845
+ async ingestEpisode(draft, audio, input = {}, filename) {
846
+ const form = new FormData();
847
+ // `audioFile` is the field name the ingest endpoint reads.
848
+ appendUpload(form, 'audioFile', audio, filename ?? 'episode.mp3');
849
+ for (const [key, value] of Object.entries(defined({ ...input }))) {
850
+ form.append(key, String(value));
851
+ }
852
+
853
+ /**
854
+ * `anonymous`, and it is load-bearing rather than tidy: this request is
855
+ * authenticated by the TICKET alone, which is the whole reason the
856
+ * draft/ingest pair exists. Without it a worker that HAPPENS to hold a user
857
+ * token would send both credentials — behaving differently from one that
858
+ * does not, and leaving the server's answer ambiguous about which
859
+ * authorized the write. Caught by a test, not by review.
860
+ */
861
+ const json = (await request(
862
+ `/api/podcasts/episodes/${encodeURIComponent(draft.episodeId)}/ingest`,
863
+ {
864
+ method: 'POST',
865
+ anonymous: true,
866
+ headers: { 'X-Ingest-Ticket': draft.ingestTicket },
867
+ body: form,
868
+ },
869
+ )) as { data?: unknown };
870
+ return episodeSummarySchema.parse(json?.data);
871
+ },
872
+
873
+ async getEpisodeStream(episodeId) {
874
+ const json = await request(
875
+ `/api/podcasts/episodes/${encodeURIComponent(episodeId)}/stream`,
876
+ { requires: 'getEpisodeStream' },
877
+ );
878
+ return episodeStreamSchema.parse(json);
879
+ },
472
880
  };
473
881
  }