KintoClientBase
Direct Subclass:
High level HTTP client for the Kinto API.
Example:
const client = new KintoClient("https://kinto.dev.mozaws.net/v1");
client.bucket("default")
.collection("my-blog")
.createRecord({title: "First article"})
.then(console.log.bind(console))
.catch(console.error.bind(console));
Constructor Summary
Public Constructor | ||
public |
constructor(remote: String, options: Object) Constructor. |
Member Summary
Public Members | ||
public get |
backoff: Number Backoff remaining time, in milliseconds. |
|
public get |
remote: String The remote endpoint base URL. |
|
public get |
version: String The current server protocol version, eg. |
Private Members | ||
private |
|
|
private |
_headers: * |
|
private |
_isBatch: * |
|
private |
_remote: * |
|
private |
_requests: *[] |
|
private |
_retry: * |
|
private |
_safe: * |
|
private |
_version: * |
Method Summary
Public Methods | ||
public |
Retrieve a bucket object to perform operations on it. |
|
public |
async createBucket(id: String | null, options: Object): Promise<Object, Error> Creates a new bucket on the server. |
|
public |
async fetchHTTPApiVersion(options: Object): Promise<Object, Error> Retrieve authenticated user information. |
|
public |
async fetchServerCapabilities(options: Object): Promise<Object, Error> Retrieve server capabilities information. |
|
public |
async fetchServerInfo(options: Object): Promise<Object, Error> Retrieves server information and persist them locally. |
|
public |
async fetchServerSettings(options: Object): Promise<Object, Error> Retrieves Kinto server settings. |
|
public |
async fetchUser(options: Object): Promise<Object, Error> Retrieve authenticated user information. |
|
public |
async listBuckets(options: Object): Promise<Object[], Error> Retrieves the list of buckets. |
|
public |
async listPermissions(options: Object): Promise<Object[], Error> Lists all permissions. |
|
public |
setHeaders(headers: Object) Set client "headers" for every request, updating previous headers (if any). |
Private Methods | ||
private |
async _batchRequests(requests: Array, options: Object): Promise<Object, Error> Process batch requests, chunking them according to the batch_max_requests server setting when needed. |
|
private |
_getHeaders(options: Object): Object Get the value of "headers" for a given request, merging the per-request headers with our own "default" headers. |
|
private |
async _getHello(options: Object): Promise<Object, Error> Retrieves the server's "hello" endpoint. This endpoint reveals server capabilities and settings as well as telling the client "who they are" according to their given authorization headers. |
|
private |
_getRetry(options: *): * As _getSafe, but for "retry". |
|
private |
_getSafe(options: Object): Boolean Get the value of "safe" for a given request, using the per-request option if present or falling back to our default otherwise. |
|
private |
Registers HTTP events. |
|
private |
async execute(request: Object, options: Object): Promise<Object, Error> Executes an atomic HTTP request. |
|
private |
async paginatedList(path: String, params: Object, options: Object): * Fetch some pages from a paginated list, following the |
Public Constructors
public constructor(remote: String, options: Object) source
Constructor.
Params:
Name | Type | Attribute | Description |
remote | String | The remote URL. |
|
options | Object |
|
The options object. |
options.safe | Boolean |
|
Adds concurrency headers to every requests. |
options.events | EventEmitter |
|
The events handler instance. |
options.headers | Object |
|
The key-value headers to pass to each request. |
options.retry | Object |
|
Number of retries when request fails (default: 0) |
options.bucket | String |
|
The default bucket to use. |
options.requestMode | String |
|
The HTTP request mode (from ES6 fetch spec). |
options.timeout | Number |
|
The request timeout in ms, if any. |
Public Members
public get backoff: Number source
Backoff remaining time, in milliseconds. Defaults to zero if no backoff is ongoing.
public get remote: String source
The remote endpoint base URL. Setting the value will also extract and validate the version.
Private Members
private _backoffReleaseTime: * source
private _headers: * source
private _isBatch: * source
private _remote: * source
private _requests: *[] source
private _retry: * source
private _safe: * source
private _version: * source
Public Methods
public bucket(name: String, options: Object): Bucket source
Retrieve a bucket object to perform operations on it.
Params:
Name | Type | Attribute | Description |
name | String | The bucket name. |
|
options | Object |
|
The request options. |
options.safe | Boolean |
|
The resulting safe option. |
options.retry | Number |
|
The resulting retry option. |
options.headers | Object |
|
The extended headers object option. |
Test:
public async createBucket(id: String | null, options: Object): Promise<Object, Error> source
Creates a new bucket on the server.
Params:
Name | Type | Attribute | Description |
id | String | null | The bucket name (optional). |
|
options | Object |
|
The options object. |
options.data | Boolean |
|
The bucket data option. |
options.safe | Boolean |
|
The safe option. |
options.headers | Object |
|
The headers object option. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object, Error> |
public async fetchHTTPApiVersion(options: Object): Promise<Object, Error> source
Retrieve authenticated user information.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The request options. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object, Error> |
Decorators:
- nobatch("This operation is not supported within a batch operation.")
public async fetchServerCapabilities(options: Object): Promise<Object, Error> source
Retrieve server capabilities information.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The request options. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object, Error> |
Decorators:
- nobatch("This operation is not supported within a batch operation.")
public async fetchServerInfo(options: Object): Promise<Object, Error> source
Retrieves server information and persist them locally. This operation is usually performed a single time during the instance lifecycle.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The request options. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object, Error> |
public async fetchServerSettings(options: Object): Promise<Object, Error> source
Retrieves Kinto server settings.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The request options. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object, Error> |
Decorators:
- nobatch("This operation is not supported within a batch operation.")
public async fetchUser(options: Object): Promise<Object, Error> source
Retrieve authenticated user information.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The request options. |
options.headers | Object |
|
Headers to use when making this request. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object, Error> |
Decorators:
- nobatch("This operation is not supported within a batch operation.")
Test:
public async listBuckets(options: Object): Promise<Object[], Error> source
Retrieves the list of buckets.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The options object. |
options.headers | Object |
|
Headers to use when making this request. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object[], Error> |
public async listPermissions(options: Object): Promise<Object[], Error> source
Lists all permissions.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The options object. |
options.headers | Object |
|
Headers to use when making this request. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object[], Error> |
Decorators:
- capable(["permissions_endpoint"])
public setHeaders(headers: Object) source
Set client "headers" for every request, updating previous headers (if any).
Params:
Name | Type | Attribute | Description |
headers | Object | The headers to merge with existing ones. |
Test:
Private Methods
private async _batchRequests(requests: Array, options: Object): Promise<Object, Error> source
Process batch requests, chunking them according to the batch_max_requests server setting when needed.
Params:
Name | Type | Attribute | Description |
requests | Array | The list of batch subrequests to perform. |
|
options | Object |
|
The options object. |
Return:
Promise<Object, Error> |
private _getHeaders(options: Object): Object source
Get the value of "headers" for a given request, merging the per-request headers with our own "default" headers.
Note that unlike other options, headers aren't overridden, but merged instead.
Params:
Name | Type | Attribute | Description |
options | Object | The options for a request. |
Return:
Object |
private async _getHello(options: Object): Promise<Object, Error> source
Retrieves the server's "hello" endpoint. This endpoint reveals server capabilities and settings as well as telling the client "who they are" according to their given authorization headers.
Params:
Name | Type | Attribute | Description |
options | Object |
|
The request options. |
options.headers | Object |
|
Headers to use when making this request. |
options.retry | Number |
|
Number of retries to make when faced with transient errors. |
Return:
Promise<Object, Error> |
private _getRetry(options: *): * source
As _getSafe, but for "retry".
Params:
Name | Type | Attribute | Description |
options | * |
Return:
* |
private _getSafe(options: Object): Boolean source
Get the value of "safe" for a given request, using the per-request option if present or falling back to our default otherwise.
Params:
Name | Type | Attribute | Description |
options | Object | The options for a request. |
Return:
Boolean |
private async execute(request: Object, options: Object): Promise<Object, Error> source
Executes an atomic HTTP request.
Params:
Name | Type | Attribute | Description |
request | Object | The request object. |
|
request.path | String | The path to fetch, relative to the Kinto server root. |
|
request.method | String |
|
The method to use in the request. |
request.body | Body |
|
The request body. |
request.headers | Object |
|
The request headers. |
options | Object |
|
The options object. |
options.raw | Boolean |
|
If true, resolve with full response |
options.stringify | Boolean |
|
If true, serialize body data to |
options.retry | Number |
|
The number of times to retry a request if the server responds with Retry-After. JSON. |
Return:
Promise<Object, Error> |
Test:
private async paginatedList(path: String, params: Object, options: Object): * source
Fetch some pages from a paginated list, following the next-page
header automatically until we have fetched the requested number
of pages. Return a response with a .next()
method that can be
called to fetch more results.
Params:
Name | Type | Attribute | Description |
path | String | The path to make the request to. |
|
params | Object | The parameters to use when making the request. |
|
params.sort | String |
|
The sorting order to use when fetching. |
params.filters | Object |
|
The filters to send in the request. |
params.limit | Number |
|
The limit to send in the request. Undefined means no limit. |
params.pages | Number |
|
The number of pages to fetch. Undefined means one page. Pass Infinity to fetch everything. |
params.since | String |
|
The ETag from which to start fetching. |
options | Object |
|
Additional request-level parameters to use in all requests. |
options.headers | Object |
|
Headers to use during all requests. |
options.retry | Number |
|
Number of times to retry each request if the server responds with Retry-After. |
Return:
* |