diff --git a/dist/osm-auth.cjs b/dist/osm-auth.cjs index c6c88f4..df0bedd 100644 --- a/dist/osm-auth.cjs +++ b/dist/osm-auth.cjs @@ -1,8 +1,6 @@ -var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; -var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) @@ -16,23 +14,34 @@ var __copyProps = (to, from, except, desc) => { } return to; }; -var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( - // If the importer is in node compatibility mode or this is not an ESM - // file that has been converted to a CommonJS file using a Babel- - // compatible transform (i.e. "__esModule" has not been set), then set - // "default" to the CommonJS "module.exports" for node compatibility. - isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, - mod -)); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var osm_auth_exports = {}; __export(osm_auth_exports, { osmAuth: () => osmAuth }); module.exports = __toCommonJS(osm_auth_exports); -var import_store = __toESM(require("store"), 1); function osmAuth(o) { var oauth = {}; + var _store = null; + try { + _store = window.localStorage; + } catch (e) { + var _mock = /* @__PURE__ */ new Map(); + _store = { + isMocked: true, + hasItem: (k) => _mock.has(k), + getItem: (k) => _mock.get(k), + setItem: (k, v) => _mock.set(k, v), + removeItem: (k) => _mock.delete(k), + clear: () => _mock.clear() + }; + } + function token(k, v) { + if (arguments.length === 1) + return _store.getItem(o.url + k); + else if (arguments.length === 2) + return _store.setItem(o.url + k, v); + } oauth.authenticated = function() { return !!token("oauth2_access_token"); }; @@ -117,8 +126,8 @@ function osmAuth(o) { code_challenge_method: pkce.code_challenge_method }); if (o.singlepage) { - if (!import_store.default.enabled) { - var error = new Error("local storage unavailable, but require in singlepage mode"); + if (_store.isMocked) { + var error = new Error("localStorage unavailable, but required in singlepage mode"); error.status = "pkce-localstorage-unavailable"; callback(error); return; @@ -299,23 +308,6 @@ function osmAuth(o) { }; return oauth.preauth(o); }; - var token; - if (import_store.default.enabled) { - token = function(x, y) { - if (arguments.length === 1) - return import_store.default.get(o.url + x); - else if (arguments.length === 2) - return import_store.default.set(o.url + x, y); - }; - } else { - var storage = {}; - token = function(x, y) { - if (arguments.length === 1) - return storage[o.url + x]; - else if (arguments.length === 2) - return storage[o.url + x] = y; - }; - } oauth.options(o); return oauth; } diff --git a/dist/osm-auth.cjs.map b/dist/osm-auth.cjs.map index a235528..bc6e70f 100644 --- a/dist/osm-auth.cjs.map +++ b/dist/osm-auth.cjs.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../src/osm-auth.mjs"], - "sourcesContent": ["import store from 'store';\n\n\n/**\n * osmAuth\n * Easy authentication with OpenStreetMap over OAuth 2.0.\n * @module\n *\n * @param o `Object` containing options:\n * @param o.scope OAuth2 scopes requested (e.g. \"read_prefs write_api\")\n * @param o.client_id OAuth2 client ID\n * @param o.redirect_uri OAuth2 redirect URI (e.g. \"http://127.0.0.1:8080/land.html\")\n * @param o.access_token Can pre-authorize with an OAuth2 bearer token if you have one\n * @param o.apiUrl A base url for the OSM API (default: \"https://api.openstreetmap.org\")\n * @param o.url A base url for the OAuth2 handshake (default: \"https://www.openstreetmap.org\")\n * @param o.auto If `true`, attempt to authenticate automatically when calling `.xhr()` or `.fetch()` (default: `false`)\n * @param o.singlepage If `true`, use page redirection instead of a popup (default: `false`)\n * @param o.loading Function called when auth-related xhr calls start\n * @param o.done Function called when auth-related xhr calls end\n * @return `self`\n */\nexport function osmAuth(o) {\n var oauth = {};\n\n /**\n * authenticated\n * Test whether the user is currently authenticated\n *\n * @return {boolean} `true` if authenticated, `false` if not\n */\n oauth.authenticated = function() {\n return !!token('oauth2_access_token');\n };\n\n\n /**\n * logout\n * Removes any stored authentication tokens (legacy OAuth1 tokens too)\n *\n * @return `self`\n */\n oauth.logout = function () {\n token('oauth2_access_token', ''); // OAuth2\n token('oauth_token', ''); // OAuth1\n token('oauth_token_secret', ''); // OAuth1\n token('oauth_request_token_secret', ''); // OAuth1\n return oauth;\n };\n\n\n /**\n * authenticate\n * First logs out, then runs the authentiation flow, finally calls the callback.\n * TODO: detect lack of click event (probably can settimeout it)\n *\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n oauth.authenticate = function(callback) {\n if (oauth.authenticated()) {\n callback(null, oauth);\n return;\n }\n\n oauth.logout();\n\n _preopenPopup(function(error, popup) {\n if (error) {\n callback(error);\n } else {\n _generatePkceChallenge(function(pkce) {\n _authenticate(pkce, popup, callback);\n });\n }\n });\n };\n\n\n /**\n * authenticateAsync\n * Promisified version of `authenticate`\n * @return {Promise} Promise settled with whatever `_authenticate` did\n */\n oauth.authenticateAsync = function() {\n if (oauth.authenticated()) {\n return Promise.resolve(oauth);\n }\n\n oauth.logout();\n\n return new Promise((resolve, reject) => {\n var errback = (err, result) => {\n if (err) {\n reject(err);\n } else {\n resolve(result);\n }\n };\n\n _preopenPopup((error, popup) => {\n if (error) {\n errback(error);\n } else {\n _generatePkceChallenge(pkce => _authenticate(pkce, popup, errback));\n }\n });\n });\n };\n\n\n /**\n * opens an empty popup to be later used for the authentication page\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n function _preopenPopup(callback) {\n if (o.singlepage) {\n callback(null, undefined);\n return;\n }\n\n // Create a 550x610 popup window in the center of the screen\n var w = 550;\n var h = 610;\n var settings = [\n ['width', w],\n ['height', h],\n ['left', window.screen.width / 2 - w / 2],\n ['top', window.screen.height / 2 - h / 2],\n ]\n .map(function (x) { return x.join('='); })\n .join(',');\n var popup = window.open('about:blank', 'oauth_window', settings);\n if (popup) {\n callback(null, popup);\n } else {\n var error = new Error('Popup was blocked');\n error.status = 'popup-blocked';\n callback(error);\n }\n }\n\n\n /**\n * _authenticate\n * internal authenticate\n *\n * @param {Object} pkce Object containing PKCE code challenge properties\n * @param {Window} popup Popup Window to use for the authentication page, should be undefined when using singlepage mode\n * @param {function} callback Errback-style callback that accepts `(err, result)`\n */\n function _authenticate(pkce, popup, callback) {\n var state = generateState();\n\n // ## Request authorization to access resources from the user\n // and receive authorization code\n var url =\n o.url +\n '/oauth2/authorize?' +\n utilQsString({\n client_id: o.client_id,\n redirect_uri: o.redirect_uri,\n response_type: 'code',\n scope: o.scope,\n state: state,\n code_challenge: pkce.code_challenge,\n code_challenge_method: pkce.code_challenge_method,\n });\n\n if (o.singlepage) {\n if (!store.enabled) {\n // in singlepage mode, PKCE requires working non-volatile storage\n var error = new Error('local storage unavailable, but require in singlepage mode');\n error.status = 'pkce-localstorage-unavailable';\n callback(error);\n return;\n }\n var params = utilStringQs(window.location.search.slice(1));\n if (params.code) {\n oauth.bootstrapToken(params.code, callback);\n } else {\n // save OAuth2 state and PKCE challenge in local storage, for later use\n // in the `/oauth/token` request\n token('oauth2_state', state);\n token('oauth2_pkce_code_verifier', pkce.code_verifier);\n window.location = url;\n }\n } else {\n oauth.popupWindow = popup;\n popup.location = url;\n }\n\n // Called by a function in the redirect URL page, in the popup window. The\n // window closes itself.\n window.authComplete = function (url) {\n var params = utilStringQs(url.split('?')[1]);\n if (params.state !== state) {\n error = new Error('Invalid state');\n error.status = 'invalid-state';\n callback(error);\n return;\n }\n _getAccessToken(params.code, pkce.code_verifier, accessTokenDone);\n delete window.authComplete;\n };\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) {\n callback(err);\n return;\n }\n var access_token = JSON.parse(xhr.response);\n token('oauth2_access_token', access_token.access_token);\n callback(null, oauth);\n }\n }\n\n\n /**\n * _getAccessToken\n * The client requests an access token by authenticating with the\n * authorization server and presenting the `auth_code`, brought\n * in from a function call on a landing page popup.\n * @param {string} auth_code\n * @param {string} code_verifier\n * @param {function} accessTokenDone Errback-style callback `(err, result)`, called when complete\n */\n function _getAccessToken(auth_code, code_verifier, accessTokenDone) {\n var url =\n o.url +\n '/oauth2/token?' +\n utilQsString({\n client_id: o.client_id,\n redirect_uri: o.redirect_uri,\n grant_type: 'authorization_code',\n code: auth_code,\n code_verifier: code_verifier\n });\n\n // The authorization server authenticates the client and validates\n // the authorization grant, and if valid, issues an access token.\n oauth.rawxhr('POST', url, null, null, null, accessTokenDone);\n o.loading();\n }\n\n\n /**\n * bringPopupWindowToFront\n * Tries to bring an existing authentication popup to the front.\n *\n * @return {boolean} `true` if it succeeded, `false` if not\n */\n oauth.bringPopupWindowToFront = function() {\n var broughtPopupToFront = false;\n try {\n // This may cause a cross-origin error:\n // `DOMException: Blocked a frame with origin \"...\" from accessing a cross-origin frame.`\n if (oauth.popupWindow && !oauth.popupWindow.closed) {\n oauth.popupWindow.focus();\n broughtPopupToFront = true;\n }\n } catch (err) {\n // Bringing popup window to front failed (probably because of the cross-origin error mentioned above)\n }\n return broughtPopupToFront;\n };\n\n\n /**\n * bootstrapToken\n * The authorization code is a temporary code that a client can exchange for an access token.\n * If using this library in single-page mode, you'll need to call this once your application\n * has an `auth_code` and wants to get an access_token.\n *\n * @param {string} auth_code The OAuth2 `auth_code`\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n oauth.bootstrapToken = function(auth_code, callback) {\n var state = token('oauth2_state');\n token('oauth2_state', '');\n var params = utilStringQs(window.location.search.slice(1));\n if (params.state !== state) {\n var error = new Error('Invalid state');\n error.status = 'invalid-state';\n callback(error);\n return;\n }\n var code_verifier = token('oauth2_pkce_code_verifier');\n token('oauth2_pkce_code_verifier', '');\n _getAccessToken(auth_code, code_verifier, accessTokenDone);\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) {\n callback(err);\n return;\n }\n var access_token = JSON.parse(xhr.response);\n token('oauth2_access_token', access_token.access_token);\n callback(null, oauth);\n }\n };\n\n\n /**\n * fetch\n * A `fetch` wrapper that includes the Authorization header if the user is authenticated.\n * https://developer.mozilla.org/en-US/docs/Web/API/fetch\n *\n * @param {string} resource Resource passed to `fetch`\n * @param {Object} options Options passed to `fetch`\n * @return {Promise} Promise that wraps `authenticateAsync` then `fetch`\n */\n oauth.fetch = function(resource, options) {\n if (oauth.authenticated()) {\n return _doFetch();\n } else {\n if (o.auto) {\n return oauth.authenticateAsync().then(_doFetch);\n } else {\n return Promise.reject(new Error('not authenticated'));\n }\n }\n\n function _doFetch() {\n options = options || {};\n if (!options.headers) {\n options.headers = { 'Content-Type': 'application/x-www-form-urlencoded' };\n }\n options.headers.Authorization = 'Bearer ' + token('oauth2_access_token');\n return fetch(resource, options);\n }\n };\n\n\n /**\n * xhr\n * A `XMLHttpRequest` wrapper that does authenticated calls if the user has logged in.\n * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\n *\n * @param {Object} options\n * @param options.method Passed to `xhr.open` (e.g. 'GET', 'POST')\n * @param options.prefix If `true` path contains a path, if `false` path contains the full url\n * @param options.path The URL path (e.g. \"/api/0.6/user/details\") (or full url, if `prefix`=`false`)\n * @param options.content Passed to `xhr.send`\n * @param options.headers `Object` containing request headers\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return {XMLHttpRequest} `XMLHttpRequest` if authenticated, otherwise `null`\n */\n oauth.xhr = function (options, callback) {\n if (oauth.authenticated()) {\n return _doXHR();\n } else {\n if (o.auto) {\n oauth.authenticate(_doXHR);\n return;\n } else {\n callback('not authenticated', null);\n return;\n }\n }\n\n function _doXHR() {\n var url = options.prefix !== false ? (o.apiUrl + options.path) : options.path;\n return oauth.rawxhr(\n options.method,\n url,\n token('oauth2_access_token'),\n options.content,\n options.headers,\n done\n );\n }\n\n function done(err, xhr) {\n if (err) {\n callback(err);\n } else if (xhr.responseXML) {\n callback(err, xhr.responseXML);\n } else {\n callback(err, xhr.response);\n }\n }\n };\n\n\n /**\n * rawxhr\n * Creates the XMLHttpRequest set up with a header and response handling\n * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\n *\n * @param method Passed to `xhr.open` (e.g. 'GET', 'POST')\n * @param url Passed to `xhr.open`\n * @param access_token OAuth2 bearer token\n * @param data Passed to `xhr.send`\n * @param headers `Object` containing request headers\n * @param callback An \"errback\"-style callback (`err`, `result`), called when complete\n * @return `XMLHttpRequest`\n */\n oauth.rawxhr = function(method, url, access_token, data, headers, callback) {\n headers = headers || { 'Content-Type': 'application/x-www-form-urlencoded' };\n\n if (access_token) {\n headers.Authorization = 'Bearer ' + access_token;\n }\n\n var xhr = new XMLHttpRequest();\n\n xhr.onreadystatechange = function () {\n if (4 === xhr.readyState && 0 !== xhr.status) {\n if (/^20\\d$/.test(xhr.status)) { // a 20x status code - OK\n callback(null, xhr);\n } else {\n callback(xhr, null);\n }\n }\n };\n xhr.onerror = function (e) {\n callback(e, null);\n };\n\n xhr.open(method, url, true);\n for (var h in headers) xhr.setRequestHeader(h, headers[h]);\n\n xhr.send(data);\n return xhr;\n };\n\n\n /**\n * preauth\n * Pre-authorize this object, if we already have access token from the start\n *\n * @param {Object} val Object containing `access_token` property\n * @return `self`\n */\n oauth.preauth = function(val) {\n if (val && val.access_token) {\n token('oauth2_access_token', val.access_token);\n }\n return oauth;\n };\n\n\n /**\n * options (getter / setter)\n * If passed with no arguments, just return the options\n * If passed an Object, set the options then attempt to pre-authorize\n *\n * @param val? Object containing options\n * @return current `options` (if getting), or `self` (if setting)\n */\n oauth.options = function(val) {\n if (!arguments.length) return o;\n\n o = val;\n o.apiUrl = o.apiUrl || 'https://api.openstreetmap.org';\n o.url = o.url || 'https://www.openstreetmap.org';\n o.auto = o.auto || false;\n o.singlepage = o.singlepage || false;\n\n // Optional loading and loading-done functions for nice UI feedback.\n // by default, no-ops\n o.loading = o.loading || function () {};\n o.done = o.done || function () {};\n return oauth.preauth(o);\n };\n\n\n // Everything below here is initialization/setup code\n\n // get/set tokens. These are prefixed with the base URL so that `osm-auth`\n // can be used with multiple APIs and the keys in `localStorage`\n // will not clash\n var token;\n\n if (store.enabled) {\n token = function (x, y) {\n if (arguments.length === 1) return store.get(o.url + x);\n else if (arguments.length === 2) return store.set(o.url + x, y);\n };\n } else {\n var storage = {};\n token = function (x, y) {\n if (arguments.length === 1) return storage[o.url + x];\n else if (arguments.length === 2) return (storage[o.url + x] = y);\n };\n }\n\n // Handle options and attempt to pre-authorize\n oauth.options(o);\n\n return oauth;\n}\n\n\n/**\n * utilQsString\n * Transforms object of `key=value` pairs into query string\n * @param {Object} Object of `key=value` pairs\n * @returns {string} query string\n */\nfunction utilQsString(obj) {\n return Object.keys(obj)\n .filter(function(key) {\n return obj[key] !== undefined;\n })\n .sort()\n .map(function(key) {\n return (encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));\n })\n .join('&');\n}\n\n/**\n * utilStringQs\n * Transforms query string into object of `key=value` pairs\n * @param {string} query string\n * @returns {Object} Object of `key=value` pairs\n */\nfunction utilStringQs(str) {\n var i = 0; // advance past any leading '?' or '#' characters\n while (i < str.length && (str[i] === '?' || str[i] === '#')) i++;\n str = str.slice(i);\n\n return str.split('&').reduce(function(obj, pair) {\n var parts = pair.split('=');\n if (parts.length === 2) {\n obj[parts[0]] = decodeURIComponent(parts[1]);\n }\n return obj;\n }, {});\n}\n\n\n/**\n * supportsWebCryptoAPI\n * https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API\n * @returns {boolean} `true` if WebCryptoAPI is available\n */\nfunction supportsWebCryptoAPI() {\n return window && window.crypto\n && window.crypto.getRandomValues\n && window.crypto.subtle\n && window.crypto.subtle.digest;\n}\n\n\n/**\n * Generates a challenge/verifier pair for PKCE.\n * If the browser does not support the WebCryptoAPI, the \"plain\" method is\n * used as a fallback instead of a SHA-256 hash.\n * @param {callback} callback called with the result of the generated PKCE challenge\n */\nfunction _generatePkceChallenge(callback) {\n var code_verifier;\n if (supportsWebCryptoAPI()) {\n // generate a random code_verifier\n // https://datatracker.ietf.org/doc/html/rfc7636#section-7.1\n var random = window.crypto.getRandomValues(new Uint8Array(32));\n code_verifier = base64(random.buffer);\n var verifier = Uint8Array.from(Array.from(code_verifier).map(function(char) {\n return char.charCodeAt(0);\n }));\n\n // generate challenge for code verifier\n window.crypto.subtle.digest('SHA-256', verifier).then(function(hash) {\n var code_challenge = base64(hash);\n\n callback({\n code_challenge: code_challenge,\n code_verifier: code_verifier,\n code_challenge_method: 'S256'\n });\n });\n } else {\n // browser does not support Web Crypto API (e.g. IE11) -> fall back to \"plain\" method\n var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n code_verifier = '';\n for (var i=0; i<64; i++) {\n code_verifier += chars[Math.floor(Math.random() * chars.length)];\n }\n callback({\n code_verifier: code_verifier,\n code_challenge: code_verifier,\n code_challenge_method: 'plain',\n });\n }\n}\n\n\n/**\n * Returns a random state to be used as the \"state\" of the OAuth2 authentication\n * See https://datatracker.ietf.org/doc/html/rfc6749#section-10.12\n */\nfunction generateState() {\n var state;\n if (supportsWebCryptoAPI()) {\n var random = window.crypto.getRandomValues(new Uint8Array(32));\n state = base64(random.buffer);\n } else {\n // browser does not support Web Crypto API (e.g. IE11) -> fall back to \"plain\" method\n var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n state = '';\n for (var i=0; i<64; i++) {\n state += chars[Math.floor(Math.random() * chars.length)];\n }\n }\n return state;\n}\n\n\n/**\n * base64\n * Converts binary buffer to base64 encoded string, as used in rfc7636\n * @param {ArrayBuffer} buffer\n * @returns {string} base64 encoded\n */\nfunction base64(buffer) {\n return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)))\n .replace(/\\//g, '_')\n .replace(/\\+/g, '-')\n .replace(/[=]/g, '');\n}"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAqBX,SAAS,QAAQ,GAAG;AACzB,MAAI,QAAQ,CAAC;AAQb,QAAM,gBAAgB,WAAW;AAC/B,WAAO,CAAC,CAAC,MAAM,qBAAqB;AAAA,EACtC;AASA,QAAM,SAAS,WAAY;AACzB,UAAM,uBAAuB,EAA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AAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,GAAG,EAClB,QAAQ,QAAQ,EAAE;AACvB;", - "names": ["store", "url", "params"] + "sourcesContent": ["\n/**\n * osmAuth\n * Easy authentication with OpenStreetMap over OAuth 2.0.\n * @module\n *\n * @param o `Object` containing options:\n * @param o.scope OAuth2 scopes requested (e.g. \"read_prefs write_api\")\n * @param o.client_id OAuth2 client ID\n * @param o.redirect_uri OAuth2 redirect URI (e.g. \"http://127.0.0.1:8080/land.html\")\n * @param o.access_token Can pre-authorize with an OAuth2 bearer token if you have one\n * @param o.apiUrl A base url for the OSM API (default: \"https://api.openstreetmap.org\")\n * @param o.url A base url for the OAuth2 handshake (default: \"https://www.openstreetmap.org\")\n * @param o.auto If `true`, attempt to authenticate automatically when calling `.xhr()` or `.fetch()` (default: `false`)\n * @param o.singlepage If `true`, use page redirection instead of a popup (default: `false`)\n * @param o.loading Function called when auth-related xhr calls start\n * @param o.done Function called when auth-related xhr calls end\n * @return `self`\n */\nexport function osmAuth(o) {\n var oauth = {};\n\n // Mock localStorage if needed.\n // Note that accessing localStorage may throw a `SecurityError`, so wrap in a try/catch.\n var _store = null;\n try {\n _store = window.localStorage;\n } catch (e) {\n var _mock = new Map();\n _store = {\n isMocked: true,\n hasItem: (k) => _mock.has(k),\n getItem: (k) => _mock.get(k),\n setItem: (k, v) => _mock.set(k, v),\n removeItem: (k) => _mock.delete(k),\n clear: () => _mock.clear()\n };\n }\n\n /**\n * token\n * Get/Set tokens. These are prefixed with the base URL so that `osm-auth`\n * can be used with multiple APIs and the keys in `localStorage` will not clash\n * @param {string} k key\n * @param {string?} v value\n * @return {string?} If getting, returns the stored value or `null`. If setting, returns `undefined`.\n */\n function token(k, v) {\n if (arguments.length === 1) return _store.getItem(o.url + k);\n else if (arguments.length === 2) return _store.setItem(o.url + k, v);\n }\n\n\n /**\n * authenticated\n * Test whether the user is currently authenticated\n *\n * @return {boolean} `true` if authenticated, `false` if not\n */\n oauth.authenticated = function() {\n return !!token('oauth2_access_token');\n };\n\n\n /**\n * logout\n * Removes any stored authentication tokens (legacy OAuth1 tokens too)\n *\n * @return `self`\n */\n oauth.logout = function () {\n token('oauth2_access_token', ''); // OAuth2\n token('oauth_token', ''); // OAuth1\n token('oauth_token_secret', ''); // OAuth1\n token('oauth_request_token_secret', ''); // OAuth1\n return oauth;\n };\n\n\n /**\n * authenticate\n * First logs out, then runs the authentiation flow, finally calls the callback.\n * TODO: detect lack of click event (probably can settimeout it)\n *\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n oauth.authenticate = function(callback) {\n if (oauth.authenticated()) {\n callback(null, oauth);\n return;\n }\n\n oauth.logout();\n\n _preopenPopup(function(error, popup) {\n if (error) {\n callback(error);\n } else {\n _generatePkceChallenge(function(pkce) {\n _authenticate(pkce, popup, callback);\n });\n }\n });\n };\n\n\n /**\n * authenticateAsync\n * Promisified version of `authenticate`\n * @return {Promise} Promise settled with whatever `_authenticate` did\n */\n oauth.authenticateAsync = function() {\n if (oauth.authenticated()) {\n return Promise.resolve(oauth);\n }\n\n oauth.logout();\n\n return new Promise((resolve, reject) => {\n var errback = (err, result) => {\n if (err) {\n reject(err);\n } else {\n resolve(result);\n }\n };\n\n _preopenPopup((error, popup) => {\n if (error) {\n errback(error);\n } else {\n _generatePkceChallenge(pkce => _authenticate(pkce, popup, errback));\n }\n });\n });\n };\n\n\n /**\n * opens an empty popup to be later used for the authentication page\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n function _preopenPopup(callback) {\n if (o.singlepage) {\n callback(null, undefined);\n return;\n }\n\n // Create a 550x610 popup window in the center of the screen\n var w = 550;\n var h = 610;\n var settings = [\n ['width', w],\n ['height', h],\n ['left', window.screen.width / 2 - w / 2],\n ['top', window.screen.height / 2 - h / 2],\n ]\n .map(function (x) { return x.join('='); })\n .join(',');\n var popup = window.open('about:blank', 'oauth_window', settings);\n if (popup) {\n callback(null, popup);\n } else {\n var error = new Error('Popup was blocked');\n error.status = 'popup-blocked';\n callback(error);\n }\n }\n\n\n /**\n * _authenticate\n * internal authenticate\n *\n * @param {Object} pkce Object containing PKCE code challenge properties\n * @param {Window} popup Popup Window to use for the authentication page, should be undefined when using singlepage mode\n * @param {function} callback Errback-style callback that accepts `(err, result)`\n */\n function _authenticate(pkce, popup, callback) {\n var state = generateState();\n\n // ## Request authorization to access resources from the user\n // and receive authorization code\n var url =\n o.url +\n '/oauth2/authorize?' +\n utilQsString({\n client_id: o.client_id,\n redirect_uri: o.redirect_uri,\n response_type: 'code',\n scope: o.scope,\n state: state,\n code_challenge: pkce.code_challenge,\n code_challenge_method: pkce.code_challenge_method,\n });\n\n if (o.singlepage) {\n if (_store.isMocked) {\n // in singlepage mode, PKCE requires working non-volatile storage\n var error = new Error('localStorage unavailable, but required in singlepage mode');\n error.status = 'pkce-localstorage-unavailable';\n callback(error);\n return;\n }\n var params = utilStringQs(window.location.search.slice(1));\n if (params.code) {\n oauth.bootstrapToken(params.code, callback);\n } else {\n // save OAuth2 state and PKCE challenge in local storage, for later use\n // in the `/oauth/token` request\n token('oauth2_state', state);\n token('oauth2_pkce_code_verifier', pkce.code_verifier);\n window.location = url;\n }\n } else {\n oauth.popupWindow = popup;\n popup.location = url;\n }\n\n // Called by a function in the redirect URL page, in the popup window. The\n // window closes itself.\n window.authComplete = function (url) {\n var params = utilStringQs(url.split('?')[1]);\n if (params.state !== state) {\n error = new Error('Invalid state');\n error.status = 'invalid-state';\n callback(error);\n return;\n }\n _getAccessToken(params.code, pkce.code_verifier, accessTokenDone);\n delete window.authComplete;\n };\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) {\n callback(err);\n return;\n }\n var access_token = JSON.parse(xhr.response);\n token('oauth2_access_token', access_token.access_token);\n callback(null, oauth);\n }\n }\n\n\n /**\n * _getAccessToken\n * The client requests an access token by authenticating with the\n * authorization server and presenting the `auth_code`, brought\n * in from a function call on a landing page popup.\n * @param {string} auth_code\n * @param {string} code_verifier\n * @param {function} accessTokenDone Errback-style callback `(err, result)`, called when complete\n */\n function _getAccessToken(auth_code, code_verifier, accessTokenDone) {\n var url =\n o.url +\n '/oauth2/token?' +\n utilQsString({\n client_id: o.client_id,\n redirect_uri: o.redirect_uri,\n grant_type: 'authorization_code',\n code: auth_code,\n code_verifier: code_verifier\n });\n\n // The authorization server authenticates the client and validates\n // the authorization grant, and if valid, issues an access token.\n oauth.rawxhr('POST', url, null, null, null, accessTokenDone);\n o.loading();\n }\n\n\n /**\n * bringPopupWindowToFront\n * Tries to bring an existing authentication popup to the front.\n *\n * @return {boolean} `true` if it succeeded, `false` if not\n */\n oauth.bringPopupWindowToFront = function() {\n var broughtPopupToFront = false;\n try {\n // This may cause a cross-origin error:\n // `DOMException: Blocked a frame with origin \"...\" from accessing a cross-origin frame.`\n if (oauth.popupWindow && !oauth.popupWindow.closed) {\n oauth.popupWindow.focus();\n broughtPopupToFront = true;\n }\n } catch (err) {\n // Bringing popup window to front failed (probably because of the cross-origin error mentioned above)\n }\n return broughtPopupToFront;\n };\n\n\n /**\n * bootstrapToken\n * The authorization code is a temporary code that a client can exchange for an access token.\n * If using this library in single-page mode, you'll need to call this once your application\n * has an `auth_code` and wants to get an access_token.\n *\n * @param {string} auth_code The OAuth2 `auth_code`\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n oauth.bootstrapToken = function(auth_code, callback) {\n var state = token('oauth2_state');\n token('oauth2_state', '');\n var params = utilStringQs(window.location.search.slice(1));\n if (params.state !== state) {\n var error = new Error('Invalid state');\n error.status = 'invalid-state';\n callback(error);\n return;\n }\n var code_verifier = token('oauth2_pkce_code_verifier');\n token('oauth2_pkce_code_verifier', '');\n _getAccessToken(auth_code, code_verifier, accessTokenDone);\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) {\n callback(err);\n return;\n }\n var access_token = JSON.parse(xhr.response);\n token('oauth2_access_token', access_token.access_token);\n callback(null, oauth);\n }\n };\n\n\n /**\n * fetch\n * A `fetch` wrapper that includes the Authorization header if the user is authenticated.\n * https://developer.mozilla.org/en-US/docs/Web/API/fetch\n *\n * @param {string} resource Resource passed to `fetch`\n * @param {Object} options Options passed to `fetch`\n * @return {Promise} Promise that wraps `authenticateAsync` then `fetch`\n */\n oauth.fetch = function(resource, options) {\n if (oauth.authenticated()) {\n return _doFetch();\n } else {\n if (o.auto) {\n return oauth.authenticateAsync().then(_doFetch);\n } else {\n return Promise.reject(new Error('not authenticated'));\n }\n }\n\n function _doFetch() {\n options = options || {};\n if (!options.headers) {\n options.headers = { 'Content-Type': 'application/x-www-form-urlencoded' };\n }\n options.headers.Authorization = 'Bearer ' + token('oauth2_access_token');\n return fetch(resource, options);\n }\n };\n\n\n /**\n * xhr\n * A `XMLHttpRequest` wrapper that does authenticated calls if the user has logged in.\n * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\n *\n * @param {Object} options\n * @param options.method Passed to `xhr.open` (e.g. 'GET', 'POST')\n * @param options.prefix If `true` path contains a path, if `false` path contains the full url\n * @param options.path The URL path (e.g. \"/api/0.6/user/details\") (or full url, if `prefix`=`false`)\n * @param options.content Passed to `xhr.send`\n * @param options.headers `Object` containing request headers\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return {XMLHttpRequest} `XMLHttpRequest` if authenticated, otherwise `null`\n */\n oauth.xhr = function (options, callback) {\n if (oauth.authenticated()) {\n return _doXHR();\n } else {\n if (o.auto) {\n oauth.authenticate(_doXHR);\n return;\n } else {\n callback('not authenticated', null);\n return;\n }\n }\n\n function _doXHR() {\n var url = options.prefix !== false ? (o.apiUrl + options.path) : options.path;\n return oauth.rawxhr(\n options.method,\n url,\n token('oauth2_access_token'),\n options.content,\n options.headers,\n done\n );\n }\n\n function done(err, xhr) {\n if (err) {\n callback(err);\n } else if (xhr.responseXML) {\n callback(err, xhr.responseXML);\n } else {\n callback(err, xhr.response);\n }\n }\n };\n\n\n /**\n * rawxhr\n * Creates the XMLHttpRequest set up with a header and response handling\n * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\n *\n * @param method Passed to `xhr.open` (e.g. 'GET', 'POST')\n * @param url Passed to `xhr.open`\n * @param access_token OAuth2 bearer token\n * @param data Passed to `xhr.send`\n * @param headers `Object` containing request headers\n * @param callback An \"errback\"-style callback (`err`, `result`), called when complete\n * @return `XMLHttpRequest`\n */\n oauth.rawxhr = function(method, url, access_token, data, headers, callback) {\n headers = headers || { 'Content-Type': 'application/x-www-form-urlencoded' };\n\n if (access_token) {\n headers.Authorization = 'Bearer ' + access_token;\n }\n\n var xhr = new XMLHttpRequest();\n\n xhr.onreadystatechange = function () {\n if (4 === xhr.readyState && 0 !== xhr.status) {\n if (/^20\\d$/.test(xhr.status)) { // a 20x status code - OK\n callback(null, xhr);\n } else {\n callback(xhr, null);\n }\n }\n };\n xhr.onerror = function (e) {\n callback(e, null);\n };\n\n xhr.open(method, url, true);\n for (var h in headers) xhr.setRequestHeader(h, headers[h]);\n\n xhr.send(data);\n return xhr;\n };\n\n\n /**\n * preauth\n * Pre-authorize this object, if we already have access token from the start\n *\n * @param {Object} val Object containing `access_token` property\n * @return `self`\n */\n oauth.preauth = function(val) {\n if (val && val.access_token) {\n token('oauth2_access_token', val.access_token);\n }\n return oauth;\n };\n\n\n /**\n * options (getter / setter)\n * If passed with no arguments, just return the options\n * If passed an Object, set the options then attempt to pre-authorize\n *\n * @param val? Object containing options\n * @return current `options` (if getting), or `self` (if setting)\n */\n oauth.options = function(val) {\n if (!arguments.length) return o;\n\n o = val;\n o.apiUrl = o.apiUrl || 'https://api.openstreetmap.org';\n o.url = o.url || 'https://www.openstreetmap.org';\n o.auto = o.auto || false;\n o.singlepage = o.singlepage || false;\n\n // Optional loading and loading-done functions for nice UI feedback.\n // by default, no-ops\n o.loading = o.loading || function () {};\n o.done = o.done || function () {};\n return oauth.preauth(o);\n };\n\n\n // Everything below here is initialization/setup code\n // Handle options and attempt to pre-authorize\n oauth.options(o);\n\n return oauth;\n}\n\n\n/**\n * utilQsString\n * Transforms object of `key=value` pairs into query string\n * @param {Object} Object of `key=value` pairs\n * @returns {string} query string\n */\nfunction utilQsString(obj) {\n return Object.keys(obj)\n .filter(function(key) {\n return obj[key] !== undefined;\n })\n .sort()\n .map(function(key) {\n return (encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));\n })\n .join('&');\n}\n\n/**\n * utilStringQs\n * Transforms query string into object of `key=value` pairs\n * @param {string} query string\n * @returns {Object} Object of `key=value` pairs\n */\nfunction utilStringQs(str) {\n var i = 0; // advance past any leading '?' or '#' characters\n while (i < str.length && (str[i] === '?' || str[i] === '#')) i++;\n str = str.slice(i);\n\n return str.split('&').reduce(function(obj, pair) {\n var parts = pair.split('=');\n if (parts.length === 2) {\n obj[parts[0]] = decodeURIComponent(parts[1]);\n }\n return obj;\n }, {});\n}\n\n\n/**\n * supportsWebCryptoAPI\n * https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API\n * @returns {boolean} `true` if WebCryptoAPI is available\n */\nfunction supportsWebCryptoAPI() {\n return window && window.crypto\n && window.crypto.getRandomValues\n && window.crypto.subtle\n && window.crypto.subtle.digest;\n}\n\n\n/**\n * Generates a challenge/verifier pair for PKCE.\n * If the browser does not support the WebCryptoAPI, the \"plain\" method is\n * used as a fallback instead of a SHA-256 hash.\n * @param {callback} callback called with the result of the generated PKCE challenge\n */\nfunction _generatePkceChallenge(callback) {\n var code_verifier;\n if (supportsWebCryptoAPI()) {\n // generate a random code_verifier\n // https://datatracker.ietf.org/doc/html/rfc7636#section-7.1\n var random = window.crypto.getRandomValues(new Uint8Array(32));\n code_verifier = base64(random.buffer);\n var verifier = Uint8Array.from(Array.from(code_verifier).map(function(char) {\n return char.charCodeAt(0);\n }));\n\n // generate challenge for code verifier\n window.crypto.subtle.digest('SHA-256', verifier).then(function(hash) {\n var code_challenge = base64(hash);\n\n callback({\n code_challenge: code_challenge,\n code_verifier: code_verifier,\n code_challenge_method: 'S256'\n });\n });\n } else {\n // browser does not support Web Crypto API (e.g. IE11) -> fall back to \"plain\" method\n var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n code_verifier = '';\n for (var i=0; i<64; i++) {\n code_verifier += chars[Math.floor(Math.random() * chars.length)];\n }\n callback({\n code_verifier: code_verifier,\n code_challenge: code_verifier,\n code_challenge_method: 'plain',\n });\n }\n}\n\n\n/**\n * Returns a random state to be used as the \"state\" of the OAuth2 authentication\n * See https://datatracker.ietf.org/doc/html/rfc6749#section-10.12\n */\nfunction generateState() {\n var state;\n if (supportsWebCryptoAPI()) {\n var random = window.crypto.getRandomValues(new Uint8Array(32));\n state = base64(random.buffer);\n } else {\n // browser does not support Web Crypto API (e.g. IE11) -> fall back to \"plain\" method\n var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n state = '';\n for (var i=0; i<64; i++) {\n state += chars[Math.floor(Math.random() * chars.length)];\n }\n }\n return state;\n}\n\n\n/**\n * base64\n * Converts binary buffer to base64 encoded string, as used in rfc7636\n * @param {ArrayBuffer} buffer\n * @returns {string} base64 encoded\n */\nfunction base64(buffer) {\n return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)))\n .replace(/\\//g, '_')\n .replace(/\\+/g, '-')\n .replace(/[=]/g, '');\n}\n"], + "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBO,SAAS,QAAQ,GAAG;AACzB,MAAI,QAAQ,CAAC;AAIb,MAAI,SAAS;AACb,MAAI;AACF,aAAS,OAAO;AAAA,EAClB,SAAS,GAAG;AACV,QAAI,QAAQ,oBAAI,IAAI;AACpB,aAAS;AAAA,MACP,UAAU;AAAA,MACV,SAAS,CAAC,MAAM,MAAM,IAAI,CAAC;AAAA,MAC3B,SAAS,CAAC,MAAM,MAAM,IAAI,CAAC;AAAA,MAC3B,SAAS,CAAC,GAAG,MAAM,MAAM,IAAI,GAAG,CAAC;AAAA,MACjC,YAA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"names": ["url", "params"] } diff --git a/dist/osm-auth.iife.js b/dist/osm-auth.iife.js index d5c74aa..06e2e0f 100644 --- a/dist/osm-auth.iife.js +++ b/dist/osm-auth.iife.js @@ -1,2 +1,2 @@ -var osmAuth=(function(){var Pe=Object.create;var T=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var Fe=Object.getPrototypeOf,qe=Object.prototype.hasOwnProperty;var h=function(e,t){return function(){return t||e((t={exports:{}}).exports,t),t.exports}},Ce=function(e,t){for(var r in t)T(e,r,{get:t[r],enumerable:!0})},$=function(e,t,r,i){if(t&&typeof t=="object"||typeof t=="function")for(var o=Ee(t),u=0,g=o.length,a;u=0;t--){var r=A().key(t);e(Q(r),r)}}function tt(e){return A().removeItem(e)}function rt(){return A().clear()}});var te=h(function(Xt,ee){var nt=y(),at=nt.Global;ee.exports={name:"oldFF-globalStorage",read:it,write:ot,each:V,remove:ut,clearAll:ct};var b=at.globalStorage;function it(e){return b[e]}function ot(e,t){b[e]=t}function V(e){for(var t=b.length-1;t>=0;t--){var r=b.key(t);e(b[r],r)}}function ut(e){return b.removeItem(e)}function ct(){V(function(e,t){delete b[e]})}});var ae=h(function($t,ne){var st=y(),L=st.Global;ne.exports={name:"oldIE-userDataStorage",write:ft,read:lt,each:pt,remove:dt,clearAll:gt};var E="storejs",P=L.document,F=vt(),re=(L.navigator?L.navigator.userAgent:"").match(/ (MSIE 8|MSIE 9|MSIE 10)\./);function ft(e,t){if(!re){var r=z(e);F(function(i){i.setAttribute(r,t),i.save(E)})}}function lt(e){if(!re){var t=z(e),r=null;return F(function(i){r=i.getAttribute(t)}),r}}function pt(e){F(function(t){for(var r=t.XMLDocument.documentElement.attributes,i=r.length-1;i>=0;i--){var o=r[i];e(t.getAttribute(o.name),o.name)}})}function dt(e){var t=z(e);F(function(r){r.removeAttribute(t),r.save(E)})}function gt(){F(function(e){var t=e.XMLDocument.documentElement.attributes;e.load(E);for(var r=t.length-1;r>=0;r--)e.removeAttribute(t[r].name);e.save(E)})}var ht=new RegExp("[!\"#$%&'()*+,/\\\\:;<=>?@[\\]^`{|}~]","g");function z(e){return e.replace(/^\d/,"___$&").replace(ht,"___")}function vt(){if(!P||!P.documentElement||!P.documentElement.addBehavior)return null;var e="script",t,r,i;try{r=new ActiveXObject("htmlfile"),r.open(),r.write("<"+e+">document.w=window'),r.close(),t=r.w.frames[0].document,i=t.createElement("div")}catch(o){i=P.createElement("div"),t=P.body}return function(o){var u=[].slice.call(arguments,0);u.unshift(i),t.appendChild(i),i.addBehavior("#default#userData"),i.load(E),o.apply(this,u),t.removeChild(i)}}});var fe=h(function(Bt,se){var ie=y(),_t=ie.Global,mt=ie.trim;se.exports={name:"cookieStorage",read:wt,write:yt,each:oe,remove:ue,clearAll:bt};var q=_t.document;function wt(e){if(!e||!ce(e))return null;var t="(?:^|.*;\\s*)"+escape(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(q.cookie.replace(new RegExp(t),"$1"))}function oe(e){for(var t=q.cookie.split(/; ?/g),r=t.length-1;r>=0;r--)if(mt(t[r])){var i=t[r].split("="),o=unescape(i[0]),u=unescape(i[1]);e(u,o)}}function yt(e,t){e&&(q.cookie=escape(e)+"="+escape(t)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/")}function ue(e){!e||!ce(e)||(q.cookie=escape(e)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function bt(){oe(function(e,t){ue(t)})}function ce(e){return new RegExp("(?:^|;\\s*)"+escape(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(q.cookie)}});var de=h(function(Wt,pe){var St=y(),xt=St.Global;pe.exports={name:"sessionStorage",read:le,write:At,each:Ot,remove:Pt,clearAll:jt};function O(){return xt.sessionStorage}function le(e){return O().getItem(e)}function At(e,t){return O().setItem(e,t)}function Ot(e){for(var t=O().length-1;t>=0;t--){var r=O().key(t);e(le(r),r)}}function Pt(e){return O().removeItem(e)}function jt(){return O().clear()}});var he=h(function(Ht,ge){ge.exports={name:"memoryStorage",read:Et,write:Ft,each:qt,remove:Ct,clearAll:Tt};var S={};function Et(e){return S[e]}function Ft(e,t){S[e]=t}function qt(e){for(var t in S)S.hasOwnProperty(t)&&e(S[t],t)}function Ct(e){delete S[e]}function Tt(e){S={}}});var _e=h(function(Kt,ve){ve.exports=[Y(),te(),ae(),fe(),de(),he()]});var me=h(function(exports,module){typeof JSON!="object"&&(JSON={});(function(){"use strict";var rx_one=/^[\],:{}\s]*$/,rx_two=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,rx_three=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,rx_four=/(?:^|:|,)(?:\s*\[)+/g,rx_escapable=/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,rx_dangerous=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;function f(e){return e<10?"0"+e:e}function this_value(){return this.valueOf()}typeof Date.prototype.toJSON!="function"&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},Boolean.prototype.toJSON=this_value,Number.prototype.toJSON=this_value,String.prototype.toJSON=this_value);var gap,indent,meta,rep;function quote(e){return rx_escapable.lastIndex=0,rx_escapable.test(e)?'"'+e.replace(rx_escapable,function(t){var r=meta[t];return typeof r=="string"?r:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function str(e,t){var r,i,o,u,g=gap,a,n=t[e];switch(n&&typeof n=="object"&&typeof n.toJSON=="function"&&(n=n.toJSON(e)),typeof rep=="function"&&(n=rep.call(t,e,n)),typeof n){case"string":return quote(n);case"number":return isFinite(n)?String(n):"null";case"boolean":case"null":return String(n);case"object":if(!n)return"null";if(gap+=indent,a=[],Object.prototype.toString.apply(n)==="[object Array]"){for(u=n.length,r=0;r= 0; i--) {\n\t\tvar key = localStorage().key(i)\n\t\tfn(read(key), key)\n\t}\n}\n\nfunction remove(key) {\n\treturn localStorage().removeItem(key)\n}\n\nfunction clearAll() {\n\treturn localStorage().clear()\n}\n", "// oldFF-globalStorage provides storage for Firefox\n// versions 6 and 7, where no localStorage, etc\n// is available.\n\nvar util = require('../src/util')\nvar Global = util.Global\n\nmodule.exports = {\n\tname: 'oldFF-globalStorage',\n\tread: read,\n\twrite: write,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll,\n}\n\nvar globalStorage = Global.globalStorage\n\nfunction read(key) {\n\treturn globalStorage[key]\n}\n\nfunction write(key, data) {\n\tglobalStorage[key] = data\n}\n\nfunction each(fn) {\n\tfor (var i = globalStorage.length - 1; i >= 0; i--) {\n\t\tvar key = globalStorage.key(i)\n\t\tfn(globalStorage[key], key)\n\t}\n}\n\nfunction remove(key) {\n\treturn globalStorage.removeItem(key)\n}\n\nfunction clearAll() {\n\teach(function(key, _) {\n\t\tdelete globalStorage[key]\n\t})\n}\n", "// oldIE-userDataStorage provides storage for Internet Explorer\n// versions 6 and 7, where no localStorage, sessionStorage, etc\n// is available.\n\nvar util = require('../src/util')\nvar Global = util.Global\n\nmodule.exports = {\n\tname: 'oldIE-userDataStorage',\n\twrite: write,\n\tread: read,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll,\n}\n\nvar storageName = 'storejs'\nvar doc = Global.document\nvar _withStorageEl = _makeIEStorageElFunction()\nvar disable = (Global.navigator ? Global.navigator.userAgent : '').match(/ (MSIE 8|MSIE 9|MSIE 10)\\./) // MSIE 9.x, MSIE 10.x\n\nfunction write(unfixedKey, data) {\n\tif (disable) { return }\n\tvar fixedKey = fixKey(unfixedKey)\n\t_withStorageEl(function(storageEl) {\n\t\tstorageEl.setAttribute(fixedKey, data)\n\t\tstorageEl.save(storageName)\n\t})\n}\n\nfunction read(unfixedKey) {\n\tif (disable) { return }\n\tvar fixedKey = fixKey(unfixedKey)\n\tvar res = null\n\t_withStorageEl(function(storageEl) {\n\t\tres = storageEl.getAttribute(fixedKey)\n\t})\n\treturn res\n}\n\nfunction each(callback) {\n\t_withStorageEl(function(storageEl) {\n\t\tvar attributes = storageEl.XMLDocument.documentElement.attributes\n\t\tfor (var i=attributes.length-1; i>=0; i--) {\n\t\t\tvar attr = attributes[i]\n\t\t\tcallback(storageEl.getAttribute(attr.name), attr.name)\n\t\t}\n\t})\n}\n\nfunction remove(unfixedKey) {\n\tvar fixedKey = fixKey(unfixedKey)\n\t_withStorageEl(function(storageEl) {\n\t\tstorageEl.removeAttribute(fixedKey)\n\t\tstorageEl.save(storageName)\n\t})\n}\n\nfunction clearAll() {\n\t_withStorageEl(function(storageEl) {\n\t\tvar attributes = storageEl.XMLDocument.documentElement.attributes\n\t\tstorageEl.load(storageName)\n\t\tfor (var i=attributes.length-1; i>=0; i--) {\n\t\t\tstorageEl.removeAttribute(attributes[i].name)\n\t\t}\n\t\tstorageEl.save(storageName)\n\t})\n}\n\n// Helpers\n//////////\n\n// In IE7, keys cannot start with a digit or contain certain chars.\n// See https://github.com/marcuswestin/store.js/issues/40\n// See https://github.com/marcuswestin/store.js/issues/83\nvar forbiddenCharsRegex = new RegExp(\"[!\\\"#$%&'()*+,/\\\\\\\\:;<=>?@[\\\\]^`{|}~]\", \"g\")\nfunction fixKey(key) {\n\treturn key.replace(/^\\d/, '___$&').replace(forbiddenCharsRegex, '___')\n}\n\nfunction _makeIEStorageElFunction() {\n\tif (!doc || !doc.documentElement || !doc.documentElement.addBehavior) {\n\t\treturn null\n\t}\n\tvar scriptTag = 'script',\n\t\tstorageOwner,\n\t\tstorageContainer,\n\t\tstorageEl\n\n\t// Since #userData storage applies only to specific paths, we need to\n\t// somehow link our data to a specific path. We choose /favicon.ico\n\t// as a pretty safe option, since all browsers already make a request to\n\t// this URL anyway and being a 404 will not hurt us here. We wrap an\n\t// iframe pointing to the favicon in an ActiveXObject(htmlfile) object\n\t// (see: http://msdn.microsoft.com/en-us/library/aa752574(v=VS.85).aspx)\n\t// since the iframe access rules appear to allow direct access and\n\t// manipulation of the document element, even for a 404 page. This\n\t// document can be used instead of the current document (which would\n\t// have been limited to the current path) to perform #userData storage.\n\ttry {\n\t\t/* global ActiveXObject */\n\t\tstorageContainer = new ActiveXObject('htmlfile')\n\t\tstorageContainer.open()\n\t\tstorageContainer.write('<'+scriptTag+'>document.w=window')\n\t\tstorageContainer.close()\n\t\tstorageOwner = storageContainer.w.frames[0].document\n\t\tstorageEl = storageOwner.createElement('div')\n\t} catch(e) {\n\t\t// somehow ActiveXObject instantiation failed (perhaps some special\n\t\t// security settings or otherwse), fall back to per-path storage\n\t\tstorageEl = doc.createElement('div')\n\t\tstorageOwner = doc.body\n\t}\n\n\treturn function(storeFunction) {\n\t\tvar args = [].slice.call(arguments, 0)\n\t\targs.unshift(storageEl)\n\t\t// See http://msdn.microsoft.com/en-us/library/ms531081(v=VS.85).aspx\n\t\t// and http://msdn.microsoft.com/en-us/library/ms531424(v=VS.85).aspx\n\t\tstorageOwner.appendChild(storageEl)\n\t\tstorageEl.addBehavior('#default#userData')\n\t\tstorageEl.load(storageName)\n\t\tstoreFunction.apply(this, args)\n\t\tstorageOwner.removeChild(storageEl)\n\t\treturn\n\t}\n}\n", "// cookieStorage is useful Safari private browser mode, where localStorage\n// doesn't work but cookies do. This implementation is adopted from\n// https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage\n\nvar util = require('../src/util')\nvar Global = util.Global\nvar trim = util.trim\n\nmodule.exports = {\n\tname: 'cookieStorage',\n\tread: read,\n\twrite: write,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll,\n}\n\nvar doc = Global.document\n\nfunction read(key) {\n\tif (!key || !_has(key)) { return null }\n\tvar regexpStr = \"(?:^|.*;\\\\s*)\" +\n\t\tescape(key).replace(/[\\-\\.\\+\\*]/g, \"\\\\$&\") +\n\t\t\"\\\\s*\\\\=\\\\s*((?:[^;](?!;))*[^;]?).*\"\n\treturn unescape(doc.cookie.replace(new RegExp(regexpStr), \"$1\"))\n}\n\nfunction each(callback) {\n\tvar cookies = doc.cookie.split(/; ?/g)\n\tfor (var i = cookies.length - 1; i >= 0; i--) {\n\t\tif (!trim(cookies[i])) {\n\t\t\tcontinue\n\t\t}\n\t\tvar kvp = cookies[i].split('=')\n\t\tvar key = unescape(kvp[0])\n\t\tvar val = unescape(kvp[1])\n\t\tcallback(val, key)\n\t}\n}\n\nfunction write(key, data) {\n\tif(!key) { return }\n\tdoc.cookie = escape(key) + \"=\" + escape(data) + \"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/\"\n}\n\nfunction remove(key) {\n\tif (!key || !_has(key)) {\n\t\treturn\n\t}\n\tdoc.cookie = escape(key) + \"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/\"\n}\n\nfunction clearAll() {\n\teach(function(_, key) {\n\t\tremove(key)\n\t})\n}\n\nfunction _has(key) {\n\treturn (new RegExp(\"(?:^|;\\\\s*)\" + escape(key).replace(/[\\-\\.\\+\\*]/g, \"\\\\$&\") + \"\\\\s*\\\\=\")).test(doc.cookie)\n}\n", "var util = require('../src/util')\nvar Global = util.Global\n\nmodule.exports = {\n\tname: 'sessionStorage',\n\tread: read,\n\twrite: write,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll\n}\n\nfunction sessionStorage() {\n\treturn Global.sessionStorage\n}\n\nfunction read(key) {\n\treturn sessionStorage().getItem(key)\n}\n\nfunction write(key, data) {\n\treturn sessionStorage().setItem(key, data)\n}\n\nfunction each(fn) {\n\tfor (var i = sessionStorage().length - 1; i >= 0; i--) {\n\t\tvar key = sessionStorage().key(i)\n\t\tfn(read(key), key)\n\t}\n}\n\nfunction remove(key) {\n\treturn sessionStorage().removeItem(key)\n}\n\nfunction clearAll() {\n\treturn sessionStorage().clear()\n}\n", "// memoryStorage is a useful last fallback to ensure that the store\n// is functions (meaning store.get(), store.set(), etc will all function).\n// However, stored values will not persist when the browser navigates to\n// a new page or reloads the current page.\n\nmodule.exports = {\n\tname: 'memoryStorage',\n\tread: read,\n\twrite: write,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll,\n}\n\nvar memoryStorage = {}\n\nfunction read(key) {\n\treturn memoryStorage[key]\n}\n\nfunction write(key, data) {\n\tmemoryStorage[key] = data\n}\n\nfunction each(callback) {\n\tfor (var key in memoryStorage) {\n\t\tif (memoryStorage.hasOwnProperty(key)) {\n\t\t\tcallback(memoryStorage[key], key)\n\t\t}\n\t}\n}\n\nfunction remove(key) {\n\tdelete memoryStorage[key]\n}\n\nfunction clearAll(key) {\n\tmemoryStorage = {}\n}\n", "module.exports = [\n\t// Listed in order of usage preference\n\trequire('./localStorage'),\n\trequire('./oldFF-globalStorage'),\n\trequire('./oldIE-userDataStorage'),\n\trequire('./cookieStorage'),\n\trequire('./sessionStorage'),\n\trequire('./memoryStorage')\n]\n", "/* eslint-disable */\n\n// json2.js\n// 2016-10-28\n// Public Domain.\n// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n// See http://www.JSON.org/js.html\n// This code should be minified before deployment.\n// See http://javascript.crockford.com/jsmin.html\n\n// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO\n// NOT CONTROL.\n\n// This file creates a global JSON object containing two methods: stringify\n// and parse. This file provides the ES5 JSON capability to ES3 systems.\n// If a project might run on IE8 or earlier, then this file should be included.\n// This file does nothing on ES5 systems.\n\n// JSON.stringify(value, replacer, space)\n// value any JavaScript value, usually an object or array.\n// replacer an optional parameter that determines how object\n// values are stringified for objects. It can be a\n// function or an array of strings.\n// space an optional parameter that specifies the indentation\n// of nested structures. If it is omitted, the text will\n// be packed without extra whitespace. If it is a number,\n// it will specify the number of spaces to indent at each\n// level. If it is a string (such as \"\\t\" or \" \"),\n// it contains the characters used to indent at each level.\n// This method produces a JSON text from a JavaScript value.\n// When an object value is found, if the object contains a toJSON\n// method, its toJSON method will be called and the result will be\n// stringified. A toJSON method does not serialize: it returns the\n// value represented by the name/value pair that should be serialized,\n// or undefined if nothing should be serialized. The toJSON method\n// will be passed the key associated with the value, and this will be\n// bound to the value.\n\n// For example, this would serialize Dates as ISO strings.\n\n// Date.prototype.toJSON = function (key) {\n// function f(n) {\n// // Format integers to have at least two digits.\n// return (n < 10)\n// ? \"0\" + n\n// : n;\n// }\n// return this.getUTCFullYear() + \"-\" +\n// f(this.getUTCMonth() + 1) + \"-\" +\n// f(this.getUTCDate()) + \"T\" +\n// f(this.getUTCHours()) + \":\" +\n// f(this.getUTCMinutes()) + \":\" +\n// f(this.getUTCSeconds()) + \"Z\";\n// };\n\n// You can provide an optional replacer method. It will be passed the\n// key and value of each member, with this bound to the containing\n// object. The value that is returned from your method will be\n// serialized. If your method returns undefined, then the member will\n// be excluded from the serialization.\n\n// If the replacer parameter is an array of strings, then it will be\n// used to select the members to be serialized. It filters the results\n// such that only members with keys listed in the replacer array are\n// stringified.\n\n// Values that do not have JSON representations, such as undefined or\n// functions, will not be serialized. Such values in objects will be\n// dropped; in arrays they will be replaced with null. You can use\n// a replacer function to replace those with JSON values.\n\n// JSON.stringify(undefined) returns undefined.\n\n// The optional space parameter produces a stringification of the\n// value that is filled with line breaks and indentation to make it\n// easier to read.\n\n// If the space parameter is a non-empty string, then that string will\n// be used for indentation. If the space parameter is a number, then\n// the indentation will be that many spaces.\n\n// Example:\n\n// text = JSON.stringify([\"e\", {pluribus: \"unum\"}]);\n// // text is '[\"e\",{\"pluribus\":\"unum\"}]'\n\n// text = JSON.stringify([\"e\", {pluribus: \"unum\"}], null, \"\\t\");\n// // text is '[\\n\\t\"e\",\\n\\t{\\n\\t\\t\"pluribus\": \"unum\"\\n\\t}\\n]'\n\n// text = JSON.stringify([new Date()], function (key, value) {\n// return this[key] instanceof Date\n// ? \"Date(\" + this[key] + \")\"\n// : value;\n// });\n// // text is '[\"Date(---current time---)\"]'\n\n// JSON.parse(text, reviver)\n// This method parses a JSON text to produce an object or array.\n// It can throw a SyntaxError exception.\n\n// The optional reviver parameter is a function that can filter and\n// transform the results. It receives each of the keys and values,\n// and its return value is used instead of the original value.\n// If it returns what it received, then the structure is not modified.\n// If it returns undefined then the member is deleted.\n\n// Example:\n\n// // Parse the text. Values that look like ISO date strings will\n// // be converted to Date objects.\n\n// myData = JSON.parse(text, function (key, value) {\n// var a;\n// if (typeof value === \"string\") {\n// a =\n// /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2}(?:\\.\\d*)?)Z$/.exec(value);\n// if (a) {\n// return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],\n// +a[5], +a[6]));\n// }\n// }\n// return value;\n// });\n\n// myData = JSON.parse('[\"Date(09/09/2001)\"]', function (key, value) {\n// var d;\n// if (typeof value === \"string\" &&\n// value.slice(0, 5) === \"Date(\" &&\n// value.slice(-1) === \")\") {\n// d = new Date(value.slice(5, -1));\n// if (d) {\n// return d;\n// }\n// }\n// return value;\n// });\n\n// This is a reference implementation. You are free to copy, modify, or\n// redistribute.\n\n/*jslint\n eval, for, this\n*/\n\n/*property\n JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,\n getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,\n lastIndex, length, parse, prototype, push, replace, slice, stringify,\n test, toJSON, toString, valueOf\n*/\n\n\n// Create a JSON object only if one does not already exist. We create the\n// methods in a closure to avoid creating global variables.\n\nif (typeof JSON !== \"object\") {\n JSON = {};\n}\n\n(function () {\n \"use strict\";\n\n var rx_one = /^[\\],:{}\\s]*$/;\n var rx_two = /\\\\(?:[\"\\\\\\/bfnrt]|u[0-9a-fA-F]{4})/g;\n var rx_three = /\"[^\"\\\\\\n\\r]*\"|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g;\n var rx_four = /(?:^|:|,)(?:\\s*\\[)+/g;\n var rx_escapable = /[\\\\\"\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g;\n var rx_dangerous = /[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g;\n\n function f(n) {\n // Format integers to have at least two digits.\n return n < 10\n ? \"0\" + n\n : n;\n }\n\n function this_value() {\n return this.valueOf();\n }\n\n if (typeof Date.prototype.toJSON !== \"function\") {\n\n Date.prototype.toJSON = function () {\n\n return isFinite(this.valueOf())\n ? this.getUTCFullYear() + \"-\" +\n f(this.getUTCMonth() + 1) + \"-\" +\n f(this.getUTCDate()) + \"T\" +\n f(this.getUTCHours()) + \":\" +\n f(this.getUTCMinutes()) + \":\" +\n f(this.getUTCSeconds()) + \"Z\"\n : null;\n };\n\n Boolean.prototype.toJSON = this_value;\n Number.prototype.toJSON = this_value;\n String.prototype.toJSON = this_value;\n }\n\n var gap;\n var indent;\n var meta;\n var rep;\n\n\n function quote(string) {\n\n// If the string contains no control characters, no quote characters, and no\n// backslash characters, then we can safely slap some quotes around it.\n// Otherwise we must also replace the offending characters with safe escape\n// sequences.\n\n rx_escapable.lastIndex = 0;\n return rx_escapable.test(string)\n ? \"\\\"\" + string.replace(rx_escapable, function (a) {\n var c = meta[a];\n return typeof c === \"string\"\n ? c\n : \"\\\\u\" + (\"0000\" + a.charCodeAt(0).toString(16)).slice(-4);\n }) + \"\\\"\"\n : \"\\\"\" + string + \"\\\"\";\n }\n\n\n function str(key, holder) {\n\n// Produce a string from holder[key].\n\n var i; // The loop counter.\n var k; // The member key.\n var v; // The member value.\n var length;\n var mind = gap;\n var partial;\n var value = holder[key];\n\n// If the value has a toJSON method, call it to obtain a replacement value.\n\n if (value && typeof value === \"object\" &&\n typeof value.toJSON === \"function\") {\n value = value.toJSON(key);\n }\n\n// If we were called with a replacer function, then call the replacer to\n// obtain a replacement value.\n\n if (typeof rep === \"function\") {\n value = rep.call(holder, key, value);\n }\n\n// What happens next depends on the value's type.\n\n switch (typeof value) {\n case \"string\":\n return quote(value);\n\n case \"number\":\n\n// JSON numbers must be finite. Encode non-finite numbers as null.\n\n return isFinite(value)\n ? String(value)\n : \"null\";\n\n case \"boolean\":\n case \"null\":\n\n// If the value is a boolean or null, convert it to a string. Note:\n// typeof null does not produce \"null\". The case is included here in\n// the remote chance that this gets fixed someday.\n\n return String(value);\n\n// If the type is \"object\", we might be dealing with an object or an array or\n// null.\n\n case \"object\":\n\n// Due to a specification blunder in ECMAScript, typeof null is \"object\",\n// so watch out for that case.\n\n if (!value) {\n return \"null\";\n }\n\n// Make an array to hold the partial results of stringifying this object value.\n\n gap += indent;\n partial = [];\n\n// Is the value an array?\n\n if (Object.prototype.toString.apply(value) === \"[object Array]\") {\n\n// The value is an array. Stringify every element. Use null as a placeholder\n// for non-JSON values.\n\n length = value.length;\n for (i = 0; i < length; i += 1) {\n partial[i] = str(i, value) || \"null\";\n }\n\n// Join all of the elements together, separated with commas, and wrap them in\n// brackets.\n\n v = partial.length === 0\n ? \"[]\"\n : gap\n ? \"[\\n\" + gap + partial.join(\",\\n\" + gap) + \"\\n\" + mind + \"]\"\n : \"[\" + partial.join(\",\") + \"]\";\n gap = mind;\n return v;\n }\n\n// If the replacer is an array, use it to select the members to be stringified.\n\n if (rep && typeof rep === \"object\") {\n length = rep.length;\n for (i = 0; i < length; i += 1) {\n if (typeof rep[i] === \"string\") {\n k = rep[i];\n v = str(k, value);\n if (v) {\n partial.push(quote(k) + (\n gap\n ? \": \"\n : \":\"\n ) + v);\n }\n }\n }\n } else {\n\n// Otherwise, iterate through all of the keys in the object.\n\n for (k in value) {\n if (Object.prototype.hasOwnProperty.call(value, k)) {\n v = str(k, value);\n if (v) {\n partial.push(quote(k) + (\n gap\n ? \": \"\n : \":\"\n ) + v);\n }\n }\n }\n }\n\n// Join all of the member texts together, separated with commas,\n// and wrap them in braces.\n\n v = partial.length === 0\n ? \"{}\"\n : gap\n ? \"{\\n\" + gap + partial.join(\",\\n\" + gap) + \"\\n\" + mind + \"}\"\n : \"{\" + partial.join(\",\") + \"}\";\n gap = mind;\n return v;\n }\n }\n\n// If the JSON object does not yet have a stringify method, give it one.\n\n if (typeof JSON.stringify !== \"function\") {\n meta = { // table of character substitutions\n \"\\b\": \"\\\\b\",\n \"\\t\": \"\\\\t\",\n \"\\n\": \"\\\\n\",\n \"\\f\": \"\\\\f\",\n \"\\r\": \"\\\\r\",\n \"\\\"\": \"\\\\\\\"\",\n \"\\\\\": \"\\\\\\\\\"\n };\n JSON.stringify = function (value, replacer, space) {\n\n// The stringify method takes a value and an optional replacer, and an optional\n// space parameter, and returns a JSON text. The replacer can be a function\n// that can replace values, or an array of strings that will select the keys.\n// A default replacer method can be provided. Use of the space parameter can\n// produce text that is more easily readable.\n\n var i;\n gap = \"\";\n indent = \"\";\n\n// If the space parameter is a number, make an indent string containing that\n// many spaces.\n\n if (typeof space === \"number\") {\n for (i = 0; i < space; i += 1) {\n indent += \" \";\n }\n\n// If the space parameter is a string, it will be used as the indent string.\n\n } else if (typeof space === \"string\") {\n indent = space;\n }\n\n// If there is a replacer, it must be a function or an array.\n// Otherwise, throw an error.\n\n rep = replacer;\n if (replacer && typeof replacer !== \"function\" &&\n (typeof replacer !== \"object\" ||\n typeof replacer.length !== \"number\")) {\n throw new Error(\"JSON.stringify\");\n }\n\n// Make a fake root object containing our value under the key of \"\".\n// Return the result of stringifying the value.\n\n return str(\"\", {\"\": value});\n };\n }\n\n\n// If the JSON object does not yet have a parse method, give it one.\n\n if (typeof JSON.parse !== \"function\") {\n JSON.parse = function (text, reviver) {\n\n// The parse method takes a text and an optional reviver function, and returns\n// a JavaScript value if the text is a valid JSON text.\n\n var j;\n\n function walk(holder, key) {\n\n// The walk method is used to recursively walk the resulting structure so\n// that modifications can be made.\n\n var k;\n var v;\n var value = holder[key];\n if (value && typeof value === \"object\") {\n for (k in value) {\n if (Object.prototype.hasOwnProperty.call(value, k)) {\n v = walk(value, k);\n if (v !== undefined) {\n value[k] = v;\n } else {\n delete value[k];\n }\n }\n }\n }\n return reviver.call(holder, key, value);\n }\n\n\n// Parsing happens in four stages. In the first stage, we replace certain\n// Unicode characters with escape sequences. JavaScript handles many characters\n// incorrectly, either silently deleting them, or treating them as line endings.\n\n text = String(text);\n rx_dangerous.lastIndex = 0;\n if (rx_dangerous.test(text)) {\n text = text.replace(rx_dangerous, function (a) {\n return \"\\\\u\" +\n (\"0000\" + a.charCodeAt(0).toString(16)).slice(-4);\n });\n }\n\n// In the second stage, we run the text against regular expressions that look\n// for non-JSON patterns. We are especially concerned with \"()\" and \"new\"\n// because they can cause invocation, and \"=\" because it can cause mutation.\n// But just to be safe, we want to reject all unexpected forms.\n\n// We split the second stage into 4 regexp operations in order to work around\n// crippling inefficiencies in IE's and Safari's regexp engines. First we\n// replace the JSON backslash pairs with \"@\" (a non-JSON character). Second, we\n// replace all simple value tokens with \"]\" characters. Third, we delete all\n// open brackets that follow a colon or comma or that begin the text. Finally,\n// we look to see that the remaining characters are only whitespace or \"]\" or\n// \",\" or \":\" or \"{\" or \"}\". If that is so, then the text is safe for eval.\n\n if (\n rx_one.test(\n text\n .replace(rx_two, \"@\")\n .replace(rx_three, \"]\")\n .replace(rx_four, \"\")\n )\n ) {\n\n// In the third stage we use the eval function to compile the text into a\n// JavaScript structure. The \"{\" operator is subject to a syntactic ambiguity\n// in JavaScript: it can begin a block or an object literal. We wrap the text\n// in parens to eliminate the ambiguity.\n\n j = eval(\"(\" + text + \")\");\n\n// In the optional fourth stage, we recursively walk the new structure, passing\n// each name/value pair to a reviver function for possible transformation.\n\n return (typeof reviver === \"function\")\n ? walk({\"\": j}, \"\")\n : j;\n }\n\n// If the text is not JSON parseable, then a SyntaxError is thrown.\n\n throw new SyntaxError(\"JSON.parse\");\n };\n }\n}());", "module.exports = json2Plugin\n\nfunction json2Plugin() {\n\trequire('./lib/json2')\n\treturn {}\n}\n", "var engine = require('../src/store-engine')\n\nvar storages = require('../storages/all')\nvar plugins = [require('../plugins/json2')]\n\nmodule.exports = engine.createStore(storages, plugins)\n", "import store from 'store';\n\n\n/**\n * osmAuth\n * Easy authentication with OpenStreetMap over OAuth 2.0.\n * @module\n *\n * @param o `Object` containing options:\n * @param o.scope OAuth2 scopes requested (e.g. \"read_prefs write_api\")\n * @param o.client_id OAuth2 client ID\n * @param o.redirect_uri OAuth2 redirect URI (e.g. \"http://127.0.0.1:8080/land.html\")\n * @param o.access_token Can pre-authorize with an OAuth2 bearer token if you have one\n * @param o.apiUrl A base url for the OSM API (default: \"https://api.openstreetmap.org\")\n * @param o.url A base url for the OAuth2 handshake (default: \"https://www.openstreetmap.org\")\n * @param o.auto If `true`, attempt to authenticate automatically when calling `.xhr()` or `.fetch()` (default: `false`)\n * @param o.singlepage If `true`, use page redirection instead of a popup (default: `false`)\n * @param o.loading Function called when auth-related xhr calls start\n * @param o.done Function called when auth-related xhr calls end\n * @return `self`\n */\nexport function osmAuth(o) {\n var oauth = {};\n\n /**\n * authenticated\n * Test whether the user is currently authenticated\n *\n * @return {boolean} `true` if authenticated, `false` if not\n */\n oauth.authenticated = function() {\n return !!token('oauth2_access_token');\n };\n\n\n /**\n * logout\n * Removes any stored authentication tokens (legacy OAuth1 tokens too)\n *\n * @return `self`\n */\n oauth.logout = function () {\n token('oauth2_access_token', ''); // OAuth2\n token('oauth_token', ''); // OAuth1\n token('oauth_token_secret', ''); // OAuth1\n token('oauth_request_token_secret', ''); // OAuth1\n return oauth;\n };\n\n\n /**\n * authenticate\n * First logs out, then runs the authentiation flow, finally calls the callback.\n * TODO: detect lack of click event (probably can settimeout it)\n *\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n oauth.authenticate = function(callback) {\n if (oauth.authenticated()) {\n callback(null, oauth);\n return;\n }\n\n oauth.logout();\n\n _preopenPopup(function(error, popup) {\n if (error) {\n callback(error);\n } else {\n _generatePkceChallenge(function(pkce) {\n _authenticate(pkce, popup, callback);\n });\n }\n });\n };\n\n\n /**\n * authenticateAsync\n * Promisified version of `authenticate`\n * @return {Promise} Promise settled with whatever `_authenticate` did\n */\n oauth.authenticateAsync = function() {\n if (oauth.authenticated()) {\n return Promise.resolve(oauth);\n }\n\n oauth.logout();\n\n return new Promise((resolve, reject) => {\n var errback = (err, result) => {\n if (err) {\n reject(err);\n } else {\n resolve(result);\n }\n };\n\n _preopenPopup((error, popup) => {\n if (error) {\n errback(error);\n } else {\n _generatePkceChallenge(pkce => _authenticate(pkce, popup, errback));\n }\n });\n });\n };\n\n\n /**\n * opens an empty popup to be later used for the authentication page\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n function _preopenPopup(callback) {\n if (o.singlepage) {\n callback(null, undefined);\n return;\n }\n\n // Create a 550x610 popup window in the center of the screen\n var w = 550;\n var h = 610;\n var settings = [\n ['width', w],\n ['height', h],\n ['left', window.screen.width / 2 - w / 2],\n ['top', window.screen.height / 2 - h / 2],\n ]\n .map(function (x) { return x.join('='); })\n .join(',');\n var popup = window.open('about:blank', 'oauth_window', settings);\n if (popup) {\n callback(null, popup);\n } else {\n var error = new Error('Popup was blocked');\n error.status = 'popup-blocked';\n callback(error);\n }\n }\n\n\n /**\n * _authenticate\n * internal authenticate\n *\n * @param {Object} pkce Object containing PKCE code challenge properties\n * @param {Window} popup Popup Window to use for the authentication page, should be undefined when using singlepage mode\n * @param {function} callback Errback-style callback that accepts `(err, result)`\n */\n function _authenticate(pkce, popup, callback) {\n var state = generateState();\n\n // ## Request authorization to access resources from the user\n // and receive authorization code\n var url =\n o.url +\n '/oauth2/authorize?' +\n utilQsString({\n client_id: o.client_id,\n redirect_uri: o.redirect_uri,\n response_type: 'code',\n scope: o.scope,\n state: state,\n code_challenge: pkce.code_challenge,\n code_challenge_method: pkce.code_challenge_method,\n });\n\n if (o.singlepage) {\n if (!store.enabled) {\n // in singlepage mode, PKCE requires working non-volatile storage\n var error = new Error('local storage unavailable, but require in singlepage mode');\n error.status = 'pkce-localstorage-unavailable';\n callback(error);\n return;\n }\n var params = utilStringQs(window.location.search.slice(1));\n if (params.code) {\n oauth.bootstrapToken(params.code, callback);\n } else {\n // save OAuth2 state and PKCE challenge in local storage, for later use\n // in the `/oauth/token` request\n token('oauth2_state', state);\n token('oauth2_pkce_code_verifier', pkce.code_verifier);\n window.location = url;\n }\n } else {\n oauth.popupWindow = popup;\n popup.location = url;\n }\n\n // Called by a function in the redirect URL page, in the popup window. The\n // window closes itself.\n window.authComplete = function (url) {\n var params = utilStringQs(url.split('?')[1]);\n if (params.state !== state) {\n error = new Error('Invalid state');\n error.status = 'invalid-state';\n callback(error);\n return;\n }\n _getAccessToken(params.code, pkce.code_verifier, accessTokenDone);\n delete window.authComplete;\n };\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) {\n callback(err);\n return;\n }\n var access_token = JSON.parse(xhr.response);\n token('oauth2_access_token', access_token.access_token);\n callback(null, oauth);\n }\n }\n\n\n /**\n * _getAccessToken\n * The client requests an access token by authenticating with the\n * authorization server and presenting the `auth_code`, brought\n * in from a function call on a landing page popup.\n * @param {string} auth_code\n * @param {string} code_verifier\n * @param {function} accessTokenDone Errback-style callback `(err, result)`, called when complete\n */\n function _getAccessToken(auth_code, code_verifier, accessTokenDone) {\n var url =\n o.url +\n '/oauth2/token?' +\n utilQsString({\n client_id: o.client_id,\n redirect_uri: o.redirect_uri,\n grant_type: 'authorization_code',\n code: auth_code,\n code_verifier: code_verifier\n });\n\n // The authorization server authenticates the client and validates\n // the authorization grant, and if valid, issues an access token.\n oauth.rawxhr('POST', url, null, null, null, accessTokenDone);\n o.loading();\n }\n\n\n /**\n * bringPopupWindowToFront\n * Tries to bring an existing authentication popup to the front.\n *\n * @return {boolean} `true` if it succeeded, `false` if not\n */\n oauth.bringPopupWindowToFront = function() {\n var broughtPopupToFront = false;\n try {\n // This may cause a cross-origin error:\n // `DOMException: Blocked a frame with origin \"...\" from accessing a cross-origin frame.`\n if (oauth.popupWindow && !oauth.popupWindow.closed) {\n oauth.popupWindow.focus();\n broughtPopupToFront = true;\n }\n } catch (err) {\n // Bringing popup window to front failed (probably because of the cross-origin error mentioned above)\n }\n return broughtPopupToFront;\n };\n\n\n /**\n * bootstrapToken\n * The authorization code is a temporary code that a client can exchange for an access token.\n * If using this library in single-page mode, you'll need to call this once your application\n * has an `auth_code` and wants to get an access_token.\n *\n * @param {string} auth_code The OAuth2 `auth_code`\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n oauth.bootstrapToken = function(auth_code, callback) {\n var state = token('oauth2_state');\n token('oauth2_state', '');\n var params = utilStringQs(window.location.search.slice(1));\n if (params.state !== state) {\n var error = new Error('Invalid state');\n error.status = 'invalid-state';\n callback(error);\n return;\n }\n var code_verifier = token('oauth2_pkce_code_verifier');\n token('oauth2_pkce_code_verifier', '');\n _getAccessToken(auth_code, code_verifier, accessTokenDone);\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) {\n callback(err);\n return;\n }\n var access_token = JSON.parse(xhr.response);\n token('oauth2_access_token', access_token.access_token);\n callback(null, oauth);\n }\n };\n\n\n /**\n * fetch\n * A `fetch` wrapper that includes the Authorization header if the user is authenticated.\n * https://developer.mozilla.org/en-US/docs/Web/API/fetch\n *\n * @param {string} resource Resource passed to `fetch`\n * @param {Object} options Options passed to `fetch`\n * @return {Promise} Promise that wraps `authenticateAsync` then `fetch`\n */\n oauth.fetch = function(resource, options) {\n if (oauth.authenticated()) {\n return _doFetch();\n } else {\n if (o.auto) {\n return oauth.authenticateAsync().then(_doFetch);\n } else {\n return Promise.reject(new Error('not authenticated'));\n }\n }\n\n function _doFetch() {\n options = options || {};\n if (!options.headers) {\n options.headers = { 'Content-Type': 'application/x-www-form-urlencoded' };\n }\n options.headers.Authorization = 'Bearer ' + token('oauth2_access_token');\n return fetch(resource, options);\n }\n };\n\n\n /**\n * xhr\n * A `XMLHttpRequest` wrapper that does authenticated calls if the user has logged in.\n * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\n *\n * @param {Object} options\n * @param options.method Passed to `xhr.open` (e.g. 'GET', 'POST')\n * @param options.prefix If `true` path contains a path, if `false` path contains the full url\n * @param options.path The URL path (e.g. \"/api/0.6/user/details\") (or full url, if `prefix`=`false`)\n * @param options.content Passed to `xhr.send`\n * @param options.headers `Object` containing request headers\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return {XMLHttpRequest} `XMLHttpRequest` if authenticated, otherwise `null`\n */\n oauth.xhr = function (options, callback) {\n if (oauth.authenticated()) {\n return _doXHR();\n } else {\n if (o.auto) {\n oauth.authenticate(_doXHR);\n return;\n } else {\n callback('not authenticated', null);\n return;\n }\n }\n\n function _doXHR() {\n var url = options.prefix !== false ? (o.apiUrl + options.path) : options.path;\n return oauth.rawxhr(\n options.method,\n url,\n token('oauth2_access_token'),\n options.content,\n options.headers,\n done\n );\n }\n\n function done(err, xhr) {\n if (err) {\n callback(err);\n } else if (xhr.responseXML) {\n callback(err, xhr.responseXML);\n } else {\n callback(err, xhr.response);\n }\n }\n };\n\n\n /**\n * rawxhr\n * Creates the XMLHttpRequest set up with a header and response handling\n * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\n *\n * @param method Passed to `xhr.open` (e.g. 'GET', 'POST')\n * @param url Passed to `xhr.open`\n * @param access_token OAuth2 bearer token\n * @param data Passed to `xhr.send`\n * @param headers `Object` containing request headers\n * @param callback An \"errback\"-style callback (`err`, `result`), called when complete\n * @return `XMLHttpRequest`\n */\n oauth.rawxhr = function(method, url, access_token, data, headers, callback) {\n headers = headers || { 'Content-Type': 'application/x-www-form-urlencoded' };\n\n if (access_token) {\n headers.Authorization = 'Bearer ' + access_token;\n }\n\n var xhr = new XMLHttpRequest();\n\n xhr.onreadystatechange = function () {\n if (4 === xhr.readyState && 0 !== xhr.status) {\n if (/^20\\d$/.test(xhr.status)) { // a 20x status code - OK\n callback(null, xhr);\n } else {\n callback(xhr, null);\n }\n }\n };\n xhr.onerror = function (e) {\n callback(e, null);\n };\n\n xhr.open(method, url, true);\n for (var h in headers) xhr.setRequestHeader(h, headers[h]);\n\n xhr.send(data);\n return xhr;\n };\n\n\n /**\n * preauth\n * Pre-authorize this object, if we already have access token from the start\n *\n * @param {Object} val Object containing `access_token` property\n * @return `self`\n */\n oauth.preauth = function(val) {\n if (val && val.access_token) {\n token('oauth2_access_token', val.access_token);\n }\n return oauth;\n };\n\n\n /**\n * options (getter / setter)\n * If passed with no arguments, just return the options\n * If passed an Object, set the options then attempt to pre-authorize\n *\n * @param val? Object containing options\n * @return current `options` (if getting), or `self` (if setting)\n */\n oauth.options = function(val) {\n if (!arguments.length) return o;\n\n o = val;\n o.apiUrl = o.apiUrl || 'https://api.openstreetmap.org';\n o.url = o.url || 'https://www.openstreetmap.org';\n o.auto = o.auto || false;\n o.singlepage = o.singlepage || false;\n\n // Optional loading and loading-done functions for nice UI feedback.\n // by default, no-ops\n o.loading = o.loading || function () {};\n o.done = o.done || function () {};\n return oauth.preauth(o);\n };\n\n\n // Everything below here is initialization/setup code\n\n // get/set tokens. These are prefixed with the base URL so that `osm-auth`\n // can be used with multiple APIs and the keys in `localStorage`\n // will not clash\n var token;\n\n if (store.enabled) {\n token = function (x, y) {\n if (arguments.length === 1) return store.get(o.url + x);\n else if (arguments.length === 2) return store.set(o.url + x, y);\n };\n } else {\n var storage = {};\n token = function (x, y) {\n if (arguments.length === 1) return storage[o.url + x];\n else if (arguments.length === 2) return (storage[o.url + x] = y);\n };\n }\n\n // Handle options and attempt to pre-authorize\n oauth.options(o);\n\n return oauth;\n}\n\n\n/**\n * utilQsString\n * Transforms object of `key=value` pairs into query string\n * @param {Object} Object of `key=value` pairs\n * @returns {string} query string\n */\nfunction utilQsString(obj) {\n return Object.keys(obj)\n .filter(function(key) {\n return obj[key] !== undefined;\n })\n .sort()\n .map(function(key) {\n return (encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));\n })\n .join('&');\n}\n\n/**\n * utilStringQs\n * Transforms query string into object of `key=value` pairs\n * @param {string} query string\n * @returns {Object} Object of `key=value` pairs\n */\nfunction utilStringQs(str) {\n var i = 0; // advance past any leading '?' or '#' characters\n while (i < str.length && (str[i] === '?' || str[i] === '#')) i++;\n str = str.slice(i);\n\n return str.split('&').reduce(function(obj, pair) {\n var parts = pair.split('=');\n if (parts.length === 2) {\n obj[parts[0]] = decodeURIComponent(parts[1]);\n }\n return obj;\n }, {});\n}\n\n\n/**\n * supportsWebCryptoAPI\n * https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API\n * @returns {boolean} `true` if WebCryptoAPI is available\n */\nfunction supportsWebCryptoAPI() {\n return window && window.crypto\n && window.crypto.getRandomValues\n && window.crypto.subtle\n && window.crypto.subtle.digest;\n}\n\n\n/**\n * Generates a challenge/verifier pair for PKCE.\n * If the browser does not support the WebCryptoAPI, the \"plain\" method is\n * used as a fallback instead of a SHA-256 hash.\n * @param {callback} callback called with the result of the generated PKCE challenge\n */\nfunction _generatePkceChallenge(callback) {\n var code_verifier;\n if (supportsWebCryptoAPI()) {\n // generate a random code_verifier\n // https://datatracker.ietf.org/doc/html/rfc7636#section-7.1\n var random = window.crypto.getRandomValues(new Uint8Array(32));\n code_verifier = base64(random.buffer);\n var verifier = Uint8Array.from(Array.from(code_verifier).map(function(char) {\n return char.charCodeAt(0);\n }));\n\n // generate challenge for code verifier\n window.crypto.subtle.digest('SHA-256', verifier).then(function(hash) {\n var code_challenge = base64(hash);\n\n callback({\n code_challenge: code_challenge,\n code_verifier: code_verifier,\n code_challenge_method: 'S256'\n });\n });\n } else {\n // browser does not support Web Crypto API (e.g. IE11) -> fall back to \"plain\" method\n var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n code_verifier = '';\n for (var i=0; i<64; i++) {\n code_verifier += chars[Math.floor(Math.random() * chars.length)];\n }\n callback({\n code_verifier: code_verifier,\n code_challenge: code_verifier,\n code_challenge_method: 'plain',\n });\n }\n}\n\n\n/**\n * Returns a random state to be used as the \"state\" of the OAuth2 authentication\n * See https://datatracker.ietf.org/doc/html/rfc6749#section-10.12\n */\nfunction generateState() {\n var state;\n if (supportsWebCryptoAPI()) {\n var random = window.crypto.getRandomValues(new Uint8Array(32));\n state = base64(random.buffer);\n } else {\n // browser does not support Web Crypto API (e.g. IE11) -> fall back to \"plain\" method\n var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n state = '';\n for (var i=0; i<64; i++) {\n state += chars[Math.floor(Math.random() * chars.length)];\n }\n }\n return state;\n}\n\n\n/**\n * base64\n * Converts binary buffer to base64 encoded string, as used in rfc7636\n * @param {ArrayBuffer} buffer\n * @returns {string} base64 encoded\n */\nfunction base64(buffer) {\n return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)))\n .replace(/\\//g, '_')\n .replace(/\\+/g, '-')\n .replace(/[=]/g, '');\n}"], - "mappings": "4wBAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,KAAIC,EAASC,GAAY,EACrBC,GAASC,GAAY,EACrBC,GAAOC,GAAU,EACjBC,GAAU,OAAO,QAAW,YAAc,OAAS,OAEvDP,EAAO,QAAU,CAChB,OAAQC,EACR,OAAQE,GACR,KAAME,GACN,KAAMG,GACN,MAAOC,EACP,KAAMC,EACN,IAAKC,GACL,MAAOC,EACP,OAAQC,EACR,WAAYC,GACZ,SAAUC,GACV,OAAQR,EACT,EAEA,SAASL,IAAc,CACtB,OAAI,OAAO,OACH,OAAO,OAEP,SAAoBc,EAAKC,EAAQC,EAAQC,EAAK,CACpD,QAASC,EAAI,EAAGA,EAA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IAAI,SAASwB,EAAM,CAC1E,OAAOA,EAAK,WAAW,CAAC,CAC1B,CAAC,CAAC,EAGF,OAAO,OAAO,OAAO,OAAO,UAAWD,CAAQ,EAAE,KAAK,SAASE,EAAM,CACnE,IAAIC,EAAiBJ,EAAOG,CAAI,EAEhCrD,EAAS,CACP,eAAgBsD,EAChB,cAAe1B,EACf,sBAAuB,MACzB,CAAC,CACH,CAAC,CACH,KAAO,CAEL,IAAI2B,EAAQ,mEACZ3B,EAAgB,GAChB,QAASiB,EAAE,EAAGA,EAAE,GAAIA,IAClBjB,GAAiB2B,EAAM,KAAK,MAAM,KAAK,OAAO,EAAIA,EAAM,MAAM,CAAC,EAEjEvD,EAAS,CACP,cAAe4B,EACf,eAAgBA,EAChB,sBAAuB,OACzB,CAAC,CACH,CACF,CAOA,SAASX,IAAgB,CACvB,IAAID,EACJ,GAAIgC,GAAqB,EAAG,CAC1B,IAAIC,EAAS,OAAO,OAAO,gBAAgB,IAAI,WAAW,EAAE,CAAC,EAC7DjC,EAAQkC,EAAOD,EAAO,MAAM,CAC9B,KAAO,CAEL,IAAIM,EAAQ,mEACZvC,EAAQ,GACR,QAAS,EAAE,EAAG,EAAE,GAAI,IAClBA,GAASuC,EAAM,KAAK,MAAM,KAAK,OAAO,EAAIA,EAAM,MAAM,CAAC,CAE3D,CACA,OAAOvC,CACT,CASA,SAASkC,EAAOM,EAAQ,CACtB,OAAO,KAAK,OAAO,aAAa,MAAM,KAAM,IAAI,WAAWA,CAAM,CAAC,CAAC,EAChE,QAAQ,MAAO,GAAG,EAClB,QAAQ,MAAO,GAAG,EAClB,QAAQ,OAAQ,EAAE,CACvB", - "names": ["require_util", "__commonJSMin", "exports", "module", "assign", "make_assign", "create", "make_create", "trim", "make_trim", "Global", "bind", "slice", "each", "map", "pluck", "isList", "isFunction", "isObject", "obj", "props1", "props2", "etc", "i", "val", "key", "assignProps1", "assignProps2", "assignArgsList", "F", "str", "fn", "arr", "index", "res", "v", "k", "require_store_engine", "__commonJSMin", "exports", "module", "util", "slice", "pluck", "each", "bind", "create", "isList", "isFunction", "isObject", "createStore", "storeAPI", "key", "optionalDefaultValue", "data", "value", "callback", "self", "val", "namespacedKey", "namespace", "plugin", "_warn", "_console", "fn", "storages", "plugins", "namespacePrefix", "namespaceRegexp", "legalNamespaces", "_privateStoreProps", "storage", "testStr", "ok", "e", "pluginFnProp", "propName", "oldFn", "args", "super_fn", "arg", "i", "newFnArgs", "obj", "strVal", "defaultVal", "seenPlugin", "pluginProperties", "store", "prop", "require_localStorage", "__commonJSMin", "exports", "module", "util", "Global", "read", "write", "each", "remove", "clearAll", "localStorage", "key", "data", "fn", "i", "require_oldFF_globalStorage", "__commonJSMin", "exports", "module", "util", "Global", "read", "write", "each", "remove", "clearAll", "globalStorage", "key", "data", "fn", "i", "_", "require_oldIE_userDataStorage", "__commonJSMin", "exports", "module", "util", "Global", "write", "read", "each", "remove", "clearAll", "storageName", "doc", "_withStorageEl", "_makeIEStorageElFunction", "disable", "unfixedKey", "data", "fixedKey", "fixKey", "storageEl", "res", "callback", "attributes", "attr", "i", "forbiddenCharsRegex", "key", "scriptTag", "storageOwner", "storageContainer", "e", "storeFunction", "args", "require_cookieStorage", "__commonJSMin", "exports", "module", "util", "Global", "trim", "read", "write", "each", "remove", "clearAll", "doc", "key", "_has", "regexpStr", "callback", "cookies", "i", "kvp", "val", "data", "_", "require_sessionStorage", "__commonJSMin", "exports", "module", "util", "Global", "read", "write", "each", "remove", "clearAll", "sessionStorage", "key", "data", "fn", "i", "require_memoryStorage", "__commonJSMin", "exports", "module", "read", "write", "each", "remove", "clearAll", "memoryStorage", "key", "data", "callback", "require_all", "__commonJSMin", "exports", "module", "require_json2", "__commonJSMin", "n", "string", "a", "c", "key", "holder", "i", "k", "v", "length", "mind", "partial", "value", "replacer", "space", "require_json2", "__commonJSMin", "exports", "module", "json2Plugin", "require_store_legacy", "__commonJSMin", "exports", "module", "engine", "storages", "plugins", "osm_auth_exports", "__export", "osmAuth", "import_store", "o", "oauth", "token", "callback", "_preopenPopup", "error", "popup", "_generatePkceChallenge", "pkce", "_authenticate", "resolve", "reject", "errback", "err", "result", "w", "h", "settings", "x", "state", "generateState", "url", "utilQsString", "store", "params", "utilStringQs", "_getAccessToken", "accessTokenDone", "xhr", "access_token", "auth_code", "code_verifier", "broughtPopupToFront", "resource", "options", "_doFetch", "_doXHR", "done", "method", "data", "headers", "e", "val", "y", "storage", "obj", "key", "str", "i", "pair", "parts", "supportsWebCryptoAPI", "random", "base64", "verifier", "char", "hash", "code_challenge", "chars", "buffer"] + "sources": ["../src/osm-auth.mjs"], + "sourcesContent": ["\n/**\n * osmAuth\n * Easy authentication with OpenStreetMap over OAuth 2.0.\n * @module\n *\n * @param o `Object` containing options:\n * @param o.scope OAuth2 scopes requested (e.g. \"read_prefs write_api\")\n * @param o.client_id OAuth2 client ID\n * @param o.redirect_uri OAuth2 redirect URI (e.g. \"http://127.0.0.1:8080/land.html\")\n * @param o.access_token Can pre-authorize with an OAuth2 bearer token if you have one\n * @param o.apiUrl A base url for the OSM API (default: \"https://api.openstreetmap.org\")\n * @param o.url A base url for the OAuth2 handshake (default: \"https://www.openstreetmap.org\")\n * @param o.auto If `true`, attempt to authenticate automatically when calling `.xhr()` or `.fetch()` (default: `false`)\n * @param o.singlepage If `true`, use page redirection instead of a popup (default: `false`)\n * @param o.loading Function called when auth-related xhr calls start\n * @param o.done Function called when auth-related xhr calls end\n * @return `self`\n */\nexport function osmAuth(o) {\n var oauth = {};\n\n // Mock localStorage if needed.\n // Note that accessing localStorage may throw a `SecurityError`, so wrap in a try/catch.\n var _store = null;\n try {\n _store = window.localStorage;\n } catch (e) {\n var _mock = new Map();\n _store = {\n isMocked: true,\n hasItem: (k) => _mock.has(k),\n getItem: (k) => _mock.get(k),\n setItem: (k, v) => _mock.set(k, v),\n removeItem: (k) => _mock.delete(k),\n clear: () => _mock.clear()\n };\n }\n\n /**\n * token\n * Get/Set tokens. These are prefixed with the base URL so that `osm-auth`\n * can be used with multiple APIs and the keys in `localStorage` will not clash\n * @param {string} k key\n * @param {string?} v value\n * @return {string?} If getting, returns the stored value or `null`. If setting, returns `undefined`.\n */\n function token(k, v) {\n if (arguments.length === 1) return _store.getItem(o.url + k);\n else if (arguments.length === 2) return _store.setItem(o.url + k, v);\n }\n\n\n /**\n * authenticated\n * Test whether the user is currently authenticated\n *\n * @return {boolean} `true` if authenticated, `false` if not\n */\n oauth.authenticated = function() {\n return !!token('oauth2_access_token');\n };\n\n\n /**\n * logout\n * Removes any stored authentication tokens (legacy OAuth1 tokens too)\n *\n * @return `self`\n */\n oauth.logout = function () {\n token('oauth2_access_token', ''); // OAuth2\n token('oauth_token', ''); // OAuth1\n token('oauth_token_secret', ''); // OAuth1\n token('oauth_request_token_secret', ''); // OAuth1\n return oauth;\n };\n\n\n /**\n * authenticate\n * First logs out, then runs the authentiation flow, finally calls the callback.\n * TODO: detect lack of click event (probably can settimeout it)\n *\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n oauth.authenticate = function(callback) {\n if (oauth.authenticated()) {\n callback(null, oauth);\n return;\n }\n\n oauth.logout();\n\n _preopenPopup(function(error, popup) {\n if (error) {\n callback(error);\n } else {\n _generatePkceChallenge(function(pkce) {\n _authenticate(pkce, popup, callback);\n });\n }\n });\n };\n\n\n /**\n * authenticateAsync\n * Promisified version of `authenticate`\n * @return {Promise} Promise settled with whatever `_authenticate` did\n */\n oauth.authenticateAsync = function() {\n if (oauth.authenticated()) {\n return Promise.resolve(oauth);\n }\n\n oauth.logout();\n\n return new Promise((resolve, reject) => {\n var errback = (err, result) => {\n if (err) {\n reject(err);\n } else {\n resolve(result);\n }\n };\n\n _preopenPopup((error, popup) => {\n if (error) {\n errback(error);\n } else {\n _generatePkceChallenge(pkce => _authenticate(pkce, popup, errback));\n }\n });\n });\n };\n\n\n /**\n * opens an empty popup to be later used for the authentication page\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n function _preopenPopup(callback) {\n if (o.singlepage) {\n callback(null, undefined);\n return;\n }\n\n // Create a 550x610 popup window in the center of the screen\n var w = 550;\n var h = 610;\n var settings = [\n ['width', w],\n ['height', h],\n ['left', window.screen.width / 2 - w / 2],\n ['top', window.screen.height / 2 - h / 2],\n ]\n .map(function (x) { return x.join('='); })\n .join(',');\n var popup = window.open('about:blank', 'oauth_window', settings);\n if (popup) {\n callback(null, popup);\n } else {\n var error = new Error('Popup was blocked');\n error.status = 'popup-blocked';\n callback(error);\n }\n }\n\n\n /**\n * _authenticate\n * internal authenticate\n *\n * @param {Object} pkce Object containing PKCE code challenge properties\n * @param {Window} popup Popup Window to use for the authentication page, should be undefined when using singlepage mode\n * @param {function} callback Errback-style callback that accepts `(err, result)`\n */\n function _authenticate(pkce, popup, callback) {\n var state = generateState();\n\n // ## Request authorization to access resources from the user\n // and receive authorization code\n var url =\n o.url +\n '/oauth2/authorize?' +\n utilQsString({\n client_id: o.client_id,\n redirect_uri: o.redirect_uri,\n response_type: 'code',\n scope: o.scope,\n state: state,\n code_challenge: pkce.code_challenge,\n code_challenge_method: pkce.code_challenge_method,\n });\n\n if (o.singlepage) {\n if (_store.isMocked) {\n // in singlepage mode, PKCE requires working non-volatile storage\n var error = new Error('localStorage unavailable, but required in singlepage mode');\n error.status = 'pkce-localstorage-unavailable';\n callback(error);\n return;\n }\n var params = utilStringQs(window.location.search.slice(1));\n if (params.code) {\n oauth.bootstrapToken(params.code, callback);\n } else {\n // save OAuth2 state and PKCE challenge in local storage, for later use\n // in the `/oauth/token` request\n token('oauth2_state', state);\n token('oauth2_pkce_code_verifier', pkce.code_verifier);\n window.location = url;\n }\n } else {\n oauth.popupWindow = popup;\n popup.location = url;\n }\n\n // Called by a function in the redirect URL page, in the popup window. The\n // window closes itself.\n window.authComplete = function (url) {\n var params = utilStringQs(url.split('?')[1]);\n if (params.state !== state) {\n error = new Error('Invalid state');\n error.status = 'invalid-state';\n callback(error);\n return;\n }\n _getAccessToken(params.code, pkce.code_verifier, accessTokenDone);\n delete window.authComplete;\n };\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) {\n callback(err);\n return;\n }\n var access_token = JSON.parse(xhr.response);\n token('oauth2_access_token', access_token.access_token);\n callback(null, oauth);\n }\n }\n\n\n /**\n * _getAccessToken\n * The client requests an access token by authenticating with the\n * authorization server and presenting the `auth_code`, brought\n * in from a function call on a landing page popup.\n * @param {string} auth_code\n * @param {string} code_verifier\n * @param {function} accessTokenDone Errback-style callback `(err, result)`, called when complete\n */\n function _getAccessToken(auth_code, code_verifier, accessTokenDone) {\n var url =\n o.url +\n '/oauth2/token?' +\n utilQsString({\n client_id: o.client_id,\n redirect_uri: o.redirect_uri,\n grant_type: 'authorization_code',\n code: auth_code,\n code_verifier: code_verifier\n });\n\n // The authorization server authenticates the client and validates\n // the authorization grant, and if valid, issues an access token.\n oauth.rawxhr('POST', url, null, null, null, accessTokenDone);\n o.loading();\n }\n\n\n /**\n * bringPopupWindowToFront\n * Tries to bring an existing authentication popup to the front.\n *\n * @return {boolean} `true` if it succeeded, `false` if not\n */\n oauth.bringPopupWindowToFront = function() {\n var broughtPopupToFront = false;\n try {\n // This may cause a cross-origin error:\n // `DOMException: Blocked a frame with origin \"...\" from accessing a cross-origin frame.`\n if (oauth.popupWindow && !oauth.popupWindow.closed) {\n oauth.popupWindow.focus();\n broughtPopupToFront = true;\n }\n } catch (err) {\n // Bringing popup window to front failed (probably because of the cross-origin error mentioned above)\n }\n return broughtPopupToFront;\n };\n\n\n /**\n * bootstrapToken\n * The authorization code is a temporary code that a client can exchange for an access token.\n * If using this library in single-page mode, you'll need to call this once your application\n * has an `auth_code` and wants to get an access_token.\n *\n * @param {string} auth_code The OAuth2 `auth_code`\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return none\n */\n oauth.bootstrapToken = function(auth_code, callback) {\n var state = token('oauth2_state');\n token('oauth2_state', '');\n var params = utilStringQs(window.location.search.slice(1));\n if (params.state !== state) {\n var error = new Error('Invalid state');\n error.status = 'invalid-state';\n callback(error);\n return;\n }\n var code_verifier = token('oauth2_pkce_code_verifier');\n token('oauth2_pkce_code_verifier', '');\n _getAccessToken(auth_code, code_verifier, accessTokenDone);\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) {\n callback(err);\n return;\n }\n var access_token = JSON.parse(xhr.response);\n token('oauth2_access_token', access_token.access_token);\n callback(null, oauth);\n }\n };\n\n\n /**\n * fetch\n * A `fetch` wrapper that includes the Authorization header if the user is authenticated.\n * https://developer.mozilla.org/en-US/docs/Web/API/fetch\n *\n * @param {string} resource Resource passed to `fetch`\n * @param {Object} options Options passed to `fetch`\n * @return {Promise} Promise that wraps `authenticateAsync` then `fetch`\n */\n oauth.fetch = function(resource, options) {\n if (oauth.authenticated()) {\n return _doFetch();\n } else {\n if (o.auto) {\n return oauth.authenticateAsync().then(_doFetch);\n } else {\n return Promise.reject(new Error('not authenticated'));\n }\n }\n\n function _doFetch() {\n options = options || {};\n if (!options.headers) {\n options.headers = { 'Content-Type': 'application/x-www-form-urlencoded' };\n }\n options.headers.Authorization = 'Bearer ' + token('oauth2_access_token');\n return fetch(resource, options);\n }\n };\n\n\n /**\n * xhr\n * A `XMLHttpRequest` wrapper that does authenticated calls if the user has logged in.\n * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\n *\n * @param {Object} options\n * @param options.method Passed to `xhr.open` (e.g. 'GET', 'POST')\n * @param options.prefix If `true` path contains a path, if `false` path contains the full url\n * @param options.path The URL path (e.g. \"/api/0.6/user/details\") (or full url, if `prefix`=`false`)\n * @param options.content Passed to `xhr.send`\n * @param options.headers `Object` containing request headers\n * @param {function} callback Errback-style callback `(err, result)`, called when complete\n * @return {XMLHttpRequest} `XMLHttpRequest` if authenticated, otherwise `null`\n */\n oauth.xhr = function (options, callback) {\n if (oauth.authenticated()) {\n return _doXHR();\n } else {\n if (o.auto) {\n oauth.authenticate(_doXHR);\n return;\n } else {\n callback('not authenticated', null);\n return;\n }\n }\n\n function _doXHR() {\n var url = options.prefix !== false ? (o.apiUrl + options.path) : options.path;\n return oauth.rawxhr(\n options.method,\n url,\n token('oauth2_access_token'),\n options.content,\n options.headers,\n done\n );\n }\n\n function done(err, xhr) {\n if (err) {\n callback(err);\n } else if (xhr.responseXML) {\n callback(err, xhr.responseXML);\n } else {\n callback(err, xhr.response);\n }\n }\n };\n\n\n /**\n * rawxhr\n * Creates the XMLHttpRequest set up with a header and response handling\n * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\n *\n * @param method Passed to `xhr.open` (e.g. 'GET', 'POST')\n * @param url Passed to `xhr.open`\n * @param access_token OAuth2 bearer token\n * @param data Passed to `xhr.send`\n * @param headers `Object` containing request headers\n * @param callback An \"errback\"-style callback (`err`, `result`), called when complete\n * @return `XMLHttpRequest`\n */\n oauth.rawxhr = function(method, url, access_token, data, headers, callback) {\n headers = headers || { 'Content-Type': 'application/x-www-form-urlencoded' };\n\n if (access_token) {\n headers.Authorization = 'Bearer ' + access_token;\n }\n\n var xhr = new XMLHttpRequest();\n\n xhr.onreadystatechange = function () {\n if (4 === xhr.readyState && 0 !== xhr.status) {\n if (/^20\\d$/.test(xhr.status)) { // a 20x status code - OK\n callback(null, xhr);\n } else {\n callback(xhr, null);\n }\n }\n };\n xhr.onerror = function (e) {\n callback(e, null);\n };\n\n xhr.open(method, url, true);\n for (var h in headers) xhr.setRequestHeader(h, headers[h]);\n\n xhr.send(data);\n return xhr;\n };\n\n\n /**\n * preauth\n * Pre-authorize this object, if we already have access token from the start\n *\n * @param {Object} val Object containing `access_token` property\n * @return `self`\n */\n oauth.preauth = function(val) {\n if (val && val.access_token) {\n token('oauth2_access_token', val.access_token);\n }\n return oauth;\n };\n\n\n /**\n * options (getter / setter)\n * If passed with no arguments, just return the options\n * If passed an Object, set the options then attempt to pre-authorize\n *\n * @param val? Object containing options\n * @return current `options` (if getting), or `self` (if setting)\n */\n oauth.options = function(val) {\n if (!arguments.length) return o;\n\n o = val;\n o.apiUrl = o.apiUrl || 'https://api.openstreetmap.org';\n o.url = o.url || 'https://www.openstreetmap.org';\n o.auto = o.auto || false;\n o.singlepage = o.singlepage || false;\n\n // Optional loading and loading-done functions for nice UI feedback.\n // by default, no-ops\n o.loading = o.loading || function () {};\n o.done = o.done || function () {};\n return oauth.preauth(o);\n };\n\n\n // Everything below here is initialization/setup code\n // Handle options and attempt to pre-authorize\n oauth.options(o);\n\n return oauth;\n}\n\n\n/**\n * utilQsString\n * Transforms object of `key=value` pairs into query string\n * @param {Object} Object of `key=value` pairs\n * @returns {string} query string\n */\nfunction utilQsString(obj) {\n return Object.keys(obj)\n .filter(function(key) {\n return obj[key] !== undefined;\n })\n .sort()\n .map(function(key) {\n return (encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));\n })\n .join('&');\n}\n\n/**\n * utilStringQs\n * Transforms query string into object of `key=value` pairs\n * @param {string} query string\n * @returns {Object} Object of `key=value` pairs\n */\nfunction utilStringQs(str) {\n var i = 0; // advance past any leading '?' or '#' characters\n while (i < str.length && (str[i] === '?' || str[i] === '#')) i++;\n str = str.slice(i);\n\n return str.split('&').reduce(function(obj, pair) {\n var parts = pair.split('=');\n if (parts.length === 2) {\n obj[parts[0]] = decodeURIComponent(parts[1]);\n }\n return obj;\n }, {});\n}\n\n\n/**\n * supportsWebCryptoAPI\n * https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API\n * @returns {boolean} `true` if WebCryptoAPI is available\n */\nfunction supportsWebCryptoAPI() {\n return window && window.crypto\n && window.crypto.getRandomValues\n && window.crypto.subtle\n && window.crypto.subtle.digest;\n}\n\n\n/**\n * Generates a challenge/verifier pair for PKCE.\n * If the browser does not support the WebCryptoAPI, the \"plain\" method is\n * used as a fallback instead of a SHA-256 hash.\n * @param {callback} callback called with the result of the generated PKCE challenge\n */\nfunction _generatePkceChallenge(callback) {\n var code_verifier;\n if (supportsWebCryptoAPI()) {\n // generate a random code_verifier\n // https://datatracker.ietf.org/doc/html/rfc7636#section-7.1\n var random = window.crypto.getRandomValues(new Uint8Array(32));\n code_verifier = base64(random.buffer);\n var verifier = Uint8Array.from(Array.from(code_verifier).map(function(char) {\n return char.charCodeAt(0);\n }));\n\n // generate challenge for code verifier\n window.crypto.subtle.digest('SHA-256', verifier).then(function(hash) {\n var code_challenge = base64(hash);\n\n callback({\n code_challenge: code_challenge,\n code_verifier: code_verifier,\n code_challenge_method: 'S256'\n });\n });\n } else {\n // browser does not support Web Crypto API (e.g. IE11) -> fall back to \"plain\" method\n var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n code_verifier = '';\n for (var i=0; i<64; i++) {\n code_verifier += chars[Math.floor(Math.random() * chars.length)];\n }\n callback({\n code_verifier: code_verifier,\n code_challenge: code_verifier,\n code_challenge_method: 'plain',\n });\n }\n}\n\n\n/**\n * Returns a random state to be used as the \"state\" of the OAuth2 authentication\n * See https://datatracker.ietf.org/doc/html/rfc6749#section-10.12\n */\nfunction generateState() {\n var state;\n if (supportsWebCryptoAPI()) {\n var random = window.crypto.getRandomValues(new Uint8Array(32));\n state = base64(random.buffer);\n } else {\n // browser does not support Web Crypto API (e.g. IE11) -> fall back to \"plain\" method\n var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n state = '';\n for (var i=0; i<64; i++) {\n state += chars[Math.floor(Math.random() * chars.length)];\n }\n }\n return state;\n}\n\n\n/**\n * base64\n * Converts binary buffer to base64 encoded string, as used in rfc7636\n * @param {ArrayBuffer} buffer\n * @returns {string} base64 encoded\n */\nfunction base64(buffer) {\n return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)))\n .replace(/\\//g, '_')\n .replace(/\\+/g, '-')\n .replace(/[=]/g, '');\n}\n"], + "mappings": "2gBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,KAmBO,SAASA,EAAQC,EAAG,CACzB,IAAIC,EAAQ,CAAC,EAITC,EAAS,KACb,GAAI,C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BJ,EAAOG,CAAI,EAEhCjD,EAAS,CACP,eAAgBkD,EAChB,cAAevB,EACf,sBAAuB,MACzB,CAAC,CACH,CAAC,CACH,KAAO,CAEL,IAAIwB,EAAQ,mEACZxB,EAAgB,GAChB,QAASc,EAAE,EAAGA,EAAE,GAAIA,IAClBd,GAAiBwB,EAAM,KAAK,MAAM,KAAK,OAAO,EAAIA,EAAM,MAAM,CAAC,EAEjEnD,EAAS,CACP,cAAe2B,EACf,eAAgBA,EAChB,sBAAuB,OACzB,CAAC,CACH,CACF,CAOA,SAASV,GAAgB,CACvB,IAAID,EACJ,GAAI4B,EAAqB,EAAG,CAC1B,IAAIC,EAAS,OAAO,OAAO,gBAAgB,IAAI,WAAW,EAAE,CAAC,EAC7D7B,EAAQ8B,EAAOD,EAAO,MAAM,CAC9B,KAAO,CAEL,IAAIM,EAAQ,mEACZnC,EAAQ,GACR,QAASyB,EAAE,EAAGA,EAAE,GAAIA,IAClBzB,GAASmC,EAAM,KAAK,MAAM,KAAK,OAAO,EAAIA,EAAM,MAAM,CAAC,CAE3D,CACA,OAAOnC,CACT,CASA,SAAS8B,EAAOM,EAAQ,CACtB,OAAO,KAAK,OAAO,aAAa,MAAM,KAAM,IAAI,WAAWA,CAAM,CAAC,CAAC,EAChE,QAAQ,MAAO,GAAG,EAClB,QAAQ,MAAO,GAAG,EAClB,QAAQ,OAAQ,EAAE,CACvB", + "names": ["osm_auth_exports", "__export", "osmAuth", "o", "oauth", "_store", "e", "_mock", "k", "v", "token", "callback", "_preopenPopup", "error", "popup", "_generatePkceChallenge", "pkce", "_authenticate", "resolve", "reject", "errback", "err", "result", "w", "h", "settings", "x", "state", "generateState", "url", "utilQsString", "params", "utilStringQs", "_getAccessToken", "accessTokenDone", "xhr", "access_token", "auth_code", "code_verifier", "broughtPopupToFront", "resource", "options", "_doFetch", "_doXHR", "done", "method", "data", "headers", "val", "obj", "key", "str", "i", "pair", "parts", "supportsWebCryptoAPI", "random", "base64", "verifier", "char", "hash", "code_challenge", "chars", "buffer"] } diff --git a/package.json b/package.json index d0cf8d3..7e02dc3 100644 --- a/package.json +++ b/package.json @@ -35,9 +35,6 @@ "test": "run-s build test:node", "test:node": "c8 node --test test/" }, - "dependencies": { - "store": "~2.0.12" - }, "devDependencies": { "c8": "^9.0.0", "esbuild": "^0.19.11", diff --git a/src/osm-auth.mjs b/src/osm-auth.mjs index 877a52e..8f391d9 100644 --- a/src/osm-auth.mjs +++ b/src/osm-auth.mjs @@ -1,5 +1,3 @@ -import store from 'store'; - /** * osmAuth @@ -22,6 +20,37 @@ import store from 'store'; export function osmAuth(o) { var oauth = {}; + // Mock localStorage if needed. + // Note that accessing localStorage may throw a `SecurityError`, so wrap in a try/catch. + var _store = null; + try { + _store = window.localStorage; + } catch (e) { + var _mock = new Map(); + _store = { + isMocked: true, + hasItem: (k) => _mock.has(k), + getItem: (k) => _mock.get(k), + setItem: (k, v) => _mock.set(k, v), + removeItem: (k) => _mock.delete(k), + clear: () => _mock.clear() + }; + } + + /** + * token + * Get/Set tokens. These are prefixed with the base URL so that `osm-auth` + * can be used with multiple APIs and the keys in `localStorage` will not clash + * @param {string} k key + * @param {string?} v value + * @return {string?} If getting, returns the stored value or `null`. If setting, returns `undefined`. + */ + function token(k, v) { + if (arguments.length === 1) return _store.getItem(o.url + k); + else if (arguments.length === 2) return _store.setItem(o.url + k, v); + } + + /** * authenticated * Test whether the user is currently authenticated @@ -168,9 +197,9 @@ export function osmAuth(o) { }); if (o.singlepage) { - if (!store.enabled) { + if (_store.isMocked) { // in singlepage mode, PKCE requires working non-volatile storage - var error = new Error('local storage unavailable, but require in singlepage mode'); + var error = new Error('localStorage unavailable, but required in singlepage mode'); error.status = 'pkce-localstorage-unavailable'; callback(error); return; @@ -470,25 +499,6 @@ export function osmAuth(o) { // Everything below here is initialization/setup code - - // get/set tokens. These are prefixed with the base URL so that `osm-auth` - // can be used with multiple APIs and the keys in `localStorage` - // will not clash - var token; - - if (store.enabled) { - token = function (x, y) { - if (arguments.length === 1) return store.get(o.url + x); - else if (arguments.length === 2) return store.set(o.url + x, y); - }; - } else { - var storage = {}; - token = function (x, y) { - if (arguments.length === 1) return storage[o.url + x]; - else if (arguments.length === 2) return (storage[o.url + x] = y); - }; - } - // Handle options and attempt to pre-authorize oauth.options(o); @@ -623,4 +633,4 @@ function base64(buffer) { .replace(/\//g, '_') .replace(/\+/g, '-') .replace(/[=]/g, ''); -} \ No newline at end of file +}