@authup/client-web-kit 1.0.0-beta.13 → 1.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { REALM_MASTER_NAME, DomainEventName, buildDomainChannelName, DomainType, isRealmResourceWritable, IdentityProviderProtocol, IdentityProviderPreset, getIdentityProviderProtocolForPreset } from '@authup/core-kit';
2
- import { hasInjectionContext, inject as inject$2, provide as provide$1, toRaw, isRef, isReactive, toRef, getCurrentInstance, ref, watch, reactive, markRaw, effectScope, nextTick, computed, getCurrentScope, onScopeDispose, toRefs, unref, h, onMounted, onUnmounted, shallowRef, watchEffect, defineComponent, resolveDynamicComponent, mergeProps } from 'vue';
2
+ import { hasInjectionContext, inject as inject$2, provide as provide$1, ref, computed, getCurrentScope, onScopeDispose, toRaw, isRef, isReactive, toRef, unref, h, onMounted, onUnmounted, watch, shallowRef, watchEffect, defineComponent, reactive, nextTick, getCurrentInstance, resolveDynamicComponent, mergeProps } from 'vue';
3
3
  import { Client, isClientTokenExpiredError, CookieName, ClientResponseErrorTokenHook } from '@authup/core-http-kit';
4
+ import { defineStore, storeToRefs as storeToRefs$1 } from 'pinia';
4
5
  import { Abilities, buildEventFullName, EventNameSuffix, hasOwnProperty, createNanoID, isOAuth2OpenIDProviderMetadata, isObject as isObject$1 } from '@authup/kit';
5
6
  import { merge, isObject, createMerger } from 'smob';
6
7
  import { buildList, SlotName } from '@vuecs/list-controls';
@@ -53,644 +54,6 @@ function injectHTTPClient(app) {
53
54
  return instance;
54
55
  }
55
56
 
56
- var isVue2 = false;
57
- function set(target, key, val) {
58
- if (Array.isArray(target)) {
59
- target.length = Math.max(target.length, key);
60
- target.splice(key, 1, val);
61
- return val;
62
- }
63
- target[key] = val;
64
- return val;
65
- }
66
- function del(target, key) {
67
- if (Array.isArray(target)) {
68
- target.splice(key, 1);
69
- return;
70
- }
71
- delete target[key];
72
- }
73
-
74
- /**
75
- * setActivePinia must be called to handle SSR at the top of functions like
76
- * `fetch`, `setup`, `serverPrefetch` and others
77
- */ let activePinia;
78
- /**
79
- * Sets or unsets the active pinia. Used in SSR and internally when calling
80
- * actions and getters
81
- *
82
- * @param pinia - Pinia instance
83
- */ // @ts-expect-error: cannot constrain the type of the return
84
- const setActivePinia = (pinia)=>activePinia = pinia;
85
- const piniaSymbol = process.env.NODE_ENV !== 'production' ? Symbol('pinia') : /* istanbul ignore next */ Symbol();
86
- function isPlainObject(// eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- o) {
88
- return o && typeof o === 'object' && Object.prototype.toString.call(o) === '[object Object]' && typeof o.toJSON !== 'function';
89
- }
90
- // type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> }
91
- // TODO: can we change these to numbers?
92
- /**
93
- * Possible types for SubscriptionCallback
94
- */ var MutationType;
95
- (function(MutationType) {
96
- /**
97
- * Direct mutation of the state:
98
- *
99
- * - `store.name = 'new name'`
100
- * - `store.$state.name = 'new name'`
101
- * - `store.list.push('new item')`
102
- */ MutationType["direct"] = "direct";
103
- /**
104
- * Mutated the state with `$patch` and an object
105
- *
106
- * - `store.$patch({ name: 'newName' })`
107
- */ MutationType["patchObject"] = "patch object";
108
- /**
109
- * Mutated the state with `$patch` and a function
110
- *
111
- * - `store.$patch(state => state.name = 'newName')`
112
- */ MutationType["patchFunction"] = "patch function";
113
- // maybe reset? for $state = {} and $reset
114
- })(MutationType || (MutationType = {}));
115
- const IS_CLIENT = typeof window !== 'undefined';
116
- /**
117
- * Should we add the devtools plugins.
118
- * - only if dev mode or forced through the prod devtools flag
119
- * - not in test
120
- * - only if window exists (could change in the future)
121
- */ const USE_DEVTOOLS = (process.env.NODE_ENV !== 'production' || typeof __VUE_PROD_DEVTOOLS__ !== 'undefined' && __VUE_PROD_DEVTOOLS__) && !(process.env.NODE_ENV === 'test') && IS_CLIENT;
122
- /**
123
- * Mutates in place `newState` with `oldState` to _hot update_ it. It will
124
- * remove any key not existing in `newState` and recursively merge plain
125
- * objects.
126
- *
127
- * @param newState - new state object to be patched
128
- * @param oldState - old state that should be used to patch newState
129
- * @returns - newState
130
- */ function patchObject(newState, oldState) {
131
- // no need to go through symbols because they cannot be serialized anyway
132
- for(const key in oldState){
133
- const subPatch = oldState[key];
134
- // skip the whole sub tree
135
- if (!(key in newState)) {
136
- continue;
137
- }
138
- const targetValue = newState[key];
139
- if (isPlainObject(targetValue) && isPlainObject(subPatch) && !isRef(subPatch) && !isReactive(subPatch)) {
140
- newState[key] = patchObject(targetValue, subPatch);
141
- } else {
142
- // objects are either a bit more complex (e.g. refs) or primitives, so we
143
- // just set the whole thing
144
- {
145
- newState[key] = subPatch;
146
- }
147
- }
148
- }
149
- return newState;
150
- }
151
- const noop$1 = ()=>{};
152
- function addSubscription(subscriptions, callback, detached, onCleanup = noop$1) {
153
- subscriptions.push(callback);
154
- const removeSubscription = ()=>{
155
- const idx = subscriptions.indexOf(callback);
156
- if (idx > -1) {
157
- subscriptions.splice(idx, 1);
158
- onCleanup();
159
- }
160
- };
161
- if (!detached && getCurrentScope()) {
162
- onScopeDispose(removeSubscription);
163
- }
164
- return removeSubscription;
165
- }
166
- function triggerSubscriptions(subscriptions, ...args) {
167
- subscriptions.slice().forEach((callback)=>{
168
- callback(...args);
169
- });
170
- }
171
- const fallbackRunWithContext = (fn)=>fn();
172
- function mergeReactiveObjects(target, patchToApply) {
173
- // Handle Map instances
174
- if (target instanceof Map && patchToApply instanceof Map) {
175
- patchToApply.forEach((value, key)=>target.set(key, value));
176
- }
177
- // Handle Set instances
178
- if (target instanceof Set && patchToApply instanceof Set) {
179
- patchToApply.forEach(target.add, target);
180
- }
181
- // no need to go through symbols because they cannot be serialized anyway
182
- for(const key in patchToApply){
183
- if (!patchToApply.hasOwnProperty(key)) continue;
184
- const subPatch = patchToApply[key];
185
- const targetValue = target[key];
186
- if (isPlainObject(targetValue) && isPlainObject(subPatch) && target.hasOwnProperty(key) && !isRef(subPatch) && !isReactive(subPatch)) {
187
- // NOTE: here I wanted to warn about inconsistent types but it's not possible because in setup stores one might
188
- // start the value of a property as a certain type e.g. a Map, and then for some reason, during SSR, change that
189
- // to `undefined`. When trying to hydrate, we want to override the Map with `undefined`.
190
- target[key] = mergeReactiveObjects(targetValue, subPatch);
191
- } else {
192
- // @ts-expect-error: subPatch is a valid value
193
- target[key] = subPatch;
194
- }
195
- }
196
- return target;
197
- }
198
- const skipHydrateSymbol = process.env.NODE_ENV !== 'production' ? Symbol('pinia:skipHydration') : /* istanbul ignore next */ Symbol();
199
- /**
200
- * Returns whether a value should be hydrated
201
- *
202
- * @param obj - target variable
203
- * @returns true if `obj` should be hydrated
204
- */ function shouldHydrate(obj) {
205
- return !isPlainObject(obj) || !obj.hasOwnProperty(skipHydrateSymbol);
206
- }
207
- const { assign } = Object;
208
- function isComputed(o) {
209
- return !!(isRef(o) && o.effect);
210
- }
211
- function createOptionsStore(id, options, pinia, hot) {
212
- const { state, actions, getters } = options;
213
- const initialState = pinia.state.value[id];
214
- let store;
215
- function setup() {
216
- if (!initialState && (!(process.env.NODE_ENV !== 'production') || !hot)) {
217
- /* istanbul ignore if */ {
218
- pinia.state.value[id] = state ? state() : {};
219
- }
220
- }
221
- // avoid creating a state in pinia.state.value
222
- const localState = process.env.NODE_ENV !== 'production' && hot ? toRefs(ref(state ? state() : {}).value) : toRefs(pinia.state.value[id]);
223
- return assign(localState, actions, Object.keys(getters || {}).reduce((computedGetters, name)=>{
224
- if (process.env.NODE_ENV !== 'production' && name in localState) {
225
- console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${name}" in store "${id}".`);
226
- }
227
- computedGetters[name] = markRaw(computed(()=>{
228
- setActivePinia(pinia);
229
- // it was created just before
230
- const store = pinia._s.get(id);
231
- // @ts-expect-error
232
- // return getters![name].call(context, context)
233
- // TODO: avoid reading the getter while assigning with a global variable
234
- return getters[name].call(store, store);
235
- }));
236
- return computedGetters;
237
- }, {}));
238
- }
239
- store = createSetupStore(id, setup, options, pinia, hot, true);
240
- return store;
241
- }
242
- function createSetupStore($id, setup, options = {}, pinia, hot, isOptionsStore) {
243
- let scope;
244
- const optionsForPlugin = assign({
245
- actions: {}
246
- }, options);
247
- /* istanbul ignore if */ if (process.env.NODE_ENV !== 'production' && !pinia._e.active) {
248
- throw new Error('Pinia destroyed');
249
- }
250
- // watcher options for $subscribe
251
- const $subscribeOptions = {
252
- deep: true
253
- };
254
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production' && !isVue2) {
255
- $subscribeOptions.onTrigger = (event)=>{
256
- /* istanbul ignore else */ if (isListening) {
257
- debuggerEvents = event;
258
- // avoid triggering this while the store is being built and the state is being set in pinia
259
- } else if (isListening == false && !store._hotUpdating) {
260
- // let patch send all the events together later
261
- /* istanbul ignore else */ if (Array.isArray(debuggerEvents)) {
262
- debuggerEvents.push(event);
263
- } else {
264
- console.error('🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug.');
265
- }
266
- }
267
- };
268
- }
269
- // internal state
270
- let isListening; // set to true at the end
271
- let isSyncListening; // set to true at the end
272
- let subscriptions = [];
273
- let actionSubscriptions = [];
274
- let debuggerEvents;
275
- const initialState = pinia.state.value[$id];
276
- // avoid setting the state for option stores if it is set
277
- // by the setup
278
- if (!isOptionsStore && !initialState && (!(process.env.NODE_ENV !== 'production') || !hot)) {
279
- /* istanbul ignore if */ {
280
- pinia.state.value[$id] = {};
281
- }
282
- }
283
- const hotState = ref({});
284
- // avoid triggering too many listeners
285
- // https://github.com/vuejs/pinia/issues/1129
286
- let activeListener;
287
- function $patch(partialStateOrMutator) {
288
- let subscriptionMutation;
289
- isListening = isSyncListening = false;
290
- // reset the debugger events since patches are sync
291
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
292
- debuggerEvents = [];
293
- }
294
- if (typeof partialStateOrMutator === 'function') {
295
- partialStateOrMutator(pinia.state.value[$id]);
296
- subscriptionMutation = {
297
- type: MutationType.patchFunction,
298
- storeId: $id,
299
- events: debuggerEvents
300
- };
301
- } else {
302
- mergeReactiveObjects(pinia.state.value[$id], partialStateOrMutator);
303
- subscriptionMutation = {
304
- type: MutationType.patchObject,
305
- payload: partialStateOrMutator,
306
- storeId: $id,
307
- events: debuggerEvents
308
- };
309
- }
310
- const myListenerId = activeListener = Symbol();
311
- nextTick().then(()=>{
312
- if (activeListener === myListenerId) {
313
- isListening = true;
314
- }
315
- });
316
- isSyncListening = true;
317
- // because we paused the watcher, we need to manually call the subscriptions
318
- triggerSubscriptions(subscriptions, subscriptionMutation, pinia.state.value[$id]);
319
- }
320
- const $reset = isOptionsStore ? function $reset() {
321
- const { state } = options;
322
- const newState = state ? state() : {};
323
- // we use a patch to group all changes into one single subscription
324
- this.$patch(($state)=>{
325
- assign($state, newState);
326
- });
327
- } : /* istanbul ignore next */ process.env.NODE_ENV !== 'production' ? ()=>{
328
- throw new Error(`🍍: Store "${$id}" is built using the setup syntax and does not implement $reset().`);
329
- } : noop$1;
330
- function $dispose() {
331
- scope.stop();
332
- subscriptions = [];
333
- actionSubscriptions = [];
334
- pinia._s.delete($id);
335
- }
336
- /**
337
- * Wraps an action to handle subscriptions.
338
- *
339
- * @param name - name of the action
340
- * @param action - action to wrap
341
- * @returns a wrapped action to handle subscriptions
342
- */ function wrapAction(name, action) {
343
- return function() {
344
- setActivePinia(pinia);
345
- const args = Array.from(arguments);
346
- const afterCallbackList = [];
347
- const onErrorCallbackList = [];
348
- function after(callback) {
349
- afterCallbackList.push(callback);
350
- }
351
- function onError(callback) {
352
- onErrorCallbackList.push(callback);
353
- }
354
- // @ts-expect-error
355
- triggerSubscriptions(actionSubscriptions, {
356
- args,
357
- name,
358
- store,
359
- after,
360
- onError
361
- });
362
- let ret;
363
- try {
364
- ret = action.apply(this && this.$id === $id ? this : store, args);
365
- // handle sync errors
366
- } catch (error) {
367
- triggerSubscriptions(onErrorCallbackList, error);
368
- throw error;
369
- }
370
- if (ret instanceof Promise) {
371
- return ret.then((value)=>{
372
- triggerSubscriptions(afterCallbackList, value);
373
- return value;
374
- }).catch((error)=>{
375
- triggerSubscriptions(onErrorCallbackList, error);
376
- return Promise.reject(error);
377
- });
378
- }
379
- // trigger after callbacks
380
- triggerSubscriptions(afterCallbackList, ret);
381
- return ret;
382
- };
383
- }
384
- const _hmrPayload = /*#__PURE__*/ markRaw({
385
- actions: {},
386
- getters: {},
387
- state: [],
388
- hotState
389
- });
390
- const partialStore = {
391
- _p: pinia,
392
- // _s: scope,
393
- $id,
394
- $onAction: addSubscription.bind(null, actionSubscriptions),
395
- $patch,
396
- $reset,
397
- $subscribe (callback, options = {}) {
398
- const removeSubscription = addSubscription(subscriptions, callback, options.detached, ()=>stopWatcher());
399
- const stopWatcher = scope.run(()=>watch(()=>pinia.state.value[$id], (state)=>{
400
- if (options.flush === 'sync' ? isSyncListening : isListening) {
401
- callback({
402
- storeId: $id,
403
- type: MutationType.direct,
404
- events: debuggerEvents
405
- }, state);
406
- }
407
- }, assign({}, $subscribeOptions, options)));
408
- return removeSubscription;
409
- },
410
- $dispose
411
- };
412
- const store = reactive(process.env.NODE_ENV !== 'production' || USE_DEVTOOLS ? assign({
413
- _hmrPayload,
414
- _customProperties: markRaw(new Set())
415
- }, partialStore) : partialStore);
416
- // store the partial store now so the setup of stores can instantiate each other before they are finished without
417
- // creating infinite loops.
418
- pinia._s.set($id, store);
419
- const runWithContext = pinia._a && pinia._a.runWithContext || fallbackRunWithContext;
420
- // TODO: idea create skipSerialize that marks properties as non serializable and they are skipped
421
- const setupStore = runWithContext(()=>pinia._e.run(()=>(scope = effectScope()).run(setup)));
422
- // overwrite existing actions to support $onAction
423
- for(const key in setupStore){
424
- const prop = setupStore[key];
425
- if (isRef(prop) && !isComputed(prop) || isReactive(prop)) {
426
- // mark it as a piece of state to be serialized
427
- if (process.env.NODE_ENV !== 'production' && hot) {
428
- set(hotState.value, key, toRef(setupStore, key));
429
- // createOptionStore directly sets the state in pinia.state.value so we
430
- // can just skip that
431
- } else if (!isOptionsStore) {
432
- // in setup stores we must hydrate the state and sync pinia state tree with the refs the user just created
433
- if (initialState && shouldHydrate(prop)) {
434
- if (isRef(prop)) {
435
- prop.value = initialState[key];
436
- } else {
437
- // probably a reactive object, lets recursively assign
438
- // @ts-expect-error: prop is unknown
439
- mergeReactiveObjects(prop, initialState[key]);
440
- }
441
- }
442
- // transfer the ref to the pinia state to keep everything in sync
443
- /* istanbul ignore if */ {
444
- pinia.state.value[$id][key] = prop;
445
- }
446
- }
447
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
448
- _hmrPayload.state.push(key);
449
- }
450
- // action
451
- } else if (typeof prop === 'function') {
452
- // @ts-expect-error: we are overriding the function we avoid wrapping if
453
- const actionValue = process.env.NODE_ENV !== 'production' && hot ? prop : wrapAction(key, prop);
454
- // this a hot module replacement store because the hotUpdate method needs
455
- // to do it with the right context
456
- /* istanbul ignore if */ {
457
- // @ts-expect-error
458
- setupStore[key] = actionValue;
459
- }
460
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
461
- _hmrPayload.actions[key] = prop;
462
- }
463
- // list actions so they can be used in plugins
464
- // @ts-expect-error
465
- optionsForPlugin.actions[key] = prop;
466
- } else if (process.env.NODE_ENV !== 'production') {
467
- // add getters for devtools
468
- if (isComputed(prop)) {
469
- _hmrPayload.getters[key] = isOptionsStore ? options.getters[key] : prop;
470
- if (IS_CLIENT) {
471
- const getters = setupStore._getters || // @ts-expect-error: same
472
- (setupStore._getters = markRaw([]));
473
- getters.push(key);
474
- }
475
- }
476
- }
477
- }
478
- // add the state, getters, and action properties
479
- /* istanbul ignore if */ {
480
- assign(store, setupStore);
481
- // allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.
482
- // Make `storeToRefs()` work with `reactive()` #799
483
- assign(toRaw(store), setupStore);
484
- }
485
- // use this instead of a computed with setter to be able to create it anywhere
486
- // without linking the computed lifespan to wherever the store is first
487
- // created.
488
- Object.defineProperty(store, '$state', {
489
- get: ()=>process.env.NODE_ENV !== 'production' && hot ? hotState.value : pinia.state.value[$id],
490
- set: (state)=>{
491
- /* istanbul ignore if */ if (process.env.NODE_ENV !== 'production' && hot) {
492
- throw new Error('cannot set hotState');
493
- }
494
- $patch(($state)=>{
495
- assign($state, state);
496
- });
497
- }
498
- });
499
- // add the hotUpdate before plugins to allow them to override it
500
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
501
- store._hotUpdate = markRaw((newStore)=>{
502
- store._hotUpdating = true;
503
- newStore._hmrPayload.state.forEach((stateKey)=>{
504
- if (stateKey in store.$state) {
505
- const newStateTarget = newStore.$state[stateKey];
506
- const oldStateSource = store.$state[stateKey];
507
- if (typeof newStateTarget === 'object' && isPlainObject(newStateTarget) && isPlainObject(oldStateSource)) {
508
- patchObject(newStateTarget, oldStateSource);
509
- } else {
510
- // transfer the ref
511
- newStore.$state[stateKey] = oldStateSource;
512
- }
513
- }
514
- // patch direct access properties to allow store.stateProperty to work as
515
- // store.$state.stateProperty
516
- set(store, stateKey, toRef(newStore.$state, stateKey));
517
- });
518
- // remove deleted state properties
519
- Object.keys(store.$state).forEach((stateKey)=>{
520
- if (!(stateKey in newStore.$state)) {
521
- del(store, stateKey);
522
- }
523
- });
524
- // avoid devtools logging this as a mutation
525
- isListening = false;
526
- isSyncListening = false;
527
- pinia.state.value[$id] = toRef(newStore._hmrPayload, 'hotState');
528
- isSyncListening = true;
529
- nextTick().then(()=>{
530
- isListening = true;
531
- });
532
- for(const actionName in newStore._hmrPayload.actions){
533
- const action = newStore[actionName];
534
- set(store, actionName, wrapAction(actionName, action));
535
- }
536
- // TODO: does this work in both setup and option store?
537
- for(const getterName in newStore._hmrPayload.getters){
538
- const getter = newStore._hmrPayload.getters[getterName];
539
- const getterValue = isOptionsStore ? computed(()=>{
540
- setActivePinia(pinia);
541
- return getter.call(store, store);
542
- }) : getter;
543
- set(store, getterName, getterValue);
544
- }
545
- // remove deleted getters
546
- Object.keys(store._hmrPayload.getters).forEach((key)=>{
547
- if (!(key in newStore._hmrPayload.getters)) {
548
- del(store, key);
549
- }
550
- });
551
- // remove old actions
552
- Object.keys(store._hmrPayload.actions).forEach((key)=>{
553
- if (!(key in newStore._hmrPayload.actions)) {
554
- del(store, key);
555
- }
556
- });
557
- // update the values used in devtools and to allow deleting new properties later on
558
- store._hmrPayload = newStore._hmrPayload;
559
- store._getters = newStore._getters;
560
- store._hotUpdating = false;
561
- });
562
- }
563
- if (USE_DEVTOOLS) {
564
- const nonEnumerable = {
565
- writable: true,
566
- configurable: true,
567
- // avoid warning on devtools trying to display this property
568
- enumerable: false
569
- };
570
- [
571
- '_p',
572
- '_hmrPayload',
573
- '_getters',
574
- '_customProperties'
575
- ].forEach((p)=>{
576
- Object.defineProperty(store, p, assign({
577
- value: store[p]
578
- }, nonEnumerable));
579
- });
580
- }
581
- // apply all plugins
582
- pinia._p.forEach((extender)=>{
583
- /* istanbul ignore else */ if (USE_DEVTOOLS) {
584
- const extensions = scope.run(()=>extender({
585
- store,
586
- app: pinia._a,
587
- pinia,
588
- options: optionsForPlugin
589
- }));
590
- Object.keys(extensions || {}).forEach((key)=>store._customProperties.add(key));
591
- assign(store, extensions);
592
- } else {
593
- assign(store, scope.run(()=>extender({
594
- store,
595
- app: pinia._a,
596
- pinia,
597
- options: optionsForPlugin
598
- })));
599
- }
600
- });
601
- if (process.env.NODE_ENV !== 'production' && store.$state && typeof store.$state === 'object' && typeof store.$state.constructor === 'function' && !store.$state.constructor.toString().includes('[native code]')) {
602
- console.warn(`[🍍]: The "state" must be a plain object. It cannot be\n` + `\tstate: () => new MyClass()\n` + `Found in store "${store.$id}".`);
603
- }
604
- // only apply hydrate to option stores with an initial state in pinia
605
- if (initialState && isOptionsStore && options.hydrate) {
606
- options.hydrate(store.$state, initialState);
607
- }
608
- isListening = true;
609
- isSyncListening = true;
610
- return store;
611
- }
612
- function defineStore(// TODO: add proper types from above
613
- idOrOptions, setup, setupOptions) {
614
- let id;
615
- let options;
616
- const isSetupStore = typeof setup === 'function';
617
- {
618
- id = idOrOptions;
619
- // the option store setup will contain the actual options in this case
620
- options = isSetupStore ? setupOptions : setup;
621
- }
622
- function useStore(pinia, hot) {
623
- const hasContext = hasInjectionContext();
624
- pinia = // in test mode, ignore the argument provided as we can always retrieve a
625
- // pinia instance with getActivePinia()
626
- (process.env.NODE_ENV === 'test' && activePinia && activePinia._testing ? null : pinia) || (hasContext ? inject$2(piniaSymbol, null) : null);
627
- if (pinia) setActivePinia(pinia);
628
- if (process.env.NODE_ENV !== 'production' && !activePinia) {
629
- throw new Error(`[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"?\n` + `See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help.\n` + `This will fail in production.`);
630
- }
631
- pinia = activePinia;
632
- if (!pinia._s.has(id)) {
633
- // creating the store registers it in `pinia._s`
634
- if (isSetupStore) {
635
- createSetupStore(id, setup, options, pinia);
636
- } else {
637
- createOptionsStore(id, options, pinia);
638
- }
639
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
640
- // @ts-expect-error: not the right inferred type
641
- useStore._pinia = pinia;
642
- }
643
- }
644
- const store = pinia._s.get(id);
645
- if (process.env.NODE_ENV !== 'production' && hot) {
646
- const hotId = '__hot:' + id;
647
- const newStore = isSetupStore ? createSetupStore(hotId, setup, options, pinia, true) : createOptionsStore(hotId, assign({}, options), pinia, true);
648
- hot._hotUpdate(newStore);
649
- // cleanup the state properties and the store from the cache
650
- delete pinia.state.value[hotId];
651
- pinia._s.delete(hotId);
652
- }
653
- if (process.env.NODE_ENV !== 'production' && IS_CLIENT) {
654
- const currentInstance = getCurrentInstance();
655
- // save stores in instances to access them devtools
656
- if (currentInstance && currentInstance.proxy && // avoid adding stores that are just built for hot module replacement
657
- !hot) {
658
- const vm = currentInstance.proxy;
659
- const cache = '_pStores' in vm ? vm._pStores : vm._pStores = {};
660
- cache[id] = store;
661
- }
662
- }
663
- // StoreGeneric cannot be casted towards Store
664
- return store;
665
- }
666
- useStore.$id = id;
667
- return useStore;
668
- }
669
- /**
670
- * Creates an object of references with all the state, getters, and plugin-added
671
- * state properties of the store. Similar to `toRefs()` but specifically
672
- * designed for Pinia stores so methods and non reactive properties are
673
- * completely ignored.
674
- *
675
- * @param store - store to extract the refs from
676
- */ function storeToRefs$1(store) {
677
- // See https://github.com/vuejs/pinia/issues/852
678
- // It's easier to just use toRefs() even if it includes more stuff
679
- {
680
- store = toRaw(store);
681
- const refs = {};
682
- for(const key in store){
683
- const value = store[key];
684
- if (isRef(value) || isReactive(value)) {
685
- // @ts-expect-error: the key is state or getter
686
- refs[key] = // ---
687
- toRef(store, key);
688
- }
689
- }
690
- return refs;
691
- }
692
- }
693
-
694
57
  /*
695
58
  * Copyright (c) 2024.
696
59
  * Author Peter Placzek (tada5hi)
@@ -988,7 +351,7 @@ function installStore(app, options = {}) {
988
351
  const storeCreator = defineStore(STORE_ID, ()=>createStore({
989
352
  baseURL: options.baseURL
990
353
  }));
991
- const store = storeCreator();
354
+ const store = storeCreator(options.pinia);
992
355
  const cookies = useCookies();
993
356
  let cookieGet;
994
357
  if (options.cookieGet) {
@@ -1119,7 +482,7 @@ function installHTTPClient(app, options = {}) {
1119
482
  baseURL: options.baseURL
1120
483
  });
1121
484
  const storeCreator = injectStore(app);
1122
- const store = storeCreator();
485
+ const store = storeCreator(options.pinia);
1123
486
  const { refreshToken } = storeToRefs$1(store);
1124
487
  const tokenHook = new ClientResponseErrorTokenHook(client, {
1125
488
  baseURL: options.baseURL,
@@ -7332,10 +6695,12 @@ function install(app1, options) {
7332
6695
  baseURL: options.baseURL,
7333
6696
  cookieSet: options.cookieSet,
7334
6697
  cookieGet: options.cookieGet,
7335
- cookieUnset: options.cookieUnset
6698
+ cookieUnset: options.cookieUnset,
6699
+ pinia: options.pinia
7336
6700
  });
7337
6701
  installHTTPClient(app1, {
7338
- baseURL: options.baseURL
6702
+ baseURL: options.baseURL,
6703
+ pinia: options.pinia
7339
6704
  });
7340
6705
  installTranslator(app1, {
7341
6706
  locale: options.translatorLocale