@smartsides/oracle-ebs-sdk 1.0.7 → 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.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,127 @@ 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
+
579
686
  // src/client/OracleEBSClient.ts
580
687
  var OracleEBSClient = class {
581
688
  constructor(config) {
@@ -588,6 +695,7 @@ var OracleEBSClient = class {
588
695
  this.accrualBalances = new AccrualBalancesModule(config);
589
696
  this.forms = new FormsModule(config);
590
697
  this.health = new HealthModule(config);
698
+ this.ai = new AiModule(config);
591
699
  }
592
700
  /**
593
701
  * Set authentication token for all modules
@@ -602,6 +710,7 @@ var OracleEBSClient = class {
602
710
  this.accrualBalances.setToken(token, user);
603
711
  this.forms.setToken(token, user);
604
712
  this.health.setToken(token, user);
713
+ this.ai.setToken(token, user);
605
714
  }
606
715
  /**
607
716
  * Clear authentication token from all modules
@@ -616,17 +725,238 @@ var OracleEBSClient = class {
616
725
  this.accrualBalances.clearToken();
617
726
  this.forms.clearToken();
618
727
  this.health.clearToken();
728
+ this.ai.clearToken();
729
+ }
730
+ };
731
+
732
+ // src/types/ai.ts
733
+ var MessageRole = /* @__PURE__ */ ((MessageRole2) => {
734
+ MessageRole2["USER"] = "user";
735
+ MessageRole2["ASSISTANT"] = "assistant";
736
+ MessageRole2["SYSTEM"] = "system";
737
+ return MessageRole2;
738
+ })(MessageRole || {});
739
+ var ActionType = /* @__PURE__ */ ((ActionType2) => {
740
+ ActionType2["NAVIGATE"] = "navigate";
741
+ ActionType2["API_CALL"] = "api_call";
742
+ ActionType2["DOWNLOAD"] = "download";
743
+ ActionType2["CLOSE_NOTIFICATION"] = "close_notification";
744
+ ActionType2["SUBMIT_LEAVE"] = "submit_leave";
745
+ ActionType2["APPROVE_NOTIFICATION"] = "approve_notification";
746
+ ActionType2["DECLINE_NOTIFICATION"] = "decline_notification";
747
+ return ActionType2;
748
+ })(ActionType || {});
749
+ var UserIntent = /* @__PURE__ */ ((UserIntent2) => {
750
+ UserIntent2["NOTIFICATIONS_SUMMARY"] = "notifications_summary";
751
+ UserIntent2["NOTIFICATION_CLOSE"] = "notification_close";
752
+ UserIntent2["NOTIFICATION_ACTION"] = "notification_action";
753
+ UserIntent2["PAYSLIP_QUERY"] = "payslip_query";
754
+ UserIntent2["PAYSLIP_RETRIEVAL"] = "payslip_retrieval";
755
+ UserIntent2["SALARY_DEDUCTION"] = "salary_deduction";
756
+ UserIntent2["LEAVE_BALANCE"] = "leave_balance";
757
+ UserIntent2["LEAVE_REQUEST"] = "leave_request";
758
+ UserIntent2["PROFILE_INFO"] = "profile_info";
759
+ UserIntent2["HIRING_DATE"] = "hiring_date";
760
+ UserIntent2["POSITION_INFO"] = "position_info";
761
+ UserIntent2["GENERAL_QUERY"] = "general_query";
762
+ UserIntent2["OUT_OF_SCOPE"] = "out_of_scope";
763
+ return UserIntent2;
764
+ })(UserIntent || {});
765
+ var queryKeys = {
766
+ auth: {
767
+ userContext: ["auth", "user-context"]
768
+ },
769
+ leaves: {
770
+ restrictedTypes: (params) => ["leaves", "restricted-types", params],
771
+ history: ["leaves", "history"]
772
+ },
773
+ sitRequests: {
774
+ segments: (params) => ["sit-requests", "segments", params],
775
+ history: ["sit-requests", "history"]
776
+ },
777
+ notifications: {
778
+ list: ["notifications", "list"],
779
+ details: (notificationId) => ["notifications", "details", notificationId]
780
+ },
781
+ payslip: {
782
+ header: (periodName) => ["payslip", "header", periodName],
783
+ details: (periodName) => ["payslip", "details", periodName]
784
+ },
785
+ employee: {
786
+ personalInfo: ["employee", "personal-info"],
787
+ hierarchy: ["employee", "hierarchy"]
788
+ },
789
+ accrualBalances: {
790
+ get: (calculationDate) => ["accrual-balances", calculationDate]
791
+ },
792
+ forms: {
793
+ tableColumns: (tableName) => ["forms", "table-columns", tableName],
794
+ dffSegments: (params) => ["forms", "dff-segments", params]
795
+ },
796
+ health: {
797
+ check: ["health", "check"]
619
798
  }
620
799
  };
800
+ function useLogin(client, options) {
801
+ return reactQuery.useMutation({
802
+ mutationFn: (credentials) => client.auth.login(credentials),
803
+ ...options
804
+ });
805
+ }
806
+ function useUserContext(client, options) {
807
+ return reactQuery.useQuery({
808
+ queryKey: queryKeys.auth.userContext,
809
+ queryFn: () => client.auth.getUserContext(),
810
+ ...options
811
+ });
812
+ }
813
+ function useLeaveTypes(client, params, options) {
814
+ return reactQuery.useQuery({
815
+ queryKey: queryKeys.leaves.restrictedTypes(params),
816
+ queryFn: () => client.leaves.getRestrictedTypes(params),
817
+ ...options
818
+ });
819
+ }
820
+ function useLeaveHistory(client, options) {
821
+ return reactQuery.useQuery({
822
+ queryKey: queryKeys.leaves.history,
823
+ queryFn: () => client.leaves.getHistory(),
824
+ ...options
825
+ });
826
+ }
827
+ function useCreateLeaveRequest(client, options) {
828
+ return reactQuery.useMutation({
829
+ mutationFn: (input) => client.leaves.createRequest(input),
830
+ ...options
831
+ });
832
+ }
833
+ function useSitSegments(client, params, options) {
834
+ return reactQuery.useQuery({
835
+ queryKey: queryKeys.sitRequests.segments(params),
836
+ queryFn: () => client.sitRequests.getSegments(params),
837
+ ...options
838
+ });
839
+ }
840
+ function useSaveAndPreviewSitRequest(client, options) {
841
+ return reactQuery.useMutation({
842
+ mutationFn: (input) => client.sitRequests.saveAndPreview(input),
843
+ ...options
844
+ });
845
+ }
846
+ function useSubmitSitRequest(client, options) {
847
+ return reactQuery.useMutation({
848
+ mutationFn: (input) => client.sitRequests.submit(input),
849
+ ...options
850
+ });
851
+ }
852
+ function useNotifications(client, options) {
853
+ return reactQuery.useQuery({
854
+ queryKey: queryKeys.notifications.list,
855
+ queryFn: () => client.notifications.getList(),
856
+ ...options
857
+ });
858
+ }
859
+ function useNotificationDetails(client, params, options) {
860
+ return reactQuery.useQuery({
861
+ queryKey: queryKeys.notifications.details(params.notificationId),
862
+ queryFn: () => client.notifications.getDetails(params),
863
+ ...options
864
+ });
865
+ }
866
+ function useProcessApproval(client, options) {
867
+ return reactQuery.useMutation({
868
+ mutationFn: (input) => client.notifications.processApproval(input),
869
+ ...options
870
+ });
871
+ }
872
+ function usePayslipHeader(client, params, options) {
873
+ return reactQuery.useQuery({
874
+ queryKey: queryKeys.payslip.header(params.periodName),
875
+ queryFn: () => client.payslip.getHeader(params),
876
+ ...options
877
+ });
878
+ }
879
+ function usePayslipDetails(client, params, options) {
880
+ return reactQuery.useQuery({
881
+ queryKey: queryKeys.payslip.details(params.periodName),
882
+ queryFn: () => client.payslip.getDetails(params),
883
+ ...options
884
+ });
885
+ }
886
+ function usePersonalInfo(client, options) {
887
+ return reactQuery.useQuery({
888
+ queryKey: queryKeys.employee.personalInfo,
889
+ queryFn: () => client.employee.getPersonalInfo(),
890
+ ...options
891
+ });
892
+ }
893
+ function useEmployeeHierarchy(client, options) {
894
+ return reactQuery.useQuery({
895
+ queryKey: queryKeys.employee.hierarchy,
896
+ queryFn: () => client.employee.getHierarchy(),
897
+ ...options
898
+ });
899
+ }
900
+ function useAccrualBalances(client, params, options) {
901
+ return reactQuery.useQuery({
902
+ queryKey: queryKeys.accrualBalances.get(params.calculationDate),
903
+ queryFn: () => client.accrualBalances.getBalances(params),
904
+ ...options
905
+ });
906
+ }
907
+ function useTableColumns(client, params, options) {
908
+ return reactQuery.useQuery({
909
+ queryKey: queryKeys.forms.tableColumns(params.tableName),
910
+ queryFn: () => client.forms.getTableColumns(params),
911
+ ...options
912
+ });
913
+ }
914
+ function useDffSegments(client, params, options) {
915
+ return reactQuery.useQuery({
916
+ queryKey: queryKeys.forms.dffSegments(params),
917
+ queryFn: () => client.forms.getDffSegments(params),
918
+ ...options
919
+ });
920
+ }
921
+ function useHealthCheck(client, options) {
922
+ return reactQuery.useQuery({
923
+ queryKey: queryKeys.health.check,
924
+ queryFn: () => client.health.check(),
925
+ ...options
926
+ });
927
+ }
621
928
 
622
929
  exports.APIError = APIError;
930
+ exports.ActionType = ActionType;
623
931
  exports.ForbiddenError = ForbiddenError;
932
+ exports.MessageRole = MessageRole;
624
933
  exports.NetworkError = NetworkError;
625
934
  exports.NotFoundError = NotFoundError;
626
935
  exports.OracleEBSClient = OracleEBSClient;
627
936
  exports.ServerError = ServerError;
628
937
  exports.TimeoutError = TimeoutError;
629
938
  exports.UnauthorizedError = UnauthorizedError;
939
+ exports.UserIntent = UserIntent;
630
940
  exports.ValidationError = ValidationError;
941
+ exports.queryKeys = queryKeys;
942
+ exports.useAccrualBalances = useAccrualBalances;
943
+ exports.useCreateLeaveRequest = useCreateLeaveRequest;
944
+ exports.useDffSegments = useDffSegments;
945
+ exports.useEmployeeHierarchy = useEmployeeHierarchy;
946
+ exports.useHealthCheck = useHealthCheck;
947
+ exports.useLeaveHistory = useLeaveHistory;
948
+ exports.useLeaveTypes = useLeaveTypes;
949
+ exports.useLogin = useLogin;
950
+ exports.useNotificationDetails = useNotificationDetails;
951
+ exports.useNotifications = useNotifications;
952
+ exports.usePayslipDetails = usePayslipDetails;
953
+ exports.usePayslipHeader = usePayslipHeader;
954
+ exports.usePersonalInfo = usePersonalInfo;
955
+ exports.useProcessApproval = useProcessApproval;
956
+ exports.useSaveAndPreviewSitRequest = useSaveAndPreviewSitRequest;
957
+ exports.useSitSegments = useSitSegments;
958
+ exports.useSubmitSitRequest = useSubmitSitRequest;
959
+ exports.useTableColumns = useTableColumns;
960
+ exports.useUserContext = useUserContext;
631
961
  //# sourceMappingURL=index.js.map
632
962
  //# sourceMappingURL=index.js.map