diff --git a/lib/package_version.js b/lib/package_version.js new file mode 100644 index 00000000..dc9c54da --- /dev/null +++ b/lib/package_version.js @@ -0,0 +1,3 @@ +// This will become package_version_browser.js when doing a browser build. +// See for more. +module.exports = require('../package.json').version; diff --git a/lib/package_version_browser.js b/lib/package_version_browser.js new file mode 100644 index 00000000..8de08b02 --- /dev/null +++ b/lib/package_version_browser.js @@ -0,0 +1 @@ +module.exports = process.env.npm_package_version; diff --git a/lib/run_action.js b/lib/run_action.js index f349ac03..ea95264f 100644 --- a/lib/run_action.js +++ b/lib/run_action.js @@ -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); @@ -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 diff --git a/package.json b/package.json index 3e685517..6b6b3ed5 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ }, "main": "./lib/airtable.js", "browser": { - "request": "xhr" + "request": "xhr", + "./lib/package_version": "./lib/package_version_browser" }, "files": [ "/README.md",