Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix User-Agent version bug in Node #132

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/package_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This will become package_version_browser.js when doing a browser build.
// See <https://github.com/Airtable/airtable.js/pull/132> for more.
module.exports = require('../package.json').version;
1 change: 1 addition & 0 deletions lib/package_version_browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = process.env.npm_package_version;
5 changes: 3 additions & 2 deletions lib/run_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

var internalConfig = require('./internal_config.json');
var objectToQueryParamString = require('./object_to_query_param_string');
var packageVersion = require('./package_version');

// This will become require('xhr') in the browser.
var request = require('request');

var userAgent = 'Airtable.js/' + packageVersion;

// "Full Jitter" algorithm taken from https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
function exponentialBackoffWithJitter(numberOfRetries, initialBackoffTimeMs, maxBackoffTimeMs) {
var rawBackoffTimeMs = initialBackoffTimeMs * Math.pow(2, numberOfRetries);
Expand All @@ -22,8 +25,6 @@ function runAction(base, method, path, queryParams, bodyData, callback, numAttem
'x-api-version': base._airtable._apiVersion,
'x-airtable-application-id': base.getId(),
};

var userAgent = 'Airtable.js/' + process.env.npm_package_version;
var isBrowser = typeof window !== 'undefined';
// Some browsers do not allow overriding the user agent.
// https://github.com/Airtable/airtable.js/issues/52
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"main": "./lib/airtable.js",
"browser": {
"request": "xhr"
"request": "xhr",
"./lib/package_version": "./lib/package_version_browser"
},
"files": [
"/README.md",
Expand Down