musicbrainz-api
Advanced tools
Comparing version 0.6.0 to 0.7.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DigestAuth = void 0; | ||
const uuid = require("uuid/v4"); | ||
const uuid_1 = require("uuid"); | ||
const crypto = require("crypto"); | ||
@@ -53,3 +53,3 @@ function md5(str) { | ||
const nc = qop && '00000001'; | ||
const cnonce = qop && uuid().replace(/-/g, ''); | ||
const cnonce = qop && (0, uuid_1.v4)().replace(/-/g, ''); | ||
const ha1 = DigestAuth.ha1Compute(challenge.algorithm, this.credentials.username, challenge.realm, this.credentials.password, challenge.nonce, cnonce); | ||
@@ -56,0 +56,0 @@ const ha2 = md5(method + ':' + path); // lgtm [js/insufficient-password-hash] |
@@ -155,5 +155,4 @@ export { XmlMetadata } from './xml/xml-metadata'; | ||
searchUrl(query: string | IFormData, offset?: number, limit?: number): Promise<mb.IUrlList>; | ||
private fetchValue; | ||
private getSession; | ||
} | ||
export declare function makeAndQueryString(keyValuePairs: IFormData): string; |
@@ -15,3 +15,3 @@ "use strict"; | ||
const assert = require("assert"); | ||
const HttpStatus = require("http-status-codes"); | ||
const http_status_codes_1 = require("http-status-codes"); | ||
const Url = require("url"); | ||
@@ -43,3 +43,3 @@ const Debug = require("debug"); | ||
const cookieJar = new tough.CookieJar(); | ||
this.getCookies = util_1.promisify(cookieJar.getCookies.bind(cookieJar)); | ||
this.getCookies = (0, util_1.promisify)(cookieJar.getCookies.bind(cookieJar)); | ||
this.options = { | ||
@@ -114,10 +114,10 @@ prefixUrl: this.config.baseUrl, | ||
switch (response.statusCode) { | ||
case HttpStatus.OK: | ||
case http_status_codes_1.StatusCodes.OK: | ||
return response.body; | ||
case HttpStatus.BAD_REQUEST: | ||
case HttpStatus.NOT_FOUND: | ||
throw new Error(`Got response status ${response.statusCode}: ${HttpStatus.getStatusText(response.status)}`); | ||
case HttpStatus.SERVICE_UNAVAILABLE: // 503 | ||
case http_status_codes_1.StatusCodes.BAD_REQUEST: | ||
case http_status_codes_1.StatusCodes.NOT_FOUND: | ||
throw new Error(`Got response status ${response.statusCode}: ${(0, http_status_codes_1.getReasonPhrase)(response.status)}`); | ||
case http_status_codes_1.StatusCodes.SERVICE_UNAVAILABLE: // 503 | ||
default: | ||
const msg = `Got response status ${response.statusCode} on attempt #${attempt} (${HttpStatus.getStatusText(response.status)})`; | ||
const msg = `Got response status ${response.statusCode} on attempt #${attempt} (${(0, http_status_codes_1.getReasonPhrase)(response.status)})`; | ||
debug(msg); | ||
@@ -217,3 +217,3 @@ if (attempt < retries) { | ||
}, body: postData, throwHttpErrors: false }, this.options)); | ||
if (response.statusCode === HttpStatus.UNAUTHORIZED) { | ||
if (response.statusCode === http_status_codes_1.StatusCodes.UNAUTHORIZED) { | ||
// Respond to digest challenge | ||
@@ -252,3 +252,3 @@ const auth = new digest_auth_1.DigestAuth(this.config.botAccount); | ||
}, form: formData }, this.options)); | ||
const success = response.statusCode === HttpStatus.MOVED_TEMPORARILY && response.headers.location === redirectUri; | ||
const success = response.statusCode === http_status_codes_1.StatusCodes.MOVED_TEMPORARILY && response.headers.location === redirectUri; | ||
if (success) { | ||
@@ -267,3 +267,3 @@ this.session.loggedIn = true; | ||
} }, this.options)); | ||
const success = response.statusCode === HttpStatus.MOVED_TEMPORARILY && response.headers.location === redirectUri; | ||
const success = response.statusCode === http_status_codes_1.StatusCodes.MOVED_TEMPORARILY && response.headers.location === redirectUri; | ||
if (success) { | ||
@@ -289,5 +289,5 @@ this.session.loggedIn = true; | ||
const response = await got_1.default.post(`${entity}/${mbid}/edit`, Object.assign({ form: formData, followRedirect: false }, this.options)); | ||
if (response.statusCode === HttpStatus.OK) | ||
if (response.statusCode === http_status_codes_1.StatusCodes.OK) | ||
throw new Error(`Failed to submit form data`); | ||
if (response.statusCode === HttpStatus.MOVED_TEMPORARILY) | ||
if (response.statusCode === http_status_codes_1.StatusCodes.MOVED_TEMPORARILY) | ||
return; | ||
@@ -383,17 +383,2 @@ throw new Error(`Unexpected status code: ${response.statusCode}`); | ||
} | ||
fetchValue(html, key) { | ||
let pos = html.indexOf(`name="${key}"`); | ||
if (pos >= 0) { | ||
pos = html.indexOf('value="', pos + key.length + 7); | ||
if (pos >= 0) { | ||
pos += 7; | ||
const startValuePos = pos + key.length + 15; | ||
if (startValuePos >= 0) { | ||
const endValuePos = html.indexOf('"', startValuePos); | ||
const value = html.substring(startValuePos, endValuePos); | ||
return value; | ||
} | ||
} | ||
} | ||
} | ||
async getSession(url) { | ||
@@ -400,0 +385,0 @@ const response = await got_1.default.get('login', Object.assign({ followRedirect: false, responseType: 'text' }, this.options)); |
@@ -50,2 +50,3 @@ import DateTimeFormat = Intl.DateTimeFormat; | ||
releases?: IRelease[]; | ||
'release-groups'?: IReleaseGroup[]; | ||
} | ||
@@ -52,0 +53,0 @@ export interface IArtistCredit { |
{ | ||
"name": "musicbrainz-api", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "MusicBrainz API client for reading and submitting metadata", | ||
@@ -29,12 +29,12 @@ "main": "lib/musicbrainz-api", | ||
"@types/chai": "^4.2.5", | ||
"@types/mocha": "^7.0.1", | ||
"@types/node": "^14.0.27", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^17.0.8", | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.9", | ||
"del-cli": "^3.0.0", | ||
"mocha": "^8.1.2", | ||
"del-cli": "^4.0.1", | ||
"mocha": "^9.0.1", | ||
"nyc": "^15.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-lint-recommended": "^5.0.0", | ||
"ts-node": "^9.0.0", | ||
"remark-cli": "^10.0.1", | ||
"remark-preset-lint-recommended": "^6.1.2", | ||
"ts-node": "^10.0.0", | ||
"tslint": "^6.1.1", | ||
@@ -56,3 +56,3 @@ "typescript": "^4.0.2" | ||
"@types/request-promise-native": "^1.0.17", | ||
"@types/uuid": "^3.4.6", | ||
"@types/uuid": "^8.3.0", | ||
"caseless": "^0.12.0", | ||
@@ -66,3 +66,3 @@ "debug": "^4.1.1", | ||
"tough-cookie": "^4.0.0", | ||
"uuid": "^3.3.2" | ||
"uuid": "^8.3.2" | ||
}, | ||
@@ -69,0 +69,0 @@ "scripts": { |
@@ -5,5 +5,4 @@ [![Node.js CI](https://github.com/Borewit/musicbrainz-api/actions/workflows/nodejs-ci.yml/badge.svg)](https://github.com/Borewit/musicbrainz-api/actions/workflows/nodejs-ci.yml) | ||
[![Coverage Status](https://coveralls.io/repos/github/Borewit/musicbrainz-api/badge.svg?branch=master)](https://coveralls.io/github/Borewit/musicbrainz-api?branch=master) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5289de6ccf224ca8a94f430f8a9f1784)](https://www.codacy.com/app/Borewit/musicbrainz-augmentation?utm_source=github.com&utm_medium=referral&utm_content=Borewit/musicbrainz-augmentation&utm_campaign=Badge_Grade) | ||
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/2bc47b2006454bae8c737991f152e518)](https://www.codacy.com/gh/Borewit/musicbrainz-api/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Borewit/musicbrainz-api&utm_campaign=Badge_Grade) | ||
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/Borewit/musicbrainz-api.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Borewit/musicbrainz-api/context:javascript) | ||
[![Dependencies](https://david-dm.org/Borewit/musicbrainz-api.svg)](https://david-dm.org/Borewit/musicbrainz-api) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/Borewit/musicbrainz-api/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/musicbrainz-api?targetFile=package.json) | ||
@@ -151,4 +150,25 @@ [![Total alerts](https://img.shields.io/lgtm/alerts/g/Borewit/musicbrainz-api.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Borewit/musicbrainz-api/alerts/) | ||
Searches can be performed using the generic search function: `query(entity: mb.EntityType, query: string | IFormData, offset?: number, limit?: number)`: | ||
Searches can be performed using the generic search function: `query(entity: mb.EntityType, query: string | IFormData, offset?: number, limit?: number)` | ||
Arguments: | ||
* Entity type, which can be one of: | ||
* `artist`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Artist) | ||
* `label`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Label) | ||
* `recording`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Recording) | ||
* `release`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Release) | ||
* `release-group`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Release_Group) | ||
* `work`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Work) | ||
* `area`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Area) | ||
* `url`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#URL) | ||
* `query {query: string, offset: number, limit: number}` | ||
* `query.query`: supports the full Lucene Search syntax; you can find a detailed guide at [Lucene Search Syntax](https://lucene.apache.org/core/4_3_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description). For example, you can set conditions while searching for a name with the AND operator. | ||
* `query.offset`: optional, return search results starting at a given offset. Used for paging through more than one page of results. | ||
* `limit.query`: optional, an integer value defining how many entries should be returned. Only values between 1 and 100 (both inclusive) are allowed. If not given, this defaults to 25. | ||
For example, to find any recordings of _'We Will Rock You'_ by Queen: | ||
```javascript | ||
const query = 'query="We Will Rock You" AND arid:0383dadf-2a4e-4d10-a46a-e9e041da8eb3'; | ||
const result = await mbApi.query<mb.IReleaseGroupList>('release-group', {query}); | ||
``` | ||
##### Example: search Île-de-France | ||
@@ -182,25 +202,2 @@ | ||
Arguments: | ||
* Entity type, which can be one of: | ||
* `artist`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Artist) | ||
* `label`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Label) | ||
* `recording`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Recording) | ||
* `release`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Release) | ||
* `release-group`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Release_Group) | ||
* `work`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Work) | ||
* `area`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#Area) | ||
* `url`: [search fields](https://wiki.musicbrainz.org/Development/XML_Web_Service/Version_2/Search#URL) | ||
* `query {query: string, offset: number, limit: number}` | ||
* `query.query`: supports the full Lucene Search syntax; you can find a detailed guide at [Lucene Search Syntax](https://lucene.apache.org/core/4_3_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description). For example, you can set conditions while searching for a name with the AND operator. | ||
* `query.offset`: optional, return search results starting at a given offset. Used for paging through more than one page of results. | ||
* `limit.query`: optional, an integer value defining how many entries should be returned. Only values between 1 and 100 (both inclusive) are allowed. If not given, this defaults to 25. | ||
For example, to find any recordings of _'We Will Rock You'_ by Queen: | ||
```javascript | ||
const query = 'query="We Will Rock You" AND arid:0383dadf-2a4e-4d10-a46a-e9e041da8eb3'; | ||
const result = await mbApi.query<mb.IReleaseGroupList>('release-group', {query}); | ||
``` | ||
## Specialized search functions | ||
Search artist: | ||
@@ -207,0 +204,0 @@ ```javascript |
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
445837
35
1132
1
285
+ Added@types/uuid@8.3.4(transitive)
+ Addeduuid@8.3.2(transitive)
- Removed@types/uuid@3.4.13(transitive)
- Removeduuid@3.4.0(transitive)
Updated@types/uuid@^8.3.0
Updateduuid@^8.3.2