yoto-nodejs-client 0.0.2 → 0.0.4

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 (75) hide show
  1. package/README.md +523 -30
  2. package/bin/auth.js +36 -46
  3. package/bin/content.js +0 -0
  4. package/bin/device-model.d.ts +3 -0
  5. package/bin/device-model.d.ts.map +1 -0
  6. package/bin/device-model.js +360 -0
  7. package/bin/device-tui.TODO.md +125 -0
  8. package/bin/device-tui.d.ts +31 -0
  9. package/bin/device-tui.d.ts.map +1 -0
  10. package/bin/device-tui.js +1123 -0
  11. package/bin/devices.js +166 -28
  12. package/bin/groups.js +0 -0
  13. package/bin/icons.js +0 -0
  14. package/bin/lib/cli-helpers.d.ts +1 -1
  15. package/bin/lib/cli-helpers.d.ts.map +1 -1
  16. package/bin/lib/cli-helpers.js +5 -5
  17. package/bin/refresh-token.js +6 -6
  18. package/bin/token-info.js +3 -3
  19. package/index.d.ts +4 -585
  20. package/index.d.ts.map +1 -1
  21. package/index.js +11 -689
  22. package/lib/api-client.d.ts +576 -0
  23. package/lib/api-client.d.ts.map +1 -0
  24. package/lib/api-client.js +681 -0
  25. package/lib/api-endpoints/auth.d.ts +199 -8
  26. package/lib/api-endpoints/auth.d.ts.map +1 -1
  27. package/lib/api-endpoints/auth.js +224 -7
  28. package/lib/api-endpoints/auth.test.js +54 -2
  29. package/lib/api-endpoints/constants.d.ts +14 -8
  30. package/lib/api-endpoints/constants.d.ts.map +1 -1
  31. package/lib/api-endpoints/constants.js +17 -10
  32. package/lib/api-endpoints/content.test.js +1 -1
  33. package/lib/api-endpoints/devices.d.ts +405 -117
  34. package/lib/api-endpoints/devices.d.ts.map +1 -1
  35. package/lib/api-endpoints/devices.js +114 -52
  36. package/lib/api-endpoints/devices.test.js +1 -1
  37. package/lib/api-endpoints/{test-helpers.d.ts → endpoint-test-helpers.d.ts} +1 -1
  38. package/lib/api-endpoints/endpoint-test-helpers.d.ts.map +1 -0
  39. package/lib/api-endpoints/family-library-groups.test.js +1 -1
  40. package/lib/api-endpoints/family.test.js +1 -1
  41. package/lib/api-endpoints/icons.test.js +1 -1
  42. package/lib/helpers/power-state.d.ts +53 -0
  43. package/lib/helpers/power-state.d.ts.map +1 -0
  44. package/lib/helpers/power-state.js +73 -0
  45. package/lib/helpers/power-state.test.js +100 -0
  46. package/lib/helpers/temperature.d.ts +24 -0
  47. package/lib/helpers/temperature.d.ts.map +1 -0
  48. package/lib/helpers/temperature.js +61 -0
  49. package/lib/helpers/temperature.test.js +58 -0
  50. package/lib/helpers/typed-keys.d.ts +7 -0
  51. package/lib/helpers/typed-keys.d.ts.map +1 -0
  52. package/lib/helpers/typed-keys.js +8 -0
  53. package/lib/mqtt/client.d.ts +348 -22
  54. package/lib/mqtt/client.d.ts.map +1 -1
  55. package/lib/mqtt/client.js +213 -31
  56. package/lib/mqtt/factory.d.ts +22 -4
  57. package/lib/mqtt/factory.d.ts.map +1 -1
  58. package/lib/mqtt/factory.js +27 -5
  59. package/lib/mqtt/mqtt.test.js +85 -28
  60. package/lib/mqtt/topics.d.ts +41 -13
  61. package/lib/mqtt/topics.d.ts.map +1 -1
  62. package/lib/mqtt/topics.js +54 -20
  63. package/lib/pkg.d.cts +8 -0
  64. package/lib/token.d.ts +21 -6
  65. package/lib/token.d.ts.map +1 -1
  66. package/lib/token.js +30 -23
  67. package/lib/yoto-account.d.ts +163 -0
  68. package/lib/yoto-account.d.ts.map +1 -0
  69. package/lib/yoto-account.js +340 -0
  70. package/lib/yoto-device.d.ts +656 -0
  71. package/lib/yoto-device.d.ts.map +1 -0
  72. package/lib/yoto-device.js +2850 -0
  73. package/package.json +21 -15
  74. package/lib/api-endpoints/test-helpers.d.ts.map +0 -1
  75. /package/lib/api-endpoints/{test-helpers.js → endpoint-test-helpers.js} +0 -0
package/index.d.ts CHANGED
@@ -1,586 +1,5 @@
1
- /**
2
- * @typedef {Object} RefreshSuccessEvent
3
- * @property {string} clientId - The OAuth client ID
4
- * @property {string} accessToken - The new access token
5
- * @property {string} refreshToken - The refresh token (may be updated)
6
- * @property {number} expiresAt - Unix timestamp in seconds when token expires
7
- */
8
- /**
9
- * @typedef {Object} YotoClientConstructorOptions
10
- * @property {string} clientId - OAuth client ID
11
- * @property {string} refreshToken - OAuth refresh token
12
- * @property {string} accessToken - Initial OAuth access token (JWT)
13
- * @property {(event: RefreshSuccessEvent) => void | Promise<void>} onTokenRefresh - **REQUIRED** Callback invoked when tokens are refreshed. You MUST persist these tokens (to file, database, etc.) as the refresh can happen at any time during API calls. The refresh token may be rotated by the auth server. **DO NOT STUB THIS CALLBACK** - always implement proper persistence logic.
14
- * @property {number} [bufferSeconds=30] - Seconds before expiration to consider token expired
15
- * @property {() => void | Promise<void>} [onRefreshStart] - Optional callback invoked when token refresh starts. Defaults to console.log.
16
- * @property {(error: Error) => void | Promise<void>} [onRefreshError] - Optional callback invoked when token refresh fails with a transient error. Defaults to console.warn.
17
- * @property {(error: Error) => void | Promise<void>} [onInvalid] - Optional callback invoked when refresh token is permanently invalid. Defaults to console.error.
18
- * @property {string} [userAgent] - Optional user agent string to identify your application
19
- * @property {RequestOptions} [defaultRequestOptions] - Default undici request options for all requests (dispatcher, timeouts, etc.)
20
- */
21
- /**
22
- * Yoto API Client with automatic token refresh
23
- */
24
- export class YotoClient {
25
- /**
26
- * Get authorization URL for browser-based OAuth flow
27
- * @see https://yoto.dev/api/get-authorize/
28
- * @param {object} params
29
- * @param {string} params.clientId - OAuth client ID
30
- * @param {string} params.redirectUri - Redirect URI after authorization
31
- * @param {'code' | 'token' | 'id_token' | 'code token' | 'code id_token' | 'token id_token' | 'code token id_token'} params.responseType - OAuth response type
32
- * @param {string} params.state - State parameter for CSRF protection
33
- * @param {string} [params.audience] - Audience for the token
34
- * @param {string} [params.scope] - Requested scopes
35
- * @param {string} [params.nonce] - Nonce for replay attack prevention
36
- * @param {'none' | 'login' | 'consent' | 'select_account'} [params.prompt] - Authorization prompt behavior
37
- * @param {number} [params.maxAge] - Maximum authentication age in seconds
38
- * @param {string} [params.codeChallenge] - PKCE code challenge
39
- * @param {'S256' | 'plain'} [params.codeChallengeMethod] - PKCE code challenge method
40
- * @returns {string} Authorization URL
41
- */
42
- static getAuthorizeUrl(params: {
43
- clientId: string;
44
- redirectUri: string;
45
- responseType: "code" | "token" | "id_token" | "code token" | "code id_token" | "token id_token" | "code token id_token";
46
- state: string;
47
- audience?: string | undefined;
48
- scope?: string | undefined;
49
- nonce?: string | undefined;
50
- prompt?: "none" | "login" | "consent" | "select_account" | undefined;
51
- maxAge?: number | undefined;
52
- codeChallenge?: string | undefined;
53
- codeChallengeMethod?: "S256" | "plain" | undefined;
54
- }): string;
55
- /**
56
- * Exchange authorization code or refresh token for access tokens
57
- * @see https://yoto.dev/api/post-oauth-token/
58
- * @param {object} params
59
- * @param {'authorization_code' | 'refresh_token' | 'client_credentials' | 'urn:ietf:params:oauth:grant-type:device_code'} params.grantType - OAuth grant type
60
- * @param {string} [params.code] - Authorization code (required for authorization_code grant)
61
- * @param {string} [params.redirectUri] - Redirect URI (required for authorization_code grant if used in authorize request)
62
- * @param {string} [params.refreshToken] - Refresh token (required for refresh_token grant)
63
- * @param {string} [params.clientId] - OAuth client ID
64
- * @param {string} [params.clientSecret] - OAuth client secret
65
- * @param {string} [params.scope] - Requested scope
66
- * @param {string} [params.codeVerifier] - PKCE code verifier
67
- * @param {string} [params.deviceCode] - Device code (required for device_code grant)
68
- * @param {string} [params.audience] - Audience for the token
69
- * @returns {Promise<YotoTokenResponse>}
70
- */
71
- static exchangeToken(params: {
72
- grantType: "authorization_code" | "refresh_token" | "client_credentials" | "urn:ietf:params:oauth:grant-type:device_code";
73
- code?: string | undefined;
74
- redirectUri?: string | undefined;
75
- refreshToken?: string | undefined;
76
- clientId?: string | undefined;
77
- clientSecret?: string | undefined;
78
- scope?: string | undefined;
79
- codeVerifier?: string | undefined;
80
- deviceCode?: string | undefined;
81
- audience?: string | undefined;
82
- }): Promise<Auth.YotoTokenResponse>;
83
- /**
84
- * Request device code for device authorization flow
85
- * @see https://yoto.dev/api/post-oauth-device-code/
86
- * @param {object} params
87
- * @param {string} params.clientId - OAuth client ID
88
- * @param {string} [params.scope] - Requested scopes
89
- * @param {string} [params.audience] - Audience for the token
90
- * @returns {Promise<YotoDeviceCodeResponse>}
91
- */
92
- static requestDeviceCode(params: {
93
- clientId: string;
94
- scope?: string | undefined;
95
- audience?: string | undefined;
96
- }): Promise<Auth.YotoDeviceCodeResponse>;
97
- /**
98
- * Create a new Yoto API client
99
- * @param {YotoClientConstructorOptions} options
100
- */
101
- constructor({ clientId, refreshToken, accessToken, onTokenRefresh, bufferSeconds, onRefreshStart, onRefreshError, onInvalid, userAgent, defaultRequestOptions }: YotoClientConstructorOptions);
102
- /**
103
- * Get the underlying RefreshableToken instance
104
- * @returns {RefreshableToken}
105
- */
106
- get token(): RefreshableToken;
107
- /**
108
- * Get content/card details
109
- * @see https://yoto.dev/api/getcontent/
110
- * @param {object} params
111
- * @param {string} params.cardId - The card/content ID
112
- * @param {string} [params.timezone] - Timezone for schedule-based content
113
- * @param {'full' | 'pre'} [params.signingType] - Type of URL signing
114
- * @param {boolean} [params.playable] - Whether to include playback URLs
115
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
116
- * @returns {Promise<YotoContentResponse>}
117
- */
118
- getContent({ cardId, timezone, signingType, playable, requestOptions }: {
119
- cardId: string;
120
- timezone?: string | undefined;
121
- signingType?: "full" | "pre" | undefined;
122
- playable?: boolean | undefined;
123
- requestOptions?: ({
124
- dispatcher?: import("undici").Dispatcher;
125
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
126
- }): Promise<Content.YotoContentResponse>;
127
- /**
128
- * Get user's MYO (Make Your Own) content
129
- * @see https://yoto.dev/api/getusersmyocontent/
130
- * @param {object} [params]
131
- * @param {boolean} [params.showDeleted=false] - Include deleted content
132
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
133
- * @returns {Promise<YotoMyoContentResponse>}
134
- */
135
- getUserMyoContent({ showDeleted, requestOptions }?: {
136
- showDeleted?: boolean | undefined;
137
- requestOptions?: ({
138
- dispatcher?: import("undici").Dispatcher;
139
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
140
- }): Promise<Content.YotoMyoContentResponse>;
141
- /**
142
- * Create or update content/card
143
- * @see https://yoto.dev/api/createorupdatecontent/
144
- * @param {object} params
145
- * @param {YotoCreateOrUpdateContentRequest} params.content - Content data to create/update
146
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
147
- * @returns {Promise<YotoCreateOrUpdateContentResponse>}
148
- */
149
- createOrUpdateContent({ content, requestOptions }: {
150
- content: Content.YotoCreateOrUpdateContentRequest;
151
- requestOptions?: ({
152
- dispatcher?: import("undici").Dispatcher;
153
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
154
- }): Promise<Content.YotoCreateOrUpdateContentResponse>;
155
- /**
156
- * Delete content/card
157
- * @see https://yoto.dev/api/deletecontent/
158
- * @param {object} params
159
- * @param {string} params.cardId - The card/content ID to delete
160
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
161
- * @returns {Promise<YotoDeleteContentResponse>}
162
- */
163
- deleteContent({ cardId, requestOptions }: {
164
- cardId: string;
165
- requestOptions?: ({
166
- dispatcher?: import("undici").Dispatcher;
167
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
168
- }): Promise<Content.YotoDeleteContentResponse>;
169
- /**
170
- * Get all devices for authenticated user
171
- * @see https://yoto.dev/api/getdevices/
172
- * @param {object} [params]
173
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
174
- * @returns {Promise<YotoDevicesResponse>}
175
- */
176
- getDevices({ requestOptions }?: {
177
- requestOptions?: ({
178
- dispatcher?: import("undici").Dispatcher;
179
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
180
- }): Promise<Devices.YotoDevicesResponse>;
181
- /**
182
- * Get device status
183
- * @see https://yoto.dev/api/getdevicestatus/
184
- * @param {object} params
185
- * @param {string} params.deviceId - Device ID
186
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
187
- * @returns {Promise<YotoDeviceStatusResponse>}
188
- */
189
- getDeviceStatus({ deviceId, requestOptions }: {
190
- deviceId: string;
191
- requestOptions?: ({
192
- dispatcher?: import("undici").Dispatcher;
193
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
194
- }): Promise<Devices.YotoDeviceStatusResponse>;
195
- /**
196
- * Get device configuration
197
- * @see https://yoto.dev/api/getdeviceconfig/
198
- * @param {object} params
199
- * @param {string} params.deviceId - Device ID
200
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
201
- * @returns {Promise<YotoDeviceConfigResponse>}
202
- */
203
- getDeviceConfig({ deviceId, requestOptions }: {
204
- deviceId: string;
205
- requestOptions?: ({
206
- dispatcher?: import("undici").Dispatcher;
207
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
208
- }): Promise<Devices.YotoDeviceConfigResponse>;
209
- /**
210
- * Update device configuration
211
- * @see https://yoto.dev/api/updatedeviceconfig/
212
- * @param {object} params
213
- * @param {string} params.deviceId - Device ID
214
- * @param {YotoUpdateDeviceConfigRequest} params.configUpdate - Config updates
215
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
216
- * @returns {Promise<YotoUpdateDeviceConfigResponse>}
217
- */
218
- updateDeviceConfig({ deviceId, configUpdate, requestOptions }: {
219
- deviceId: string;
220
- configUpdate: Devices.YotoUpdateDeviceConfigRequest;
221
- requestOptions?: ({
222
- dispatcher?: import("undici").Dispatcher;
223
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
224
- }): Promise<Devices.YotoUpdateDeviceConfigResponse>;
225
- /**
226
- * Update device shortcuts
227
- * @see https://yoto.dev/api/updateshortcutsbeta/
228
- * @param {object} params
229
- * @param {string} params.deviceId - Device ID
230
- * @param {YotoUpdateShortcutsRequest} params.shortcutsUpdate - Shortcuts config
231
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
232
- * @returns {Promise<YotoUpdateShortcutsResponse>}
233
- */
234
- updateDeviceShortcuts({ deviceId, shortcutsUpdate, requestOptions }: {
235
- deviceId: string;
236
- shortcutsUpdate: Devices.YotoUpdateShortcutsRequest;
237
- requestOptions?: ({
238
- dispatcher?: import("undici").Dispatcher;
239
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
240
- }): Promise<Devices.YotoUpdateShortcutsResponse>;
241
- /**
242
- * Send command to device
243
- * @see https://yoto.dev/api/senddevicecommand/
244
- * @see https://yoto.dev/players-mqtt/mqtt-docs/
245
- * @param {object} params
246
- * @param {string} params.deviceId - Device ID
247
- * @param {YotoDeviceCommand} params.command - Command to send
248
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
249
- * @returns {Promise<YotoDeviceCommandResponse>}
250
- */
251
- sendDeviceCommand({ deviceId, command, requestOptions }: {
252
- deviceId: string;
253
- command: Devices.YotoDeviceCommand;
254
- requestOptions?: ({
255
- dispatcher?: import("undici").Dispatcher;
256
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
257
- }): Promise<Devices.YotoDeviceCommandResponse>;
258
- /**
259
- * Get all family library groups
260
- * @see https://yoto.dev/api/getgroups/
261
- * @param {object} [params]
262
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
263
- * @returns {Promise<YotoGroup[]>}
264
- */
265
- getGroups({ requestOptions }?: {
266
- requestOptions?: ({
267
- dispatcher?: import("undici").Dispatcher;
268
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
269
- }): Promise<FamilyLibraryGroups.YotoGroup[]>;
270
- /**
271
- * Create a family library group
272
- * @see https://yoto.dev/api/createagroup/
273
- * @param {object} params
274
- * @param {YotoCreateGroupRequest} params.group - Group data
275
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
276
- * @returns {Promise<YotoGroup>}
277
- */
278
- createGroup({ group, requestOptions }: {
279
- group: FamilyLibraryGroups.YotoCreateGroupRequest;
280
- requestOptions?: ({
281
- dispatcher?: import("undici").Dispatcher;
282
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
283
- }): Promise<FamilyLibraryGroups.YotoGroup>;
284
- /**
285
- * Get a specific family library group
286
- * @see https://yoto.dev/api/getgroup/
287
- * @param {object} params
288
- * @param {string} params.groupId - Group ID
289
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
290
- * @returns {Promise<YotoGroup>}
291
- */
292
- getGroup({ groupId, requestOptions }: {
293
- groupId: string;
294
- requestOptions?: ({
295
- dispatcher?: import("undici").Dispatcher;
296
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
297
- }): Promise<FamilyLibraryGroups.YotoGroup>;
298
- /**
299
- * Update a family library group
300
- * @see https://yoto.dev/api/updateagroup/
301
- * @param {object} params
302
- * @param {string} params.groupId - Group ID
303
- * @param {YotoUpdateGroupRequest} params.group - Updated group data
304
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
305
- * @returns {Promise<YotoGroup>}
306
- */
307
- updateGroup({ groupId, group, requestOptions }: {
308
- groupId: string;
309
- group: FamilyLibraryGroups.YotoUpdateGroupRequest;
310
- requestOptions?: ({
311
- dispatcher?: import("undici").Dispatcher;
312
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
313
- }): Promise<FamilyLibraryGroups.YotoGroup>;
314
- /**
315
- * Delete a family library group
316
- * @see https://yoto.dev/api/deleteagroup/
317
- * @param {object} params
318
- * @param {string} params.groupId - Group ID
319
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
320
- * @returns {Promise<YotoDeleteGroupResponse>}
321
- */
322
- deleteGroup({ groupId, requestOptions }: {
323
- groupId: string;
324
- requestOptions?: ({
325
- dispatcher?: import("undici").Dispatcher;
326
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
327
- }): Promise<FamilyLibraryGroups.YotoDeleteGroupResponse>;
328
- /**
329
- * Get all family images
330
- * @see https://yoto.dev/api/getfamilyimages/
331
- * @param {object} [params]
332
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
333
- * @returns {Promise<YotoFamilyImagesResponse>}
334
- */
335
- getFamilyImages({ requestOptions }?: {
336
- requestOptions?: ({
337
- dispatcher?: import("undici").Dispatcher;
338
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
339
- }): Promise<Family.YotoFamilyImagesResponse>;
340
- /**
341
- * Get a specific family image
342
- * @see https://yoto.dev/api/getafamilyimage/
343
- * @param {object} params
344
- * @param {string} params.imageId - Image ID
345
- * @param {'640x480' | '320x320'} params.size - Image size
346
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
347
- * @returns {Promise<YotoFamilyImageResponse>}
348
- */
349
- getAFamilyImage({ imageId, size, requestOptions }: {
350
- imageId: string;
351
- size: "640x480" | "320x320";
352
- requestOptions?: ({
353
- dispatcher?: import("undici").Dispatcher;
354
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
355
- }): Promise<Family.YotoFamilyImageResponse>;
356
- /**
357
- * Upload a family image
358
- * @see https://yoto.dev/api/uploadafamilyimage/
359
- * @param {object} params
360
- * @param {Buffer} params.imageData - Image binary data
361
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
362
- * @returns {Promise<YotoUploadFamilyImageResponse>}
363
- */
364
- uploadAFamilyImage({ imageData, requestOptions }: {
365
- imageData: Buffer;
366
- requestOptions?: ({
367
- dispatcher?: import("undici").Dispatcher;
368
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
369
- }): Promise<Family.YotoUploadFamilyImageResponse>;
370
- /**
371
- * Get public Yoto icons
372
- * @see https://yoto.dev/api/getpublicicons/
373
- * @param {object} [params]
374
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
375
- * @returns {Promise<YotoPublicIconsResponse>}
376
- */
377
- getPublicIcons({ requestOptions }?: {
378
- requestOptions?: ({
379
- dispatcher?: import("undici").Dispatcher;
380
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
381
- }): Promise<Icons.YotoPublicIconsResponse>;
382
- /**
383
- * Get user's custom icons
384
- * @see https://yoto.dev/api/getusericons/
385
- * @param {object} [params]
386
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
387
- * @returns {Promise<YotoUserIconsResponse>}
388
- */
389
- getUserIcons({ requestOptions }?: {
390
- requestOptions?: ({
391
- dispatcher?: import("undici").Dispatcher;
392
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
393
- }): Promise<Icons.YotoUserIconsResponse>;
394
- /**
395
- * Upload a custom icon
396
- * @see https://yoto.dev/api/uploadicon/
397
- * @param {object} params
398
- * @param {Buffer} params.imageData - Image binary data
399
- * @param {boolean} [params.autoConvert=true] - Auto-convert to proper format
400
- * @param {string} [params.filename] - Optional filename
401
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
402
- * @returns {Promise<YotoUploadIconResponse>}
403
- */
404
- uploadIcon({ imageData, autoConvert, filename, requestOptions }: {
405
- imageData: Buffer;
406
- autoConvert?: boolean | undefined;
407
- filename?: string | undefined;
408
- requestOptions?: ({
409
- dispatcher?: import("undici").Dispatcher;
410
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
411
- }): Promise<Icons.YotoUploadIconResponse>;
412
- /**
413
- * Get audio upload URL
414
- * @see https://yoto.dev/api/getaudiouploadurl/
415
- * @param {object} params
416
- * @param {string} params.sha256 - SHA256 hash of audio file
417
- * @param {string} [params.filename] - Optional filename
418
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
419
- * @returns {Promise<YotoAudioUploadUrlResponse>}
420
- */
421
- getAudioUploadUrl({ sha256, filename, requestOptions }: {
422
- sha256: string;
423
- filename?: string | undefined;
424
- requestOptions?: ({
425
- dispatcher?: import("undici").Dispatcher;
426
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
427
- }): Promise<Media.YotoAudioUploadUrlResponse>;
428
- /**
429
- * Upload a cover image
430
- * @see https://yoto.dev/api/uploadcoverimage/
431
- * @param {object} params
432
- * @param {Buffer} [params.imageData] - Image binary data
433
- * @param {string} [params.imageUrl] - URL to image
434
- * @param {boolean} [params.autoConvert] - Auto-convert to proper format
435
- * @param {YotoCoverType} [params.coverType] - Cover image type
436
- * @param {string} [params.filename] - Optional filename
437
- * @param {RequestOptions} [params.requestOptions] - Request options that override defaults
438
- * @returns {Promise<YotoUploadCoverImageResponse>}
439
- */
440
- uploadCoverImage({ imageData, imageUrl, autoConvert, coverType, filename, requestOptions }: {
441
- imageData?: Buffer<ArrayBufferLike> | undefined;
442
- imageUrl?: string | undefined;
443
- autoConvert?: boolean | undefined;
444
- coverType?: Media.YotoCoverType | undefined;
445
- filename?: string | undefined;
446
- requestOptions?: ({
447
- dispatcher?: import("undici").Dispatcher;
448
- } & Omit<import("undici").Dispatcher.RequestOptions<unknown>, "origin" | "path" | "method"> & Partial<Pick<import("undici").Dispatcher.RequestOptions<null>, "method">>) | undefined;
449
- }): Promise<Media.YotoUploadCoverImageResponse>;
450
- /**
451
- * Create an MQTT client for a specific device
452
- *
453
- * The MQTT client provides real-time communication with Yoto devices:
454
- * - Subscribe to device events (playback, volume, card changes)
455
- * - Subscribe to device status (battery, temperature, network)
456
- * - Send commands (volume, card playback, ambient lights, etc.)
457
- *
458
- * @see https://yoto.dev/players-mqtt/
459
- * @param {object} params
460
- * @param {string} params.deviceId - The device ID to connect to
461
- * @param {object} [params.options] - MQTT client options
462
- * @param {boolean} [params.options.autoSubscribe=true] - Auto-subscribe to device topics on connect
463
- * @returns {Promise<YotoMqttClient>} MQTT client instance
464
- *
465
- * @example
466
- * // Create YotoClient with token refresh callback
467
- * const client = new YotoClient({
468
- * clientId: 'your-client-id',
469
- * refreshToken: 'your-refresh-token',
470
- * accessToken: 'your-access-token',
471
- * onTokenRefresh: async (event) => {
472
- * // Save tokens to file/database
473
- * await saveTokens(event.accessToken, event.refreshToken)
474
- * }
475
- * })
476
- *
477
- * // Get an online device
478
- * const devices = await client.getDevices()
479
- * const device = devices.devices.find(d => d.online)
480
- *
481
- * // Create MQTT client for the device
482
- * const mqttClient = await client.createMqttClient({ deviceId: device.deviceId })
483
- *
484
- * // Setup event handlers
485
- * mqttClient.on('events', (message) => {
486
- * console.log('Playback event:', message.playbackStatus)
487
- * console.log('Volume:', message.volume)
488
- * })
489
- *
490
- * mqttClient.on('status', (message) => {
491
- * console.log('Battery:', message.status.batteryLevel)
492
- * console.log('Temperature:', message.status.temp)
493
- * })
494
- *
495
- * mqttClient.on('response', (message) => {
496
- * console.log('Command acknowledged:', message.status)
497
- * })
498
- *
499
- * // Connect and send commands
500
- * await mqttClient.connect()
501
- * await mqttClient.requestStatus()
502
- * await mqttClient.setVolume(50)
503
- * await mqttClient.startCard({ uri: 'https://yoto.io/cardId123' })
504
- *
505
- * // Cleanup
506
- * await mqttClient.disconnect()
507
- */
508
- createMqttClient({ deviceId, options }: {
509
- deviceId: string;
510
- options?: {
511
- autoSubscribe?: boolean | undefined;
512
- } | undefined;
513
- }): Promise<YotoMqttClient>;
514
- #private;
515
- }
516
- export type RefreshSuccessEvent = {
517
- /**
518
- * - The OAuth client ID
519
- */
520
- clientId: string;
521
- /**
522
- * - The new access token
523
- */
524
- accessToken: string;
525
- /**
526
- * - The refresh token (may be updated)
527
- */
528
- refreshToken: string;
529
- /**
530
- * - Unix timestamp in seconds when token expires
531
- */
532
- expiresAt: number;
533
- };
534
- export type YotoClientConstructorOptions = {
535
- /**
536
- * - OAuth client ID
537
- */
538
- clientId: string;
539
- /**
540
- * - OAuth refresh token
541
- */
542
- refreshToken: string;
543
- /**
544
- * - Initial OAuth access token (JWT)
545
- */
546
- accessToken: string;
547
- /**
548
- * - **REQUIRED** Callback invoked when tokens are refreshed. You MUST persist these tokens (to file, database, etc.) as the refresh can happen at any time during API calls. The refresh token may be rotated by the auth server. **DO NOT STUB THIS CALLBACK** - always implement proper persistence logic.
549
- */
550
- onTokenRefresh: (event: RefreshSuccessEvent) => void | Promise<void>;
551
- /**
552
- * - Seconds before expiration to consider token expired
553
- */
554
- bufferSeconds?: number;
555
- /**
556
- * - Optional callback invoked when token refresh starts. Defaults to console.log.
557
- */
558
- onRefreshStart?: () => void | Promise<void>;
559
- /**
560
- * - Optional callback invoked when token refresh fails with a transient error. Defaults to console.warn.
561
- */
562
- onRefreshError?: (error: Error) => void | Promise<void>;
563
- /**
564
- * - Optional callback invoked when refresh token is permanently invalid. Defaults to console.error.
565
- */
566
- onInvalid?: (error: Error) => void | Promise<void>;
567
- /**
568
- * - Optional user agent string to identify your application
569
- */
570
- userAgent?: string;
571
- /**
572
- * - Default undici request options for all requests (dispatcher, timeouts, etc.)
573
- */
574
- defaultRequestOptions?: RequestOptions;
575
- };
576
- import { RefreshableToken } from './lib/token.js';
577
- import * as Content from './lib/api-endpoints/content.js';
578
- import * as Devices from './lib/api-endpoints/devices.js';
579
- import * as FamilyLibraryGroups from './lib/api-endpoints/family-library-groups.js';
580
- import * as Family from './lib/api-endpoints/family.js';
581
- import * as Icons from './lib/api-endpoints/icons.js';
582
- import * as Media from './lib/api-endpoints/media.js';
583
- import type { YotoMqttClient } from './lib/mqtt/client.js';
584
- import * as Auth from './lib/api-endpoints/auth.js';
585
- import type { RequestOptions } from './lib/api-endpoints/helpers.js';
1
+ export { YotoClient } from "./lib/api-client.js";
2
+ export { YotoDeviceModel } from "./lib/yoto-device.js";
3
+ export { YotoAccount } from "./lib/yoto-account.js";
4
+ export { DEFAULT_CLIENT_ID, DEFAULT_AUDIENCE, DEFAULT_SCOPE, DEVICE_CODE_GRANT_TYPE } from "./lib/api-endpoints/constants.js";
586
5
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],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