/**
* Creates a new `kitsu` instance
*
* @param {Object} [options] Options
* @param {string} [options.baseURL='https://kitsu.app/api/edge'] Set the API endpoint
* @param {Object} [options.headers] Additional headers to send with the requests
* @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 {boolean} [options.camelCaseTypes=true] If enabled, `type` will be converted to camelCase from kebab-casae or snake_case
* @param {'kebab'|'snake'|'none'} [options.resourceCase=kebab] Case to convert camelCase to. `kebab` - `/library-entries`; `snake` - /library_entries`; `none` - `/libraryEntries`
* @param {boolean} [options.pluralize=true] If enabled, `/user` will become `/users` in the URL request and `type` will be pluralized in POST, PATCH and DELETE requests
* @param {number} [options.timeout=30000] Set the request timeout in milliseconds
* @param {Object} [options.axiosOptions] Additional options for the axios instance (see [axios/axios#request-config](https://github.com/axios/axios#request-config) for details)
* @param {boolean} [options.hoistData=false] If enabled, the contents of the `data` property will be hoisted to the parent. This provides a flatter response object, but removes access to `links` and `meta` properties. It will transform:
* ```js
* { data: { id: '1', type: 'people', coworkers: data: [ { id: '2', type: 'people' } ] } }
* ```
* into the following:
* ```js
* { id: '1', type: 'people', coworkers: [ { id: '2', type: 'people' } ] }
* ```
* @example
Using with kitsu.app's API
* const api = new Kitsu()
* @example
Using another API server
* const api = new Kitsu({
* baseURL: 'https://api.example.org/2'
* })
* @example
Setting headers
* const api = new Kitsu({
* headers: {
* 'User-Agent': 'MyApp/1.0.0 (github.com/username/repo)',
* Authorization: 'Bearer 1234567890'
* }
* })
*/
export default class Kitsu {
constructor(options?: {});
query: any;
camel: (s: any) => any;
resCase: (s: any) => any;
plural: any;
/**
* Get the current headers or add additional headers
*
* @memberof Kitsu
* @returns {Object} All the current headers
* @example
Get all headers
* api.headers
* @example
Get a single header's value
* api.headers['User-Agent']
* @example
Add or update a header's value
* api.headers['Authorization'] = 'Bearer 1234567890'
*/
headers: any;
axios: import("axios").AxiosInstance;
hoistData: any;
fetch: (model: string, config?: {
headers?: any;
params?: {
fields?: any;
filter?: any;
include?: string;
sort?: string;
page?: {
limit?: number;
offset?: number;
number?: number;
size?: number;
before?: string;
after?: string;
};
};
axiosOptions?: any;
}) => Promise;
update: (model: string, body: any | any[], config?: {
params?: any;
headers?: any;
axiosOptions?: any;
}) => Promise;
create: (model: string, body: any | any[], config?: {
params?: any;
headers?: any;
axiosOptions?: any;
}) => Promise;
remove: (model: string, id: string | number | number[], config?: {
params?: any;
headers?: any;
axiosOptions?: any;
}) => Promise;
/**
* Axios Interceptors (alias of `axios.interceptors`)
*
* You can intercept responses before they are handled by `get`, `post`, `patch` and `delete` and before requests are sent to the API server.
*
* @memberof Kitsu
* @see {@link https://github.com/axios/axios#interceptors} for documentation
* @example
Request Interceptor
* // Add a request interceptor
* api.interceptors.request.use(config => {
* // Do something before request is sent
* return config
* }, error => {
* // Do something with the request error
* return Promise.reject(error)
* })
* @example
Response Interceptor
* // Add a response interceptor
* api.interceptors.response.use(response => {
* // Any status code that lie within the range of 2xx cause this function to trigger
* // Do something with response data
* return response
* }, error => {
* // Any status codes that falls outside the range of 2xx cause this function to trigger
* // Do something with response error
* return Promise.reject(error)
* })
* @example
Removing Interceptors
* const myInterceptor = api.interceptors.request.use(function () {...})
* api.interceptors.request.eject(myInterceptor)
*/
interceptors: {
request: import("axios").AxiosInterceptorManager;
response: import("axios").AxiosInterceptorManager;
};
/**
* Fetch resources (alias `fetch`)
*
* @memberof Kitsu
* @param {string} model Resource to fetch data from. Expected formats are [`:resource`](https://jsonapi.org/format/#document-resource-objects), [`:resource/:id`](https://jsonapi.org/format/#document-resource-objects), [`:resource/:id/:relationship`](https://jsonapi.org/format/#document-resource-object-relationships) or [`:resource/:id/relationships/:relationship`](https://jsonapi.org/format/#document-resource-object-linkage)
* @param {Object} [config] Additional configuration
* @param {Object} [config.headers] Additional headers to send with the request
* @param {Object} [config.params] JSON:API request queries. JSON:API query parameters not listed are supported
* @param {Object} [config.params.fields] Return a sparse fieldset with only the included attributes/relationships - [JSON:API Sparse Fieldsets](http://jsonapi.org/format/#fetching-sparse-fieldsets)
* @param {Object} [config.params.filter] Filter dataset by attribute values - [JSON:API Filtering](http://jsonapi.org/format/#fetching-filtering)
* @param {string} [config.params.include] Include relationship data - [JSON:API Includes](http://jsonapi.org/format/#fetching-includes)
* @param {string} [config.params.sort] Sort dataset by one or more comma separated attributes (prepend `-` for descending order) - [JSON:API Sorting](http://jsonapi.org/format/#fetching-sorting)
* @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.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.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)
* @returns {Promise