@smartsides/oracle-ebs-sdk 1.0.6 → 1.0.9

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.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import ky from 'ky';
2
+ import { useMutation, useQuery } from '@tanstack/react-query';
2
3
 
3
4
  // src/client/BaseClient.ts
4
5
 
@@ -173,7 +174,8 @@ var BaseClient = class {
173
174
  async post(url, data, options) {
174
175
  try {
175
176
  this.log("info", `POST ${url}`);
176
- const response = await this.client.post(url, { json: data, ...options }).json();
177
+ const requestOptions = data instanceof FormData ? { body: data, ...options } : { json: data, ...options };
178
+ const response = await this.client.post(url, requestOptions).json();
177
179
  return response;
178
180
  } catch (error) {
179
181
  throw this.handleError(error);
@@ -362,10 +364,11 @@ var SitRequestsModule = class extends BaseClient {
362
364
  */
363
365
  async getHistory(params) {
364
366
  const searchParams = new URLSearchParams();
365
- if (params?.startDate) searchParams.set("startDate", params.startDate);
366
- if (params?.endDate) searchParams.set("endDate", params.endDate);
367
- const url = `sit-requests/history${searchParams.toString() ? `?${searchParams}` : ""}`;
368
- const response = await this.get(url);
367
+ searchParams.set("sitName", params.sitName);
368
+ if (params.transactionId) searchParams.set("transactionId", params.transactionId);
369
+ if (params.startDate) searchParams.set("startDate", params.startDate);
370
+ if (params.endDate) searchParams.set("endDate", params.endDate);
371
+ const response = await this.get(`sit-requests/history?${searchParams}`);
369
372
  return response.data;
370
373
  }
371
374
  };
@@ -389,78 +392,92 @@ var NotificationsModule = class extends BaseClient {
389
392
  return response.data;
390
393
  }
391
394
  /**
392
- * Process approval action (approve/reject)
395
+ * Get all notification details (SSHR_SIT_REQDTLS)
396
+ * All parameters are required
397
+ */
398
+ async getAllDetails(params) {
399
+ const searchParams = new URLSearchParams();
400
+ searchParams.set("notificationId", params.notificationId);
401
+ searchParams.set("itemKey", params.itemKey);
402
+ searchParams.set("analysisCriteriaId", params.analysisCriteriaId);
403
+ searchParams.set("idFlexNum", params.idFlexNum);
404
+ const response = await this.get(`notifications/all-details?${searchParams}`);
405
+ return response.data;
406
+ }
407
+ /**
408
+ * Get absence details for FYI notifications
409
+ */
410
+ async getAbsenceDetails(params) {
411
+ const searchParams = new URLSearchParams();
412
+ searchParams.set("itemKey", params.itemKey);
413
+ const response = await this.get(`notifications/absence-details?${searchParams}`);
414
+ return response.data;
415
+ }
416
+ /**
417
+ * Get action history for a notification
418
+ */
419
+ async getActionHistory(params) {
420
+ const searchParams = new URLSearchParams();
421
+ searchParams.set("notificationId", params.notificationId);
422
+ const response = await this.get(`notifications/action-history?${searchParams}`);
423
+ return response.data;
424
+ }
425
+ /**
426
+ * Process approval action (APPROVE/DECLINE)
393
427
  */
394
428
  async processApproval(input) {
395
- const response = await this.post("notifications/process-approval", input);
429
+ const response = await this.post("notifications/process-approval-action", input);
396
430
  return response.data;
397
431
  }
398
432
  /**
399
433
  * Close FYI notification
400
434
  */
401
435
  async closeFyi(params) {
402
- const searchParams = new URLSearchParams();
403
- searchParams.set("notificationId", params.notificationId);
404
- const response = await this.get(`notifications/close-fyi?${searchParams}`);
436
+ const response = await this.post("notifications/close-fyi", {
437
+ notificationId: params.notificationId
438
+ });
405
439
  return response.data;
406
440
  }
407
441
  };
408
442
 
409
443
  // src/modules/PayslipModule.ts
410
444
  var PayslipModule = class extends BaseClient {
411
- /**
412
- * Get employee number from stored user context
413
- */
414
- getEmployeeNumberFromContext(providedEmployeeNumber) {
415
- if (providedEmployeeNumber) {
416
- return providedEmployeeNumber;
417
- }
418
- const employeeNumber = this.getEmployeeNumber();
419
- if (!employeeNumber) {
420
- throw new Error("Employee number not available. Please login first.");
421
- }
422
- return employeeNumber;
423
- }
424
445
  /**
425
446
  * Get payslip header
447
+ * Note: employeeNumber is extracted from JWT by backend
426
448
  */
427
449
  async getHeader(params) {
428
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
429
450
  const searchParams = new URLSearchParams();
430
- searchParams.set("employeeNumber", employeeNumber);
431
451
  searchParams.set("periodName", params.periodName);
432
452
  const response = await this.get(`payslip/header?${searchParams}`);
433
453
  return response.data;
434
454
  }
435
455
  /**
436
456
  * Get payslip details
457
+ * Note: employeeNumber is extracted from JWT by backend
437
458
  */
438
459
  async getDetails(params) {
439
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
440
460
  const searchParams = new URLSearchParams();
441
- searchParams.set("employeeNumber", employeeNumber);
442
461
  searchParams.set("periodName", params.periodName);
443
462
  const response = await this.get(`payslip/details?${searchParams}`);
444
463
  return response.data;
445
464
  }
446
465
  /**
447
466
  * Get payslip leave details
467
+ * Note: employeeNumber is extracted from JWT by backend
448
468
  */
449
469
  async getLeaveDetails(params) {
450
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
451
470
  const searchParams = new URLSearchParams();
452
- searchParams.set("employeeNumber", employeeNumber);
453
471
  searchParams.set("periodName", params.periodName);
454
472
  const response = await this.get(`payslip/leave-details?${searchParams}`);
455
473
  return response.data;
456
474
  }
457
475
  /**
458
476
  * Get payslip run balances
477
+ * Note: employeeNumber is extracted from JWT by backend
459
478
  */
460
479
  async getRunBalances(params) {
461
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
462
480
  const searchParams = new URLSearchParams();
463
- searchParams.set("employeeNumber", employeeNumber);
464
481
  searchParams.set("periodName", params.periodName);
465
482
  const response = await this.get(`payslip/run-balances?${searchParams}`);
466
483
  return response.data;
@@ -539,6 +556,127 @@ var HealthModule = class extends BaseClient {
539
556
  }
540
557
  };
541
558
 
559
+ // src/modules/AiModule.ts
560
+ var AiModule = class extends BaseClient {
561
+ /**
562
+ * Send a text message to the AI assistant
563
+ * @param request Chat request with message and optional history
564
+ * @returns AI response with message and CTAs
565
+ */
566
+ async sendMessage(request) {
567
+ const response = await this.post("ai/chat", request);
568
+ return response.data;
569
+ }
570
+ /**
571
+ * Send a voice message to the AI assistant
572
+ * @param audioBlob Audio file as Blob
573
+ * @param options Optional language and threadId for conversation continuity
574
+ * @returns Transcription and AI response
575
+ */
576
+ async sendVoice(audioBlob, options) {
577
+ const formData = new FormData();
578
+ formData.append("audio", audioBlob, "voice-message.webm");
579
+ if (options?.language) {
580
+ formData.append("language", options.language);
581
+ }
582
+ if (options?.threadId) {
583
+ formData.append("threadId", options.threadId);
584
+ }
585
+ const response = await this.post("ai/voice", formData, {
586
+ headers: {
587
+ // Let browser set Content-Type with boundary for multipart/form-data
588
+ }
589
+ });
590
+ return response.data;
591
+ }
592
+ /**
593
+ * Save chat message to local history
594
+ * @param message Chat message to save
595
+ */
596
+ saveChatMessage(message) {
597
+ try {
598
+ const history = this.getLocalChatHistory();
599
+ history.push({
600
+ ...message,
601
+ timestamp: /* @__PURE__ */ new Date()
602
+ });
603
+ const trimmedHistory = history.slice(-50);
604
+ if (typeof localStorage !== "undefined") {
605
+ localStorage.setItem(
606
+ "ai_chat_history",
607
+ JSON.stringify(trimmedHistory)
608
+ );
609
+ }
610
+ } catch (error) {
611
+ console.error("Failed to save chat message:", error);
612
+ }
613
+ }
614
+ /**
615
+ * Get local chat history from localStorage
616
+ * @returns Array of chat messages with timestamps
617
+ */
618
+ getLocalChatHistory() {
619
+ try {
620
+ if (typeof localStorage === "undefined") return [];
621
+ const stored = localStorage.getItem("ai_chat_history");
622
+ if (!stored) return [];
623
+ const parsed = JSON.parse(stored);
624
+ return parsed.map((msg) => ({
625
+ ...msg,
626
+ timestamp: new Date(msg.timestamp)
627
+ }));
628
+ } catch (error) {
629
+ console.error("Failed to get chat history:", error);
630
+ return [];
631
+ }
632
+ }
633
+ /**
634
+ * Clear local chat history
635
+ */
636
+ clearChatHistory() {
637
+ try {
638
+ if (typeof localStorage !== "undefined") {
639
+ localStorage.removeItem("ai_chat_history");
640
+ }
641
+ } catch (error) {
642
+ console.error("Failed to clear chat history:", error);
643
+ }
644
+ }
645
+ // ==================== Chat Thread Management ====================
646
+ /**
647
+ * Get all chat threads for the current user
648
+ * @returns Array of chat threads
649
+ */
650
+ async getChatThreads() {
651
+ const response = await this.get("ai/threads");
652
+ return response.data.threads;
653
+ }
654
+ /**
655
+ * Get messages for a specific thread
656
+ * @param threadId Thread ID
657
+ * @returns Thread with messages
658
+ */
659
+ async getThreadMessages(threadId) {
660
+ const response = await this.get(`ai/threads/${threadId}/messages`);
661
+ return response.data;
662
+ }
663
+ /**
664
+ * Create a new chat thread
665
+ * @returns New thread
666
+ */
667
+ async createThread() {
668
+ const response = await this.post("ai/threads", {});
669
+ return response.data.thread;
670
+ }
671
+ /**
672
+ * Delete a chat thread
673
+ * @param threadId Thread ID to delete
674
+ */
675
+ async deleteThread(threadId) {
676
+ await this.delete(`ai/threads/${threadId}`);
677
+ }
678
+ };
679
+
542
680
  // src/client/OracleEBSClient.ts
543
681
  var OracleEBSClient = class {
544
682
  constructor(config) {
@@ -551,6 +689,7 @@ var OracleEBSClient = class {
551
689
  this.accrualBalances = new AccrualBalancesModule(config);
552
690
  this.forms = new FormsModule(config);
553
691
  this.health = new HealthModule(config);
692
+ this.ai = new AiModule(config);
554
693
  }
555
694
  /**
556
695
  * Set authentication token for all modules
@@ -565,6 +704,7 @@ var OracleEBSClient = class {
565
704
  this.accrualBalances.setToken(token, user);
566
705
  this.forms.setToken(token, user);
567
706
  this.health.setToken(token, user);
707
+ this.ai.setToken(token, user);
568
708
  }
569
709
  /**
570
710
  * Clear authentication token from all modules
@@ -579,9 +719,207 @@ var OracleEBSClient = class {
579
719
  this.accrualBalances.clearToken();
580
720
  this.forms.clearToken();
581
721
  this.health.clearToken();
722
+ this.ai.clearToken();
723
+ }
724
+ };
725
+
726
+ // src/types/ai.ts
727
+ var MessageRole = /* @__PURE__ */ ((MessageRole2) => {
728
+ MessageRole2["USER"] = "user";
729
+ MessageRole2["ASSISTANT"] = "assistant";
730
+ MessageRole2["SYSTEM"] = "system";
731
+ return MessageRole2;
732
+ })(MessageRole || {});
733
+ var ActionType = /* @__PURE__ */ ((ActionType2) => {
734
+ ActionType2["NAVIGATE"] = "navigate";
735
+ ActionType2["API_CALL"] = "api_call";
736
+ ActionType2["DOWNLOAD"] = "download";
737
+ ActionType2["CLOSE_NOTIFICATION"] = "close_notification";
738
+ ActionType2["SUBMIT_LEAVE"] = "submit_leave";
739
+ ActionType2["APPROVE_NOTIFICATION"] = "approve_notification";
740
+ ActionType2["DECLINE_NOTIFICATION"] = "decline_notification";
741
+ return ActionType2;
742
+ })(ActionType || {});
743
+ var UserIntent = /* @__PURE__ */ ((UserIntent2) => {
744
+ UserIntent2["NOTIFICATIONS_SUMMARY"] = "notifications_summary";
745
+ UserIntent2["NOTIFICATION_CLOSE"] = "notification_close";
746
+ UserIntent2["NOTIFICATION_ACTION"] = "notification_action";
747
+ UserIntent2["PAYSLIP_QUERY"] = "payslip_query";
748
+ UserIntent2["PAYSLIP_RETRIEVAL"] = "payslip_retrieval";
749
+ UserIntent2["SALARY_DEDUCTION"] = "salary_deduction";
750
+ UserIntent2["LEAVE_BALANCE"] = "leave_balance";
751
+ UserIntent2["LEAVE_REQUEST"] = "leave_request";
752
+ UserIntent2["PROFILE_INFO"] = "profile_info";
753
+ UserIntent2["HIRING_DATE"] = "hiring_date";
754
+ UserIntent2["POSITION_INFO"] = "position_info";
755
+ UserIntent2["GENERAL_QUERY"] = "general_query";
756
+ UserIntent2["OUT_OF_SCOPE"] = "out_of_scope";
757
+ return UserIntent2;
758
+ })(UserIntent || {});
759
+ var queryKeys = {
760
+ auth: {
761
+ userContext: ["auth", "user-context"]
762
+ },
763
+ leaves: {
764
+ restrictedTypes: (params) => ["leaves", "restricted-types", params],
765
+ history: ["leaves", "history"]
766
+ },
767
+ sitRequests: {
768
+ segments: (params) => ["sit-requests", "segments", params],
769
+ history: ["sit-requests", "history"]
770
+ },
771
+ notifications: {
772
+ list: ["notifications", "list"],
773
+ details: (notificationId) => ["notifications", "details", notificationId]
774
+ },
775
+ payslip: {
776
+ header: (periodName) => ["payslip", "header", periodName],
777
+ details: (periodName) => ["payslip", "details", periodName]
778
+ },
779
+ employee: {
780
+ personalInfo: ["employee", "personal-info"],
781
+ hierarchy: ["employee", "hierarchy"]
782
+ },
783
+ accrualBalances: {
784
+ get: (calculationDate) => ["accrual-balances", calculationDate]
785
+ },
786
+ forms: {
787
+ tableColumns: (tableName) => ["forms", "table-columns", tableName],
788
+ dffSegments: (params) => ["forms", "dff-segments", params]
789
+ },
790
+ health: {
791
+ check: ["health", "check"]
582
792
  }
583
793
  };
794
+ function useLogin(client, options) {
795
+ return useMutation({
796
+ mutationFn: (credentials) => client.auth.login(credentials),
797
+ ...options
798
+ });
799
+ }
800
+ function useUserContext(client, options) {
801
+ return useQuery({
802
+ queryKey: queryKeys.auth.userContext,
803
+ queryFn: () => client.auth.getUserContext(),
804
+ ...options
805
+ });
806
+ }
807
+ function useLeaveTypes(client, params, options) {
808
+ return useQuery({
809
+ queryKey: queryKeys.leaves.restrictedTypes(params),
810
+ queryFn: () => client.leaves.getRestrictedTypes(params),
811
+ ...options
812
+ });
813
+ }
814
+ function useLeaveHistory(client, options) {
815
+ return useQuery({
816
+ queryKey: queryKeys.leaves.history,
817
+ queryFn: () => client.leaves.getHistory(),
818
+ ...options
819
+ });
820
+ }
821
+ function useCreateLeaveRequest(client, options) {
822
+ return useMutation({
823
+ mutationFn: (input) => client.leaves.createRequest(input),
824
+ ...options
825
+ });
826
+ }
827
+ function useSitSegments(client, params, options) {
828
+ return useQuery({
829
+ queryKey: queryKeys.sitRequests.segments(params),
830
+ queryFn: () => client.sitRequests.getSegments(params),
831
+ ...options
832
+ });
833
+ }
834
+ function useSaveAndPreviewSitRequest(client, options) {
835
+ return useMutation({
836
+ mutationFn: (input) => client.sitRequests.saveAndPreview(input),
837
+ ...options
838
+ });
839
+ }
840
+ function useSubmitSitRequest(client, options) {
841
+ return useMutation({
842
+ mutationFn: (input) => client.sitRequests.submit(input),
843
+ ...options
844
+ });
845
+ }
846
+ function useNotifications(client, options) {
847
+ return useQuery({
848
+ queryKey: queryKeys.notifications.list,
849
+ queryFn: () => client.notifications.getList(),
850
+ ...options
851
+ });
852
+ }
853
+ function useNotificationDetails(client, params, options) {
854
+ return useQuery({
855
+ queryKey: queryKeys.notifications.details(params.notificationId),
856
+ queryFn: () => client.notifications.getDetails(params),
857
+ ...options
858
+ });
859
+ }
860
+ function useProcessApproval(client, options) {
861
+ return useMutation({
862
+ mutationFn: (input) => client.notifications.processApproval(input),
863
+ ...options
864
+ });
865
+ }
866
+ function usePayslipHeader(client, params, options) {
867
+ return useQuery({
868
+ queryKey: queryKeys.payslip.header(params.periodName),
869
+ queryFn: () => client.payslip.getHeader(params),
870
+ ...options
871
+ });
872
+ }
873
+ function usePayslipDetails(client, params, options) {
874
+ return useQuery({
875
+ queryKey: queryKeys.payslip.details(params.periodName),
876
+ queryFn: () => client.payslip.getDetails(params),
877
+ ...options
878
+ });
879
+ }
880
+ function usePersonalInfo(client, options) {
881
+ return useQuery({
882
+ queryKey: queryKeys.employee.personalInfo,
883
+ queryFn: () => client.employee.getPersonalInfo(),
884
+ ...options
885
+ });
886
+ }
887
+ function useEmployeeHierarchy(client, options) {
888
+ return useQuery({
889
+ queryKey: queryKeys.employee.hierarchy,
890
+ queryFn: () => client.employee.getHierarchy(),
891
+ ...options
892
+ });
893
+ }
894
+ function useAccrualBalances(client, params, options) {
895
+ return useQuery({
896
+ queryKey: queryKeys.accrualBalances.get(params.calculationDate),
897
+ queryFn: () => client.accrualBalances.getBalances(params),
898
+ ...options
899
+ });
900
+ }
901
+ function useTableColumns(client, params, options) {
902
+ return useQuery({
903
+ queryKey: queryKeys.forms.tableColumns(params.tableName),
904
+ queryFn: () => client.forms.getTableColumns(params),
905
+ ...options
906
+ });
907
+ }
908
+ function useDffSegments(client, params, options) {
909
+ return useQuery({
910
+ queryKey: queryKeys.forms.dffSegments(params),
911
+ queryFn: () => client.forms.getDffSegments(params),
912
+ ...options
913
+ });
914
+ }
915
+ function useHealthCheck(client, options) {
916
+ return useQuery({
917
+ queryKey: queryKeys.health.check,
918
+ queryFn: () => client.health.check(),
919
+ ...options
920
+ });
921
+ }
584
922
 
585
- export { APIError, ForbiddenError, NetworkError, NotFoundError, OracleEBSClient, ServerError, TimeoutError, UnauthorizedError, ValidationError };
923
+ export { APIError, ActionType, ForbiddenError, MessageRole, NetworkError, NotFoundError, OracleEBSClient, ServerError, TimeoutError, UnauthorizedError, UserIntent, ValidationError, queryKeys, useAccrualBalances, useCreateLeaveRequest, useDffSegments, useEmployeeHierarchy, useHealthCheck, useLeaveHistory, useLeaveTypes, useLogin, useNotificationDetails, useNotifications, usePayslipDetails, usePayslipHeader, usePersonalInfo, useProcessApproval, useSaveAndPreviewSitRequest, useSitSegments, useSubmitSitRequest, useTableColumns, useUserContext };
586
924
  //# sourceMappingURL=index.mjs.map
587
925
  //# sourceMappingURL=index.mjs.map