odesli.js 1.3.9 โ 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -85
- package/lib/index.d.ts +114 -17
- package/lib/index.js +893 -201
- package/lib/index.mjs +6 -3
- package/package.json +8 -2
- package/.eslintrc.js +0 -33
- package/.gitattributes +0 -1
- package/.github/dependabot.yml +0 -56
- package/.github/workflows/ci.yml +0 -94
- package/.github/workflows/dependabot-auto-merge.yml +0 -137
- package/.github/workflows/publish-github-packages.yml +0 -46
- package/.github/workflows/publish-npm.yml +0 -133
- package/.prettierignore +0 -31
- package/.prettierrc +0 -11
- package/API_IMPROVEMENTS.md +0 -318
- package/CHANGELOG.md +0 -256
- package/CODE_OF_CONDUCT.md +0 -125
- package/CONTRIBUTING.md +0 -104
- package/RELEASE_NOTES_1.1.0.md +0 -84
- package/SECURITY.md +0 -112
- package/examples/README.md +0 -442
- package/examples/advanced-features-example.js +0 -205
- package/examples/advanced-usage.js +0 -247
- package/examples/basic-usage.js +0 -100
- package/examples/cache-test.js +0 -119
- package/examples/rate-limiter-strategies.js +0 -83
- package/examples/test-apple-music-extraction.js +0 -60
- package/examples/user-agent-example.js +0 -46
- package/jest.config.js +0 -14
- package/jsdoc.json +0 -24
- package/scripts/version-bump.js +0 -41
- package/tests/advanced-features.test.js +0 -423
- package/tests/odesli.test.js +0 -742
- package/tests/setup.js +0 -22
- package/tsconfig.json +0 -21
package/README.md
CHANGED
|
@@ -8,7 +8,14 @@
|
|
|
8
8
|
[](https://www.npmjs.com/package/odesli.js)
|
|
9
9
|
[](https://www.typescriptlang.org/)
|
|
10
10
|
|
|
11
|
-
A Node.js client for the [Odesli API](https://odesli.co/)
|
|
11
|
+
A Node.js/TypeScript client for the [Songlink/Odesli API](https://odesli.co/) that helps you find links to music across multiple streaming platforms.
|
|
12
|
+
|
|
13
|
+
> [!IMPORTANT]
|
|
14
|
+
> The **unauthenticated** Songlink/Odesli public API was retired on **July 31, 2026**.
|
|
15
|
+
> `odesli.js` v2 requires an **allowlisted API key** (`apiKey` option or `ODESLI_API_KEY`).
|
|
16
|
+
> This package does **not** issue or bundle API keys.
|
|
17
|
+
> If you only need a shareable landing page, use `Odesli.getPageUrl(url)` or open `https://song.link/<your-url>` directly.
|
|
18
|
+
> Official announcement: [Sunsetting the Songlink (Odesli) public API](https://linktr.ee/help/articles/15201827-sunsetting-the-songlink-odesli-public-api).
|
|
12
19
|
|
|
13
20
|
## ๐ Table of Contents
|
|
14
21
|
|
|
@@ -17,6 +24,7 @@ A Node.js client for the [Odesli API](https://odesli.co/) (formerly song.link/al
|
|
|
17
24
|
- [Features](#features)
|
|
18
25
|
- [Installation](#installation)
|
|
19
26
|
- [From npm](#from-npm)
|
|
27
|
+
- [Migrating from v1 to v2](#migrating-from-v1-to-v2)
|
|
20
28
|
- [Quick Start](#quick-start)
|
|
21
29
|
- [API Key](#api-key)
|
|
22
30
|
- [Usage](#usage)
|
|
@@ -43,11 +51,12 @@ A Node.js client for the [Odesli API](https://odesli.co/) (formerly song.link/al
|
|
|
43
51
|
- ๐ **Cross-platform links**: Get links for music across Spotify, Apple Music, YouTube Music, and more
|
|
44
52
|
- ๐ต **Song & Album support**: Works with both individual tracks and full albums
|
|
45
53
|
- ๐ **Multi-country support**: Specify country codes for region-specific results
|
|
46
|
-
- ๐ **API
|
|
54
|
+
- ๐ **Allowlisted API key required**: Pass `{ apiKey }` or set `ODESLI_API_KEY`
|
|
55
|
+
- ๐งญ **Zero-key helpers**: `Odesli.detectPlatform`, `Odesli.extractId`, and `Odesli.getPageUrl` work without credentials
|
|
47
56
|
- ๐ฆ **TypeScript support**: Full TypeScript definitions included
|
|
48
57
|
- โก **Lightweight**: Minimal dependencies, fast performance
|
|
49
|
-
- ๐ก๏ธ **
|
|
50
|
-
- ๐งช **Fully tested**:
|
|
58
|
+
- ๐ก๏ธ **Structured errors**: `OdesliError` with sunset/auth codes and non-retryable 401/410 handling
|
|
59
|
+
- ๐งช **Fully tested**: High coverage unit suite plus optional live API smoke tests
|
|
51
60
|
|
|
52
61
|
## Installation
|
|
53
62
|
|
|
@@ -57,6 +66,13 @@ A Node.js client for the [Odesli API](https://odesli.co/) (formerly song.link/al
|
|
|
57
66
|
npm install odesli.js
|
|
58
67
|
```
|
|
59
68
|
|
|
69
|
+
## Migrating from v1 to v2
|
|
70
|
+
|
|
71
|
+
1. **Provide an allowlisted API key** via `new Odesli({ apiKey })` or `ODESLI_API_KEY`.
|
|
72
|
+
2. Catch `Odesli.OdesliError` and inspect `error.code` (`MISSING_API_KEY`, `PUBLIC_API_ACCESS_DEPRECATED`, `INVALID_ACCESS_KEY`, `API_SUNSET_GONE`, `RATE_LIMITED`, โฆ).
|
|
73
|
+
3. If you no longer have API access, use `Odesli.getPageUrl(url)` to build `https://song.link/...` landing links without calling the API.
|
|
74
|
+
4. Request allowlisted API access from Songlink/Odesli if you need programmatic lookups: [Songlink/Odesli API sunset article](https://linktr.ee/help/articles/15201827-sunsetting-the-songlink-odesli-public-api).
|
|
75
|
+
|
|
60
76
|
## Quick Start
|
|
61
77
|
|
|
62
78
|
**CommonJS (require):**
|
|
@@ -64,28 +80,21 @@ npm install odesli.js
|
|
|
64
80
|
```js
|
|
65
81
|
const Odesli = require('odesli.js');
|
|
66
82
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// apiKey: 'your-api-key-here',
|
|
73
|
-
// version: 'v1-alpha.1', // optional, defaults to v1-alpha.1
|
|
74
|
-
// });
|
|
75
|
-
|
|
76
|
-
// You can also disable the metrics collector if you don't need it
|
|
77
|
-
// const odesliLight = new Odesli({ metrics: false });
|
|
83
|
+
// Prefer environment configuration in production:
|
|
84
|
+
// export ODESLI_API_KEY=your-allowlisted-key
|
|
85
|
+
const odesli = new Odesli({
|
|
86
|
+
apiKey: process.env.ODESLI_API_KEY,
|
|
87
|
+
});
|
|
78
88
|
|
|
79
|
-
// Fetch a song by URL (this is the actual working example)
|
|
80
89
|
(async () => {
|
|
81
90
|
try {
|
|
82
91
|
const song = await odesli.fetch(
|
|
83
92
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
|
|
84
93
|
);
|
|
85
|
-
console.log(
|
|
86
|
-
console.log(
|
|
94
|
+
console.log(`${song.title} by ${song.artist.join(', ')}`);
|
|
95
|
+
console.log(`Song.link: ${song.pageUrl}`);
|
|
87
96
|
} catch (error) {
|
|
88
|
-
console.error(
|
|
97
|
+
console.error(error.code || 'ERROR', error.message);
|
|
89
98
|
}
|
|
90
99
|
})();
|
|
91
100
|
```
|
|
@@ -95,35 +104,48 @@ const odesli = new Odesli();
|
|
|
95
104
|
```js
|
|
96
105
|
import Odesli from 'odesli.js';
|
|
97
106
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// Or with API key for higher limits
|
|
102
|
-
// const odesli = new Odesli({
|
|
103
|
-
// apiKey: 'your-api-key-here',
|
|
104
|
-
// version: 'v1-alpha.1', // optional, defaults to v1-alpha.1
|
|
105
|
-
// });
|
|
106
|
-
|
|
107
|
-
// You can also disable the metrics collector if you don't need it
|
|
108
|
-
// const odesliLight = new Odesli({ metrics: false });
|
|
107
|
+
const odesli = new Odesli({
|
|
108
|
+
apiKey: process.env.ODESLI_API_KEY,
|
|
109
|
+
});
|
|
109
110
|
|
|
110
|
-
// Fetch a song by URL (this is the actual working example)
|
|
111
111
|
try {
|
|
112
112
|
const song = await odesli.fetch(
|
|
113
113
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
|
|
114
114
|
);
|
|
115
|
-
console.log(
|
|
116
|
-
console.log(
|
|
115
|
+
console.log(`${song.title} by ${song.artist.join(', ')}`);
|
|
116
|
+
console.log(`Song.link: ${song.pageUrl}`);
|
|
117
117
|
} catch (error) {
|
|
118
|
-
console.error(
|
|
118
|
+
console.error(error.code || 'ERROR', error.message);
|
|
119
119
|
}
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
+
**No API key (landing page only):**
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
const { Odesli } = require('odesli.js');
|
|
126
|
+
const pageUrl = Odesli.getPageUrl(
|
|
127
|
+
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
|
|
128
|
+
);
|
|
129
|
+
// => https://song.link/https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR
|
|
130
|
+
```
|
|
131
|
+
|
|
122
132
|
## API Key
|
|
123
133
|
|
|
124
|
-
An API key is **
|
|
134
|
+
An allowlisted API key is **required** for all API requests in v2.
|
|
125
135
|
|
|
126
|
-
|
|
136
|
+
Set it via environment variable (recommended):
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
export ODESLI_API_KEY=your-allowlisted-key
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Or pass it explicitly:
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
const odesli = new Odesli({ apiKey: process.env.ODESLI_API_KEY });
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`odesli.js` does not provide or redistribute API keys. Request access through the Songlink/Odesli API allowlist process described in the [official sunset announcement](https://linktr.ee/help/articles/15201827-sunsetting-the-songlink-odesli-public-api).
|
|
127
149
|
|
|
128
150
|
## Usage
|
|
129
151
|
|
|
@@ -134,22 +156,16 @@ To get an API key, email `developers@song.link`.
|
|
|
134
156
|
```js
|
|
135
157
|
const Odesli = require('odesli.js');
|
|
136
158
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// Or with API key for higher limits
|
|
141
|
-
// const odesli = new Odesli({
|
|
142
|
-
// apiKey: 'your-api-key-here',
|
|
143
|
-
// });
|
|
159
|
+
const odesli = new Odesli({
|
|
160
|
+
apiKey: process.env.ODESLI_API_KEY,
|
|
161
|
+
});
|
|
144
162
|
|
|
145
163
|
(async () => {
|
|
146
|
-
// Fetch a song by URL
|
|
147
164
|
const song = await odesli.fetch(
|
|
148
165
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
|
|
149
166
|
);
|
|
150
167
|
console.log(`${song.title} by ${song.artist.join(', ')}`);
|
|
151
168
|
|
|
152
|
-
// Fetch multiple songs at once
|
|
153
169
|
const urls = [
|
|
154
170
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR',
|
|
155
171
|
'https://open.spotify.com/track/0V3wPSX9ygBnCm8psDIegu',
|
|
@@ -164,21 +180,15 @@ const odesli = new Odesli();
|
|
|
164
180
|
```js
|
|
165
181
|
import Odesli from 'odesli.js';
|
|
166
182
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
// Or with API key for higher limits
|
|
171
|
-
// const odesli = new Odesli({
|
|
172
|
-
// apiKey: 'your-api-key-here',
|
|
173
|
-
// });
|
|
183
|
+
const odesli = new Odesli({
|
|
184
|
+
apiKey: process.env.ODESLI_API_KEY,
|
|
185
|
+
});
|
|
174
186
|
|
|
175
|
-
// Fetch a song by URL
|
|
176
187
|
const song = await odesli.fetch(
|
|
177
188
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
|
|
178
189
|
);
|
|
179
190
|
console.log(`${song.title} by ${song.artist.join(', ')}`);
|
|
180
191
|
|
|
181
|
-
// Fetch multiple songs at once
|
|
182
192
|
const urls = [
|
|
183
193
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR',
|
|
184
194
|
'https://open.spotify.com/track/0V3wPSX9ygBnCm8psDIegu',
|
|
@@ -346,6 +356,10 @@ All methods return a response object with the following structure:
|
|
|
346
356
|
- Napster
|
|
347
357
|
- Yandex Music
|
|
348
358
|
- Spinrilla
|
|
359
|
+
- Audiomack
|
|
360
|
+
- Anghami
|
|
361
|
+
- Boomplay
|
|
362
|
+
- Audius
|
|
349
363
|
|
|
350
364
|
## TypeScript Support
|
|
351
365
|
|
|
@@ -356,7 +370,7 @@ This package includes full TypeScript definitions with strict country code valid
|
|
|
356
370
|
```typescript
|
|
357
371
|
const Odesli = require('odesli.js');
|
|
358
372
|
|
|
359
|
-
const odesli = new Odesli({ apiKey:
|
|
373
|
+
const odesli = new Odesli({ apiKey: process.env.ODESLI_API_KEY });
|
|
360
374
|
|
|
361
375
|
(async () => {
|
|
362
376
|
// Get all valid country codes and names for UI dropdowns
|
|
@@ -385,7 +399,7 @@ const odesli = new Odesli({ apiKey: 'your-key' });
|
|
|
385
399
|
```typescript
|
|
386
400
|
import Odesli, { CountryCode } from 'odesli.js';
|
|
387
401
|
|
|
388
|
-
const odesli = new Odesli({ apiKey:
|
|
402
|
+
const odesli = new Odesli({ apiKey: process.env.ODESLI_API_KEY });
|
|
389
403
|
|
|
390
404
|
// Get all valid country codes and names for UI dropdowns
|
|
391
405
|
const countryOptions = Odesli.getCountryOptions();
|
|
@@ -424,7 +438,7 @@ Check out the [examples directory](./examples) for comprehensive usage examples:
|
|
|
424
438
|
```js
|
|
425
439
|
const Odesli = require('odesli.js');
|
|
426
440
|
|
|
427
|
-
const odesli = new Odesli();
|
|
441
|
+
const odesli = new Odesli({ apiKey: process.env.ODESLI_API_KEY });
|
|
428
442
|
|
|
429
443
|
// Get country options for UI dropdowns
|
|
430
444
|
const countries = Odesli.getCountryOptions();
|
|
@@ -447,7 +461,7 @@ console.log(`Available countries: ${countries.length}`);
|
|
|
447
461
|
```js
|
|
448
462
|
import Odesli from 'odesli.js';
|
|
449
463
|
|
|
450
|
-
const odesli = new Odesli();
|
|
464
|
+
const odesli = new Odesli({ apiKey: process.env.ODESLI_API_KEY });
|
|
451
465
|
|
|
452
466
|
// Get country options for UI dropdowns
|
|
453
467
|
const countries = Odesli.getCountryOptions();
|
|
@@ -470,7 +484,7 @@ console.log(`Fetched: ${song.title}`);
|
|
|
470
484
|
```js
|
|
471
485
|
const Odesli = require('odesli.js');
|
|
472
486
|
|
|
473
|
-
const odesli = new Odesli();
|
|
487
|
+
const odesli = new Odesli({ apiKey: process.env.ODESLI_API_KEY });
|
|
474
488
|
|
|
475
489
|
const urls = [
|
|
476
490
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR',
|
|
@@ -495,7 +509,7 @@ const urls = [
|
|
|
495
509
|
```js
|
|
496
510
|
import Odesli from 'odesli.js';
|
|
497
511
|
|
|
498
|
-
const odesli = new Odesli();
|
|
512
|
+
const odesli = new Odesli({ apiKey: process.env.ODESLI_API_KEY });
|
|
499
513
|
|
|
500
514
|
const urls = [
|
|
501
515
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR',
|
|
@@ -513,20 +527,18 @@ results.forEach((result, index) => {
|
|
|
513
527
|
});
|
|
514
528
|
```
|
|
515
529
|
|
|
516
|
-
**Platform detection and ID extraction:**
|
|
530
|
+
**Platform detection and ID extraction (no API key required):**
|
|
517
531
|
|
|
518
532
|
**CommonJS (require):**
|
|
519
533
|
|
|
520
534
|
```js
|
|
521
535
|
const Odesli = require('odesli.js');
|
|
522
536
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
// These methods are synchronous, so no async handling needed
|
|
526
|
-
const platform = odesli.detectPlatform(
|
|
537
|
+
// Static helpers work without constructing a client / API key
|
|
538
|
+
const platform = Odesli.detectPlatform(
|
|
527
539
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
|
|
528
540
|
);
|
|
529
|
-
const id =
|
|
541
|
+
const id = Odesli.extractId(
|
|
530
542
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
|
|
531
543
|
);
|
|
532
544
|
console.log(`Platform: ${platform}, ID: ${id}`);
|
|
@@ -537,13 +549,10 @@ console.log(`Platform: ${platform}, ID: ${id}`);
|
|
|
537
549
|
```js
|
|
538
550
|
import Odesli from 'odesli.js';
|
|
539
551
|
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
// These methods are synchronous, so no async handling needed
|
|
543
|
-
const platform = odesli.detectPlatform(
|
|
552
|
+
const platform = Odesli.detectPlatform(
|
|
544
553
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
|
|
545
554
|
);
|
|
546
|
-
const id =
|
|
555
|
+
const id = Odesli.extractId(
|
|
547
556
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR'
|
|
548
557
|
);
|
|
549
558
|
console.log(`Platform: ${platform}, ID: ${id}`);
|
|
@@ -555,21 +564,31 @@ For more detailed information about the Odesli API, check the [official document
|
|
|
555
564
|
|
|
556
565
|
## Contributing
|
|
557
566
|
|
|
567
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
568
|
+
|
|
558
569
|
1. Fork the repository
|
|
559
570
|
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
560
571
|
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
561
572
|
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
562
573
|
5. Open a Pull Request
|
|
563
574
|
|
|
575
|
+
**Resources for Contributors:**
|
|
576
|
+
|
|
577
|
+
- ๐ [Contributing Guide](CONTRIBUTING.md) - Guidelines for contributing
|
|
578
|
+
- ๐ [Security Policy](SECURITY.md) - Security reporting guidelines
|
|
579
|
+
- ๐ [Code of Conduct](CODE_OF_CONDUCT.md) - Community standards
|
|
580
|
+
|
|
564
581
|
## License
|
|
565
582
|
|
|
566
583
|
This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details.
|
|
567
584
|
|
|
568
585
|
## Support
|
|
569
586
|
|
|
570
|
-
-
|
|
587
|
+
- ๐ API access: [Songlink/Odesli public API sunset / allowlist info](https://linktr.ee/help/articles/15201827-sunsetting-the-songlink-odesli-public-api)
|
|
571
588
|
- ๐ Issues: [GitHub Issues](https://github.com/MattrAus/odesli.js/issues)
|
|
572
|
-
- ๐
|
|
589
|
+
- ๐ [Odesli API Docs](https://linktree.notion.site/API-d0ebe08a5e304a55928405eb682f6741) - Official Odesli API documentation (historical / partner reference)
|
|
590
|
+
- ๐ [Security Issues](SECURITY.md) - Report security vulnerabilities
|
|
591
|
+
- ๐ [Changelog](CHANGELOG.md) - See what's new in each version
|
|
573
592
|
|
|
574
593
|
## Extensions: Advanced Features
|
|
575
594
|
|
|
@@ -581,12 +600,7 @@ Odesli.js provides several advanced extensions to help you build robust, scalabl
|
|
|
581
600
|
|
|
582
601
|
**Default Rate Limiting Behavior:**
|
|
583
602
|
|
|
584
|
-
The main Odesli client does **not** include built-in rate limiting. Rate limits are enforced by the Odesli API
|
|
585
|
-
|
|
586
|
-
- **Without API key**: 10 requests per minute (enforced by API)
|
|
587
|
-
- **With API key**: Higher limits (enforced by API)
|
|
588
|
-
|
|
589
|
-
When you exceed the API rate limit, you'll receive a 429 error: `"You are being rate limited, No API Key is 10 Requests / Minute"`
|
|
603
|
+
The main Odesli client does **not** include built-in rate limiting. Rate limits are enforced by the Songlink/Odesli API for your allowlisted key. Exceeding them returns a `429` `OdesliError` with `code: 'RATE_LIMITED'`.
|
|
590
604
|
|
|
591
605
|
**Why use the RateLimiter extension?**
|
|
592
606
|
|
|
@@ -653,11 +667,9 @@ const leakyBucketLimiter = new RateLimiter({
|
|
|
653
667
|
```js
|
|
654
668
|
const Odesli = require('odesli.js');
|
|
655
669
|
|
|
656
|
-
// Without RateLimiter - relies on API rate limiting
|
|
657
|
-
const odesli = new Odesli();
|
|
670
|
+
// Without RateLimiter - relies on API rate limiting for your allowlisted key
|
|
671
|
+
const odesli = new Odesli({ apiKey: process.env.ODESLI_API_KEY });
|
|
658
672
|
|
|
659
|
-
// This works fine for < 10 requests/minute
|
|
660
|
-
// But will throw 429 errors if you exceed the limit
|
|
661
673
|
const urls = [
|
|
662
674
|
'https://open.spotify.com/track/4Km5HrUvYTaSUfiSGPJeQR',
|
|
663
675
|
'https://open.spotify.com/track/0V3wPSX9ygBnCm8psDIegu',
|
|
@@ -667,7 +679,7 @@ const songs = await odesli.fetch(urls); // May hit API rate limit
|
|
|
667
679
|
// With RateLimiter - proactive client-side limiting
|
|
668
680
|
const { RateLimiter } = require('odesli.js/rate-limiter');
|
|
669
681
|
const limiter = new RateLimiter({
|
|
670
|
-
maxRequests: 8,
|
|
682
|
+
maxRequests: 8,
|
|
671
683
|
windowMs: 60000,
|
|
672
684
|
strategy: 'sliding-window',
|
|
673
685
|
});
|
|
@@ -687,7 +699,7 @@ async function safeFetch(url) {
|
|
|
687
699
|
const Odesli = require('odesli.js');
|
|
688
700
|
const { RateLimiter } = require('odesli.js/rate-limiter');
|
|
689
701
|
|
|
690
|
-
const odesli = new Odesli();
|
|
702
|
+
const odesli = new Odesli({ apiKey: process.env.ODESLI_API_KEY });
|
|
691
703
|
const limiter = new RateLimiter({
|
|
692
704
|
maxRequests: 2,
|
|
693
705
|
windowMs: 3000, // 2 requests per 3 seconds
|
package/lib/index.d.ts
CHANGED
|
@@ -255,35 +255,86 @@ type CountryCode =
|
|
|
255
255
|
| "ZM" // Zambia
|
|
256
256
|
| "ZW"; // Zimbabwe
|
|
257
257
|
|
|
258
|
+
type OdesliErrorCode =
|
|
259
|
+
| 'MISSING_API_KEY'
|
|
260
|
+
| 'PUBLIC_API_ACCESS_DEPRECATED'
|
|
261
|
+
| 'INVALID_ACCESS_KEY'
|
|
262
|
+
| 'API_SUNSET_GONE'
|
|
263
|
+
| 'UNAUTHORIZED'
|
|
264
|
+
| 'RATE_LIMITED'
|
|
265
|
+
| 'CLIENT_ERROR'
|
|
266
|
+
| 'SERVER_ERROR'
|
|
267
|
+
| 'TIMEOUT'
|
|
268
|
+
| 'NETWORK_ERROR'
|
|
269
|
+
| 'UNEXPECTED_RESPONSE'
|
|
270
|
+
| 'INVALID_URL'
|
|
271
|
+
| 'ODESLI_ERROR'
|
|
272
|
+
| string;
|
|
273
|
+
|
|
274
|
+
declare class OdesliError extends Error {
|
|
275
|
+
name: 'OdesliError';
|
|
276
|
+
code: OdesliErrorCode;
|
|
277
|
+
statusCode: number | null;
|
|
278
|
+
retryable: boolean;
|
|
279
|
+
docsUrl?: string;
|
|
280
|
+
retryAfterMs?: number;
|
|
281
|
+
cause?: Error;
|
|
282
|
+
|
|
283
|
+
constructor(
|
|
284
|
+
message: string,
|
|
285
|
+
options?: {
|
|
286
|
+
code?: OdesliErrorCode;
|
|
287
|
+
statusCode?: number | null;
|
|
288
|
+
retryable?: boolean;
|
|
289
|
+
docsUrl?: string;
|
|
290
|
+
cause?: Error;
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
258
295
|
// Core Odesli class
|
|
259
296
|
declare class Odesli {
|
|
260
297
|
constructor(options?: OdesliOptions);
|
|
261
|
-
|
|
298
|
+
|
|
299
|
+
static OdesliError: typeof OdesliError;
|
|
300
|
+
static SUNSET_DOCS_URL: string;
|
|
301
|
+
|
|
262
302
|
// Core methods
|
|
263
|
-
fetch(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
303
|
+
fetch(url: string, options?: FetchOptions | CountryCode): Promise<SongData>;
|
|
304
|
+
fetch(urls: string[], options?: FetchOptions | CountryCode): Promise<BatchResult>;
|
|
305
|
+
fetch(urlOrUrls: string | string[], options?: FetchOptions | CountryCode): Promise<SongData | BatchResult>;
|
|
306
|
+
getByParams(platform: string, type: string, id: string, options?: FetchOptions | CountryCode): Promise<SongData>;
|
|
307
|
+
getById(id: string, options?: FetchOptions | CountryCode): Promise<SongData>;
|
|
308
|
+
|
|
309
|
+
// Utility methods (also available statically without an API key)
|
|
268
310
|
detectPlatform(url: string): string | null;
|
|
269
311
|
extractId(url: string): string | null;
|
|
270
312
|
getSupportedPlatforms(): string[];
|
|
313
|
+
getPageUrl(url: string): string;
|
|
271
314
|
getUserAgent(): string;
|
|
272
|
-
|
|
315
|
+
|
|
273
316
|
// Cache methods
|
|
274
317
|
clearCache(): void;
|
|
275
318
|
getCacheStats(): CacheStats;
|
|
276
|
-
|
|
319
|
+
|
|
277
320
|
// Metrics methods
|
|
278
321
|
getMetrics(): MetricsCollector;
|
|
279
|
-
|
|
322
|
+
|
|
280
323
|
// Static methods
|
|
324
|
+
static detectPlatform(url: string): string | null;
|
|
325
|
+
static extractId(url: string): string | null;
|
|
326
|
+
static getSupportedPlatforms(): string[];
|
|
327
|
+
static getPageUrl(url: string): string;
|
|
281
328
|
static getCountryOptions(): Array<{ code: CountryCode; name: string }>;
|
|
282
329
|
}
|
|
283
330
|
|
|
284
331
|
// Configuration options for Odesli client
|
|
285
332
|
interface OdesliOptions {
|
|
286
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Allowlisted Songlink/Odesli API key.
|
|
335
|
+
* Required either here or via `process.env.ODESLI_API_KEY` (public API retired July 2026).
|
|
336
|
+
*/
|
|
337
|
+
apiKey?: string;
|
|
287
338
|
version?: string; // API version to use (default: 'v1-alpha.1')
|
|
288
339
|
cache?: boolean; // Enable response caching with 5-minute TTL (default: true)
|
|
289
340
|
timeout?: number; // Request timeout in milliseconds (default: 10000)
|
|
@@ -317,13 +368,25 @@ interface BatchError {
|
|
|
317
368
|
timestamp: string;
|
|
318
369
|
statusCode: number | null;
|
|
319
370
|
retryable: boolean;
|
|
320
|
-
|
|
371
|
+
code?: OdesliErrorCode;
|
|
372
|
+
errorType:
|
|
373
|
+
| 'BAD_REQUEST'
|
|
374
|
+
| 'UNAUTHORIZED'
|
|
375
|
+
| 'INVALID_ACCESS_KEY'
|
|
376
|
+
| 'PUBLIC_API_ACCESS_DEPRECATED'
|
|
377
|
+
| 'API_SUNSET_GONE'
|
|
378
|
+
| 'RATE_LIMITED'
|
|
379
|
+
| 'NOT_FOUND'
|
|
380
|
+
| 'TIMEOUT'
|
|
381
|
+
| 'UNKNOWN';
|
|
321
382
|
suggestion: string;
|
|
322
383
|
}
|
|
323
384
|
|
|
324
385
|
// Song/Album data structure returned by Odesli API
|
|
325
386
|
interface SongData {
|
|
326
387
|
entityUniqueId: string; // Unique identifier for the main entity
|
|
388
|
+
userCountry: string; // Country code used to localize matches
|
|
389
|
+
pageUrl: string; // Shareable song.link / album.link landing page URL
|
|
327
390
|
entitiesByUniqueId: Record<string, EntityData>; // Collection of all related entities
|
|
328
391
|
linksByPlatform: Record<string, PlatformLink>; // Links to different streaming platforms
|
|
329
392
|
id: string; // Platform-specific ID for the main entity
|
|
@@ -356,11 +419,11 @@ interface PlatformLink {
|
|
|
356
419
|
// Cache statistics and performance metrics
|
|
357
420
|
interface CacheStats {
|
|
358
421
|
size: number; // Current number of cached items
|
|
359
|
-
ttl
|
|
422
|
+
ttl?: number; // Time-to-live for cached items in milliseconds
|
|
360
423
|
hitCount: number; // Number of cache hits
|
|
361
424
|
missCount: number; // Number of cache misses
|
|
362
|
-
hitRate: number; // Cache hit rate
|
|
363
|
-
totalRequests
|
|
425
|
+
hitRate: number; // Cache hit rate (0-1)
|
|
426
|
+
totalRequests?: number; // Total number of requests made
|
|
364
427
|
}
|
|
365
428
|
|
|
366
429
|
// Rate Limiter
|
|
@@ -667,7 +730,11 @@ type Platform =
|
|
|
667
730
|
| 'soundcloud' // SoundCloud - Audio distribution platform
|
|
668
731
|
| 'napster' // Napster - Music streaming service
|
|
669
732
|
| 'yandex' // Yandex Music - Russian music streaming service
|
|
670
|
-
| 'spinrilla'
|
|
733
|
+
| 'spinrilla' // Spinrilla - Mixtape and hip-hop music platform
|
|
734
|
+
| 'audiomack' // Audiomack - Music streaming and discovery
|
|
735
|
+
| 'anghami' // Anghami - Middle East music streaming
|
|
736
|
+
| 'boomplay' // Boomplay - African music streaming
|
|
737
|
+
| 'audius'; // Audius - Decentralized music streaming
|
|
671
738
|
|
|
672
739
|
type APIProvider =
|
|
673
740
|
| 'spotify' // Spotify Web API
|
|
@@ -681,11 +748,41 @@ type APIProvider =
|
|
|
681
748
|
| 'soundcloud' // SoundCloud API
|
|
682
749
|
| 'napster' // Napster API
|
|
683
750
|
| 'yandex' // Yandex Music API
|
|
684
|
-
| 'spinrilla'
|
|
751
|
+
| 'spinrilla' // Spinrilla API
|
|
752
|
+
| 'audiomack' // Audiomack API
|
|
753
|
+
| 'anghami' // Anghami API
|
|
754
|
+
| 'boomplay' // Boomplay API
|
|
755
|
+
| 'audius'; // Audius API
|
|
685
756
|
|
|
686
757
|
type entityType =
|
|
687
758
|
| 'song' // Individual track/song
|
|
688
759
|
| 'album'; // Complete album or compilation
|
|
689
760
|
|
|
690
|
-
|
|
761
|
+
declare namespace Odesli {
|
|
762
|
+
export {
|
|
763
|
+
CountryCode,
|
|
764
|
+
OdesliError,
|
|
765
|
+
OdesliErrorCode,
|
|
766
|
+
OdesliOptions,
|
|
767
|
+
FetchOptions,
|
|
768
|
+
BatchResult,
|
|
769
|
+
BatchError,
|
|
770
|
+
SongData,
|
|
771
|
+
EntityData,
|
|
772
|
+
PlatformLink,
|
|
773
|
+
CacheStats,
|
|
774
|
+
RateLimiter,
|
|
775
|
+
RateLimiterOptions,
|
|
776
|
+
RateLimiterStatus,
|
|
777
|
+
MetricsCollector,
|
|
778
|
+
MetricsOptions,
|
|
779
|
+
RequestMetrics,
|
|
780
|
+
Platform,
|
|
781
|
+
APIProvider,
|
|
782
|
+
entityType,
|
|
783
|
+
};
|
|
784
|
+
export const SUNSET_DOCS_URL: string;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Export the main class and merged namespace for CJS + ESM interop
|
|
691
788
|
export = Odesli;
|