Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Releases: Kinto/kinto-http.js

v2.5.1

16 Sep 09:31
0a55d52
Compare
Choose a tag to compare
  • Aggregated batch: provide id and path in objects provided in skipped attribute (#140)
  • Fix docs about client instantiation

v2.5.0

01 Sep 09:03
Compare
Choose a tag to compare
  • Fix #135: Allow retrieval of collection total number of records. (#136)
  • Improve HTTP 412 error message. (#137)

v2.4.1

31 Aug 13:53
Compare
Choose a tag to compare
  • Fix #129: Join multiple same-key parameters with a comma (#134)

v2.4.0

25 Aug 11:46
Compare
Choose a tag to compare
  • Expose a hasNextPage property to the list results object. (#131)

v2.3.0

23 Aug 11:16
Compare
Choose a tag to compare
  • Add listHistory() on buckets (#125)

Listing bucket history

client.bucket("blog").listHistory()
  .then(({data}) => ...);

Sample result:

{
  "data": [
    {
      "action": "update",
      "collection_id": "articles",
      "date": "2016-07-20T11:18:36.530281",
      "id": "cb98ecd7-a66f-4f9d-82c5-73d06930f4f2",
      "last_modified": 1469006316530,
      "record_id": "b3b76c56-b6df-4195-8189-d79da4a128e1",
      "resource_name": "record",
      "target": {
          "data": {
              "id": "b3b76c56-b6df-4195-8189-d79da4a128e1",
              "last_modified": 1469006316529,
              "title": "Modified title"
          },
          "permissions": {
              "write": [
                  "basicauth:43181ac0ae7581a23288c25a98786ef9db86433c62a04fd6071d11653ee69089"
              ]
          }
      },
      "timestamp": 1469006098757,
      "uri": "/buckets/blog/collections/articles/records/b3b76c56-b6df-4195-8189-d79da4a128e1",
      "user_id": "basicauth:43181ac0ae7581a23288c25a98786ef9db86433c62a04fd6071d11653ee69089",
    }
  ]
}

Options

  • headers: Custom headers object to send along the HTTP request

This method accepts the generic parameters for sorting, filtering and paginating results.

v2.2.1

22 Aug 14:02
Compare
Choose a tag to compare
  • Fix #124: Fixed error where the client was trying to consume HTTP headers from fake batch responses. (#126)

v2.2.0

21 Jul 09:20
Compare
Choose a tag to compare

New features

  • Add support for the /permissions endpoint (#123)
  • Generalize list signatures (#116)

Listing all resource permissions

If the permissions_endpoint capability is installed on the server, you can retrieve the list of all permissions set for the authenticated user using the listPermissions() method:

client.listPermissions([options])
  .then(result => ...);

Sample result:

{
  "data": [
    {
      "bucket_id": "mybucket",
      "id": "mybucket",
      "permissions": [
        "write",
        "read",
        "group:create",
        "collection:create"
      ],
      "resource_name": "bucket",
      "uri": "/buckets/mybucket"
    },
    ...
  ]
}

Generic options for list operations

Every list operations like listBuckets(), listCollections, listGroups() or listRecords() accept parameters to sort, filter and paginate the results:

  • sort: The order field (default: -last_modified);
  • pages: The number of result pages to retrieve (default: 1);
  • limit: The number of records to retrieve per page: unset by default, uses default server configuration;
  • filters: An object defining the filters to apply; read more about what's supported;
  • since: The ETag header value received from the last response from the server.

Sorting

By default, results are listed by last_modified descending order. You can set the sort option to order by another field:

client.bucket("blog").collection("posts")
  .listRecords({sort: "title"})
  .then(({data, next}) => {

Polling for changes

To retrieve the results modified since a given timestamp, use the since option:

client.bucket("blog").collection("posts")
  .listRecords({since: "1456183930780"})
  .then(({data, next}) => {

Paginating results

By default, all results of the first page are retrieved, and the default configuration of the server defines no limit. To specify a max number of results to retrieve, you can use the limit option:

client.bucket("blog").collection("posts")
  .listRecords({limit: 20})
  .then(({data, next}) => {

To retrieve the next page of results, just call next() from the result object obtained. If no next page is available, next() throws an error you can catch to exit the flow:

let getNextPage;

client.bucket("blog").collection("posts")
  .listRecords({limit: 20})
  .then(({data, next}) => {
    console.log("Page 1", data);
    getNextPage = next;
  });

Later down the flow:

getNextPage()
  .then(({data, next}) => {
    console.log("Page 2", data);
  })
  .catch(_ => {
    console.log("No more pages.");
  });

Last, if you just want to retrieve and aggregate a given number of result pages, instead of dealing with calling next() recursively you can simply specify the pages option:

client.bucket("blog").collection("posts")
  .listRecords({limit: 20, pages: 3})
  .then(({data, next}) => ...); // A maximum of 60 results will be retrieved here
Notes

If you plan on fetching all the available pages, you can set the pages option to Infinity. Be aware that for large datasets this strategy can possibly issue an important amount of HTTP requests.

v2.1.1

19 Jul 07:50
Compare
Choose a tag to compare
  • Fix #119: Ensure sending a multipart Content-Type header along attachments. (#120)

v2.1.0

18 Jul 17:13
Compare
Choose a tag to compare
  • Added support for the Kinto attachments API. (#115)

Attachments

If the attachment capability is available from the Kinto server, you can attach files to records. Files must be passed as data urls, which can be generated using the FileReader API in the browser.

Adding an attachment to a record

client.bucket("blog").collection("posts")
  .addAttachment(dataURL, {title: "First post"});

Options

  • headers: Custom headers object to send along the HTTP request;
  • safe: Ensures operations won't override existing resources on the server if their associated last_modified value or option are provided; otherwise ensures resources won't be overriden if they already exist on the server;
  • last_modified: When safe is true, the last timestamp we know the resource has been updated on the server;
  • permissions: Permissions to be set on the record;
  • filename: Allows to specify the attachment filename, in case the data URI does not contain any, or if the file has to be renamed on upload;

Updating an attachment

client.bucket("blog").collection("posts")
  .addAttachment(dataURL, {id: "22c1319e-7b09-46db-bec4-c240bdf4e3e9"});

Deleting an attachment

client.bucket("blog").collection("posts")
  .removeAttachment("22c1319e-7b09-46db-bec4-c240bdf4e3e9");

v2.0.0

27 Jun 21:27
Compare
Choose a tag to compare

Breaking changes

  • Remove quotes from last_modified attribute in listRecords() result (fixes #109) (#110)
  • Expose KintoClient() constructor in browserify builds (fixes #77) (#105)

New features

  • Add hint when server is readonly (fixes #56) (#106)