Skip to content

Commit

Permalink
Get record: Added deprecated warning for disableRedirect option (apif…
Browse files Browse the repository at this point in the history
  • Loading branch information
drobnikj authored Feb 24, 2021
1 parent a5dfd2d commit c7f05cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.0.6 / NEXT
===================
- Deprecated disableRedirect option for `kvs.setRecord()`

1.0.5 / 2021/02/16
===================
- Fix requests timing out too early due to socket timeouts.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apify-client",
"version": "1.0.5",
"version": "1.0.6",
"description": "Apify API client for JavaScript",
"main": "src/index.js",
"keywords": [
Expand Down
11 changes: 6 additions & 5 deletions src/resource_clients/key_value_store.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const ow = require('ow').default;
const log = require('apify-shared/log');
const ResourceClient = require('../base/resource_client');
const { isBuffer, isStream } = require('../utils');
const {
Expand Down Expand Up @@ -77,7 +78,6 @@ class KeyValueStoreClient extends ResourceClient {
* @param {object} [options]
* @param {boolean} [options.buffer]
* @param {boolean} [options.stream]
* @param {boolean} [options.disableRedirect]
* @return {Promise<KeyValueStoreRecord>}
*/
async getRecord(key, options = {}) {
Expand All @@ -91,14 +91,15 @@ class KeyValueStoreClient extends ResourceClient {
throw new Error('The stream option can only be used in Node.js environment.');
}

const params = {
disableRedirect: options.disableRedirect,
};
if ('disableRedirect' in options) {
log.deprecated('The disableRedirect option for getRecord() is deprecated. '
+ 'It has no effect and will be removed in the following major release.');
}

const requestOpts = {
url: this._url(`records/${key}`),
method: 'GET',
params: this._params(params),
params: this._params(),
};

if (options.buffer) requestOpts.forceBuffer = true;
Expand Down
11 changes: 4 additions & 7 deletions test/key_value_stores.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ describe('Key-Value Store methods', () => {
test('getRecord() works', async () => {
const key = 'some-key';
const storeId = 'some-id';
const options = {
disableRedirect: true,
};

const expectedBody = 'hello-world';
const expectedContentType = 'text/plain; charset=utf-8';
Expand All @@ -147,18 +144,18 @@ describe('Key-Value Store methods', () => {

mockServer.setResponse({ headers: expectedHeaders, body: expectedBody });

const res = await client.keyValueStore(storeId).getRecord(key, options);
const res = await client.keyValueStore(storeId).getRecord(key);
const expectedResult = {
key,
value: expectedBody,
contentType: expectedContentType,
};
expect(res).toEqual(expectedResult);
validateRequest(options, { storeId, key });
validateRequest({}, { storeId, key });

const browserRes = await page.evaluate((id, k, opts) => client.keyValueStore(id).getRecord(k, opts), storeId, key, options);
const browserRes = await page.evaluate((id, k) => client.keyValueStore(id).getRecord(k), storeId, key);
expect(browserRes).toEqual(res);
validateRequest(options, { storeId, key });
validateRequest({}, { storeId, key });
});

test('getRecord() parses JSON', async () => {
Expand Down

0 comments on commit c7f05cb

Please sign in to comment.