musicbrainz-api 0.16.0 → 0.17.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 CHANGED
@@ -69,7 +69,10 @@ const config = {
69
69
  },
70
70
 
71
71
  // Your e-mail address, required for submitting ISRCs
72
- appMail: string
72
+ appMail: string,
73
+
74
+ // Helpful if you have your own MusicBrainz server, default: false (optional)
75
+ disableRateLimiting: false,
73
76
  }
74
77
 
75
78
  const mbApi = new MusicbrainzApi(config);
@@ -61,6 +61,7 @@ export interface IMusicBrainzConfig {
61
61
  * User e-mail address or application URL
62
62
  */
63
63
  appContactInfo?: string;
64
+ disableRateLimiting?: boolean;
64
65
  }
65
66
  export interface ICsrfSession {
66
67
  sessionKey: string;
@@ -174,5 +175,6 @@ export declare class MusicBrainzApi {
174
175
  */
175
176
  addSpotifyIdToRecording(recording: mb.IRecording, spotifyId: string, editNote: string): Promise<void>;
176
177
  private getSession;
178
+ private applyRateLimiter;
177
179
  }
178
180
  export declare function makeAndQueryString(keyValuePairs: IFormData): string;
@@ -53,8 +53,7 @@ export class MusicBrainzApi {
53
53
  }
54
54
  async restGet(relUrl, query = {}) {
55
55
  query.fmt = 'json';
56
- const delay = await this.rateLimiter.limit();
57
- debug(`Client side rate limiter activated: cool down for ${Math.round(delay / 100) / 10} s...`);
56
+ await this.applyRateLimiter();
58
57
  const response = await got.get(`ws/2${relUrl}`, {
59
58
  ...this.options,
60
59
  searchParams: query,
@@ -96,7 +95,7 @@ export class MusicBrainzApi {
96
95
  let n = 1;
97
96
  const postData = xmlMetadata.toXml();
98
97
  do {
99
- await this.rateLimiter.limit();
98
+ await this.applyRateLimiter();
100
99
  const response = await got.post(path, {
101
100
  ...this.options,
102
101
  searchParams: { client: clientId },
@@ -179,7 +178,7 @@ export class MusicBrainzApi {
179
178
  */
180
179
  async editEntity(entity, mbid, formData) {
181
180
  var _a, _b;
182
- await this.rateLimiter.limit();
181
+ await this.applyRateLimiter();
183
182
  this.session = await this.getSession();
184
183
  formData.csrf_session_key = this.session.csrf.sessionKey;
185
184
  formData.csrf_token = this.session.csrf.token;
@@ -263,6 +262,12 @@ export class MusicBrainzApi {
263
262
  csrf: MusicBrainzApi.fetchCsrf(response.body)
264
263
  };
265
264
  }
265
+ async applyRateLimiter() {
266
+ if (!this.config.disableRateLimiting) {
267
+ const delay = await this.rateLimiter.limit();
268
+ debug(`Client side rate limiter activated: cool down for ${Math.round(delay / 100) / 10} s...`);
269
+ }
270
+ }
266
271
  }
267
272
  export function makeAndQueryString(keyValuePairs) {
268
273
  return Object.keys(keyValuePairs).map(key => `${key}:"${keyValuePairs[key]}"`).join(' AND ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musicbrainz-api",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "MusicBrainz API client for reading and submitting metadata",
5
5
  "exports": "./lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -65,12 +65,14 @@
65
65
  "@types/jsontoxml": "^1.0.5",
66
66
  "@types/mocha": "^10.0.4",
67
67
  "@types/node": "^22.1.0",
68
+ "@types/sinon": "^17.0.3",
68
69
  "c8": "^10.1.2",
69
70
  "chai": "^5.1.0",
70
71
  "del-cli": "^5.0.0",
71
72
  "mocha": "^10.1.0",
72
73
  "remark-cli": "^12.0.0",
73
74
  "remark-preset-lint-recommended": "^7.0.0",
75
+ "sinon": "^18.0.0",
74
76
  "ts-node": "^10.0.0",
75
77
  "typescript": "^5.0.2"
76
78
  },