academe-kit 0.5.2 → 0.5.4
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.cjs +91 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +917 -586
- package/dist/index.esm.js +91 -37
- package/dist/index.esm.js.map +1 -1
- package/dist/types/context/SecurityProvider/types.d.ts +1 -0
- package/dist/types/services/CertificateService.d.ts +71 -4
- package/dist/types/services/ClassroomService.d.ts +31 -34
- package/dist/types/services/SerieService.d.ts +30 -37
- package/dist/types/services/ShiftService.d.ts +30 -37
- package/dist/types/services/UserService.d.ts +87 -164
- package/dist/types/types/academe-api.d.ts +659 -304
- package/dist/types/types/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4559,6 +4559,11 @@ function createUserService(apiClient) {
|
|
|
4559
4559
|
body,
|
|
4560
4560
|
});
|
|
4561
4561
|
},
|
|
4562
|
+
updateMe(body) {
|
|
4563
|
+
return apiClient.PUT("/users/me", {
|
|
4564
|
+
body,
|
|
4565
|
+
});
|
|
4566
|
+
},
|
|
4562
4567
|
/**
|
|
4563
4568
|
* Delete user
|
|
4564
4569
|
*/
|
|
@@ -4912,10 +4917,14 @@ function createReportService(apiClient) {
|
|
|
4912
4917
|
function createClassroomService(apiClient) {
|
|
4913
4918
|
return {
|
|
4914
4919
|
/**
|
|
4915
|
-
* List all classrooms
|
|
4920
|
+
* List all classrooms with optional filters
|
|
4916
4921
|
*/
|
|
4917
|
-
getAll() {
|
|
4918
|
-
return apiClient.GET("/classrooms"
|
|
4922
|
+
getAll(params) {
|
|
4923
|
+
return apiClient.GET("/classrooms", {
|
|
4924
|
+
params: {
|
|
4925
|
+
query: params,
|
|
4926
|
+
},
|
|
4927
|
+
});
|
|
4919
4928
|
},
|
|
4920
4929
|
/**
|
|
4921
4930
|
* Get classroom by ID
|
|
@@ -5021,16 +5030,20 @@ function createOrganizationService(apiClient) {
|
|
|
5021
5030
|
function createSerieService(apiClient) {
|
|
5022
5031
|
return {
|
|
5023
5032
|
/**
|
|
5024
|
-
* List all series
|
|
5033
|
+
* List all series with optional filters
|
|
5025
5034
|
*/
|
|
5026
|
-
getAll() {
|
|
5027
|
-
return apiClient.GET(
|
|
5035
|
+
getAll(params) {
|
|
5036
|
+
return apiClient.GET("/series", {
|
|
5037
|
+
params: {
|
|
5038
|
+
query: params,
|
|
5039
|
+
},
|
|
5040
|
+
});
|
|
5028
5041
|
},
|
|
5029
5042
|
/**
|
|
5030
5043
|
* Get serie by ID
|
|
5031
5044
|
*/
|
|
5032
5045
|
getById(id) {
|
|
5033
|
-
return apiClient.GET(
|
|
5046
|
+
return apiClient.GET("/series/{id}", {
|
|
5034
5047
|
params: { path: { id } },
|
|
5035
5048
|
});
|
|
5036
5049
|
},
|
|
@@ -5038,7 +5051,7 @@ function createSerieService(apiClient) {
|
|
|
5038
5051
|
* Create a new serie
|
|
5039
5052
|
*/
|
|
5040
5053
|
create(data) {
|
|
5041
|
-
return apiClient.POST(
|
|
5054
|
+
return apiClient.POST("/series", {
|
|
5042
5055
|
body: data,
|
|
5043
5056
|
});
|
|
5044
5057
|
},
|
|
@@ -5046,7 +5059,7 @@ function createSerieService(apiClient) {
|
|
|
5046
5059
|
* Update serie
|
|
5047
5060
|
*/
|
|
5048
5061
|
update(id, data) {
|
|
5049
|
-
return apiClient.PATCH(
|
|
5062
|
+
return apiClient.PATCH("/series/{id}", {
|
|
5050
5063
|
params: { path: { id } },
|
|
5051
5064
|
body: data,
|
|
5052
5065
|
});
|
|
@@ -5055,7 +5068,7 @@ function createSerieService(apiClient) {
|
|
|
5055
5068
|
* Delete serie
|
|
5056
5069
|
*/
|
|
5057
5070
|
delete(id) {
|
|
5058
|
-
return apiClient.DELETE(
|
|
5071
|
+
return apiClient.DELETE("/series/{id}", {
|
|
5059
5072
|
params: { path: { id } },
|
|
5060
5073
|
});
|
|
5061
5074
|
},
|
|
@@ -5065,16 +5078,20 @@ function createSerieService(apiClient) {
|
|
|
5065
5078
|
function createShiftService(apiClient) {
|
|
5066
5079
|
return {
|
|
5067
5080
|
/**
|
|
5068
|
-
* List all shifts
|
|
5081
|
+
* List all shifts with optional filters
|
|
5069
5082
|
*/
|
|
5070
|
-
getAll() {
|
|
5071
|
-
return apiClient.GET(
|
|
5083
|
+
getAll(params) {
|
|
5084
|
+
return apiClient.GET("/shifts", {
|
|
5085
|
+
params: {
|
|
5086
|
+
query: params,
|
|
5087
|
+
},
|
|
5088
|
+
});
|
|
5072
5089
|
},
|
|
5073
5090
|
/**
|
|
5074
5091
|
* Get shift by ID
|
|
5075
5092
|
*/
|
|
5076
5093
|
getById(id) {
|
|
5077
|
-
return apiClient.GET(
|
|
5094
|
+
return apiClient.GET("/shifts/{id}", {
|
|
5078
5095
|
params: { path: { id } },
|
|
5079
5096
|
});
|
|
5080
5097
|
},
|
|
@@ -5082,7 +5099,7 @@ function createShiftService(apiClient) {
|
|
|
5082
5099
|
* Create a new shift
|
|
5083
5100
|
*/
|
|
5084
5101
|
create(data) {
|
|
5085
|
-
return apiClient.POST(
|
|
5102
|
+
return apiClient.POST("/shifts", {
|
|
5086
5103
|
body: data,
|
|
5087
5104
|
});
|
|
5088
5105
|
},
|
|
@@ -5090,7 +5107,7 @@ function createShiftService(apiClient) {
|
|
|
5090
5107
|
* Update shift
|
|
5091
5108
|
*/
|
|
5092
5109
|
update(id, data) {
|
|
5093
|
-
return apiClient.PATCH(
|
|
5110
|
+
return apiClient.PATCH("/shifts/{id}", {
|
|
5094
5111
|
params: { path: { id } },
|
|
5095
5112
|
body: data,
|
|
5096
5113
|
});
|
|
@@ -5099,7 +5116,7 @@ function createShiftService(apiClient) {
|
|
|
5099
5116
|
* Delete shift
|
|
5100
5117
|
*/
|
|
5101
5118
|
delete(id) {
|
|
5102
|
-
return apiClient.DELETE(
|
|
5119
|
+
return apiClient.DELETE("/shifts/{id}", {
|
|
5103
5120
|
params: { path: { id } },
|
|
5104
5121
|
});
|
|
5105
5122
|
},
|
|
@@ -5325,14 +5342,17 @@ function createCertificateService(apiClient) {
|
|
|
5325
5342
|
/**
|
|
5326
5343
|
* List all certificates
|
|
5327
5344
|
*/
|
|
5345
|
+
getMe() {
|
|
5346
|
+
return apiClient.GET("/certificates/me");
|
|
5347
|
+
},
|
|
5328
5348
|
getAll() {
|
|
5329
|
-
return apiClient.GET(
|
|
5349
|
+
return apiClient.GET("/certificates");
|
|
5330
5350
|
},
|
|
5331
5351
|
/**
|
|
5332
5352
|
* Get certificate by ID
|
|
5333
5353
|
*/
|
|
5334
5354
|
getById(id) {
|
|
5335
|
-
return apiClient.GET(
|
|
5355
|
+
return apiClient.GET("/certificates/{id}", {
|
|
5336
5356
|
params: { path: { id } },
|
|
5337
5357
|
});
|
|
5338
5358
|
},
|
|
@@ -5340,7 +5360,7 @@ function createCertificateService(apiClient) {
|
|
|
5340
5360
|
* Create a new certificate
|
|
5341
5361
|
*/
|
|
5342
5362
|
create(data) {
|
|
5343
|
-
return apiClient.POST(
|
|
5363
|
+
return apiClient.POST("/certificates", {
|
|
5344
5364
|
body: data,
|
|
5345
5365
|
});
|
|
5346
5366
|
},
|
|
@@ -5348,7 +5368,7 @@ function createCertificateService(apiClient) {
|
|
|
5348
5368
|
* Update certificate
|
|
5349
5369
|
*/
|
|
5350
5370
|
update(id, data) {
|
|
5351
|
-
return apiClient.PATCH(
|
|
5371
|
+
return apiClient.PATCH("/certificates/{id}", {
|
|
5352
5372
|
params: { path: { id } },
|
|
5353
5373
|
body: data,
|
|
5354
5374
|
});
|
|
@@ -5357,7 +5377,7 @@ function createCertificateService(apiClient) {
|
|
|
5357
5377
|
* Delete certificate
|
|
5358
5378
|
*/
|
|
5359
5379
|
delete(id) {
|
|
5360
|
-
return apiClient.DELETE(
|
|
5380
|
+
return apiClient.DELETE("/certificates/{id}", {
|
|
5361
5381
|
params: { path: { id } },
|
|
5362
5382
|
});
|
|
5363
5383
|
},
|
|
@@ -5570,6 +5590,7 @@ const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, a
|
|
|
5570
5590
|
};
|
|
5571
5591
|
const SecurityContext = React2.createContext({
|
|
5572
5592
|
isInitialized: false,
|
|
5593
|
+
isTokenReady: false,
|
|
5573
5594
|
user: null,
|
|
5574
5595
|
refreshUserData: async () => { },
|
|
5575
5596
|
signOut: () => null,
|
|
@@ -5598,6 +5619,10 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5598
5619
|
const auth = useAuth();
|
|
5599
5620
|
const [currentUser, setCurrentUser] = React2.useState(null);
|
|
5600
5621
|
const hasTriedSignInSilent = React2.useRef(false);
|
|
5622
|
+
const [isTokenReady, setIsTokenReady] = React2.useState(false);
|
|
5623
|
+
// Ref para armazenar o resolver da Promise de token
|
|
5624
|
+
const tokenReadyResolverRef = React2.useRef(null);
|
|
5625
|
+
const tokenReadyPromiseRef = React2.useRef(null);
|
|
5601
5626
|
// Extrair valores primitivos do auth para usar como dependências estáveis
|
|
5602
5627
|
const isAuthenticated = auth.isAuthenticated;
|
|
5603
5628
|
const isLoading = auth.isLoading;
|
|
@@ -5619,8 +5644,33 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5619
5644
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5620
5645
|
}, [isAuthenticated, isLoading, activeNavigator]);
|
|
5621
5646
|
// --- 2. Configuração de API e Services ---
|
|
5647
|
+
// Ref para armazenar o token atual (acessível no middleware)
|
|
5648
|
+
const currentTokenRef = React2.useRef(undefined);
|
|
5622
5649
|
const apiClient = React2.useMemo(() => {
|
|
5623
|
-
|
|
5650
|
+
const client = createAcademeApiClient(apiBaseUrl);
|
|
5651
|
+
// Inicializa a Promise de token ready
|
|
5652
|
+
tokenReadyPromiseRef.current = new Promise((resolve) => {
|
|
5653
|
+
tokenReadyResolverRef.current = resolve;
|
|
5654
|
+
});
|
|
5655
|
+
// Middleware que aguarda o token estar disponível antes de fazer requests
|
|
5656
|
+
client.use({
|
|
5657
|
+
async onRequest({ request }) {
|
|
5658
|
+
// Se já tem token, usa imediatamente
|
|
5659
|
+
if (currentTokenRef.current) {
|
|
5660
|
+
request.headers.set("Authorization", `Bearer ${currentTokenRef.current}`);
|
|
5661
|
+
return request;
|
|
5662
|
+
}
|
|
5663
|
+
// Se ainda está carregando a auth, aguarda o token ficar pronto
|
|
5664
|
+
if (tokenReadyPromiseRef.current) {
|
|
5665
|
+
await tokenReadyPromiseRef.current;
|
|
5666
|
+
if (currentTokenRef.current) {
|
|
5667
|
+
request.headers.set("Authorization", `Bearer ${currentTokenRef.current}`);
|
|
5668
|
+
}
|
|
5669
|
+
}
|
|
5670
|
+
return request;
|
|
5671
|
+
},
|
|
5672
|
+
});
|
|
5673
|
+
return client;
|
|
5624
5674
|
}, [apiBaseUrl]);
|
|
5625
5675
|
const services = React2.useMemo(() => {
|
|
5626
5676
|
return createAcademeServices(apiClient);
|
|
@@ -5628,25 +5678,27 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5628
5678
|
const decodedAccessToken = React2.useMemo(() => {
|
|
5629
5679
|
return accessToken ? decodeAccessToken(accessToken) : null;
|
|
5630
5680
|
}, [accessToken]);
|
|
5631
|
-
//
|
|
5681
|
+
// Atualização do Token e resolução da Promise
|
|
5632
5682
|
React2.useEffect(() => {
|
|
5683
|
+
currentTokenRef.current = accessToken;
|
|
5684
|
+
if (typeof window !== "undefined") {
|
|
5685
|
+
window.accessToken = accessToken;
|
|
5686
|
+
}
|
|
5633
5687
|
if (accessToken) {
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
},
|
|
5639
|
-
});
|
|
5640
|
-
if (typeof window !== "undefined") {
|
|
5641
|
-
window.accessToken = accessToken;
|
|
5688
|
+
// Resolve a promise indicando que o token está pronto
|
|
5689
|
+
if (tokenReadyResolverRef.current) {
|
|
5690
|
+
tokenReadyResolverRef.current();
|
|
5691
|
+
setIsTokenReady(true);
|
|
5642
5692
|
}
|
|
5643
5693
|
}
|
|
5644
|
-
else {
|
|
5645
|
-
|
|
5646
|
-
|
|
5694
|
+
else if (!isLoading && !isAuthenticated) {
|
|
5695
|
+
// Usuário não autenticado - resolve a promise para não bloquear requests públicas
|
|
5696
|
+
if (tokenReadyResolverRef.current) {
|
|
5697
|
+
tokenReadyResolverRef.current();
|
|
5698
|
+
setIsTokenReady(true);
|
|
5647
5699
|
}
|
|
5648
5700
|
}
|
|
5649
|
-
}, [accessToken,
|
|
5701
|
+
}, [accessToken, isLoading, isAuthenticated]);
|
|
5650
5702
|
// --- 3. Helpers de Usuário e Roles ---
|
|
5651
5703
|
const getKeycloakUser = React2.useCallback(() => {
|
|
5652
5704
|
const profile = userProfile;
|
|
@@ -5680,7 +5732,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5680
5732
|
const academeUser = {
|
|
5681
5733
|
keycloakUser: getKeycloakUser(),
|
|
5682
5734
|
};
|
|
5683
|
-
setCurrentUser({ ...academeUser, id: userProfileSub });
|
|
5735
|
+
setCurrentUser({ ...academeUser, id: userProfileSub || "" });
|
|
5684
5736
|
}
|
|
5685
5737
|
return;
|
|
5686
5738
|
}
|
|
@@ -5763,6 +5815,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5763
5815
|
// Memoizar o value do context para evitar re-renders desnecessários
|
|
5764
5816
|
const contextValue = React2.useMemo(() => ({
|
|
5765
5817
|
isInitialized: !isLoading,
|
|
5818
|
+
isTokenReady,
|
|
5766
5819
|
user: currentUser,
|
|
5767
5820
|
refreshUserData,
|
|
5768
5821
|
signOut,
|
|
@@ -5776,6 +5829,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5776
5829
|
services,
|
|
5777
5830
|
}), [
|
|
5778
5831
|
isLoading,
|
|
5832
|
+
isTokenReady,
|
|
5779
5833
|
currentUser,
|
|
5780
5834
|
refreshUserData,
|
|
5781
5835
|
signOut,
|