@capitalos/react 1.1.0-rc.1 → 1.2.1-rc.1

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.
@@ -1,3 +1,4 @@
1
+ import { Connection } from 'penpal';
1
2
  import { IFrameComponent } from 'iframe-resizer';
2
3
  import { IFrameMessageData } from 'iframe-resizer';
3
4
  import { IFrameOptions } from 'iframe-resizer';
@@ -5,6 +6,7 @@ import { IFrameResizedData } from 'iframe-resizer';
5
6
  import { IFrameScrollData } from 'iframe-resizer';
6
7
  import { default as React_2 } from 'react';
7
8
  import { ReactNode } from 'react';
9
+ import { RefObject } from 'react';
8
10
  import { z } from 'zod';
9
11
  import * as z_2 from 'zod';
10
12
 
@@ -30,6 +32,34 @@ export declare type AccountStatus = z_2.infer<typeof accountStatusSchema>;
30
32
 
31
33
  declare const accountStatusSchema: z_2.ZodEnum<["eligible", "ineligible", "engaged", "onboarding", "approved", "processing", "pending", "declined", "closed", "waiting"]>;
32
34
 
35
+ export declare type ActionResult<T = void> = {
36
+ success: true;
37
+ canceled: false;
38
+ data: T;
39
+ } | {
40
+ success: false;
41
+ canceled: true;
42
+ } | {
43
+ success: false;
44
+ canceled: false;
45
+ error: CapitalOSError;
46
+ };
47
+
48
+ export declare const ActionsIframeContext: React_2.Context<ActionsIframeContextValue | null>;
49
+
50
+ declare interface ActionsIframeContextValue {
51
+ childFunctions: ChildFunctions | null;
52
+ actions: {
53
+ freezeCard: (cardId: string) => Promise<ActionResult<Card>>;
54
+ unfreezeCard: (cardId: string) => Promise<ActionResult<Card>>;
55
+ } | null;
56
+ isLoading: boolean;
57
+ }
58
+
59
+ export declare function ActionsIframeProvider({ children }: {
60
+ children: React_2.ReactNode;
61
+ }): JSX.Element;
62
+
33
63
  declare type AllowedExitPoints = {
34
64
  welcome: 'application' | 'activation';
35
65
  application: 'application' | 'activation';
@@ -71,6 +101,10 @@ declare type CapitalOsAuthenticationContextType = {
71
101
  * The authentication flow will automatically refresh the token after invalidation.
72
102
  */
73
103
  invalidateToken: () => void;
104
+ /**
105
+ * Optional flag indicating whether to log events to the console.
106
+ */
107
+ enableLogging: boolean;
74
108
  };
75
109
 
76
110
  declare const CapitalOsAuthenticationProvider: React_2.FC<ProviderProps>;
@@ -90,7 +124,7 @@ export declare class CapitalOSError extends Error {
90
124
 
91
125
  declare type CapitalOsProps<T extends CapitalOsRenderingContext> = CommonProps & {
92
126
  renderingContext: T;
93
- methods?: Partial<IframeConnectionMethods>;
127
+ methods?: Partial<ParentFunctions>;
94
128
  sizeWidth?: boolean;
95
129
  };
96
130
 
@@ -99,6 +133,10 @@ export declare type CapitalOsRenderingContext = {
99
133
  referer?: string;
100
134
  };
101
135
 
136
+ export declare type Card = {
137
+ status: 'active' | 'inactive' | 'canceled' | 'frozen';
138
+ };
139
+
102
140
  export declare type CardApiDto = z_2.infer<typeof cardApiDtoSchema>;
103
141
 
104
142
  declare const cardApiDtoSchema: z_2.ZodObject<{
@@ -187,7 +225,7 @@ declare const cardApiDtoSchema: z_2.ZodObject<{
187
225
  limit?: number | undefined;
188
226
  };
189
227
  }>;
190
- allowedSpendCategories: z_2.ZodArray<z_2.ZodEnum<["airlines", "carRental", "carService", "education", "electronics", "gasPump", "gasStation", "generalMerchandise", "government", "hardwareAndConstruction", "insurance", "legal", "lodging", "medical", "other", "parking", "phoneAndInternet", "professionalServices", "recreationAndEntertainment", "restaurants", "shipping", "software", "taxisAndRideshare", "transportation", "travelMisc", "utilities"]>, "many">;
228
+ allowedSpendCategories: z_2.ZodArray<z_2.ZodEnum<["advertisingAndMarketing", "airlines", "carRental", "carService", "education", "electronics", "gasPump", "gasStation", "generalMerchandise", "government", "hardwareAndConstruction", "insurance", "legal", "lodging", "medical", "other", "parking", "phoneAndInternet", "professionalServices", "recreationAndEntertainment", "restaurants", "shipping", "software", "taxisAndRideshare", "transportation", "travelMisc", "utilities"]>, "many">;
191
229
  allowedMerchants: z_2.ZodArray<z_2.ZodObject<{
192
230
  id: z_2.ZodUnion<[z_2.ZodString, z_2.ZodString]>;
193
231
  name: z_2.ZodString;
@@ -206,7 +244,7 @@ declare const cardApiDtoSchema: z_2.ZodObject<{
206
244
  shipment: z_2.ZodObject<{
207
245
  address: z_2.ZodObject<{
208
246
  addressLine1: z_2.ZodString;
209
- addressLine2: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
247
+ addressLine2: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodEffects<z_2.ZodNullable<z_2.ZodString>, string | null, string | null>>>;
210
248
  city: z_2.ZodString;
211
249
  state: z_2.ZodEffects<z_2.ZodString, string, string>;
212
250
  zipcode: z_2.ZodString;
@@ -330,7 +368,7 @@ declare const cardApiDtoSchema: z_2.ZodObject<{
330
368
  limit?: number | undefined;
331
369
  };
332
370
  };
333
- allowedSpendCategories: ("airlines" | "carRental" | "carService" | "education" | "electronics" | "gasPump" | "gasStation" | "generalMerchandise" | "government" | "hardwareAndConstruction" | "insurance" | "legal" | "lodging" | "medical" | "other" | "parking" | "phoneAndInternet" | "professionalServices" | "recreationAndEntertainment" | "restaurants" | "shipping" | "software" | "taxisAndRideshare" | "transportation" | "travelMisc" | "utilities")[];
371
+ allowedSpendCategories: ("advertisingAndMarketing" | "airlines" | "carRental" | "carService" | "education" | "electronics" | "gasPump" | "gasStation" | "generalMerchandise" | "government" | "hardwareAndConstruction" | "insurance" | "legal" | "lodging" | "medical" | "other" | "parking" | "phoneAndInternet" | "professionalServices" | "recreationAndEntertainment" | "restaurants" | "shipping" | "software" | "taxisAndRideshare" | "transportation" | "travelMisc" | "utilities")[];
334
372
  allowedMerchants: {
335
373
  id: string;
336
374
  name: string;
@@ -385,7 +423,7 @@ declare const cardApiDtoSchema: z_2.ZodObject<{
385
423
  limit?: number | undefined;
386
424
  };
387
425
  };
388
- allowedSpendCategories: ("airlines" | "carRental" | "carService" | "education" | "electronics" | "gasPump" | "gasStation" | "generalMerchandise" | "government" | "hardwareAndConstruction" | "insurance" | "legal" | "lodging" | "medical" | "other" | "parking" | "phoneAndInternet" | "professionalServices" | "recreationAndEntertainment" | "restaurants" | "shipping" | "software" | "taxisAndRideshare" | "transportation" | "travelMisc" | "utilities")[];
426
+ allowedSpendCategories: ("advertisingAndMarketing" | "airlines" | "carRental" | "carService" | "education" | "electronics" | "gasPump" | "gasStation" | "generalMerchandise" | "government" | "hardwareAndConstruction" | "insurance" | "legal" | "lodging" | "medical" | "other" | "parking" | "phoneAndInternet" | "professionalServices" | "recreationAndEntertainment" | "restaurants" | "shipping" | "software" | "taxisAndRideshare" | "transportation" | "travelMisc" | "utilities")[];
389
427
  allowedMerchants: {
390
428
  id: string;
391
429
  name: string;
@@ -435,6 +473,24 @@ export declare type CardDetailsProps = CommonProps & {
435
473
  */
436
474
  export declare function CardsApp(props: CommonProps): JSX.Element;
437
475
 
476
+ export declare type ChildFunctions = {
477
+ freezeCard: (cardId: string) => Promise<ClientActionResult<Card>>;
478
+ unfreezeCard: (cardId: string) => Promise<ClientActionResult<Card>>;
479
+ };
480
+
481
+ export declare type ClientActionResult<T> = {
482
+ success: true;
483
+ canceled: false;
484
+ data: T;
485
+ } | {
486
+ success: false;
487
+ canceled: true;
488
+ } | {
489
+ success: false;
490
+ canceled: false;
491
+ error: string;
492
+ };
493
+
438
494
  export declare type CommonProps = {
439
495
  /**
440
496
  * The token provided by initiate-login.
@@ -462,6 +518,13 @@ export declare type CommonProps = {
462
518
  theme?: ThemeColorScheme;
463
519
  };
464
520
 
521
+ export declare function ContactSupport({ onDone, onCancel, ...restOfProps }: ContactSupportProps): JSX.Element;
522
+
523
+ export declare type ContactSupportProps = CommonProps & {
524
+ onDone: () => void;
525
+ onCancel: () => void;
526
+ };
527
+
465
528
  export declare function decodeOneTimeToken(token: string): any;
466
529
 
467
530
  /**
@@ -517,40 +580,6 @@ export declare const ErrorCode: {
517
580
 
518
581
  export declare type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
519
582
 
520
- export declare type IframeConnectionMethods = {
521
- onLoad: () => void;
522
- onError: (error: RawErrorDetails) => void;
523
- /**
524
- * Called when the iframe detects that the JWT token has expired.
525
- * This triggers the token refresh flow, which will obtain a new token
526
- * and reload the iframe with the fresh token.
527
- */
528
- onTokenExpired?: () => void;
529
- createCard?: {
530
- onDone?: () => void;
531
- onCancel?: () => void;
532
- };
533
- createDispute?: {
534
- onDone?: () => void;
535
- onCancel?: () => void;
536
- };
537
- onboarding?: {
538
- onDone?: (account: Account) => void;
539
- };
540
- tokenExchange?: {
541
- onLongLivedToken?: (jwtToken: string) => void;
542
- };
543
- makePayment?: {
544
- onDone?: () => void;
545
- };
546
- devTools?: {
547
- onClose?: () => void;
548
- };
549
- cardDetails?: {
550
- onCardCanceled?: () => void;
551
- };
552
- };
553
-
554
583
  export declare const IframeResizer: React_2.ForwardRefExoticComponent<Omit<IFrameOptions, "closedCallback" | "scrollCallback" | "resizedCallback" | "messageCallback" | "initCallback"> & {
555
584
  onClosed?(iframeId: string): void;
556
585
  onInit?(iframe: IFrameComponent): void;
@@ -648,6 +677,22 @@ export declare type IssueCardProps = CommonProps & {
648
677
  onCancel: () => void;
649
678
  };
650
679
 
680
+ export declare function LegalDocuments({ onDone, ...restOfProps }: LegalDocumentsProps): JSX.Element;
681
+
682
+ export declare type LegalDocumentsProps = CommonProps & {
683
+ onDone: () => void;
684
+ };
685
+
686
+ export declare const logger: {
687
+ log: (message: string, options?: LoggerOptions) => void;
688
+ warn: (message: string, options?: LoggerOptions) => void;
689
+ error: (message: string, options?: LoggerOptions) => void;
690
+ };
691
+
692
+ declare type LoggerOptions = {
693
+ enableLogging: boolean | undefined;
694
+ };
695
+
651
696
  /**
652
697
  * Renders the CapitalOS Make a Payment experience.
653
698
  */
@@ -660,6 +705,81 @@ export declare type MakePaymentProps = CommonProps & {
660
705
  onDone: () => void;
661
706
  };
662
707
 
708
+ export declare function Mfa({ onDone, onCancel, mfaId, destination, codeLength, canResendAfter, operationName, ...restOfProps }: MfaProps): JSX.Element;
709
+
710
+ export declare type MfaActionResult = ActionResult<void>;
711
+
712
+ export declare type MfaProps = CommonProps & {
713
+ /**
714
+ * The ID of the MFA request.
715
+ */
716
+ mfaId: string;
717
+ /**
718
+ * The destination of the MFA request.
719
+ */
720
+ destination: string;
721
+ /**
722
+ * The length of the code to be entered.
723
+ */
724
+ codeLength: number;
725
+ /**
726
+ * ISO string representation of DateTime in UTC
727
+ */
728
+ canResendAfter: string;
729
+ /**
730
+ * The name of the operation that is being performed.
731
+ */
732
+ operationName?: string;
733
+ /**
734
+ * Callback to invoke when the MFA was successfully completed.
735
+ */
736
+ onDone: () => void;
737
+ /**
738
+ * Callback to invoke when the MFA was cancelled by the user.
739
+ */
740
+ onCancel: () => void;
741
+ };
742
+
743
+ export declare interface MfaRequestContext {
744
+ mfaId: string;
745
+ destination: string;
746
+ codeLength: number;
747
+ canResendAfter: string;
748
+ operationName?: string;
749
+ }
750
+
751
+ export declare interface MfaResult {
752
+ success: boolean;
753
+ canceled?: boolean;
754
+ error?: string;
755
+ }
756
+
757
+ declare interface MfaState {
758
+ context: MfaRequestContext;
759
+ resolve: (result: MfaActionResult) => void;
760
+ reject: (error: Error) => void;
761
+ }
762
+
763
+ /**
764
+ * Generic modal component that displays content with backdrop/blur
765
+ */
766
+ export declare function Modal({ onClose, children, ariaLabel }: ModalProps): JSX.Element;
767
+
768
+ export declare interface ModalProps {
769
+ /**
770
+ * Callback when modal should be closed (backdrop click)
771
+ */
772
+ onClose: () => void;
773
+ /**
774
+ * Content to render inside the modal
775
+ */
776
+ children: ReactNode;
777
+ /**
778
+ * Accessible label for screen readers
779
+ */
780
+ ariaLabel?: string;
781
+ }
782
+
663
783
  export declare function Onboarding<T extends OnboardingEntryPoint>({ onDone, entryPoint: onboardingEntryPoint, exitPoint: onboardingExitPoint, ...restOfProps }: OnboardingProps<T>): JSX.Element;
664
784
 
665
785
  declare type OnboardingEntryPoint = keyof AllowedExitPoints;
@@ -670,6 +790,65 @@ declare type OnboardingProps<T extends keyof AllowedExitPoints> = CommonProps &
670
790
  onDone: (account: Account) => void;
671
791
  };
672
792
 
793
+ export declare type ParentFunctions = {
794
+ onLoad: () => void;
795
+ onError: (error: RawErrorDetails) => void;
796
+ /**
797
+ * Called when the iframe detects that the JWT token has expired.
798
+ * This triggers the token refresh flow, which will obtain a new token
799
+ * and reload the iframe with the fresh token.
800
+ */
801
+ onTokenExpired?: () => void;
802
+ cardDetails?: {
803
+ onCardCanceled?: () => void;
804
+ };
805
+ contactSupport?: {
806
+ onDone?: () => void;
807
+ onCancel?: () => void;
808
+ };
809
+ createCard?: {
810
+ onDone?: () => void;
811
+ onCancel?: () => void;
812
+ };
813
+ createDispute?: {
814
+ onDone?: () => void;
815
+ onCancel?: () => void;
816
+ };
817
+ devTools?: {
818
+ onClose?: () => void;
819
+ };
820
+ legalDocuments?: {
821
+ onDone?: () => void;
822
+ };
823
+ makePayment?: {
824
+ onDone?: () => void;
825
+ };
826
+ mfa?: {
827
+ onDone?: () => void;
828
+ onCancel?: () => void;
829
+ };
830
+ onboarding?: {
831
+ onDone?: (account: Account) => void;
832
+ };
833
+ replaceCard?: {
834
+ onDone?: () => void;
835
+ onClose?: () => void;
836
+ };
837
+ 'system-messages'?: {
838
+ requestMfa?: (context: MfaRequestContext) => Promise<MfaResult>;
839
+ };
840
+ statements?: {
841
+ onDone?: () => void;
842
+ };
843
+ terminateCard?: {
844
+ onDone?: () => void;
845
+ onClose?: () => void;
846
+ };
847
+ tokenExchange?: {
848
+ onLongLivedToken?: (jwtToken: string) => void;
849
+ };
850
+ };
851
+
673
852
  declare type ProviderProps = {
674
853
  getToken: () => Promise<string>;
675
854
  enableLogging?: boolean | undefined;
@@ -828,6 +1007,69 @@ declare const renderingContextSchema: z.ZodIntersection<z.ZodDiscriminatedUnion<
828
1007
  entryPoint: "devTools";
829
1008
  }, {
830
1009
  entryPoint: "devTools";
1010
+ }>, z.ZodObject<{
1011
+ entryPoint: z.ZodLiteral<"contactSupport">;
1012
+ }, "strip", z.ZodTypeAny, {
1013
+ entryPoint: "contactSupport";
1014
+ }, {
1015
+ entryPoint: "contactSupport";
1016
+ }>, z.ZodObject<{
1017
+ entryPoint: z.ZodLiteral<"statements">;
1018
+ }, "strip", z.ZodTypeAny, {
1019
+ entryPoint: "statements";
1020
+ }, {
1021
+ entryPoint: "statements";
1022
+ }>, z.ZodObject<{
1023
+ entryPoint: z.ZodLiteral<"legalDocuments">;
1024
+ }, "strip", z.ZodTypeAny, {
1025
+ entryPoint: "legalDocuments";
1026
+ }, {
1027
+ entryPoint: "legalDocuments";
1028
+ }>, z.ZodObject<{
1029
+ entryPoint: z.ZodLiteral<"replaceCard">;
1030
+ cardId: z.ZodString;
1031
+ }, "strip", z.ZodTypeAny, {
1032
+ cardId: string;
1033
+ entryPoint: "replaceCard";
1034
+ }, {
1035
+ cardId: string;
1036
+ entryPoint: "replaceCard";
1037
+ }>, z.ZodObject<{
1038
+ entryPoint: z.ZodLiteral<"terminateCard">;
1039
+ cardId: z.ZodString;
1040
+ }, "strip", z.ZodTypeAny, {
1041
+ cardId: string;
1042
+ entryPoint: "terminateCard";
1043
+ }, {
1044
+ cardId: string;
1045
+ entryPoint: "terminateCard";
1046
+ }>, z.ZodObject<{
1047
+ entryPoint: z.ZodLiteral<"actions">;
1048
+ }, "strip", z.ZodTypeAny, {
1049
+ entryPoint: "actions";
1050
+ }, {
1051
+ entryPoint: "actions";
1052
+ }>, z.ZodObject<{
1053
+ entryPoint: z.ZodLiteral<"mfa">;
1054
+ mfaId: z.ZodString;
1055
+ destination: z.ZodString;
1056
+ codeLength: z.ZodNumber;
1057
+ canResendAfter: z.ZodString;
1058
+ operationName: z.ZodOptional<z.ZodString>;
1059
+ }, "strip", z.ZodTypeAny, {
1060
+ entryPoint: "mfa";
1061
+ mfaId: string;
1062
+ destination: string;
1063
+ codeLength: number;
1064
+ canResendAfter: string;
1065
+ operationName?: string | undefined;
1066
+ }, {
1067
+ entryPoint: "mfa";
1068
+ mfaId: string;
1069
+ destination: string;
1070
+ codeLength: number;
1071
+ canResendAfter: string;
1072
+ operationName?: string | undefined;
831
1073
  }>]>, z.ZodObject<{
832
1074
  referer: z.ZodOptional<z.ZodNullable<z.ZodString>>;
833
1075
  }, "strip", z.ZodTypeAny, {
@@ -836,11 +1078,33 @@ declare const renderingContextSchema: z.ZodIntersection<z.ZodDiscriminatedUnion<
836
1078
  referer?: string | null | undefined;
837
1079
  }>>;
838
1080
 
1081
+ export declare function ReplaceCard({ cardId, onDone, onClose, ...restOfProps }: ReplaceCardProps): JSX.Element;
1082
+
1083
+ export declare type ReplaceCardProps = CommonProps & {
1084
+ cardId: string;
1085
+ onDone: () => void;
1086
+ onClose: () => void;
1087
+ };
1088
+
839
1089
  /**
840
1090
  * Safely decodes a URL component, handling potential errors
841
1091
  */
842
1092
  export declare function safeDecodeURIComponent(str: string): string;
843
1093
 
1094
+ export declare function Statements({ onDone, ...restOfProps }: StatementsProps): JSX.Element;
1095
+
1096
+ export declare type StatementsProps = CommonProps & {
1097
+ onDone: () => void;
1098
+ };
1099
+
1100
+ export declare function TerminateCard({ cardId, onDone, onClose, ...restOfProps }: TerminateCardProps): JSX.Element;
1101
+
1102
+ export declare type TerminateCardProps = CommonProps & {
1103
+ cardId: string;
1104
+ onDone: () => void;
1105
+ onClose: () => void;
1106
+ };
1107
+
844
1108
  export declare type ThemeColorScheme = 'light' | 'dark' | 'system';
845
1109
 
846
1110
  export declare type TokenData = {
@@ -892,8 +1156,61 @@ export declare enum TokenType {
892
1156
  longLived = "longLived"
893
1157
  }
894
1158
 
1159
+ /**
1160
+ * Hook to access the actions iframe functions.
1161
+ *
1162
+ * @returns An object containing the actions functions and loading state
1163
+ * @throws {CapitalOSError} If the hook is used outside of a CapitalOS component
1164
+ *
1165
+ * @example
1166
+ * ```tsx
1167
+ * const { actions, isLoading } = useActions()
1168
+ *
1169
+ * if (isLoading) {
1170
+ * return <LoadingSpinner />
1171
+ * }
1172
+ *
1173
+ * // Use the actions
1174
+ * await actions.freezeCard()
1175
+ * ```
1176
+ */
1177
+ export declare function useActions(): {
1178
+ actions: ChildFunctions | null;
1179
+ isLoading: boolean;
1180
+ };
1181
+
895
1182
  export declare const useCapitalOsAuthContext: () => CapitalOsAuthenticationContextType;
896
1183
 
1184
+ /**
1185
+ * Hook to resolve logging preference, with direct prop taking precedence over context.
1186
+ * @param enableLoggingProp Direct prop for enableLogging.
1187
+ * @returns Effective logging flag.
1188
+ */
1189
+ export declare function useEnableLogging(enableLoggingProp?: boolean): boolean;
1190
+
1191
+ /**
1192
+ * A React hook that manages the iframe connection lifecycle, including:
1193
+ * - Establishing and maintaining the iframe connection
1194
+ * - Handling token expiration and refresh flows
1195
+ * - Managing loading states
1196
+ * - Coordinating between one-time tokens and context-based authentication
1197
+ * - Providing error handling and logging capabilities
1198
+ */
1199
+ export declare function useIframe(props: {
1200
+ renderingContext: CapitalOsRenderingContext;
1201
+ oneTimeToken?: string | undefined;
1202
+ enableLogging?: boolean | undefined;
1203
+ onError?: ((error: Error) => void) | undefined;
1204
+ theme?: ThemeColorScheme | undefined;
1205
+ methods?: Partial<Omit<ParentFunctions, 'onLoad' | 'onError' | 'onTokenExpired'>> | undefined;
1206
+ }): {
1207
+ isLoaded: boolean;
1208
+ url: string | undefined;
1209
+ tokenData: TokenData | undefined;
1210
+ iframeRef: RefObject<HTMLIFrameElement>;
1211
+ connection: Connection<ChildFunctions> | null;
1212
+ };
1213
+
897
1214
  /**
898
1215
  * connects to child iframe and returns whether the iframe is loaded or not.
899
1216
  * token was added to the list of dependencies to make sure that the connection is re-established when the token changes.
@@ -902,9 +1219,12 @@ export declare function useIframeConnection({ iframeRef, token, onError, methods
902
1219
  iframeRef: React.RefObject<HTMLIFrameElement>;
903
1220
  token: string | undefined;
904
1221
  onError: ((error: Error) => void) | undefined | null;
905
- methods: IframeConnectionMethods;
906
- }): void;
1222
+ methods: ParentFunctions;
1223
+ }): Connection<ChildFunctions> | null;
907
1224
 
1225
+ /**
1226
+ * returns a memoized url of the iframe or undefined if the token is not available yet.
1227
+ */
908
1228
  export declare function useIframeUrl({ tokenData, renderingContext, theme, onError, }: {
909
1229
  tokenData: TokenData | undefined;
910
1230
  renderingContext: CapitalOsRenderingContext;
@@ -912,4 +1232,24 @@ export declare function useIframeUrl({ tokenData, renderingContext, theme, onErr
912
1232
  onError?: ((error: Error) => void) | undefined;
913
1233
  }): string | undefined;
914
1234
 
1235
+ /**
1236
+ * Hook that provides stable logging functions (log, warn, error), scoped to the resolved enableLogging flag.
1237
+ * @param enableLoggingProp Optional direct prop to override logging.
1238
+ */
1239
+ export declare function useLogger(enableLoggingProp?: boolean): {
1240
+ log: (message: string) => void;
1241
+ warn: (message: string) => void;
1242
+ error: (message: string) => void;
1243
+ };
1244
+
1245
+ export declare function useMfaState(): {
1246
+ activeMfaRequest: MfaState | null;
1247
+ isMfaActive: boolean;
1248
+ mfaContext: MfaRequestContext | null;
1249
+ requestMfa: (context: MfaRequestContext) => Promise<MfaActionResult>;
1250
+ handleMfaDone: () => void;
1251
+ handleMfaCancel: () => void;
1252
+ handleMfaError: (error: CapitalOSError) => void;
1253
+ };
1254
+
915
1255
  export { }
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use client";var ie=Object.defineProperty,se=Object.defineProperties;var ae=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var V=(e,t,o)=>t in e?ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,a=(e,t)=>{for(var o in t||(t={}))J.call(t,o)&&V(e,o,t[o]);if(R)for(var o of R(t))$.call(t,o)&&V(e,o,t[o]);return e},c=(e,t)=>se(e,ae(t));var b=(e,t)=>{var o={};for(var n in e)J.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(e!=null&&R)for(var n of R(e))t.indexOf(n)<0&&$.call(e,n)&&(o[n]=e[n]);return o};var q=(e,t,o)=>new Promise((n,r)=>{var i=p=>{try{d(o.next(p))}catch(f){r(f)}},s=p=>{try{d(o.throw(p))}catch(f){r(f)}},d=p=>p.done?n(p.value):Promise.resolve(p.value).then(i,s);d((o=o.apply(e,t)).next())});import l,{useMemo as u}from"react";import L,{useEffect as te,useMemo as Fe,useRef as oe,useState as Re,useCallback as He}from"react";import _,{createContext as we,useContext as Me,useState as D,useMemo as Ae,useCallback as j,useEffect as Se}from"react";import Oe,{useMemo as De,useRef as Le}from"react";var g=class extends Error{constructor({message:t,code:o}){super(t),this.name="CapitalOSError",this.code=o}},E={unauthorized:"unauthorized",invalid_account_status:"invalid_account_status",unsupported_entry_point:"unsupported_entry_point",internal_error:"internal_error"},v=class extends g{constructor(t){super({message:`Invalid token ${t!=null?t:""}`,code:E.unauthorized}),this.name="CapitalOSInvalidTokenError"}};import{connectToChild as fe}from"penpal";import{useEffect as ge,useMemo as he,useRef as Q}from"react";var Z="1.1.0-rc.1";function le(e){let t=JSON.stringify(e),o=btoa(t);return encodeURIComponent(o)}function W(e){try{let t=decodeURIComponent(e),o=atob(t);return JSON.parse(o)}catch(t){throw new v}}function ue(e){try{return decodeURIComponent(e)}catch(t){return e}}function G({tokenData:e,renderingContext:t,theme:o,onError:n}){try{let r=t?c(a({},t),{referer:window.location.href}):null,i=r?le(r):null,s=new URL(e.baseUrl),d=ue(e.token);return e.paramLocation==="search"?s.searchParams.set(e.paramKey,d):e.paramLocation==="hash"&&(s.hash=e.paramKey+"="+encodeURIComponent(d)),s.searchParams.set("sdkVersion",Z),i&&s.searchParams.set("renderingContext",i),o&&s.searchParams.set("theme",o),s.toString()}catch(r){n==null||n(new v);return}}function H(e){let o=W(e).path;if(!o||typeof o!="string")throw new v;return{token:e,tokenType:"oneTime",baseUrl:o,paramKey:"token",paramLocation:"search"}}var Ce=1e4;function B({iframeRef:e,token:t,onError:o,methods:n}){ge(()=>{if(!e.current)return;let r=fe({iframe:e.current,childOrigin:"*",debug:!0,timeout:Ce,methods:n});return r.promise.catch(i=>{o==null||o(i)}),()=>{r.destroy()}},[t,e])}function U({tokenData:e,renderingContext:t,theme:o,onError:n}){let r=Q(n),i=Q(t);return he(()=>{if(e)return G({tokenData:e,renderingContext:i.current,theme:o,onError:r.current})},[e,o,r,i])}import{iframeResizer as xe}from"iframe-resizer";import ye,{forwardRef as Te,useEffect as ke,useImperativeHandle as Pe,useRef as be}from"react";var O=Te((e,t)=>{let o=e.title||"iframe",{iframeHTMLAttributes:n,resizerOptions:r}=Ee(e),i=be(null);return ke(()=>{let s=i.current;return xe(a({},r),s),()=>s.iFrameResizer&&s.iFrameResizer.removeListeners()}),Pe(t,()=>i.current),ye.createElement("iframe",c(a({},n),{title:o,ref:i}))});O.displayName="IframeResizer";var ve=["autoResize","bodyBackground","bodyMargin","bodyPadding","checkOrigin","inPageLinks","heightCalculationMethod","interval","log","maxHeight","maxWidth","minHeight","minWidth","resizeFrom","scrolling","sizeHeight","sizeWidth","warningTimeout","tolerance","widthCalculationMethod","onClosed","onInit","onMessage","onResized","onScroll"],Ie=new Set(ve);function Ee(e){return Object.keys(e).reduce((o,n)=>{let r=e[n];return Ie.has(n)?r!==void 0&&(o.resizerOptions[n]=e[n]):o.iframeHTMLAttributes[n]=e[n],o},{resizerOptions:{},iframeHTMLAttributes:{}})}function X(e){let{oneTimeToken:t,enableLogging:o,onExchangeComplete:n,onExchangeError:r}=e,i=Le(null),s=De(()=>H(t),[t]),p=U({tokenData:s,onError:r,renderingContext:{entryPoint:"tokenExchange"}});return B({iframeRef:i,token:t,onError:r,methods:{onLoad:()=>{},onError:f=>{r==null||r(new g(f))},tokenExchange:{onLongLivedToken:n}}}),Oe.createElement(O,{src:p,checkOrigin:!1,style:{display:"none"},log:!!o,ref:i})}var Y=we({isLoading:!1,invalidateToken:()=>{}}),ze=({getToken:e,enableLogging:t,children:o})=>{let[n,r]=D(void 0),[i,s]=D(void 0),[d,p]=D(void 0),[f,C]=D(!1),[A,x]=D(void 0),I=j(()=>q(void 0,null,function*(){C(!0);try{let h=yield e();r(h),x(void 0);let z=W(h),F=new URL(z.path);F.pathname="",s(F.toString())}catch(h){x(h)}finally{C(!1)}}),[e]),k=j(()=>{p(void 0)},[]);Se(()=>{d||I()},[d,I]);let S=j(h=>{p(h),r(void 0),x(void 0)},[]),y=Ae(()=>{if(d&&!i)throw new g({message:"baseUrl is required for long lived tokens",code:E.unauthorized});return{tokenData:d?{token:d,tokenType:"longLived",baseUrl:i,paramKey:"access_token",paramLocation:"hash"}:void 0,isLoading:f,error:A,invalidateToken:k}},[d,f,A,k,i]);return _.createElement(_.Fragment,null,_.createElement(Y.Provider,{value:y},o),n&&!d&&_.createElement(X,{oneTimeToken:n,onExchangeComplete:S,enableLogging:t,onExchangeError:x}))},ee=()=>Me(Y);function m(e){let{token:t,className:o,enableLogging:n,onError:r,loadingComponent:i,renderingContext:s,methods:d,theme:p,sizeWidth:f}=e,{tokenData:C,error:A,invalidateToken:x}=ee(),[I,k]=Re(!1),S=oe(null);Be(A,r);let y=Fe(()=>t?H(t):C,[t,C]),h=He(()=>{if(n&&console.log("CapitalOS: Token expired, invalidating..."),t){r==null||r(new g({message:"Token expired. Cannot automatically refresh when using token prop.",code:E.unauthorized}));return}x(),k(!1)},[t,x,n,r]);te(()=>{t&&C&&n&&console.warn("CapitalOS: token was provided both from provider and from the token prop. the prop will take precedence")},[t,C,n]);let z=U({tokenData:y,renderingContext:s,theme:p,onError:r});if(B({iframeRef:S,token:y==null?void 0:y.token,onError:P=>{r==null||r(P),k(!0)},methods:a({onLoad:()=>{k(!0)},onError:P=>{let N=new g(P);r==null||r(N)},onTokenExpired:h},d)}),!y||!z)return L.createElement(L.Fragment,null,i||null);let F=s.entryPoint!=="insightsWidget";return L.createElement(L.Fragment,null,!I&&i,L.createElement(O,{src:z,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:o,log:!!n,ref:S,hidden:!I,onResized:P=>{if(!F)return;let N=`${parseInt(P.height)+12}px`;P.iframe.style.height=N},sizeWidth:f}))}function Be(e,t){let o=oe(!1);te(()=>{e&&!o.current&&(t==null||t(e),o.current=!0)},[e,t])}import M,{useMemo as Ue}from"react";import{useState as _e}from"react";import T,{useState as ne}from"react";var w={bugButton:{position:"fixed",left:"12px",bottom:"12px",margin:"12px",padding:"4px",display:"inline-flex",alignItems:"center",borderRadius:"9999px",border:"1px solid transparent",backgroundColor:"#2563eb",color:"white",opacity:.4,boxShadow:"0 1px 3px 0 rgb(0 0 0 / 0.1)",cursor:"pointer",zIndex:50,transition:"opacity 0.3s ease-in-out"},bugButtonHover:{backgroundColor:"#1d4ed8",opacity:1},bugButtonFocus:{outline:"none",boxShadow:"0 0 0 2px white, 0 0 0 4px #3b82f6"},bugIcon:{width:"20px",height:"20px"},loadingButton:{cursor:"default",opacity:1,animation:"pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite"}},re=()=>T.createElement("svg",{style:w.bugIcon,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor"},T.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 12.75c1.148 0 2.278.08 3.383.237 1.037.146 1.866.966 1.866 2.013 0 3.728-2.35 6.75-5.25 6.75S6.75 18.728 6.75 15c0-1.046.83-1.867 1.866-2.013A24.204 24.204 0 0 1 12 12.75Zm0 0c2.883 0 5.647.508 8.207 1.44a23.91 23.91 0 0 1-1.152 6.06M12 12.75c-2.883 0-5.647.508-8.208 1.44.125 2.104.52 4.136 1.153 6.06M12 12.75a2.25 2.25 0 0 0 2.248-2.354M12 12.75a2.25 2.25 0 0 1-2.248-2.354M12 8.25c.995 0 1.971-.08 2.922-.236.403-.066.74-.358.795-.762a3.778 3.778 0 0 0-.399-2.25M12 8.25c-.995 0-1.97-.08-2.922-.236-.402-.066-.74-.358-.795-.762a3.734 3.734 0 0 1 .4-2.253M12 8.25a2.25 2.25 0 0 0-2.248 2.146M12 8.25a2.25 2.25 0 0 1 2.248 2.146M8.683 5a6.032 6.032 0 0 1-1.155-1.002c.07-.63.27-1.222.574-1.747m.581 2.749A3.75 3.75 0 0 1 15.318 5m0 0c.427-.283.815-.62 1.155-.999a4.471 4.471 0 0 0-.575-1.752M4.921 6a24.048 24.048 0 0 0-.392 3.314c1.668.546 3.416.914 5.223 1.082M19.08 6c.205 1.08.337 2.187.392 3.314a23.882 23.882 0 0 1-5.223 1.082"}));function K({onClick:e,isLoading:t=!1}){let[o,n]=ne(!1),[r,i]=ne(!1),s=a(a(a(a({},w.bugButton),t&&w.loadingButton),!t&&o&&w.bugButtonHover),!t&&r&&w.bugButtonFocus);return t?T.createElement("div",{style:s},T.createElement("style",null,`
1
+ "use client";var be=Object.defineProperty,ke=Object.defineProperties;var Te=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var ne=(e,t,n)=>t in e?be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var n in t||(t={}))oe.call(t,n)&&ne(e,n,t[n]);if(U)for(var n of U(t))re.call(t,n)&&ne(e,n,t[n]);return e},l=(e,t)=>ke(e,Te(t));var v=(e,t)=>{var n={};for(var o in e)oe.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&U)for(var o of U(e))t.indexOf(o)<0&&re.call(e,o)&&(n[o]=e[o]);return n};var A=(e,t,n)=>new Promise((o,i)=>{var r=d=>{try{a(n.next(d))}catch(u){i(u)}},s=d=>{try{a(n.throw(d))}catch(u){i(u)}},a=d=>d.done?o(d.value):Promise.resolve(d.value).then(r,s);a((n=n.apply(e,t)).next())});import x,{useMemo as h,useContext as ct}from"react";import B from"react";import z,{createContext as et,useContext as tt,useState as H,useMemo as xe,useCallback as S,useEffect as nt}from"react";import je,{useMemo as $e,useRef as Ke}from"react";var C=class extends Error{constructor({message:t,code:n}){super(t),this.name="CapitalOSError",this.code=n}},b={unauthorized:"unauthorized",invalid_account_status:"invalid_account_status",unsupported_entry_point:"unsupported_entry_point",internal_error:"internal_error"},D=class extends C{constructor(t){super({message:`Invalid token ${t!=null?t:""}`,code:b.unauthorized}),this.name="CapitalOSInvalidTokenError"}};import{connectToChild as De}from"penpal";import{useCallback as we,useEffect as J,useMemo as ae,useRef as W,useState as ce}from"react";var ie="1.2.1-rc.1";function Oe(e){let t=JSON.stringify(e),n=btoa(t);return encodeURIComponent(n)}function V(e){try{let t=decodeURIComponent(e),n=atob(t);return JSON.parse(n)}catch(t){throw new D}}function Ae(e){try{return decodeURIComponent(e)}catch(t){return e}}function se({tokenData:e,renderingContext:t,theme:n,onError:o}){try{let i=t?l(c({},t),{referer:window.location.href}):null,r=i?Oe(i):null,s=new URL(e.baseUrl),a=Ae(e.token);return e.paramLocation==="search"?s.searchParams.set(e.paramKey,a):e.paramLocation==="hash"&&(s.hash=e.paramKey+"="+encodeURIComponent(a)),s.searchParams.set("sdkVersion",ie),r&&s.searchParams.set("renderingContext",r),n&&s.searchParams.set("theme",n),s.toString()}catch(i){o==null||o(new D);return}}function q(e){let n=V(e).path;if(!n||typeof n!="string")throw new D;return{token:e,tokenType:"oneTime",baseUrl:n,paramKey:"token",paramLocation:"search"}}var Se=1e4;function X({iframeRef:e,token:t,onError:n,methods:o}){let[i,r]=ce(null);return J(()=>{if(!e.current)return;let s=De({iframe:e.current,childOrigin:"*",debug:!0,timeout:Se,methods:o});return s.promise.then(()=>{r(s)}).catch(a=>{n==null||n(a),r(null)}),()=>{s.destroy(),r(null)}},[t,e]),i}function Z({tokenData:e,renderingContext:t,theme:n,onError:o}){let i=W(o),r=W(t);return ae(()=>{if(e)return se({tokenData:e,renderingContext:r.current,theme:n,onError:i.current})},[e,n,i,r])}function j(e){let{oneTimeToken:t,enableLogging:n,onError:o,renderingContext:i,theme:r,methods:s}=e,{tokenData:a,error:d,invalidateToken:u}=G(),{log:f,warn:y}=w(n),[P,k]=ce(!1),T=W(null);Re(d,o);let E=ae(()=>t?q(t):a,[t,a]),I=we(()=>{if(f("Token expired, invalidating..."),t){o==null||o(new C({message:"Token expired. Cannot automatically refresh when using token prop.",code:b.unauthorized}));return}u(),k(!1)},[t,u,f,o]);J(()=>{t&&a&&y("token was provided both from provider and from the token prop. the prop will take precedence")},[t,a,y]);let g=Z({tokenData:E,renderingContext:i,theme:r,onError:o}),p=X({iframeRef:T,token:E==null?void 0:E.token,onError:O=>{o==null||o(O),k(!0)},methods:c({onLoad:()=>{k(!0)},onError:O=>{let ve=new C(O);o==null||o(ve)},onTokenExpired:I},s)});return{isLoaded:P,url:g,tokenData:E,iframeRef:T,connection:p}}function Re(e,t){let n=W(!1);J(()=>{e&&!n.current&&(t==null||t(e),n.current=!0)},[e,t])}import{iframeResizer as Fe}from"iframe-resizer";import ze,{forwardRef as He,useEffect as Be,useImperativeHandle as Ne,useRef as _e}from"react";var M=He((e,t)=>{let n=e.title||"iframe",{iframeHTMLAttributes:o,resizerOptions:i}=We(e),r=_e(null);return Be(()=>{let s=r.current;return Fe(c({},i),s),()=>s.iFrameResizer&&s.iFrameResizer.removeListeners()}),Ne(t,()=>r.current),ze.createElement("iframe",l(c({},o),{title:n,ref:r}))});M.displayName="IframeResizer";var Ue=["autoResize","bodyBackground","bodyMargin","bodyPadding","checkOrigin","inPageLinks","heightCalculationMethod","interval","log","maxHeight","maxWidth","minHeight","minWidth","resizeFrom","scrolling","sizeHeight","sizeWidth","warningTimeout","tolerance","widthCalculationMethod","onClosed","onInit","onMessage","onResized","onScroll"],qe=new Set(Ue);function We(e){return Object.keys(e).reduce((n,o)=>{let i=e[o];return qe.has(o)?i!==void 0&&(n.resizerOptions[o]=e[o]):n.iframeHTMLAttributes[o]=e[o],n},{resizerOptions:{},iframeHTMLAttributes:{}})}function de(e){let{oneTimeToken:t,enableLogging:n,onExchangeComplete:o,onExchangeError:i}=e,r=R(n),s=Ke(null),a=$e(()=>q(t),[t]),u=Z({tokenData:a,onError:i,renderingContext:{entryPoint:"tokenExchange"}});return X({iframeRef:s,token:t,onError:i,methods:{onLoad:()=>{},onError:f=>{i==null||i(new C(f))},tokenExchange:{onLongLivedToken:o}}}),je.createElement(M,{src:u,checkOrigin:!1,style:{display:"none"},log:r,ref:s})}var Q={enableLogging:!1},Y="[CapitalOS] ",$={log:(e,t=Q)=>{t.enableLogging&&console.log(`${Y}${e}`)},warn:(e,t=Q)=>{t.enableLogging&&console.warn(`${Y}${e}`)},error:(e,t=Q)=>{t.enableLogging&&console.error(`${Y}${e}`)}};import F,{createContext as Ge,useState as Qe,useMemo as ge,useCallback as Ye}from"react";import Ve from"react";import{useMemo as Je}from"react";function le(d){var u=d,{onDone:e,onCancel:t,mfaId:n,destination:o,codeLength:i,canResendAfter:r,operationName:s}=u,a=v(u,["onDone","onCancel","mfaId","destination","codeLength","canResendAfter","operationName"]);let f="mfa",y=Je(()=>({entryPoint:f,mfaId:n,destination:o,codeLength:i,canResendAfter:r,operationName:s}),[f,n,o,i,r,s]);return Ve.createElement(m,l(c({},a),{renderingContext:y,methods:{mfa:{onDone:e,onCancel:t}}}))}import pe,{useEffect as Xe}from"react";var ue={backdrop:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(2px)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",padding:"20px"},container:{backgroundColor:"white",borderRadius:"8px",boxShadow:"0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05)",maxWidth:"600px",width:"100%",maxHeight:"90vh",overflow:"hidden",position:"relative"}};function me({onClose:e,children:t,ariaLabel:n="Modal dialog"}){Xe(()=>{let i=r=>{r.key==="Escape"&&e()};return document.addEventListener("keydown",i),()=>{document.removeEventListener("keydown",i)}},[e]);let o=i=>{i.target===i.currentTarget&&e()};return pe.createElement("div",{style:ue.backdrop,onClick:o,role:"dialog","aria-modal":"true","aria-label":n},pe.createElement("div",{style:ue.container},t))}import{useState as Ze,useCallback as K}from"react";function fe(){var u;let[e,t]=Ze(null),{log:n}=w(),o=K(f=>(n("MFA requested"),new Promise((y,P)=>{t({context:f,resolve:y,reject:P})})),[n]),i=K(()=>{e&&(n("MFA completed successfully"),e.resolve({success:!0,canceled:!1,data:void 0}),t(null))},[e,n]),r=K(()=>{e&&(n("MFA canceled"),e.resolve({success:!1,canceled:!0}),t(null))},[e,n]),s=K(f=>{e&&(n("MFA error: "+f.message),e.resolve({success:!1,canceled:!1,error:f}),t(null))},[e,n]),a=!!e,d=(u=e==null?void 0:e.context)!=null?u:null;return{activeMfaRequest:e,isMfaActive:a,mfaContext:d,requestMfa:o,handleMfaDone:i,handleMfaCancel:r,handleMfaError:s}}var ee=Ge(null);function Ce({children:e}){let[t,n]=Qe(null),{log:o}=w(),{requestMfa:i,handleMfaDone:r,handleMfaCancel:s,isMfaActive:a,mfaContext:d}=fe(),u=Ye(g=>A(this,null,function*(){let p=yield i(g);return p.success?{success:!0}:p.canceled?{success:!1,canceled:!0}:{success:!1,error:p.error.message}}),[i]),f=ge(()=>t?{freezeCard:g=>A(this,null,function*(){try{let p=yield t.freezeCard(g);return p.success?{success:!0,canceled:!1,data:p.data}:p.canceled?{success:!1,canceled:!0}:{success:!1,canceled:!1,error:new C({code:b.internal_error,message:p.error})}}catch(p){return{success:!1,canceled:!1,error:new C({code:b.internal_error,message:p instanceof Error?p.message:"Communication error with iframe"})}}}),unfreezeCard:g=>A(this,null,function*(){try{let p=yield t.unfreezeCard(g);return p.success?{success:!0,canceled:!1,data:p.data}:p.canceled?{success:!1,canceled:!0}:{success:!1,canceled:!1,error:new C({code:b.internal_error,message:p.error})}}catch(p){return{success:!1,canceled:!1,error:new C({code:b.internal_error,message:p instanceof Error?p.message:"Communication error with iframe"})}}})}:null,[t]),y=ge(()=>({"system-messages":{requestMfa:u},mfa:{onDone:r,onCancel:s}}),[u,r,s]),{isLoaded:P,url:k,connection:T,iframeRef:E}=j({renderingContext:{entryPoint:"actions"},methods:y});F.useEffect(()=>{let g=!0;return T&&T.promise.then(p=>{g&&(n(p),o("Actions iframe child functions loaded"))}),()=>{g=!1}},[T,o]);let I=!P||!t;return F.createElement(ee.Provider,{value:{childFunctions:t,actions:f,isLoading:I}},e,k&&F.createElement(M,{src:k,style:{display:"none"},checkOrigin:!1,ref:E}),a&&d&&F.createElement(me,{onClose:s,ariaLabel:"Multi-factor authentication"},F.createElement(le,l(c({mfaId:d.mfaId,destination:d.destination,codeLength:d.codeLength,canResendAfter:d.canResendAfter},d.operationName&&{operationName:d.operationName}),{onDone:r,onCancel:s}))))}var he=et({isLoading:!1,invalidateToken:()=>{},enableLogging:!1}),ot=({getToken:e,enableLogging:t,children:n})=>{let[o,i]=H(void 0),[r,s]=H(void 0),[a,d]=H(void 0),[u,f]=H(!1),[y,P]=H(void 0),k=S(()=>A(void 0,null,function*(){f(!0);try{let g=yield e();i(g),P(void 0);let p=V(g),O=new URL(p.path);O.pathname="",s(O.toString())}catch(g){P(g)}finally{f(!1)}}),[e]),T=S(()=>{d(void 0)},[]);nt(()=>{a||k()},[a,k]);let E=S(g=>{d(g),i(void 0),P(void 0)},[]),I=xe(()=>{if(a&&!r)throw new C({message:"baseUrl is required for long lived tokens",code:b.unauthorized});return{tokenData:a?{token:a,tokenType:"longLived",baseUrl:r,paramKey:"access_token",paramLocation:"hash"}:void 0,isLoading:u,error:y,invalidateToken:T,enableLogging:t!=null?t:!1}},[a,u,y,T,r,t]);return z.createElement(z.Fragment,null,z.createElement(he.Provider,{value:I},z.createElement(Ce,null,n)),o&&!a&&z.createElement(de,{oneTimeToken:o,onExchangeComplete:E,enableLogging:t,onExchangeError:P}))},G=()=>tt(he);function R(e){let{enableLogging:t}=G();return e!==void 0?e:t}function w(e){let t=R(e),n=S(r=>{$.log(r,{enableLogging:t})},[t]),o=S(r=>{$.warn(r,{enableLogging:t})},[t]),i=S(r=>{$.error(r,{enableLogging:t})},[t]);return xe(()=>({log:n,warn:o,error:i}),[n,o,i])}function m(e){let{token:t,className:n,enableLogging:o,onError:i,loadingComponent:r,renderingContext:s,methods:a,theme:d,sizeWidth:u}=e,f=R(o),{isLoaded:y,url:P,tokenData:k,iframeRef:T}=j({oneTimeToken:t,enableLogging:f,onError:i,renderingContext:s,theme:d,methods:a});if(!k||!P)return B.createElement(B.Fragment,null,r||null);let E=s.entryPoint!=="insightsWidget";return B.createElement(B.Fragment,null,!y&&r,B.createElement(M,{src:P,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:n,log:f,ref:T,hidden:!y,onResized:I=>{if(!E)return;let g=`${parseInt(I.height)+12}px`;I.iframe.style.height=g},sizeWidth:u}))}import _,{useMemo as rt}from"react";import{useState as it}from"react";import L,{useState as ye}from"react";var N={bugButton:{position:"fixed",left:"12px",bottom:"12px",margin:"12px",padding:"4px",display:"inline-flex",alignItems:"center",borderRadius:"9999px",border:"1px solid transparent",backgroundColor:"#2563eb",color:"white",opacity:.4,boxShadow:"0 1px 3px 0 rgb(0 0 0 / 0.1)",cursor:"pointer",zIndex:50,transition:"opacity 0.3s ease-in-out"},bugButtonHover:{backgroundColor:"#1d4ed8",opacity:1},bugButtonFocus:{outline:"none",boxShadow:"0 0 0 2px white, 0 0 0 4px #3b82f6"},bugIcon:{width:"20px",height:"20px"},loadingButton:{cursor:"default",opacity:1,animation:"pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite"}},Pe=()=>L.createElement("svg",{style:N.bugIcon,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor"},L.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 12.75c1.148 0 2.278.08 3.383.237 1.037.146 1.866.966 1.866 2.013 0 3.728-2.35 6.75-5.25 6.75S6.75 18.728 6.75 15c0-1.046.83-1.867 1.866-2.013A24.204 24.204 0 0 1 12 12.75Zm0 0c2.883 0 5.647.508 8.207 1.44a23.91 23.91 0 0 1-1.152 6.06M12 12.75c-2.883 0-5.647.508-8.208 1.44.125 2.104.52 4.136 1.153 6.06M12 12.75a2.25 2.25 0 0 0 2.248-2.354M12 12.75a2.25 2.25 0 0 1-2.248-2.354M12 8.25c.995 0 1.971-.08 2.922-.236.403-.066.74-.358.795-.762a3.778 3.778 0 0 0-.399-2.25M12 8.25c-.995 0-1.97-.08-2.922-.236-.402-.066-.74-.358-.795-.762a3.734 3.734 0 0 1 .4-2.253M12 8.25a2.25 2.25 0 0 0-2.248 2.146M12 8.25a2.25 2.25 0 0 1 2.248 2.146M8.683 5a6.032 6.032 0 0 1-1.155-1.002c.07-.63.27-1.222.574-1.747m.581 2.749A3.75 3.75 0 0 1 15.318 5m0 0c.427-.283.815-.62 1.155-.999a4.471 4.471 0 0 0-.575-1.752M4.921 6a24.048 24.048 0 0 0-.392 3.314c1.668.546 3.416.914 5.223 1.082M19.08 6c.205 1.08.337 2.187.392 3.314a23.882 23.882 0 0 1-5.223 1.082"}));function te({onClick:e,isLoading:t=!1}){let[n,o]=ye(!1),[i,r]=ye(!1),s=c(c(c(c({},N.bugButton),t&&N.loadingButton),!t&&n&&N.bugButtonHover),!t&&i&&N.bugButtonFocus);return t?L.createElement("div",{style:s},L.createElement("style",null,`
2
2
  @keyframes pulse {
3
3
  0%, 100% {
4
4
  opacity: 1;
@@ -7,5 +7,5 @@
7
7
  opacity: 0.4;
8
8
  }
9
9
  }
10
- `),T.createElement(re,null)):T.createElement("button",{id:"dev-tools-button",onClick:e,type:"button",style:s,onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),onFocus:()=>i(!0),onBlur:()=>i(!1)},T.createElement(re,null))}var Ne={panel:{position:"fixed",bottom:"20px",left:"20px",zIndex:50}};function We(e){let t="devTools",o=Ue(()=>({entryPoint:t}),[t]),[n,r]=_e(!1);return M.createElement("aside",{"aria-label":"CapitalOS dev tools"},!n&&M.createElement(K,{onClick:()=>r(!n)}),n&&M.createElement("div",{style:Ne.panel},M.createElement(m,c(a({},e),{renderingContext:o,methods:{devTools:{onClose:()=>r(!1)}},enableLogging:!0,sizeWidth:!0,loadingComponent:M.createElement(K,{isLoading:!0})}))))}function je(e){let t="cardsApp",o=u(()=>({entryPoint:t}),[t]);return l.createElement(m,c(a({},e),{renderingContext:o}))}var Xt=je;function Yt(r){var i=r,{cardholder:e,onDone:t,onCancel:o}=i,n=b(i,["cardholder","onDone","onCancel"]);let s="createCard",d=u(()=>({entryPoint:s,cardholder:e}),[e]);return l.createElement(m,c(a({},n),{renderingContext:d,methods:{createCard:{onDone:t,onCancel:o}}}))}function eo(r){var i=r,{transactionId:e,onDone:t,onCancel:o}=i,n=b(i,["transactionId","onDone","onCancel"]);let s="createDispute",d=u(()=>({entryPoint:s,transactionId:e}),[e]);return l.createElement(m,c(a({},n),{renderingContext:d,methods:{createDispute:{onDone:t,onCancel:o}}}))}function to(e){let t="billPayApp",o=u(()=>({entryPoint:t}),[t]);return l.createElement(m,c(a({},e),{renderingContext:o}))}function oo(e){let i=e,{onCardCanceled:t}=i,o=b(i,["onCardCanceled"]),n="cardDetails",r=u(()=>({entryPoint:n,cardId:e.cardId,cardOnly:e.cardOnly,hideAddress:e.hideAddress}),[n,e.cardId,e.cardOnly]);return l.createElement(m,c(a({},o),{renderingContext:r,methods:{cardDetails:{onCardCanceled:t!=null?t:()=>{}}}}))}function no(e){let t="accountDetails",o=u(()=>({entryPoint:t}),[t]);return l.createElement(m,c(a({},e),{renderingContext:o}))}function ro(e){let t="accountActions",o=u(()=>({entryPoint:t}),[t]);return l.createElement(m,c(a({},e),{renderingContext:o}))}function io(e){let t="insightsDashboard",o=u(()=>({entryPoint:t}),[t]);return l.createElement(m,c(a({},e),{renderingContext:o}))}function so(e){let t="insightsWidget",{widget:o,hideTitle:n,height:r,width:i}=e,s=u(()=>({entryPoint:t,widget:o,hideTitle:n,height:r,width:i}),[t,o,n,r,i]);return l.createElement(m,c(a({},e),{renderingContext:s}))}function ao(r){var i=r,{onDone:e,entryPoint:t,exitPoint:o}=i,n=b(i,["onDone","entryPoint","exitPoint"]);let s="onboarding",d=u(()=>({entryPoint:s,onboardingEntryPoint:t,onboardingExitPoint:o}),[s,t,o]);return l.createElement(m,c(a({},n),{renderingContext:d,methods:{onboarding:{onDone:e}}}))}function co(o){var n=o,{onDone:e}=n,t=b(n,["onDone"]);let r="makePayment",i=u(()=>({entryPoint:r}),[r]);return l.createElement(m,c(a({},t),{renderingContext:i,methods:{makePayment:{onDone:e}}}))}export{ro as AccountActions,no as AccountDetails,Xt as App,to as BillPayApp,ze as CapitalOsAuthenticationProvider,oo as CardDetails,je as CardsApp,We as DevTools,eo as DisputeTransaction,io as InsightsDashboard,so as InsightsWidget,Yt as IssueCard,co as MakePayment,ao as Onboarding};
10
+ `),L.createElement(Pe,null)):L.createElement("button",{id:"dev-tools-button",onClick:e,type:"button",style:s,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),onFocus:()=>r(!0),onBlur:()=>r(!1)},L.createElement(Pe,null))}var st={panel:{position:"fixed",bottom:"20px",left:"20px",zIndex:50}};function at(e){let t="devTools",n=rt(()=>({entryPoint:t}),[t]),[o,i]=it(!1);return _.createElement("aside",{"aria-label":"CapitalOS dev tools"},!o&&_.createElement(te,{onClick:()=>i(!o)}),o&&_.createElement("div",{style:st.panel},_.createElement(m,l(c({},e),{renderingContext:n,methods:{devTools:{onClose:()=>i(!1)}},enableLogging:!0,sizeWidth:!0,loadingComponent:_.createElement(te,{isLoading:!0})}))))}function dt(e){let t="cardsApp",n=h(()=>({entryPoint:t}),[t]);return x.createElement(m,l(c({},e),{renderingContext:n}))}var Xn=dt;function Zn(i){var r=i,{cardholder:e,onDone:t,onCancel:n}=r,o=v(r,["cardholder","onDone","onCancel"]);let s="createCard",a=h(()=>({entryPoint:s,cardholder:e}),[e]);return x.createElement(m,l(c({},o),{renderingContext:a,methods:{createCard:{onDone:t,onCancel:n}}}))}function Gn(i){var r=i,{transactionId:e,onDone:t,onCancel:n}=r,o=v(r,["transactionId","onDone","onCancel"]);let s="createDispute",a=h(()=>({entryPoint:s,transactionId:e}),[e]);return x.createElement(m,l(c({},o),{renderingContext:a,methods:{createDispute:{onDone:t,onCancel:n}}}))}function Qn(e){let t="billPayApp",n=h(()=>({entryPoint:t}),[t]);return x.createElement(m,l(c({},e),{renderingContext:n}))}function Yn(e){let r=e,{onCardCanceled:t}=r,n=v(r,["onCardCanceled"]),o="cardDetails",i=h(()=>({entryPoint:o,cardId:e.cardId,cardOnly:e.cardOnly,hideAddress:e.hideAddress}),[o,e.cardId,e.cardOnly]);return x.createElement(m,l(c({},n),{renderingContext:i,methods:{cardDetails:{onCardCanceled:t!=null?t:()=>{}}}}))}function eo(e){let t="accountDetails",n=h(()=>({entryPoint:t}),[t]);return x.createElement(m,l(c({},e),{renderingContext:n}))}function to(e){let t="accountActions",n=h(()=>({entryPoint:t}),[t]);return x.createElement(m,l(c({},e),{renderingContext:n}))}function no(e){let t="insightsDashboard",n=h(()=>({entryPoint:t}),[t]);return x.createElement(m,l(c({},e),{renderingContext:n}))}function oo(e){let t="insightsWidget",{widget:n,hideTitle:o,height:i,width:r}=e,s=h(()=>({entryPoint:t,widget:n,hideTitle:o,height:i,width:r}),[t,n,o,i,r]);return x.createElement(m,l(c({},e),{renderingContext:s}))}function ro(i){var r=i,{onDone:e,entryPoint:t,exitPoint:n}=r,o=v(r,["onDone","entryPoint","exitPoint"]);let s="onboarding",a=h(()=>({entryPoint:s,onboardingEntryPoint:t,onboardingExitPoint:n}),[s,t,n]);return x.createElement(m,l(c({},o),{renderingContext:a,methods:{onboarding:{onDone:e}}}))}function io(n){var o=n,{onDone:e}=o,t=v(o,["onDone"]);let i="makePayment",r=h(()=>({entryPoint:i}),[i]);return x.createElement(m,l(c({},t),{renderingContext:r,methods:{makePayment:{onDone:e}}}))}function so(o){var i=o,{onDone:e,onCancel:t}=i,n=v(i,["onDone","onCancel"]);let r="contactSupport",s=h(()=>({entryPoint:r}),[r]);return x.createElement(m,l(c({},n),{renderingContext:s,methods:{contactSupport:{onDone:e,onCancel:t}}}))}function ao(n){var o=n,{onDone:e}=o,t=v(o,["onDone"]);let i="statements",r=h(()=>({entryPoint:i}),[i]);return x.createElement(m,l(c({},t),{renderingContext:r,methods:{statements:{onDone:e}}}))}function co(n){var o=n,{onDone:e}=o,t=v(o,["onDone"]);let i="legalDocuments",r=h(()=>({entryPoint:i}),[i]);return x.createElement(m,l(c({},t),{renderingContext:r,methods:{legalDocuments:{onDone:e}}}))}function lo(i){var r=i,{cardId:e,onDone:t,onClose:n}=r,o=v(r,["cardId","onDone","onClose"]);let s="replaceCard",a=h(()=>({entryPoint:s,cardId:e}),[e]);return x.createElement(m,l(c({},o),{renderingContext:a,methods:{replaceCard:{onDone:t,onClose:n}}}))}function po(i){var r=i,{cardId:e,onDone:t,onClose:n}=r,o=v(r,["cardId","onDone","onClose"]);let s="terminateCard",a=h(()=>({entryPoint:s,cardId:e}),[e]);return x.createElement(m,l(c({},o),{renderingContext:a,methods:{terminateCard:{onDone:t,onClose:n}}}))}function uo(){let e=ct(ee);if(!e)throw new C({message:"useActions must be used within a CapitalOsAuthenticationProvider",code:b.internal_error});let{childFunctions:t,isLoading:n}=e;return{actions:t,isLoading:n}}export{to as AccountActions,eo as AccountDetails,Xn as App,Qn as BillPayApp,ot as CapitalOsAuthenticationProvider,Yn as CardDetails,dt as CardsApp,so as ContactSupport,at as DevTools,Gn as DisputeTransaction,no as InsightsDashboard,oo as InsightsWidget,Zn as IssueCard,co as LegalDocuments,io as MakePayment,ro as Onboarding,lo as ReplaceCard,ao as Statements,po as TerminateCard,uo as useActions};
11
11
  //# sourceMappingURL=index.js.map