@smartsides/oracle-ebs-sdk 1.0.7 → 1.0.10

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.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var ky = require('ky');
4
+ var reactQuery = require('@tanstack/react-query');
4
5
 
5
6
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
7
 
@@ -179,7 +180,8 @@ var BaseClient = class {
179
180
  async post(url, data, options) {
180
181
  try {
181
182
  this.log("info", `POST ${url}`);
182
- const response = await this.client.post(url, { json: data, ...options }).json();
183
+ const requestOptions = data instanceof FormData ? { body: data, ...options } : { json: data, ...options };
184
+ const response = await this.client.post(url, requestOptions).json();
183
185
  return response;
184
186
  } catch (error) {
185
187
  throw this.handleError(error);
@@ -368,10 +370,11 @@ var SitRequestsModule = class extends BaseClient {
368
370
  */
369
371
  async getHistory(params) {
370
372
  const searchParams = new URLSearchParams();
371
- if (params?.startDate) searchParams.set("startDate", params.startDate);
372
- if (params?.endDate) searchParams.set("endDate", params.endDate);
373
- const url = `sit-requests/history${searchParams.toString() ? `?${searchParams}` : ""}`;
374
- const response = await this.get(url);
373
+ searchParams.set("sitName", params.sitName);
374
+ if (params.transactionId) searchParams.set("transactionId", params.transactionId);
375
+ if (params.startDate) searchParams.set("startDate", params.startDate);
376
+ if (params.endDate) searchParams.set("endDate", params.endDate);
377
+ const response = await this.get(`sit-requests/history?${searchParams}`);
375
378
  return response.data;
376
379
  }
377
380
  };
@@ -445,59 +448,42 @@ var NotificationsModule = class extends BaseClient {
445
448
 
446
449
  // src/modules/PayslipModule.ts
447
450
  var PayslipModule = class extends BaseClient {
448
- /**
449
- * Get employee number from stored user context
450
- */
451
- getEmployeeNumberFromContext(providedEmployeeNumber) {
452
- if (providedEmployeeNumber) {
453
- return providedEmployeeNumber;
454
- }
455
- const employeeNumber = this.getEmployeeNumber();
456
- if (!employeeNumber) {
457
- throw new Error("Employee number not available. Please login first.");
458
- }
459
- return employeeNumber;
460
- }
461
451
  /**
462
452
  * Get payslip header
453
+ * Note: employeeNumber is extracted from JWT by backend
463
454
  */
464
455
  async getHeader(params) {
465
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
466
456
  const searchParams = new URLSearchParams();
467
- searchParams.set("employeeNumber", employeeNumber);
468
457
  searchParams.set("periodName", params.periodName);
469
458
  const response = await this.get(`payslip/header?${searchParams}`);
470
459
  return response.data;
471
460
  }
472
461
  /**
473
462
  * Get payslip details
463
+ * Note: employeeNumber is extracted from JWT by backend
474
464
  */
475
465
  async getDetails(params) {
476
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
477
466
  const searchParams = new URLSearchParams();
478
- searchParams.set("employeeNumber", employeeNumber);
479
467
  searchParams.set("periodName", params.periodName);
480
468
  const response = await this.get(`payslip/details?${searchParams}`);
481
469
  return response.data;
482
470
  }
483
471
  /**
484
472
  * Get payslip leave details
473
+ * Note: employeeNumber is extracted from JWT by backend
485
474
  */
486
475
  async getLeaveDetails(params) {
487
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
488
476
  const searchParams = new URLSearchParams();
489
- searchParams.set("employeeNumber", employeeNumber);
490
477
  searchParams.set("periodName", params.periodName);
491
478
  const response = await this.get(`payslip/leave-details?${searchParams}`);
492
479
  return response.data;
493
480
  }
494
481
  /**
495
482
  * Get payslip run balances
483
+ * Note: employeeNumber is extracted from JWT by backend
496
484
  */
497
485
  async getRunBalances(params) {
498
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
499
486
  const searchParams = new URLSearchParams();
500
- searchParams.set("employeeNumber", employeeNumber);
501
487
  searchParams.set("periodName", params.periodName);
502
488
  const response = await this.get(`payslip/run-balances?${searchParams}`);
503
489
  return response.data;
@@ -576,6 +562,140 @@ var HealthModule = class extends BaseClient {
576
562
  }
577
563
  };
578
564
 
565
+ // src/modules/AiModule.ts
566
+ var AiModule = class extends BaseClient {
567
+ /**
568
+ * Send a text message to the AI assistant
569
+ * @param request Chat request with message and optional history
570
+ * @returns AI response with message and CTAs
571
+ */
572
+ async sendMessage(request) {
573
+ const response = await this.post("ai/chat", request);
574
+ return response.data;
575
+ }
576
+ /**
577
+ * Send a voice message to the AI assistant
578
+ * @param audioBlob Audio file as Blob
579
+ * @param options Optional language and threadId for conversation continuity
580
+ * @returns Transcription and AI response
581
+ */
582
+ async sendVoice(audioBlob, options) {
583
+ const formData = new FormData();
584
+ formData.append("audio", audioBlob, "voice-message.webm");
585
+ if (options?.language) {
586
+ formData.append("language", options.language);
587
+ }
588
+ if (options?.threadId) {
589
+ formData.append("threadId", options.threadId);
590
+ }
591
+ const response = await this.post("ai/voice", formData, {
592
+ headers: {
593
+ // Let browser set Content-Type with boundary for multipart/form-data
594
+ }
595
+ });
596
+ return response.data;
597
+ }
598
+ /**
599
+ * Save chat message to local history
600
+ * @param message Chat message to save
601
+ */
602
+ saveChatMessage(message) {
603
+ try {
604
+ const history = this.getLocalChatHistory();
605
+ history.push({
606
+ ...message,
607
+ timestamp: /* @__PURE__ */ new Date()
608
+ });
609
+ const trimmedHistory = history.slice(-50);
610
+ if (typeof localStorage !== "undefined") {
611
+ localStorage.setItem(
612
+ "ai_chat_history",
613
+ JSON.stringify(trimmedHistory)
614
+ );
615
+ }
616
+ } catch (error) {
617
+ console.error("Failed to save chat message:", error);
618
+ }
619
+ }
620
+ /**
621
+ * Get local chat history from localStorage
622
+ * @returns Array of chat messages with timestamps
623
+ */
624
+ getLocalChatHistory() {
625
+ try {
626
+ if (typeof localStorage === "undefined") return [];
627
+ const stored = localStorage.getItem("ai_chat_history");
628
+ if (!stored) return [];
629
+ const parsed = JSON.parse(stored);
630
+ return parsed.map((msg) => ({
631
+ ...msg,
632
+ timestamp: new Date(msg.timestamp)
633
+ }));
634
+ } catch (error) {
635
+ console.error("Failed to get chat history:", error);
636
+ return [];
637
+ }
638
+ }
639
+ /**
640
+ * Clear local chat history
641
+ */
642
+ clearChatHistory() {
643
+ try {
644
+ if (typeof localStorage !== "undefined") {
645
+ localStorage.removeItem("ai_chat_history");
646
+ }
647
+ } catch (error) {
648
+ console.error("Failed to clear chat history:", error);
649
+ }
650
+ }
651
+ // ==================== Chat Thread Management ====================
652
+ /**
653
+ * Get all chat threads for the current user
654
+ * @returns Array of chat threads
655
+ */
656
+ async getChatThreads() {
657
+ const response = await this.get("ai/threads");
658
+ return response.data.threads;
659
+ }
660
+ /**
661
+ * Get messages for a specific thread
662
+ * @param threadId Thread ID
663
+ * @returns Thread with messages
664
+ */
665
+ async getThreadMessages(threadId) {
666
+ const response = await this.get(`ai/threads/${threadId}/messages`);
667
+ return response.data;
668
+ }
669
+ /**
670
+ * Create a new chat thread
671
+ * @returns New thread
672
+ */
673
+ async createThread() {
674
+ const response = await this.post("ai/threads", {});
675
+ return response.data.thread;
676
+ }
677
+ /**
678
+ * Delete a chat thread
679
+ * @param threadId Thread ID to delete
680
+ */
681
+ async deleteThread(threadId) {
682
+ await this.delete(`ai/threads/${threadId}`);
683
+ }
684
+ };
685
+
686
+ // src/modules/SegmentsModule.ts
687
+ var SegmentsModule = class extends BaseClient {
688
+ /**
689
+ * Get SIT segments
690
+ */
691
+ async getSitSegments(params) {
692
+ const searchParams = new URLSearchParams();
693
+ searchParams.set("idFlexNum", params.idFlexNum);
694
+ const response = await this.get(`segments/sit-segments?${searchParams}`);
695
+ return response.data;
696
+ }
697
+ };
698
+
579
699
  // src/client/OracleEBSClient.ts
580
700
  var OracleEBSClient = class {
581
701
  constructor(config) {
@@ -588,6 +708,8 @@ var OracleEBSClient = class {
588
708
  this.accrualBalances = new AccrualBalancesModule(config);
589
709
  this.forms = new FormsModule(config);
590
710
  this.health = new HealthModule(config);
711
+ this.ai = new AiModule(config);
712
+ this.segments = new SegmentsModule(config);
591
713
  }
592
714
  /**
593
715
  * Set authentication token for all modules
@@ -602,6 +724,8 @@ var OracleEBSClient = class {
602
724
  this.accrualBalances.setToken(token, user);
603
725
  this.forms.setToken(token, user);
604
726
  this.health.setToken(token, user);
727
+ this.ai.setToken(token, user);
728
+ this.segments.setToken(token, user);
605
729
  }
606
730
  /**
607
731
  * Clear authentication token from all modules
@@ -616,17 +740,239 @@ var OracleEBSClient = class {
616
740
  this.accrualBalances.clearToken();
617
741
  this.forms.clearToken();
618
742
  this.health.clearToken();
743
+ this.ai.clearToken();
744
+ this.segments.clearToken();
745
+ }
746
+ };
747
+
748
+ // src/types/ai.ts
749
+ var MessageRole = /* @__PURE__ */ ((MessageRole2) => {
750
+ MessageRole2["USER"] = "user";
751
+ MessageRole2["ASSISTANT"] = "assistant";
752
+ MessageRole2["SYSTEM"] = "system";
753
+ return MessageRole2;
754
+ })(MessageRole || {});
755
+ var ActionType = /* @__PURE__ */ ((ActionType2) => {
756
+ ActionType2["NAVIGATE"] = "navigate";
757
+ ActionType2["API_CALL"] = "api_call";
758
+ ActionType2["DOWNLOAD"] = "download";
759
+ ActionType2["CLOSE_NOTIFICATION"] = "close_notification";
760
+ ActionType2["SUBMIT_LEAVE"] = "submit_leave";
761
+ ActionType2["APPROVE_NOTIFICATION"] = "approve_notification";
762
+ ActionType2["DECLINE_NOTIFICATION"] = "decline_notification";
763
+ return ActionType2;
764
+ })(ActionType || {});
765
+ var UserIntent = /* @__PURE__ */ ((UserIntent2) => {
766
+ UserIntent2["NOTIFICATIONS_SUMMARY"] = "notifications_summary";
767
+ UserIntent2["NOTIFICATION_CLOSE"] = "notification_close";
768
+ UserIntent2["NOTIFICATION_ACTION"] = "notification_action";
769
+ UserIntent2["PAYSLIP_QUERY"] = "payslip_query";
770
+ UserIntent2["PAYSLIP_RETRIEVAL"] = "payslip_retrieval";
771
+ UserIntent2["SALARY_DEDUCTION"] = "salary_deduction";
772
+ UserIntent2["LEAVE_BALANCE"] = "leave_balance";
773
+ UserIntent2["LEAVE_REQUEST"] = "leave_request";
774
+ UserIntent2["PROFILE_INFO"] = "profile_info";
775
+ UserIntent2["HIRING_DATE"] = "hiring_date";
776
+ UserIntent2["POSITION_INFO"] = "position_info";
777
+ UserIntent2["GENERAL_QUERY"] = "general_query";
778
+ UserIntent2["OUT_OF_SCOPE"] = "out_of_scope";
779
+ return UserIntent2;
780
+ })(UserIntent || {});
781
+ var queryKeys = {
782
+ auth: {
783
+ userContext: ["auth", "user-context"]
784
+ },
785
+ leaves: {
786
+ restrictedTypes: (params) => ["leaves", "restricted-types", params],
787
+ history: ["leaves", "history"]
788
+ },
789
+ sitRequests: {
790
+ segments: (params) => ["sit-requests", "segments", params],
791
+ history: ["sit-requests", "history"]
792
+ },
793
+ notifications: {
794
+ list: ["notifications", "list"],
795
+ details: (notificationId) => ["notifications", "details", notificationId]
796
+ },
797
+ payslip: {
798
+ header: (periodName) => ["payslip", "header", periodName],
799
+ details: (periodName) => ["payslip", "details", periodName]
800
+ },
801
+ employee: {
802
+ personalInfo: ["employee", "personal-info"],
803
+ hierarchy: ["employee", "hierarchy"]
804
+ },
805
+ accrualBalances: {
806
+ get: (calculationDate) => ["accrual-balances", calculationDate]
807
+ },
808
+ forms: {
809
+ tableColumns: (tableName) => ["forms", "table-columns", tableName],
810
+ dffSegments: (params) => ["forms", "dff-segments", params]
811
+ },
812
+ health: {
813
+ check: ["health", "check"]
619
814
  }
620
815
  };
816
+ function useLogin(client, options) {
817
+ return reactQuery.useMutation({
818
+ mutationFn: (credentials) => client.auth.login(credentials),
819
+ ...options
820
+ });
821
+ }
822
+ function useUserContext(client, options) {
823
+ return reactQuery.useQuery({
824
+ queryKey: queryKeys.auth.userContext,
825
+ queryFn: () => client.auth.getUserContext(),
826
+ ...options
827
+ });
828
+ }
829
+ function useLeaveTypes(client, params, options) {
830
+ return reactQuery.useQuery({
831
+ queryKey: queryKeys.leaves.restrictedTypes(params),
832
+ queryFn: () => client.leaves.getRestrictedTypes(params),
833
+ ...options
834
+ });
835
+ }
836
+ function useLeaveHistory(client, options) {
837
+ return reactQuery.useQuery({
838
+ queryKey: queryKeys.leaves.history,
839
+ queryFn: () => client.leaves.getHistory(),
840
+ ...options
841
+ });
842
+ }
843
+ function useCreateLeaveRequest(client, options) {
844
+ return reactQuery.useMutation({
845
+ mutationFn: (input) => client.leaves.createRequest(input),
846
+ ...options
847
+ });
848
+ }
849
+ function useSitSegments(client, params, options) {
850
+ return reactQuery.useQuery({
851
+ queryKey: queryKeys.sitRequests.segments(params),
852
+ queryFn: () => client.sitRequests.getSegments(params),
853
+ ...options
854
+ });
855
+ }
856
+ function useSaveAndPreviewSitRequest(client, options) {
857
+ return reactQuery.useMutation({
858
+ mutationFn: (input) => client.sitRequests.saveAndPreview(input),
859
+ ...options
860
+ });
861
+ }
862
+ function useSubmitSitRequest(client, options) {
863
+ return reactQuery.useMutation({
864
+ mutationFn: (input) => client.sitRequests.submit(input),
865
+ ...options
866
+ });
867
+ }
868
+ function useNotifications(client, options) {
869
+ return reactQuery.useQuery({
870
+ queryKey: queryKeys.notifications.list,
871
+ queryFn: () => client.notifications.getList(),
872
+ ...options
873
+ });
874
+ }
875
+ function useNotificationDetails(client, params, options) {
876
+ return reactQuery.useQuery({
877
+ queryKey: queryKeys.notifications.details(params.notificationId),
878
+ queryFn: () => client.notifications.getDetails(params),
879
+ ...options
880
+ });
881
+ }
882
+ function useProcessApproval(client, options) {
883
+ return reactQuery.useMutation({
884
+ mutationFn: (input) => client.notifications.processApproval(input),
885
+ ...options
886
+ });
887
+ }
888
+ function usePayslipHeader(client, params, options) {
889
+ return reactQuery.useQuery({
890
+ queryKey: queryKeys.payslip.header(params.periodName),
891
+ queryFn: () => client.payslip.getHeader(params),
892
+ ...options
893
+ });
894
+ }
895
+ function usePayslipDetails(client, params, options) {
896
+ return reactQuery.useQuery({
897
+ queryKey: queryKeys.payslip.details(params.periodName),
898
+ queryFn: () => client.payslip.getDetails(params),
899
+ ...options
900
+ });
901
+ }
902
+ function usePersonalInfo(client, options) {
903
+ return reactQuery.useQuery({
904
+ queryKey: queryKeys.employee.personalInfo,
905
+ queryFn: () => client.employee.getPersonalInfo(),
906
+ ...options
907
+ });
908
+ }
909
+ function useEmployeeHierarchy(client, options) {
910
+ return reactQuery.useQuery({
911
+ queryKey: queryKeys.employee.hierarchy,
912
+ queryFn: () => client.employee.getHierarchy(),
913
+ ...options
914
+ });
915
+ }
916
+ function useAccrualBalances(client, params, options) {
917
+ return reactQuery.useQuery({
918
+ queryKey: queryKeys.accrualBalances.get(params.calculationDate),
919
+ queryFn: () => client.accrualBalances.getBalances(params),
920
+ ...options
921
+ });
922
+ }
923
+ function useTableColumns(client, params, options) {
924
+ return reactQuery.useQuery({
925
+ queryKey: queryKeys.forms.tableColumns(params.tableName),
926
+ queryFn: () => client.forms.getTableColumns(params),
927
+ ...options
928
+ });
929
+ }
930
+ function useDffSegments(client, params, options) {
931
+ return reactQuery.useQuery({
932
+ queryKey: queryKeys.forms.dffSegments(params),
933
+ queryFn: () => client.forms.getDffSegments(params),
934
+ ...options
935
+ });
936
+ }
937
+ function useHealthCheck(client, options) {
938
+ return reactQuery.useQuery({
939
+ queryKey: queryKeys.health.check,
940
+ queryFn: () => client.health.check(),
941
+ ...options
942
+ });
943
+ }
621
944
 
622
945
  exports.APIError = APIError;
946
+ exports.ActionType = ActionType;
623
947
  exports.ForbiddenError = ForbiddenError;
948
+ exports.MessageRole = MessageRole;
624
949
  exports.NetworkError = NetworkError;
625
950
  exports.NotFoundError = NotFoundError;
626
951
  exports.OracleEBSClient = OracleEBSClient;
627
952
  exports.ServerError = ServerError;
628
953
  exports.TimeoutError = TimeoutError;
629
954
  exports.UnauthorizedError = UnauthorizedError;
955
+ exports.UserIntent = UserIntent;
630
956
  exports.ValidationError = ValidationError;
957
+ exports.queryKeys = queryKeys;
958
+ exports.useAccrualBalances = useAccrualBalances;
959
+ exports.useCreateLeaveRequest = useCreateLeaveRequest;
960
+ exports.useDffSegments = useDffSegments;
961
+ exports.useEmployeeHierarchy = useEmployeeHierarchy;
962
+ exports.useHealthCheck = useHealthCheck;
963
+ exports.useLeaveHistory = useLeaveHistory;
964
+ exports.useLeaveTypes = useLeaveTypes;
965
+ exports.useLogin = useLogin;
966
+ exports.useNotificationDetails = useNotificationDetails;
967
+ exports.useNotifications = useNotifications;
968
+ exports.usePayslipDetails = usePayslipDetails;
969
+ exports.usePayslipHeader = usePayslipHeader;
970
+ exports.usePersonalInfo = usePersonalInfo;
971
+ exports.useProcessApproval = useProcessApproval;
972
+ exports.useSaveAndPreviewSitRequest = useSaveAndPreviewSitRequest;
973
+ exports.useSitSegments = useSitSegments;
974
+ exports.useSubmitSitRequest = useSubmitSitRequest;
975
+ exports.useTableColumns = useTableColumns;
976
+ exports.useUserContext = useUserContext;
631
977
  //# sourceMappingURL=index.js.map
632
978
  //# sourceMappingURL=index.js.map