From 95003f816bf4eee2e8245663a840a6fe47ee06ad Mon Sep 17 00:00:00 2001 From: Mathias Biilmann Christensen Date: Sat, 2 Sep 2017 18:01:04 -0700 Subject: Add identity script --- gulpfile.babel.js | 11 +- site/layouts/partials/head.html | 1 + site/static/admin/netlify-identity-umd.js | 3389 +++++++++++++++++++++++++++++ 3 files changed, 3398 insertions(+), 3 deletions(-) create mode 100644 site/static/admin/netlify-identity-umd.js diff --git a/gulpfile.babel.js b/gulpfile.babel.js index a50a03c..d1420f2 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -19,8 +19,8 @@ const defaultArgs = ["-d", "../dist", "-s", "site"]; gulp.task("hugo", (cb) => buildSite(cb)); gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"])); -gulp.task("build", ["css", "js", "hugo"]); -gulp.task("build-preview", ["css", "js", "hugo-preview"]); +gulp.task("build", ["css", "js", "cms-assets", "hugo"]); +gulp.task("build-preview", ["css", "js", "cms-assets", "hugo-preview"]); gulp.task("css", () => ( gulp.src("./src/css/*.css") @@ -33,6 +33,11 @@ gulp.task("css", () => ( .pipe(browserSync.stream()) )); +gulp.task("cms-assets", () => ( + gulp.src("./node_modules/netlify-cms/dist/*.{woff,eot,woff2,ttf,svg,png}") + .pipe(gulp.dest("./dist/css")) +)) + gulp.task("js", (cb) => { const myConfig = Object.assign({}, webpackConfig); @@ -63,7 +68,7 @@ gulp.task("svg", () => { .pipe(gulp.dest("site/layouts/partials/")); }); -gulp.task("server", ["hugo", "css", "js", "svg"], () => { +gulp.task("server", ["hugo", "css", "cms-assets", "js", "svg"], () => { browserSync.init({ server: { baseDir: "./dist" diff --git a/site/layouts/partials/head.html b/site/layouts/partials/head.html index 8768260..83b3907 100644 --- a/site/layouts/partials/head.html +++ b/site/layouts/partials/head.html @@ -25,6 +25,7 @@ + diff --git a/site/static/admin/netlify-identity-umd.js b/site/static/admin/netlify-identity-umd.js new file mode 100644 index 0000000..1378abe --- /dev/null +++ b/site/static/admin/netlify-identity-umd.js @@ -0,0 +1,3389 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.netlifyIdentity = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { + str = CHARS[integer % 62] + str; + integer = Math.floor(integer / 62); + } + return str; +}; +},{}],17:[function(require,module,exports){ +'use strict'; +var makeComposition = require('./composition').makeComposition; +module.exports = function createExports(classes, keyframes, compositions) { + var keyframesObj = Object.keys(keyframes).reduce(function (acc, key) { + var val = keyframes[key]; + acc[val] = makeComposition([key], [val], true); + return acc; + }, {}); + var exports = Object.keys(classes).reduce(function (acc, key) { + var val = classes[key]; + var composition = compositions[key]; + var extended = composition ? getClassChain(composition) : []; + var allClasses = [key].concat(extended); + var unscoped = allClasses.map(function (name) { + return classes[name] ? classes[name] : name; + }); + acc[val] = makeComposition(allClasses, unscoped); + return acc; + }, keyframesObj); + return exports; +}; +function getClassChain(obj) { + var visited = {}, acc = []; + function traverse(obj) { + return Object.keys(obj).forEach(function (key) { + if (!visited[key]) { + visited[key] = true; + acc.push(key); + traverse(obj[key]); + } + }); + } + traverse(obj); + return acc; +} +},{"./composition":18}],18:[function(require,module,exports){ +'use strict'; +module.exports = { + makeComposition: makeComposition, + isComposition: isComposition, + ignoreComposition: ignoreComposition +}; +function makeComposition(classNames, unscoped, isAnimation) { + var classString = classNames.join(' '); + return Object.create(Composition.prototype, { + classNames: { + value: Object.freeze(classNames), + configurable: false, + writable: false, + enumerable: true + }, + unscoped: { + value: Object.freeze(unscoped), + configurable: false, + writable: false, + enumerable: true + }, + className: { + value: classString, + configurable: false, + writable: false, + enumerable: true + }, + selector: { + value: classNames.map(function (name) { + return isAnimation ? name : '.' + name; + }).join(', '), + configurable: false, + writable: false, + enumerable: true + }, + toString: { + value: function () { + return classString; + }, + configurable: false, + writeable: false, + enumerable: false + } + }); +} +function isComposition(value) { + return value instanceof Composition; +} +function ignoreComposition(values) { + return values.reduce(function (acc, val) { + if (isComposition(val)) { + val.classNames.forEach(function (name, i) { + acc[name] = val.unscoped[i]; + }); + } + return acc; + }, {}); +} +function Composition() { +} +},{}],19:[function(require,module,exports){ +'use strict'; +var extractExtends = require('./css-extract-extends'); +var composition = require('./composition'); +var isComposition = composition.isComposition; +var ignoreComposition = composition.ignoreComposition; +var buildExports = require('./build-exports'); +var scopify = require('./scopeify'); +var cssKey = require('./css-key'); +var extractExports = require('./extract-exports'); +module.exports = function csjsTemplate(opts) { + opts = typeof opts === 'undefined' ? {} : opts; + var noscope = typeof opts.noscope === 'undefined' ? false : opts.noscope; + return function csjsHandler(strings, values) { + var values = Array(arguments.length - 1); + for (var i = 1; i < arguments.length; i++) { + values[i - 1] = arguments[i]; + } + var css = joiner(strings, values.map(selectorize)); + var ignores = ignoreComposition(values); + var scope = noscope ? extractExports(css) : scopify(css, ignores); + var extracted = extractExtends(scope.css); + var localClasses = without(scope.classes, ignores); + var localKeyframes = without(scope.keyframes, ignores); + var compositions = extracted.compositions; + var exports = buildExports(localClasses, localKeyframes, compositions); + return Object.defineProperty(exports, cssKey, { + enumerable: false, + configurable: false, + writeable: false, + value: extracted.css + }); + }; +}; +function selectorize(value) { + return isComposition(value) ? value.selector : value; +} +function joiner(strings, values) { + return strings.map(function (str, i) { + return i !== values.length ? str + values[i] : str; + }).join(''); +} +function without(obj, unwanted) { + return Object.keys(obj).reduce(function (acc, key) { + if (!unwanted[key]) { + acc[key] = obj[key]; + } + return acc; + }, {}); +} +},{"./build-exports":17,"./composition":18,"./css-extract-extends":20,"./css-key":21,"./extract-exports":22,"./scopeify":28}],20:[function(require,module,exports){ +'use strict'; +var makeComposition = require('./composition').makeComposition; +var regex = /\.([^\s]+)(\s+)(extends\s+)(\.[^{]+)/g; +module.exports = function extractExtends(css) { + var found, matches = []; + while (found = regex.exec(css)) { + matches.unshift(found); + } + function extractCompositions(acc, match) { + var extendee = getClassName(match[1]); + var keyword = match[3]; + var extended = match[4]; + var index = match.index + match[1].length + match[2].length; + var len = keyword.length + extended.length; + acc.css = acc.css.slice(0, index) + ' ' + acc.css.slice(index + len + 1); + var extendedClasses = splitter(extended); + extendedClasses.forEach(function (className) { + if (!acc.compositions[extendee]) { + acc.compositions[extendee] = {}; + } + if (!acc.compositions[className]) { + acc.compositions[className] = {}; + } + acc.compositions[extendee][className] = acc.compositions[className]; + }); + return acc; + } + return matches.reduce(extractCompositions, { + css: css, + compositions: {} + }); +}; +function splitter(match) { + return match.split(',').map(getClassName); +} +function getClassName(str) { + var trimmed = str.trim(); + return trimmed[0] === '.' ? trimmed.substr(1) : trimmed; +} +},{"./composition":18}],21:[function(require,module,exports){ +'use strict'; +module.exports = ' css '; +},{}],22:[function(require,module,exports){ +'use strict'; +var regex = require('./regex'); +var classRegex = regex.classRegex; +var keyframesRegex = regex.keyframesRegex; +module.exports = extractExports; +function extractExports(css) { + return { + css: css, + keyframes: getExport(css, keyframesRegex), + classes: getExport(css, classRegex) + }; +} +function getExport(css, regex) { + var prop = {}; + var match; + while ((match = regex.exec(css)) !== null) { + var name = match[2]; + prop[name] = name; + } + return prop; +} +},{"./regex":25}],23:[function(require,module,exports){ +'use strict'; +var cssKey = require('./css-key'); +module.exports = function getCss(csjs) { + return csjs[cssKey]; +}; +},{"./css-key":21}],24:[function(require,module,exports){ +'use strict'; +module.exports = function hashStr(str) { + var hash = 5381; + var i = str.length; + while (i) { + hash = hash * 33 ^ str.charCodeAt(--i); + } + return hash >>> 0; +}; +},{}],25:[function(require,module,exports){ +'use strict'; +var findClasses = /(\.)(?!\d)([^\s\.,{\[>+~#:)]*)(?![^{]*})/.source; +var findKeyframes = /(@\S*keyframes\s*)([^{\s]*)/.source; +var ignoreComments = /(?!(?:[^*\/]|\*[^\/]|\/[^*])*\*+\/)/.source; +var classRegex = new RegExp(findClasses + ignoreComments, 'g'); +var keyframesRegex = new RegExp(findKeyframes + ignoreComments, 'g'); +module.exports = { + classRegex: classRegex, + keyframesRegex: keyframesRegex, + ignoreComments: ignoreComments +}; +},{}],26:[function(require,module,exports){ +var ignoreComments = require('./regex').ignoreComments; +module.exports = replaceAnimations; +function replaceAnimations(result) { + var animations = Object.keys(result.keyframes).reduce(function (acc, key) { + acc[result.keyframes[key]] = key; + return acc; + }, {}); + var unscoped = Object.keys(animations); + if (unscoped.length) { + var regexStr = '((?:animation|animation-name)\\s*:[^};]*)(' + unscoped.join('|') + ')([;\\s])' + ignoreComments; + var regex = new RegExp(regexStr, 'g'); + var replaced = result.css.replace(regex, function (match, preamble, name, ending) { + return preamble + animations[name] + ending; + }); + return { + css: replaced, + keyframes: result.keyframes, + classes: result.classes + }; + } + return result; +} +},{"./regex":25}],27:[function(require,module,exports){ +'use strict'; +var encode = require('./base62-encode'); +var hash = require('./hash-string'); +module.exports = function fileScoper(fileSrc) { + var suffix = encode(hash(fileSrc)); + return function scopedName(name) { + return name + '_' + suffix; + }; +}; +},{"./base62-encode":16,"./hash-string":24}],28:[function(require,module,exports){ +'use strict'; +var fileScoper = require('./scoped-name'); +var replaceAnimations = require('./replace-animations'); +var regex = require('./regex'); +var classRegex = regex.classRegex; +var keyframesRegex = regex.keyframesRegex; +module.exports = scopify; +function scopify(css, ignores) { + var makeScopedName = fileScoper(css); + var replacers = { + classes: classRegex, + keyframes: keyframesRegex + }; + function scopeCss(result, key) { + var replacer = replacers[key]; + function replaceFn(fullMatch, prefix, name) { + var scopedName = ignores[name] ? name : makeScopedName(name); + result[key][scopedName] = name; + return prefix + scopedName; + } + return { + css: result.css.replace(replacer, replaceFn), + keyframes: result.keyframes, + classes: result.classes + }; + } + var result = Object.keys(replacers).reduce(scopeCss, { + css: css, + keyframes: {}, + classes: {} + }); + return replaceAnimations(result); +} +},{"./regex":25,"./replace-animations":26,"./scoped-name":27}],29:[function(require,module,exports){ +'use strict'; +var token = '%[a-f0-9]{2}'; +var singleMatcher = new RegExp(token, 'gi'); +var multiMatcher = new RegExp('(' + token + ')+', 'gi'); +function decodeComponents(components, split) { + try { + return decodeURIComponent(components.join('')); + } catch (err) { + } + if (components.length === 1) { + return components; + } + split = split || 1; + var left = components.slice(0, split); + var right = components.slice(split); + return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right)); +} +function decode(input) { + try { + return decodeURIComponent(input); + } catch (err) { + var tokens = input.match(singleMatcher); + for (var i = 1; i < tokens.length; i++) { + input = decodeComponents(tokens, i).join(''); + tokens = input.match(singleMatcher); + } + return input; + } +} +function customDecodeURIComponent(input) { + var replaceMap = { + '%FE%FF': '\uFFFD\uFFFD', + '%FF%FE': '\uFFFD\uFFFD' + }; + var match = multiMatcher.exec(input); + while (match) { + try { + replaceMap[match[0]] = decodeURIComponent(match[0]); + } catch (err) { + var result = decode(match[0]); + if (result !== match[0]) { + replaceMap[match[0]] = result; + } + } + match = multiMatcher.exec(input); + } + replaceMap['%C2'] = '\uFFFD'; + var entries = Object.keys(replaceMap); + for (var i = 0; i < entries.length; i++) { + var key = entries[i]; + input = input.replace(new RegExp(key, 'g'), replaceMap[key]); + } + return input; +} +module.exports = function (encodedURI) { + if (typeof encodedURI !== 'string') { + throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`'); + } + try { + encodedURI = encodedURI.replace(/\+/g, ' '); + return decodeURIComponent(encodedURI); + } catch (err) { + return customDecodeURIComponent(encodedURI); + } +}; +},{}],30:[function(require,module,exports){ +(function (global){ +var topLevel = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {}; +var minDoc = require('min-document'); +var doccy; +if (typeof document !== 'undefined') { + doccy = document; +} else { + doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4']; + if (!doccy) { + doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc; + } +} +module.exports = doccy; +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"min-document":7}],31:[function(require,module,exports){ +(function (global){ +var win; +if (typeof window !== 'undefined') { + win = window; +} else if (typeof global !== 'undefined') { + win = global; +} else if (typeof self !== 'undefined') { + win = self; +} else { + win = {}; +} +module.exports = win; +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],32:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ('value' in descriptor) + descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + return function (Constructor, protoProps, staticProps) { + if (protoProps) + defineProperties(Constructor.prototype, protoProps); + if (staticProps) + defineProperties(Constructor, staticProps); + return Constructor; + }; +}(); +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError('Cannot call a class as a function'); + } +} +var Admin = function () { + function Admin(user) { + _classCallCheck(this, Admin); + this.user = user; + } + _createClass(Admin, [ + { + key: 'listUsers', + value: function listUsers(aud) { + return this.user._request('/admin/users', { + method: 'GET', + audience: aud + }); + } + }, + { + key: 'getUser', + value: function getUser(user) { + return this.user._request('/admin/users/' + user.id); + } + }, + { + key: 'updateUser', + value: function updateUser(user) { + var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return this.user._request('/admin/users/' + user.id, { + method: 'PUT', + body: JSON.stringify(attributes) + }); + } + }, + { + key: 'createUser', + value: function createUser(email, password) { + var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + attributes.email = email; + attributes.password = password; + return this.user._request('/admin/users', { + method: 'POST', + body: JSON.stringify(attributes) + }); + } + }, + { + key: 'deleteUser', + value: function deleteUser(user) { + return this.user._request('/admin/users/' + user.id, { method: 'DELETE' }); + } + } + ]); + return Admin; +}(); +exports.default = Admin; +},{}],33:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ('value' in descriptor) + descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + return function (Constructor, protoProps, staticProps) { + if (protoProps) + defineProperties(Constructor.prototype, protoProps); + if (staticProps) + defineProperties(Constructor, staticProps); + return Constructor; + }; +}(); +var _microApiClient = require('micro-api-client'); +var _microApiClient2 = _interopRequireDefault(_microApiClient); +var _user = require('./user'); +var _user2 = _interopRequireDefault(_user); +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError('Cannot call a class as a function'); + } +} +var HTTPRegexp = /^http:\/\//; +var defaultApiURL = 'https://' + window.location.hostname + '/.netlify/identity'; +var GoTrue = function () { + function GoTrue() { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$APIUrl = _ref.APIUrl, APIUrl = _ref$APIUrl === undefined ? defaultApiURL : _ref$APIUrl, _ref$audience = _ref.audience, audience = _ref$audience === undefined ? '' : _ref$audience; + _classCallCheck(this, GoTrue); + if (APIUrl.match(HTTPRegexp)) { + console.warn('Warning:\n\nDO NOT USE HTTP IN PRODUCTION FOR GOTRUE EVER!\nGoTrue REQUIRES HTTPS to work securely.'); + } + if (audience) { + this.audience = audience; + } + this.api = new _microApiClient2.default(APIUrl); + } + _createClass(GoTrue, [ + { + key: '_request', + value: function _request(path) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + options.headers = options.headers || {}; + var aud = options.audience || this.audience; + if (aud) { + options.headers['X-JWT-AUD'] = aud; + } + return this.api.request(path, options); + } + }, + { + key: 'signup', + value: function signup(email, password, data) { + return this._request('/signup', { + method: 'POST', + body: JSON.stringify({ + email: email, + password: password, + data: data + }) + }); + } + }, + { + key: 'login', + value: function login(email, password, remember) { + var _this = this; + return this._request('/token', { + method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: 'grant_type=password&username=' + encodeURIComponent(email) + '&password=' + encodeURIComponent(password) + }).then(function (response) { + _user2.default.removeSavedSession(); + return _this.createUser(response, remember); + }); + } + }, + { + key: 'loginExternalUrl', + value: function loginExternalUrl(provider) { + return this.api.apiURL + '/authorize?provider=' + provider; + } + }, + { + key: 'confirm', + value: function confirm(token) { + return this.verify('signup', token); + } + }, + { + key: 'requestPasswordRecovery', + value: function requestPasswordRecovery(email) { + return this._request('/recover', { + method: 'POST', + body: JSON.stringify({ email: email }) + }); + } + }, + { + key: 'recover', + value: function recover(token) { + return this.verify('recovery', token); + } + }, + { + key: 'acceptInvite', + value: function acceptInvite(token, password) { + var _this2 = this; + return this._request('/verify', { + method: 'POST', + body: JSON.stringify({ + token: token, + password: password, + type: 'signup' + }) + }).then(function (response) { + return _this2.createUser(response); + }); + } + }, + { + key: 'createUser', + value: function createUser(tokenResponse) { + var remember = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var user = new _user2.default(this.api, tokenResponse, this.audience); + return user.getUserData().then(function (user) { + if (remember) { + user._saveSession(); + } + return user; + }); + } + }, + { + key: 'currentUser', + value: function currentUser() { + return _user2.default.recoverSession(); + } + }, + { + key: 'verify', + value: function verify(type, token) { + var _this3 = this; + return this._request('/verify', { + method: 'POST', + body: JSON.stringify({ + token: token, + type: type + }) + }).then(function (response) { + return _this3.createUser(response); + }); + } + } + ]); + return GoTrue; +}(); +exports.default = GoTrue; +if (typeof window !== 'undefined') { + window.GoTrue = GoTrue; +} +},{"./user":34,"micro-api-client":36}],34:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +var _extends = Object.assign || function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; +}; +var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ('value' in descriptor) + descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + return function (Constructor, protoProps, staticProps) { + if (protoProps) + defineProperties(Constructor.prototype, protoProps); + if (staticProps) + defineProperties(Constructor, staticProps); + return Constructor; + }; +}(); +var _microApiClient = require('micro-api-client'); +var _microApiClient2 = _interopRequireDefault(_microApiClient); +var _admin = require('./admin'); +var _admin2 = _interopRequireDefault(_admin); +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError('Cannot call a class as a function'); + } +} +var ExpiryMargin = 60 * 1000; +var storageKey = 'gotrue.user'; +var currentUser = null; +var forbiddenUpdateAttributes = { + api: 1, + token: 1, + audience: 1, + url: 1 +}; +var forbiddenSaveAttributes = { api: 1 }; +var User = function () { + function User(api, tokenResponse, audience) { + _classCallCheck(this, User); + this.api = api; + this.url = api.apiURL; + this.audience = audience; + this._processTokenResponse(tokenResponse); + currentUser = this; + } + _createClass(User, [ + { + key: 'update', + value: function update(attributes) { + var _this = this; + return this._request('/user', { + method: 'PUT', + body: JSON.stringify(attributes) + }).then(function (response) { + return _this._saveUserData(response)._refreshSavedSession(); + }); + } + }, + { + key: 'jwt', + value: function jwt() { + var _this2 = this; + var _tokenDetails = this.tokenDetails(), expires_at = _tokenDetails.expires_at, refresh_token = _tokenDetails.refresh_token, access_token = _tokenDetails.access_token; + if (expires_at - ExpiryMargin < Date.now()) { + return this.api._request('/token', { + method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: 'grant_type=refresh_token&refresh_token=' + refresh_token + }).then(function (response) { + _this2._processTokenResponse(response); + _this2._refreshSavedSession(); + return _this2.token.access_token; + }).catch(function (error) { + _this2.clearSession(); + return Promise.reject(error); + }); + } + return Promise.resolve(access_token); + } + }, + { + key: 'logout', + value: function logout() { + return this._request('/logout', { method: 'POST' }).then(this.clearSession.bind(this)).catch(this.clearSession.bind(this)); + } + }, + { + key: '_request', + value: function _request(path) { + var _this3 = this; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + options.headers = options.headers || {}; + var aud = options.audience || this.audience; + if (aud) { + options.headers['X-JWT-AUD'] = aud; + } + return this.jwt().then(function (token) { + return _this3.api.request(path, _extends({ headers: Object.assign(options.headers, { Authorization: 'Bearer ' + token }) }, options)); + }); + } + }, + { + key: 'getUserData', + value: function getUserData() { + return this._request('/user').then(this._saveUserData.bind(this)).then(this._refreshSavedSession.bind(this)); + } + }, + { + key: '_saveUserData', + value: function _saveUserData(attributes) { + for (var key in attributes) { + if (key in User.prototype || key in forbiddenUpdateAttributes) { + continue; + } + this[key] = attributes[key]; + } + return this; + } + }, + { + key: '_processTokenResponse', + value: function _processTokenResponse(tokenResponse) { + this.token = tokenResponse; + this.token.expires_at = Date.now() + tokenResponse.expires_in * 1000; + } + }, + { + key: '_refreshSavedSession', + value: function _refreshSavedSession() { + if (localStorage.getItem(storageKey)) { + this._saveSession(); + } + return this; + } + }, + { + key: '_saveSession', + value: function _saveSession() { + localStorage.setItem(storageKey, JSON.stringify(this._details)); + return this; + } + }, + { + key: 'tokenDetails', + value: function tokenDetails() { + return this.token; + } + }, + { + key: 'clearSession', + value: function clearSession() { + User.removeSavedSession(); + this.token = null; + currentUser = null; + } + }, + { + key: 'admin', + get: function get() { + return new _admin2.default(this); + } + }, + { + key: '_details', + get: function get() { + var userCopy = {}; + for (var key in this) { + if (key in User.prototype || key in forbiddenSaveAttributes) { + continue; + } + userCopy[key] = this[key]; + } + return userCopy; + } + } + ], [ + { + key: 'removeSavedSession', + value: function removeSavedSession() { + localStorage.removeItem(storageKey); + } + }, + { + key: 'recoverSession', + value: function recoverSession() { + if (currentUser) { + return currentUser; + } + var json = localStorage.getItem(storageKey); + if (json) { + try { + var data = JSON.parse(json); + var url = data.url, token = data.token, audience = data.audience; + if (!url || !token) { + return null; + } + var api = new _microApiClient2.default(url); + return new User(api, token, audience)._saveUserData(data); + } catch (ex) { + return null; + } + } + return null; + } + } + ]); + return User; +}(); +exports.default = User; +},{"./admin":32,"micro-api-client":36}],35:[function(require,module,exports){ +var inserted = {}; +module.exports = function (css, options) { + if (inserted[css]) + return; + inserted[css] = true; + var elem = document.createElement('style'); + elem.setAttribute('type', 'text/css'); + if ('textContent' in elem) { + elem.textContent = css; + } else { + elem.styleSheet.cssText = css; + } + var head = document.getElementsByTagName('head')[0]; + if (options && options.prepend) { + head.insertBefore(elem, head.childNodes[0]); + } else { + head.appendChild(elem); + } +}; +},{}],36:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +var _extends = Object.assign || function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; +}; +var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ('value' in descriptor) + descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + return function (Constructor, protoProps, staticProps) { + if (protoProps) + defineProperties(Constructor.prototype, protoProps); + if (staticProps) + defineProperties(Constructor, staticProps); + return Constructor; + }; +}(); +var _pagination = require('./pagination'); +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError('Cannot call a class as a function'); + } +} +var API = function () { + function API(apiURL) { + _classCallCheck(this, API); + this.apiURL = apiURL; + } + _createClass(API, [ + { + key: 'headers', + value: function headers() { + var _headers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return _extends({ 'Content-Type': 'application/json' }, _headers); + } + }, + { + key: 'parseJsonResponse', + value: function parseJsonResponse(response) { + return response.json().then(function (json) { + if (!response.ok) { + return Promise.reject(json); + } + var pagination = (0, _pagination.getPagination)(response); + return pagination ? { + pagination: pagination, + items: json + } : json; + }); + } + }, + { + key: 'request', + value: function request(path) { + var _this = this; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var headers = this.headers(options.headers || {}); + return fetch(this.apiURL + path, _extends({}, options, { headers: headers })).then(function (response) { + var contentType = response.headers.get('Content-Type'); + if (contentType && contentType.match(/json/)) { + return _this.parseJsonResponse(response); + } + return response.text().then(function (data) { + if (!response.ok) { + return Promise.reject({ data: data }); + } + return { data: data }; + }); + }); + } + } + ]); + return API; +}(); +exports.default = API; +},{"./pagination":37}],37:[function(require,module,exports){ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +var _slicedToArray = function () { + function sliceIterator(arr, i) { + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + if (i && _arr.length === i) + break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i['return']) + _i['return'](); + } finally { + if (_d) + throw _e; + } + } + return _arr; + } + return function (arr, i) { + if (Array.isArray(arr)) { + return arr; + } else if (Symbol.iterator in Object(arr)) { + return sliceIterator(arr, i); + } else { + throw new TypeError('Invalid attempt to destructure non-iterable instance'); + } + }; +}(); +exports.getPagination = getPagination; +function getPagination(response) { + var links = response.headers.get('Link'); + var pagination = {}; + if (links == null) { + return null; + } + links = links.split(','); + var total = response.headers.get('X-Total-Count'); + for (var i = 0, len = links.length; i < len; i++) { + var link = links[i].replace(/(^\s*|\s*$)/, ''); + var _link$split = link.split(';'); + var _link$split2 = _slicedToArray(_link$split, 2); + var url = _link$split2[0]; + var rel = _link$split2[1]; + var m = url.match(/page=(\d+)/); + var page = m && parseInt(m[1], 10); + if (rel.match(/last/)) { + pagination.last = page; + } else if (rel.match(/next/)) { + pagination.next = page; + } else if (rel.match(/prev/)) { + pagination.prev = page; + } else if (rel.match(/first/)) { + pagination.first = page; + } + } + pagination.last = Math.max(pagination.last || 0, pagination.prev && pagination.prev + 1 || 0); + pagination.current = pagination.next ? pagination.next - 1 : pagination.last || 1; + pagination.total = total ? parseInt(total, 10) : null; + return pagination; +} +},{}],38:[function(require,module,exports){ +var splice = require('remove-array-items'); +var nanotiming = require('nanotiming'); +module.exports = Nanobus; +function Nanobus(name) { + if (!(this instanceof Nanobus)) + return new Nanobus(name); + this._name = name || 'nanobus'; + this._starListeners = []; + this._listeners = {}; +} +Nanobus.prototype.emit = function (eventName, data) { + var emitTiming = nanotiming(this._name + '(\'' + eventName + '\')'); + var listeners = this._listeners[eventName]; + if (listeners && listeners.length > 0) { + this._emit(this._listeners[eventName], data); + } + if (this._starListeners.length > 0) { + this._emit(this._starListeners, eventName, data, emitTiming.uuid); + } + emitTiming(); + return this; +}; +Nanobus.prototype.on = Nanobus.prototype.addListener = function (eventName, listener) { + if (eventName === '*') { + this._starListeners.push(listener); + } else { + if (!this._listeners[eventName]) + this._listeners[eventName] = []; + this._listeners[eventName].push(listener); + } + return this; +}; +Nanobus.prototype.prependListener = function (eventName, listener) { + if (eventName === '*') { + this._starListeners.unshift(listener); + } else { + if (!this._listeners[eventName]) + this._listeners[eventName] = []; + this._listeners[eventName].unshift(listener); + } + return this; +}; +Nanobus.prototype.once = function (eventName, listener) { + var self = this; + this.on(eventName, once); + function once() { + listener.apply(self, arguments); + self.removeListener(eventName, once); + } + return this; +}; +Nanobus.prototype.prependOnceListener = function (eventName, listener) { + var self = this; + this.prependListener(eventName, once); + function once() { + listener.apply(self, arguments); + self.removeListener(eventName, once); + } + return this; +}; +Nanobus.prototype.removeListener = function (eventName, listener) { + if (eventName === '*') { + this._starListeners = this._starListeners.slice(); + return remove(this._starListeners, listener); + } else { + if (typeof this._listeners[eventName] !== 'undefined') { + this._listeners[eventName] = this._listeners[eventName].slice(); + } + return remove(this._listeners[eventName], listener); + } + function remove(arr, listener) { + if (!arr) + return; + var index = arr.indexOf(listener); + if (index !== -1) { + splice(arr, index, 1); + return true; + } + } +}; +Nanobus.prototype.removeAllListeners = function (eventName) { + if (eventName) { + if (eventName === '*') { + this._starListeners = []; + } else { + this._listeners[eventName] = []; + } + } else { + this._starListeners = []; + this._listeners = {}; + } + return this; +}; +Nanobus.prototype.listeners = function (eventName) { + var listeners = eventName !== '*' ? this._listeners[eventName] : this._starListeners; + var ret = []; + if (listeners) { + var ilength = listeners.length; + for (var i = 0; i < ilength; i++) + ret.push(listeners[i]); + } + return ret; +}; +Nanobus.prototype._emit = function (arr, eventName, data, uuid) { + if (typeof arr === 'undefined') + return; + if (data === undefined) { + data = eventName; + eventName = null; + } + var length = arr.length; + for (var i = 0; i < length; i++) { + var listener = arr[i]; + if (eventName) { + if (uuid !== undefined) + listener(eventName, data, uuid); + else + listener(eventName, data); + } else { + listener(data); + } + } +}; +},{"nanotiming":43,"remove-array-items":48}],39:[function(require,module,exports){ +var document = require('global/document'); +var nanotiming = require('nanotiming'); +var morph = require('nanomorph'); +var onload = require('on-load'); +module.exports = Nanocomponent; +function makeID() { + return 'ncid-' + Math.floor((1 + Math.random()) * 65536).toString(16).substring(1); +} +function Nanocomponent(name) { + this._hasWindow = typeof window !== 'undefined'; + this._id = null; + this._ncID = null; + this._proxy = null; + this._loaded = false; + this._rootNodeName = null; + this._name = name || 'nanocomponent'; + this._handleLoad = this._handleLoad.bind(this); + this._handleUnload = this._handleUnload.bind(this); + var self = this; + Object.defineProperty(this, 'element', { + get: function () { + var el = document.getElementById(self._id); + if (el) + return el.dataset.nanocomponent === self._ncID ? el : undefined; + } + }); +} +Nanocomponent.prototype.render = function () { + var timing = nanotiming(this._name + '.render'); + var self = this; + var args = new Array(arguments.length); + var el; + for (var i = 0; i < arguments.length; i++) + args[i] = arguments[i]; + if (!this._hasWindow) { + el = this.createElement.apply(this, args); + timing(); + return el; + } else if (this.element) { + var shouldUpdate = this.update.apply(this, args); + if (shouldUpdate) { + morph(this.element, this._handleRender(args)); + if (this.afterupdate) + this.afterupdate(this.element); + } + if (!this._proxy) { + this._proxy = this._createProxy(); + } + timing(); + return this._proxy; + } else { + this._reset(); + el = this._handleRender(args); + if (this.beforerender) + this.beforerender(el); + if (this.load || this.unload || this.afterrreorder) { + onload(el, self._handleLoad, self._handleUnload, self); + } + timing(); + return el; + } +}; +Nanocomponent.prototype._handleRender = function (args) { + var el = this.createElement.apply(this, args); + if (!this._rootNodeName) + this._rootNodeName = el.nodeName; + return this._brandNode(this._ensureID(el)); +}; +Nanocomponent.prototype._createProxy = function () { + var proxy = document.createElement('div'); + var self = this; + this._brandNode(proxy); + proxy.id = this._id; + proxy.setAttribute('data-proxy', ''); + proxy.isSameNode = function (el) { + return el && el.dataset.nanocomponent === self._ncID; + }; + return proxy; +}; +Nanocomponent.prototype._reset = function () { + this._ncID = makeID(); + this._id = null; + this._proxy = null; + this._rootNodeName = null; +}; +Nanocomponent.prototype._brandNode = function (node) { + node.setAttribute('data-nanocomponent', this._ncID); + return node; +}; +Nanocomponent.prototype._ensureID = function (node) { + if (node.id) + this._id = node.id; + else + node.id = this._id = this._ncID; + return node; +}; +Nanocomponent.prototype._handleLoad = function (el) { + var self = this; + if (this._loaded) { + if (this.afterreorder) + window.requestAnimationFrame(function () { + self.afterreorder(el); + }); + return; + } + this._loaded = true; + if (this.load) + window.requestAnimationFrame(function () { + self.load(el); + }); +}; +Nanocomponent.prototype._handleUnload = function (el) { + var self = this; + if (this.element) + return; + this._loaded = false; + if (this.unload) + window.requestAnimationFrame(function () { + self.unload(el); + }); +}; +Nanocomponent.prototype.createElement = function () { + throw new Error('nanocomponent: createElement should be implemented!'); +}; +Nanocomponent.prototype.update = function () { + throw new Error('nanocomponent: update should be implemented!'); +}; +},{"global/document":30,"nanomorph":40,"nanotiming":43,"on-load":46}],40:[function(require,module,exports){ +var morph = require('./lib/morph'); +var TEXT_NODE = 3; +module.exports = nanomorph; +function nanomorph(oldTree, newTree) { + var tree = walk(newTree, oldTree); + return tree; +} +function walk(newNode, oldNode) { + if (!oldNode) { + return newNode; + } else if (!newNode) { + return null; + } else if (newNode.isSameNode && newNode.isSameNode(oldNode)) { + return oldNode; + } else if (newNode.tagName !== oldNode.tagName) { + return newNode; + } else { + morph(newNode, oldNode); + updateChildren(newNode, oldNode); + return oldNode; + } +} +function updateChildren(newNode, oldNode) { + var oldChild, newChild, morphed, oldMatch; + var offset = 0; + for (var i = 0;; i++) { + oldChild = oldNode.childNodes[i]; + newChild = newNode.childNodes[i - offset]; + if (!oldChild && !newChild) { + break; + } else if (!newChild) { + oldNode.removeChild(oldChild); + i--; + } else if (!oldChild) { + oldNode.appendChild(newChild); + offset++; + } else if (same(newChild, oldChild)) { + morphed = walk(newChild, oldChild); + if (morphed !== oldChild) { + oldNode.replaceChild(morphed, oldChild); + offset++; + } + } else { + oldMatch = null; + for (var j = i; j < oldNode.childNodes.length; j++) { + if (same(oldNode.childNodes[j], newChild)) { + oldMatch = oldNode.childNodes[j]; + break; + } + } + if (oldMatch) { + morphed = walk(newChild, oldMatch); + if (morphed !== oldMatch) + offset++; + oldNode.insertBefore(morphed, oldChild); + } else if (!newChild.id && !oldChild.id) { + morphed = walk(newChild, oldChild); + if (morphed !== oldChild) { + oldNode.replaceChild(morphed, oldChild); + offset++; + } + } else { + oldNode.insertBefore(newChild, oldChild); + offset++; + } + } + } +} +function same(a, b) { + if (a.id) + return a.id === b.id; + if (a.isSameNode) + return a.isSameNode(b); + if (a.tagName !== b.tagName) + return false; + if (a.type === TEXT_NODE) + return a.nodeValue === b.nodeValue; + return false; +} +},{"./lib/morph":42}],41:[function(require,module,exports){ +module.exports = [ + 'onclick', + 'ondblclick', + 'onmousedown', + 'onmouseup', + 'onmouseover', + 'onmousemove', + 'onmouseout', + 'onmouseenter', + 'onmouseleave', + 'ondragstart', + 'ondrag', + 'ondragenter', + 'ondragleave', + 'ondragover', + 'ondrop', + 'ondragend', + 'onkeydown', + 'onkeypress', + 'onkeyup', + 'onunload', + 'onabort', + 'onerror', + 'onresize', + 'onscroll', + 'onselect', + 'onchange', + 'onsubmit', + 'onreset', + 'onfocus', + 'onblur', + 'oninput', + 'oncontextmenu', + 'onfocusin', + 'onfocusout' +]; +},{}],42:[function(require,module,exports){ +var events = require('./events'); +var eventsLength = events.length; +var ELEMENT_NODE = 1; +var TEXT_NODE = 3; +var COMMENT_NODE = 8; +module.exports = morph; +function morph(newNode, oldNode) { + var nodeType = newNode.nodeType; + var nodeName = newNode.nodeName; + if (nodeType === ELEMENT_NODE) { + copyAttrs(newNode, oldNode); + } + if (nodeType === TEXT_NODE || nodeType === COMMENT_NODE) { + oldNode.nodeValue = newNode.nodeValue; + } + if (nodeName === 'INPUT') + updateInput(newNode, oldNode); + else if (nodeName === 'OPTION') + updateOption(newNode, oldNode); + else if (nodeName === 'TEXTAREA') + updateTextarea(newNode, oldNode); + copyEvents(newNode, oldNode); +} +function copyAttrs(newNode, oldNode) { + var oldAttrs = oldNode.attributes; + var newAttrs = newNode.attributes; + var attrNamespaceURI = null; + var attrValue = null; + var fromValue = null; + var attrName = null; + var attr = null; + for (var i = newAttrs.length - 1; i >= 0; --i) { + attr = newAttrs[i]; + attrName = attr.name; + attrNamespaceURI = attr.namespaceURI; + attrValue = attr.value; + if (attrNamespaceURI) { + attrName = attr.localName || attrName; + fromValue = oldNode.getAttributeNS(attrNamespaceURI, attrName); + if (fromValue !== attrValue) { + oldNode.setAttributeNS(attrNamespaceURI, attrName, attrValue); + } + } else { + if (!oldNode.hasAttribute(attrName)) { + oldNode.setAttribute(attrName, attrValue); + } else { + fromValue = oldNode.getAttribute(attrName); + if (fromValue !== attrValue) { + if (attrValue === 'null' || attrValue === 'undefined') { + oldNode.removeAttribute(attrName); + } else { + oldNode.setAttribute(attrName, attrValue); + } + } + } + } + } + for (var j = oldAttrs.length - 1; j >= 0; --j) { + attr = oldAttrs[j]; + if (attr.specified !== false) { + attrName = attr.name; + attrNamespaceURI = attr.namespaceURI; + if (attrNamespaceURI) { + attrName = attr.localName || attrName; + if (!newNode.hasAttributeNS(attrNamespaceURI, attrName)) { + oldNode.removeAttributeNS(attrNamespaceURI, attrName); + } + } else { + if (!newNode.hasAttributeNS(null, attrName)) { + oldNode.removeAttribute(attrName); + } + } + } + } +} +function copyEvents(newNode, oldNode) { + for (var i = 0; i < eventsLength; i++) { + var ev = events[i]; + if (newNode[ev]) { + oldNode[ev] = newNode[ev]; + } else if (oldNode[ev]) { + oldNode[ev] = undefined; + } + } +} +function updateOption(newNode, oldNode) { + updateAttribute(newNode, oldNode, 'selected'); +} +function updateInput(newNode, oldNode) { + var newValue = newNode.value; + var oldValue = oldNode.value; + updateAttribute(newNode, oldNode, 'checked'); + updateAttribute(newNode, oldNode, 'disabled'); + if (newValue !== oldValue) { + oldNode.setAttribute('value', newValue); + oldNode.value = newValue; + } + if (newValue === 'null') { + oldNode.value = ''; + oldNode.removeAttribute('value'); + } + if (!newNode.hasAttributeNS(null, 'value')) { + oldNode.removeAttribute('value'); + } else if (oldNode.type === 'range') { + oldNode.value = newValue; + } +} +function updateTextarea(newNode, oldNode) { + var newValue = newNode.value; + if (newValue !== oldNode.value) { + oldNode.value = newValue; + } + if (oldNode.firstChild && oldNode.firstChild.nodeValue !== newValue) { + if (newValue === '' && oldNode.firstChild.nodeValue === oldNode.placeholder) { + return; + } + oldNode.firstChild.nodeValue = newValue; + } +} +function updateAttribute(newNode, oldNode, name) { + if (newNode[name] !== oldNode[name]) { + oldNode[name] = newNode[name]; + if (newNode[name]) { + oldNode.setAttribute(name, ''); + } else { + oldNode.removeAttribute(name); + } + } +} +},{"./events":41}],43:[function(require,module,exports){ +var onIdle = require('on-idle'); +var perf; +var disabled = true; +try { + perf = window.performance; + disabled = window.localStorage.DISABLE_NANOTIMING === 'true' || !perf.mark; +} catch (e) { +} +module.exports = nanotiming; +function nanotiming(name) { + if (disabled) + return noop; + var uuid = (perf.now() * 100).toFixed(); + var startName = 'start-' + uuid + '-' + name; + perf.mark(startName); + function end(cb) { + var endName = 'end-' + uuid + '-' + name; + perf.mark(endName); + onIdle(function () { + var measureName = name + ' [' + uuid + ']'; + perf.measure(measureName, startName, endName); + perf.clearMarks(startName); + perf.clearMarks(endName); + if (cb) + cb(name); + }); + } + end.uuid = uuid; + return end; +} +function noop(cb) { + if (cb) + onIdle(cb); +} +},{"on-idle":45}],44:[function(require,module,exports){ +'use strict'; +var getOwnPropertySymbols = Object.getOwnPropertySymbols; +var hasOwnProperty = Object.prototype.hasOwnProperty; +var propIsEnumerable = Object.prototype.propertyIsEnumerable; +function toObject(val) { + if (val === null || val === undefined) { + throw new TypeError('Object.assign cannot be called with null or undefined'); + } + return Object(val); +} +function shouldUseNative() { + try { + if (!Object.assign) { + return false; + } + var test1 = new String('abc'); + test1[5] = 'de'; + if (Object.getOwnPropertyNames(test1)[0] === '5') { + return false; + } + var test2 = {}; + for (var i = 0; i < 10; i++) { + test2['_' + String.fromCharCode(i)] = i; + } + var order2 = Object.getOwnPropertyNames(test2).map(function (n) { + return test2[n]; + }); + if (order2.join('') !== '0123456789') { + return false; + } + var test3 = {}; + 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { + test3[letter] = letter; + }); + if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') { + return false; + } + return true; + } catch (err) { + return false; + } +} +module.exports = shouldUseNative() ? Object.assign : function (target, source) { + var from; + var to = toObject(target); + var symbols; + for (var s = 1; s < arguments.length; s++) { + from = Object(arguments[s]); + for (var key in from) { + if (hasOwnProperty.call(from, key)) { + to[key] = from[key]; + } + } + if (getOwnPropertySymbols) { + symbols = getOwnPropertySymbols(from); + for (var i = 0; i < symbols.length; i++) { + if (propIsEnumerable.call(from, symbols[i])) { + to[symbols[i]] = from[symbols[i]]; + } + } + } + } + return to; +}; +},{}],45:[function(require,module,exports){ +var dftOpts = {}; +var hasWindow = typeof window !== 'undefined'; +var hasIdle = hasWindow && window.requestIdleCallback; +module.exports = onIdle; +function onIdle(cb, opts) { + opts = opts || dftOpts; + var timerId; + if (hasIdle) { + timerId = window.requestIdleCallback(function (idleDeadline) { + if (idleDeadline.timeRemaining() <= 10 && !idleDeadline.didTimeout) { + return onIdle(cb, opts); + } else { + cb(idleDeadline); + } + }, opts); + return window.cancelIdleCallback.bind(window, timerId); + } else if (hasWindow) { + timerId = setTimeout(cb, 0); + return clearTimeout.bind(window, timerId); + } +} +},{}],46:[function(require,module,exports){ +var document = require('global/document'); +var window = require('global/window'); +var watch = Object.create(null); +var KEY_ID = 'onloadid' + (new Date() % 9000000).toString(36); +var KEY_ATTR = 'data-' + KEY_ID; +var INDEX = 0; +if (window && window.MutationObserver) { + var observer = new MutationObserver(function (mutations) { + if (Object.keys(watch).length < 1) + return; + for (var i = 0; i < mutations.length; i++) { + if (mutations[i].attributeName === KEY_ATTR) { + eachAttr(mutations[i], turnon, turnoff); + continue; + } + eachMutation(mutations[i].removedNodes, turnoff); + eachMutation(mutations[i].addedNodes, turnon); + } + }); + observer.observe(document.body, { + childList: true, + subtree: true, + attributes: true, + attributeOldValue: true, + attributeFilter: [KEY_ATTR] + }); +} +module.exports = function onload(el, on, off, caller) { + on = on || function () { + }; + off = off || function () { + }; + el.setAttribute(KEY_ATTR, 'o' + INDEX); + watch['o' + INDEX] = [ + on, + off, + 0, + caller || onload.caller + ]; + INDEX += 1; + return el; +}; +function turnon(index, el) { + if (watch[index][0] && watch[index][2] === 0) { + watch[index][0](el); + watch[index][2] = 1; + } +} +function turnoff(index, el) { + if (watch[index][1] && watch[index][2] === 1) { + watch[index][1](el); + watch[index][2] = 0; + } +} +function eachAttr(mutation, on, off) { + var newValue = mutation.target.getAttribute(KEY_ATTR); + if (sameOrigin(mutation.oldValue, newValue)) { + watch[newValue] = watch[mutation.oldValue]; + return; + } + if (watch[mutation.oldValue]) { + off(mutation.oldValue, mutation.target); + } + if (watch[newValue]) { + on(newValue, mutation.target); + } +} +function sameOrigin(oldValue, newValue) { + if (!oldValue || !newValue) + return false; + return watch[oldValue][3] === watch[newValue][3]; +} +function eachMutation(nodes, fn) { + var keys = Object.keys(watch); + for (var i = 0; i < nodes.length; i++) { + if (nodes[i] && nodes[i].getAttribute && nodes[i].getAttribute(KEY_ATTR)) { + var onloadid = nodes[i].getAttribute(KEY_ATTR); + keys.forEach(function (k) { + if (onloadid === k) { + fn(k, nodes[i]); + } + }); + } + if (nodes[i].childNodes.length > 0) { + eachMutation(nodes[i].childNodes, fn); + } + } +} +},{"global/document":30,"global/window":31}],47:[function(require,module,exports){ +'use strict'; +var strictUriEncode = require('strict-uri-encode'); +var objectAssign = require('object-assign'); +var decodeComponent = require('decode-uri-component'); +function encoderForArrayFormat(opts) { + switch (opts.arrayFormat) { + case 'index': + return function (key, value, index) { + return value === null ? [ + encode(key, opts), + '[', + index, + ']' + ].join('') : [ + encode(key, opts), + '[', + encode(index, opts), + ']=', + encode(value, opts) + ].join(''); + }; + case 'bracket': + return function (key, value) { + return value === null ? encode(key, opts) : [ + encode(key, opts), + '[]=', + encode(value, opts) + ].join(''); + }; + default: + return function (key, value) { + return value === null ? encode(key, opts) : [ + encode(key, opts), + '=', + encode(value, opts) + ].join(''); + }; + } +} +function parserForArrayFormat(opts) { + var result; + switch (opts.arrayFormat) { + case 'index': + return function (key, value, accumulator) { + result = /\[(\d*)\]$/.exec(key); + key = key.replace(/\[\d*\]$/, ''); + if (!result) { + accumulator[key] = value; + return; + } + if (accumulator[key] === undefined) { + accumulator[key] = {}; + } + accumulator[key][result[1]] = value; + }; + case 'bracket': + return function (key, value, accumulator) { + result = /(\[\])$/.exec(key); + key = key.replace(/\[\]$/, ''); + if (!result) { + accumulator[key] = value; + return; + } else if (accumulator[key] === undefined) { + accumulator[key] = [value]; + return; + } + accumulator[key] = [].concat(accumulator[key], value); + }; + default: + return function (key, value, accumulator) { + if (accumulator[key] === undefined) { + accumulator[key] = value; + return; + } + accumulator[key] = [].concat(accumulator[key], value); + }; + } +} +function encode(value, opts) { + if (opts.encode) { + return opts.strict ? strictUriEncode(value) : encodeURIComponent(value); + } + return value; +} +function keysSorter(input) { + if (Array.isArray(input)) { + return input.sort(); + } else if (typeof input === 'object') { + return keysSorter(Object.keys(input)).sort(function (a, b) { + return Number(a) - Number(b); + }).map(function (key) { + return input[key]; + }); + } + return input; +} +exports.extract = function (str) { + return str.split('?')[1] || ''; +}; +exports.parse = function (str, opts) { + opts = objectAssign({ arrayFormat: 'none' }, opts); + var formatter = parserForArrayFormat(opts); + var ret = Object.create(null); + if (typeof str !== 'string') { + return ret; + } + str = str.trim().replace(/^(\?|#|&)/, ''); + if (!str) { + return ret; + } + str.split('&').forEach(function (param) { + var parts = param.replace(/\+/g, ' ').split('='); + var key = parts.shift(); + var val = parts.length > 0 ? parts.join('=') : undefined; + val = val === undefined ? null : decodeComponent(val); + formatter(decodeComponent(key), val, ret); + }); + return Object.keys(ret).sort().reduce(function (result, key) { + var val = ret[key]; + if (Boolean(val) && typeof val === 'object' && !Array.isArray(val)) { + result[key] = keysSorter(val); + } else { + result[key] = val; + } + return result; + }, Object.create(null)); +}; +exports.stringify = function (obj, opts) { + var defaults = { + encode: true, + strict: true, + arrayFormat: 'none' + }; + opts = objectAssign(defaults, opts); + var formatter = encoderForArrayFormat(opts); + return obj ? Object.keys(obj).sort().map(function (key) { + var val = obj[key]; + if (val === undefined) { + return ''; + } + if (val === null) { + return encode(key, opts); + } + if (Array.isArray(val)) { + var result = []; + val.slice().forEach(function (val2) { + if (val2 === undefined) { + return; + } + result.push(formatter(key, val2, result.length)); + }); + return result.join('&'); + } + return encode(key, opts) + '=' + encode(val, opts); + }).filter(function (x) { + return x.length > 0; + }).join('&') : ''; +}; +},{"decode-uri-component":29,"object-assign":44,"strict-uri-encode":49}],48:[function(require,module,exports){ +'use strict'; +module.exports = function removeItems(arr, startIdx, removeCount) { + var i, length = arr.length; + if (startIdx >= length || removeCount === 0) { + return; + } + removeCount = startIdx + removeCount > length ? length - startIdx : removeCount; + var len = length - removeCount; + for (i = startIdx; i < len; ++i) { + arr[i] = arr[i + removeCount]; + } + arr.length = len; +}; +},{}],49:[function(require,module,exports){ +'use strict'; +module.exports = function (str) { + return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { + return '%' + c.charCodeAt(0).toString(16).toUpperCase(); + }); +}; +},{}],50:[function(require,module,exports){ +'use strict'; +module.exports = function yoyoifyAppendChild(el, childs) { + for (var i = 0; i < childs.length; i++) { + var node = childs[i]; + if (Array.isArray(node)) { + yoyoifyAppendChild(el, node); + continue; + } + if (typeof node === 'number' || typeof node === 'boolean' || node instanceof Date || node instanceof RegExp) { + node = node.toString(); + } + if (typeof node === 'string') { + if (/^[\n\r\s]+$/.test(node)) + continue; + if (el.lastChild && el.lastChild.nodeName === '#text') { + el.lastChild.nodeValue += node; + continue; + } + node = document.createTextNode(node); + } + if (node && node.nodeType) { + el.appendChild(node); + } + } +}; +},{}],51:[function(require,module,exports){ +'use strict'; +var NetlifyIdentity = require('./index.js'); +var netlifyIdentity = new NetlifyIdentity(); +module.exports = netlifyIdentity; +document.addEventListener('DOMContentLoaded', function (event) { + init(); +}); +function init() { + if (!window.netlifyIdentity) { + window.netlifyIdentity = netlifyIdentity; + } + var modalContainer = document.querySelector('div[data-netlify-identity-modal=""]'); + if (!modalContainer) { + modalContainer = document.createElement('div'); + document.body.appendChild(modalContainer); + } + if (!window.goTrue) { + } + if (!netlifyIdentity.isMounted) { + netlifyIdentity.create().then(function (node) { + return modalContainer.appendChild(node); + }); + } else { + console.warn('NetlifyIdentity: two or more instances are running on the same page'); + } +} +},{"./index.js":6}]},{},[51])(51) +}); \ No newline at end of file -- cgit v1.3