@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.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
  };
@@ -439,59 +442,42 @@ var NotificationsModule = class extends BaseClient {
439
442
 
440
443
  // src/modules/PayslipModule.ts
441
444
  var PayslipModule = class extends BaseClient {
442
- /**
443
- * Get employee number from stored user context
444
- */
445
- getEmployeeNumberFromContext(providedEmployeeNumber) {
446
- if (providedEmployeeNumber) {
447
- return providedEmployeeNumber;
448
- }
449
- const employeeNumber = this.getEmployeeNumber();
450
- if (!employeeNumber) {
451
- throw new Error("Employee number not available. Please login first.");
452
- }
453
- return employeeNumber;
454
- }
455
445
  /**
456
446
  * Get payslip header
447
+ * Note: employeeNumber is extracted from JWT by backend
457
448
  */
458
449
  async getHeader(params) {
459
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
460
450
  const searchParams = new URLSearchParams();
461
- searchParams.set("employeeNumber", employeeNumber);
462
451
  searchParams.set("periodName", params.periodName);
463
452
  const response = await this.get(`payslip/header?${searchParams}`);
464
453
  return response.data;
465
454
  }
466
455
  /**
467
456
  * Get payslip details
457
+ * Note: employeeNumber is extracted from JWT by backend
468
458
  */
469
459
  async getDetails(params) {
470
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
471
460
  const searchParams = new URLSearchParams();
472
- searchParams.set("employeeNumber", employeeNumber);
473
461
  searchParams.set("periodName", params.periodName);
474
462
  const response = await this.get(`payslip/details?${searchParams}`);
475
463
  return response.data;
476
464
  }
477
465
  /**
478
466
  * Get payslip leave details
467
+ * Note: employeeNumber is extracted from JWT by backend
479
468
  */
480
469
  async getLeaveDetails(params) {
481
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
482
470
  const searchParams = new URLSearchParams();
483
- searchParams.set("employeeNumber", employeeNumber);
484
471
  searchParams.set("periodName", params.periodName);
485
472
  const response = await this.get(`payslip/leave-details?${searchParams}`);
486
473
  return response.data;
487
474
  }
488
475
  /**
489
476
  * Get payslip run balances
477
+ * Note: employeeNumber is extracted from JWT by backend
490
478
  */
491
479
  async getRunBalances(params) {
492
- const employeeNumber = this.getEmployeeNumberFromContext(params.employeeNumber);
493
480
  const searchParams = new URLSearchParams();
494
- searchParams.set("employeeNumber", employeeNumber);
495
481
  searchParams.set("periodName", params.periodName);
496
482
  const response = await this.get(`payslip/run-balances?${searchParams}`);
497
483
  return response.data;
@@ -570,6 +556,140 @@ var HealthModule = class extends BaseClient {
570
556
  }
571
557
  };
572
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
+
680
+ // src/modules/SegmentsModule.ts
681
+ var SegmentsModule = class extends BaseClient {
682
+ /**
683
+ * Get SIT segments
684
+ */
685
+ async getSitSegments(params) {
686
+ const searchParams = new URLSearchParams();
687
+ searchParams.set("idFlexNum", params.idFlexNum);
688
+ const response = await this.get(`segments/sit-segments?${searchParams}`);
689
+ return response.data;
690
+ }
691
+ };
692
+
573
693
  // src/client/OracleEBSClient.ts
574
694
  var OracleEBSClient = class {
575
695
  constructor(config) {
@@ -582,6 +702,8 @@ var OracleEBSClient = class {
582
702
  this.accrualBalances = new AccrualBalancesModule(config);
583
703
  this.forms = new FormsModule(config);
584
704
  this.health = new HealthModule(config);
705
+ this.ai = new AiModule(config);
706
+ this.segments = new SegmentsModule(config);
585
707
  }
586
708
  /**
587
709
  * Set authentication token for all modules
@@ -596,6 +718,8 @@ var OracleEBSClient = class {
596
718
  this.accrualBalances.setToken(token, user);
597
719
  this.forms.setToken(token, user);
598
720
  this.health.setToken(token, user);
721
+ this.ai.setToken(token, user);
722
+ this.segments.setToken(token, user);
599
723
  }
600
724
  /**
601
725
  * Clear authentication token from all modules
@@ -610,9 +734,208 @@ var OracleEBSClient = class {
610
734
  this.accrualBalances.clearToken();
611
735
  this.forms.clearToken();
612
736
  this.health.clearToken();
737
+ this.ai.clearToken();
738
+ this.segments.clearToken();
739
+ }
740
+ };
741
+
742
+ // src/types/ai.ts
743
+ var MessageRole = /* @__PURE__ */ ((MessageRole2) => {
744
+ MessageRole2["USER"] = "user";
745
+ MessageRole2["ASSISTANT"] = "assistant";
746
+ MessageRole2["SYSTEM"] = "system";
747
+ return MessageRole2;
748
+ })(MessageRole || {});
749
+ var ActionType = /* @__PURE__ */ ((ActionType2) => {
750
+ ActionType2["NAVIGATE"] = "navigate";
751
+ ActionType2["API_CALL"] = "api_call";
752
+ ActionType2["DOWNLOAD"] = "download";
753
+ ActionType2["CLOSE_NOTIFICATION"] = "close_notification";
754
+ ActionType2["SUBMIT_LEAVE"] = "submit_leave";
755
+ ActionType2["APPROVE_NOTIFICATION"] = "approve_notification";
756
+ ActionType2["DECLINE_NOTIFICATION"] = "decline_notification";
757
+ return ActionType2;
758
+ })(ActionType || {});
759
+ var UserIntent = /* @__PURE__ */ ((UserIntent2) => {
760
+ UserIntent2["NOTIFICATIONS_SUMMARY"] = "notifications_summary";
761
+ UserIntent2["NOTIFICATION_CLOSE"] = "notification_close";
762
+ UserIntent2["NOTIFICATION_ACTION"] = "notification_action";
763
+ UserIntent2["PAYSLIP_QUERY"] = "payslip_query";
764
+ UserIntent2["PAYSLIP_RETRIEVAL"] = "payslip_retrieval";
765
+ UserIntent2["SALARY_DEDUCTION"] = "salary_deduction";
766
+ UserIntent2["LEAVE_BALANCE"] = "leave_balance";
767
+ UserIntent2["LEAVE_REQUEST"] = "leave_request";
768
+ UserIntent2["PROFILE_INFO"] = "profile_info";
769
+ UserIntent2["HIRING_DATE"] = "hiring_date";
770
+ UserIntent2["POSITION_INFO"] = "position_info";
771
+ UserIntent2["GENERAL_QUERY"] = "general_query";
772
+ UserIntent2["OUT_OF_SCOPE"] = "out_of_scope";
773
+ return UserIntent2;
774
+ })(UserIntent || {});
775
+ var queryKeys = {
776
+ auth: {
777
+ userContext: ["auth", "user-context"]
778
+ },
779
+ leaves: {
780
+ restrictedTypes: (params) => ["leaves", "restricted-types", params],
781
+ history: ["leaves", "history"]
782
+ },
783
+ sitRequests: {
784
+ segments: (params) => ["sit-requests", "segments", params],
785
+ history: ["sit-requests", "history"]
786
+ },
787
+ notifications: {
788
+ list: ["notifications", "list"],
789
+ details: (notificationId) => ["notifications", "details", notificationId]
790
+ },
791
+ payslip: {
792
+ header: (periodName) => ["payslip", "header", periodName],
793
+ details: (periodName) => ["payslip", "details", periodName]
794
+ },
795
+ employee: {
796
+ personalInfo: ["employee", "personal-info"],
797
+ hierarchy: ["employee", "hierarchy"]
798
+ },
799
+ accrualBalances: {
800
+ get: (calculationDate) => ["accrual-balances", calculationDate]
801
+ },
802
+ forms: {
803
+ tableColumns: (tableName) => ["forms", "table-columns", tableName],
804
+ dffSegments: (params) => ["forms", "dff-segments", params]
805
+ },
806
+ health: {
807
+ check: ["health", "check"]
613
808
  }
614
809
  };
810
+ function useLogin(client, options) {
811
+ return useMutation({
812
+ mutationFn: (credentials) => client.auth.login(credentials),
813
+ ...options
814
+ });
815
+ }
816
+ function useUserContext(client, options) {
817
+ return useQuery({
818
+ queryKey: queryKeys.auth.userContext,
819
+ queryFn: () => client.auth.getUserContext(),
820
+ ...options
821
+ });
822
+ }
823
+ function useLeaveTypes(client, params, options) {
824
+ return useQuery({
825
+ queryKey: queryKeys.leaves.restrictedTypes(params),
826
+ queryFn: () => client.leaves.getRestrictedTypes(params),
827
+ ...options
828
+ });
829
+ }
830
+ function useLeaveHistory(client, options) {
831
+ return useQuery({
832
+ queryKey: queryKeys.leaves.history,
833
+ queryFn: () => client.leaves.getHistory(),
834
+ ...options
835
+ });
836
+ }
837
+ function useCreateLeaveRequest(client, options) {
838
+ return useMutation({
839
+ mutationFn: (input) => client.leaves.createRequest(input),
840
+ ...options
841
+ });
842
+ }
843
+ function useSitSegments(client, params, options) {
844
+ return useQuery({
845
+ queryKey: queryKeys.sitRequests.segments(params),
846
+ queryFn: () => client.sitRequests.getSegments(params),
847
+ ...options
848
+ });
849
+ }
850
+ function useSaveAndPreviewSitRequest(client, options) {
851
+ return useMutation({
852
+ mutationFn: (input) => client.sitRequests.saveAndPreview(input),
853
+ ...options
854
+ });
855
+ }
856
+ function useSubmitSitRequest(client, options) {
857
+ return useMutation({
858
+ mutationFn: (input) => client.sitRequests.submit(input),
859
+ ...options
860
+ });
861
+ }
862
+ function useNotifications(client, options) {
863
+ return useQuery({
864
+ queryKey: queryKeys.notifications.list,
865
+ queryFn: () => client.notifications.getList(),
866
+ ...options
867
+ });
868
+ }
869
+ function useNotificationDetails(client, params, options) {
870
+ return useQuery({
871
+ queryKey: queryKeys.notifications.details(params.notificationId),
872
+ queryFn: () => client.notifications.getDetails(params),
873
+ ...options
874
+ });
875
+ }
876
+ function useProcessApproval(client, options) {
877
+ return useMutation({
878
+ mutationFn: (input) => client.notifications.processApproval(input),
879
+ ...options
880
+ });
881
+ }
882
+ function usePayslipHeader(client, params, options) {
883
+ return useQuery({
884
+ queryKey: queryKeys.payslip.header(params.periodName),
885
+ queryFn: () => client.payslip.getHeader(params),
886
+ ...options
887
+ });
888
+ }
889
+ function usePayslipDetails(client, params, options) {
890
+ return useQuery({
891
+ queryKey: queryKeys.payslip.details(params.periodName),
892
+ queryFn: () => client.payslip.getDetails(params),
893
+ ...options
894
+ });
895
+ }
896
+ function usePersonalInfo(client, options) {
897
+ return useQuery({
898
+ queryKey: queryKeys.employee.personalInfo,
899
+ queryFn: () => client.employee.getPersonalInfo(),
900
+ ...options
901
+ });
902
+ }
903
+ function useEmployeeHierarchy(client, options) {
904
+ return useQuery({
905
+ queryKey: queryKeys.employee.hierarchy,
906
+ queryFn: () => client.employee.getHierarchy(),
907
+ ...options
908
+ });
909
+ }
910
+ function useAccrualBalances(client, params, options) {
911
+ return useQuery({
912
+ queryKey: queryKeys.accrualBalances.get(params.calculationDate),
913
+ queryFn: () => client.accrualBalances.getBalances(params),
914
+ ...options
915
+ });
916
+ }
917
+ function useTableColumns(client, params, options) {
918
+ return useQuery({
919
+ queryKey: queryKeys.forms.tableColumns(params.tableName),
920
+ queryFn: () => client.forms.getTableColumns(params),
921
+ ...options
922
+ });
923
+ }
924
+ function useDffSegments(client, params, options) {
925
+ return useQuery({
926
+ queryKey: queryKeys.forms.dffSegments(params),
927
+ queryFn: () => client.forms.getDffSegments(params),
928
+ ...options
929
+ });
930
+ }
931
+ function useHealthCheck(client, options) {
932
+ return useQuery({
933
+ queryKey: queryKeys.health.check,
934
+ queryFn: () => client.health.check(),
935
+ ...options
936
+ });
937
+ }
615
938
 
616
- export { APIError, ForbiddenError, NetworkError, NotFoundError, OracleEBSClient, ServerError, TimeoutError, UnauthorizedError, ValidationError };
939
+ 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 };
617
940
  //# sourceMappingURL=index.mjs.map
618
941
  //# sourceMappingURL=index.mjs.map