@1interface/chat-core 0.20.3 → 0.21.0

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.d.ts CHANGED
@@ -35,7 +35,6 @@ import { QueryDefinition } from '@reduxjs/toolkit/query';
35
35
  import { QueryStatus } from '@reduxjs/toolkit/query';
36
36
  import { QuerySubState } from '@reduxjs/toolkit/query';
37
37
  import { reactHooksModuleName } from '@reduxjs/toolkit/query/react';
38
- import { ReactNode } from 'react';
39
38
  import { Reducer } from '@reduxjs/toolkit';
40
39
  import { RefObject } from 'react';
41
40
  import { RefreshApiResult } from '@1interface/shared-core';
@@ -361,8 +360,6 @@ export declare interface BridgeRequestOptions {
361
360
 
362
361
  export declare function buildBrandSkin(styles: ChatThemeStyles, resolvedTheme: "light" | "dark"): PaymentSkin;
363
362
 
364
- export declare function buildCallbackUrl(givenId?: string | null): string;
365
-
366
363
  export declare const CHAT_INPUT_MODES: {
367
364
  readonly NORMAL: "normal";
368
365
  readonly RECORDING: "recording";
@@ -821,10 +818,21 @@ export declare function createSessionRefresher(store: SessionStoreLike): () => P
821
818
 
822
819
  export declare const DEFAULT_CONVERSATION_TITLE = "New Conversation";
823
820
 
824
- export declare const DEFAULT_PAYMENT_PROVIDER: PaymentProviderType;
825
-
826
821
  export declare const DEFAULT_PROTOCOL: ProtocolType;
827
822
 
823
+ export declare function defaultAgentText({ status, amount, currency, paymentId }: DefaultAgentTextInput): string;
824
+
825
+ export declare interface DefaultAgentTextInput {
826
+ status: PaymentOutcomeStatus;
827
+ amount?: number;
828
+ currency?: string;
829
+ paymentId?: string;
830
+ }
831
+
832
+ export declare function defaultCancelOutcome({ modelText }?: {
833
+ modelText?: string;
834
+ }): PaymentOutcome;
835
+
828
836
  export declare const dequeueMessage: ActionCreatorWithoutPayload<"chat/dequeueMessage">;
829
837
 
830
838
  export declare interface DocumentsConfig {
@@ -876,15 +884,6 @@ export declare function forgotPasswordApi(payload: ForgotPasswordRequest): Promi
876
884
 
877
885
  export declare function formatAmount(minorUnits: number | undefined, currency: string | undefined): string | null;
878
886
 
879
- export declare function formatPaymentResult(result: PaymentResult): FormattedPaymentResult;
880
-
881
- export declare function formatResultMessage(result: PaymentResult): string;
882
-
883
- export declare interface FormattedPaymentResult {
884
- text: string;
885
- modelText?: string;
886
- }
887
-
888
887
  export declare const GENERIC_SERVER_ERROR_MESSAGE = "Something went wrong. Please try again.";
889
888
 
890
889
  export declare function getApiErrorMessage(err: unknown, clientFallback?: string): string;
@@ -901,6 +900,8 @@ export declare function getErrorGroup(error: unknown): string | null;
901
900
 
902
901
  export declare const getLatestRequestId: () => string;
903
902
 
903
+ export declare function getPaymentProvider(type?: string | null): PaymentProviderEntry | undefined;
904
+
904
905
  export declare function guestLoginApi(): Promise<AuthApiResult>;
905
906
 
906
907
  export declare const hasAnyExtraData: (msg: any) => boolean;
@@ -945,13 +946,6 @@ export declare interface MessageArrival {
945
946
 
946
947
  export declare const MODEL_CONTEXT_TEXT_MAX_LENGTH = 1000;
947
948
 
948
- export declare const MOYASAR_CALLBACK_SENTINEL = "moyasar_cb";
949
-
950
- export declare interface MoyasarCallbackResult {
951
- result: PaymentResult;
952
- conversationId: string | null;
953
- }
954
-
955
949
  export declare interface NormalizedEvent {
956
950
  type: NormalizedEventType;
957
951
  data: NormalizedEventData;
@@ -982,6 +976,14 @@ export declare type NormalizedEventData = {
982
976
 
983
977
  export declare type NormalizedEventType = 'text' | 'error' | 'widget' | 'status_update' | 'payment' | 'sign_in' | 'request_documents' | 'conversation_title' | 'stream_end';
984
978
 
979
+ export declare interface NormalizedPayment<Config = unknown> {
980
+ provider: string;
981
+ paymentId: string;
982
+ amount?: number;
983
+ currency?: string;
984
+ config: Config;
985
+ }
986
+
985
987
  export declare const OAUTH_ERROR_TYPE: "OAUTH_ERROR";
986
988
 
987
989
  export declare const OAUTH_SUCCESS_TYPE: "OAUTH_SUCCESS";
@@ -992,21 +994,16 @@ export declare const PAGINATION: {
992
994
  readonly MESSAGE_PAGE_SIZE: 25;
993
995
  };
994
996
 
995
- export declare function parseMoyasarCallbackFromUrl(search: string): MoyasarCallbackResult | null;
996
-
997
- export declare const PAYMENT_FAILURE_CODES: {
998
- readonly SESSION_INVALID: "session_invalid";
999
- readonly LOAD_FAILED: "load_failed";
997
+ export declare const PAYMENT_OUTCOME_STATUSES: {
998
+ readonly SUCCESS: "success";
999
+ readonly FAILURE: "failure";
1000
+ readonly CANCEL: "cancel";
1000
1001
  };
1001
1002
 
1002
1003
  export declare interface PaymentAdapter {
1003
- readonly type: PaymentProviderType;
1004
1004
  readonly label: string;
1005
1005
  readonly hideShellSubmit?: boolean;
1006
1006
  readonly hideShellFooter?: boolean;
1007
- ProviderWrapper?: React.FC<{
1008
- children: ReactNode;
1009
- }>;
1010
1007
  FormComponent: React.FC<PaymentFormProps>;
1011
1008
  }
1012
1009
 
@@ -1016,12 +1013,31 @@ export declare interface PaymentConfirmHandle {
1016
1013
  }
1017
1014
 
1018
1015
  export declare interface PaymentFormProps {
1019
- amount: number;
1020
- currency: string;
1021
1016
  skin: PaymentSkin;
1022
1017
  onReady?: () => void;
1023
1018
  }
1024
1019
 
1020
+ export declare interface PaymentOutcome {
1021
+ status: PaymentOutcomeStatus;
1022
+ agentText: string;
1023
+ modelText?: string;
1024
+ userMessage?: string;
1025
+ }
1026
+
1027
+ export declare type PaymentOutcomeStatus = (typeof PAYMENT_OUTCOME_STATUSES)[keyof typeof PAYMENT_OUTCOME_STATUSES];
1028
+
1029
+ export declare type PaymentProviderEntry<Config = unknown> = PaymentProviderSpec<Config> & {
1030
+ loadAdapter(): Promise<{
1031
+ default: PaymentAdapter;
1032
+ }>;
1033
+ };
1034
+
1035
+ export declare interface PaymentProviderSpec<Config = unknown> {
1036
+ type: PaymentProviderType;
1037
+ normalize(raw: PaymentInitPayload): NormalizedPayment<Config> | null;
1038
+ cancelOutcome?(payment: NormalizedPayment<Config>): PaymentOutcome;
1039
+ }
1040
+
1025
1041
  export declare type PaymentResult = {
1026
1042
  status: "success";
1027
1043
  provider: PaymentProviderType;
@@ -1039,6 +1055,8 @@ export declare type PaymentResult = {
1039
1055
  provider: PaymentProviderType;
1040
1056
  };
1041
1057
 
1058
+ declare type PaymentResultInput = PaymentOutcome | PaymentResult;
1059
+
1042
1060
  export declare interface PaymentSkin {
1043
1061
  pageBg: string;
1044
1062
  cardBg: string;
@@ -1119,6 +1137,8 @@ export declare interface QueuedMessage {
1119
1137
 
1120
1138
  export declare function refreshTokenApi(payload: RefreshRequest): Promise<RefreshApiResult>;
1121
1139
 
1140
+ export declare function registerPaymentProvider<Config>(entry: PaymentProviderEntry<Config>): void;
1141
+
1122
1142
  export declare function resendVerificationApi(payload: ResendVerificationRequest): Promise<string | undefined>;
1123
1143
 
1124
1144
  export declare const resetAllApiState: () => ThunkAction<void, unknown, unknown, UnknownAction>;
@@ -1129,6 +1149,8 @@ export declare const resetChatState: ActionCreatorWithoutPayload<"chat/resetChat
1129
1149
 
1130
1150
  export declare function resetPasswordApi(payload: ResetPasswordRequest): Promise<string | undefined>;
1131
1151
 
1152
+ export declare function resolvePaymentProvider(provider?: unknown): PaymentProviderEntry | undefined;
1153
+
1132
1154
  export declare type RootState = ReturnType<typeof store.getState>;
1133
1155
 
1134
1156
  export declare type SendMessageFn = (inputMsg?: string, transcriptionIds?: string[], options?: SendMessageOptions) => Promise<void>;
@@ -1152,6 +1174,8 @@ export declare interface SessionStoreLike {
1152
1174
 
1153
1175
  export declare const setActiveConversationId: ActionCreatorWithOptionalPayload<string, "conversations/setActiveConversationId">;
1154
1176
 
1177
+ export declare function setDefaultPaymentProvider(type: string): void;
1178
+
1155
1179
  export declare const setIsAgentWorking: ActionCreatorWithOptionalPayload<boolean, "chat/setIsAgentWorking">;
1156
1180
 
1157
1181
  export declare const setResponseStartTime: ActionCreatorWithOptionalPayload<number, "chat/setResponseStartTime">;
@@ -4129,31 +4153,33 @@ declare interface UsePaymentFlowArgs {
4129
4153
 
4130
4154
  declare interface UsePaymentFlowReturn {
4131
4155
  paymentInit: PaymentInitPayload | null;
4156
+ payment: NormalizedPayment | null;
4132
4157
  setPaymentInit: (next: PaymentInitPayload | null) => void;
4133
4158
  clearPaymentInit: () => void;
4134
- handlePaymentResult: (result: PaymentResult) => void;
4159
+ handlePaymentResult: (result: PaymentOutcome | PaymentResult) => void;
4135
4160
  }
4136
4161
 
4137
4162
  export declare interface UsePaymentResult {
4138
4163
  paymentInit: PaymentInitPayload | null;
4164
+ payment: NormalizedPayment | null;
4139
4165
  setPaymentInit: (next: PaymentInitPayload | null) => void;
4140
4166
  isOpen: boolean;
4141
4167
  onOpenChange: (open: boolean) => void;
4142
- onResult: (result: PaymentResult) => void;
4168
+ onResult: (result: PaymentOutcome | PaymentResult) => void;
4143
4169
  clearPaymentInit: () => void;
4144
4170
  }
4145
4171
 
4146
- export declare function usePaymentResultDedup({ paymentInit, onPaymentResult, onClearPaymentInit, }: UsePaymentResultDedupArgs): UsePaymentResultDedupReturn;
4172
+ export declare function usePaymentResultDedup({ payment, onPaymentResult, onClearPaymentInit, }: UsePaymentResultDedupArgs): UsePaymentResultDedupReturn;
4147
4173
 
4148
4174
  declare interface UsePaymentResultDedupArgs {
4149
- paymentInit: PaymentInitPayload | null;
4150
- onPaymentResult?: (result: PaymentResult) => void;
4175
+ payment: NormalizedPayment | null;
4176
+ onPaymentResult?: (result: PaymentResultInput) => void;
4151
4177
  onClearPaymentInit?: () => void;
4152
4178
  }
4153
4179
 
4154
4180
  declare interface UsePaymentResultDedupReturn {
4155
- handlePaymentResult: (result: PaymentResult) => void;
4156
- handleModalOpenChange: (next: boolean) => void;
4181
+ handlePaymentResult: (result: PaymentResultInput) => void;
4182
+ handleSurfaceOpenChange: (next: boolean) => void;
4157
4183
  }
4158
4184
 
4159
4185
  export declare const useProtocol: () => ProtocolContextType;