@authup/client-web-kit 1.0.0-beta.25 → 1.0.0-beta.26

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/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2021-2025 Peter Placzek
189
+ Copyright 2021-2025 Peter Placzek <peter.placzek1996@gmail.com>
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
@@ -0,0 +1,3 @@
1
+ export * from './install';
2
+ export * from './singleton';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/http-client/authentication-hook/index.ts"],"names":[],"mappings":"AAOA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { App } from 'vue';
2
+ import type { HTTPClientAuthenticationHookInstallOptions } from './types';
3
+ export declare function installHTTPClientAuthenticationHook(app: App, options?: HTTPClientAuthenticationHookInstallOptions): void;
4
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../../src/core/http-client/authentication-hook/install.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAI/B,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,SAAS,CAAC;AAE1E,wBAAgB,mCAAmC,CAC/C,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,0CAA+C,QA+E3D"}
@@ -0,0 +1,6 @@
1
+ import type { App } from 'vue';
2
+ import type { ClientAuthenticationHook } from '@authup/core-http-kit';
3
+ export declare function injectHTTPClientAuthenticationHook(app?: App): ClientAuthenticationHook;
4
+ export declare function hasHTTPClientAuthenticationHook(app?: App): boolean;
5
+ export declare function provideHTTPClientAuthenticationHook(refresher: ClientAuthenticationHook, app?: App): void;
6
+ //# sourceMappingURL=singleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../../../../src/core/http-client/authentication-hook/singleton.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAMtE,wBAAgB,kCAAkC,CAAC,GAAG,CAAC,EAAE,GAAG,GAAI,wBAAwB,CAOvF;AAED,wBAAgB,+BAA+B,CAAC,GAAG,CAAC,EAAE,GAAG,GAAI,OAAO,CAMnE;AAED,wBAAgB,mCAAmC,CAC/C,SAAS,EAAE,wBAAwB,EACnC,GAAG,CAAC,EAAE,GAAG,QAGZ"}
@@ -0,0 +1,7 @@
1
+ import type { Pinia } from 'pinia';
2
+ export type HTTPClientAuthenticationHookInstallOptions = {
3
+ baseURL?: string;
4
+ pinia?: Pinia;
5
+ isServer?: boolean;
6
+ };
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/http-client/authentication-hook/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAEnC,MAAM,MAAM,0CAA0C,GAAG;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACrB,CAAC"}
@@ -1,3 +1,4 @@
1
+ export * from './authentication-hook';
1
2
  export * from './singleton';
2
3
  export * from './install';
3
4
  export * from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/http-client/index.ts"],"names":[],"mappings":"AAOA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/http-client/index.ts"],"names":[],"mappings":"AAOA,cAAc,uBAAuB,CAAC;AAEtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/core/http-client/install.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAI/B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,wBAA6B,QA2FjF"}
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/core/http-client/install.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAGxD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,wBAA6B,QAWjF"}
@@ -1 +1 @@
1
- {"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../../../src/core/http-client/singleton.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAI/B,eAAO,MAAM,gBAAgB,eAAiC,CAAC;AAE/D,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,QAE1D;AAED,wBAAgB,aAAa,CAAC,GAAG,CAAC,EAAE,GAAG,GAAI,OAAO,CAEjD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,CAAC,EAAE,GAAG,UAOzC"}
1
+ {"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../../../src/core/http-client/singleton.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAI/B,eAAO,MAAM,gBAAgB,eAAiC,CAAC;AAE/D,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,QAE1D;AAED,wBAAgB,aAAa,CAAC,GAAG,CAAC,EAAE,GAAG,GAAI,OAAO,CAMjD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,CAAC,EAAE,GAAG,UAOzC"}
package/dist/index.cjs CHANGED
@@ -11,8 +11,8 @@ var validators = require('@vuelidate/validators');
11
11
  var listControls = require('@vuecs/list-controls');
12
12
  var coreHttpKit = require('@authup/core-http-kit');
13
13
  var pinia = require('pinia');
14
- var specs = require('@authup/specs');
15
14
  var access = require('@authup/access');
15
+ var specs = require('@authup/specs');
16
16
  var smob = require('smob');
17
17
  var kit = require('@authup/kit');
18
18
  var rapiq = require('rapiq');
@@ -157,20 +157,24 @@ function provide(key, value, app) {
157
157
  app.provide(key, value);
158
158
  }
159
159
 
160
- const HTTPClientSymbol = Symbol.for('AuthupHTTPClient');
161
- function provideHTTPClient(client, app) {
162
- provide(HTTPClientSymbol, client, app);
163
- }
164
- function hasHTTPClient(app) {
165
- return !!inject$1(HTTPClientSymbol, app);
166
- }
167
- function injectHTTPClient(app) {
168
- const instance = inject$1(HTTPClientSymbol, app);
160
+ const sym$2 = Symbol.for('AuthupHTTPClientAuthenticationHook');
161
+ function injectHTTPClientAuthenticationHook(app) {
162
+ const instance = inject$1(sym$2, app);
169
163
  if (!instance) {
170
- throw new Error('The api client has not been injected.');
164
+ throw new Error('The http client authentication hook has not been injected in the app context.');
171
165
  }
172
166
  return instance;
173
167
  }
168
+ function hasHTTPClientAuthenticationHook(app) {
169
+ try {
170
+ return !!injectHTTPClientAuthenticationHook(app);
171
+ } catch (e) {
172
+ return false;
173
+ }
174
+ }
175
+ function provideHTTPClientAuthenticationHook(refresher, app) {
176
+ provide(sym$2, refresher, app);
177
+ }
174
178
 
175
179
  /*
176
180
  * Copyright (c) 2024.
@@ -768,71 +772,93 @@ function storeToRefs(store) {
768
772
  return refs;
769
773
  }
770
774
 
771
- function installHTTPClient(app, options = {}) {
772
- if (hasHTTPClient(app)) {
775
+ function installHTTPClientAuthenticationHook(app, options = {}) {
776
+ if (hasHTTPClientAuthenticationHook(app)) {
773
777
  return;
774
778
  }
775
- const client = new coreHttpKit.Client({
776
- baseURL: options.baseURL
777
- });
778
779
  const storeFactory = injectStoreFactory(app);
779
780
  const store = storeFactory(options.pinia);
780
781
  const { refreshToken } = pinia.storeToRefs(store);
781
- client.on('responseError', (err)=>{
782
- const { request } = err;
783
- const code = coreHttpKit.getClientErrorCode(err);
784
- if (specs.isJWKErrorCode(code)) {
785
- return store.logout().then(()=>{
786
- if (request.headers) {
787
- coreHttpKit.unsetHeader(request.headers, 'authorization');
788
- return client.request(request);
789
- }
790
- return Promise.reject(err);
791
- });
792
- }
793
- return Promise.reject(err);
794
- });
795
- const tokenHook = new coreHttpKit.ClientResponseErrorTokenHook({
782
+ const hook = new coreHttpKit.ClientAuthenticationHook({
796
783
  baseURL: options.baseURL,
797
784
  tokenCreator: ()=>{
798
785
  if (!refreshToken.value) {
799
786
  throw new Error('No refresh token available.');
800
787
  }
788
+ const client = new coreHttpKit.Client({
789
+ baseURL: options.baseURL
790
+ });
801
791
  return client.token.createWithRefreshToken({
802
792
  refresh_token: refreshToken.value
803
793
  });
804
794
  },
805
795
  timer: !options.isServer
806
796
  });
807
- tokenHook.on(coreHttpKit.ClientResponseTokenHookEventName.REFRESH_FINISHED, (response)=>{
797
+ hook.on(coreHttpKit.ClientAuthenticationHookEventName.REFRESH_FINISHED, (response)=>{
808
798
  store.applyTokenGrantResponse(response);
809
799
  });
810
- tokenHook.on(coreHttpKit.ClientResponseTokenHookEventName.REFRESH_FAILED, ()=>{
811
- Promise.resolve().then(()=>store.logout());
800
+ let isSelfCallee = false;
801
+ hook.on(coreHttpKit.ClientAuthenticationHookEventName.HEADER_UNSET, ()=>{
802
+ if (!isSelfCallee) {
803
+ Promise.resolve().then(()=>store.logout());
804
+ }
812
805
  });
813
806
  const storeDispatcher = injectStoreDispatcher(app);
814
807
  const handleAccessTokenEvent = ()=>{
808
+ isSelfCallee = true;
815
809
  if (store.accessToken) {
816
- client.setAuthorizationHeader({
810
+ hook.enable();
811
+ hook.setAuthorizationHeader({
817
812
  type: 'Bearer',
818
813
  token: store.accessToken
819
814
  });
820
- tokenHook.mount(client);
821
815
  } else {
822
- client.unsetAuthorizationHeader();
823
- tokenHook.unmount(client);
816
+ hook.disable();
817
+ hook.unsetAuthorizationHeader();
824
818
  }
819
+ isSelfCallee = false;
825
820
  };
826
821
  const handleAccessTokenExpireDateEvent = ()=>{
827
822
  if (store.accessTokenExpireDate) {
828
823
  const expiresIn = Math.floor((store.accessTokenExpireDate.getTime() - Date.now()) / 1000);
829
- tokenHook.setTimer(expiresIn);
824
+ hook.setTimer(expiresIn);
830
825
  }
831
826
  };
832
827
  storeDispatcher.on(StoreDispatcherEventName.ACCESS_TOKEN_UPDATED, ()=>handleAccessTokenEvent());
833
828
  storeDispatcher.on(StoreDispatcherEventName.ACCESS_TOKEN_EXPIRE_DATE_UPDATED, ()=>handleAccessTokenExpireDateEvent());
834
829
  handleAccessTokenEvent();
835
830
  handleAccessTokenExpireDateEvent();
831
+ provideHTTPClientAuthenticationHook(hook, app);
832
+ }
833
+
834
+ const HTTPClientSymbol = Symbol.for('AuthupHTTPClient');
835
+ function provideHTTPClient(client, app) {
836
+ provide(HTTPClientSymbol, client, app);
837
+ }
838
+ function hasHTTPClient(app) {
839
+ try {
840
+ return !!injectHTTPClient(app);
841
+ } catch (e) {
842
+ return false;
843
+ }
844
+ }
845
+ function injectHTTPClient(app) {
846
+ const instance = inject$1(HTTPClientSymbol, app);
847
+ if (!instance) {
848
+ throw new Error('The api client has not been injected.');
849
+ }
850
+ return instance;
851
+ }
852
+
853
+ function installHTTPClient(app, options = {}) {
854
+ if (hasHTTPClient(app)) {
855
+ return;
856
+ }
857
+ const client = new coreHttpKit.Client({
858
+ baseURL: options.baseURL
859
+ });
860
+ const authenticationHook = injectHTTPClientAuthenticationHook(app);
861
+ authenticationHook.attach(client);
836
862
  provideHTTPClient(client, app);
837
863
  }
838
864
 
@@ -9448,6 +9474,11 @@ function install(app, options) {
9448
9474
  cookieGet: options.cookieGet,
9449
9475
  cookieUnset: options.cookieUnset
9450
9476
  });
9477
+ installHTTPClientAuthenticationHook(app, {
9478
+ pinia: options.pinia,
9479
+ baseURL: options.baseURL,
9480
+ isServer: options.isServer
9481
+ });
9451
9482
  installHTTPClient(app, {
9452
9483
  pinia: options.pinia,
9453
9484
  baseURL: options.baseURL,
@@ -9577,10 +9608,12 @@ exports.defineEntityVProps = defineEntityVProps;
9577
9608
  exports.extractVuelidateResultsFromChild = extractVuelidateResultsFromChild;
9578
9609
  exports.getVuelidateSeverity = getVuelidateSeverity;
9579
9610
  exports.hasHTTPClient = hasHTTPClient;
9611
+ exports.hasHTTPClientAuthenticationHook = hasHTTPClientAuthenticationHook;
9580
9612
  exports.hasNormalizedSlot = hasNormalizedSlot;
9581
9613
  exports.hasStoreFactory = hasStoreFactory;
9582
9614
  exports.inject = inject$1;
9583
9615
  exports.injectHTTPClient = injectHTTPClient;
9616
+ exports.injectHTTPClientAuthenticationHook = injectHTTPClientAuthenticationHook;
9584
9617
  exports.injectSocketManager = injectSocketManager;
9585
9618
  exports.injectStore = injectStore;
9586
9619
  exports.injectStoreDispatcher = injectStoreDispatcher;
@@ -9588,6 +9621,7 @@ exports.injectStoreFactory = injectStoreFactory;
9588
9621
  exports.injectTranslatorLocale = injectTranslatorLocale;
9589
9622
  exports.install = install;
9590
9623
  exports.installHTTPClient = installHTTPClient;
9624
+ exports.installHTTPClientAuthenticationHook = installHTTPClientAuthenticationHook;
9591
9625
  exports.installSocketManager = installSocketManager;
9592
9626
  exports.installStore = installStore;
9593
9627
  exports.installTranslator = installTranslator;
@@ -9598,6 +9632,7 @@ exports.normalizeSlot = normalizeSlot;
9598
9632
  exports.onChange = onChange;
9599
9633
  exports.provide = provide;
9600
9634
  exports.provideHTTPClient = provideHTTPClient;
9635
+ exports.provideHTTPClientAuthenticationHook = provideHTTPClientAuthenticationHook;
9601
9636
  exports.provideSocketManager = provideSocketManager;
9602
9637
  exports.provideStoreDispatcher = provideStoreDispatcher;
9603
9638
  exports.provideStoreFactory = provideStoreFactory;