academe-kit 0.5.3 → 0.5.5

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 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('/series');
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('/series/{id}', {
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('/series', {
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('/series/{id}', {
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('/series/{id}', {
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('/shifts');
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('/shifts/{id}', {
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('/shifts', {
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('/shifts/{id}', {
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('/shifts/{id}', {
5119
+ return apiClient.DELETE("/shifts/{id}", {
5103
5120
  params: { path: { id } },
5104
5121
  });
5105
5122
  },
@@ -5317,6 +5334,181 @@ function createQuizService(apiClient) {
5317
5334
  params: { path: { id } },
5318
5335
  });
5319
5336
  },
5337
+ // ============================================================================
5338
+ // Quiz Questions
5339
+ // ============================================================================
5340
+ /**
5341
+ * List all quiz questions
5342
+ */
5343
+ getQuestions(params) {
5344
+ return apiClient.GET('/quiz-questions', {
5345
+ params: {
5346
+ query: params,
5347
+ },
5348
+ });
5349
+ },
5350
+ /**
5351
+ * Get quiz question by ID
5352
+ */
5353
+ getQuestionById(id) {
5354
+ return apiClient.GET('/quiz-questions/{id}', {
5355
+ params: { path: { id } },
5356
+ });
5357
+ },
5358
+ /**
5359
+ * Create a new quiz question
5360
+ */
5361
+ createQuestion(data) {
5362
+ return apiClient.POST('/quiz-questions', {
5363
+ body: data,
5364
+ });
5365
+ },
5366
+ /**
5367
+ * Update quiz question
5368
+ */
5369
+ updateQuestion(id, data) {
5370
+ return apiClient.PATCH('/quiz-questions/{id}', {
5371
+ params: { path: { id } },
5372
+ body: data,
5373
+ });
5374
+ },
5375
+ /**
5376
+ * Delete quiz question
5377
+ */
5378
+ deleteQuestion(id) {
5379
+ return apiClient.DELETE('/quiz-questions/{id}', {
5380
+ params: { path: { id } },
5381
+ });
5382
+ },
5383
+ // ============================================================================
5384
+ // Quiz Question Answers
5385
+ // ============================================================================
5386
+ /**
5387
+ * List all quiz question answers
5388
+ */
5389
+ getQuestionAnswers(params) {
5390
+ return apiClient.GET('/quiz-question-answers', {
5391
+ params: {
5392
+ query: params,
5393
+ },
5394
+ });
5395
+ },
5396
+ /**
5397
+ * Get quiz question answer by ID
5398
+ */
5399
+ getQuestionAnswerById(id) {
5400
+ return apiClient.GET('/quiz-question-answers/{id}', {
5401
+ params: { path: { id } },
5402
+ });
5403
+ },
5404
+ /**
5405
+ * Create a new quiz question answer
5406
+ */
5407
+ createQuestionAnswer(data) {
5408
+ return apiClient.POST('/quiz-question-answers', {
5409
+ body: data,
5410
+ });
5411
+ },
5412
+ /**
5413
+ * Update quiz question answer
5414
+ */
5415
+ updateQuestionAnswer(id, data) {
5416
+ return apiClient.PATCH('/quiz-question-answers/{id}', {
5417
+ params: { path: { id } },
5418
+ body: data,
5419
+ });
5420
+ },
5421
+ /**
5422
+ * Delete quiz question answer
5423
+ */
5424
+ deleteQuestionAnswer(id) {
5425
+ return apiClient.DELETE('/quiz-question-answers/{id}', {
5426
+ params: { path: { id } },
5427
+ });
5428
+ },
5429
+ // ============================================================================
5430
+ // Quiz Attempts
5431
+ // ============================================================================
5432
+ /**
5433
+ * List all quiz attempts
5434
+ */
5435
+ getAttempts(params) {
5436
+ return apiClient.GET('/quiz-attempts', {
5437
+ params: {
5438
+ query: params,
5439
+ },
5440
+ });
5441
+ },
5442
+ /**
5443
+ * Get quiz attempt by ID
5444
+ */
5445
+ getAttemptById(id) {
5446
+ return apiClient.GET('/quiz-attempts/{id}', {
5447
+ params: { path: { id } },
5448
+ });
5449
+ },
5450
+ /**
5451
+ * Create a new quiz attempt
5452
+ */
5453
+ createAttempt(data) {
5454
+ return apiClient.POST('/quiz-attempts', {
5455
+ body: data,
5456
+ });
5457
+ },
5458
+ /**
5459
+ * Update quiz attempt
5460
+ */
5461
+ updateAttempt(id, data) {
5462
+ return apiClient.PATCH('/quiz-attempts/{id}', {
5463
+ params: { path: { id } },
5464
+ body: data,
5465
+ });
5466
+ },
5467
+ /**
5468
+ * Delete quiz attempt
5469
+ */
5470
+ deleteAttempt(id) {
5471
+ return apiClient.DELETE('/quiz-attempts/{id}', {
5472
+ params: { path: { id } },
5473
+ });
5474
+ },
5475
+ // ============================================================================
5476
+ // Quiz Attempt Answers
5477
+ // ============================================================================
5478
+ /**
5479
+ * List all quiz attempt answers
5480
+ */
5481
+ getAttemptAnswers(params) {
5482
+ return apiClient.GET('/quiz-attempt-answers', {
5483
+ params: {
5484
+ query: params,
5485
+ },
5486
+ });
5487
+ },
5488
+ /**
5489
+ * Get quiz attempt answer by ID
5490
+ */
5491
+ getAttemptAnswerById(id) {
5492
+ return apiClient.GET('/quiz-attempt-answers/{id}', {
5493
+ params: { path: { id } },
5494
+ });
5495
+ },
5496
+ /**
5497
+ * Submit a quiz attempt answer
5498
+ */
5499
+ createAttemptAnswer(data) {
5500
+ return apiClient.POST('/quiz-attempt-answers', {
5501
+ body: data,
5502
+ });
5503
+ },
5504
+ /**
5505
+ * Delete quiz attempt answer
5506
+ */
5507
+ deleteAttemptAnswer(id) {
5508
+ return apiClient.DELETE('/quiz-attempt-answers/{id}', {
5509
+ params: { path: { id } },
5510
+ });
5511
+ },
5320
5512
  };
5321
5513
  }
5322
5514
 
@@ -5325,14 +5517,25 @@ function createCertificateService(apiClient) {
5325
5517
  /**
5326
5518
  * List all certificates
5327
5519
  */
5520
+ getMe() {
5521
+ return apiClient.GET("/certificates/me");
5522
+ },
5328
5523
  getAll() {
5329
- return apiClient.GET('/certificates');
5524
+ return apiClient.GET("/certificates");
5525
+ },
5526
+ /**
5527
+ * Get current user's certificates
5528
+ */
5529
+ getMyCertificates(query) {
5530
+ return apiClient.GET('/certificates/me', {
5531
+ params: { query },
5532
+ });
5330
5533
  },
5331
5534
  /**
5332
5535
  * Get certificate by ID
5333
5536
  */
5334
5537
  getById(id) {
5335
- return apiClient.GET('/certificates/{id}', {
5538
+ return apiClient.GET("/certificates/{id}", {
5336
5539
  params: { path: { id } },
5337
5540
  });
5338
5541
  },
@@ -5340,7 +5543,7 @@ function createCertificateService(apiClient) {
5340
5543
  * Create a new certificate
5341
5544
  */
5342
5545
  create(data) {
5343
- return apiClient.POST('/certificates', {
5546
+ return apiClient.POST("/certificates", {
5344
5547
  body: data,
5345
5548
  });
5346
5549
  },
@@ -5348,7 +5551,7 @@ function createCertificateService(apiClient) {
5348
5551
  * Update certificate
5349
5552
  */
5350
5553
  update(id, data) {
5351
- return apiClient.PATCH('/certificates/{id}', {
5554
+ return apiClient.PATCH("/certificates/{id}", {
5352
5555
  params: { path: { id } },
5353
5556
  body: data,
5354
5557
  });
@@ -5357,7 +5560,55 @@ function createCertificateService(apiClient) {
5357
5560
  * Delete certificate
5358
5561
  */
5359
5562
  delete(id) {
5360
- return apiClient.DELETE('/certificates/{id}', {
5563
+ return apiClient.DELETE("/certificates/{id}", {
5564
+ params: { path: { id } },
5565
+ });
5566
+ },
5567
+ };
5568
+ }
5569
+
5570
+ function createCertificateTemplateService(apiClient) {
5571
+ return {
5572
+ /**
5573
+ * List all certificate templates
5574
+ */
5575
+ getAll(params) {
5576
+ return apiClient.GET('/certificate-templates', {
5577
+ params: {
5578
+ query: params,
5579
+ },
5580
+ });
5581
+ },
5582
+ /**
5583
+ * Get certificate template by ID
5584
+ */
5585
+ getById(id) {
5586
+ return apiClient.GET('/certificate-templates/{id}', {
5587
+ params: { path: { id } },
5588
+ });
5589
+ },
5590
+ /**
5591
+ * Create a new certificate template
5592
+ */
5593
+ create(data) {
5594
+ return apiClient.POST('/certificate-templates', {
5595
+ body: data,
5596
+ });
5597
+ },
5598
+ /**
5599
+ * Update certificate template
5600
+ */
5601
+ update(id, data) {
5602
+ return apiClient.PATCH('/certificate-templates/{id}', {
5603
+ params: { path: { id } },
5604
+ body: data,
5605
+ });
5606
+ },
5607
+ /**
5608
+ * Delete certificate template
5609
+ */
5610
+ delete(id) {
5611
+ return apiClient.DELETE('/certificate-templates/{id}', {
5361
5612
  params: { path: { id } },
5362
5613
  });
5363
5614
  },
@@ -5539,6 +5790,7 @@ function createAcademeServices(apiClient) {
5539
5790
  group: createGroupService(apiClient),
5540
5791
  quiz: createQuizService(apiClient),
5541
5792
  certificate: createCertificateService(apiClient),
5793
+ certificateTemplate: createCertificateTemplateService(apiClient),
5542
5794
  seatCode: createSeatCodeService(apiClient),
5543
5795
  product: createProductService(apiClient),
5544
5796
  };
@@ -5570,6 +5822,7 @@ const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, a
5570
5822
  };
5571
5823
  const SecurityContext = React2.createContext({
5572
5824
  isInitialized: false,
5825
+ isTokenReady: false,
5573
5826
  user: null,
5574
5827
  refreshUserData: async () => { },
5575
5828
  signOut: () => null,
@@ -5598,6 +5851,10 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
5598
5851
  const auth = useAuth();
5599
5852
  const [currentUser, setCurrentUser] = React2.useState(null);
5600
5853
  const hasTriedSignInSilent = React2.useRef(false);
5854
+ const [isTokenReady, setIsTokenReady] = React2.useState(false);
5855
+ // Ref para armazenar o resolver da Promise de token
5856
+ const tokenReadyResolverRef = React2.useRef(null);
5857
+ const tokenReadyPromiseRef = React2.useRef(null);
5601
5858
  // Extrair valores primitivos do auth para usar como dependências estáveis
5602
5859
  const isAuthenticated = auth.isAuthenticated;
5603
5860
  const isLoading = auth.isLoading;
@@ -5619,8 +5876,33 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
5619
5876
  // eslint-disable-next-line react-hooks/exhaustive-deps
5620
5877
  }, [isAuthenticated, isLoading, activeNavigator]);
5621
5878
  // --- 2. Configuração de API e Services ---
5879
+ // Ref para armazenar o token atual (acessível no middleware)
5880
+ const currentTokenRef = React2.useRef(undefined);
5622
5881
  const apiClient = React2.useMemo(() => {
5623
- return createAcademeApiClient(apiBaseUrl);
5882
+ const client = createAcademeApiClient(apiBaseUrl);
5883
+ // Inicializa a Promise de token ready
5884
+ tokenReadyPromiseRef.current = new Promise((resolve) => {
5885
+ tokenReadyResolverRef.current = resolve;
5886
+ });
5887
+ // Middleware que aguarda o token estar disponível antes de fazer requests
5888
+ client.use({
5889
+ async onRequest({ request }) {
5890
+ // Se já tem token, usa imediatamente
5891
+ if (currentTokenRef.current) {
5892
+ request.headers.set("Authorization", `Bearer ${currentTokenRef.current}`);
5893
+ return request;
5894
+ }
5895
+ // Se ainda está carregando a auth, aguarda o token ficar pronto
5896
+ if (tokenReadyPromiseRef.current) {
5897
+ await tokenReadyPromiseRef.current;
5898
+ if (currentTokenRef.current) {
5899
+ request.headers.set("Authorization", `Bearer ${currentTokenRef.current}`);
5900
+ }
5901
+ }
5902
+ return request;
5903
+ },
5904
+ });
5905
+ return client;
5624
5906
  }, [apiBaseUrl]);
5625
5907
  const services = React2.useMemo(() => {
5626
5908
  return createAcademeServices(apiClient);
@@ -5628,25 +5910,27 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
5628
5910
  const decodedAccessToken = React2.useMemo(() => {
5629
5911
  return accessToken ? decodeAccessToken(accessToken) : null;
5630
5912
  }, [accessToken]);
5631
- // Injeção do Token na API
5913
+ // Atualização do Token e resolução da Promise
5632
5914
  React2.useEffect(() => {
5915
+ currentTokenRef.current = accessToken;
5916
+ if (typeof window !== "undefined") {
5917
+ window.accessToken = accessToken;
5918
+ }
5633
5919
  if (accessToken) {
5634
- apiClient.use({
5635
- onRequest({ request }) {
5636
- request.headers.set("Authorization", `Bearer ${accessToken}`);
5637
- return request;
5638
- },
5639
- });
5640
- if (typeof window !== "undefined") {
5641
- window.accessToken = accessToken;
5920
+ // Resolve a promise indicando que o token está pronto
5921
+ if (tokenReadyResolverRef.current) {
5922
+ tokenReadyResolverRef.current();
5923
+ setIsTokenReady(true);
5642
5924
  }
5643
5925
  }
5644
- else {
5645
- if (typeof window !== "undefined") {
5646
- window.accessToken = undefined;
5926
+ else if (!isLoading && !isAuthenticated) {
5927
+ // Usuário não autenticado - resolve a promise para não bloquear requests públicas
5928
+ if (tokenReadyResolverRef.current) {
5929
+ tokenReadyResolverRef.current();
5930
+ setIsTokenReady(true);
5647
5931
  }
5648
5932
  }
5649
- }, [accessToken, apiClient]);
5933
+ }, [accessToken, isLoading, isAuthenticated]);
5650
5934
  // --- 3. Helpers de Usuário e Roles ---
5651
5935
  const getKeycloakUser = React2.useCallback(() => {
5652
5936
  const profile = userProfile;
@@ -5680,7 +5964,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
5680
5964
  const academeUser = {
5681
5965
  keycloakUser: getKeycloakUser(),
5682
5966
  };
5683
- setCurrentUser({ ...academeUser, id: userProfileSub });
5967
+ setCurrentUser({ ...academeUser, id: userProfileSub || "" });
5684
5968
  }
5685
5969
  return;
5686
5970
  }
@@ -5763,6 +6047,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
5763
6047
  // Memoizar o value do context para evitar re-renders desnecessários
5764
6048
  const contextValue = React2.useMemo(() => ({
5765
6049
  isInitialized: !isLoading,
6050
+ isTokenReady,
5766
6051
  user: currentUser,
5767
6052
  refreshUserData,
5768
6053
  signOut,
@@ -5776,6 +6061,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
5776
6061
  services,
5777
6062
  }), [
5778
6063
  isLoading,
6064
+ isTokenReady,
5779
6065
  currentUser,
5780
6066
  refreshUserData,
5781
6067
  signOut,