@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.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,127 @@ 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
+
573
680
  // src/client/OracleEBSClient.ts
574
681
  var OracleEBSClient = class {
575
682
  constructor(config) {
@@ -582,6 +689,7 @@ var OracleEBSClient = class {
582
689
  this.accrualBalances = new AccrualBalancesModule(config);
583
690
  this.forms = new FormsModule(config);
584
691
  this.health = new HealthModule(config);
692
+ this.ai = new AiModule(config);
585
693
  }
586
694
  /**
587
695
  * Set authentication token for all modules
@@ -596,6 +704,7 @@ var OracleEBSClient = class {
596
704
  this.accrualBalances.setToken(token, user);
597
705
  this.forms.setToken(token, user);
598
706
  this.health.setToken(token, user);
707
+ this.ai.setToken(token, user);
599
708
  }
600
709
  /**
601
710
  * Clear authentication token from all modules
@@ -610,9 +719,207 @@ var OracleEBSClient = class {
610
719
  this.accrualBalances.clearToken();
611
720
  this.forms.clearToken();
612
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"]
613
792
  }
614
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
+ }
615
922
 
616
- 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 };
617
924
  //# sourceMappingURL=index.mjs.map
618
925
  //# sourceMappingURL=index.mjs.map