Comparing version 10.1.5 to 10.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [10.2.0](https://github.com/wopian/kitsu/compare/v10.1.5...v10.2.0) (2025-01-03) | ||
### Features | ||
* add http status code to kitsu responses ([#1041](https://github.com/wopian/kitsu/issues/1041)) ([9244269](https://github.com/wopian/kitsu/commit/9244269d408214c142bbc6840300b84e3b4ee987)) | ||
## [10.1.5](https://github.com/wopian/kitsu/compare/v10.1.4...v10.1.5) (2024-03-30) | ||
@@ -8,0 +19,0 @@ |
@@ -13,4 +13,3 @@ 'use strict'; | ||
class Kitsu { | ||
constructor() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
constructor(options = {}) { | ||
const traditional = typeof options.query === 'string' ? options.query === 'traditional' : true; | ||
@@ -30,3 +29,3 @@ this.query = typeof options.query === 'function' ? options.query : obj => kitsuCore.query(obj, null, traditional); | ||
...{ | ||
baseURL: options.baseURL || 'https://kitsu.io/api/edge', | ||
baseURL: options.baseURL || 'https://kitsu.app/api/edge', | ||
timeout: options.timeout || 30000 | ||
@@ -45,4 +44,3 @@ }, | ||
} | ||
async get(model) { | ||
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
async get(model, config = {}) { | ||
try { | ||
@@ -64,3 +62,4 @@ const headers = { | ||
data, | ||
headers: responseHeaders | ||
headers: responseHeaders, | ||
status | ||
} = await this.axios.get(url, { | ||
@@ -71,8 +70,9 @@ headers, | ||
}); | ||
return responseHeaders ? { | ||
return { | ||
...kitsuCore.deserialise(data), | ||
...{ | ||
status, | ||
...(responseHeaders ? { | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} : {}) | ||
}; | ||
} catch (E) { | ||
@@ -82,4 +82,3 @@ throw kitsuCore.error(E); | ||
} | ||
async patch(model, body) { | ||
let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
async patch(model, body, config = {}) { | ||
try { | ||
@@ -105,3 +104,4 @@ const headers = { | ||
data, | ||
headers: responseHeaders | ||
headers: responseHeaders, | ||
status | ||
} = await this.axios.patch(fullURL, serialData, { | ||
@@ -112,8 +112,9 @@ headers, | ||
}); | ||
return responseHeaders ? { | ||
return { | ||
...kitsuCore.deserialise(data), | ||
...{ | ||
status, | ||
...(responseHeaders ? { | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} : {}) | ||
}; | ||
} catch (E) { | ||
@@ -123,4 +124,3 @@ throw kitsuCore.error(E); | ||
} | ||
async post(model, body) { | ||
let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
async post(model, body, config = {}) { | ||
try { | ||
@@ -141,3 +141,4 @@ const headers = { | ||
data, | ||
headers: responseHeaders | ||
headers: responseHeaders, | ||
status | ||
} = await this.axios.post(url, kitsuCore.serialise(resourceModel, body, 'POST', { | ||
@@ -151,8 +152,9 @@ camelCaseTypes: this.camel, | ||
}); | ||
return responseHeaders ? { | ||
return { | ||
...kitsuCore.deserialise(data), | ||
...{ | ||
status, | ||
...(responseHeaders ? { | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} : {}) | ||
}; | ||
} catch (E) { | ||
@@ -162,4 +164,3 @@ throw kitsuCore.error(E); | ||
} | ||
async delete(model, id) { | ||
let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
async delete(model, id, config = {}) { | ||
try { | ||
@@ -193,3 +194,4 @@ const headers = { | ||
data, | ||
headers: responseHeaders | ||
headers: responseHeaders, | ||
status | ||
} = await this.axios.delete(path, { | ||
@@ -204,8 +206,9 @@ data: kitsuCore.serialise(resourceModel, payload, 'DELETE', { | ||
}); | ||
return responseHeaders ? { | ||
return { | ||
...kitsuCore.deserialise(data), | ||
...{ | ||
status, | ||
...(responseHeaders ? { | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} : {}) | ||
}; | ||
} catch (E) { | ||
@@ -215,4 +218,3 @@ throw kitsuCore.error(E); | ||
} | ||
async self() { | ||
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
async self(config = {}) { | ||
try { | ||
@@ -254,12 +256,11 @@ const headers = { | ||
} | ||
async request(_ref) { | ||
let { | ||
body, | ||
method, | ||
params, | ||
type, | ||
url, | ||
headers, | ||
axiosOptions | ||
} = _ref; | ||
async request({ | ||
body, | ||
method, | ||
params, | ||
type, | ||
url, | ||
headers, | ||
axiosOptions | ||
}) { | ||
try { | ||
@@ -270,3 +271,4 @@ var _method; | ||
data, | ||
headers: responseHeaders | ||
headers: responseHeaders, | ||
status | ||
} = await this.axios.request({ | ||
@@ -286,8 +288,9 @@ method, | ||
}); | ||
return responseHeaders ? { | ||
return { | ||
...kitsuCore.deserialise(data), | ||
...{ | ||
status, | ||
...(responseHeaders ? { | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} : {}) | ||
}; | ||
} catch (E) { | ||
@@ -294,0 +297,0 @@ throw kitsuCore.error(E); |
{ | ||
"version": "10.1.5", | ||
"version": "10.2.0", | ||
"name": "kitsu", | ||
@@ -29,3 +29,3 @@ "description": "A simple, lightweight & framework agnostic JSON:API client using Axios", | ||
"kitsu", | ||
"kitsu.io", | ||
"kitsu.app", | ||
"anime", | ||
@@ -53,4 +53,4 @@ "manga", | ||
"dependencies": { | ||
"axios": "^0.28.1", | ||
"kitsu-core": "^10.1.5", | ||
"axios": "^0.29.0", | ||
"kitsu-core": "^10.2.0", | ||
"pluralize": "^8.0.0" | ||
@@ -57,0 +57,0 @@ }, |
@@ -119,3 +119,3 @@ <h1 align=center>Kitsu</h1> | ||
```javascript | ||
// Kitsu.io's API | ||
// kitsu.app's API | ||
const api = new Kitsu() | ||
@@ -177,3 +177,3 @@ | ||
If you're working with [Kitsu.io]'s API, their [API docs][kitsu.io api docs] lists all available resources with their attributes & relationships | ||
If you're working with [kitsu.app]'s API, their [API docs][kitsu.app api docs] lists all available resources with their attributes & relationships | ||
@@ -192,3 +192,3 @@ ## Contributing | ||
[kitsu.io]: https://kitsu.io | ||
[kitsu.app]: https://kitsu.app | ||
@@ -201,3 +201,3 @@ [json:api]: http://jsonapi.org | ||
[kitsu.io api docs]: https://kitsu.docs.apiary.io | ||
[kitsu.app api docs]: https://kitsu.docs.apiary.io | ||
@@ -248,3 +248,3 @@ [migration guide]: https://github.com/wopian/kitsu/blob/master/packages/kitsu/MIGRATING.md | ||
[packages/kitsu/src/index.js:31-532](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L31-L532 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:31-532](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L31-L532 "Source code on GitHub") | ||
@@ -257,3 +257,3 @@ Creates a new `kitsu` instance | ||
* `options.baseURL` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Set the API endpoint (optional, default `https://kitsu.io/api/edge`) | ||
* `options.baseURL` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Set the API endpoint (optional, default `https://kitsu.app/api/edge`) | ||
* `options.headers` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Additional headers to send with the requests | ||
@@ -269,3 +269,3 @@ * `options.query` **(`"traditional"` | `"modern"` | [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** Query serializer function to use. This will impact the way keys are serialized when passing arrays as query parameters. 'modern' is recommended for new projects. (optional, default `traditional`) | ||
Using with Kitsu.io's API | ||
Using with kitsu.app's API | ||
@@ -297,3 +297,3 @@ ```javascript | ||
[packages/kitsu/src/index.js:58-59](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L58-L59 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:58-59](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L58-L59 "Source code on GitHub") | ||
@@ -317,3 +317,3 @@ * **See**: <https://www.npmjs.com/package/pluralize> for documentation | ||
[packages/kitsu/src/index.js:73-73](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L73-L73 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:73-73](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L73-L73 "Source code on GitHub") | ||
@@ -346,3 +346,3 @@ Get the current headers or add additional headers | ||
[packages/kitsu/src/index.js:120-120](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L120-L120 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:120-120](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L120-L120 "Source code on GitHub") | ||
@@ -394,3 +394,3 @@ * **See**: <https://github.com/axios/axios#interceptors> for documentation | ||
[packages/kitsu/src/index.js:218-246](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L218-L246 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:218-246](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L218-L246 "Source code on GitHub") | ||
@@ -413,8 +413,8 @@ Fetch resources (alias `fetch`) | ||
* `config.params.page.limit` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Number of resources to return in request (Offset-based) - **Note:** For Kitsu.io, max is `20` except on `libraryEntries` which has a max of `500` | ||
* `config.params.page.limit` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Number of resources to return in request (Offset-based) - **Note:** For kitsu.app, max is `20` except on `libraryEntries` which has a max of `500` | ||
* `config.params.page.offset` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Number of resources to offset the dataset by (Offset-based) | ||
* `config.params.page.number` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Page of resources to return in request (Page-based) - **Note:** Not supported on Kitsu.io | ||
* `config.params.page.size` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Number of resources to return in request (Page-based and cursor-based) - **Note:** Not supported on Kitsu.io | ||
* `config.params.page.before` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Get the previous page of resources (Cursor-based) - **Note:** Not Supported on Kitsu.io | ||
* `config.params.page.after` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Get the next page of resources (Cursor-based) - **Note:** Not Supported on Kitsu.io | ||
* `config.params.page.number` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Page of resources to return in request (Page-based) - **Note:** Not supported on kitsu.app | ||
* `config.params.page.size` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Number of resources to return in request (Page-based and cursor-based) - **Note:** Not supported on kitsu.app | ||
* `config.params.page.before` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Get the previous page of resources (Cursor-based) - **Note:** Not Supported on kitsu.app | ||
* `config.params.page.after` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Get the next page of resources (Cursor-based) - **Note:** Not Supported on kitsu.app | ||
* `config.axiosOptions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Additional options for the axios instance (see [axios/axios#request-config](https://github.com/axios/axios#request-config) for details) | ||
@@ -476,3 +476,3 @@ | ||
Getting a resource with nested JSON:API filters (not supported by Kitsu.io's API) | ||
Getting a resource with nested JSON:API filters (not supported by kitsu.app's API) | ||
@@ -534,3 +534,3 @@ ```javascript | ||
[packages/kitsu/src/index.js:282-309](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L282-L309 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:282-309](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L282-L309 "Source code on GitHub") | ||
@@ -597,3 +597,3 @@ Update a resource (alias `update`) | ||
[packages/kitsu/src/index.js:344-369](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L344-L369 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:344-369](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L344-L369 "Source code on GitHub") | ||
@@ -647,3 +647,3 @@ Create a new resource (alias `create`) | ||
[packages/kitsu/src/index.js:389-422](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L389-L422 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:389-422](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L389-L422 "Source code on GitHub") | ||
@@ -686,3 +686,3 @@ Remove a resource (alias `remove`) | ||
[packages/kitsu/src/index.js:446-455](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L446-L455 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:446-455](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L446-L455 "Source code on GitHub") | ||
@@ -725,3 +725,3 @@ Get the authenticated user's data | ||
[packages/kitsu/src/index.js:510-531](https://github.com/wopian/kitsu/blob/ac2311858c29afa9c31f9fe6a68474a6edf853c7/packages/kitsu/src/index.js#L510-L531 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:510-531](https://github.com/wopian/kitsu/blob/9244269d408214c142bbc6840300b84e3b4ee987/packages/kitsu/src/index.js#L510-L531 "Source code on GitHub") | ||
@@ -728,0 +728,0 @@ Send arbitrary requests |
@@ -5,3 +5,3 @@ /** | ||
* @param {Object} [options] Options | ||
* @param {string} [options.baseURL=https://kitsu.io/api/edge] Set the API endpoint | ||
* @param {string} [options.baseURL=https://kitsu.app/api/edge] Set the API endpoint | ||
* @param {Object} [options.headers] Additional headers to send with the requests | ||
@@ -14,3 +14,3 @@ * @param {'traditional'|'modern'|Function} [options.query=traditional] Query serializer function to use. This will impact the way keys are serialized when passing arrays as query parameters. 'modern' is recommended for new projects. | ||
* @param {Object} [options.axiosOptions] Additional options for the axios instance (see [axios/axios#request-config](https://github.com/axios/axios#request-config) for details) | ||
* @example <caption>Using with Kitsu.io's API</caption> | ||
* @example <caption>Using with kitsu.app's API</caption> | ||
* const api = new Kitsu() | ||
@@ -114,4 +114,4 @@ * @example <caption>Using another API server</caption> | ||
interceptors: { | ||
request: import("axios").AxiosInterceptorManager<import("axios").AxiosRequestConfig<any>>; | ||
response: import("axios").AxiosInterceptorManager<import("axios").AxiosResponse<any, any>>; | ||
request: import("axios").AxiosInterceptorManager<import("axios").AxiosRequestConfig>; | ||
response: import("axios").AxiosInterceptorManager<import("axios").AxiosResponse>; | ||
}; | ||
@@ -131,8 +131,8 @@ /** | ||
* @param {Object} [config.params.page] [JSON:API Pagination](http://jsonapi.org/format/#fetching-pagination). All pagination strategies are supported, even if they are not listed below. | ||
* @param {number} [config.params.page.limit] Number of resources to return in request (Offset-based) - **Note:** For Kitsu.io, max is `20` except on `libraryEntries` which has a max of `500` | ||
* @param {number} [config.params.page.limit] Number of resources to return in request (Offset-based) - **Note:** For kitsu.app, max is `20` except on `libraryEntries` which has a max of `500` | ||
* @param {number} [config.params.page.offset] Number of resources to offset the dataset by (Offset-based) | ||
* @param {number} [config.params.page.number] Page of resources to return in request (Page-based) - **Note:** Not supported on Kitsu.io | ||
* @param {number} [config.params.page.size] Number of resources to return in request (Page-based and cursor-based) - **Note:** Not supported on Kitsu.io | ||
* @param {string} [config.params.page.before] Get the previous page of resources (Cursor-based) - **Note:** Not Supported on Kitsu.io | ||
* @param {string} [config.params.page.after] Get the next page of resources (Cursor-based) - **Note:** Not Supported on Kitsu.io | ||
* @param {number} [config.params.page.number] Page of resources to return in request (Page-based) - **Note:** Not supported on kitsu.app | ||
* @param {number} [config.params.page.size] Number of resources to return in request (Page-based and cursor-based) - **Note:** Not supported on kitsu.app | ||
* @param {string} [config.params.page.before] Get the previous page of resources (Cursor-based) - **Note:** Not Supported on kitsu.app | ||
* @param {string} [config.params.page.after] Get the next page of resources (Cursor-based) - **Note:** Not Supported on kitsu.app | ||
* @param {Object} [config.axiosOptions] Additional options for the axios instance (see [axios/axios#request-config](https://github.com/axios/axios#request-config) for details) | ||
@@ -172,3 +172,3 @@ * @returns {Object} JSON-parsed response | ||
* api.get('anime/2/categories') | ||
* @example <caption>Getting a resource with nested JSON:API filters (not supported by Kitsu.io's API)</caption> | ||
* @example <caption>Getting a resource with nested JSON:API filters (not supported by kitsu.app's API)</caption> | ||
* // resource?filter[x][y]=value | ||
@@ -175,0 +175,0 @@ * api.get('resource', { |
Sorry, the diff of this file is not supported yet
975
88722
+ Addedaxios@0.29.0(transitive)
- Removedaxios@0.28.1(transitive)
Updatedaxios@^0.29.0
Updatedkitsu-core@^10.2.0