diff --git a/CHANGELOG.md b/CHANGELOG.md index 71b0f203..ee69f6a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,16 @@ +# v0.11.6 + * Remove behavior of including `AIRTABLE_API_KEY` in airtable.browser.js via envify + * Add web worker compatibility + # v0.11.5 * Update select() and list() to support to use POST endpoint when GET url length would exceed Airtable's 16k character limit - * Update select() and list() to explicitly choose to use GET or POST endpoint via new 'method' arg + * Update select() and list() to explicitly choose to use GET or POST endpoint via new 'method' arg # v0.11.4 * Add support for returnFieldsByFieldId param. # v0.11.3 - * Adds a UMD build to use for browser-targeted builds. This fixes an issue where other apps that + * Add a UMD build to use for browser-targeted builds. This fixes an issue where other apps that use airtable.js as a dependency were bundling code that expects to run in a node environment when building for a browser enviornment. diff --git a/README.md b/README.md index 8382a1be..e176fdfe 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ There are three configurable options available: * `apiKey` - your secret API token. Visit [/create/tokens](https://airtable.com/create/tokens) to create a personal access token. [OAuth access tokens](https://airtable.com/developers/web/guides/oauth-integrations) can also be used. * `endpointUrl` - the API endpoint to hit. You might want to override - it if you are using an API proxy (e.g. runscope.net) to debug your API calls. (`AIRTABLE_ENDPOINT_URL`) + it if you are using an API proxy (e.g. runscope.net) to debug your API calls. (`AIRTABLE_ENDPOINT_URL`) * `requestTimeout` - the timeout in milliseconds for requests. The default is 5 minutes (`300000`) You can set the options globally via `Airtable.configure`: diff --git a/build/airtable.browser.js b/build/airtable.browser.js index 72b79d33..74d3d106 100644 --- a/build/airtable.browser.js +++ b/build/airtable.browser.js @@ -2,11 +2,12 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c= "use strict"; // istanbul ignore file var AbortController; -if (typeof window === 'undefined') { +var browserGlobal = typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : null; // self is the global in web workers +if (!browserGlobal) { AbortController = require('abort-controller'); } else if ('signal' in new Request('')) { - AbortController = window.AbortController; + AbortController = browserGlobal.AbortController; } else { /* eslint-disable @typescript-eslint/no-var-requires */ @@ -326,7 +327,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; // istanbul ignore file var node_fetch_1 = __importDefault(require("node-fetch")); -module.exports = typeof window === 'undefined' ? node_fetch_1.default : window.fetch.bind(window); +var browserGlobal = typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : null; // self is the global in web workers +module.exports = !browserGlobal ? node_fetch_1.default : browserGlobal.fetch.bind(browserGlobal); },{"node-fetch":20}],8:[function(require,module,exports){ "use strict"; @@ -443,7 +445,7 @@ module.exports = objectToQueryParamString; },{"lodash/isArray":79,"lodash/isNil":85,"lodash/keys":93}],12:[function(require,module,exports){ "use strict"; -module.exports = "0.11.5"; +module.exports = "0.11.6"; },{}],13:[function(require,module,exports){ "use strict"; @@ -3718,9 +3720,9 @@ var Airtable = /** @class */ (function () { }; Airtable.default_config = function () { return { - endpointUrl: undefined || 'https://api.airtable.com', + endpointUrl: "" || 'https://api.airtable.com', apiVersion: '0.1.0', - apiKey: undefined, + apiKey: "", noRetryIfRateLimited: false, requestTimeout: 300 * 1000, }; diff --git a/gruntfile.js b/gruntfile.js index 497c7488..6e799437 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -21,8 +21,11 @@ module.exports = function(grunt) { transform: [ [ 'envify', + // IMPORTANT: mask out environment variables that should never be shipped to the browser { _: 'purge', + AIRTABLE_ENDPOINT_URL: '', + AIRTABLE_API_KEY: '', npm_package_version: pkg.version, }, ], @@ -42,8 +45,11 @@ module.exports = function(grunt) { transform: [ [ 'envify', + // IMPORTANT: mask out environment variables that should never be shipped to the browser { _: 'purge', + AIRTABLE_ENDPOINT_URL: '', + AIRTABLE_API_KEY: '', npm_package_version: pkg.version, }, ], diff --git a/package-lock.json b/package-lock.json index 6a0b6d79..5a78988b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "airtable", - "version": "0.11.5", + "version": "0.11.6", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 086e0c56..d2f339ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "airtable", - "version": "0.11.5", + "version": "0.11.6", "license": "MIT", "homepage": "https://github.com/airtable/airtable.js", "repository": "git://github.com/airtable/airtable.js.git", diff --git a/src/abort-controller.ts b/src/abort-controller.ts index f6482128..ed11d79a 100644 --- a/src/abort-controller.ts +++ b/src/abort-controller.ts @@ -1,9 +1,11 @@ // istanbul ignore file let AbortController: new () => AbortController; -if (typeof window === 'undefined') { +const browserGlobal = + typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : null; // self is the global in web workers +if (!browserGlobal) { AbortController = require('abort-controller'); } else if ('signal' in new Request('')) { - AbortController = window.AbortController; + AbortController = browserGlobal.AbortController; } else { /* eslint-disable @typescript-eslint/no-var-requires */ const polyfill = require('abortcontroller-polyfill/dist/cjs-ponyfill'); diff --git a/src/fetch.ts b/src/fetch.ts index d1cc2736..08f7f0ed 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -1,4 +1,7 @@ // istanbul ignore file import nodeFetch from 'node-fetch'; -export = typeof window === 'undefined' ? (nodeFetch as typeof fetch) : window.fetch.bind(window); +const browserGlobal = + typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : null; // self is the global in web workers + +export = !browserGlobal ? (nodeFetch as typeof fetch) : browserGlobal.fetch.bind(browserGlobal); diff --git a/test/test_files/airtable.browser.js b/test/test_files/airtable.browser.js index 72b79d33..74d3d106 100644 --- a/test/test_files/airtable.browser.js +++ b/test/test_files/airtable.browser.js @@ -2,11 +2,12 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c= "use strict"; // istanbul ignore file var AbortController; -if (typeof window === 'undefined') { +var browserGlobal = typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : null; // self is the global in web workers +if (!browserGlobal) { AbortController = require('abort-controller'); } else if ('signal' in new Request('')) { - AbortController = window.AbortController; + AbortController = browserGlobal.AbortController; } else { /* eslint-disable @typescript-eslint/no-var-requires */ @@ -326,7 +327,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; // istanbul ignore file var node_fetch_1 = __importDefault(require("node-fetch")); -module.exports = typeof window === 'undefined' ? node_fetch_1.default : window.fetch.bind(window); +var browserGlobal = typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : null; // self is the global in web workers +module.exports = !browserGlobal ? node_fetch_1.default : browserGlobal.fetch.bind(browserGlobal); },{"node-fetch":20}],8:[function(require,module,exports){ "use strict"; @@ -443,7 +445,7 @@ module.exports = objectToQueryParamString; },{"lodash/isArray":79,"lodash/isNil":85,"lodash/keys":93}],12:[function(require,module,exports){ "use strict"; -module.exports = "0.11.5"; +module.exports = "0.11.6"; },{}],13:[function(require,module,exports){ "use strict"; @@ -3718,9 +3720,9 @@ var Airtable = /** @class */ (function () { }; Airtable.default_config = function () { return { - endpointUrl: undefined || 'https://api.airtable.com', + endpointUrl: "" || 'https://api.airtable.com', apiVersion: '0.1.0', - apiKey: undefined, + apiKey: "", noRetryIfRateLimited: false, requestTimeout: 300 * 1000, };