@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 +1 -1
- package/dist/core/http-client/authentication-hook/index.d.ts +3 -0
- package/dist/core/http-client/authentication-hook/index.d.ts.map +1 -0
- package/dist/core/http-client/authentication-hook/install.d.ts +4 -0
- package/dist/core/http-client/authentication-hook/install.d.ts.map +1 -0
- package/dist/core/http-client/authentication-hook/singleton.d.ts +6 -0
- package/dist/core/http-client/authentication-hook/singleton.d.ts.map +1 -0
- package/dist/core/http-client/authentication-hook/types.d.ts +7 -0
- package/dist/core/http-client/authentication-hook/types.d.ts.map +1 -0
- package/dist/core/http-client/index.d.ts +1 -0
- package/dist/core/http-client/index.d.ts.map +1 -1
- package/dist/core/http-client/install.d.ts.map +1 -1
- package/dist/core/http-client/singleton.d.ts.map +1 -1
- package/dist/index.cjs +74 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +72 -41
- package/dist/index.mjs.map +1 -1
- package/dist/module.d.ts.map +1 -1
- package/package.json +15 -15
package/dist/index.mjs
CHANGED
|
@@ -5,10 +5,10 @@ import { VCFormGroup, VCFormInput, buildFormSubmit, buildFormInputText, buildFor
|
|
|
5
5
|
import useVuelidate from '@vuelidate/core';
|
|
6
6
|
import { maxLength, minLength, required, helpers, url, numeric, maxValue, minValue, email, sameAs } from '@vuelidate/validators';
|
|
7
7
|
import { SlotName, buildList } from '@vuecs/list-controls';
|
|
8
|
-
import { Client, CookieName,
|
|
8
|
+
import { Client, CookieName, ClientAuthenticationHook, ClientAuthenticationHookEventName } from '@authup/core-http-kit';
|
|
9
9
|
import { defineStore, storeToRefs as storeToRefs$1 } from 'pinia';
|
|
10
|
-
import { OAuth2Error, isJWKErrorCode, isOpenIDProviderMetadata } from '@authup/specs';
|
|
11
10
|
import { PermissionMemoryProvider, PermissionChecker, PolicyEngine, TimePolicyInterval, isIntervalForDayOfWeek, isIntervalForDayOfMonth, isIntervalForDayOfYear, BuiltInPolicyType } from '@authup/access';
|
|
11
|
+
import { OAuth2Error, isOpenIDProviderMetadata } from '@authup/specs';
|
|
12
12
|
import { isObject as isObject$1, merge, createMerger } from 'smob';
|
|
13
13
|
import { hasOwnProperty, extendObject, isObject as isObject$2, createNanoID } from '@authup/kit';
|
|
14
14
|
import { SortDirection } from 'rapiq';
|
|
@@ -153,20 +153,24 @@ function provide(key, value, app) {
|
|
|
153
153
|
app.provide(key, value);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
const
|
|
157
|
-
function
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
function hasHTTPClient(app) {
|
|
161
|
-
return !!inject$1(HTTPClientSymbol, app);
|
|
162
|
-
}
|
|
163
|
-
function injectHTTPClient(app) {
|
|
164
|
-
const instance = inject$1(HTTPClientSymbol, app);
|
|
156
|
+
const sym$2 = Symbol.for('AuthupHTTPClientAuthenticationHook');
|
|
157
|
+
function injectHTTPClientAuthenticationHook(app) {
|
|
158
|
+
const instance = inject$1(sym$2, app);
|
|
165
159
|
if (!instance) {
|
|
166
|
-
throw new Error('The
|
|
160
|
+
throw new Error('The http client authentication hook has not been injected in the app context.');
|
|
167
161
|
}
|
|
168
162
|
return instance;
|
|
169
163
|
}
|
|
164
|
+
function hasHTTPClientAuthenticationHook(app) {
|
|
165
|
+
try {
|
|
166
|
+
return !!injectHTTPClientAuthenticationHook(app);
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function provideHTTPClientAuthenticationHook(refresher, app) {
|
|
172
|
+
provide(sym$2, refresher, app);
|
|
173
|
+
}
|
|
170
174
|
|
|
171
175
|
/*
|
|
172
176
|
* Copyright (c) 2024.
|
|
@@ -764,71 +768,93 @@ function storeToRefs(store) {
|
|
|
764
768
|
return refs;
|
|
765
769
|
}
|
|
766
770
|
|
|
767
|
-
function
|
|
768
|
-
if (
|
|
771
|
+
function installHTTPClientAuthenticationHook(app, options = {}) {
|
|
772
|
+
if (hasHTTPClientAuthenticationHook(app)) {
|
|
769
773
|
return;
|
|
770
774
|
}
|
|
771
|
-
const client = new Client({
|
|
772
|
-
baseURL: options.baseURL
|
|
773
|
-
});
|
|
774
775
|
const storeFactory = injectStoreFactory(app);
|
|
775
776
|
const store = storeFactory(options.pinia);
|
|
776
777
|
const { refreshToken } = storeToRefs$1(store);
|
|
777
|
-
|
|
778
|
-
const { request } = err;
|
|
779
|
-
const code = getClientErrorCode(err);
|
|
780
|
-
if (isJWKErrorCode(code)) {
|
|
781
|
-
return store.logout().then(()=>{
|
|
782
|
-
if (request.headers) {
|
|
783
|
-
unsetHeader(request.headers, 'authorization');
|
|
784
|
-
return client.request(request);
|
|
785
|
-
}
|
|
786
|
-
return Promise.reject(err);
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
return Promise.reject(err);
|
|
790
|
-
});
|
|
791
|
-
const tokenHook = new ClientResponseErrorTokenHook({
|
|
778
|
+
const hook = new ClientAuthenticationHook({
|
|
792
779
|
baseURL: options.baseURL,
|
|
793
780
|
tokenCreator: ()=>{
|
|
794
781
|
if (!refreshToken.value) {
|
|
795
782
|
throw new Error('No refresh token available.');
|
|
796
783
|
}
|
|
784
|
+
const client = new Client({
|
|
785
|
+
baseURL: options.baseURL
|
|
786
|
+
});
|
|
797
787
|
return client.token.createWithRefreshToken({
|
|
798
788
|
refresh_token: refreshToken.value
|
|
799
789
|
});
|
|
800
790
|
},
|
|
801
791
|
timer: !options.isServer
|
|
802
792
|
});
|
|
803
|
-
|
|
793
|
+
hook.on(ClientAuthenticationHookEventName.REFRESH_FINISHED, (response)=>{
|
|
804
794
|
store.applyTokenGrantResponse(response);
|
|
805
795
|
});
|
|
806
|
-
|
|
807
|
-
|
|
796
|
+
let isSelfCallee = false;
|
|
797
|
+
hook.on(ClientAuthenticationHookEventName.HEADER_UNSET, ()=>{
|
|
798
|
+
if (!isSelfCallee) {
|
|
799
|
+
Promise.resolve().then(()=>store.logout());
|
|
800
|
+
}
|
|
808
801
|
});
|
|
809
802
|
const storeDispatcher = injectStoreDispatcher(app);
|
|
810
803
|
const handleAccessTokenEvent = ()=>{
|
|
804
|
+
isSelfCallee = true;
|
|
811
805
|
if (store.accessToken) {
|
|
812
|
-
|
|
806
|
+
hook.enable();
|
|
807
|
+
hook.setAuthorizationHeader({
|
|
813
808
|
type: 'Bearer',
|
|
814
809
|
token: store.accessToken
|
|
815
810
|
});
|
|
816
|
-
tokenHook.mount(client);
|
|
817
811
|
} else {
|
|
818
|
-
|
|
819
|
-
|
|
812
|
+
hook.disable();
|
|
813
|
+
hook.unsetAuthorizationHeader();
|
|
820
814
|
}
|
|
815
|
+
isSelfCallee = false;
|
|
821
816
|
};
|
|
822
817
|
const handleAccessTokenExpireDateEvent = ()=>{
|
|
823
818
|
if (store.accessTokenExpireDate) {
|
|
824
819
|
const expiresIn = Math.floor((store.accessTokenExpireDate.getTime() - Date.now()) / 1000);
|
|
825
|
-
|
|
820
|
+
hook.setTimer(expiresIn);
|
|
826
821
|
}
|
|
827
822
|
};
|
|
828
823
|
storeDispatcher.on(StoreDispatcherEventName.ACCESS_TOKEN_UPDATED, ()=>handleAccessTokenEvent());
|
|
829
824
|
storeDispatcher.on(StoreDispatcherEventName.ACCESS_TOKEN_EXPIRE_DATE_UPDATED, ()=>handleAccessTokenExpireDateEvent());
|
|
830
825
|
handleAccessTokenEvent();
|
|
831
826
|
handleAccessTokenExpireDateEvent();
|
|
827
|
+
provideHTTPClientAuthenticationHook(hook, app);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
const HTTPClientSymbol = Symbol.for('AuthupHTTPClient');
|
|
831
|
+
function provideHTTPClient(client, app) {
|
|
832
|
+
provide(HTTPClientSymbol, client, app);
|
|
833
|
+
}
|
|
834
|
+
function hasHTTPClient(app) {
|
|
835
|
+
try {
|
|
836
|
+
return !!injectHTTPClient(app);
|
|
837
|
+
} catch (e) {
|
|
838
|
+
return false;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
function injectHTTPClient(app) {
|
|
842
|
+
const instance = inject$1(HTTPClientSymbol, app);
|
|
843
|
+
if (!instance) {
|
|
844
|
+
throw new Error('The api client has not been injected.');
|
|
845
|
+
}
|
|
846
|
+
return instance;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
function installHTTPClient(app, options = {}) {
|
|
850
|
+
if (hasHTTPClient(app)) {
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
const client = new Client({
|
|
854
|
+
baseURL: options.baseURL
|
|
855
|
+
});
|
|
856
|
+
const authenticationHook = injectHTTPClientAuthenticationHook(app);
|
|
857
|
+
authenticationHook.attach(client);
|
|
832
858
|
provideHTTPClient(client, app);
|
|
833
859
|
}
|
|
834
860
|
|
|
@@ -9444,6 +9470,11 @@ function install(app, options) {
|
|
|
9444
9470
|
cookieGet: options.cookieGet,
|
|
9445
9471
|
cookieUnset: options.cookieUnset
|
|
9446
9472
|
});
|
|
9473
|
+
installHTTPClientAuthenticationHook(app, {
|
|
9474
|
+
pinia: options.pinia,
|
|
9475
|
+
baseURL: options.baseURL,
|
|
9476
|
+
isServer: options.isServer
|
|
9477
|
+
});
|
|
9447
9478
|
installHTTPClient(app, {
|
|
9448
9479
|
pinia: options.pinia,
|
|
9449
9480
|
baseURL: options.baseURL,
|
|
@@ -9459,5 +9490,5 @@ var index = {
|
|
|
9459
9490
|
install
|
|
9460
9491
|
};
|
|
9461
9492
|
|
|
9462
|
-
export { AAttributeNamesPolicyForm, AClient, AClientForm, AClientPermissionAssignment, AClientPermissionAssignments, AClientPicker, AClientRoleAssignment, AClientRoleAssignments, AClientScope, AClientScopeAssignment, AClientScopeAssignments, AClientScopes, AClients, ACompositePolicyForm, ADatePolicyForm, AEntityDelete, AFormInputList, AFormInputListItem, AFormSubmit, AIdentityPolicyForm, AIdentityProvider, AIdentityProviderForm, AIdentityProviderIcon, AIdentityProviderLdapForm, AIdentityProviderOAuth2Form, AIdentityProviderPreset, AIdentityProviderProtocol, AIdentityProviderRoleAssignment, AIdentityProviderRoleAssignments, AIdentityProviders, APagination, APermission, APermissionCheck, APermissionClientAssignments, APermissionForm, APermissionRobotAssignments, APermissionRoleAssignments, APermissionUserAssignments, APermissions, APolicies, APolicy, APolicyForm, APolicyTypePicker, ARealm, ARealmForm, ARealmMatchPolicyForm, ARealmPicker, ARealms, ARobot, ARobotForm, ARobotPermissionAssignment, ARobotPermissionAssignments, ARobotRoleAssignment, ARobotRoleAssignments, ARobots, ARole, ARoleClientAssignments, ARoleForm, ARolePermissionAssignment, ARolePermissionAssignments, ARoleRobotAssignments, ARoleUserAssignments, ARoles, AScope, AScopeClientAssignments, AScopeForm, AScopes, ASearch, ATimePolicyForm, ATitle, AUser, AUserForm, AUserPasswordForm, AUserPermissionAssignment, AUserPermissionAssignments, AUserRoleAssignment, AUserRoleAssignments, AUsers, EntityRecordError, HTTPClientSymbol, LanguageSwitcherDropdown, STORE_ID, SocketClientSymbol, StoreDispatcherEventName, TranslatorTranslationClientKey, TranslatorTranslationDefaultKey, TranslatorTranslationGroup, TranslatorTranslationVuecsKey, VuelidateCustomRule, VuelidateCustomRuleKey, assignFormProperties, buildEntityCollectionCreatedHandler, buildEntityCollectionDeletedHandler, buildEntityCollectionUpdatedHandler, buildEntityVSlotProps, buildFormSubmitWithTranslations, createFormSubmitTranslations, createPermissionCheckerReactiveFn, createStore, createStoreDispatcher, index as default, defineEntityCollectionManager, defineEntityCollectionVEmitOptions, defineEntityCollectionVProps, defineEntityManager, defineEntityPicker, defineEntityPickerVEmitOptions, defineEntityPickerVProps, defineEntitySocketManager, defineEntityVEmitOptions, defineEntityVProps, extractVuelidateResultsFromChild, getVuelidateSeverity, hasHTTPClient, hasNormalizedSlot, hasStoreFactory, inject$1 as inject, injectHTTPClient, injectSocketManager, injectStore, injectStoreDispatcher, injectStoreFactory, injectTranslatorLocale, install, installHTTPClient, installSocketManager, installStore, installTranslator, isQuerySortedDescByDate, isSocketManagerUsable, mergeEntityCollectionRenderOptions, normalizeSlot, onChange, provide, provideHTTPClient, provideSocketManager, provideStoreDispatcher, provideStoreFactory, renderToggleButton, storeToRefs, useIsEditing, usePermissionCheck, useTranslation, useTranslationsForBaseValidation, useTranslationsForGroup, useTranslationsForNestedValidation, useUpdatedAt, wrapFnWithBusyState };
|
|
9493
|
+
export { AAttributeNamesPolicyForm, AClient, AClientForm, AClientPermissionAssignment, AClientPermissionAssignments, AClientPicker, AClientRoleAssignment, AClientRoleAssignments, AClientScope, AClientScopeAssignment, AClientScopeAssignments, AClientScopes, AClients, ACompositePolicyForm, ADatePolicyForm, AEntityDelete, AFormInputList, AFormInputListItem, AFormSubmit, AIdentityPolicyForm, AIdentityProvider, AIdentityProviderForm, AIdentityProviderIcon, AIdentityProviderLdapForm, AIdentityProviderOAuth2Form, AIdentityProviderPreset, AIdentityProviderProtocol, AIdentityProviderRoleAssignment, AIdentityProviderRoleAssignments, AIdentityProviders, APagination, APermission, APermissionCheck, APermissionClientAssignments, APermissionForm, APermissionRobotAssignments, APermissionRoleAssignments, APermissionUserAssignments, APermissions, APolicies, APolicy, APolicyForm, APolicyTypePicker, ARealm, ARealmForm, ARealmMatchPolicyForm, ARealmPicker, ARealms, ARobot, ARobotForm, ARobotPermissionAssignment, ARobotPermissionAssignments, ARobotRoleAssignment, ARobotRoleAssignments, ARobots, ARole, ARoleClientAssignments, ARoleForm, ARolePermissionAssignment, ARolePermissionAssignments, ARoleRobotAssignments, ARoleUserAssignments, ARoles, AScope, AScopeClientAssignments, AScopeForm, AScopes, ASearch, ATimePolicyForm, ATitle, AUser, AUserForm, AUserPasswordForm, AUserPermissionAssignment, AUserPermissionAssignments, AUserRoleAssignment, AUserRoleAssignments, AUsers, EntityRecordError, HTTPClientSymbol, LanguageSwitcherDropdown, STORE_ID, SocketClientSymbol, StoreDispatcherEventName, TranslatorTranslationClientKey, TranslatorTranslationDefaultKey, TranslatorTranslationGroup, TranslatorTranslationVuecsKey, VuelidateCustomRule, VuelidateCustomRuleKey, assignFormProperties, buildEntityCollectionCreatedHandler, buildEntityCollectionDeletedHandler, buildEntityCollectionUpdatedHandler, buildEntityVSlotProps, buildFormSubmitWithTranslations, createFormSubmitTranslations, createPermissionCheckerReactiveFn, createStore, createStoreDispatcher, index as default, defineEntityCollectionManager, defineEntityCollectionVEmitOptions, defineEntityCollectionVProps, defineEntityManager, defineEntityPicker, defineEntityPickerVEmitOptions, defineEntityPickerVProps, defineEntitySocketManager, defineEntityVEmitOptions, defineEntityVProps, extractVuelidateResultsFromChild, getVuelidateSeverity, hasHTTPClient, hasHTTPClientAuthenticationHook, hasNormalizedSlot, hasStoreFactory, inject$1 as inject, injectHTTPClient, injectHTTPClientAuthenticationHook, injectSocketManager, injectStore, injectStoreDispatcher, injectStoreFactory, injectTranslatorLocale, install, installHTTPClient, installHTTPClientAuthenticationHook, installSocketManager, installStore, installTranslator, isQuerySortedDescByDate, isSocketManagerUsable, mergeEntityCollectionRenderOptions, normalizeSlot, onChange, provide, provideHTTPClient, provideHTTPClientAuthenticationHook, provideSocketManager, provideStoreDispatcher, provideStoreFactory, renderToggleButton, storeToRefs, useIsEditing, usePermissionCheck, useTranslation, useTranslationsForBaseValidation, useTranslationsForGroup, useTranslationsForNestedValidation, useUpdatedAt, wrapFnWithBusyState };
|
|
9463
9494
|
//# sourceMappingURL=index.mjs.map
|