odesli.js 1.3.4 → 1.3.6
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/.github/dependabot.yml +56 -0
- package/.github/workflows/dependabot-auto-merge.yml +137 -0
- package/API_IMPROVEMENTS.md +16 -16
- package/README.md +468 -85
- package/RELEASE_NOTES_1.1.0.md +1 -1
- package/examples/README.md +281 -60
- package/examples/advanced-features-example.js +4 -4
- package/examples/advanced-usage.js +3 -3
- package/examples/basic-usage.js +4 -9
- package/examples/cache-test.js +1 -1
- package/examples/rate-limiter-strategies.js +83 -0
- package/examples/test-apple-music-extraction.js +1 -1
- package/examples/user-agent-example.js +1 -1
- package/lib/rate-limiter.js +16 -15
- package/package.json +17 -5
- package/scripts/version-bump.js +41 -0
package/lib/rate-limiter.js
CHANGED
|
@@ -27,22 +27,23 @@ class RateLimiter {
|
|
|
27
27
|
* Most efficient for burst handling
|
|
28
28
|
*/
|
|
29
29
|
async tokenBucket() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.tokens
|
|
39
|
-
|
|
30
|
+
while (true) {
|
|
31
|
+
const now = Date.now()
|
|
32
|
+
const timePassed = now - this.lastRefill
|
|
33
|
+
const tokensToAdd = Math.floor(timePassed / this.windowMs) * this.maxRequests
|
|
34
|
+
|
|
35
|
+
this.tokens = Math.min(this.maxRequests, this.tokens + tokensToAdd)
|
|
36
|
+
this.lastRefill = now
|
|
37
|
+
|
|
38
|
+
if (this.tokens >= 1) {
|
|
39
|
+
this.tokens--
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Calculate wait time
|
|
44
|
+
const waitTime = this.windowMs - (timePassed % this.windowMs)
|
|
45
|
+
await new Promise(resolve => setTimeout(resolve, waitTime))
|
|
40
46
|
}
|
|
41
|
-
|
|
42
|
-
// Calculate wait time
|
|
43
|
-
const waitTime = this.windowMs - (timePassed % this.windowMs)
|
|
44
|
-
await new Promise(resolve => setTimeout(resolve, waitTime))
|
|
45
|
-
return this.tokenBucket()
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odesli.js",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Node.js Client to query odesli.co (song.link/album.link) API",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
"types": "./lib/index.d.ts",
|
|
11
11
|
"import": "./lib/index.js",
|
|
12
12
|
"require": "./lib/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./rate-limiter": {
|
|
15
|
+
"import": "./lib/rate-limiter.js",
|
|
16
|
+
"require": "./lib/rate-limiter.js"
|
|
17
|
+
},
|
|
18
|
+
"./metrics": {
|
|
19
|
+
"import": "./lib/metrics.js",
|
|
20
|
+
"require": "./lib/metrics.js"
|
|
21
|
+
},
|
|
22
|
+
"./plugin-system": {
|
|
23
|
+
"import": "./lib/plugin-system.js",
|
|
24
|
+
"require": "./lib/plugin-system.js"
|
|
13
25
|
}
|
|
14
26
|
},
|
|
15
27
|
"engines": {
|
|
@@ -54,7 +66,7 @@
|
|
|
54
66
|
"url": "https://github.com/MattrAus/odesli.js/issues"
|
|
55
67
|
},
|
|
56
68
|
"dependencies": {
|
|
57
|
-
"@types/node": "^24.0.
|
|
69
|
+
"@types/node": "^24.0.13",
|
|
58
70
|
"node-fetch": "^2.7.0"
|
|
59
71
|
},
|
|
60
72
|
"devDependencies": {
|
|
@@ -68,13 +80,13 @@
|
|
|
68
80
|
"eslint-plugin-import": "^2.28.0",
|
|
69
81
|
"eslint-plugin-jest": "^29.0.1",
|
|
70
82
|
"eslint-plugin-node": "^11.1.0",
|
|
71
|
-
"eslint-plugin-prettier": "^5.5.
|
|
83
|
+
"eslint-plugin-prettier": "^5.5.1",
|
|
72
84
|
"eslint-plugin-promise": "^6.6.0",
|
|
73
85
|
"jest": "^29.5.0",
|
|
74
86
|
"jest-fetch-mock": "^3.0.3",
|
|
75
87
|
"jsdoc": "^4.0.2",
|
|
76
|
-
"prettier": "^3.
|
|
77
|
-
"snyk": "^1.
|
|
88
|
+
"prettier": "^3.6.2",
|
|
89
|
+
"snyk": "^1.1297.3",
|
|
78
90
|
"ts-jest": "^29.1.0",
|
|
79
91
|
"typescript": "^5.0.0"
|
|
80
92
|
},
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Automatically bump version based on dependency changes
|
|
8
|
+
* Usage: node scripts/version-bump.js [patch|minor|major]
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
function bumpVersion(type = 'patch') {
|
|
12
|
+
const packagePath = path.join(__dirname, '..', 'package.json');
|
|
13
|
+
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
14
|
+
|
|
15
|
+
const currentVersion = packageJson.version;
|
|
16
|
+
const [major, minor, patch] = currentVersion.split('.').map(Number);
|
|
17
|
+
|
|
18
|
+
let newVersion;
|
|
19
|
+
switch (type) {
|
|
20
|
+
case 'major':
|
|
21
|
+
newVersion = `${major + 1}.0.0`;
|
|
22
|
+
break;
|
|
23
|
+
case 'minor':
|
|
24
|
+
newVersion = `${major}.${minor + 1}.0`;
|
|
25
|
+
break;
|
|
26
|
+
case 'patch':
|
|
27
|
+
default:
|
|
28
|
+
newVersion = `${major}.${minor}.${patch + 1}`;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
packageJson.version = newVersion;
|
|
33
|
+
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
34
|
+
|
|
35
|
+
console.log(`Version bumped from ${currentVersion} to ${newVersion}`);
|
|
36
|
+
return newVersion;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Get version type from command line argument
|
|
40
|
+
const versionType = process.argv[2] || 'patch';
|
|
41
|
+
bumpVersion(versionType);
|