@dsb-norge/vue-keycloak-js
Advanced tools
Comparing version 2.1.3-beta to 2.1.4-beta
/*! | ||
* vue-keycloak-js v2.1.3-beta | ||
* vue-keycloak-js v2.0.0-beta | ||
* @license ISC | ||
@@ -8,71 +8,22 @@ */ | ||
var Keycloak = require('keycloak-js'); | ||
var vue = require('vue'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
} | ||
var Keycloak__default = /*#__PURE__*/_interopDefaultLegacy(Keycloak); | ||
var vue__namespace = /*#__PURE__*/_interopNamespace(vue); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
let installed = false; | ||
const KeycloakSymbol = Symbol('keycloak'); | ||
var index = { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
install: function (app, params = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (installed) | ||
return; | ||
installed = true; | ||
const defaultParams = { | ||
config: window.__BASEURL__ ? `${window.__BASEURL__}/config` : '/config', | ||
init: { onLoad: 'login-required' }, | ||
}; | ||
const options = Object.assign({}, defaultParams, params); | ||
if (assertOptions(options).hasError) | ||
throw new Error(`Invalid options given: ${assertOptions(options).error}`); | ||
const watch = yield vue2AndVue3Reactive(app, defaultEmptyVueKeycloakInstance()); | ||
if (installed) | ||
return; | ||
installed = true; | ||
const defaultParams = { | ||
config: window.__BASEURL__ ? `${window.__BASEURL__}/config` : '/config', | ||
init: { onLoad: 'login-required' }, | ||
}; | ||
const options = Object.assign({}, defaultParams, params); | ||
if (assertOptions(options).hasError) | ||
throw new Error(`Invalid options given: ${assertOptions(options).error}`); | ||
vue2AndVue3Reactive(app, defaultEmptyVueKeycloakInstance()).then((watch) => { | ||
getConfig(options.config) | ||
@@ -87,3 +38,2 @@ .then((config) => { | ||
}, | ||
KeycloakSymbol | ||
}; | ||
@@ -143,10 +93,12 @@ function defaultEmptyVueKeycloakInstance() { | ||
// Assign an object immediately to allow usage of $keycloak in view | ||
//const vue = await import('vue') | ||
const reactiveObj = defaultEmptyVueKeycloakInstance(); | ||
app.config.globalProperties.$keycloak = reactiveObj; | ||
// Async load module to allow vue 2 to not have the dependency. | ||
const reactiveObj = vue__namespace.reactive(object); | ||
// Override the existing reactiveObj so references contains the new reactive values | ||
app.config.globalProperties.$keycloak = reactiveObj; | ||
// Use provide/inject in Vue3 apps | ||
app.provide(KeycloakSymbol, reactiveObj); | ||
resolve(reactiveObj); | ||
Promise.resolve().then(function () { return reactivity_esmBundler; }).then((reactivity) => { | ||
// Override the existing reactiveObj so references contains the new reactive values | ||
Object.assign(reactiveObj, reactivity.reactive(object)); | ||
resolve(reactiveObj); | ||
}).catch(e => { | ||
reject(e); | ||
}); | ||
} | ||
@@ -175,4 +127,2 @@ }); | ||
updateWatchVariables(true); | ||
typeof options.onAuthRefreshSuccess === 'function' && | ||
options.onAuthRefreshSuccess(keycloak); | ||
}; | ||
@@ -193,3 +143,3 @@ keycloak.onAuthRefreshError = function () { | ||
updateWatchVariables(false); | ||
const error = Error('Failure during initialization of keycloak-js adapter'); | ||
const error = Error('Could not initialized keycloak-js adapter'); | ||
typeof options.onInitError === 'function' | ||
@@ -294,2 +244,979 @@ ? options.onInitError(error, err) | ||
/** | ||
* Make a map and return a function for checking if a key | ||
* is in that map. | ||
* IMPORTANT: all calls of this function must be prefixed with | ||
* \/\*#\_\_PURE\_\_\*\/ | ||
* So that rollup can tree-shake them if necessary. | ||
*/ | ||
function makeMap(str, expectsLowerCase) { | ||
const map = Object.create(null); | ||
const list = str.split(','); | ||
for (let i = 0; i < list.length; i++) { | ||
map[list[i]] = true; | ||
} | ||
return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]; | ||
} | ||
const EMPTY_OBJ = (process.env.NODE_ENV !== 'production') | ||
? Object.freeze({}) | ||
: {}; | ||
(process.env.NODE_ENV !== 'production') ? Object.freeze([]) : []; | ||
const NOOP = () => { }; | ||
const extend = Object.assign; | ||
const hasOwnProperty = Object.prototype.hasOwnProperty; | ||
const hasOwn = (val, key) => hasOwnProperty.call(val, key); | ||
const isArray = Array.isArray; | ||
const isMap = (val) => toTypeString(val) === '[object Map]'; | ||
const isFunction = (val) => typeof val === 'function'; | ||
const isString = (val) => typeof val === 'string'; | ||
const isSymbol = (val) => typeof val === 'symbol'; | ||
const isObject = (val) => val !== null && typeof val === 'object'; | ||
const objectToString = Object.prototype.toString; | ||
const toTypeString = (value) => objectToString.call(value); | ||
const toRawType = (value) => { | ||
// extract "RawType" from strings like "[object RawType]" | ||
return toTypeString(value).slice(8, -1); | ||
}; | ||
const isIntegerKey = (key) => isString(key) && | ||
key !== 'NaN' && | ||
key[0] !== '-' && | ||
'' + parseInt(key, 10) === key; | ||
const cacheStringFunction = (fn) => { | ||
const cache = Object.create(null); | ||
return ((str) => { | ||
const hit = cache[str]; | ||
return hit || (cache[str] = fn(str)); | ||
}); | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1)); | ||
// compare whether a value has changed, accounting for NaN. | ||
const hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue); | ||
const def = (obj, key, value) => { | ||
Object.defineProperty(obj, key, { | ||
configurable: true, | ||
enumerable: false, | ||
value | ||
}); | ||
}; | ||
const targetMap = new WeakMap(); | ||
const effectStack = []; | ||
let activeEffect; | ||
const ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'iterate' : ''); | ||
const MAP_KEY_ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'Map key iterate' : ''); | ||
function isEffect(fn) { | ||
return fn && fn._isEffect === true; | ||
} | ||
function effect(fn, options = EMPTY_OBJ) { | ||
if (isEffect(fn)) { | ||
fn = fn.raw; | ||
} | ||
const effect = createReactiveEffect(fn, options); | ||
if (!options.lazy) { | ||
effect(); | ||
} | ||
return effect; | ||
} | ||
function stop(effect) { | ||
if (effect.active) { | ||
cleanup(effect); | ||
if (effect.options.onStop) { | ||
effect.options.onStop(); | ||
} | ||
effect.active = false; | ||
} | ||
} | ||
let uid = 0; | ||
function createReactiveEffect(fn, options) { | ||
const effect = function reactiveEffect() { | ||
if (!effect.active) { | ||
return options.scheduler ? undefined : fn(); | ||
} | ||
if (!effectStack.includes(effect)) { | ||
cleanup(effect); | ||
try { | ||
enableTracking(); | ||
effectStack.push(effect); | ||
activeEffect = effect; | ||
return fn(); | ||
} | ||
finally { | ||
effectStack.pop(); | ||
resetTracking(); | ||
activeEffect = effectStack[effectStack.length - 1]; | ||
} | ||
} | ||
}; | ||
effect.id = uid++; | ||
effect.allowRecurse = !!options.allowRecurse; | ||
effect._isEffect = true; | ||
effect.active = true; | ||
effect.raw = fn; | ||
effect.deps = []; | ||
effect.options = options; | ||
return effect; | ||
} | ||
function cleanup(effect) { | ||
const { deps } = effect; | ||
if (deps.length) { | ||
for (let i = 0; i < deps.length; i++) { | ||
deps[i].delete(effect); | ||
} | ||
deps.length = 0; | ||
} | ||
} | ||
let shouldTrack = true; | ||
const trackStack = []; | ||
function pauseTracking() { | ||
trackStack.push(shouldTrack); | ||
shouldTrack = false; | ||
} | ||
function enableTracking() { | ||
trackStack.push(shouldTrack); | ||
shouldTrack = true; | ||
} | ||
function resetTracking() { | ||
const last = trackStack.pop(); | ||
shouldTrack = last === undefined ? true : last; | ||
} | ||
function track(target, type, key) { | ||
if (!shouldTrack || activeEffect === undefined) { | ||
return; | ||
} | ||
let depsMap = targetMap.get(target); | ||
if (!depsMap) { | ||
targetMap.set(target, (depsMap = new Map())); | ||
} | ||
let dep = depsMap.get(key); | ||
if (!dep) { | ||
depsMap.set(key, (dep = new Set())); | ||
} | ||
if (!dep.has(activeEffect)) { | ||
dep.add(activeEffect); | ||
activeEffect.deps.push(dep); | ||
if ((process.env.NODE_ENV !== 'production') && activeEffect.options.onTrack) { | ||
activeEffect.options.onTrack({ | ||
effect: activeEffect, | ||
target, | ||
type, | ||
key | ||
}); | ||
} | ||
} | ||
} | ||
function trigger(target, type, key, newValue, oldValue, oldTarget) { | ||
const depsMap = targetMap.get(target); | ||
if (!depsMap) { | ||
// never been tracked | ||
return; | ||
} | ||
const effects = new Set(); | ||
const add = (effectsToAdd) => { | ||
if (effectsToAdd) { | ||
effectsToAdd.forEach(effect => { | ||
if (effect !== activeEffect || effect.allowRecurse) { | ||
effects.add(effect); | ||
} | ||
}); | ||
} | ||
}; | ||
if (type === "clear" /* CLEAR */) { | ||
// collection being cleared | ||
// trigger all effects for target | ||
depsMap.forEach(add); | ||
} | ||
else if (key === 'length' && isArray(target)) { | ||
depsMap.forEach((dep, key) => { | ||
if (key === 'length' || key >= newValue) { | ||
add(dep); | ||
} | ||
}); | ||
} | ||
else { | ||
// schedule runs for SET | ADD | DELETE | ||
if (key !== void 0) { | ||
add(depsMap.get(key)); | ||
} | ||
// also run for iteration key on ADD | DELETE | Map.SET | ||
switch (type) { | ||
case "add" /* ADD */: | ||
if (!isArray(target)) { | ||
add(depsMap.get(ITERATE_KEY)); | ||
if (isMap(target)) { | ||
add(depsMap.get(MAP_KEY_ITERATE_KEY)); | ||
} | ||
} | ||
else if (isIntegerKey(key)) { | ||
// new index added to array -> length changes | ||
add(depsMap.get('length')); | ||
} | ||
break; | ||
case "delete" /* DELETE */: | ||
if (!isArray(target)) { | ||
add(depsMap.get(ITERATE_KEY)); | ||
if (isMap(target)) { | ||
add(depsMap.get(MAP_KEY_ITERATE_KEY)); | ||
} | ||
} | ||
break; | ||
case "set" /* SET */: | ||
if (isMap(target)) { | ||
add(depsMap.get(ITERATE_KEY)); | ||
} | ||
break; | ||
} | ||
} | ||
const run = (effect) => { | ||
if ((process.env.NODE_ENV !== 'production') && effect.options.onTrigger) { | ||
effect.options.onTrigger({ | ||
effect, | ||
target, | ||
key, | ||
type, | ||
newValue, | ||
oldValue, | ||
oldTarget | ||
}); | ||
} | ||
if (effect.options.scheduler) { | ||
effect.options.scheduler(effect); | ||
} | ||
else { | ||
effect(); | ||
} | ||
}; | ||
effects.forEach(run); | ||
} | ||
const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`); | ||
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol) | ||
.map(key => Symbol[key]) | ||
.filter(isSymbol)); | ||
const get = /*#__PURE__*/ createGetter(); | ||
const shallowGet = /*#__PURE__*/ createGetter(false, true); | ||
const readonlyGet = /*#__PURE__*/ createGetter(true); | ||
const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true); | ||
const arrayInstrumentations = {}; | ||
['includes', 'indexOf', 'lastIndexOf'].forEach(key => { | ||
const method = Array.prototype[key]; | ||
arrayInstrumentations[key] = function (...args) { | ||
const arr = toRaw(this); | ||
for (let i = 0, l = this.length; i < l; i++) { | ||
track(arr, "get" /* GET */, i + ''); | ||
} | ||
// we run the method using the original args first (which may be reactive) | ||
const res = method.apply(arr, args); | ||
if (res === -1 || res === false) { | ||
// if that didn't work, run it again using raw values. | ||
return method.apply(arr, args.map(toRaw)); | ||
} | ||
else { | ||
return res; | ||
} | ||
}; | ||
}); | ||
['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => { | ||
const method = Array.prototype[key]; | ||
arrayInstrumentations[key] = function (...args) { | ||
pauseTracking(); | ||
const res = method.apply(this, args); | ||
resetTracking(); | ||
return res; | ||
}; | ||
}); | ||
function createGetter(isReadonly = false, shallow = false) { | ||
return function get(target, key, receiver) { | ||
if (key === "__v_isReactive" /* IS_REACTIVE */) { | ||
return !isReadonly; | ||
} | ||
else if (key === "__v_isReadonly" /* IS_READONLY */) { | ||
return isReadonly; | ||
} | ||
else if (key === "__v_raw" /* RAW */ && | ||
receiver === | ||
(isReadonly | ||
? shallow | ||
? shallowReadonlyMap | ||
: readonlyMap | ||
: shallow | ||
? shallowReactiveMap | ||
: reactiveMap).get(target)) { | ||
return target; | ||
} | ||
const targetIsArray = isArray(target); | ||
if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) { | ||
return Reflect.get(arrayInstrumentations, key, receiver); | ||
} | ||
const res = Reflect.get(target, key, receiver); | ||
if (isSymbol(key) | ||
? builtInSymbols.has(key) | ||
: isNonTrackableKeys(key)) { | ||
return res; | ||
} | ||
if (!isReadonly) { | ||
track(target, "get" /* GET */, key); | ||
} | ||
if (shallow) { | ||
return res; | ||
} | ||
if (isRef(res)) { | ||
// ref unwrapping - does not apply for Array + integer key. | ||
const shouldUnwrap = !targetIsArray || !isIntegerKey(key); | ||
return shouldUnwrap ? res.value : res; | ||
} | ||
if (isObject(res)) { | ||
// Convert returned value into a proxy as well. we do the isObject check | ||
// here to avoid invalid value warning. Also need to lazy access readonly | ||
// and reactive here to avoid circular dependency. | ||
return isReadonly ? readonly(res) : reactive(res); | ||
} | ||
return res; | ||
}; | ||
} | ||
const set = /*#__PURE__*/ createSetter(); | ||
const shallowSet = /*#__PURE__*/ createSetter(true); | ||
function createSetter(shallow = false) { | ||
return function set(target, key, value, receiver) { | ||
let oldValue = target[key]; | ||
if (!shallow) { | ||
value = toRaw(value); | ||
oldValue = toRaw(oldValue); | ||
if (!isArray(target) && isRef(oldValue) && !isRef(value)) { | ||
oldValue.value = value; | ||
return true; | ||
} | ||
} | ||
const hadKey = isArray(target) && isIntegerKey(key) | ||
? Number(key) < target.length | ||
: hasOwn(target, key); | ||
const result = Reflect.set(target, key, value, receiver); | ||
// don't trigger if target is something up in the prototype chain of original | ||
if (target === toRaw(receiver)) { | ||
if (!hadKey) { | ||
trigger(target, "add" /* ADD */, key, value); | ||
} | ||
else if (hasChanged(value, oldValue)) { | ||
trigger(target, "set" /* SET */, key, value, oldValue); | ||
} | ||
} | ||
return result; | ||
}; | ||
} | ||
function deleteProperty(target, key) { | ||
const hadKey = hasOwn(target, key); | ||
const oldValue = target[key]; | ||
const result = Reflect.deleteProperty(target, key); | ||
if (result && hadKey) { | ||
trigger(target, "delete" /* DELETE */, key, undefined, oldValue); | ||
} | ||
return result; | ||
} | ||
function has(target, key) { | ||
const result = Reflect.has(target, key); | ||
if (!isSymbol(key) || !builtInSymbols.has(key)) { | ||
track(target, "has" /* HAS */, key); | ||
} | ||
return result; | ||
} | ||
function ownKeys(target) { | ||
track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY); | ||
return Reflect.ownKeys(target); | ||
} | ||
const mutableHandlers = { | ||
get, | ||
set, | ||
deleteProperty, | ||
has, | ||
ownKeys | ||
}; | ||
const readonlyHandlers = { | ||
get: readonlyGet, | ||
set(target, key) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
}, | ||
deleteProperty(target, key) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
} | ||
}; | ||
const shallowReactiveHandlers = extend({}, mutableHandlers, { | ||
get: shallowGet, | ||
set: shallowSet | ||
}); | ||
// Props handlers are special in the sense that it should not unwrap top-level | ||
// refs (in order to allow refs to be explicitly passed down), but should | ||
// retain the reactivity of the normal readonly object. | ||
const shallowReadonlyHandlers = extend({}, readonlyHandlers, { | ||
get: shallowReadonlyGet | ||
}); | ||
const toReactive = (value) => isObject(value) ? reactive(value) : value; | ||
const toReadonly = (value) => isObject(value) ? readonly(value) : value; | ||
const toShallow = (value) => value; | ||
const getProto = (v) => Reflect.getPrototypeOf(v); | ||
function get$1(target, key, isReadonly = false, isShallow = false) { | ||
// #1772: readonly(reactive(Map)) should return readonly + reactive version | ||
// of the value | ||
target = target["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (key !== rawKey) { | ||
!isReadonly && track(rawTarget, "get" /* GET */, key); | ||
} | ||
!isReadonly && track(rawTarget, "get" /* GET */, rawKey); | ||
const { has } = getProto(rawTarget); | ||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; | ||
if (has.call(rawTarget, key)) { | ||
return wrap(target.get(key)); | ||
} | ||
else if (has.call(rawTarget, rawKey)) { | ||
return wrap(target.get(rawKey)); | ||
} | ||
} | ||
function has$1(key, isReadonly = false) { | ||
const target = this["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (key !== rawKey) { | ||
!isReadonly && track(rawTarget, "has" /* HAS */, key); | ||
} | ||
!isReadonly && track(rawTarget, "has" /* HAS */, rawKey); | ||
return key === rawKey | ||
? target.has(key) | ||
: target.has(key) || target.has(rawKey); | ||
} | ||
function size(target, isReadonly = false) { | ||
target = target["__v_raw" /* RAW */]; | ||
!isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY); | ||
return Reflect.get(target, 'size', target); | ||
} | ||
function add(value) { | ||
value = toRaw(value); | ||
const target = toRaw(this); | ||
const proto = getProto(target); | ||
const hadKey = proto.has.call(target, value); | ||
if (!hadKey) { | ||
target.add(value); | ||
trigger(target, "add" /* ADD */, value, value); | ||
} | ||
return this; | ||
} | ||
function set$1(key, value) { | ||
value = toRaw(value); | ||
const target = toRaw(this); | ||
const { has, get } = getProto(target); | ||
let hadKey = has.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has.call(target, key); | ||
} | ||
else if ((process.env.NODE_ENV !== 'production')) { | ||
checkIdentityKeys(target, has, key); | ||
} | ||
const oldValue = get.call(target, key); | ||
target.set(key, value); | ||
if (!hadKey) { | ||
trigger(target, "add" /* ADD */, key, value); | ||
} | ||
else if (hasChanged(value, oldValue)) { | ||
trigger(target, "set" /* SET */, key, value, oldValue); | ||
} | ||
return this; | ||
} | ||
function deleteEntry(key) { | ||
const target = toRaw(this); | ||
const { has, get } = getProto(target); | ||
let hadKey = has.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has.call(target, key); | ||
} | ||
else if ((process.env.NODE_ENV !== 'production')) { | ||
checkIdentityKeys(target, has, key); | ||
} | ||
const oldValue = get ? get.call(target, key) : undefined; | ||
// forward the operation before queueing reactions | ||
const result = target.delete(key); | ||
if (hadKey) { | ||
trigger(target, "delete" /* DELETE */, key, undefined, oldValue); | ||
} | ||
return result; | ||
} | ||
function clear() { | ||
const target = toRaw(this); | ||
const hadItems = target.size !== 0; | ||
const oldTarget = (process.env.NODE_ENV !== 'production') | ||
? isMap(target) | ||
? new Map(target) | ||
: new Set(target) | ||
: undefined; | ||
// forward the operation before queueing reactions | ||
const result = target.clear(); | ||
if (hadItems) { | ||
trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget); | ||
} | ||
return result; | ||
} | ||
function createForEach(isReadonly, isShallow) { | ||
return function forEach(callback, thisArg) { | ||
const observed = this; | ||
const target = observed["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; | ||
!isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY); | ||
return target.forEach((value, key) => { | ||
// important: make sure the callback is | ||
// 1. invoked with the reactive map as `this` and 3rd arg | ||
// 2. the value received should be a corresponding reactive/readonly. | ||
return callback.call(thisArg, wrap(value), wrap(key), observed); | ||
}); | ||
}; | ||
} | ||
function createIterableMethod(method, isReadonly, isShallow) { | ||
return function (...args) { | ||
const target = this["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const targetIsMap = isMap(rawTarget); | ||
const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap); | ||
const isKeyOnly = method === 'keys' && targetIsMap; | ||
const innerIterator = target[method](...args); | ||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; | ||
!isReadonly && | ||
track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
// return a wrapped iterator which returns observed versions of the | ||
// values emitted from the real iterator | ||
return { | ||
// iterator protocol | ||
next() { | ||
const { value, done } = innerIterator.next(); | ||
return done | ||
? { value, done } | ||
: { | ||
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value), | ||
done | ||
}; | ||
}, | ||
// iterable protocol | ||
[Symbol.iterator]() { | ||
return this; | ||
} | ||
}; | ||
}; | ||
} | ||
function createReadonlyMethod(type) { | ||
return function (...args) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
}; | ||
} | ||
const mutableInstrumentations = { | ||
get(key) { | ||
return get$1(this, key); | ||
}, | ||
get size() { | ||
return size(this); | ||
}, | ||
has: has$1, | ||
add, | ||
set: set$1, | ||
delete: deleteEntry, | ||
clear, | ||
forEach: createForEach(false, false) | ||
}; | ||
const shallowInstrumentations = { | ||
get(key) { | ||
return get$1(this, key, false, true); | ||
}, | ||
get size() { | ||
return size(this); | ||
}, | ||
has: has$1, | ||
add, | ||
set: set$1, | ||
delete: deleteEntry, | ||
clear, | ||
forEach: createForEach(false, true) | ||
}; | ||
const readonlyInstrumentations = { | ||
get(key) { | ||
return get$1(this, key, true); | ||
}, | ||
get size() { | ||
return size(this, true); | ||
}, | ||
has(key) { | ||
return has$1.call(this, key, true); | ||
}, | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true, false) | ||
}; | ||
const shallowReadonlyInstrumentations = { | ||
get(key) { | ||
return get$1(this, key, true, true); | ||
}, | ||
get size() { | ||
return size(this, true); | ||
}, | ||
has(key) { | ||
return has$1.call(this, key, true); | ||
}, | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true, true) | ||
}; | ||
const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator]; | ||
iteratorMethods.forEach(method => { | ||
mutableInstrumentations[method] = createIterableMethod(method, false, false); | ||
readonlyInstrumentations[method] = createIterableMethod(method, true, false); | ||
shallowInstrumentations[method] = createIterableMethod(method, false, true); | ||
shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true); | ||
}); | ||
function createInstrumentationGetter(isReadonly, shallow) { | ||
const instrumentations = shallow | ||
? isReadonly | ||
? shallowReadonlyInstrumentations | ||
: shallowInstrumentations | ||
: isReadonly | ||
? readonlyInstrumentations | ||
: mutableInstrumentations; | ||
return (target, key, receiver) => { | ||
if (key === "__v_isReactive" /* IS_REACTIVE */) { | ||
return !isReadonly; | ||
} | ||
else if (key === "__v_isReadonly" /* IS_READONLY */) { | ||
return isReadonly; | ||
} | ||
else if (key === "__v_raw" /* RAW */) { | ||
return target; | ||
} | ||
return Reflect.get(hasOwn(instrumentations, key) && key in target | ||
? instrumentations | ||
: target, key, receiver); | ||
}; | ||
} | ||
const mutableCollectionHandlers = { | ||
get: createInstrumentationGetter(false, false) | ||
}; | ||
const shallowCollectionHandlers = { | ||
get: createInstrumentationGetter(false, true) | ||
}; | ||
const readonlyCollectionHandlers = { | ||
get: createInstrumentationGetter(true, false) | ||
}; | ||
const shallowReadonlyCollectionHandlers = { | ||
get: createInstrumentationGetter(true, true) | ||
}; | ||
function checkIdentityKeys(target, has, key) { | ||
const rawKey = toRaw(key); | ||
if (rawKey !== key && has.call(target, rawKey)) { | ||
const type = toRawType(target); | ||
console.warn(`Reactive ${type} contains both the raw and reactive ` + | ||
`versions of the same object${type === `Map` ? ` as keys` : ``}, ` + | ||
`which can lead to inconsistencies. ` + | ||
`Avoid differentiating between the raw and reactive versions ` + | ||
`of an object and only use the reactive version if possible.`); | ||
} | ||
} | ||
const reactiveMap = new WeakMap(); | ||
const shallowReactiveMap = new WeakMap(); | ||
const readonlyMap = new WeakMap(); | ||
const shallowReadonlyMap = new WeakMap(); | ||
function targetTypeMap(rawType) { | ||
switch (rawType) { | ||
case 'Object': | ||
case 'Array': | ||
return 1 /* COMMON */; | ||
case 'Map': | ||
case 'Set': | ||
case 'WeakMap': | ||
case 'WeakSet': | ||
return 2 /* COLLECTION */; | ||
default: | ||
return 0 /* INVALID */; | ||
} | ||
} | ||
function getTargetType(value) { | ||
return value["__v_skip" /* SKIP */] || !Object.isExtensible(value) | ||
? 0 /* INVALID */ | ||
: targetTypeMap(toRawType(value)); | ||
} | ||
function reactive(target) { | ||
// if trying to observe a readonly proxy, return the readonly version. | ||
if (target && target["__v_isReadonly" /* IS_READONLY */]) { | ||
return target; | ||
} | ||
return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap); | ||
} | ||
/** | ||
* Return a shallowly-reactive copy of the original object, where only the root | ||
* level properties are reactive. It also does not auto-unwrap refs (even at the | ||
* root level). | ||
*/ | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap); | ||
} | ||
/** | ||
* Creates a readonly copy of the original object. Note the returned copy is not | ||
* made reactive, but `readonly` can be called on an already reactive object. | ||
*/ | ||
function readonly(target) { | ||
return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap); | ||
} | ||
/** | ||
* Returns a reactive-copy of the original object, where only the root level | ||
* properties are readonly, and does NOT unwrap refs nor recursively convert | ||
* returned properties. | ||
* This is used for creating the props proxy object for stateful components. | ||
*/ | ||
function shallowReadonly(target) { | ||
return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap); | ||
} | ||
function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) { | ||
if (!isObject(target)) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`value cannot be made reactive: ${String(target)}`); | ||
} | ||
return target; | ||
} | ||
// target is already a Proxy, return it. | ||
// exception: calling readonly() on a reactive object | ||
if (target["__v_raw" /* RAW */] && | ||
!(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) { | ||
return target; | ||
} | ||
// target already has corresponding Proxy | ||
const existingProxy = proxyMap.get(target); | ||
if (existingProxy) { | ||
return existingProxy; | ||
} | ||
// only a whitelist of value types can be observed. | ||
const targetType = getTargetType(target); | ||
if (targetType === 0 /* INVALID */) { | ||
return target; | ||
} | ||
const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers); | ||
proxyMap.set(target, proxy); | ||
return proxy; | ||
} | ||
function isReactive(value) { | ||
if (isReadonly(value)) { | ||
return isReactive(value["__v_raw" /* RAW */]); | ||
} | ||
return !!(value && value["__v_isReactive" /* IS_REACTIVE */]); | ||
} | ||
function isReadonly(value) { | ||
return !!(value && value["__v_isReadonly" /* IS_READONLY */]); | ||
} | ||
function isProxy(value) { | ||
return isReactive(value) || isReadonly(value); | ||
} | ||
function toRaw(observed) { | ||
return ((observed && toRaw(observed["__v_raw" /* RAW */])) || observed); | ||
} | ||
function markRaw(value) { | ||
def(value, "__v_skip" /* SKIP */, true); | ||
return value; | ||
} | ||
const convert = (val) => isObject(val) ? reactive(val) : val; | ||
function isRef(r) { | ||
return Boolean(r && r.__v_isRef === true); | ||
} | ||
function ref(value) { | ||
return createRef(value); | ||
} | ||
function shallowRef(value) { | ||
return createRef(value, true); | ||
} | ||
class RefImpl { | ||
constructor(_rawValue, _shallow = false) { | ||
this._rawValue = _rawValue; | ||
this._shallow = _shallow; | ||
this.__v_isRef = true; | ||
this._value = _shallow ? _rawValue : convert(_rawValue); | ||
} | ||
get value() { | ||
track(toRaw(this), "get" /* GET */, 'value'); | ||
return this._value; | ||
} | ||
set value(newVal) { | ||
if (hasChanged(toRaw(newVal), this._rawValue)) { | ||
this._rawValue = newVal; | ||
this._value = this._shallow ? newVal : convert(newVal); | ||
trigger(toRaw(this), "set" /* SET */, 'value', newVal); | ||
} | ||
} | ||
} | ||
function createRef(rawValue, shallow = false) { | ||
if (isRef(rawValue)) { | ||
return rawValue; | ||
} | ||
return new RefImpl(rawValue, shallow); | ||
} | ||
function triggerRef(ref) { | ||
trigger(toRaw(ref), "set" /* SET */, 'value', (process.env.NODE_ENV !== 'production') ? ref.value : void 0); | ||
} | ||
function unref(ref) { | ||
return isRef(ref) ? ref.value : ref; | ||
} | ||
const shallowUnwrapHandlers = { | ||
get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)), | ||
set: (target, key, value, receiver) => { | ||
const oldValue = target[key]; | ||
if (isRef(oldValue) && !isRef(value)) { | ||
oldValue.value = value; | ||
return true; | ||
} | ||
else { | ||
return Reflect.set(target, key, value, receiver); | ||
} | ||
} | ||
}; | ||
function proxyRefs(objectWithRefs) { | ||
return isReactive(objectWithRefs) | ||
? objectWithRefs | ||
: new Proxy(objectWithRefs, shallowUnwrapHandlers); | ||
} | ||
class CustomRefImpl { | ||
constructor(factory) { | ||
this.__v_isRef = true; | ||
const { get, set } = factory(() => track(this, "get" /* GET */, 'value'), () => trigger(this, "set" /* SET */, 'value')); | ||
this._get = get; | ||
this._set = set; | ||
} | ||
get value() { | ||
return this._get(); | ||
} | ||
set value(newVal) { | ||
this._set(newVal); | ||
} | ||
} | ||
function customRef(factory) { | ||
return new CustomRefImpl(factory); | ||
} | ||
function toRefs(object) { | ||
if ((process.env.NODE_ENV !== 'production') && !isProxy(object)) { | ||
console.warn(`toRefs() expects a reactive object but received a plain one.`); | ||
} | ||
const ret = isArray(object) ? new Array(object.length) : {}; | ||
for (const key in object) { | ||
ret[key] = toRef(object, key); | ||
} | ||
return ret; | ||
} | ||
class ObjectRefImpl { | ||
constructor(_object, _key) { | ||
this._object = _object; | ||
this._key = _key; | ||
this.__v_isRef = true; | ||
} | ||
get value() { | ||
return this._object[this._key]; | ||
} | ||
set value(newVal) { | ||
this._object[this._key] = newVal; | ||
} | ||
} | ||
function toRef(object, key) { | ||
return isRef(object[key]) | ||
? object[key] | ||
: new ObjectRefImpl(object, key); | ||
} | ||
class ComputedRefImpl { | ||
constructor(getter, _setter, isReadonly) { | ||
this._setter = _setter; | ||
this._dirty = true; | ||
this.__v_isRef = true; | ||
this.effect = effect(getter, { | ||
lazy: true, | ||
scheduler: () => { | ||
if (!this._dirty) { | ||
this._dirty = true; | ||
trigger(toRaw(this), "set" /* SET */, 'value'); | ||
} | ||
} | ||
}); | ||
this["__v_isReadonly" /* IS_READONLY */] = isReadonly; | ||
} | ||
get value() { | ||
// the computed ref may get wrapped by other proxies e.g. readonly() #3376 | ||
const self = toRaw(this); | ||
if (self._dirty) { | ||
self._value = this.effect(); | ||
self._dirty = false; | ||
} | ||
track(self, "get" /* GET */, 'value'); | ||
return self._value; | ||
} | ||
set value(newValue) { | ||
this._setter(newValue); | ||
} | ||
} | ||
function computed(getterOrOptions) { | ||
let getter; | ||
let setter; | ||
if (isFunction(getterOrOptions)) { | ||
getter = getterOrOptions; | ||
setter = (process.env.NODE_ENV !== 'production') | ||
? () => { | ||
console.warn('Write operation failed: computed value is readonly'); | ||
} | ||
: NOOP; | ||
} | ||
else { | ||
getter = getterOrOptions.get; | ||
setter = getterOrOptions.set; | ||
} | ||
return new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set); | ||
} | ||
var reactivity_esmBundler = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
ITERATE_KEY: ITERATE_KEY, | ||
computed: computed, | ||
customRef: customRef, | ||
effect: effect, | ||
enableTracking: enableTracking, | ||
isProxy: isProxy, | ||
isReactive: isReactive, | ||
isReadonly: isReadonly, | ||
isRef: isRef, | ||
markRaw: markRaw, | ||
pauseTracking: pauseTracking, | ||
proxyRefs: proxyRefs, | ||
reactive: reactive, | ||
readonly: readonly, | ||
ref: ref, | ||
resetTracking: resetTracking, | ||
shallowReactive: shallowReactive, | ||
shallowReadonly: shallowReadonly, | ||
shallowRef: shallowRef, | ||
stop: stop, | ||
toRaw: toRaw, | ||
toRef: toRef, | ||
toRefs: toRefs, | ||
track: track, | ||
trigger: trigger, | ||
triggerRef: triggerRef, | ||
unref: unref | ||
}); | ||
module.exports = index; |
/*! | ||
* vue-keycloak-js v2.1.3-beta | ||
* vue-keycloak-js v2.0.0-beta | ||
* @license ISC | ||
*/ | ||
import Keycloak from 'keycloak-js'; | ||
import * as vue from 'vue'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
let installed = false; | ||
const KeycloakSymbol = Symbol('keycloak'); | ||
var index = { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
install: function (app, params = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (installed) | ||
return; | ||
installed = true; | ||
const defaultParams = { | ||
config: window.__BASEURL__ ? `${window.__BASEURL__}/config` : '/config', | ||
init: { onLoad: 'login-required' }, | ||
}; | ||
const options = Object.assign({}, defaultParams, params); | ||
if (assertOptions(options).hasError) | ||
throw new Error(`Invalid options given: ${assertOptions(options).error}`); | ||
const watch = yield vue2AndVue3Reactive(app, defaultEmptyVueKeycloakInstance()); | ||
if (installed) | ||
return; | ||
installed = true; | ||
const defaultParams = { | ||
config: window.__BASEURL__ ? `${window.__BASEURL__}/config` : '/config', | ||
init: { onLoad: 'login-required' }, | ||
}; | ||
const options = Object.assign({}, defaultParams, params); | ||
if (assertOptions(options).hasError) | ||
throw new Error(`Invalid options given: ${assertOptions(options).error}`); | ||
vue2AndVue3Reactive(app, defaultEmptyVueKeycloakInstance()).then((watch) => { | ||
getConfig(options.config) | ||
@@ -59,3 +31,2 @@ .then((config) => { | ||
}, | ||
KeycloakSymbol | ||
}; | ||
@@ -115,10 +86,12 @@ function defaultEmptyVueKeycloakInstance() { | ||
// Assign an object immediately to allow usage of $keycloak in view | ||
//const vue = await import('vue') | ||
const reactiveObj = defaultEmptyVueKeycloakInstance(); | ||
app.config.globalProperties.$keycloak = reactiveObj; | ||
// Async load module to allow vue 2 to not have the dependency. | ||
const reactiveObj = vue.reactive(object); | ||
// Override the existing reactiveObj so references contains the new reactive values | ||
app.config.globalProperties.$keycloak = reactiveObj; | ||
// Use provide/inject in Vue3 apps | ||
app.provide(KeycloakSymbol, reactiveObj); | ||
resolve(reactiveObj); | ||
Promise.resolve().then(function () { return reactivity_esmBundler; }).then((reactivity) => { | ||
// Override the existing reactiveObj so references contains the new reactive values | ||
Object.assign(reactiveObj, reactivity.reactive(object)); | ||
resolve(reactiveObj); | ||
}).catch(e => { | ||
reject(e); | ||
}); | ||
} | ||
@@ -147,4 +120,2 @@ }); | ||
updateWatchVariables(true); | ||
typeof options.onAuthRefreshSuccess === 'function' && | ||
options.onAuthRefreshSuccess(keycloak); | ||
}; | ||
@@ -165,3 +136,3 @@ keycloak.onAuthRefreshError = function () { | ||
updateWatchVariables(false); | ||
const error = Error('Failure during initialization of keycloak-js adapter'); | ||
const error = Error('Could not initialized keycloak-js adapter'); | ||
typeof options.onInitError === 'function' | ||
@@ -266,2 +237,979 @@ ? options.onInitError(error, err) | ||
/** | ||
* Make a map and return a function for checking if a key | ||
* is in that map. | ||
* IMPORTANT: all calls of this function must be prefixed with | ||
* \/\*#\_\_PURE\_\_\*\/ | ||
* So that rollup can tree-shake them if necessary. | ||
*/ | ||
function makeMap(str, expectsLowerCase) { | ||
const map = Object.create(null); | ||
const list = str.split(','); | ||
for (let i = 0; i < list.length; i++) { | ||
map[list[i]] = true; | ||
} | ||
return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]; | ||
} | ||
const EMPTY_OBJ = (process.env.NODE_ENV !== 'production') | ||
? Object.freeze({}) | ||
: {}; | ||
(process.env.NODE_ENV !== 'production') ? Object.freeze([]) : []; | ||
const NOOP = () => { }; | ||
const extend = Object.assign; | ||
const hasOwnProperty = Object.prototype.hasOwnProperty; | ||
const hasOwn = (val, key) => hasOwnProperty.call(val, key); | ||
const isArray = Array.isArray; | ||
const isMap = (val) => toTypeString(val) === '[object Map]'; | ||
const isFunction = (val) => typeof val === 'function'; | ||
const isString = (val) => typeof val === 'string'; | ||
const isSymbol = (val) => typeof val === 'symbol'; | ||
const isObject = (val) => val !== null && typeof val === 'object'; | ||
const objectToString = Object.prototype.toString; | ||
const toTypeString = (value) => objectToString.call(value); | ||
const toRawType = (value) => { | ||
// extract "RawType" from strings like "[object RawType]" | ||
return toTypeString(value).slice(8, -1); | ||
}; | ||
const isIntegerKey = (key) => isString(key) && | ||
key !== 'NaN' && | ||
key[0] !== '-' && | ||
'' + parseInt(key, 10) === key; | ||
const cacheStringFunction = (fn) => { | ||
const cache = Object.create(null); | ||
return ((str) => { | ||
const hit = cache[str]; | ||
return hit || (cache[str] = fn(str)); | ||
}); | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1)); | ||
// compare whether a value has changed, accounting for NaN. | ||
const hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue); | ||
const def = (obj, key, value) => { | ||
Object.defineProperty(obj, key, { | ||
configurable: true, | ||
enumerable: false, | ||
value | ||
}); | ||
}; | ||
const targetMap = new WeakMap(); | ||
const effectStack = []; | ||
let activeEffect; | ||
const ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'iterate' : ''); | ||
const MAP_KEY_ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'Map key iterate' : ''); | ||
function isEffect(fn) { | ||
return fn && fn._isEffect === true; | ||
} | ||
function effect(fn, options = EMPTY_OBJ) { | ||
if (isEffect(fn)) { | ||
fn = fn.raw; | ||
} | ||
const effect = createReactiveEffect(fn, options); | ||
if (!options.lazy) { | ||
effect(); | ||
} | ||
return effect; | ||
} | ||
function stop(effect) { | ||
if (effect.active) { | ||
cleanup(effect); | ||
if (effect.options.onStop) { | ||
effect.options.onStop(); | ||
} | ||
effect.active = false; | ||
} | ||
} | ||
let uid = 0; | ||
function createReactiveEffect(fn, options) { | ||
const effect = function reactiveEffect() { | ||
if (!effect.active) { | ||
return options.scheduler ? undefined : fn(); | ||
} | ||
if (!effectStack.includes(effect)) { | ||
cleanup(effect); | ||
try { | ||
enableTracking(); | ||
effectStack.push(effect); | ||
activeEffect = effect; | ||
return fn(); | ||
} | ||
finally { | ||
effectStack.pop(); | ||
resetTracking(); | ||
activeEffect = effectStack[effectStack.length - 1]; | ||
} | ||
} | ||
}; | ||
effect.id = uid++; | ||
effect.allowRecurse = !!options.allowRecurse; | ||
effect._isEffect = true; | ||
effect.active = true; | ||
effect.raw = fn; | ||
effect.deps = []; | ||
effect.options = options; | ||
return effect; | ||
} | ||
function cleanup(effect) { | ||
const { deps } = effect; | ||
if (deps.length) { | ||
for (let i = 0; i < deps.length; i++) { | ||
deps[i].delete(effect); | ||
} | ||
deps.length = 0; | ||
} | ||
} | ||
let shouldTrack = true; | ||
const trackStack = []; | ||
function pauseTracking() { | ||
trackStack.push(shouldTrack); | ||
shouldTrack = false; | ||
} | ||
function enableTracking() { | ||
trackStack.push(shouldTrack); | ||
shouldTrack = true; | ||
} | ||
function resetTracking() { | ||
const last = trackStack.pop(); | ||
shouldTrack = last === undefined ? true : last; | ||
} | ||
function track(target, type, key) { | ||
if (!shouldTrack || activeEffect === undefined) { | ||
return; | ||
} | ||
let depsMap = targetMap.get(target); | ||
if (!depsMap) { | ||
targetMap.set(target, (depsMap = new Map())); | ||
} | ||
let dep = depsMap.get(key); | ||
if (!dep) { | ||
depsMap.set(key, (dep = new Set())); | ||
} | ||
if (!dep.has(activeEffect)) { | ||
dep.add(activeEffect); | ||
activeEffect.deps.push(dep); | ||
if ((process.env.NODE_ENV !== 'production') && activeEffect.options.onTrack) { | ||
activeEffect.options.onTrack({ | ||
effect: activeEffect, | ||
target, | ||
type, | ||
key | ||
}); | ||
} | ||
} | ||
} | ||
function trigger(target, type, key, newValue, oldValue, oldTarget) { | ||
const depsMap = targetMap.get(target); | ||
if (!depsMap) { | ||
// never been tracked | ||
return; | ||
} | ||
const effects = new Set(); | ||
const add = (effectsToAdd) => { | ||
if (effectsToAdd) { | ||
effectsToAdd.forEach(effect => { | ||
if (effect !== activeEffect || effect.allowRecurse) { | ||
effects.add(effect); | ||
} | ||
}); | ||
} | ||
}; | ||
if (type === "clear" /* CLEAR */) { | ||
// collection being cleared | ||
// trigger all effects for target | ||
depsMap.forEach(add); | ||
} | ||
else if (key === 'length' && isArray(target)) { | ||
depsMap.forEach((dep, key) => { | ||
if (key === 'length' || key >= newValue) { | ||
add(dep); | ||
} | ||
}); | ||
} | ||
else { | ||
// schedule runs for SET | ADD | DELETE | ||
if (key !== void 0) { | ||
add(depsMap.get(key)); | ||
} | ||
// also run for iteration key on ADD | DELETE | Map.SET | ||
switch (type) { | ||
case "add" /* ADD */: | ||
if (!isArray(target)) { | ||
add(depsMap.get(ITERATE_KEY)); | ||
if (isMap(target)) { | ||
add(depsMap.get(MAP_KEY_ITERATE_KEY)); | ||
} | ||
} | ||
else if (isIntegerKey(key)) { | ||
// new index added to array -> length changes | ||
add(depsMap.get('length')); | ||
} | ||
break; | ||
case "delete" /* DELETE */: | ||
if (!isArray(target)) { | ||
add(depsMap.get(ITERATE_KEY)); | ||
if (isMap(target)) { | ||
add(depsMap.get(MAP_KEY_ITERATE_KEY)); | ||
} | ||
} | ||
break; | ||
case "set" /* SET */: | ||
if (isMap(target)) { | ||
add(depsMap.get(ITERATE_KEY)); | ||
} | ||
break; | ||
} | ||
} | ||
const run = (effect) => { | ||
if ((process.env.NODE_ENV !== 'production') && effect.options.onTrigger) { | ||
effect.options.onTrigger({ | ||
effect, | ||
target, | ||
key, | ||
type, | ||
newValue, | ||
oldValue, | ||
oldTarget | ||
}); | ||
} | ||
if (effect.options.scheduler) { | ||
effect.options.scheduler(effect); | ||
} | ||
else { | ||
effect(); | ||
} | ||
}; | ||
effects.forEach(run); | ||
} | ||
const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`); | ||
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol) | ||
.map(key => Symbol[key]) | ||
.filter(isSymbol)); | ||
const get = /*#__PURE__*/ createGetter(); | ||
const shallowGet = /*#__PURE__*/ createGetter(false, true); | ||
const readonlyGet = /*#__PURE__*/ createGetter(true); | ||
const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true); | ||
const arrayInstrumentations = {}; | ||
['includes', 'indexOf', 'lastIndexOf'].forEach(key => { | ||
const method = Array.prototype[key]; | ||
arrayInstrumentations[key] = function (...args) { | ||
const arr = toRaw(this); | ||
for (let i = 0, l = this.length; i < l; i++) { | ||
track(arr, "get" /* GET */, i + ''); | ||
} | ||
// we run the method using the original args first (which may be reactive) | ||
const res = method.apply(arr, args); | ||
if (res === -1 || res === false) { | ||
// if that didn't work, run it again using raw values. | ||
return method.apply(arr, args.map(toRaw)); | ||
} | ||
else { | ||
return res; | ||
} | ||
}; | ||
}); | ||
['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => { | ||
const method = Array.prototype[key]; | ||
arrayInstrumentations[key] = function (...args) { | ||
pauseTracking(); | ||
const res = method.apply(this, args); | ||
resetTracking(); | ||
return res; | ||
}; | ||
}); | ||
function createGetter(isReadonly = false, shallow = false) { | ||
return function get(target, key, receiver) { | ||
if (key === "__v_isReactive" /* IS_REACTIVE */) { | ||
return !isReadonly; | ||
} | ||
else if (key === "__v_isReadonly" /* IS_READONLY */) { | ||
return isReadonly; | ||
} | ||
else if (key === "__v_raw" /* RAW */ && | ||
receiver === | ||
(isReadonly | ||
? shallow | ||
? shallowReadonlyMap | ||
: readonlyMap | ||
: shallow | ||
? shallowReactiveMap | ||
: reactiveMap).get(target)) { | ||
return target; | ||
} | ||
const targetIsArray = isArray(target); | ||
if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) { | ||
return Reflect.get(arrayInstrumentations, key, receiver); | ||
} | ||
const res = Reflect.get(target, key, receiver); | ||
if (isSymbol(key) | ||
? builtInSymbols.has(key) | ||
: isNonTrackableKeys(key)) { | ||
return res; | ||
} | ||
if (!isReadonly) { | ||
track(target, "get" /* GET */, key); | ||
} | ||
if (shallow) { | ||
return res; | ||
} | ||
if (isRef(res)) { | ||
// ref unwrapping - does not apply for Array + integer key. | ||
const shouldUnwrap = !targetIsArray || !isIntegerKey(key); | ||
return shouldUnwrap ? res.value : res; | ||
} | ||
if (isObject(res)) { | ||
// Convert returned value into a proxy as well. we do the isObject check | ||
// here to avoid invalid value warning. Also need to lazy access readonly | ||
// and reactive here to avoid circular dependency. | ||
return isReadonly ? readonly(res) : reactive(res); | ||
} | ||
return res; | ||
}; | ||
} | ||
const set = /*#__PURE__*/ createSetter(); | ||
const shallowSet = /*#__PURE__*/ createSetter(true); | ||
function createSetter(shallow = false) { | ||
return function set(target, key, value, receiver) { | ||
let oldValue = target[key]; | ||
if (!shallow) { | ||
value = toRaw(value); | ||
oldValue = toRaw(oldValue); | ||
if (!isArray(target) && isRef(oldValue) && !isRef(value)) { | ||
oldValue.value = value; | ||
return true; | ||
} | ||
} | ||
const hadKey = isArray(target) && isIntegerKey(key) | ||
? Number(key) < target.length | ||
: hasOwn(target, key); | ||
const result = Reflect.set(target, key, value, receiver); | ||
// don't trigger if target is something up in the prototype chain of original | ||
if (target === toRaw(receiver)) { | ||
if (!hadKey) { | ||
trigger(target, "add" /* ADD */, key, value); | ||
} | ||
else if (hasChanged(value, oldValue)) { | ||
trigger(target, "set" /* SET */, key, value, oldValue); | ||
} | ||
} | ||
return result; | ||
}; | ||
} | ||
function deleteProperty(target, key) { | ||
const hadKey = hasOwn(target, key); | ||
const oldValue = target[key]; | ||
const result = Reflect.deleteProperty(target, key); | ||
if (result && hadKey) { | ||
trigger(target, "delete" /* DELETE */, key, undefined, oldValue); | ||
} | ||
return result; | ||
} | ||
function has(target, key) { | ||
const result = Reflect.has(target, key); | ||
if (!isSymbol(key) || !builtInSymbols.has(key)) { | ||
track(target, "has" /* HAS */, key); | ||
} | ||
return result; | ||
} | ||
function ownKeys(target) { | ||
track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY); | ||
return Reflect.ownKeys(target); | ||
} | ||
const mutableHandlers = { | ||
get, | ||
set, | ||
deleteProperty, | ||
has, | ||
ownKeys | ||
}; | ||
const readonlyHandlers = { | ||
get: readonlyGet, | ||
set(target, key) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
}, | ||
deleteProperty(target, key) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
} | ||
}; | ||
const shallowReactiveHandlers = extend({}, mutableHandlers, { | ||
get: shallowGet, | ||
set: shallowSet | ||
}); | ||
// Props handlers are special in the sense that it should not unwrap top-level | ||
// refs (in order to allow refs to be explicitly passed down), but should | ||
// retain the reactivity of the normal readonly object. | ||
const shallowReadonlyHandlers = extend({}, readonlyHandlers, { | ||
get: shallowReadonlyGet | ||
}); | ||
const toReactive = (value) => isObject(value) ? reactive(value) : value; | ||
const toReadonly = (value) => isObject(value) ? readonly(value) : value; | ||
const toShallow = (value) => value; | ||
const getProto = (v) => Reflect.getPrototypeOf(v); | ||
function get$1(target, key, isReadonly = false, isShallow = false) { | ||
// #1772: readonly(reactive(Map)) should return readonly + reactive version | ||
// of the value | ||
target = target["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (key !== rawKey) { | ||
!isReadonly && track(rawTarget, "get" /* GET */, key); | ||
} | ||
!isReadonly && track(rawTarget, "get" /* GET */, rawKey); | ||
const { has } = getProto(rawTarget); | ||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; | ||
if (has.call(rawTarget, key)) { | ||
return wrap(target.get(key)); | ||
} | ||
else if (has.call(rawTarget, rawKey)) { | ||
return wrap(target.get(rawKey)); | ||
} | ||
} | ||
function has$1(key, isReadonly = false) { | ||
const target = this["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (key !== rawKey) { | ||
!isReadonly && track(rawTarget, "has" /* HAS */, key); | ||
} | ||
!isReadonly && track(rawTarget, "has" /* HAS */, rawKey); | ||
return key === rawKey | ||
? target.has(key) | ||
: target.has(key) || target.has(rawKey); | ||
} | ||
function size(target, isReadonly = false) { | ||
target = target["__v_raw" /* RAW */]; | ||
!isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY); | ||
return Reflect.get(target, 'size', target); | ||
} | ||
function add(value) { | ||
value = toRaw(value); | ||
const target = toRaw(this); | ||
const proto = getProto(target); | ||
const hadKey = proto.has.call(target, value); | ||
if (!hadKey) { | ||
target.add(value); | ||
trigger(target, "add" /* ADD */, value, value); | ||
} | ||
return this; | ||
} | ||
function set$1(key, value) { | ||
value = toRaw(value); | ||
const target = toRaw(this); | ||
const { has, get } = getProto(target); | ||
let hadKey = has.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has.call(target, key); | ||
} | ||
else if ((process.env.NODE_ENV !== 'production')) { | ||
checkIdentityKeys(target, has, key); | ||
} | ||
const oldValue = get.call(target, key); | ||
target.set(key, value); | ||
if (!hadKey) { | ||
trigger(target, "add" /* ADD */, key, value); | ||
} | ||
else if (hasChanged(value, oldValue)) { | ||
trigger(target, "set" /* SET */, key, value, oldValue); | ||
} | ||
return this; | ||
} | ||
function deleteEntry(key) { | ||
const target = toRaw(this); | ||
const { has, get } = getProto(target); | ||
let hadKey = has.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has.call(target, key); | ||
} | ||
else if ((process.env.NODE_ENV !== 'production')) { | ||
checkIdentityKeys(target, has, key); | ||
} | ||
const oldValue = get ? get.call(target, key) : undefined; | ||
// forward the operation before queueing reactions | ||
const result = target.delete(key); | ||
if (hadKey) { | ||
trigger(target, "delete" /* DELETE */, key, undefined, oldValue); | ||
} | ||
return result; | ||
} | ||
function clear() { | ||
const target = toRaw(this); | ||
const hadItems = target.size !== 0; | ||
const oldTarget = (process.env.NODE_ENV !== 'production') | ||
? isMap(target) | ||
? new Map(target) | ||
: new Set(target) | ||
: undefined; | ||
// forward the operation before queueing reactions | ||
const result = target.clear(); | ||
if (hadItems) { | ||
trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget); | ||
} | ||
return result; | ||
} | ||
function createForEach(isReadonly, isShallow) { | ||
return function forEach(callback, thisArg) { | ||
const observed = this; | ||
const target = observed["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; | ||
!isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY); | ||
return target.forEach((value, key) => { | ||
// important: make sure the callback is | ||
// 1. invoked with the reactive map as `this` and 3rd arg | ||
// 2. the value received should be a corresponding reactive/readonly. | ||
return callback.call(thisArg, wrap(value), wrap(key), observed); | ||
}); | ||
}; | ||
} | ||
function createIterableMethod(method, isReadonly, isShallow) { | ||
return function (...args) { | ||
const target = this["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const targetIsMap = isMap(rawTarget); | ||
const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap); | ||
const isKeyOnly = method === 'keys' && targetIsMap; | ||
const innerIterator = target[method](...args); | ||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; | ||
!isReadonly && | ||
track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
// return a wrapped iterator which returns observed versions of the | ||
// values emitted from the real iterator | ||
return { | ||
// iterator protocol | ||
next() { | ||
const { value, done } = innerIterator.next(); | ||
return done | ||
? { value, done } | ||
: { | ||
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value), | ||
done | ||
}; | ||
}, | ||
// iterable protocol | ||
[Symbol.iterator]() { | ||
return this; | ||
} | ||
}; | ||
}; | ||
} | ||
function createReadonlyMethod(type) { | ||
return function (...args) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
}; | ||
} | ||
const mutableInstrumentations = { | ||
get(key) { | ||
return get$1(this, key); | ||
}, | ||
get size() { | ||
return size(this); | ||
}, | ||
has: has$1, | ||
add, | ||
set: set$1, | ||
delete: deleteEntry, | ||
clear, | ||
forEach: createForEach(false, false) | ||
}; | ||
const shallowInstrumentations = { | ||
get(key) { | ||
return get$1(this, key, false, true); | ||
}, | ||
get size() { | ||
return size(this); | ||
}, | ||
has: has$1, | ||
add, | ||
set: set$1, | ||
delete: deleteEntry, | ||
clear, | ||
forEach: createForEach(false, true) | ||
}; | ||
const readonlyInstrumentations = { | ||
get(key) { | ||
return get$1(this, key, true); | ||
}, | ||
get size() { | ||
return size(this, true); | ||
}, | ||
has(key) { | ||
return has$1.call(this, key, true); | ||
}, | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true, false) | ||
}; | ||
const shallowReadonlyInstrumentations = { | ||
get(key) { | ||
return get$1(this, key, true, true); | ||
}, | ||
get size() { | ||
return size(this, true); | ||
}, | ||
has(key) { | ||
return has$1.call(this, key, true); | ||
}, | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true, true) | ||
}; | ||
const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator]; | ||
iteratorMethods.forEach(method => { | ||
mutableInstrumentations[method] = createIterableMethod(method, false, false); | ||
readonlyInstrumentations[method] = createIterableMethod(method, true, false); | ||
shallowInstrumentations[method] = createIterableMethod(method, false, true); | ||
shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true); | ||
}); | ||
function createInstrumentationGetter(isReadonly, shallow) { | ||
const instrumentations = shallow | ||
? isReadonly | ||
? shallowReadonlyInstrumentations | ||
: shallowInstrumentations | ||
: isReadonly | ||
? readonlyInstrumentations | ||
: mutableInstrumentations; | ||
return (target, key, receiver) => { | ||
if (key === "__v_isReactive" /* IS_REACTIVE */) { | ||
return !isReadonly; | ||
} | ||
else if (key === "__v_isReadonly" /* IS_READONLY */) { | ||
return isReadonly; | ||
} | ||
else if (key === "__v_raw" /* RAW */) { | ||
return target; | ||
} | ||
return Reflect.get(hasOwn(instrumentations, key) && key in target | ||
? instrumentations | ||
: target, key, receiver); | ||
}; | ||
} | ||
const mutableCollectionHandlers = { | ||
get: createInstrumentationGetter(false, false) | ||
}; | ||
const shallowCollectionHandlers = { | ||
get: createInstrumentationGetter(false, true) | ||
}; | ||
const readonlyCollectionHandlers = { | ||
get: createInstrumentationGetter(true, false) | ||
}; | ||
const shallowReadonlyCollectionHandlers = { | ||
get: createInstrumentationGetter(true, true) | ||
}; | ||
function checkIdentityKeys(target, has, key) { | ||
const rawKey = toRaw(key); | ||
if (rawKey !== key && has.call(target, rawKey)) { | ||
const type = toRawType(target); | ||
console.warn(`Reactive ${type} contains both the raw and reactive ` + | ||
`versions of the same object${type === `Map` ? ` as keys` : ``}, ` + | ||
`which can lead to inconsistencies. ` + | ||
`Avoid differentiating between the raw and reactive versions ` + | ||
`of an object and only use the reactive version if possible.`); | ||
} | ||
} | ||
const reactiveMap = new WeakMap(); | ||
const shallowReactiveMap = new WeakMap(); | ||
const readonlyMap = new WeakMap(); | ||
const shallowReadonlyMap = new WeakMap(); | ||
function targetTypeMap(rawType) { | ||
switch (rawType) { | ||
case 'Object': | ||
case 'Array': | ||
return 1 /* COMMON */; | ||
case 'Map': | ||
case 'Set': | ||
case 'WeakMap': | ||
case 'WeakSet': | ||
return 2 /* COLLECTION */; | ||
default: | ||
return 0 /* INVALID */; | ||
} | ||
} | ||
function getTargetType(value) { | ||
return value["__v_skip" /* SKIP */] || !Object.isExtensible(value) | ||
? 0 /* INVALID */ | ||
: targetTypeMap(toRawType(value)); | ||
} | ||
function reactive(target) { | ||
// if trying to observe a readonly proxy, return the readonly version. | ||
if (target && target["__v_isReadonly" /* IS_READONLY */]) { | ||
return target; | ||
} | ||
return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap); | ||
} | ||
/** | ||
* Return a shallowly-reactive copy of the original object, where only the root | ||
* level properties are reactive. It also does not auto-unwrap refs (even at the | ||
* root level). | ||
*/ | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap); | ||
} | ||
/** | ||
* Creates a readonly copy of the original object. Note the returned copy is not | ||
* made reactive, but `readonly` can be called on an already reactive object. | ||
*/ | ||
function readonly(target) { | ||
return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap); | ||
} | ||
/** | ||
* Returns a reactive-copy of the original object, where only the root level | ||
* properties are readonly, and does NOT unwrap refs nor recursively convert | ||
* returned properties. | ||
* This is used for creating the props proxy object for stateful components. | ||
*/ | ||
function shallowReadonly(target) { | ||
return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap); | ||
} | ||
function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) { | ||
if (!isObject(target)) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`value cannot be made reactive: ${String(target)}`); | ||
} | ||
return target; | ||
} | ||
// target is already a Proxy, return it. | ||
// exception: calling readonly() on a reactive object | ||
if (target["__v_raw" /* RAW */] && | ||
!(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) { | ||
return target; | ||
} | ||
// target already has corresponding Proxy | ||
const existingProxy = proxyMap.get(target); | ||
if (existingProxy) { | ||
return existingProxy; | ||
} | ||
// only a whitelist of value types can be observed. | ||
const targetType = getTargetType(target); | ||
if (targetType === 0 /* INVALID */) { | ||
return target; | ||
} | ||
const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers); | ||
proxyMap.set(target, proxy); | ||
return proxy; | ||
} | ||
function isReactive(value) { | ||
if (isReadonly(value)) { | ||
return isReactive(value["__v_raw" /* RAW */]); | ||
} | ||
return !!(value && value["__v_isReactive" /* IS_REACTIVE */]); | ||
} | ||
function isReadonly(value) { | ||
return !!(value && value["__v_isReadonly" /* IS_READONLY */]); | ||
} | ||
function isProxy(value) { | ||
return isReactive(value) || isReadonly(value); | ||
} | ||
function toRaw(observed) { | ||
return ((observed && toRaw(observed["__v_raw" /* RAW */])) || observed); | ||
} | ||
function markRaw(value) { | ||
def(value, "__v_skip" /* SKIP */, true); | ||
return value; | ||
} | ||
const convert = (val) => isObject(val) ? reactive(val) : val; | ||
function isRef(r) { | ||
return Boolean(r && r.__v_isRef === true); | ||
} | ||
function ref(value) { | ||
return createRef(value); | ||
} | ||
function shallowRef(value) { | ||
return createRef(value, true); | ||
} | ||
class RefImpl { | ||
constructor(_rawValue, _shallow = false) { | ||
this._rawValue = _rawValue; | ||
this._shallow = _shallow; | ||
this.__v_isRef = true; | ||
this._value = _shallow ? _rawValue : convert(_rawValue); | ||
} | ||
get value() { | ||
track(toRaw(this), "get" /* GET */, 'value'); | ||
return this._value; | ||
} | ||
set value(newVal) { | ||
if (hasChanged(toRaw(newVal), this._rawValue)) { | ||
this._rawValue = newVal; | ||
this._value = this._shallow ? newVal : convert(newVal); | ||
trigger(toRaw(this), "set" /* SET */, 'value', newVal); | ||
} | ||
} | ||
} | ||
function createRef(rawValue, shallow = false) { | ||
if (isRef(rawValue)) { | ||
return rawValue; | ||
} | ||
return new RefImpl(rawValue, shallow); | ||
} | ||
function triggerRef(ref) { | ||
trigger(toRaw(ref), "set" /* SET */, 'value', (process.env.NODE_ENV !== 'production') ? ref.value : void 0); | ||
} | ||
function unref(ref) { | ||
return isRef(ref) ? ref.value : ref; | ||
} | ||
const shallowUnwrapHandlers = { | ||
get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)), | ||
set: (target, key, value, receiver) => { | ||
const oldValue = target[key]; | ||
if (isRef(oldValue) && !isRef(value)) { | ||
oldValue.value = value; | ||
return true; | ||
} | ||
else { | ||
return Reflect.set(target, key, value, receiver); | ||
} | ||
} | ||
}; | ||
function proxyRefs(objectWithRefs) { | ||
return isReactive(objectWithRefs) | ||
? objectWithRefs | ||
: new Proxy(objectWithRefs, shallowUnwrapHandlers); | ||
} | ||
class CustomRefImpl { | ||
constructor(factory) { | ||
this.__v_isRef = true; | ||
const { get, set } = factory(() => track(this, "get" /* GET */, 'value'), () => trigger(this, "set" /* SET */, 'value')); | ||
this._get = get; | ||
this._set = set; | ||
} | ||
get value() { | ||
return this._get(); | ||
} | ||
set value(newVal) { | ||
this._set(newVal); | ||
} | ||
} | ||
function customRef(factory) { | ||
return new CustomRefImpl(factory); | ||
} | ||
function toRefs(object) { | ||
if ((process.env.NODE_ENV !== 'production') && !isProxy(object)) { | ||
console.warn(`toRefs() expects a reactive object but received a plain one.`); | ||
} | ||
const ret = isArray(object) ? new Array(object.length) : {}; | ||
for (const key in object) { | ||
ret[key] = toRef(object, key); | ||
} | ||
return ret; | ||
} | ||
class ObjectRefImpl { | ||
constructor(_object, _key) { | ||
this._object = _object; | ||
this._key = _key; | ||
this.__v_isRef = true; | ||
} | ||
get value() { | ||
return this._object[this._key]; | ||
} | ||
set value(newVal) { | ||
this._object[this._key] = newVal; | ||
} | ||
} | ||
function toRef(object, key) { | ||
return isRef(object[key]) | ||
? object[key] | ||
: new ObjectRefImpl(object, key); | ||
} | ||
class ComputedRefImpl { | ||
constructor(getter, _setter, isReadonly) { | ||
this._setter = _setter; | ||
this._dirty = true; | ||
this.__v_isRef = true; | ||
this.effect = effect(getter, { | ||
lazy: true, | ||
scheduler: () => { | ||
if (!this._dirty) { | ||
this._dirty = true; | ||
trigger(toRaw(this), "set" /* SET */, 'value'); | ||
} | ||
} | ||
}); | ||
this["__v_isReadonly" /* IS_READONLY */] = isReadonly; | ||
} | ||
get value() { | ||
// the computed ref may get wrapped by other proxies e.g. readonly() #3376 | ||
const self = toRaw(this); | ||
if (self._dirty) { | ||
self._value = this.effect(); | ||
self._dirty = false; | ||
} | ||
track(self, "get" /* GET */, 'value'); | ||
return self._value; | ||
} | ||
set value(newValue) { | ||
this._setter(newValue); | ||
} | ||
} | ||
function computed(getterOrOptions) { | ||
let getter; | ||
let setter; | ||
if (isFunction(getterOrOptions)) { | ||
getter = getterOrOptions; | ||
setter = (process.env.NODE_ENV !== 'production') | ||
? () => { | ||
console.warn('Write operation failed: computed value is readonly'); | ||
} | ||
: NOOP; | ||
} | ||
else { | ||
getter = getterOrOptions.get; | ||
setter = getterOrOptions.set; | ||
} | ||
return new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set); | ||
} | ||
var reactivity_esmBundler = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
ITERATE_KEY: ITERATE_KEY, | ||
computed: computed, | ||
customRef: customRef, | ||
effect: effect, | ||
enableTracking: enableTracking, | ||
isProxy: isProxy, | ||
isReactive: isReactive, | ||
isReadonly: isReadonly, | ||
isRef: isRef, | ||
markRaw: markRaw, | ||
pauseTracking: pauseTracking, | ||
proxyRefs: proxyRefs, | ||
reactive: reactive, | ||
readonly: readonly, | ||
ref: ref, | ||
resetTracking: resetTracking, | ||
shallowReactive: shallowReactive, | ||
shallowReadonly: shallowReadonly, | ||
shallowRef: shallowRef, | ||
stop: stop, | ||
toRaw: toRaw, | ||
toRef: toRef, | ||
toRefs: toRefs, | ||
track: track, | ||
trigger: trigger, | ||
triggerRef: triggerRef, | ||
unref: unref | ||
}); | ||
export default index; |
/*! | ||
* vue-keycloak-js v2.1.3-beta | ||
* vue-keycloak-js v2.0.0-beta | ||
* @license ISC | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('keycloak-js'), require('vue')) : | ||
typeof define === 'function' && define.amd ? define(['keycloak-js', 'vue'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['dsb-vue-keycloak'] = factory(global.Keycloak, global.vue)); | ||
}(this, (function (Keycloak, vue) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('keycloak-js')) : | ||
typeof define === 'function' && define.amd ? define(['keycloak-js'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['dsb-vue-keycloak'] = factory(global.Keycloak)); | ||
}(this, (function (Keycloak) { 'use strict'; | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
} | ||
var Keycloak__default = /*#__PURE__*/_interopDefaultLegacy(Keycloak); | ||
var Keycloak__default = /*#__PURE__*/_interopDefaultLegacy(Keycloak); | ||
var vue__namespace = /*#__PURE__*/_interopNamespace(vue); | ||
let installed = false; | ||
var index = { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
install: function (app, params = {}) { | ||
if (installed) | ||
return; | ||
installed = true; | ||
const defaultParams = { | ||
config: window.__BASEURL__ ? `${window.__BASEURL__}/config` : '/config', | ||
init: { onLoad: 'login-required' }, | ||
}; | ||
const options = Object.assign({}, defaultParams, params); | ||
if (assertOptions(options).hasError) | ||
throw new Error(`Invalid options given: ${assertOptions(options).error}`); | ||
vue2AndVue3Reactive(app, defaultEmptyVueKeycloakInstance()).then((watch) => { | ||
getConfig(options.config) | ||
.then((config) => { | ||
init(config, watch, options); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
}); | ||
}, | ||
}; | ||
function defaultEmptyVueKeycloakInstance() { | ||
return { | ||
ready: false, | ||
authenticated: false, | ||
userName: null, | ||
fullName: null, | ||
token: null, | ||
tokenParsed: null, | ||
logoutFn: null, | ||
loginFn: null, | ||
login: null, | ||
createLoginUrl: null, | ||
createLogoutUrl: null, | ||
createRegisterUrl: null, | ||
register: null, | ||
accountManagement: null, | ||
createAccountUrl: null, | ||
loadUserProfile: null, | ||
subject: null, | ||
idToken: null, | ||
idTokenParsed: null, | ||
realmAccess: null, | ||
resourceAccess: null, | ||
refreshToken: null, | ||
refreshTokenParsed: null, | ||
timeSkew: null, | ||
responseMode: null, | ||
responseType: null, | ||
hasRealmRole: null, | ||
hasResourceRole: null, | ||
keycloak: null, | ||
}; | ||
} | ||
function vue2AndVue3Reactive(app, object) { | ||
return new Promise((resolve, reject) => { | ||
if (app.prototype) { | ||
// Vue 2 | ||
try { | ||
const reactiveObj = app.observable(object); | ||
Object.defineProperty(app.prototype, '$keycloak', { | ||
get() { | ||
return reactiveObj; | ||
} | ||
}); | ||
resolve(reactiveObj); | ||
} | ||
catch (e) { | ||
reject(e); | ||
} | ||
} | ||
else { | ||
// Vue 3 | ||
// Assign an object immediately to allow usage of $keycloak in view | ||
const reactiveObj = defaultEmptyVueKeycloakInstance(); | ||
app.config.globalProperties.$keycloak = reactiveObj; | ||
// Async load module to allow vue 2 to not have the dependency. | ||
Promise.resolve().then(function () { return reactivity_esmBundler; }).then((reactivity) => { | ||
// Override the existing reactiveObj so references contains the new reactive values | ||
Object.assign(reactiveObj, reactivity.reactive(object)); | ||
resolve(reactiveObj); | ||
}).catch(e => { | ||
reject(e); | ||
}); | ||
} | ||
}); | ||
} | ||
function init(config, watch, options) { | ||
const keycloak = Keycloak__default['default'](config); | ||
keycloak.onReady = function (authenticated) { | ||
updateWatchVariables(authenticated); | ||
watch.ready = true; | ||
typeof options.onReady === 'function' && options.onReady(keycloak, watch); | ||
}; | ||
keycloak.onAuthSuccess = function () { | ||
// Check token validity every 10 seconds (10 000 ms) and, if necessary, update the token. | ||
// Refresh token if it's valid for less then 60 seconds | ||
const updateTokenInterval = setInterval(() => keycloak.updateToken(60).catch(() => { | ||
keycloak.clearToken(); | ||
}), 10000); | ||
watch.logoutFn = () => { | ||
clearInterval(updateTokenInterval); | ||
keycloak.logout(options.logout); | ||
}; | ||
}; | ||
keycloak.onAuthRefreshSuccess = function () { | ||
updateWatchVariables(true); | ||
}; | ||
keycloak.onAuthRefreshError = function () { | ||
updateWatchVariables(false); | ||
typeof options.onAuthRefreshError === 'function' && | ||
options.onAuthRefreshError(keycloak); | ||
}; | ||
keycloak | ||
.init(options.init) | ||
.then((authenticated) => { | ||
updateWatchVariables(authenticated); | ||
typeof options.onInitSuccess === 'function' && | ||
options.onInitSuccess(authenticated); | ||
}) | ||
.catch((err) => { | ||
updateWatchVariables(false); | ||
const error = Error('Could not initialized keycloak-js adapter'); | ||
typeof options.onInitError === 'function' | ||
? options.onInitError(error, err) | ||
: console.error(error, err); | ||
}); | ||
function updateWatchVariables(isAuthenticated = false) { | ||
watch.authenticated = isAuthenticated; | ||
watch.loginFn = keycloak.login; | ||
watch.login = keycloak.login; | ||
watch.createLoginUrl = keycloak.createLoginUrl; | ||
watch.createLogoutUrl = keycloak.createLogoutUrl; | ||
watch.createRegisterUrl = keycloak.createRegisterUrl; | ||
watch.register = keycloak.register; | ||
watch.keycloak = keycloak; | ||
if (isAuthenticated) { | ||
watch.accountManagement = keycloak.accountManagement; | ||
watch.createAccountUrl = keycloak.createAccountUrl; | ||
watch.hasRealmRole = keycloak.hasRealmRole; | ||
watch.hasResourceRole = keycloak.hasResourceRole; | ||
watch.loadUserProfile = keycloak.loadUserProfile; | ||
watch.token = keycloak.token; | ||
watch.subject = keycloak.subject; | ||
watch.idToken = keycloak.idToken; | ||
watch.idTokenParsed = keycloak.idTokenParsed; | ||
watch.realmAccess = keycloak.realmAccess; | ||
watch.resourceAccess = keycloak.resourceAccess; | ||
watch.refreshToken = keycloak.refreshToken; | ||
watch.refreshTokenParsed = keycloak.refreshTokenParsed; | ||
watch.timeSkew = keycloak.timeSkew; | ||
watch.responseMode = keycloak.responseMode; | ||
watch.responseType = keycloak.responseType; | ||
watch.tokenParsed = keycloak.tokenParsed; | ||
watch.userName = keycloak.tokenParsed['preferred_username']; | ||
watch.fullName = keycloak.tokenParsed['name']; | ||
} | ||
} | ||
} | ||
function assertOptions(options) { | ||
const { config, init, onReady, onInitError, onAuthRefreshError } = options; | ||
if (typeof config !== 'string' && !_isObject(config)) { | ||
return { | ||
hasError: true, | ||
error: `'config' option must be a string or an object. Found: '${config}'`, | ||
}; | ||
} | ||
if (!_isObject(init) || typeof init.onLoad !== 'string') { | ||
return { | ||
hasError: true, | ||
error: `'init' option must be an object with an 'onLoad' property. Found: '${init}'`, | ||
}; | ||
} | ||
if (onReady && typeof onReady !== 'function') { | ||
return { | ||
hasError: true, | ||
error: `'onReady' option must be a function. Found: '${onReady}'`, | ||
}; | ||
} | ||
if (onInitError && typeof onInitError !== 'function') { | ||
return { | ||
hasError: true, | ||
error: `'onInitError' option must be a function. Found: '${onInitError}'`, | ||
}; | ||
} | ||
if (onAuthRefreshError && typeof onAuthRefreshError !== 'function') { | ||
return { | ||
hasError: true, | ||
error: `'onAuthRefreshError' option must be a function. Found: '${onAuthRefreshError}'`, | ||
}; | ||
} | ||
return { | ||
hasError: false, | ||
error: null, | ||
}; | ||
} | ||
function _isObject(obj) { | ||
return (obj !== null && | ||
typeof obj === 'object' && | ||
Object.prototype.toString.call(obj) !== '[object Array]'); | ||
} | ||
function getConfig(config) { | ||
if (_isObject(config)) | ||
return Promise.resolve(config); | ||
return new Promise((resolve, reject) => { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', config); | ||
xhr.setRequestHeader('Accept', 'application/json'); | ||
xhr.onreadystatechange = () => { | ||
if (xhr.readyState === 4) { | ||
if (xhr.status === 200) { | ||
resolve(JSON.parse(xhr.responseText)); | ||
} | ||
else { | ||
reject(Error(xhr.statusText)); | ||
} | ||
} | ||
}; | ||
xhr.send(); | ||
}); | ||
} | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
/** | ||
* Make a map and return a function for checking if a key | ||
* is in that map. | ||
* IMPORTANT: all calls of this function must be prefixed with | ||
* \/\*#\_\_PURE\_\_\*\/ | ||
* So that rollup can tree-shake them if necessary. | ||
*/ | ||
function makeMap(str, expectsLowerCase) { | ||
const map = Object.create(null); | ||
const list = str.split(','); | ||
for (let i = 0; i < list.length; i++) { | ||
map[list[i]] = true; | ||
} | ||
return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]; | ||
} | ||
const EMPTY_OBJ = (process.env.NODE_ENV !== 'production') | ||
? Object.freeze({}) | ||
: {}; | ||
(process.env.NODE_ENV !== 'production') ? Object.freeze([]) : []; | ||
const NOOP = () => { }; | ||
const extend = Object.assign; | ||
const hasOwnProperty = Object.prototype.hasOwnProperty; | ||
const hasOwn = (val, key) => hasOwnProperty.call(val, key); | ||
const isArray = Array.isArray; | ||
const isMap = (val) => toTypeString(val) === '[object Map]'; | ||
const isFunction = (val) => typeof val === 'function'; | ||
const isString = (val) => typeof val === 'string'; | ||
const isSymbol = (val) => typeof val === 'symbol'; | ||
const isObject = (val) => val !== null && typeof val === 'object'; | ||
const objectToString = Object.prototype.toString; | ||
const toTypeString = (value) => objectToString.call(value); | ||
const toRawType = (value) => { | ||
// extract "RawType" from strings like "[object RawType]" | ||
return toTypeString(value).slice(8, -1); | ||
}; | ||
const isIntegerKey = (key) => isString(key) && | ||
key !== 'NaN' && | ||
key[0] !== '-' && | ||
'' + parseInt(key, 10) === key; | ||
const cacheStringFunction = (fn) => { | ||
const cache = Object.create(null); | ||
return ((str) => { | ||
const hit = cache[str]; | ||
return hit || (cache[str] = fn(str)); | ||
}); | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1)); | ||
// compare whether a value has changed, accounting for NaN. | ||
const hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue); | ||
const def = (obj, key, value) => { | ||
Object.defineProperty(obj, key, { | ||
configurable: true, | ||
enumerable: false, | ||
value | ||
}); | ||
}; | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
const targetMap = new WeakMap(); | ||
const effectStack = []; | ||
let activeEffect; | ||
const ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'iterate' : ''); | ||
const MAP_KEY_ITERATE_KEY = Symbol((process.env.NODE_ENV !== 'production') ? 'Map key iterate' : ''); | ||
function isEffect(fn) { | ||
return fn && fn._isEffect === true; | ||
} | ||
function effect(fn, options = EMPTY_OBJ) { | ||
if (isEffect(fn)) { | ||
fn = fn.raw; | ||
} | ||
const effect = createReactiveEffect(fn, options); | ||
if (!options.lazy) { | ||
effect(); | ||
} | ||
return effect; | ||
} | ||
function stop(effect) { | ||
if (effect.active) { | ||
cleanup(effect); | ||
if (effect.options.onStop) { | ||
effect.options.onStop(); | ||
} | ||
effect.active = false; | ||
} | ||
} | ||
let uid = 0; | ||
function createReactiveEffect(fn, options) { | ||
const effect = function reactiveEffect() { | ||
if (!effect.active) { | ||
return options.scheduler ? undefined : fn(); | ||
} | ||
if (!effectStack.includes(effect)) { | ||
cleanup(effect); | ||
try { | ||
enableTracking(); | ||
effectStack.push(effect); | ||
activeEffect = effect; | ||
return fn(); | ||
} | ||
finally { | ||
effectStack.pop(); | ||
resetTracking(); | ||
activeEffect = effectStack[effectStack.length - 1]; | ||
} | ||
} | ||
}; | ||
effect.id = uid++; | ||
effect.allowRecurse = !!options.allowRecurse; | ||
effect._isEffect = true; | ||
effect.active = true; | ||
effect.raw = fn; | ||
effect.deps = []; | ||
effect.options = options; | ||
return effect; | ||
} | ||
function cleanup(effect) { | ||
const { deps } = effect; | ||
if (deps.length) { | ||
for (let i = 0; i < deps.length; i++) { | ||
deps[i].delete(effect); | ||
} | ||
deps.length = 0; | ||
} | ||
} | ||
let shouldTrack = true; | ||
const trackStack = []; | ||
function pauseTracking() { | ||
trackStack.push(shouldTrack); | ||
shouldTrack = false; | ||
} | ||
function enableTracking() { | ||
trackStack.push(shouldTrack); | ||
shouldTrack = true; | ||
} | ||
function resetTracking() { | ||
const last = trackStack.pop(); | ||
shouldTrack = last === undefined ? true : last; | ||
} | ||
function track(target, type, key) { | ||
if (!shouldTrack || activeEffect === undefined) { | ||
return; | ||
} | ||
let depsMap = targetMap.get(target); | ||
if (!depsMap) { | ||
targetMap.set(target, (depsMap = new Map())); | ||
} | ||
let dep = depsMap.get(key); | ||
if (!dep) { | ||
depsMap.set(key, (dep = new Set())); | ||
} | ||
if (!dep.has(activeEffect)) { | ||
dep.add(activeEffect); | ||
activeEffect.deps.push(dep); | ||
if ((process.env.NODE_ENV !== 'production') && activeEffect.options.onTrack) { | ||
activeEffect.options.onTrack({ | ||
effect: activeEffect, | ||
target, | ||
type, | ||
key | ||
}); | ||
} | ||
} | ||
} | ||
function trigger(target, type, key, newValue, oldValue, oldTarget) { | ||
const depsMap = targetMap.get(target); | ||
if (!depsMap) { | ||
// never been tracked | ||
return; | ||
} | ||
const effects = new Set(); | ||
const add = (effectsToAdd) => { | ||
if (effectsToAdd) { | ||
effectsToAdd.forEach(effect => { | ||
if (effect !== activeEffect || effect.allowRecurse) { | ||
effects.add(effect); | ||
} | ||
}); | ||
} | ||
}; | ||
if (type === "clear" /* CLEAR */) { | ||
// collection being cleared | ||
// trigger all effects for target | ||
depsMap.forEach(add); | ||
} | ||
else if (key === 'length' && isArray(target)) { | ||
depsMap.forEach((dep, key) => { | ||
if (key === 'length' || key >= newValue) { | ||
add(dep); | ||
} | ||
}); | ||
} | ||
else { | ||
// schedule runs for SET | ADD | DELETE | ||
if (key !== void 0) { | ||
add(depsMap.get(key)); | ||
} | ||
// also run for iteration key on ADD | DELETE | Map.SET | ||
switch (type) { | ||
case "add" /* ADD */: | ||
if (!isArray(target)) { | ||
add(depsMap.get(ITERATE_KEY)); | ||
if (isMap(target)) { | ||
add(depsMap.get(MAP_KEY_ITERATE_KEY)); | ||
} | ||
} | ||
else if (isIntegerKey(key)) { | ||
// new index added to array -> length changes | ||
add(depsMap.get('length')); | ||
} | ||
break; | ||
case "delete" /* DELETE */: | ||
if (!isArray(target)) { | ||
add(depsMap.get(ITERATE_KEY)); | ||
if (isMap(target)) { | ||
add(depsMap.get(MAP_KEY_ITERATE_KEY)); | ||
} | ||
} | ||
break; | ||
case "set" /* SET */: | ||
if (isMap(target)) { | ||
add(depsMap.get(ITERATE_KEY)); | ||
} | ||
break; | ||
} | ||
} | ||
const run = (effect) => { | ||
if ((process.env.NODE_ENV !== 'production') && effect.options.onTrigger) { | ||
effect.options.onTrigger({ | ||
effect, | ||
target, | ||
key, | ||
type, | ||
newValue, | ||
oldValue, | ||
oldTarget | ||
}); | ||
} | ||
if (effect.options.scheduler) { | ||
effect.options.scheduler(effect); | ||
} | ||
else { | ||
effect(); | ||
} | ||
}; | ||
effects.forEach(run); | ||
} | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`); | ||
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol) | ||
.map(key => Symbol[key]) | ||
.filter(isSymbol)); | ||
const get = /*#__PURE__*/ createGetter(); | ||
const shallowGet = /*#__PURE__*/ createGetter(false, true); | ||
const readonlyGet = /*#__PURE__*/ createGetter(true); | ||
const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true); | ||
const arrayInstrumentations = {}; | ||
['includes', 'indexOf', 'lastIndexOf'].forEach(key => { | ||
const method = Array.prototype[key]; | ||
arrayInstrumentations[key] = function (...args) { | ||
const arr = toRaw(this); | ||
for (let i = 0, l = this.length; i < l; i++) { | ||
track(arr, "get" /* GET */, i + ''); | ||
} | ||
// we run the method using the original args first (which may be reactive) | ||
const res = method.apply(arr, args); | ||
if (res === -1 || res === false) { | ||
// if that didn't work, run it again using raw values. | ||
return method.apply(arr, args.map(toRaw)); | ||
} | ||
else { | ||
return res; | ||
} | ||
}; | ||
}); | ||
['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => { | ||
const method = Array.prototype[key]; | ||
arrayInstrumentations[key] = function (...args) { | ||
pauseTracking(); | ||
const res = method.apply(this, args); | ||
resetTracking(); | ||
return res; | ||
}; | ||
}); | ||
function createGetter(isReadonly = false, shallow = false) { | ||
return function get(target, key, receiver) { | ||
if (key === "__v_isReactive" /* IS_REACTIVE */) { | ||
return !isReadonly; | ||
} | ||
else if (key === "__v_isReadonly" /* IS_READONLY */) { | ||
return isReadonly; | ||
} | ||
else if (key === "__v_raw" /* RAW */ && | ||
receiver === | ||
(isReadonly | ||
? shallow | ||
? shallowReadonlyMap | ||
: readonlyMap | ||
: shallow | ||
? shallowReactiveMap | ||
: reactiveMap).get(target)) { | ||
return target; | ||
} | ||
const targetIsArray = isArray(target); | ||
if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) { | ||
return Reflect.get(arrayInstrumentations, key, receiver); | ||
} | ||
const res = Reflect.get(target, key, receiver); | ||
if (isSymbol(key) | ||
? builtInSymbols.has(key) | ||
: isNonTrackableKeys(key)) { | ||
return res; | ||
} | ||
if (!isReadonly) { | ||
track(target, "get" /* GET */, key); | ||
} | ||
if (shallow) { | ||
return res; | ||
} | ||
if (isRef(res)) { | ||
// ref unwrapping - does not apply for Array + integer key. | ||
const shouldUnwrap = !targetIsArray || !isIntegerKey(key); | ||
return shouldUnwrap ? res.value : res; | ||
} | ||
if (isObject(res)) { | ||
// Convert returned value into a proxy as well. we do the isObject check | ||
// here to avoid invalid value warning. Also need to lazy access readonly | ||
// and reactive here to avoid circular dependency. | ||
return isReadonly ? readonly(res) : reactive(res); | ||
} | ||
return res; | ||
}; | ||
} | ||
const set = /*#__PURE__*/ createSetter(); | ||
const shallowSet = /*#__PURE__*/ createSetter(true); | ||
function createSetter(shallow = false) { | ||
return function set(target, key, value, receiver) { | ||
let oldValue = target[key]; | ||
if (!shallow) { | ||
value = toRaw(value); | ||
oldValue = toRaw(oldValue); | ||
if (!isArray(target) && isRef(oldValue) && !isRef(value)) { | ||
oldValue.value = value; | ||
return true; | ||
} | ||
} | ||
const hadKey = isArray(target) && isIntegerKey(key) | ||
? Number(key) < target.length | ||
: hasOwn(target, key); | ||
const result = Reflect.set(target, key, value, receiver); | ||
// don't trigger if target is something up in the prototype chain of original | ||
if (target === toRaw(receiver)) { | ||
if (!hadKey) { | ||
trigger(target, "add" /* ADD */, key, value); | ||
} | ||
else if (hasChanged(value, oldValue)) { | ||
trigger(target, "set" /* SET */, key, value, oldValue); | ||
} | ||
} | ||
return result; | ||
}; | ||
} | ||
function deleteProperty(target, key) { | ||
const hadKey = hasOwn(target, key); | ||
const oldValue = target[key]; | ||
const result = Reflect.deleteProperty(target, key); | ||
if (result && hadKey) { | ||
trigger(target, "delete" /* DELETE */, key, undefined, oldValue); | ||
} | ||
return result; | ||
} | ||
function has(target, key) { | ||
const result = Reflect.has(target, key); | ||
if (!isSymbol(key) || !builtInSymbols.has(key)) { | ||
track(target, "has" /* HAS */, key); | ||
} | ||
return result; | ||
} | ||
function ownKeys(target) { | ||
track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY); | ||
return Reflect.ownKeys(target); | ||
} | ||
const mutableHandlers = { | ||
get, | ||
set, | ||
deleteProperty, | ||
has, | ||
ownKeys | ||
}; | ||
const readonlyHandlers = { | ||
get: readonlyGet, | ||
set(target, key) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
}, | ||
deleteProperty(target, key) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target); | ||
} | ||
return true; | ||
} | ||
}; | ||
const shallowReactiveHandlers = extend({}, mutableHandlers, { | ||
get: shallowGet, | ||
set: shallowSet | ||
}); | ||
// Props handlers are special in the sense that it should not unwrap top-level | ||
// refs (in order to allow refs to be explicitly passed down), but should | ||
// retain the reactivity of the normal readonly object. | ||
const shallowReadonlyHandlers = extend({}, readonlyHandlers, { | ||
get: shallowReadonlyGet | ||
}); | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
const toReactive = (value) => isObject(value) ? reactive(value) : value; | ||
const toReadonly = (value) => isObject(value) ? readonly(value) : value; | ||
const toShallow = (value) => value; | ||
const getProto = (v) => Reflect.getPrototypeOf(v); | ||
function get$1(target, key, isReadonly = false, isShallow = false) { | ||
// #1772: readonly(reactive(Map)) should return readonly + reactive version | ||
// of the value | ||
target = target["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (key !== rawKey) { | ||
!isReadonly && track(rawTarget, "get" /* GET */, key); | ||
} | ||
!isReadonly && track(rawTarget, "get" /* GET */, rawKey); | ||
const { has } = getProto(rawTarget); | ||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; | ||
if (has.call(rawTarget, key)) { | ||
return wrap(target.get(key)); | ||
} | ||
else if (has.call(rawTarget, rawKey)) { | ||
return wrap(target.get(rawKey)); | ||
} | ||
} | ||
function has$1(key, isReadonly = false) { | ||
const target = this["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const rawKey = toRaw(key); | ||
if (key !== rawKey) { | ||
!isReadonly && track(rawTarget, "has" /* HAS */, key); | ||
} | ||
!isReadonly && track(rawTarget, "has" /* HAS */, rawKey); | ||
return key === rawKey | ||
? target.has(key) | ||
: target.has(key) || target.has(rawKey); | ||
} | ||
function size(target, isReadonly = false) { | ||
target = target["__v_raw" /* RAW */]; | ||
!isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY); | ||
return Reflect.get(target, 'size', target); | ||
} | ||
function add(value) { | ||
value = toRaw(value); | ||
const target = toRaw(this); | ||
const proto = getProto(target); | ||
const hadKey = proto.has.call(target, value); | ||
if (!hadKey) { | ||
target.add(value); | ||
trigger(target, "add" /* ADD */, value, value); | ||
} | ||
return this; | ||
} | ||
function set$1(key, value) { | ||
value = toRaw(value); | ||
const target = toRaw(this); | ||
const { has, get } = getProto(target); | ||
let hadKey = has.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has.call(target, key); | ||
} | ||
else if ((process.env.NODE_ENV !== 'production')) { | ||
checkIdentityKeys(target, has, key); | ||
} | ||
const oldValue = get.call(target, key); | ||
target.set(key, value); | ||
if (!hadKey) { | ||
trigger(target, "add" /* ADD */, key, value); | ||
} | ||
else if (hasChanged(value, oldValue)) { | ||
trigger(target, "set" /* SET */, key, value, oldValue); | ||
} | ||
return this; | ||
} | ||
function deleteEntry(key) { | ||
const target = toRaw(this); | ||
const { has, get } = getProto(target); | ||
let hadKey = has.call(target, key); | ||
if (!hadKey) { | ||
key = toRaw(key); | ||
hadKey = has.call(target, key); | ||
} | ||
else if ((process.env.NODE_ENV !== 'production')) { | ||
checkIdentityKeys(target, has, key); | ||
} | ||
const oldValue = get ? get.call(target, key) : undefined; | ||
// forward the operation before queueing reactions | ||
const result = target.delete(key); | ||
if (hadKey) { | ||
trigger(target, "delete" /* DELETE */, key, undefined, oldValue); | ||
} | ||
return result; | ||
} | ||
function clear() { | ||
const target = toRaw(this); | ||
const hadItems = target.size !== 0; | ||
const oldTarget = (process.env.NODE_ENV !== 'production') | ||
? isMap(target) | ||
? new Map(target) | ||
: new Set(target) | ||
: undefined; | ||
// forward the operation before queueing reactions | ||
const result = target.clear(); | ||
if (hadItems) { | ||
trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget); | ||
} | ||
return result; | ||
} | ||
function createForEach(isReadonly, isShallow) { | ||
return function forEach(callback, thisArg) { | ||
const observed = this; | ||
const target = observed["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; | ||
!isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY); | ||
return target.forEach((value, key) => { | ||
// important: make sure the callback is | ||
// 1. invoked with the reactive map as `this` and 3rd arg | ||
// 2. the value received should be a corresponding reactive/readonly. | ||
return callback.call(thisArg, wrap(value), wrap(key), observed); | ||
}); | ||
}; | ||
} | ||
function createIterableMethod(method, isReadonly, isShallow) { | ||
return function (...args) { | ||
const target = this["__v_raw" /* RAW */]; | ||
const rawTarget = toRaw(target); | ||
const targetIsMap = isMap(rawTarget); | ||
const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap); | ||
const isKeyOnly = method === 'keys' && targetIsMap; | ||
const innerIterator = target[method](...args); | ||
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; | ||
!isReadonly && | ||
track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); | ||
// return a wrapped iterator which returns observed versions of the | ||
// values emitted from the real iterator | ||
return { | ||
// iterator protocol | ||
next() { | ||
const { value, done } = innerIterator.next(); | ||
return done | ||
? { value, done } | ||
: { | ||
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value), | ||
done | ||
}; | ||
}, | ||
// iterable protocol | ||
[Symbol.iterator]() { | ||
return this; | ||
} | ||
}; | ||
}; | ||
} | ||
function createReadonlyMethod(type) { | ||
return function (...args) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
const key = args[0] ? `on key "${args[0]}" ` : ``; | ||
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this)); | ||
} | ||
return type === "delete" /* DELETE */ ? false : this; | ||
}; | ||
} | ||
const mutableInstrumentations = { | ||
get(key) { | ||
return get$1(this, key); | ||
}, | ||
get size() { | ||
return size(this); | ||
}, | ||
has: has$1, | ||
add, | ||
set: set$1, | ||
delete: deleteEntry, | ||
clear, | ||
forEach: createForEach(false, false) | ||
}; | ||
const shallowInstrumentations = { | ||
get(key) { | ||
return get$1(this, key, false, true); | ||
}, | ||
get size() { | ||
return size(this); | ||
}, | ||
has: has$1, | ||
add, | ||
set: set$1, | ||
delete: deleteEntry, | ||
clear, | ||
forEach: createForEach(false, true) | ||
}; | ||
const readonlyInstrumentations = { | ||
get(key) { | ||
return get$1(this, key, true); | ||
}, | ||
get size() { | ||
return size(this, true); | ||
}, | ||
has(key) { | ||
return has$1.call(this, key, true); | ||
}, | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true, false) | ||
}; | ||
const shallowReadonlyInstrumentations = { | ||
get(key) { | ||
return get$1(this, key, true, true); | ||
}, | ||
get size() { | ||
return size(this, true); | ||
}, | ||
has(key) { | ||
return has$1.call(this, key, true); | ||
}, | ||
add: createReadonlyMethod("add" /* ADD */), | ||
set: createReadonlyMethod("set" /* SET */), | ||
delete: createReadonlyMethod("delete" /* DELETE */), | ||
clear: createReadonlyMethod("clear" /* CLEAR */), | ||
forEach: createForEach(true, true) | ||
}; | ||
const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator]; | ||
iteratorMethods.forEach(method => { | ||
mutableInstrumentations[method] = createIterableMethod(method, false, false); | ||
readonlyInstrumentations[method] = createIterableMethod(method, true, false); | ||
shallowInstrumentations[method] = createIterableMethod(method, false, true); | ||
shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true); | ||
}); | ||
function createInstrumentationGetter(isReadonly, shallow) { | ||
const instrumentations = shallow | ||
? isReadonly | ||
? shallowReadonlyInstrumentations | ||
: shallowInstrumentations | ||
: isReadonly | ||
? readonlyInstrumentations | ||
: mutableInstrumentations; | ||
return (target, key, receiver) => { | ||
if (key === "__v_isReactive" /* IS_REACTIVE */) { | ||
return !isReadonly; | ||
} | ||
else if (key === "__v_isReadonly" /* IS_READONLY */) { | ||
return isReadonly; | ||
} | ||
else if (key === "__v_raw" /* RAW */) { | ||
return target; | ||
} | ||
return Reflect.get(hasOwn(instrumentations, key) && key in target | ||
? instrumentations | ||
: target, key, receiver); | ||
}; | ||
} | ||
const mutableCollectionHandlers = { | ||
get: createInstrumentationGetter(false, false) | ||
}; | ||
const shallowCollectionHandlers = { | ||
get: createInstrumentationGetter(false, true) | ||
}; | ||
const readonlyCollectionHandlers = { | ||
get: createInstrumentationGetter(true, false) | ||
}; | ||
const shallowReadonlyCollectionHandlers = { | ||
get: createInstrumentationGetter(true, true) | ||
}; | ||
function checkIdentityKeys(target, has, key) { | ||
const rawKey = toRaw(key); | ||
if (rawKey !== key && has.call(target, rawKey)) { | ||
const type = toRawType(target); | ||
console.warn(`Reactive ${type} contains both the raw and reactive ` + | ||
`versions of the same object${type === `Map` ? ` as keys` : ``}, ` + | ||
`which can lead to inconsistencies. ` + | ||
`Avoid differentiating between the raw and reactive versions ` + | ||
`of an object and only use the reactive version if possible.`); | ||
} | ||
} | ||
let installed = false; | ||
const KeycloakSymbol = Symbol('keycloak'); | ||
var index = { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
install: function (app, params = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (installed) | ||
return; | ||
installed = true; | ||
const defaultParams = { | ||
config: window.__BASEURL__ ? `${window.__BASEURL__}/config` : '/config', | ||
init: { onLoad: 'login-required' }, | ||
}; | ||
const options = Object.assign({}, defaultParams, params); | ||
if (assertOptions(options).hasError) | ||
throw new Error(`Invalid options given: ${assertOptions(options).error}`); | ||
const watch = yield vue2AndVue3Reactive(app, defaultEmptyVueKeycloakInstance()); | ||
getConfig(options.config) | ||
.then((config) => { | ||
init(config, watch, options); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
}); | ||
}, | ||
KeycloakSymbol | ||
}; | ||
function defaultEmptyVueKeycloakInstance() { | ||
return { | ||
ready: false, | ||
authenticated: false, | ||
userName: null, | ||
fullName: null, | ||
token: null, | ||
tokenParsed: null, | ||
logoutFn: null, | ||
loginFn: null, | ||
login: null, | ||
createLoginUrl: null, | ||
createLogoutUrl: null, | ||
createRegisterUrl: null, | ||
register: null, | ||
accountManagement: null, | ||
createAccountUrl: null, | ||
loadUserProfile: null, | ||
subject: null, | ||
idToken: null, | ||
idTokenParsed: null, | ||
realmAccess: null, | ||
resourceAccess: null, | ||
refreshToken: null, | ||
refreshTokenParsed: null, | ||
timeSkew: null, | ||
responseMode: null, | ||
responseType: null, | ||
hasRealmRole: null, | ||
hasResourceRole: null, | ||
keycloak: null, | ||
}; | ||
} | ||
function vue2AndVue3Reactive(app, object) { | ||
return new Promise((resolve, reject) => { | ||
if (app.prototype) { | ||
// Vue 2 | ||
try { | ||
const reactiveObj = app.observable(object); | ||
Object.defineProperty(app.prototype, '$keycloak', { | ||
get() { | ||
return reactiveObj; | ||
} | ||
}); | ||
resolve(reactiveObj); | ||
} | ||
catch (e) { | ||
reject(e); | ||
} | ||
} | ||
else { | ||
// Vue 3 | ||
// Assign an object immediately to allow usage of $keycloak in view | ||
//const vue = await import('vue') | ||
// Async load module to allow vue 2 to not have the dependency. | ||
const reactiveObj = vue__namespace.reactive(object); | ||
// Override the existing reactiveObj so references contains the new reactive values | ||
app.config.globalProperties.$keycloak = reactiveObj; | ||
// Use provide/inject in Vue3 apps | ||
app.provide(KeycloakSymbol, reactiveObj); | ||
resolve(reactiveObj); | ||
} | ||
}); | ||
} | ||
function init(config, watch, options) { | ||
const keycloak = Keycloak__default['default'](config); | ||
keycloak.onReady = function (authenticated) { | ||
updateWatchVariables(authenticated); | ||
watch.ready = true; | ||
typeof options.onReady === 'function' && options.onReady(keycloak, watch); | ||
}; | ||
keycloak.onAuthSuccess = function () { | ||
// Check token validity every 10 seconds (10 000 ms) and, if necessary, update the token. | ||
// Refresh token if it's valid for less then 60 seconds | ||
const updateTokenInterval = setInterval(() => keycloak.updateToken(60).catch(() => { | ||
keycloak.clearToken(); | ||
}), 10000); | ||
watch.logoutFn = () => { | ||
clearInterval(updateTokenInterval); | ||
keycloak.logout(options.logout); | ||
}; | ||
}; | ||
keycloak.onAuthRefreshSuccess = function () { | ||
updateWatchVariables(true); | ||
typeof options.onAuthRefreshSuccess === 'function' && | ||
options.onAuthRefreshSuccess(keycloak); | ||
}; | ||
keycloak.onAuthRefreshError = function () { | ||
updateWatchVariables(false); | ||
typeof options.onAuthRefreshError === 'function' && | ||
options.onAuthRefreshError(keycloak); | ||
}; | ||
keycloak | ||
.init(options.init) | ||
.then((authenticated) => { | ||
updateWatchVariables(authenticated); | ||
typeof options.onInitSuccess === 'function' && | ||
options.onInitSuccess(authenticated); | ||
}) | ||
.catch((err) => { | ||
updateWatchVariables(false); | ||
const error = Error('Failure during initialization of keycloak-js adapter'); | ||
typeof options.onInitError === 'function' | ||
? options.onInitError(error, err) | ||
: console.error(error, err); | ||
}); | ||
function updateWatchVariables(isAuthenticated = false) { | ||
watch.authenticated = isAuthenticated; | ||
watch.loginFn = keycloak.login; | ||
watch.login = keycloak.login; | ||
watch.createLoginUrl = keycloak.createLoginUrl; | ||
watch.createLogoutUrl = keycloak.createLogoutUrl; | ||
watch.createRegisterUrl = keycloak.createRegisterUrl; | ||
watch.register = keycloak.register; | ||
watch.keycloak = keycloak; | ||
if (isAuthenticated) { | ||
watch.accountManagement = keycloak.accountManagement; | ||
watch.createAccountUrl = keycloak.createAccountUrl; | ||
watch.hasRealmRole = keycloak.hasRealmRole; | ||
watch.hasResourceRole = keycloak.hasResourceRole; | ||
watch.loadUserProfile = keycloak.loadUserProfile; | ||
watch.token = keycloak.token; | ||
watch.subject = keycloak.subject; | ||
watch.idToken = keycloak.idToken; | ||
watch.idTokenParsed = keycloak.idTokenParsed; | ||
watch.realmAccess = keycloak.realmAccess; | ||
watch.resourceAccess = keycloak.resourceAccess; | ||
watch.refreshToken = keycloak.refreshToken; | ||
watch.refreshTokenParsed = keycloak.refreshTokenParsed; | ||
watch.timeSkew = keycloak.timeSkew; | ||
watch.responseMode = keycloak.responseMode; | ||
watch.responseType = keycloak.responseType; | ||
watch.tokenParsed = keycloak.tokenParsed; | ||
watch.userName = keycloak.tokenParsed['preferred_username']; | ||
watch.fullName = keycloak.tokenParsed['name']; | ||
} | ||
} | ||
} | ||
function assertOptions(options) { | ||
const { config, init, onReady, onInitError, onAuthRefreshError } = options; | ||
if (typeof config !== 'string' && !_isObject(config)) { | ||
return { | ||
hasError: true, | ||
error: `'config' option must be a string or an object. Found: '${config}'`, | ||
}; | ||
} | ||
if (!_isObject(init) || typeof init.onLoad !== 'string') { | ||
return { | ||
hasError: true, | ||
error: `'init' option must be an object with an 'onLoad' property. Found: '${init}'`, | ||
}; | ||
} | ||
if (onReady && typeof onReady !== 'function') { | ||
return { | ||
hasError: true, | ||
error: `'onReady' option must be a function. Found: '${onReady}'`, | ||
}; | ||
} | ||
if (onInitError && typeof onInitError !== 'function') { | ||
return { | ||
hasError: true, | ||
error: `'onInitError' option must be a function. Found: '${onInitError}'`, | ||
}; | ||
} | ||
if (onAuthRefreshError && typeof onAuthRefreshError !== 'function') { | ||
return { | ||
hasError: true, | ||
error: `'onAuthRefreshError' option must be a function. Found: '${onAuthRefreshError}'`, | ||
}; | ||
} | ||
return { | ||
hasError: false, | ||
error: null, | ||
}; | ||
} | ||
function _isObject(obj) { | ||
return (obj !== null && | ||
typeof obj === 'object' && | ||
Object.prototype.toString.call(obj) !== '[object Array]'); | ||
} | ||
function getConfig(config) { | ||
if (_isObject(config)) | ||
return Promise.resolve(config); | ||
return new Promise((resolve, reject) => { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', config); | ||
xhr.setRequestHeader('Accept', 'application/json'); | ||
xhr.onreadystatechange = () => { | ||
if (xhr.readyState === 4) { | ||
if (xhr.status === 200) { | ||
resolve(JSON.parse(xhr.responseText)); | ||
} | ||
else { | ||
reject(Error(xhr.statusText)); | ||
} | ||
} | ||
}; | ||
xhr.send(); | ||
}); | ||
} | ||
const reactiveMap = new WeakMap(); | ||
const shallowReactiveMap = new WeakMap(); | ||
const readonlyMap = new WeakMap(); | ||
const shallowReadonlyMap = new WeakMap(); | ||
function targetTypeMap(rawType) { | ||
switch (rawType) { | ||
case 'Object': | ||
case 'Array': | ||
return 1 /* COMMON */; | ||
case 'Map': | ||
case 'Set': | ||
case 'WeakMap': | ||
case 'WeakSet': | ||
return 2 /* COLLECTION */; | ||
default: | ||
return 0 /* INVALID */; | ||
} | ||
} | ||
function getTargetType(value) { | ||
return value["__v_skip" /* SKIP */] || !Object.isExtensible(value) | ||
? 0 /* INVALID */ | ||
: targetTypeMap(toRawType(value)); | ||
} | ||
function reactive(target) { | ||
// if trying to observe a readonly proxy, return the readonly version. | ||
if (target && target["__v_isReadonly" /* IS_READONLY */]) { | ||
return target; | ||
} | ||
return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap); | ||
} | ||
/** | ||
* Return a shallowly-reactive copy of the original object, where only the root | ||
* level properties are reactive. It also does not auto-unwrap refs (even at the | ||
* root level). | ||
*/ | ||
function shallowReactive(target) { | ||
return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap); | ||
} | ||
/** | ||
* Creates a readonly copy of the original object. Note the returned copy is not | ||
* made reactive, but `readonly` can be called on an already reactive object. | ||
*/ | ||
function readonly(target) { | ||
return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap); | ||
} | ||
/** | ||
* Returns a reactive-copy of the original object, where only the root level | ||
* properties are readonly, and does NOT unwrap refs nor recursively convert | ||
* returned properties. | ||
* This is used for creating the props proxy object for stateful components. | ||
*/ | ||
function shallowReadonly(target) { | ||
return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap); | ||
} | ||
function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) { | ||
if (!isObject(target)) { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
console.warn(`value cannot be made reactive: ${String(target)}`); | ||
} | ||
return target; | ||
} | ||
// target is already a Proxy, return it. | ||
// exception: calling readonly() on a reactive object | ||
if (target["__v_raw" /* RAW */] && | ||
!(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) { | ||
return target; | ||
} | ||
// target already has corresponding Proxy | ||
const existingProxy = proxyMap.get(target); | ||
if (existingProxy) { | ||
return existingProxy; | ||
} | ||
// only a whitelist of value types can be observed. | ||
const targetType = getTargetType(target); | ||
if (targetType === 0 /* INVALID */) { | ||
return target; | ||
} | ||
const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers); | ||
proxyMap.set(target, proxy); | ||
return proxy; | ||
} | ||
function isReactive(value) { | ||
if (isReadonly(value)) { | ||
return isReactive(value["__v_raw" /* RAW */]); | ||
} | ||
return !!(value && value["__v_isReactive" /* IS_REACTIVE */]); | ||
} | ||
function isReadonly(value) { | ||
return !!(value && value["__v_isReadonly" /* IS_READONLY */]); | ||
} | ||
function isProxy(value) { | ||
return isReactive(value) || isReadonly(value); | ||
} | ||
function toRaw(observed) { | ||
return ((observed && toRaw(observed["__v_raw" /* RAW */])) || observed); | ||
} | ||
function markRaw(value) { | ||
def(value, "__v_skip" /* SKIP */, true); | ||
return value; | ||
} | ||
return index; | ||
const convert = (val) => isObject(val) ? reactive(val) : val; | ||
function isRef(r) { | ||
return Boolean(r && r.__v_isRef === true); | ||
} | ||
function ref(value) { | ||
return createRef(value); | ||
} | ||
function shallowRef(value) { | ||
return createRef(value, true); | ||
} | ||
class RefImpl { | ||
constructor(_rawValue, _shallow = false) { | ||
this._rawValue = _rawValue; | ||
this._shallow = _shallow; | ||
this.__v_isRef = true; | ||
this._value = _shallow ? _rawValue : convert(_rawValue); | ||
} | ||
get value() { | ||
track(toRaw(this), "get" /* GET */, 'value'); | ||
return this._value; | ||
} | ||
set value(newVal) { | ||
if (hasChanged(toRaw(newVal), this._rawValue)) { | ||
this._rawValue = newVal; | ||
this._value = this._shallow ? newVal : convert(newVal); | ||
trigger(toRaw(this), "set" /* SET */, 'value', newVal); | ||
} | ||
} | ||
} | ||
function createRef(rawValue, shallow = false) { | ||
if (isRef(rawValue)) { | ||
return rawValue; | ||
} | ||
return new RefImpl(rawValue, shallow); | ||
} | ||
function triggerRef(ref) { | ||
trigger(toRaw(ref), "set" /* SET */, 'value', (process.env.NODE_ENV !== 'production') ? ref.value : void 0); | ||
} | ||
function unref(ref) { | ||
return isRef(ref) ? ref.value : ref; | ||
} | ||
const shallowUnwrapHandlers = { | ||
get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)), | ||
set: (target, key, value, receiver) => { | ||
const oldValue = target[key]; | ||
if (isRef(oldValue) && !isRef(value)) { | ||
oldValue.value = value; | ||
return true; | ||
} | ||
else { | ||
return Reflect.set(target, key, value, receiver); | ||
} | ||
} | ||
}; | ||
function proxyRefs(objectWithRefs) { | ||
return isReactive(objectWithRefs) | ||
? objectWithRefs | ||
: new Proxy(objectWithRefs, shallowUnwrapHandlers); | ||
} | ||
class CustomRefImpl { | ||
constructor(factory) { | ||
this.__v_isRef = true; | ||
const { get, set } = factory(() => track(this, "get" /* GET */, 'value'), () => trigger(this, "set" /* SET */, 'value')); | ||
this._get = get; | ||
this._set = set; | ||
} | ||
get value() { | ||
return this._get(); | ||
} | ||
set value(newVal) { | ||
this._set(newVal); | ||
} | ||
} | ||
function customRef(factory) { | ||
return new CustomRefImpl(factory); | ||
} | ||
function toRefs(object) { | ||
if ((process.env.NODE_ENV !== 'production') && !isProxy(object)) { | ||
console.warn(`toRefs() expects a reactive object but received a plain one.`); | ||
} | ||
const ret = isArray(object) ? new Array(object.length) : {}; | ||
for (const key in object) { | ||
ret[key] = toRef(object, key); | ||
} | ||
return ret; | ||
} | ||
class ObjectRefImpl { | ||
constructor(_object, _key) { | ||
this._object = _object; | ||
this._key = _key; | ||
this.__v_isRef = true; | ||
} | ||
get value() { | ||
return this._object[this._key]; | ||
} | ||
set value(newVal) { | ||
this._object[this._key] = newVal; | ||
} | ||
} | ||
function toRef(object, key) { | ||
return isRef(object[key]) | ||
? object[key] | ||
: new ObjectRefImpl(object, key); | ||
} | ||
class ComputedRefImpl { | ||
constructor(getter, _setter, isReadonly) { | ||
this._setter = _setter; | ||
this._dirty = true; | ||
this.__v_isRef = true; | ||
this.effect = effect(getter, { | ||
lazy: true, | ||
scheduler: () => { | ||
if (!this._dirty) { | ||
this._dirty = true; | ||
trigger(toRaw(this), "set" /* SET */, 'value'); | ||
} | ||
} | ||
}); | ||
this["__v_isReadonly" /* IS_READONLY */] = isReadonly; | ||
} | ||
get value() { | ||
// the computed ref may get wrapped by other proxies e.g. readonly() #3376 | ||
const self = toRaw(this); | ||
if (self._dirty) { | ||
self._value = this.effect(); | ||
self._dirty = false; | ||
} | ||
track(self, "get" /* GET */, 'value'); | ||
return self._value; | ||
} | ||
set value(newValue) { | ||
this._setter(newValue); | ||
} | ||
} | ||
function computed(getterOrOptions) { | ||
let getter; | ||
let setter; | ||
if (isFunction(getterOrOptions)) { | ||
getter = getterOrOptions; | ||
setter = (process.env.NODE_ENV !== 'production') | ||
? () => { | ||
console.warn('Write operation failed: computed value is readonly'); | ||
} | ||
: NOOP; | ||
} | ||
else { | ||
getter = getterOrOptions.get; | ||
setter = getterOrOptions.set; | ||
} | ||
return new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set); | ||
} | ||
var reactivity_esmBundler = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
ITERATE_KEY: ITERATE_KEY, | ||
computed: computed, | ||
customRef: customRef, | ||
effect: effect, | ||
enableTracking: enableTracking, | ||
isProxy: isProxy, | ||
isReactive: isReactive, | ||
isReadonly: isReadonly, | ||
isRef: isRef, | ||
markRaw: markRaw, | ||
pauseTracking: pauseTracking, | ||
proxyRefs: proxyRefs, | ||
reactive: reactive, | ||
readonly: readonly, | ||
ref: ref, | ||
resetTracking: resetTracking, | ||
shallowReactive: shallowReactive, | ||
shallowReadonly: shallowReadonly, | ||
shallowRef: shallowRef, | ||
stop: stop, | ||
toRaw: toRaw, | ||
toRef: toRef, | ||
toRefs: toRefs, | ||
track: track, | ||
trigger: trigger, | ||
triggerRef: triggerRef, | ||
unref: unref | ||
}); | ||
return index; | ||
}))); |
import type { VueKeycloakOptions, Vue2Vue3App } from './types'; | ||
declare const _default: { | ||
install: (app: Vue2Vue3App, params?: VueKeycloakOptions) => Promise<void>; | ||
KeycloakSymbol: symbol; | ||
install: (app: Vue2Vue3App, params?: VueKeycloakOptions) => void; | ||
}; | ||
export default _default; |
import type { KeycloakConfig, KeycloakError, KeycloakInitOptions, KeycloakInstance, KeycloakLoginOptions, KeycloakProfile, KeycloakPromise, KeycloakResourceAccess, KeycloakRoles, KeycloakTokenParsed } from 'keycloak-js'; | ||
import type { App } from 'vue'; | ||
export { KeycloakConfig, KeycloakError, KeycloakInitOptions, KeycloakInstance, KeycloakLoginOptions, KeycloakProfile, KeycloakPromise, KeycloakResourceAccess, KeycloakRoles, KeycloakTokenParsed, }; | ||
export interface Vue2Vue3App { | ||
export interface Vue2Vue3App extends App { | ||
prototype?: unknown; | ||
observable?: any; | ||
config?: any; | ||
provide?: any; | ||
} | ||
@@ -17,3 +16,2 @@ export declare type VueKeycloakConfig = KeycloakConfig | string; | ||
onAuthRefreshError?: (keycloak: KeycloakInstance) => void; | ||
onAuthRefreshSuccess?: (keycloak: KeycloakInstance) => void; | ||
onInitSuccess?(authenticated: boolean, keycloak?: KeycloakInstance, VueKeycloak?: VueKeycloakInstance): void; | ||
@@ -20,0 +18,0 @@ } |
{ | ||
"name": "@dsb-norge/vue-keycloak-js", | ||
"version": "2.1.3-beta", | ||
"author": "Nils Lien <nils.lien@gmail.com>", | ||
"version": "2.1.4-beta", | ||
"author": "Nils Lien", | ||
"description": "A Keycloak plugin for Vue >= 2.x", | ||
@@ -20,3 +20,3 @@ "main": "dist/dsb-vue-keycloak.cjs.js", | ||
"dependencies": { | ||
"keycloak-js": "^15.0.2" | ||
"keycloak-js": "15.1.1" | ||
}, | ||
@@ -28,16 +28,16 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.11.4", | ||
"@babel/preset-env": "^7.11.0", | ||
"@rollup/plugin-babel": "^5.2.0", | ||
"@rollup/plugin-commonjs": "^15.0.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.21.0", | ||
"@typescript-eslint/parser": "^4.21.0", | ||
"babel-eslint": "^10.1.0", | ||
"eslint": "^7.23.0", | ||
"rollup": "^2.26.8", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"typescript": "^4.2.3", | ||
"vue": "^3.0.9" | ||
"@babel/eslint-parser": "7.17.0", | ||
"@babel/core": "7.17.10", | ||
"@babel/preset-env": "7.17.10", | ||
"@rollup/plugin-babel": "5.3.1", | ||
"@rollup/plugin-commonjs": "22.0.0", | ||
"@rollup/plugin-node-resolve": "13.3.0", | ||
"@typescript-eslint/eslint-plugin": "5.23.0", | ||
"@typescript-eslint/parser": "5.23.0", | ||
"eslint": "8.15.0", | ||
"rollup": "2.72.1", | ||
"rollup-plugin-terser": "7.0.2", | ||
"rollup-plugin-typescript2": "0.31.2", | ||
"typescript": "4.6.4", | ||
"vue": "3.2.33" | ||
}, | ||
@@ -44,0 +44,0 @@ "peerDependencies": { |
@@ -24,5 +24,5 @@ vue-keycloak plugin | ||
will be redirected back to the application and remain unauthenticated. | ||
> | ||
> To enable login-required set onLoad to login-required and pass to the init method: | ||
> | ||
> `keycloak.init({ onLoad: 'login-required' })` | ||
@@ -56,4 +56,3 @@ | ||
Tell Vue to install the plugin, and optionally pass in a JavaScript object additional | ||
configuration. | ||
Tell Vue to install the plugin, and optionally pass in a JavaScript object for additional configuration. | ||
@@ -73,4 +72,3 @@ ```javascript | ||
Tell Vue to install the plugin, and optionally pass in a JavaScript object additional | ||
configuration. | ||
Tell Vue to install the plugin, and optionally pass in a JavaScript object for additional configuration. | ||
@@ -153,11 +151,11 @@ ```javascript | ||
You can pass in an object as options to the plugin. The following keys are valid options. See below for descpription. | ||
You can pass in an object as options to the plugin. The following keys are valid options. See below for description. | ||
|Key|Type|Default | ||
|---|---|---| | ||
| `config`|String | Object|`window.__BASEURL__ + '/config'` | ||
|`init`|Object|`{onLoad: 'login-required'}` | ||
|`logout`|Object| | ||
|`onReady`|Function(keycloak)| | ||
|`onInitError`|Function(error)| | ||
| Key | Type | Default | | ||
|---------------|----------------------|----------------------------------| | ||
| `config` | String | Object | `window.__BASEURL__ + '/config'` | | ||
| `init` | Object | `{onLoad: 'login-required'}` | | ||
| `logout` | Object | | | ||
| `onReady` | Function(keycloak) | | | ||
| `onInitError` | Function(error) | | | ||
@@ -361,3 +359,3 @@ ### config | ||
Simple 'in component' secret displaying reactiveness | ||
Simple 'in component' secret displaying reactiveness: | ||
@@ -380,3 +378,3 @@ [simple_vue2](https://github.com/dsb-norge/vue-keycloak-js/tree/master/examples/simple_vue2) | ||
The command `npm version patch` will automatically run the build, push the branch upstream and publish the package to | ||
the NPM registry | ||
the NPM registry. | ||
@@ -397,2 +395,2 @@ ## Frequently asked questions | ||
Note that if you run keycloak on your own machine its important to be consistent with the settings for it's address. Cookies created from 127.0.0.1 will not be sent to "localhost" and vice versa. | ||
Note that if you run keycloak on your own machine it is important to be consistent with the settings for its address. Cookies created from 127.0.0.1 will not be sent to "localhost" and vice versa. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
145550
3667
390
48
1
Updatedkeycloak-js@15.1.1