odesli.js 1.1.1 → 1.3.1

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/lib/index.d.ts CHANGED
@@ -1,484 +1,663 @@
1
- // Type definitions for odesli.js
2
- // Project: https://github.com/MattrAus/odesli.js, https://www.npmjs.com/package/odesli.js
3
- // Definitions by: Mattr <https://github.com/MattrAus>
4
- // TypeScript Version: 2.7
5
-
6
- declare class Odesli {
7
- /**
8
- *
9
- * @param {string=} apiKey Limited to 10 Requests per Minute without an API Key.
10
- *
11
- * Email `developers@song.link` to get an API Key.
12
- *
13
- * @param {string=} version Defaults to `v1-alpha.1`
14
- */
15
- constructor(options?: {
16
- /**
17
- * @param {string=} apiKey Optional: Limited to 10 Requests per Minute without an API Key.
18
- *
19
- * Email `developers@song.link` to get an API Key.
20
- */
21
- apiKey?: string
22
- /**
23
- * @param {string=} version Optional: Defaults to `v1-alpha.1`
24
- */
25
- version?: 'v1-alpha.1' | string
26
- });
27
-
28
- /**
29
- *
30
- * @param {string} url Streaming service URL
31
- * @param {CountryCode} [country='US'] Optional: [ISO 3166-1 Alpha-2 Code](https://www.iso.org/obp/ui/#search/code/)
32
- * @returns Promise<Page.Response>
33
- */
34
- fetch(url: string, country?: CountryCode | 'US'): Promise<Page.Response>;
35
-
36
- /**
37
- *
38
- * @param {Platform} platform Streaming service
39
- * @param {entityType} type Type: song or album
40
- * @param {string} id Type: song or album
41
- * @param {CountryCode} [country='US'] Optional: [ISO 3166-1 Alpha-2 Code](https://www.iso.org/obp/ui/#search/code/)
42
- * @returns Promise<Page.Response>
43
- */
44
- getByParams(platform: string, type: entityType, id: string, country?: CountryCode): Promise<Page.Response>;
45
-
46
- /**
47
- *
48
- * @param url Streaming service URL
49
- * @param {CountryCode} [country='US'] Optional: [ISO 3166-1 Alpha-2 Code](https://www.iso.org/obp/ui/#search/code/)
50
- * @returns Promise<Page.Response>
51
- */
52
- getById(id: string, country?: CountryCode): Promise<Page.Response>;
53
- }
54
-
55
- declare namespace Page {
56
- interface Response {
57
- /**
58
- * The unique ID for the input entity that was supplied in the request.
59
- *
60
- * The data for this entity, such as title, artistName, etc. will be found in an object at `entitiesByUniqueId[entityUniqueId]`
61
- */
62
- entityUniqueId: string,
63
-
64
- /**
65
- * Song/Album Title of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].title`
66
- */
67
- title: string,
68
-
69
- /**
70
- * Artist's Name of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].artistName`
71
- */
72
- artist: string,
73
-
74
- /**
75
- * Type (song or album) of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].type`
76
- */
77
- type: entityType,
78
-
79
- /**
80
- * Thumbnail of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].thumbnailUrl`
81
- */
82
- thumbnail: string,
83
-
84
- /**
85
- * The userCountry query param that was supplied in the request. It signals
86
- * the country/availability we use to query the streaming platforms. Defaults
87
- * to 'US' if no userCountry supplied in the request.
88
- *
89
- * NOTE: As a fallback, our service may respond with matches that were found
90
- * in a locale other than the userCountry supplied
91
- */
92
- userCountry: CountryCode,
93
-
94
- /**
95
- * A URL that will render the Songlink page for this entity
96
- */
97
- pageUrl: string,
98
-
99
- /**
100
- * A collection of objects. Each key is a platform, and each value is an
101
- * object that contains data for linking to the match
102
- */
103
- linksByPlatform: {
104
- /**
105
- * Each key in `linksByPlatform` is a Platform. A Platform will exist here
106
- * only if there is a match found. E.g. if there is no YouTube match found,
107
- * then neither `youtube` or `youtubeMusic` properties will exist here
108
- */
109
- [key in Platform]: {
110
- /**
111
- * The unique ID for this entity. Use it to look up data about this entity
112
- * at `entitiesByUniqueId[entityUniqueId]`
113
- */
114
- entityUniqueId: string,
115
-
116
- /**
117
- * The URL for this match
118
- */
119
- url: string,
120
-
121
- /**
122
- * The native app URI that can be used on mobile devices to open this
123
- * entity directly in the native app
124
- */
125
- nativeAppUriMobile?: string,
126
-
127
- /**
128
- * The native app URI that can be used on desktop devices to open this
129
- * entity directly in the native app
130
- */
131
- nativeAppUriDesktop?: string,
132
- };
133
- },
134
-
135
- /**
136
- * A collection of objects. Each key is a unique identifier for a streaming
137
- * entity, and each value is an object that contains data for that entity,
138
- * such as `title`, `artistName`, `thumbnailUrl`, etc.
139
- */
140
- entitiesByUniqueId: {
141
- /**
142
- * The unique identifier key for a streaming entitiy
143
- */
144
- [entityUniqueId: string]: {
145
- /**
146
- * This is the unique identifier on the streaming platform/API provider
147
- */
148
- id: string,
149
-
150
- /**
151
- * The type of media this entity is
152
- */
153
- type: entityType,
154
-
155
- /**
156
- * The title of the `song`/`album`
157
- */
158
- title?: string,
159
-
160
- /**
161
- * The artist/s of the `song`/`album`
162
- */
163
- artistName?: [string],
164
-
165
- /**
166
- * The coverart image URL of the `song`/`album`
167
- */
168
- thumbnailUrl?: string,
169
-
170
- /**
171
- * Coverart's width
172
- */
173
- thumbnailWidth?: number,
174
- /**
175
- * Coverart's height
176
- */
177
- thumbnailHeight?: number,
178
-
179
- /**
180
- * The API provider that powered this match. Useful if you'd like to use
181
- * this entity's data to query the API directly
182
- */
183
- apiProvider: APIProvider,
184
-
185
- /**
186
- * An array of platforms that are "powered" by this entity. E.g. an entity
187
- * from Apple Music will generally have a `platforms` array of
188
- * `["appleMusic", "itunes"]` since both those platforms/links are derived
189
- * from this single entity
190
- */
191
- platforms: Platform[],
192
- },
193
- },
194
- }
195
- }
196
-
197
- type Platform =
198
- | 'spotify'
199
- | 'itunes'
200
- | 'appleMusic'
201
- | 'youtube'
202
- | 'youtubeMusic'
203
- | 'google'
204
- | 'googleStore'
205
- | 'pandora'
206
- | 'deezer'
207
- | 'tidal'
208
- | 'amazonStore'
209
- | 'amazonMusic'
210
- | 'soundcloud'
211
- | 'napster'
212
- | 'yandex'
213
- | 'spinrilla';
214
-
215
- type APIProvider =
216
- | 'spotify'
217
- | 'itunes'
218
- | 'youtube'
219
- | 'google'
220
- | 'pandora'
221
- | 'deezer'
222
- | 'tidal'
223
- | 'amazon'
224
- | 'soundcloud'
225
- | 'napster'
226
- | 'yandex'
227
- | 'spinrilla';
228
-
229
- type entityType =
230
- | 'song'
231
- | 'album'
232
-
233
- declare enum CountryCode {
234
- Afghanistan = 'AF',
235
- AlandIslands = 'AX',
236
- Albania = 'AL',
237
- Algeria = 'DZ',
238
- AmericanSamoa = 'AS',
239
- Andorra = 'AD',
240
- Angola = 'AO',
241
- Anguilla = 'AI',
242
- Antarctica = 'AQ',
243
- AntiguaAndBarbuda = 'AG',
244
- Argentina = 'AR',
245
- Armenia = 'AM',
246
- Aruba = 'AW',
247
- Australia = 'AU',
248
- Austria = 'AT',
249
- Azerbaijan = 'AZ',
250
- Bahamas = 'BS',
251
- Bahrain = 'BH',
252
- Bangladesh = 'BD',
253
- Barbados = 'BB',
254
- Belarus = 'BY',
255
- Belgium = 'BE',
256
- Belize = 'BZ',
257
- Benin = 'BJ',
258
- Bermuda = 'BM',
259
- Bhutan = 'BT',
260
- Bolivia = 'BO',
261
- BonaireSintEustatiusSaba = 'BQ',
262
- BosniaAndHerzegovina = 'BA',
263
- Botswana = 'BW',
264
- BouvetIsland = 'BV',
265
- Brazil = 'BR',
266
- BritishIndianOceanTerritory = 'IO',
267
- BruneiDarussalam = 'BN',
268
- Bulgaria = 'BG',
269
- BurkinaFaso = 'BF',
270
- Burundi = 'BI',
271
- Cambodia = 'KH',
272
- Cameroon = 'CM',
273
- Canada = 'CA',
274
- CapeVerde = 'CV',
275
- CaymanIslands = 'KY',
276
- CentralAfricanRepublic = 'CF',
277
- Chad = 'TD',
278
- Chile = 'CL',
279
- China = 'CN',
280
- ChristmasIsland = 'CX',
281
- CocosKeelingIslands = 'CC',
282
- Colombia = 'CO',
283
- Comoros = 'KM',
284
- Congo = 'CG',
285
- CongoDemocraticRepublic = 'CD',
286
- CookIslands = 'CK',
287
- CostaRica = 'CR',
288
- CoteDIvoire = 'CI',
289
- Croatia = 'HR',
290
- Cuba = 'CU',
291
- Curaçao = 'CW',
292
- Cyprus = 'CY',
293
- CzechRepublic = 'CZ',
294
- Denmark = 'DK',
295
- Djibouti = 'DJ',
296
- Dominica = 'DM',
297
- DominicanRepublic = 'DO',
298
- Ecuador = 'EC',
299
- Egypt = 'EG',
300
- ElSalvador = 'SV',
301
- EquatorialGuinea = 'GQ',
302
- Eritrea = 'ER',
303
- Estonia = 'EE',
304
- Ethiopia = 'ET',
305
- FalklandIslands = 'FK',
306
- FaroeIslands = 'FO',
307
- Fiji = 'FJ',
308
- Finland = 'FI',
309
- France = 'FR',
310
- FrenchGuiana = 'GF',
311
- FrenchPolynesia = 'PF',
312
- FrenchSouthernTerritories = 'TF',
313
- Gabon = 'GA',
314
- Gambia = 'GM',
315
- Georgia = 'GE',
316
- Germany = 'DE',
317
- Ghana = 'GH',
318
- Gibraltar = 'GI',
319
- Greece = 'GR',
320
- Greenland = 'GL',
321
- Grenada = 'GD',
322
- Guadeloupe = 'GP',
323
- Guam = 'GU',
324
- Guatemala = 'GT',
325
- Guernsey = 'GG',
326
- Guinea = 'GN',
327
- GuineaBissau = 'GW',
328
- Guyana = 'GY',
329
- Haiti = 'HT',
330
- HeardIslandMcdonaldIslands = 'HM',
331
- HolySeeVaticanCityState = 'VA',
332
- Honduras = 'HN',
333
- HongKong = 'HK',
334
- Hungary = 'HU',
335
- Iceland = 'IS',
336
- India = 'IN',
337
- Indonesia = 'ID',
338
- Iran = 'IR',
339
- Iraq = 'IQ',
340
- Ireland = 'IE',
341
- IsleOfMan = 'IM',
342
- Israel = 'IL',
343
- Italy = 'IT',
344
- Jamaica = 'JM',
345
- Japan = 'JP',
346
- Jersey = 'JE',
347
- Jordan = 'JO',
348
- Kazakhstan = 'KZ',
349
- Kenya = 'KE',
350
- Kiribati = 'KI',
351
- Korea = 'KR',
352
- KoreaDemocraticPeoplesRepublic = 'KP',
353
- Kuwait = 'KW',
354
- Kyrgyzstan = 'KG',
355
- LaoPeoplesDemocraticRepublic = 'LA',
356
- Latvia = 'LV',
357
- Lebanon = 'LB',
358
- Lesotho = 'LS',
359
- Liberia = 'LR',
360
- LibyanArabJamahiriya = 'LY',
361
- Liechtenstein = 'LI',
362
- Lithuania = 'LT',
363
- Luxembourg = 'LU',
364
- Macao = 'MO',
365
- Macedonia = 'MK',
366
- Madagascar = 'MG',
367
- Malawi = 'MW',
368
- Malaysia = 'MY',
369
- Maldives = 'MV',
370
- Mali = 'ML',
371
- Malta = 'MT',
372
- MarshallIslands = 'MH',
373
- Martinique = 'MQ',
374
- Mauritania = 'MR',
375
- Mauritius = 'MU',
376
- Mayotte = 'YT',
377
- Mexico = 'MX',
378
- Micronesia = 'FM',
379
- Moldova = 'MD',
380
- Monaco = 'MC',
381
- Mongolia = 'MN',
382
- Montenegro = 'ME',
383
- Montserrat = 'MS',
384
- Morocco = 'MA',
385
- Mozambique = 'MZ',
386
- Myanmar = 'MM',
387
- Namibia = 'NA',
388
- Nauru = 'NR',
389
- Nepal = 'NP',
390
- Netherlands = 'NL',
391
- NewCaledonia = 'NC',
392
- NewZealand = 'NZ',
393
- Nicaragua = 'NI',
394
- Niger = 'NE',
395
- Nigeria = 'NG',
396
- Niue = 'NU',
397
- NorfolkIsland = 'NF',
398
- NorthernMarianaIslands = 'MP',
399
- Norway = 'NO',
400
- Oman = 'OM',
401
- Pakistan = 'PK',
402
- Palau = 'PW',
403
- PalestinianTerritory = 'PS',
404
- Panama = 'PA',
405
- PapuaNewGuinea = 'PG',
406
- Paraguay = 'PY',
407
- Peru = 'PE',
408
- Philippines = 'PH',
409
- Pitcairn = 'PN',
410
- Poland = 'PL',
411
- Portugal = 'PT',
412
- PuertoRico = 'PR',
413
- Qatar = 'QA',
414
- Reunion = 'RE',
415
- Romania = 'RO',
416
- RussianFederation = 'RU',
417
- Rwanda = 'RW',
418
- SaintBarthelemy = 'BL',
419
- SaintHelena = 'SH',
420
- SaintKittsAndNevis = 'KN',
421
- SaintLucia = 'LC',
422
- SaintMartin = 'MF',
423
- SaintPierreAndMiquelon = 'PM',
424
- SaintVincentAndGrenadines = 'VC',
425
- Samoa = 'WS',
426
- SanMarino = 'SM',
427
- SaoTomeAndPrincipe = 'ST',
428
- SaudiArabia = 'SA',
429
- Senegal = 'SN',
430
- Serbia = 'RS',
431
- Seychelles = 'SC',
432
- SierraLeone = 'SL',
433
- Singapore = 'SG',
434
- SintMaarten = 'SX',
435
- Slovakia = 'SK',
436
- Slovenia = 'SI',
437
- SolomonIslands = 'SB',
438
- Somalia = 'SO',
439
- SouthAfrica = 'ZA',
440
- SouthGeorgiaAndSandwichIsl = 'GS',
441
- SouthSudan = 'SS',
442
- Spain = 'ES',
443
- SriLanka = 'LK',
444
- Sudan = 'SD',
445
- Suriname = 'SR',
446
- SvalbardAndJanMayen = 'SJ',
447
- Swaziland = 'SZ',
448
- Sweden = 'SE',
449
- Switzerland = 'CH',
450
- SyrianArabRepublic = 'SY',
451
- Taiwan = 'TW',
452
- Tajikistan = 'TJ',
453
- Tanzania = 'TZ',
454
- Thailand = 'TH',
455
- TimorLeste = 'TL',
456
- Togo = 'TG',
457
- Tokelau = 'TK',
458
- Tonga = 'TO',
459
- TrinidadAndTobago = 'TT',
460
- Tunisia = 'TN',
461
- Turkey = 'TR',
462
- Turkmenistan = 'TM',
463
- TurksAndCaicosIslands = 'TC',
464
- Tuvalu = 'TV',
465
- Uganda = 'UG',
466
- Ukraine = 'UA',
467
- UnitedArabEmirates = 'AE',
468
- UnitedKingdom = 'GB',
469
- UnitedStates = 'US',
470
- UnitedStatesOutlyingIslands = 'UM',
471
- Uruguay = 'UY',
472
- Uzbekistan = 'UZ',
473
- Vanuatu = 'VU',
474
- Venezuela = 'VE',
475
- Vietnam = 'VN',
476
- VirginIslandsBritish = 'VG',
477
- VirginIslandsUS = 'VI',
478
- WallisAndFutuna = 'WF',
479
- WesternSahara = 'EH',
480
- Yemen = 'YE',
481
- Zambia = 'ZM',
482
- Zimbabwe = 'ZW',
483
- }
484
- export = Odesli;
1
+ // Type definitions for odesli.js
2
+ // Project: https://github.com/MattrAus/odesli.js, https://www.npmjs.com/package/odesli.js
3
+ // Definitions by: Mattr <https://github.com/MattrAus>
4
+ // TypeScript Version: 2.7
5
+
6
+ // Export the CountryCode type
7
+ type CountryCode =
8
+ | "AF"
9
+ | "AX"
10
+ | "AL"
11
+ | "DZ"
12
+ | "AS"
13
+ | "AD"
14
+ | "AO"
15
+ | "AI"
16
+ | "AQ"
17
+ | "AG"
18
+ | "AR"
19
+ | "AM"
20
+ | "AW"
21
+ | "AU"
22
+ | "AT"
23
+ | "AZ"
24
+ | "BS"
25
+ | "BH"
26
+ | "BD"
27
+ | "BB"
28
+ | "BY"
29
+ | "BE"
30
+ | "BZ"
31
+ | "BJ"
32
+ | "BM"
33
+ | "BT"
34
+ | "BO"
35
+ | "BQ"
36
+ | "BA"
37
+ | "BW"
38
+ | "BV"
39
+ | "BR"
40
+ | "IO"
41
+ | "BN"
42
+ | "BG"
43
+ | "BF"
44
+ | "BI"
45
+ | "KH"
46
+ | "CM"
47
+ | "CA"
48
+ | "CV"
49
+ | "KY"
50
+ | "CF"
51
+ | "TD"
52
+ | "CL"
53
+ | "CN"
54
+ | "CX"
55
+ | "CC"
56
+ | "CO"
57
+ | "KM"
58
+ | "CG"
59
+ | "CD"
60
+ | "CK"
61
+ | "CR"
62
+ | "CI"
63
+ | "HR"
64
+ | "CU"
65
+ | "CW"
66
+ | "CY"
67
+ | "CZ"
68
+ | "DK"
69
+ | "DJ"
70
+ | "DM"
71
+ | "DO"
72
+ | "EC"
73
+ | "EG"
74
+ | "SV"
75
+ | "GQ"
76
+ | "ER"
77
+ | "EE"
78
+ | "ET"
79
+ | "FK"
80
+ | "FO"
81
+ | "FJ"
82
+ | "FI"
83
+ | "FR"
84
+ | "GF"
85
+ | "PF"
86
+ | "TF"
87
+ | "GA"
88
+ | "GM"
89
+ | "GE"
90
+ | "DE"
91
+ | "GH"
92
+ | "GI"
93
+ | "GR"
94
+ | "GL"
95
+ | "GD"
96
+ | "GP"
97
+ | "GU"
98
+ | "GT"
99
+ | "GG"
100
+ | "GN"
101
+ | "GW"
102
+ | "GY"
103
+ | "HT"
104
+ | "HM"
105
+ | "VA"
106
+ | "HN"
107
+ | "HK"
108
+ | "HU"
109
+ | "IS"
110
+ | "IN"
111
+ | "ID"
112
+ | "IR"
113
+ | "IQ"
114
+ | "IE"
115
+ | "IM"
116
+ | "IL"
117
+ | "IT"
118
+ | "JM"
119
+ | "JP"
120
+ | "JE"
121
+ | "JO"
122
+ | "KZ"
123
+ | "KE"
124
+ | "KI"
125
+ | "KR"
126
+ | "KP"
127
+ | "KW"
128
+ | "KG"
129
+ | "LA"
130
+ | "LV"
131
+ | "LB"
132
+ | "LS"
133
+ | "LR"
134
+ | "LY"
135
+ | "LI"
136
+ | "LT"
137
+ | "LU"
138
+ | "MO"
139
+ | "MK"
140
+ | "MG"
141
+ | "MW"
142
+ | "MY"
143
+ | "MV"
144
+ | "ML"
145
+ | "MT"
146
+ | "MH"
147
+ | "MQ"
148
+ | "MR"
149
+ | "MU"
150
+ | "YT"
151
+ | "MX"
152
+ | "FM"
153
+ | "MD"
154
+ | "MC"
155
+ | "MN"
156
+ | "ME"
157
+ | "MS"
158
+ | "MA"
159
+ | "MZ"
160
+ | "MM"
161
+ | "NA"
162
+ | "NR"
163
+ | "NP"
164
+ | "NL"
165
+ | "NC"
166
+ | "NZ"
167
+ | "NI"
168
+ | "NE"
169
+ | "NG"
170
+ | "NU"
171
+ | "NF"
172
+ | "MP"
173
+ | "NO"
174
+ | "OM"
175
+ | "PK"
176
+ | "PW"
177
+ | "PS"
178
+ | "PA"
179
+ | "PG"
180
+ | "PY"
181
+ | "PE"
182
+ | "PH"
183
+ | "PN"
184
+ | "PL"
185
+ | "PT"
186
+ | "PR"
187
+ | "QA"
188
+ | "RE"
189
+ | "RO"
190
+ | "RU"
191
+ | "RW"
192
+ | "BL"
193
+ | "SH"
194
+ | "KN"
195
+ | "LC"
196
+ | "MF"
197
+ | "PM"
198
+ | "VC"
199
+ | "WS"
200
+ | "SM"
201
+ | "ST"
202
+ | "SA"
203
+ | "SN"
204
+ | "RS"
205
+ | "SC"
206
+ | "SL"
207
+ | "SG"
208
+ | "SX"
209
+ | "SK"
210
+ | "SI"
211
+ | "SB"
212
+ | "SO"
213
+ | "ZA"
214
+ | "GS"
215
+ | "SS"
216
+ | "ES"
217
+ | "LK"
218
+ | "SD"
219
+ | "SR"
220
+ | "SJ"
221
+ | "SZ"
222
+ | "SE"
223
+ | "CH"
224
+ | "SY"
225
+ | "TW"
226
+ | "TJ"
227
+ | "TZ"
228
+ | "TH"
229
+ | "TL"
230
+ | "TG"
231
+ | "TK"
232
+ | "TO"
233
+ | "TT"
234
+ | "TN"
235
+ | "TR"
236
+ | "TM"
237
+ | "TC"
238
+ | "TV"
239
+ | "UG"
240
+ | "UA"
241
+ | "AE"
242
+ | "GB"
243
+ | "US"
244
+ | "UM"
245
+ | "UY"
246
+ | "UZ"
247
+ | "VU"
248
+ | "VE"
249
+ | "VN"
250
+ | "VG"
251
+ | "VI"
252
+ | "WF"
253
+ | "EH"
254
+ | "YE"
255
+ | "ZM"
256
+ | "ZW";
257
+
258
+ // Core Odesli class
259
+ declare class Odesli {
260
+ constructor(options?: OdesliOptions);
261
+
262
+ // Core methods
263
+ fetch(urlOrUrls: string | string[], options?: FetchOptions): Promise<SongData | SongData[]>;
264
+ getByParams(platform: string, type: string, id: string, options?: FetchOptions): Promise<SongData>;
265
+ getById(id: string, options?: FetchOptions): Promise<SongData>;
266
+
267
+ // Utility methods
268
+ detectPlatform(url: string): string | null;
269
+ extractId(url: string): string | null;
270
+ getSupportedPlatforms(): string[];
271
+ getUserAgent(): string;
272
+
273
+ // Cache methods
274
+ clearCache(): void;
275
+ getCacheStats(): CacheStats;
276
+
277
+ // Static methods
278
+ static getCountryOptions(): Array<{ code: CountryCode; name: string }>;
279
+ }
280
+
281
+ // Configuration options
282
+ interface OdesliOptions {
283
+ apiKey?: string;
284
+ version?: string;
285
+ cache?: boolean;
286
+ timeout?: number;
287
+ maxRetries?: number;
288
+ retryDelay?: number;
289
+ headers?: Record<string, string>;
290
+ baseUrl?: string;
291
+ validateParams?: boolean;
292
+ logger?: (message: string, level: string) => void;
293
+ }
294
+
295
+ // Fetch options
296
+ interface FetchOptions {
297
+ country?: CountryCode;
298
+ skipCache?: boolean;
299
+ timeout?: number;
300
+ concurrency?: number;
301
+ }
302
+
303
+ // Song/Album data structure
304
+ interface SongData {
305
+ entityUniqueId: string;
306
+ entitiesByUniqueId: Record<string, EntityData>;
307
+ linksByPlatform: Record<string, PlatformLink>;
308
+ id: string;
309
+ title: string;
310
+ artist: string[];
311
+ type: string;
312
+ thumbnail: string;
313
+ }
314
+
315
+ interface EntityData {
316
+ id: string;
317
+ title: string;
318
+ artistName: string[];
319
+ type: string;
320
+ thumbnailUrl: string;
321
+ }
322
+
323
+ interface PlatformLink {
324
+ url: string;
325
+ nativeAppUriMobile?: string;
326
+ nativeAppUriDesktop?: string;
327
+ }
328
+
329
+ // Cache statistics
330
+ interface CacheStats {
331
+ size: number;
332
+ ttl: number;
333
+ hitCount: number;
334
+ missCount: number;
335
+ hitRate: number;
336
+ totalRequests: number;
337
+ }
338
+
339
+ // Rate Limiter
340
+ declare class RateLimiter {
341
+ constructor(options?: RateLimiterOptions);
342
+ waitForSlot(): Promise<void>;
343
+ handleRateLimitResponse(retryAfterSeconds?: number): Promise<void>;
344
+ getStatus(): RateLimiterStatus;
345
+ }
346
+
347
+ interface RateLimiterOptions {
348
+ maxRequests?: number;
349
+ windowMs?: number;
350
+ strategy?: 'token-bucket' | 'leaky-bucket' | 'sliding-window';
351
+ retryAfterMs?: number;
352
+ }
353
+
354
+ interface RateLimiterStatus {
355
+ available?: number;
356
+ max?: number;
357
+ refillRate?: number;
358
+ used?: number;
359
+ windowMs?: number;
360
+ queued?: number;
361
+ processing?: boolean;
362
+ }
363
+
364
+ // Metrics Collector
365
+ declare class MetricsCollector {
366
+ constructor(options?: MetricsOptions);
367
+ recordRequest(options: RequestMetrics): void;
368
+ recordError(error: Error, context?: Record<string, any>): void;
369
+ recordRateLimit(delayMs: number): void;
370
+ updateCacheMetrics(size: number): void;
371
+ getSummary(): MetricsSummary;
372
+ getDetailedMetrics(options?: DetailedMetricsOptions): Record<string, any>;
373
+ cleanup(): void;
374
+ reset(): void;
375
+ export(): {
376
+ summary: MetricsSummary;
377
+ detailed: Record<string, any>;
378
+ raw: {
379
+ metrics: any;
380
+ counters: any;
381
+ };
382
+ };
383
+ }
384
+
385
+ interface MetricsOptions {
386
+ enabled?: boolean;
387
+ retentionMs?: number;
388
+ maxDataPoints?: number;
389
+ }
390
+
391
+ interface RequestMetrics {
392
+ url: string;
393
+ method?: string;
394
+ startTime: number;
395
+ endTime?: number;
396
+ success?: boolean;
397
+ statusCode?: number;
398
+ error?: string;
399
+ responseTime?: number;
400
+ platform?: string;
401
+ country?: string;
402
+ cacheHit?: boolean;
403
+ }
404
+
405
+ interface MetricsSummary {
406
+ counters: {
407
+ totalRequests: number;
408
+ successfulRequests: number;
409
+ failedRequests: number;
410
+ cacheHits: number;
411
+ cacheMisses: number;
412
+ rateLimitHits: number;
413
+ };
414
+ recent: {
415
+ requests: number;
416
+ errors: number;
417
+ avgResponseTime: number;
418
+ requestsPerMinute: number;
419
+ };
420
+ rates: {
421
+ successRate: number;
422
+ cacheHitRate: number;
423
+ errorRate: number;
424
+ };
425
+ cache: {
426
+ hits: number;
427
+ misses: number;
428
+ size: number;
429
+ };
430
+ rateLimits: {
431
+ hits: number;
432
+ avgDelay: number;
433
+ };
434
+ }
435
+
436
+ interface DetailedMetricsOptions {
437
+ startTime?: number;
438
+ endTime?: number;
439
+ groupBy?: 'hour' | 'minute' | 'platform' | 'country';
440
+ }
441
+
442
+ // Plugin System
443
+ declare class PluginSystem {
444
+ constructor();
445
+ registerPlugin(name: string, plugin: Plugin): PluginSystem;
446
+ unregisterPlugin(name: string): PluginSystem;
447
+ registerHook(name: string, defaultHandlers?: any[]): PluginSystem;
448
+ registerHookHandler(hookName: string, handler: (context: any) => Promise<void> | void, pluginName?: string): PluginSystem;
449
+ executeHook(hookName: string, context?: Record<string, any>): Promise<void>;
450
+ executeMiddleware(context: any, next: () => Promise<any>): Promise<any>;
451
+ transformData(data: any, type: string, context?: Record<string, any>): Promise<any>;
452
+ getPlugin(name: string): Plugin | undefined;
453
+ getPlugins(): string[];
454
+ hasPlugin(name: string): boolean;
455
+ getPluginInfo(name: string): PluginInfo | null;
456
+ }
457
+
458
+ interface Plugin {
459
+ name?: string;
460
+ version?: string;
461
+ description?: string;
462
+ init?: () => void;
463
+ cleanup?: () => void;
464
+ hooks?: Record<string, (context: any) => Promise<void> | void>;
465
+ middleware?: (context: any, next: () => Promise<any>) => Promise<any>;
466
+ transformers?: Record<string, (data: any, context: any) => Promise<any> | any>;
467
+ }
468
+
469
+ interface PluginInfo {
470
+ name: string;
471
+ hooks: string[];
472
+ hasMiddleware: boolean;
473
+ hasTransformers: boolean;
474
+ version?: string;
475
+ description?: string;
476
+ }
477
+
478
+ // Built-in plugins
479
+ declare const loggingPlugin: Plugin;
480
+ declare const cachingPlugin: Plugin;
481
+ declare const analyticsPlugin: Plugin;
482
+ declare const responseTransformerPlugin: Plugin;
483
+
484
+ declare namespace Page {
485
+ interface Response {
486
+ /**
487
+ * The unique ID for the input entity that was supplied in the request.
488
+ *
489
+ * The data for this entity, such as title, artistName, etc. will be found in an object at `entitiesByUniqueId[entityUniqueId]`
490
+ */
491
+ entityUniqueId: string,
492
+
493
+ /**
494
+ * Song/Album Title of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].title`
495
+ */
496
+ title: string,
497
+
498
+ /**
499
+ * Artist's Name of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].artistName`
500
+ */
501
+ artist: string,
502
+
503
+ /**
504
+ * Type (song or album) of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].type`
505
+ */
506
+ type: entityType,
507
+
508
+ /**
509
+ * Thumbnail of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].thumbnailUrl`
510
+ */
511
+ thumbnail: string,
512
+
513
+ /**
514
+ * The userCountry query param that was supplied in the request. It signals
515
+ * the country/availability we use to query the streaming platforms. Defaults
516
+ * to 'US' if no userCountry supplied in the request.
517
+ *
518
+ * NOTE: As a fallback, our service may respond with matches that were found
519
+ * in a locale other than the userCountry supplied
520
+ */
521
+ userCountry: CountryCode,
522
+
523
+ /**
524
+ * A URL that will render the Songlink page for this entity
525
+ */
526
+ pageUrl: string,
527
+
528
+ /**
529
+ * A collection of objects. Each key is a platform, and each value is an
530
+ * object that contains data for linking to the match
531
+ */
532
+ linksByPlatform: {
533
+ /**
534
+ * Each key in `linksByPlatform` is a Platform. A Platform will exist here
535
+ * only if there is a match found. E.g. if there is no YouTube match found,
536
+ * then neither `youtube` or `youtubeMusic` properties will exist here
537
+ */
538
+ [key in Platform]: {
539
+ /**
540
+ * The unique ID for this entity. Use it to look up data about this entity
541
+ * at `entitiesByUniqueId[entityUniqueId]`
542
+ */
543
+ entityUniqueId: string,
544
+
545
+ /**
546
+ * The URL for this match
547
+ */
548
+ url: string,
549
+
550
+ /**
551
+ * The native app URI that can be used on mobile devices to open this
552
+ * entity directly in the native app
553
+ */
554
+ nativeAppUriMobile?: string,
555
+
556
+ /**
557
+ * The native app URI that can be used on desktop devices to open this
558
+ * entity directly in the native app
559
+ */
560
+ nativeAppUriDesktop?: string,
561
+ };
562
+ },
563
+
564
+ /**
565
+ * A collection of objects. Each key is a unique identifier for a streaming
566
+ * entity, and each value is an object that contains data for that entity,
567
+ * such as `title`, `artistName`, `thumbnailUrl`, etc.
568
+ */
569
+ entitiesByUniqueId: {
570
+ /**
571
+ * The unique identifier key for a streaming entitiy
572
+ */
573
+ [entityUniqueId: string]: {
574
+ /**
575
+ * This is the unique identifier on the streaming platform/API provider
576
+ */
577
+ id: string,
578
+
579
+ /**
580
+ * The type of media this entity is
581
+ */
582
+ type: entityType,
583
+
584
+ /**
585
+ * The title of the `song`/`album`
586
+ */
587
+ title?: string,
588
+
589
+ /**
590
+ * The artist/s of the `song`/`album`
591
+ */
592
+ artistName?: [string],
593
+
594
+ /**
595
+ * The coverart image URL of the `song`/`album`
596
+ */
597
+ thumbnailUrl?: string,
598
+
599
+ /**
600
+ * Coverart's width
601
+ */
602
+ thumbnailWidth?: number,
603
+ /**
604
+ * Coverart's height
605
+ */
606
+ thumbnailHeight?: number,
607
+
608
+ /**
609
+ * The API provider that powered this match. Useful if you'd like to use
610
+ * this entity's data to query the API directly
611
+ */
612
+ apiProvider: APIProvider,
613
+
614
+ /**
615
+ * An array of platforms that are "powered" by this entity. E.g. an entity
616
+ * from Apple Music will generally have a `platforms` array of
617
+ * `["appleMusic", "itunes"]` since both those platforms/links are derived
618
+ * from this single entity
619
+ */
620
+ platforms: Platform[],
621
+ },
622
+ },
623
+ }
624
+ }
625
+
626
+ type Platform =
627
+ | 'spotify'
628
+ | 'itunes'
629
+ | 'appleMusic'
630
+ | 'youtube'
631
+ | 'youtubeMusic'
632
+ | 'google'
633
+ | 'googleStore'
634
+ | 'pandora'
635
+ | 'deezer'
636
+ | 'tidal'
637
+ | 'amazonStore'
638
+ | 'amazonMusic'
639
+ | 'soundcloud'
640
+ | 'napster'
641
+ | 'yandex'
642
+ | 'spinrilla';
643
+
644
+ type APIProvider =
645
+ | 'spotify'
646
+ | 'itunes'
647
+ | 'youtube'
648
+ | 'google'
649
+ | 'pandora'
650
+ | 'deezer'
651
+ | 'tidal'
652
+ | 'amazon'
653
+ | 'soundcloud'
654
+ | 'napster'
655
+ | 'yandex'
656
+ | 'spinrilla';
657
+
658
+ type entityType =
659
+ | 'song'
660
+ | 'album'
661
+
662
+ // Export the main class
663
+ export = Odesli;