academe-kit 0.3.1 → 0.3.2
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.d.ts +14 -4
- package/dist/index.esm.js +32 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -6
- package/dist/index.js.map +1 -1
- package/dist/types/context/SecurityProvider/types.d.ts +7 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/roles/applications.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
-
import { KeycloakLoginOptions } from 'keycloak-js';
|
|
3
|
+
import { KeycloakInitOptions, KeycloakLoginOptions } from 'keycloak-js';
|
|
4
4
|
import * as openapi_fetch from 'openapi-fetch';
|
|
5
5
|
import openapi_fetch__default from 'openapi-fetch';
|
|
6
6
|
import { ClassValue } from 'clsx';
|
|
@@ -10185,15 +10185,18 @@ interface AcademeServices {
|
|
|
10185
10185
|
|
|
10186
10186
|
type AcademeKeycloakContextProps = {
|
|
10187
10187
|
realm: string;
|
|
10188
|
-
hubUrl
|
|
10188
|
+
hubUrl?: string;
|
|
10189
10189
|
clientId: string;
|
|
10190
10190
|
keycloakUrl: string;
|
|
10191
10191
|
apiBaseUrl?: string;
|
|
10192
|
+
initOptions?: KeycloakInitOptions;
|
|
10193
|
+
skipApiUserFetch?: boolean;
|
|
10192
10194
|
children: React.ReactElement;
|
|
10193
10195
|
};
|
|
10194
10196
|
type SecurityProviderProps = {
|
|
10195
|
-
hubUrl
|
|
10197
|
+
hubUrl?: string;
|
|
10196
10198
|
apiBaseUrl?: string;
|
|
10199
|
+
skipApiUserFetch?: boolean;
|
|
10197
10200
|
children: React.ReactElement;
|
|
10198
10201
|
};
|
|
10199
10202
|
type KeycloakUser = {
|
|
@@ -10216,6 +10219,7 @@ type SecurityContextType = {
|
|
|
10216
10219
|
hasClientRole: (role: string, resource?: string) => boolean;
|
|
10217
10220
|
apiClient: AcademeApiClient | null;
|
|
10218
10221
|
services: AcademeServices | null;
|
|
10222
|
+
accessToken: string | undefined;
|
|
10219
10223
|
};
|
|
10220
10224
|
|
|
10221
10225
|
declare const AcademeAuthProvider: React.FC<AcademeKeycloakContextProps>;
|
|
@@ -10242,5 +10246,11 @@ declare enum BACKOFFICE_ROLES {
|
|
|
10242
10246
|
declare enum DASHBOARD_ROLES {
|
|
10243
10247
|
}
|
|
10244
10248
|
|
|
10245
|
-
|
|
10249
|
+
declare enum APPLICATIONS_ROLES {
|
|
10250
|
+
ACCESS_NINA = "Acesso nina",
|
|
10251
|
+
ACCESS_MIKE = "Acesso mike",
|
|
10252
|
+
VIEW_WIDGET = "Visualizar Widget"
|
|
10253
|
+
}
|
|
10254
|
+
|
|
10255
|
+
export { APPLICATIONS_ROLES, AcademeAuthProvider, BACKOFFICE_ROLES, Button, DASHBOARD_ROLES, GLOBAL_ROLES, ProtectedApp, ProtectedComponent, ProtectedRouter, Spinner, academeApi_d as apiTypes, cn, createAcademeApiClient, index_d as types, useAcademeAuth };
|
|
10246
10256
|
export type { AcademeApiClient, AcademeKeycloakContextProps, AcademeUser, ButtonProps, KeycloakUser, SecurityContextType, SecurityProviderProps };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import React__default, { createContext, useContext,
|
|
3
|
+
import React__default, { createContext, useContext, useMemo, useState, useEffect, useCallback, forwardRef, createElement } from 'react';
|
|
4
4
|
|
|
5
5
|
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
|
|
6
6
|
|
|
@@ -3259,8 +3259,10 @@ var GLOBAL_ROLES;
|
|
|
3259
3259
|
GLOBAL_ROLES["GUARDIAN"] = "guardian";
|
|
3260
3260
|
})(GLOBAL_ROLES || (GLOBAL_ROLES = {}));
|
|
3261
3261
|
|
|
3262
|
-
const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, }) => {
|
|
3263
|
-
|
|
3262
|
+
const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, initOptions, skipApiUserFetch, }) => {
|
|
3263
|
+
const keycloakInstance = useMemo(() => new Keycloak({ clientId, realm, url: keycloakUrl }), [clientId, realm, keycloakUrl]);
|
|
3264
|
+
const keycloakInitOptions = useMemo(() => initOptions, [initOptions]);
|
|
3265
|
+
return (jsx(ReactKeycloakProvider, { authClient: keycloakInstance, initOptions: keycloakInitOptions, children: jsx(SecurityProvider, { hubUrl: hubUrl, apiBaseUrl: apiBaseUrl, skipApiUserFetch: skipApiUserFetch, children: children }) }));
|
|
3264
3266
|
};
|
|
3265
3267
|
const SecurityContext = createContext({
|
|
3266
3268
|
isInitialized: false,
|
|
@@ -3274,12 +3276,12 @@ const SecurityContext = createContext({
|
|
|
3274
3276
|
isAuthenticated: () => false,
|
|
3275
3277
|
apiClient: null,
|
|
3276
3278
|
services: null,
|
|
3279
|
+
accessToken: undefined,
|
|
3277
3280
|
});
|
|
3278
|
-
const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", children, }) => {
|
|
3281
|
+
const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipApiUserFetch = false, children, }) => {
|
|
3279
3282
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
3280
3283
|
const [currentUser, setCurrentUser] = useState(null);
|
|
3281
3284
|
const { initialized, keycloak } = useKeycloak();
|
|
3282
|
-
// Create API client with the provided baseUrl
|
|
3283
3285
|
const apiClient = useMemo(() => {
|
|
3284
3286
|
return createAcademeApiClient(apiBaseUrl);
|
|
3285
3287
|
}, [apiBaseUrl]);
|
|
@@ -3310,10 +3312,16 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
|
|
|
3310
3312
|
lastName: idTokenParsed?.family_name || "",
|
|
3311
3313
|
};
|
|
3312
3314
|
}, [keycloak?.idTokenParsed]);
|
|
3313
|
-
// Fetch user data from API when authenticated
|
|
3314
3315
|
useEffect(() => {
|
|
3315
3316
|
const fetchUserData = async () => {
|
|
3316
3317
|
if (initialized && keycloak?.authenticated && keycloak?.token) {
|
|
3318
|
+
if (skipApiUserFetch) {
|
|
3319
|
+
const academeUser = {
|
|
3320
|
+
keycloakUser: getKeycloakUser(),
|
|
3321
|
+
};
|
|
3322
|
+
setCurrentUser({ ...academeUser, id: keycloak?.idTokenParsed?.sub });
|
|
3323
|
+
return;
|
|
3324
|
+
}
|
|
3317
3325
|
try {
|
|
3318
3326
|
const response = await services.user.getMe();
|
|
3319
3327
|
if (response?.data?.data) {
|
|
@@ -3339,9 +3347,17 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
|
|
|
3339
3347
|
keycloak?.token,
|
|
3340
3348
|
getKeycloakUser,
|
|
3341
3349
|
services,
|
|
3350
|
+
skipApiUserFetch,
|
|
3342
3351
|
]);
|
|
3343
3352
|
const refreshUserData = useCallback(async () => {
|
|
3344
3353
|
if (keycloak?.authenticated) {
|
|
3354
|
+
if (skipApiUserFetch) {
|
|
3355
|
+
const academeUser = {
|
|
3356
|
+
keycloakUser: getKeycloakUser(),
|
|
3357
|
+
};
|
|
3358
|
+
setCurrentUser(academeUser);
|
|
3359
|
+
return;
|
|
3360
|
+
}
|
|
3345
3361
|
try {
|
|
3346
3362
|
const response = await services.user.getMe();
|
|
3347
3363
|
if (response?.data?.data) {
|
|
@@ -3356,7 +3372,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
|
|
|
3356
3372
|
console.error("Error refreshing user data:", error);
|
|
3357
3373
|
}
|
|
3358
3374
|
}
|
|
3359
|
-
}, [keycloak?.authenticated, getKeycloakUser, services]);
|
|
3375
|
+
}, [keycloak?.authenticated, getKeycloakUser, services, skipApiUserFetch]);
|
|
3360
3376
|
const signOut = () => {
|
|
3361
3377
|
setCurrentUser(null);
|
|
3362
3378
|
keycloak?.logout();
|
|
@@ -3383,6 +3399,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
|
|
|
3383
3399
|
goToLogin: keycloak.login,
|
|
3384
3400
|
hasRealmRole: keycloak?.hasRealmRole,
|
|
3385
3401
|
hasClientRole: keycloak.hasResourceRole,
|
|
3402
|
+
accessToken: keycloak?.token,
|
|
3386
3403
|
apiClient,
|
|
3387
3404
|
services,
|
|
3388
3405
|
}, children: children }));
|
|
@@ -6555,6 +6572,13 @@ var DASHBOARD_ROLES;
|
|
|
6555
6572
|
(function (DASHBOARD_ROLES) {
|
|
6556
6573
|
})(DASHBOARD_ROLES || (DASHBOARD_ROLES = {}));
|
|
6557
6574
|
|
|
6575
|
+
var APPLICATIONS_ROLES;
|
|
6576
|
+
(function (APPLICATIONS_ROLES) {
|
|
6577
|
+
APPLICATIONS_ROLES["ACCESS_NINA"] = "Acesso nina";
|
|
6578
|
+
APPLICATIONS_ROLES["ACCESS_MIKE"] = "Acesso mike";
|
|
6579
|
+
APPLICATIONS_ROLES["VIEW_WIDGET"] = "Visualizar Widget";
|
|
6580
|
+
})(APPLICATIONS_ROLES || (APPLICATIONS_ROLES = {}));
|
|
6581
|
+
|
|
6558
6582
|
var index = /*#__PURE__*/Object.freeze({
|
|
6559
6583
|
__proto__: null
|
|
6560
6584
|
});
|
|
@@ -6568,5 +6592,5 @@ var academeApi = /*#__PURE__*/Object.freeze({
|
|
|
6568
6592
|
__proto__: null
|
|
6569
6593
|
});
|
|
6570
6594
|
|
|
6571
|
-
export { AcademeAuthProvider, BACKOFFICE_ROLES, Button, DASHBOARD_ROLES, GLOBAL_ROLES, ProtectedApp, ProtectedComponent, ProtectedRouter, Spinner, academeApi as apiTypes, cn, createAcademeApiClient, index as types, useAcademeAuth };
|
|
6595
|
+
export { APPLICATIONS_ROLES, AcademeAuthProvider, BACKOFFICE_ROLES, Button, DASHBOARD_ROLES, GLOBAL_ROLES, ProtectedApp, ProtectedComponent, ProtectedRouter, Spinner, academeApi as apiTypes, cn, createAcademeApiClient, index as types, useAcademeAuth };
|
|
6572
6596
|
//# sourceMappingURL=index.esm.js.map
|