@capitalos/react 0.2.1-rc1 → 0.2.1-rc3
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/_tsup-dts-rollup.d.mts +65 -16
- package/dist/_tsup-dts-rollup.d.ts +65 -16
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/index.d.mts +0 -1
- package/dist/src/index.d.ts +0 -1
- package/package.json +1 -1
|
@@ -121,6 +121,7 @@ declare const cardApiDtoSchema: z.ZodObject<{
|
|
|
121
121
|
limit?: number | undefined;
|
|
122
122
|
};
|
|
123
123
|
}>;
|
|
124
|
+
allowedSpendCategories: z.ZodArray<z.ZodEnum<["airlines", "car_rental", "fuel_pump_only", "fuel_station", "lodging", "parking", "taxi_and_rideshare", "travel_misc"]>, "many">;
|
|
124
125
|
isFuelCard: z.ZodBoolean;
|
|
125
126
|
physicalCard: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
126
127
|
id: z.ZodString;
|
|
@@ -156,6 +157,7 @@ declare const cardApiDtoSchema: z.ZodObject<{
|
|
|
156
157
|
limit?: number | undefined;
|
|
157
158
|
};
|
|
158
159
|
};
|
|
160
|
+
allowedSpendCategories: ("airlines" | "car_rental" | "fuel_pump_only" | "fuel_station" | "lodging" | "parking" | "taxi_and_rideshare" | "travel_misc")[];
|
|
159
161
|
isFuelCard: boolean;
|
|
160
162
|
nickname?: string | null | undefined;
|
|
161
163
|
physicalCard?: {
|
|
@@ -188,6 +190,7 @@ declare const cardApiDtoSchema: z.ZodObject<{
|
|
|
188
190
|
limit?: number | undefined;
|
|
189
191
|
};
|
|
190
192
|
};
|
|
193
|
+
allowedSpendCategories: ("airlines" | "car_rental" | "fuel_pump_only" | "fuel_station" | "lodging" | "parking" | "taxi_and_rideshare" | "travel_misc")[];
|
|
191
194
|
isFuelCard: boolean;
|
|
192
195
|
nickname?: string | null | undefined;
|
|
193
196
|
physicalCard?: {
|
|
@@ -250,7 +253,7 @@ export declare type EntryPoint = RenderingContext_2['entryPoint'];
|
|
|
250
253
|
export declare type IframeConnectionMethods = {
|
|
251
254
|
onLoad: () => void;
|
|
252
255
|
createCard?: {
|
|
253
|
-
onDone?: (
|
|
256
|
+
onDone?: () => void;
|
|
254
257
|
onCancel?: () => void;
|
|
255
258
|
};
|
|
256
259
|
createDispute?: {
|
|
@@ -279,22 +282,48 @@ export declare class InvalidTokenError extends CapitalOSError {
|
|
|
279
282
|
*/
|
|
280
283
|
export declare function IssueCard({ defaultValues, onDone, onCancel, ...restOfProps }: IssueCardProps): JSX.Element;
|
|
281
284
|
|
|
282
|
-
export declare type IssueCardDefaultValues =
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
export declare type IssueCardDefaultValues = z_2.infer<typeof issueCardDefaultValuesSchema>;
|
|
286
|
+
|
|
287
|
+
declare const issueCardDefaultValuesSchema: z_2.ZodIntersection<z_2.ZodUnion<[z_2.ZodObject<{
|
|
288
|
+
firstName: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
289
|
+
lastName: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
290
|
+
phone: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
291
|
+
userId: z_2.ZodOptional<z_2.ZodUndefined>;
|
|
292
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
293
|
+
firstName?: string | null | undefined;
|
|
294
|
+
lastName?: string | null | undefined;
|
|
295
|
+
phone?: string | null | undefined;
|
|
296
|
+
userId?: undefined;
|
|
297
|
+
}, {
|
|
298
|
+
firstName?: string | null | undefined;
|
|
299
|
+
lastName?: string | null | undefined;
|
|
300
|
+
phone?: string | null | undefined;
|
|
301
|
+
userId?: undefined;
|
|
302
|
+
}>, z_2.ZodObject<{
|
|
303
|
+
userId: z_2.ZodString;
|
|
304
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
305
|
+
userId: string;
|
|
306
|
+
}, {
|
|
307
|
+
userId: string;
|
|
308
|
+
}>]>, z_2.ZodObject<{
|
|
309
|
+
nickname: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
310
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
311
|
+
nickname?: string | null | undefined;
|
|
312
|
+
}, {
|
|
313
|
+
nickname?: string | null | undefined;
|
|
314
|
+
}>>;
|
|
288
315
|
|
|
289
316
|
export declare type IssueCardProps = CommonProps & {
|
|
290
317
|
/**
|
|
291
318
|
* Default values to prefill the form with.
|
|
319
|
+
*
|
|
320
|
+
* Either provide a userId, in which case the default values will be taken from that user's profile, or provide the cardholder's details directly.
|
|
292
321
|
*/
|
|
293
322
|
defaultValues?: IssueCardDefaultValues;
|
|
294
323
|
/**
|
|
295
324
|
* Callback to invoke when the card was created successfully.
|
|
296
325
|
*/
|
|
297
|
-
onDone: (
|
|
326
|
+
onDone: () => void;
|
|
298
327
|
/**
|
|
299
328
|
* Callback to invoke when the card creation was cancelled by the user.
|
|
300
329
|
*/
|
|
@@ -305,38 +334,58 @@ declare type RenderingContext_2 = z_2.infer<typeof renderingContextSchema>;
|
|
|
305
334
|
|
|
306
335
|
declare const renderingContextSchema: z_2.ZodDiscriminatedUnion<"entryPoint", [z_2.ZodObject<{
|
|
307
336
|
entryPoint: z_2.ZodLiteral<"createCard">;
|
|
308
|
-
defaultValues: z_2.ZodNullable<z_2.ZodObject<{
|
|
337
|
+
defaultValues: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodIntersection<z_2.ZodUnion<[z_2.ZodObject<{
|
|
309
338
|
firstName: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
310
339
|
lastName: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
311
340
|
phone: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
312
|
-
|
|
341
|
+
userId: z_2.ZodOptional<z_2.ZodUndefined>;
|
|
313
342
|
}, "strip", z_2.ZodTypeAny, {
|
|
314
343
|
firstName?: string | null | undefined;
|
|
315
344
|
lastName?: string | null | undefined;
|
|
316
345
|
phone?: string | null | undefined;
|
|
317
|
-
|
|
346
|
+
userId?: undefined;
|
|
318
347
|
}, {
|
|
319
348
|
firstName?: string | null | undefined;
|
|
320
349
|
lastName?: string | null | undefined;
|
|
321
350
|
phone?: string | null | undefined;
|
|
351
|
+
userId?: undefined;
|
|
352
|
+
}>, z_2.ZodObject<{
|
|
353
|
+
userId: z_2.ZodString;
|
|
354
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
355
|
+
userId: string;
|
|
356
|
+
}, {
|
|
357
|
+
userId: string;
|
|
358
|
+
}>]>, z_2.ZodObject<{
|
|
359
|
+
nickname: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
360
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
361
|
+
nickname?: string | null | undefined;
|
|
362
|
+
}, {
|
|
322
363
|
nickname?: string | null | undefined;
|
|
323
|
-
}
|
|
364
|
+
}>>>>;
|
|
324
365
|
}, "strip", z_2.ZodTypeAny, {
|
|
325
366
|
entryPoint: "createCard";
|
|
326
|
-
defaultValues
|
|
367
|
+
defaultValues?: (({
|
|
327
368
|
firstName?: string | null | undefined;
|
|
328
369
|
lastName?: string | null | undefined;
|
|
329
370
|
phone?: string | null | undefined;
|
|
371
|
+
userId?: undefined;
|
|
372
|
+
} | {
|
|
373
|
+
userId: string;
|
|
374
|
+
}) & {
|
|
330
375
|
nickname?: string | null | undefined;
|
|
331
|
-
} | null;
|
|
376
|
+
}) | null | undefined;
|
|
332
377
|
}, {
|
|
333
378
|
entryPoint: "createCard";
|
|
334
|
-
defaultValues
|
|
379
|
+
defaultValues?: (({
|
|
335
380
|
firstName?: string | null | undefined;
|
|
336
381
|
lastName?: string | null | undefined;
|
|
337
382
|
phone?: string | null | undefined;
|
|
383
|
+
userId?: undefined;
|
|
384
|
+
} | {
|
|
385
|
+
userId: string;
|
|
386
|
+
}) & {
|
|
338
387
|
nickname?: string | null | undefined;
|
|
339
|
-
} | null;
|
|
388
|
+
}) | null | undefined;
|
|
340
389
|
}>, z_2.ZodObject<{
|
|
341
390
|
entryPoint: z_2.ZodLiteral<"createDispute">;
|
|
342
391
|
transactionId: z_2.ZodString;
|
|
@@ -121,6 +121,7 @@ declare const cardApiDtoSchema: z.ZodObject<{
|
|
|
121
121
|
limit?: number | undefined;
|
|
122
122
|
};
|
|
123
123
|
}>;
|
|
124
|
+
allowedSpendCategories: z.ZodArray<z.ZodEnum<["airlines", "car_rental", "fuel_pump_only", "fuel_station", "lodging", "parking", "taxi_and_rideshare", "travel_misc"]>, "many">;
|
|
124
125
|
isFuelCard: z.ZodBoolean;
|
|
125
126
|
physicalCard: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
126
127
|
id: z.ZodString;
|
|
@@ -156,6 +157,7 @@ declare const cardApiDtoSchema: z.ZodObject<{
|
|
|
156
157
|
limit?: number | undefined;
|
|
157
158
|
};
|
|
158
159
|
};
|
|
160
|
+
allowedSpendCategories: ("airlines" | "car_rental" | "fuel_pump_only" | "fuel_station" | "lodging" | "parking" | "taxi_and_rideshare" | "travel_misc")[];
|
|
159
161
|
isFuelCard: boolean;
|
|
160
162
|
nickname?: string | null | undefined;
|
|
161
163
|
physicalCard?: {
|
|
@@ -188,6 +190,7 @@ declare const cardApiDtoSchema: z.ZodObject<{
|
|
|
188
190
|
limit?: number | undefined;
|
|
189
191
|
};
|
|
190
192
|
};
|
|
193
|
+
allowedSpendCategories: ("airlines" | "car_rental" | "fuel_pump_only" | "fuel_station" | "lodging" | "parking" | "taxi_and_rideshare" | "travel_misc")[];
|
|
191
194
|
isFuelCard: boolean;
|
|
192
195
|
nickname?: string | null | undefined;
|
|
193
196
|
physicalCard?: {
|
|
@@ -250,7 +253,7 @@ export declare type EntryPoint = RenderingContext_2['entryPoint'];
|
|
|
250
253
|
export declare type IframeConnectionMethods = {
|
|
251
254
|
onLoad: () => void;
|
|
252
255
|
createCard?: {
|
|
253
|
-
onDone?: (
|
|
256
|
+
onDone?: () => void;
|
|
254
257
|
onCancel?: () => void;
|
|
255
258
|
};
|
|
256
259
|
createDispute?: {
|
|
@@ -279,22 +282,48 @@ export declare class InvalidTokenError extends CapitalOSError {
|
|
|
279
282
|
*/
|
|
280
283
|
export declare function IssueCard({ defaultValues, onDone, onCancel, ...restOfProps }: IssueCardProps): JSX.Element;
|
|
281
284
|
|
|
282
|
-
export declare type IssueCardDefaultValues =
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
export declare type IssueCardDefaultValues = z_2.infer<typeof issueCardDefaultValuesSchema>;
|
|
286
|
+
|
|
287
|
+
declare const issueCardDefaultValuesSchema: z_2.ZodIntersection<z_2.ZodUnion<[z_2.ZodObject<{
|
|
288
|
+
firstName: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
289
|
+
lastName: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
290
|
+
phone: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
291
|
+
userId: z_2.ZodOptional<z_2.ZodUndefined>;
|
|
292
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
293
|
+
firstName?: string | null | undefined;
|
|
294
|
+
lastName?: string | null | undefined;
|
|
295
|
+
phone?: string | null | undefined;
|
|
296
|
+
userId?: undefined;
|
|
297
|
+
}, {
|
|
298
|
+
firstName?: string | null | undefined;
|
|
299
|
+
lastName?: string | null | undefined;
|
|
300
|
+
phone?: string | null | undefined;
|
|
301
|
+
userId?: undefined;
|
|
302
|
+
}>, z_2.ZodObject<{
|
|
303
|
+
userId: z_2.ZodString;
|
|
304
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
305
|
+
userId: string;
|
|
306
|
+
}, {
|
|
307
|
+
userId: string;
|
|
308
|
+
}>]>, z_2.ZodObject<{
|
|
309
|
+
nickname: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
310
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
311
|
+
nickname?: string | null | undefined;
|
|
312
|
+
}, {
|
|
313
|
+
nickname?: string | null | undefined;
|
|
314
|
+
}>>;
|
|
288
315
|
|
|
289
316
|
export declare type IssueCardProps = CommonProps & {
|
|
290
317
|
/**
|
|
291
318
|
* Default values to prefill the form with.
|
|
319
|
+
*
|
|
320
|
+
* Either provide a userId, in which case the default values will be taken from that user's profile, or provide the cardholder's details directly.
|
|
292
321
|
*/
|
|
293
322
|
defaultValues?: IssueCardDefaultValues;
|
|
294
323
|
/**
|
|
295
324
|
* Callback to invoke when the card was created successfully.
|
|
296
325
|
*/
|
|
297
|
-
onDone: (
|
|
326
|
+
onDone: () => void;
|
|
298
327
|
/**
|
|
299
328
|
* Callback to invoke when the card creation was cancelled by the user.
|
|
300
329
|
*/
|
|
@@ -305,38 +334,58 @@ declare type RenderingContext_2 = z_2.infer<typeof renderingContextSchema>;
|
|
|
305
334
|
|
|
306
335
|
declare const renderingContextSchema: z_2.ZodDiscriminatedUnion<"entryPoint", [z_2.ZodObject<{
|
|
307
336
|
entryPoint: z_2.ZodLiteral<"createCard">;
|
|
308
|
-
defaultValues: z_2.ZodNullable<z_2.ZodObject<{
|
|
337
|
+
defaultValues: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodIntersection<z_2.ZodUnion<[z_2.ZodObject<{
|
|
309
338
|
firstName: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
310
339
|
lastName: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
311
340
|
phone: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
312
|
-
|
|
341
|
+
userId: z_2.ZodOptional<z_2.ZodUndefined>;
|
|
313
342
|
}, "strip", z_2.ZodTypeAny, {
|
|
314
343
|
firstName?: string | null | undefined;
|
|
315
344
|
lastName?: string | null | undefined;
|
|
316
345
|
phone?: string | null | undefined;
|
|
317
|
-
|
|
346
|
+
userId?: undefined;
|
|
318
347
|
}, {
|
|
319
348
|
firstName?: string | null | undefined;
|
|
320
349
|
lastName?: string | null | undefined;
|
|
321
350
|
phone?: string | null | undefined;
|
|
351
|
+
userId?: undefined;
|
|
352
|
+
}>, z_2.ZodObject<{
|
|
353
|
+
userId: z_2.ZodString;
|
|
354
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
355
|
+
userId: string;
|
|
356
|
+
}, {
|
|
357
|
+
userId: string;
|
|
358
|
+
}>]>, z_2.ZodObject<{
|
|
359
|
+
nickname: z_2.ZodOptional<z_2.ZodNullable<z_2.ZodString>>;
|
|
360
|
+
}, "strip", z_2.ZodTypeAny, {
|
|
361
|
+
nickname?: string | null | undefined;
|
|
362
|
+
}, {
|
|
322
363
|
nickname?: string | null | undefined;
|
|
323
|
-
}
|
|
364
|
+
}>>>>;
|
|
324
365
|
}, "strip", z_2.ZodTypeAny, {
|
|
325
366
|
entryPoint: "createCard";
|
|
326
|
-
defaultValues
|
|
367
|
+
defaultValues?: (({
|
|
327
368
|
firstName?: string | null | undefined;
|
|
328
369
|
lastName?: string | null | undefined;
|
|
329
370
|
phone?: string | null | undefined;
|
|
371
|
+
userId?: undefined;
|
|
372
|
+
} | {
|
|
373
|
+
userId: string;
|
|
374
|
+
}) & {
|
|
330
375
|
nickname?: string | null | undefined;
|
|
331
|
-
} | null;
|
|
376
|
+
}) | null | undefined;
|
|
332
377
|
}, {
|
|
333
378
|
entryPoint: "createCard";
|
|
334
|
-
defaultValues
|
|
379
|
+
defaultValues?: (({
|
|
335
380
|
firstName?: string | null | undefined;
|
|
336
381
|
lastName?: string | null | undefined;
|
|
337
382
|
phone?: string | null | undefined;
|
|
383
|
+
userId?: undefined;
|
|
384
|
+
} | {
|
|
385
|
+
userId: string;
|
|
386
|
+
}) & {
|
|
338
387
|
nickname?: string | null | undefined;
|
|
339
|
-
} | null;
|
|
388
|
+
}) | null | undefined;
|
|
340
389
|
}>, z_2.ZodObject<{
|
|
341
390
|
entryPoint: z_2.ZodLiteral<"createDispute">;
|
|
342
391
|
transactionId: z_2.ZodString;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";var
|
|
1
|
+
"use client";var H=Object.defineProperty,v=Object.defineProperties;var D=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var y=(e,t,o)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,a=(e,t)=>{for(var o in t||(t={}))L.call(t,o)&&y(e,o,t[o]);if(p)for(var o of p(t))b.call(t,o)&&y(e,o,t[o]);return e},l=(e,t)=>v(e,D(t));var u=(e,t)=>{var o={};for(var r in e)L.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&p)for(var r of p(e))t.indexOf(r)<0&&b.call(e,r)&&(o[r]=e[r]);return o};import h,{useMemo as P}from"react";import g,{useMemo as q,useRef as G,useState as K}from"react";var I=class extends Error{constructor(t){super(t),this.name="CapitalOSError"}},m=class extends I{constructor(){super("Invalid token"),this.name="CapitalOSInvalidTokenError"}};import{connectToChild as S}from"penpal";import{useEffect as w}from"react";var N=1e4;function F({iframeRef:e,token:t,onError:o,methods:r}){w(()=>{let n=S({iframe:e.current,childOrigin:"*",debug:!0,timeout:N,methods:r});return n.promise.catch(i=>{o==null||o(i)}),()=>{n.destroy()}},[t])}import{iframeResizer as A}from"iframe-resizer";import B,{forwardRef as W,useEffect as _,useImperativeHandle as j,useRef as J}from"react";var C=W((e,t)=>{let o=e.title||"iframe",{iframeHTMLAttributes:r,resizerOptions:n}=$(e),i=J(null);return _(()=>{let s=i.current;return A(a({},n),s),()=>s.iFrameResizer&&s.iFrameResizer.removeListeners()}),j(t,()=>i.current),B.createElement("iframe",l(a({},r),{title:o,ref:i}))});C.displayName="IframeResizer";var U=["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"],V=new Set(U);function $(e){return Object.keys(e).reduce((o,r)=>(V.has(r)?o.resizerOptions[r]=e[r]:o.iframeHTMLAttributes[r]=e[r],o),{resizerOptions:{},iframeHTMLAttributes:{}})}function z(e){let t=JSON.stringify(e),o=btoa(t);return encodeURIComponent(o)}function R(e){try{let t=decodeURIComponent(e),o=atob(t);return JSON.parse(o)}catch(t){throw new m}}function f(e){let{token:t,className:o,enableLogging:r,onError:n,loadingComponent:i,renderingContext:s,methods:c}=e,[T,M]=K(!1),x=G(null),k=q(()=>{try{let d=s?z(s):null,E=R(t),{path:O}=E;if(!O)throw new m;return`${O}?token=${t}&renderingContext=${d!=null?d:""}`}catch(d){n==null||n(new m);return}},[t,n]);return F({iframeRef:x,token:t,onError:d=>{n==null||n(d),M(!0)},methods:a({onLoad:()=>M(!0)},c)}),g.createElement(g.Fragment,null,!T&&i,g.createElement(C,{src:k,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:o,log:!!r,ref:x,hidden:!T}))}function ye(e){return h.createElement(f,a({},e))}function Le(n){var i=n,{defaultValues:e,onDone:t,onCancel:o}=i,r=u(i,["defaultValues","onDone","onCancel"]);let s="createCard",c=P(()=>({entryPoint:s,defaultValues:e}),[e]);return h.createElement(f,l(a({},r),{renderingContext:c,methods:{createCard:{onDone:t,onCancel:o}}}))}function be(n){var i=n,{transactionId:e,onDone:t,onCancel:o}=i,r=u(i,["transactionId","onDone","onCancel"]);let s="createDispute",c=P(()=>({entryPoint:s,transactionId:e}),[e]);return h.createElement(f,l(a({},r),{renderingContext:c,methods:{createDispute:{onDone:t,onCancel:o}}}))}export{ye as App,be as DisputeTransaction,Le as IssueCard};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.tsx","../../src/capital-os.tsx","../../src/error.ts","../../src/hooks.ts","../../src/iframe-resizer.tsx","../../src/utils.ts"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport type { CardApiDto, EntryPoint } from './external-types'\nimport type { CommonProps } from './types'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(props: CommonProps) {\n return <CapitalOS {...props} />\n}\n\nexport type IssueCardDefaultValues = {\n firstName?: string | undefined\n lastName?: string | undefined\n phone?: string | undefined\n nickname?: string | undefined\n}\n\nexport type IssueCardProps = CommonProps & {\n /**\n * Default values to prefill the form with.\n */\n defaultValues?: IssueCardDefaultValues\n\n /**\n * Callback to invoke when the card was created successfully.\n */\n onDone: (card: CardApiDto) => void\n\n /**\n * Callback to invoke when the card creation was cancelled by the user.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Issue Card experience.\n */\nexport function IssueCard({ defaultValues, onDone, onCancel, ...restOfProps }: IssueCardProps) {\n const entryPoint: EntryPoint = 'createCard'\n const renderingContext = useMemo(\n () => ({\n entryPoint,\n defaultValues: defaultValues,\n }),\n [defaultValues],\n )\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createCard: { onDone, onCancel } }} />\n )\n}\n\nexport type DisputeTransactionProps = CommonProps & {\n /**\n * The ID of the transaction to dispute.\n */\n transactionId: string\n\n /**\n * Callback to invoke when the dispute was successfully submitted.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the user cancels the dispute submission.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Dispute Transaction experience.\n */\nexport function DisputeTransaction({ transactionId, onDone, onCancel, ...restOfProps }: DisputeTransactionProps) {\n const entryPoint: EntryPoint = 'createDispute'\n const renderingContext = useMemo(() => ({ entryPoint, transactionId }), [transactionId])\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createDispute: { onDone, onCancel } }} />\n )\n}\n","import React, { useMemo, useRef, useState } from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeConnectionMethods, useIframeConnection } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps } from './types'\nimport { decodeToken, encodeRenderingContext } from './utils'\n\ntype CapitalOsProps<T> = CommonProps & {\n renderingContext?: T | undefined\n methods?: Partial<IframeConnectionMethods>\n}\n\n/**\n * The internal component that handles all the heavy lifting of connecting to the iframe and rendering the app.\n * all user facing components are basically a syntactic sugar on top of this.\n */\nexport function CapitalOS<T>(props: CapitalOsProps<T>) {\n const {\n token,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n } = props\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n // memoize the url based on the token so we don't redo the computation on each render.\n const url = useMemo(() => {\n try {\n const encodedRenderingContext = renderingContext ? encodeRenderingContext(renderingContext) : null\n\n const tokenObject = decodeToken(token)\n\n const { path } = tokenObject\n if (!path) {\n throw new InvalidTokenError()\n }\n return `${path}?token=${token}&renderingContext=${encodedRenderingContext ?? ''}`\n } catch (error) {\n // communicate a general error about the token being invalid to the parent component, no matter which internal error we encountered during token parsing.\n onError?.(new InvalidTokenError())\n return undefined\n }\n // renderingContext is not part of the dependencies since we do not want to reload the iframe unless the token changes.\n }, [token, onError])\n\n useIframeConnection({\n iframeRef,\n token,\n onError: (error) => {\n onError?.(error)\n // when connection fails it's probably a handshake timeout with the iframe. we will stop showing the loader\n // since the fact we failed communication doesn't necessarily mean the iframe didn't load\n setIsLoaded(true)\n },\n methods: { onLoad: () => setIsLoaded(true), ...methods },\n })\n\n return (\n <>\n {/* show loader as long as we're not loaded */}\n {!isLoaded && LoadingComponent}\n {/* hide the iframe as long as we're not loaded */}\n <IframeResizer\n src={url}\n allow=\"clipboard-write\"\n checkOrigin={false}\n style={{ width: '1px', height: '0px', minWidth: '100%' }}\n className={className}\n log={!!enableLogging}\n ref={iframeRef}\n hidden={!isLoaded}\n />\n </>\n )\n}\n","/**\n * Base class for all SDK errors\n */\nexport class CapitalOSError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'CapitalOSError'\n }\n}\n\n/**\n * Represents an error that occurs when an invalid token is encountered.\n */\nexport class InvalidTokenError extends CapitalOSError {\n constructor() {\n super('Invalid token')\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect } from 'react'\n\nimport type { CardApiDto } from './external-types'\n\nconst IFRAME_CONNECTION_TIMEOUT_MILLISECONDS = 10_000\n\nexport type IframeConnectionMethods = {\n onLoad: () => void\n createCard?: {\n onDone?: (card: CardApiDto) => void\n onCancel?: () => void\n }\n createDispute?: {\n onDone?: () => void\n onCancel?: () => void\n }\n}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\n const connection = connectToChild({\n iframe: iframeRef.current!,\n childOrigin: '*',\n debug: true,\n timeout: IFRAME_CONNECTION_TIMEOUT_MILLISECONDS,\n methods: methods,\n })\n\n connection.promise.catch((error) => {\n onError?.(error)\n })\n\n return () => {\n connection.destroy()\n }\n }, [token])\n}\n","import {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from 'react'\n\n// the events were renamed but package maintainers didn't update the types.\ntype IFrameOptions = Omit<\n BrokenIframeOptions,\n 'closedCallback' | 'scrollCallback' | 'resizedCallback' | 'messageCallback' | 'initCallback'\n> & {\n onClosed?(iframeId: string): void\n onInit?(iframe: IFrameComponent): void\n onMessage?(data: IFrameMessageData): void\n onResized?(data: IFrameResizedData): void\n onScroll?(data: IFrameScrollData): boolean\n}\n\ntype IframeResizerProps = IFrameOptions & IframeHTMLAttributes<HTMLIFrameElement>\ntype EnrichedHtmlIframeElement = HTMLIFrameElement & { iFrameResizer: { removeListeners: () => void } }\n\nexport const IframeResizer = forwardRef((props: IframeResizerProps, ref: React.Ref<HTMLIFrameElement>) => {\n const title = props.title || 'iframe'\n const { iframeHTMLAttributes, resizerOptions } = splitProps(props)\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n useEffect(() => {\n // effects run after render, so the ref is guaranteed to be set (unless the component conditionally renders the iframe, which is not the case)\n const iframe = iframeRef.current as EnrichedHtmlIframeElement\n\n iframeResizer({ ...resizerOptions }, iframe)\n\n return () => iframe.iFrameResizer && iframe.iFrameResizer.removeListeners()\n })\n\n // make the ref provided as a prop point to the same place as the internal iframe ref.\n useImperativeHandle(ref, () => iframeRef.current as HTMLIFrameElement)\n\n return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n})\n\nIframeResizer.displayName = 'IframeResizer'\n\nconst resizerOptions = [\n 'autoResize',\n 'bodyBackground',\n 'bodyMargin',\n 'bodyPadding',\n 'checkOrigin',\n 'inPageLinks',\n 'heightCalculationMethod',\n 'interval',\n 'log',\n 'maxHeight',\n 'maxWidth',\n 'minHeight',\n 'minWidth',\n 'resizeFrom',\n 'scrolling',\n 'sizeHeight',\n 'sizeWidth',\n 'warningTimeout',\n 'tolerance',\n 'widthCalculationMethod',\n 'onClosed',\n 'onInit',\n 'onMessage',\n 'onResized',\n 'onScroll',\n]\n\nconst resizerOptionsSet = new Set(resizerOptions)\n\n/**\n * split props into the resizer library options and the native iframe attributes.\n * the code is contains many type assertions because typescript doesn't handle reduce well.\n */\nfunction splitProps(props: IframeResizerProps) {\n const split = Object.keys(props).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n if (resizerOptionsSet.has(key)) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\n } else {\n acc.iframeHTMLAttributes[key as keyof IframeHTMLAttributes<HTMLIFrameElement>] =\n props[key as keyof typeof props]\n }\n return acc\n },\n { resizerOptions: {}, iframeHTMLAttributes: {} },\n )\n\n return split\n}\n","import { InvalidTokenError } from './error'\n\n/**\n * Encodes the rendering context as base64 and then URI encodes it.\n */\nexport function encodeRenderingContext<T>(renderingContext: NonNullable<T>) {\n const renderingContextJson = JSON.stringify(renderingContext)\n const renderingContextBase64 = btoa(renderingContextJson)\n const renderingContextEncoded = encodeURIComponent(renderingContextBase64)\n\n return renderingContextEncoded\n}\n\nexport function decodeToken(token: string) {\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n return JSON.parse(base64DecodedToken)\n } catch (error) {\n throw new InvalidTokenError()\n }\n}\n"],"mappings":"4lBAEA,OAAOA,GAAS,WAAAC,MAAe,QCF/B,OAAOC,GAAS,WAAAC,EAAS,UAAAC,EAAQ,YAAAC,MAAgB,QCG1C,IAAMC,EAAN,cAA6B,KAAM,CACxC,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb,KAAK,KAAO,gBACd,CACF,EAKaC,EAAN,cAAgCF,CAAe,CACpD,aAAc,CACZ,MAAM,eAAe,EACrB,KAAK,KAAO,4BACd,CACF,EClBA,OAAS,kBAAAG,MAAsB,SAC/B,OAAS,aAAAC,MAAiB,QAI1B,IAAMC,EAAyC,IAiBxC,SAASC,EAAoB,CAClC,UAAAC,EACA,MAAAC,EACA,QAAAC,EACA,QAAAC,CACF,EAKG,CAEDN,EAAU,IAAM,CACd,IAAMO,EAAaR,EAAe,CAChC,OAAQI,EAAU,QAClB,YAAa,IACb,MAAO,GACP,QAASF,EACT,Q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MAAO,CAAE,MAAO,MAAO,OAAQ,MAAO,SAAU,MAAO,EACvD,UAAWX,EACX,IAAK,CAAC,CAACC,EACP,IAAKQ,EACL,OAAQ,CAACH,EACX,CACF,CAEJ,CDtEO,SAASkB,GAAIC,EAAoB,CACtC,OAAOC,EAAA,cAACC,EAAAC,EAAA,GAAcH,EAAO,CAC/B,CA6BO,SAASI,GAAUC,EAAqE,CAArE,IAAAC,EAAAD,EAAE,eAAAE,EAAe,OAAAC,EAAQ,SAAAC,CA1CnD,EA0C0BH,EAAsCI,EAAAC,EAAtCL,EAAsC,CAApC,gBAAe,SAAQ,aACjD,IAAMM,EAAyB,aACzBC,EAAmBC,EACvB,KAAO,CACL,WAAAF,EACA,cAAeL,CACjB,GACA,CAACA,CAAa,CAChB,EAEA,OACEN,EAAA,cAACC,EAAAa,EAAAZ,EAAA,GAAcO,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,WAAY,CAAE,OAAAL,EAAQ,SAAAC,CAAS,CAAE,GAAG,CAEnH,CAsBO,SAASO,GAAmBX,EAA8E,CAA9E,IAAAC,EAAAD,EAAE,eAAAY,EAAe,OAAAT,EAAQ,SAAAC,CA7E5D,EA6EmCH,EAAsCI,EAAAC,EAAtCL,EAAsC,CAApC,gBAAe,SAAQ,aAC1D,IAAMM,EAAyB,gBACzBC,EAAmBC,EAAQ,KAAO,CAAE,WAAAF,EAAY,cAAAK,CAAc,GAAI,CAACA,CAAa,CAAC,EAEvF,OACEhB,EAAA,cAACC,EAAAa,EAAAZ,EAAA,GAAcO,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,cAAe,CAAE,OAAAL,EAAQ,SAAAC,CAAS,CAAE,GAAG,CAEtH","names":["React","useMemo","React","useMemo","useRef","useState","CapitalOSError","message","InvalidTokenError","connectToChild","useEffect","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","connection","error","iframeResizer","React","forwardRef","useEffect","useImperativeHandle","useRef","IframeResizer","forwardRef","props","ref","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","useRef","useEffect","iframe","iframeResizer","__spreadValues","useImperativeHandle","React","__spreadProps","resizerOptionsSet","acc","key","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","CapitalOS","props","token","className","enableLogging","onError","LoadingComponent","renderingContext","methods","isLoaded","setIsLoaded","useState","iframeRef","useRef","url","useMemo","encodedRenderingContext","encodeRenderingContext","tokenObject","decodeToken","path","InvalidTokenError","error","useIframeConnection","__spreadValues","React","IframeResizer","App","props","React","CapitalOS","__spreadValues","IssueCard","_a","_b","defaultValues","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","useMemo","__spreadProps","DisputeTransaction","transactionId"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.tsx","../../src/capital-os.tsx","../../src/error.ts","../../src/hooks.ts","../../src/iframe-resizer.tsx","../../src/utils.ts"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport type { EntryPoint, IssueCardDefaultValues } from './external-types'\nimport type { CommonProps } from './types'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(props: CommonProps) {\n return <CapitalOS {...props} />\n}\n\nexport type IssueCardProps = CommonProps & {\n /**\n * Default values to prefill the form with.\n *\n * Either provide a userId, in which case the default values will be taken from that user's profile, or provide the cardholder's details directly.\n */\n defaultValues?: IssueCardDefaultValues\n\n /**\n * Callback to invoke when the card was created successfully.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the card creation was cancelled by the user.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Issue Card experience.\n */\nexport function IssueCard({ defaultValues, onDone, onCancel, ...restOfProps }: IssueCardProps) {\n const entryPoint: EntryPoint = 'createCard'\n const renderingContext = useMemo(\n () => ({\n entryPoint,\n defaultValues: defaultValues,\n }),\n [defaultValues],\n )\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createCard: { onDone, onCancel } }} />\n )\n}\n\nexport type DisputeTransactionProps = CommonProps & {\n /**\n * The ID of the transaction to dispute.\n */\n transactionId: string\n\n /**\n * Callback to invoke when the dispute was successfully submitted.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the user cancels the dispute submission.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Dispute Transaction experience.\n */\nexport function DisputeTransaction({ transactionId, onDone, onCancel, ...restOfProps }: DisputeTransactionProps) {\n const entryPoint: EntryPoint = 'createDispute'\n const renderingContext = useMemo(() => ({ entryPoint, transactionId }), [transactionId])\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createDispute: { onDone, onCancel } }} />\n )\n}\n","import React, { useMemo, useRef, useState } from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeConnectionMethods, useIframeConnection } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps } from './types'\nimport { decodeToken, encodeRenderingContext } from './utils'\n\ntype CapitalOsProps<T> = CommonProps & {\n renderingContext?: T | undefined\n methods?: Partial<IframeConnectionMethods>\n}\n\n/**\n * The internal component that handles all the heavy lifting of connecting to the iframe and rendering the app.\n * all user facing components are basically a syntactic sugar on top of this.\n */\nexport function CapitalOS<T>(props: CapitalOsProps<T>) {\n const {\n token,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n } = props\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n // memoize the url based on the token so we don't redo the computation on each render.\n const url = useMemo(() => {\n try {\n const encodedRenderingContext = renderingContext ? encodeRenderingContext(renderingContext) : null\n\n const tokenObject = decodeToken(token)\n\n const { path } = tokenObject\n if (!path) {\n throw new InvalidTokenError()\n }\n return `${path}?token=${token}&renderingContext=${encodedRenderingContext ?? ''}`\n } catch (error) {\n // communicate a general error about the token being invalid to the parent component, no matter which internal error we encountered during token parsing.\n onError?.(new InvalidTokenError())\n return undefined\n }\n // renderingContext is not part of the dependencies since we do not want to reload the iframe unless the token changes.\n }, [token, onError])\n\n useIframeConnection({\n iframeRef,\n token,\n onError: (error) => {\n onError?.(error)\n // when connection fails it's probably a handshake timeout with the iframe. we will stop showing the loader\n // since the fact we failed communication doesn't necessarily mean the iframe didn't load\n setIsLoaded(true)\n },\n methods: { onLoad: () => setIsLoaded(true), ...methods },\n })\n\n return (\n <>\n {/* show loader as long as we're not loaded */}\n {!isLoaded && LoadingComponent}\n {/* hide the iframe as long as we're not loaded */}\n <IframeResizer\n src={url}\n allow=\"clipboard-write\"\n checkOrigin={false}\n style={{ width: '1px', height: '0px', minWidth: '100%' }}\n className={className}\n log={!!enableLogging}\n ref={iframeRef}\n hidden={!isLoaded}\n />\n </>\n )\n}\n","/**\n * Base class for all SDK errors\n */\nexport class CapitalOSError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'CapitalOSError'\n }\n}\n\n/**\n * Represents an error that occurs when an invalid token is encountered.\n */\nexport class InvalidTokenError extends CapitalOSError {\n constructor() {\n super('Invalid token')\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect } from 'react'\n\nconst IFRAME_CONNECTION_TIMEOUT_MILLISECONDS = 10_000\n\nexport type IframeConnectionMethods = {\n onLoad: () => void\n createCard?: {\n onDone?: () => void\n onCancel?: () => void\n }\n createDispute?: {\n onDone?: () => void\n onCancel?: () => void\n }\n}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\n const connection = connectToChild({\n iframe: iframeRef.current!,\n childOrigin: '*',\n debug: true,\n timeout: IFRAME_CONNECTION_TIMEOUT_MILLISECONDS,\n methods: methods,\n })\n\n connection.promise.catch((error) => {\n onError?.(error)\n })\n\n return () => {\n connection.destroy()\n }\n }, [token])\n}\n","import {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from 'react'\n\n// the events were renamed but package maintainers didn't update the types.\ntype IFrameOptions = Omit<\n BrokenIframeOptions,\n 'closedCallback' | 'scrollCallback' | 'resizedCallback' | 'messageCallback' | 'initCallback'\n> & {\n onClosed?(iframeId: string): void\n onInit?(iframe: IFrameComponent): void\n onMessage?(data: IFrameMessageData): void\n onResized?(data: IFrameResizedData): void\n onScroll?(data: IFrameScrollData): boolean\n}\n\ntype IframeResizerProps = IFrameOptions & IframeHTMLAttributes<HTMLIFrameElement>\ntype EnrichedHtmlIframeElement = HTMLIFrameElement & { iFrameResizer: { removeListeners: () => void } }\n\nexport const IframeResizer = forwardRef((props: IframeResizerProps, ref: React.Ref<HTMLIFrameElement>) => {\n const title = props.title || 'iframe'\n const { iframeHTMLAttributes, resizerOptions } = splitProps(props)\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n useEffect(() => {\n // effects run after render, so the ref is guaranteed to be set (unless the component conditionally renders the iframe, which is not the case)\n const iframe = iframeRef.current as EnrichedHtmlIframeElement\n\n iframeResizer({ ...resizerOptions }, iframe)\n\n return () => iframe.iFrameResizer && iframe.iFrameResizer.removeListeners()\n })\n\n // make the ref provided as a prop point to the same place as the internal iframe ref.\n useImperativeHandle(ref, () => iframeRef.current as HTMLIFrameElement)\n\n return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n})\n\nIframeResizer.displayName = 'IframeResizer'\n\nconst resizerOptions = [\n 'autoResize',\n 'bodyBackground',\n 'bodyMargin',\n 'bodyPadding',\n 'checkOrigin',\n 'inPageLinks',\n 'heightCalculationMethod',\n 'interval',\n 'log',\n 'maxHeight',\n 'maxWidth',\n 'minHeight',\n 'minWidth',\n 'resizeFrom',\n 'scrolling',\n 'sizeHeight',\n 'sizeWidth',\n 'warningTimeout',\n 'tolerance',\n 'widthCalculationMethod',\n 'onClosed',\n 'onInit',\n 'onMessage',\n 'onResized',\n 'onScroll',\n]\n\nconst resizerOptionsSet = new Set(resizerOptions)\n\n/**\n * split props into the resizer library options and the native iframe attributes.\n * the code is contains many type assertions because typescript doesn't handle reduce well.\n */\nfunction splitProps(props: IframeResizerProps) {\n const split = Object.keys(props).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n if (resizerOptionsSet.has(key)) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\n } else {\n acc.iframeHTMLAttributes[key as keyof IframeHTMLAttributes<HTMLIFrameElement>] =\n props[key as keyof typeof props]\n }\n return acc\n },\n { resizerOptions: {}, iframeHTMLAttributes: {} },\n )\n\n return split\n}\n","import { InvalidTokenError } from './error'\n\n/**\n * Encodes the rendering context as base64 and then URI encodes it.\n */\nexport function encodeRenderingContext<T>(renderingContext: NonNullable<T>) {\n const renderingContextJson = JSON.stringify(renderingContext)\n const renderingContextBase64 = btoa(renderingContextJson)\n const renderingContextEncoded = encodeURIComponent(renderingContextBase64)\n\n return renderingContextEncoded\n}\n\nexport function decodeToken(token: string) {\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n return JSON.parse(base64DecodedToken)\n } catch (error) {\n throw new InvalidTokenError()\n }\n}\n"],"mappings":"4lBAEA,OAAOA,GAAS,WAAAC,MAAe,QCF/B,OAAOC,GAAS,WAAAC,EAAS,UAAAC,EAAQ,YAAAC,MAAgB,QCG1C,IAAMC,EAAN,cAA6B,KAAM,CACxC,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb,KAAK,K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AAAK,CAAc,GAAI,CAACA,CAAa,CAAC,EAEvF,OACEhB,EAAA,cAACC,EAAAa,EAAAZ,EAAA,GAAcO,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,cAAe,CAAE,OAAAL,EAAQ,SAAAC,CAAS,CAAE,GAAG,CAEtH","names":["React","useMemo","React","useMemo","useRef","useState","CapitalOSError","message","InvalidTokenError","connectToChild","useEffect","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","connection","error","iframeResizer","React","forwardRef","useEffect","useImperativeHandle","useRef","IframeResizer","forwardRef","props","ref","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","useRef","useEffect","iframe","iframeResizer","__spreadValues","useImperativeHandle","React","__spreadProps","resizerOptionsSet","acc","key","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","CapitalOS","props","token","className","enableLogging","onError","LoadingComponent","renderingContext","methods","isLoaded","setIsLoaded","useState","iframeRef","useRef","url","useMemo","encodedRenderingContext","encodeRenderingContext","tokenObject","decodeToken","path","InvalidTokenError","error","useIframeConnection","__spreadValues","React","IframeResizer","App","props","React","CapitalOS","__spreadValues","IssueCard","_a","_b","defaultValues","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","useMemo","__spreadProps","DisputeTransaction","transactionId"]}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var A=Object.create;var u=Object.defineProperty,B=Object.defineProperties,W=Object.getOwnPropertyDescriptor,_=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertyNames,C=Object.getOwnPropertySymbols,J=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var z=(e,t,o)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,d=(e,t)=>{for(var o in t||(t={}))h.call(t,o)&&z(e,o,t[o]);if(C)for(var o of C(t))R.call(t,o)&&z(e,o,t[o]);return e},I=(e,t)=>B(e,_(t));var T=(e,t)=>{var o={};for(var r in e)h.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&C)for(var r of C(e))t.indexOf(r)<0&&R.call(e,r)&&(o[r]=e[r]);return o};var U=(e,t)=>{for(var o in t)u(e,o,{get:t[o],enumerable:!0})},P=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of j(t))!h.call(e,n)&&n!==o&&u(e,n,{get:()=>t[n],enumerable:!(r=W(t,n))||r.enumerable});return e};var M=(e,t,o)=>(o=e!=null?A(J(e)):{},P(t||!e||!e.__esModule?u(o,"default",{value:e,enumerable:!0}):o,e)),V=e=>P(u({},"__esModule",{value:!0}),e);var Z={};U(Z,{App:()=>Q,DisputeTransaction:()=>Y,IssueCard:()=>X});module.exports=V(Z);var l=M(require("react"));var m=M(require("react"));var x=class extends Error{constructor(t){super(t),this.name="CapitalOSError"}},c=class extends x{constructor(){super("Invalid token"),this.name="CapitalOSInvalidTokenError"}};var k=require("penpal"),E=require("react"),$=1e4;function H({iframeRef:e,token:t,onError:o,methods:r}){(0,E.useEffect)(()=>{let n=(0,k.connectToChild)({iframe:e.current,childOrigin:"*",debug:!0,timeout:$,methods:r});return n.promise.catch(i=>{o==null||o(i)}),()=>{n.destroy()}},[t])}var v=require("iframe-resizer"),a=M(require("react"));var O=(0,a.forwardRef)((e,t)=>{let o=e.title||"iframe",{iframeHTMLAttributes:r,resizerOptions:n}=K(e),i=(0,a.useRef)(null);return(0,a.useEffect)(()=>{let s=i.current;return(0,v.iframeResizer)(d({},n),s),()=>s.iFrameResizer&&s.iFrameResizer.removeListeners()}),(0,a.useImperativeHandle)(t,()=>i.current),a.default.createElement("iframe",I(d({},r),{title:o,ref:i}))});O.displayName="IframeResizer";var q=["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"],G=new Set(q);function K(e){return Object.keys(e).reduce((o,r)=>(G.has(r)?o.resizerOptions[r]=e[r]:o.iframeHTMLAttributes[r]=e[r],o),{resizerOptions:{},iframeHTMLAttributes:{}})}function D(e){let t=JSON.stringify(e),o=btoa(t);return encodeURIComponent(o)}function S(e){try{let t=decodeURIComponent(e),o=atob(t);return JSON.parse(o)}catch(t){throw new c}}function g(e){let{token:t,className:o,enableLogging:r,onError:n,loadingComponent:i,renderingContext:s,methods:f}=e,[y,L]=(0,m.useState)(!1),b=(0,m.useRef)(null),w=(0,m.useMemo)(()=>{try{let p=s?D(s):null,N=S(t),{path:F}=N;if(!F)throw new c;return`${F}?token=${t}&renderingContext=${p!=null?p:""}`}catch(p){n==null||n(new c);return}},[t,n]);return H({iframeRef:b,token:t,onError:p=>{n==null||n(p),L(!0)},methods:d({onLoad:()=>L(!0)},f)}),m.default.createElement(m.default.Fragment,null,!y&&i,m.default.createElement(O,{src:w,allow:"clipboard-write",checkOrigin:!1,style:{width:"1px",height:"0px",minWidth:"100%"},className:o,log:!!r,ref:b,hidden:!y}))}function Q(e){return l.default.createElement(g,d({},e))}function X(n){var i=n,{defaultValues:e,onDone:t,onCancel:o}=i,r=T(i,["defaultValues","onDone","onCancel"]);let s="createCard",f=(0,l.useMemo)(()=>({entryPoint:s,defaultValues:e}),[e]);return l.default.createElement(g,I(d({},r),{renderingContext:f,methods:{createCard:{onDone:t,onCancel:o}}}))}function Y(n){var i=n,{transactionId:e,onDone:t,onCancel:o}=i,r=T(i,["transactionId","onDone","onCancel"]);let s="createDispute",f=(0,l.useMemo)(()=>({entryPoint:s,transactionId:e}),[e]);return l.default.createElement(g,I(d({},r),{renderingContext:f,methods:{createDispute:{onDone:t,onCancel:o}}}))}0&&(module.exports={App,DisputeTransaction,IssueCard});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx","../src/capital-os.tsx","../src/error.ts","../src/hooks.ts","../src/iframe-resizer.tsx","../src/utils.ts"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport type { CardApiDto, EntryPoint } from './external-types'\nimport type { CommonProps } from './types'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(props: CommonProps) {\n return <CapitalOS {...props} />\n}\n\nexport type IssueCardDefaultValues = {\n firstName?: string | undefined\n lastName?: string | undefined\n phone?: string | undefined\n nickname?: string | undefined\n}\n\nexport type IssueCardProps = CommonProps & {\n /**\n * Default values to prefill the form with.\n */\n defaultValues?: IssueCardDefaultValues\n\n /**\n * Callback to invoke when the card was created successfully.\n */\n onDone: (card: CardApiDto) => void\n\n /**\n * Callback to invoke when the card creation was cancelled by the user.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Issue Card experience.\n */\nexport function IssueCard({ defaultValues, onDone, onCancel, ...restOfProps }: IssueCardProps) {\n const entryPoint: EntryPoint = 'createCard'\n const renderingContext = useMemo(\n () => ({\n entryPoint,\n defaultValues: defaultValues,\n }),\n [defaultValues],\n )\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createCard: { onDone, onCancel } }} />\n )\n}\n\nexport type DisputeTransactionProps = CommonProps & {\n /**\n * The ID of the transaction to dispute.\n */\n transactionId: string\n\n /**\n * Callback to invoke when the dispute was successfully submitted.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the user cancels the dispute submission.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Dispute Transaction experience.\n */\nexport function DisputeTransaction({ transactionId, onDone, onCancel, ...restOfProps }: DisputeTransactionProps) {\n const entryPoint: EntryPoint = 'createDispute'\n const renderingContext = useMemo(() => ({ entryPoint, transactionId }), [transactionId])\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createDispute: { onDone, onCancel } }} />\n )\n}\n","import React, { useMemo, useRef, useState } from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeConnectionMethods, useIframeConnection } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps } from './types'\nimport { decodeToken, encodeRenderingContext } from './utils'\n\ntype CapitalOsProps<T> = CommonProps & {\n renderingContext?: T | undefined\n methods?: Partial<IframeConnectionMethods>\n}\n\n/**\n * The internal component that handles all the heavy lifting of connecting to the iframe and rendering the app.\n * all user facing components are basically a syntactic sugar on top of this.\n */\nexport function CapitalOS<T>(props: CapitalOsProps<T>) {\n const {\n token,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n } = props\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n // memoize the url based on the token so we don't redo the computation on each render.\n const url = useMemo(() => {\n try {\n const encodedRenderingContext = renderingContext ? encodeRenderingContext(renderingContext) : null\n\n const tokenObject = decodeToken(token)\n\n const { path } = tokenObject\n if (!path) {\n throw new InvalidTokenError()\n }\n return `${path}?token=${token}&renderingContext=${encodedRenderingContext ?? ''}`\n } catch (error) {\n // communicate a general error about the token being invalid to the parent component, no matter which internal error we encountered during token parsing.\n onError?.(new InvalidTokenError())\n return undefined\n }\n // renderingContext is not part of the dependencies since we do not want to reload the iframe unless the token changes.\n }, [token, onError])\n\n useIframeConnection({\n iframeRef,\n token,\n onError: (error) => {\n onError?.(error)\n // when connection fails it's probably a handshake timeout with the iframe. we will stop showing the loader\n // since the fact we failed communication doesn't necessarily mean the iframe didn't load\n setIsLoaded(true)\n },\n methods: { onLoad: () => setIsLoaded(true), ...methods },\n })\n\n return (\n <>\n {/* show loader as long as we're not loaded */}\n {!isLoaded && LoadingComponent}\n {/* hide the iframe as long as we're not loaded */}\n <IframeResizer\n src={url}\n allow=\"clipboard-write\"\n checkOrigin={false}\n style={{ width: '1px', height: '0px', minWidth: '100%' }}\n className={className}\n log={!!enableLogging}\n ref={iframeRef}\n hidden={!isLoaded}\n />\n </>\n )\n}\n","/**\n * Base class for all SDK errors\n */\nexport class CapitalOSError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'CapitalOSError'\n }\n}\n\n/**\n * Represents an error that occurs when an invalid token is encountered.\n */\nexport class InvalidTokenError extends CapitalOSError {\n constructor() {\n super('Invalid token')\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect } from 'react'\n\nimport type { CardApiDto } from './external-types'\n\nconst IFRAME_CONNECTION_TIMEOUT_MILLISECONDS = 10_000\n\nexport type IframeConnectionMethods = {\n onLoad: () => void\n createCard?: {\n onDone?: (card: CardApiDto) => void\n onCancel?: () => void\n }\n createDispute?: {\n onDone?: () => void\n onCancel?: () => void\n }\n}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\n const connection = connectToChild({\n iframe: iframeRef.current!,\n childOrigin: '*',\n debug: true,\n timeout: IFRAME_CONNECTION_TIMEOUT_MILLISECONDS,\n methods: methods,\n })\n\n connection.promise.catch((error) => {\n onError?.(error)\n })\n\n return () => {\n connection.destroy()\n }\n }, [token])\n}\n","import {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from 'react'\n\n// the events were renamed but package maintainers didn't update the types.\ntype IFrameOptions = Omit<\n BrokenIframeOptions,\n 'closedCallback' | 'scrollCallback' | 'resizedCallback' | 'messageCallback' | 'initCallback'\n> & {\n onClosed?(iframeId: string): void\n onInit?(iframe: IFrameComponent): void\n onMessage?(data: IFrameMessageData): void\n onResized?(data: IFrameResizedData): void\n onScroll?(data: IFrameScrollData): boolean\n}\n\ntype IframeResizerProps = IFrameOptions & IframeHTMLAttributes<HTMLIFrameElement>\ntype EnrichedHtmlIframeElement = HTMLIFrameElement & { iFrameResizer: { removeListeners: () => void } }\n\nexport const IframeResizer = forwardRef((props: IframeResizerProps, ref: React.Ref<HTMLIFrameElement>) => {\n const title = props.title || 'iframe'\n const { iframeHTMLAttributes, resizerOptions } = splitProps(props)\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n useEffect(() => {\n // effects run after render, so the ref is guaranteed to be set (unless the component conditionally renders the iframe, which is not the case)\n const iframe = iframeRef.current as EnrichedHtmlIframeElement\n\n iframeResizer({ ...resizerOptions }, iframe)\n\n return () => iframe.iFrameResizer && iframe.iFrameResizer.removeListeners()\n })\n\n // make the ref provided as a prop point to the same place as the internal iframe ref.\n useImperativeHandle(ref, () => iframeRef.current as HTMLIFrameElement)\n\n return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n})\n\nIframeResizer.displayName = 'IframeResizer'\n\nconst resizerOptions = [\n 'autoResize',\n 'bodyBackground',\n 'bodyMargin',\n 'bodyPadding',\n 'checkOrigin',\n 'inPageLinks',\n 'heightCalculationMethod',\n 'interval',\n 'log',\n 'maxHeight',\n 'maxWidth',\n 'minHeight',\n 'minWidth',\n 'resizeFrom',\n 'scrolling',\n 'sizeHeight',\n 'sizeWidth',\n 'warningTimeout',\n 'tolerance',\n 'widthCalculationMethod',\n 'onClosed',\n 'onInit',\n 'onMessage',\n 'onResized',\n 'onScroll',\n]\n\nconst resizerOptionsSet = new Set(resizerOptions)\n\n/**\n * split props into the resizer library options and the native iframe attributes.\n * the code is contains many type assertions because typescript doesn't handle reduce well.\n */\nfunction splitProps(props: IframeResizerProps) {\n const split = Object.keys(props).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n if (resizerOptionsSet.has(key)) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\n } else {\n acc.iframeHTMLAttributes[key as keyof IframeHTMLAttributes<HTMLIFrameElement>] =\n props[key as keyof typeof props]\n }\n return acc\n },\n { resizerOptions: {}, iframeHTMLAttributes: {} },\n )\n\n return split\n}\n","import { InvalidTokenError } from './error'\n\n/**\n * Encodes the rendering context as base64 and then URI encodes it.\n */\nexport function encodeRenderingContext<T>(renderingContext: NonNullable<T>) {\n const renderingContextJson = JSON.stringify(renderingContext)\n const renderingContextBase64 = btoa(renderingContextJson)\n const renderingContextEncoded = encodeURIComponent(renderingContextBase64)\n\n return renderingContextEncoded\n}\n\nexport function decodeToken(token: string) {\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n return JSON.parse(base64DecodedToken)\n } catch (error) {\n throw new InvalidTokenError()\n }\n}\n"],"mappings":"gkCAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,EAAA,uBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAL,GAEA,IAAAM,EAA+B,oBCF/B,IAAAC,EAAiD,oBCG1C,IAAMC,EAAN,cAA6B,KAAM,CACxC,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb,KAAK,KAAO,gBACd,CACF,EAKaC,EAAN,cAAgCF,CAAe,CACpD,aAAc,CACZ,MAAM,eAAe,EACrB,KAAK,KAAO,4BACd,CACF,EClBA,IAAAG,EAA+B,kBAC/BC,EAA0B,iBAIpBC,EAAyC,IAiBxC,SAASC,EAAoB,CAClC,UAAAC,EACA,MAAAC,EACA,QAAAC,EACA,QAAAC,CACF,EAKG,IAED,aAAU,IAAM,CACd,IAAMC,KAAa,kBAAe,CAChC,OAAQJ,EAAU,QAClB,YAAa,IACb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AAWT,EACX,IAAK,CAAC,CAACC,EACP,IAAKO,EACL,OAAQ,CAACF,EACX,CACF,CAEJ,CDtEO,SAASe,EAAIC,EAAoB,CACtC,OAAO,EAAAC,QAAA,cAACC,EAAAC,EAAA,GAAcH,EAAO,CAC/B,CA6BO,SAASI,EAAUC,EAAqE,CAArE,IAAAC,EAAAD,EAAE,eAAAE,EAAe,OAAAC,EAAQ,SAAAC,CA1CnD,EA0C0BH,EAAsCI,EAAAC,EAAtCL,EAAsC,CAApC,gBAAe,SAAQ,aACjD,IAAMM,EAAyB,aACzBC,KAAmB,WACvB,KAAO,CACL,WAAAD,EACA,cAAeL,CACjB,GACA,CAACA,CAAa,CAChB,EAEA,OACE,EAAAN,QAAA,cAACC,EAAAY,EAAAX,EAAA,GAAcO,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,WAAY,CAAE,OAAAL,EAAQ,SAAAC,CAAS,CAAE,GAAG,CAEnH,CAsBO,SAASM,EAAmBV,EAA8E,CAA9E,IAAAC,EAAAD,EAAE,eAAAW,EAAe,OAAAR,EAAQ,SAAAC,CA7E5D,EA6EmCH,EAAsCI,EAAAC,EAAtCL,EAAsC,CAApC,gBAAe,SAAQ,aAC1D,IAAMM,EAAyB,gBACzBC,KAAmB,WAAQ,KAAO,CAAE,WAAAD,EAAY,cAAAI,CAAc,GAAI,CAACA,CAAa,CAAC,EAEvF,OACE,EAAAf,QAAA,cAACC,EAAAY,EAAAX,EAAA,GAAcO,GAAd,CAA2B,iBAAkBG,EAAkB,QAAS,CAAE,cAAe,CAAE,OAAAL,EAAQ,SAAAC,CAAS,CAAE,GAAG,CAEtH","names":["src_exports","__export","App","DisputeTransaction","IssueCard","__toCommonJS","import_react","import_react","CapitalOSError","message","InvalidTokenError","import_penpal","import_react","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","connection","error","import_iframe_resizer","import_react","IframeResizer","props","ref","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","iframe","__spreadValues","React","__spreadProps","resizerOptionsSet","acc","key","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","CapitalOS","props","token","className","enableLogging","onError","LoadingComponent","renderingContext","methods","isLoaded","setIsLoaded","iframeRef","url","encodedRenderingContext","encodeRenderingContext","tokenObject","decodeToken","path","InvalidTokenError","error","useIframeConnection","__spreadValues","React","IframeResizer","App","props","React","CapitalOS","__spreadValues","IssueCard","_a","_b","defaultValues","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","__spreadProps","DisputeTransaction","transactionId"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx","../src/capital-os.tsx","../src/error.ts","../src/hooks.ts","../src/iframe-resizer.tsx","../src/utils.ts"],"sourcesContent":["'use client'\n\nimport React, { useMemo } from 'react'\n\nimport { CapitalOS } from './capital-os'\nimport type { EntryPoint, IssueCardDefaultValues } from './external-types'\nimport type { CommonProps } from './types'\n\n/**\n * Renders the CapitalOS App.\n */\nexport function App(props: CommonProps) {\n return <CapitalOS {...props} />\n}\n\nexport type IssueCardProps = CommonProps & {\n /**\n * Default values to prefill the form with.\n *\n * Either provide a userId, in which case the default values will be taken from that user's profile, or provide the cardholder's details directly.\n */\n defaultValues?: IssueCardDefaultValues\n\n /**\n * Callback to invoke when the card was created successfully.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the card creation was cancelled by the user.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Issue Card experience.\n */\nexport function IssueCard({ defaultValues, onDone, onCancel, ...restOfProps }: IssueCardProps) {\n const entryPoint: EntryPoint = 'createCard'\n const renderingContext = useMemo(\n () => ({\n entryPoint,\n defaultValues: defaultValues,\n }),\n [defaultValues],\n )\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createCard: { onDone, onCancel } }} />\n )\n}\n\nexport type DisputeTransactionProps = CommonProps & {\n /**\n * The ID of the transaction to dispute.\n */\n transactionId: string\n\n /**\n * Callback to invoke when the dispute was successfully submitted.\n */\n onDone: () => void\n\n /**\n * Callback to invoke when the user cancels the dispute submission.\n */\n onCancel: () => void\n}\n\n/**\n * Renders the CapitalOS Dispute Transaction experience.\n */\nexport function DisputeTransaction({ transactionId, onDone, onCancel, ...restOfProps }: DisputeTransactionProps) {\n const entryPoint: EntryPoint = 'createDispute'\n const renderingContext = useMemo(() => ({ entryPoint, transactionId }), [transactionId])\n\n return (\n <CapitalOS {...restOfProps} renderingContext={renderingContext} methods={{ createDispute: { onDone, onCancel } }} />\n )\n}\n","import React, { useMemo, useRef, useState } from 'react'\n\nimport { InvalidTokenError } from './error'\nimport { IframeConnectionMethods, useIframeConnection } from './hooks'\nimport { IframeResizer } from './iframe-resizer'\nimport { CommonProps } from './types'\nimport { decodeToken, encodeRenderingContext } from './utils'\n\ntype CapitalOsProps<T> = CommonProps & {\n renderingContext?: T | undefined\n methods?: Partial<IframeConnectionMethods>\n}\n\n/**\n * The internal component that handles all the heavy lifting of connecting to the iframe and rendering the app.\n * all user facing components are basically a syntactic sugar on top of this.\n */\nexport function CapitalOS<T>(props: CapitalOsProps<T>) {\n const {\n token,\n className,\n enableLogging,\n onError,\n loadingComponent: LoadingComponent,\n renderingContext,\n methods,\n } = props\n // represents the state of whether all required react queries returned and the page should be visible\n const [isLoaded, setIsLoaded] = useState(false)\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n // memoize the url based on the token so we don't redo the computation on each render.\n const url = useMemo(() => {\n try {\n const encodedRenderingContext = renderingContext ? encodeRenderingContext(renderingContext) : null\n\n const tokenObject = decodeToken(token)\n\n const { path } = tokenObject\n if (!path) {\n throw new InvalidTokenError()\n }\n return `${path}?token=${token}&renderingContext=${encodedRenderingContext ?? ''}`\n } catch (error) {\n // communicate a general error about the token being invalid to the parent component, no matter which internal error we encountered during token parsing.\n onError?.(new InvalidTokenError())\n return undefined\n }\n // renderingContext is not part of the dependencies since we do not want to reload the iframe unless the token changes.\n }, [token, onError])\n\n useIframeConnection({\n iframeRef,\n token,\n onError: (error) => {\n onError?.(error)\n // when connection fails it's probably a handshake timeout with the iframe. we will stop showing the loader\n // since the fact we failed communication doesn't necessarily mean the iframe didn't load\n setIsLoaded(true)\n },\n methods: { onLoad: () => setIsLoaded(true), ...methods },\n })\n\n return (\n <>\n {/* show loader as long as we're not loaded */}\n {!isLoaded && LoadingComponent}\n {/* hide the iframe as long as we're not loaded */}\n <IframeResizer\n src={url}\n allow=\"clipboard-write\"\n checkOrigin={false}\n style={{ width: '1px', height: '0px', minWidth: '100%' }}\n className={className}\n log={!!enableLogging}\n ref={iframeRef}\n hidden={!isLoaded}\n />\n </>\n )\n}\n","/**\n * Base class for all SDK errors\n */\nexport class CapitalOSError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'CapitalOSError'\n }\n}\n\n/**\n * Represents an error that occurs when an invalid token is encountered.\n */\nexport class InvalidTokenError extends CapitalOSError {\n constructor() {\n super('Invalid token')\n this.name = 'CapitalOSInvalidTokenError'\n }\n}\n","import { connectToChild } from 'penpal'\nimport { useEffect } from 'react'\n\nconst IFRAME_CONNECTION_TIMEOUT_MILLISECONDS = 10_000\n\nexport type IframeConnectionMethods = {\n onLoad: () => void\n createCard?: {\n onDone?: () => void\n onCancel?: () => void\n }\n createDispute?: {\n onDone?: () => void\n onCancel?: () => void\n }\n}\n\n/**\n * connects to child iframe and returns whether the iframe is loaded or not.\n */\nexport function useIframeConnection({\n iframeRef,\n token,\n onError,\n methods,\n}: {\n iframeRef: React.RefObject<HTMLIFrameElement>\n token: string\n onError: ((error: Error) => void) | undefined | null\n methods: IframeConnectionMethods\n}) {\n // connect to child iframe\n useEffect(() => {\n const connection = connectToChild({\n iframe: iframeRef.current!,\n childOrigin: '*',\n debug: true,\n timeout: IFRAME_CONNECTION_TIMEOUT_MILLISECONDS,\n methods: methods,\n })\n\n connection.promise.catch((error) => {\n onError?.(error)\n })\n\n return () => {\n connection.destroy()\n }\n }, [token])\n}\n","import {\n IFrameOptions as BrokenIframeOptions,\n IFrameComponent,\n IFrameMessageData,\n IFrameResizedData,\n IFrameScrollData,\n iframeResizer,\n} from 'iframe-resizer'\nimport React, { IframeHTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from 'react'\n\n// the events were renamed but package maintainers didn't update the types.\ntype IFrameOptions = Omit<\n BrokenIframeOptions,\n 'closedCallback' | 'scrollCallback' | 'resizedCallback' | 'messageCallback' | 'initCallback'\n> & {\n onClosed?(iframeId: string): void\n onInit?(iframe: IFrameComponent): void\n onMessage?(data: IFrameMessageData): void\n onResized?(data: IFrameResizedData): void\n onScroll?(data: IFrameScrollData): boolean\n}\n\ntype IframeResizerProps = IFrameOptions & IframeHTMLAttributes<HTMLIFrameElement>\ntype EnrichedHtmlIframeElement = HTMLIFrameElement & { iFrameResizer: { removeListeners: () => void } }\n\nexport const IframeResizer = forwardRef((props: IframeResizerProps, ref: React.Ref<HTMLIFrameElement>) => {\n const title = props.title || 'iframe'\n const { iframeHTMLAttributes, resizerOptions } = splitProps(props)\n const iframeRef = useRef<HTMLIFrameElement>(null)\n\n useEffect(() => {\n // effects run after render, so the ref is guaranteed to be set (unless the component conditionally renders the iframe, which is not the case)\n const iframe = iframeRef.current as EnrichedHtmlIframeElement\n\n iframeResizer({ ...resizerOptions }, iframe)\n\n return () => iframe.iFrameResizer && iframe.iFrameResizer.removeListeners()\n })\n\n // make the ref provided as a prop point to the same place as the internal iframe ref.\n useImperativeHandle(ref, () => iframeRef.current as HTMLIFrameElement)\n\n return <iframe {...iframeHTMLAttributes} title={title} ref={iframeRef} />\n})\n\nIframeResizer.displayName = 'IframeResizer'\n\nconst resizerOptions = [\n 'autoResize',\n 'bodyBackground',\n 'bodyMargin',\n 'bodyPadding',\n 'checkOrigin',\n 'inPageLinks',\n 'heightCalculationMethod',\n 'interval',\n 'log',\n 'maxHeight',\n 'maxWidth',\n 'minHeight',\n 'minWidth',\n 'resizeFrom',\n 'scrolling',\n 'sizeHeight',\n 'sizeWidth',\n 'warningTimeout',\n 'tolerance',\n 'widthCalculationMethod',\n 'onClosed',\n 'onInit',\n 'onMessage',\n 'onResized',\n 'onScroll',\n]\n\nconst resizerOptionsSet = new Set(resizerOptions)\n\n/**\n * split props into the resizer library options and the native iframe attributes.\n * the code is contains many type assertions because typescript doesn't handle reduce well.\n */\nfunction splitProps(props: IframeResizerProps) {\n const split = Object.keys(props).reduce<{\n resizerOptions: IFrameOptions\n iframeHTMLAttributes: IframeHTMLAttributes<HTMLIFrameElement>\n }>(\n (acc, key) => {\n if (resizerOptionsSet.has(key)) {\n acc.resizerOptions[key as keyof IFrameOptions] = props[key as keyof typeof props]\n } else {\n acc.iframeHTMLAttributes[key as keyof IframeHTMLAttributes<HTMLIFrameElement>] =\n props[key as keyof typeof props]\n }\n return acc\n },\n { resizerOptions: {}, iframeHTMLAttributes: {} },\n )\n\n return split\n}\n","import { InvalidTokenError } from './error'\n\n/**\n * Encodes the rendering context as base64 and then URI encodes it.\n */\nexport function encodeRenderingContext<T>(renderingContext: NonNullable<T>) {\n const renderingContextJson = JSON.stringify(renderingContext)\n const renderingContextBase64 = btoa(renderingContextJson)\n const renderingContextEncoded = encodeURIComponent(renderingContextBase64)\n\n return renderingContextEncoded\n}\n\nexport function decodeToken(token: string) {\n try {\n const urlDecodedToken = decodeURIComponent(token)\n const base64DecodedToken = atob(urlDecodedToken)\n return JSON.parse(base64DecodedToken)\n } catch (error) {\n throw new InvalidTokenError()\n }\n}\n"],"mappings":"gkCAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,EAAA,uBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAL,GAEA,IAAAM,EAA+B,oBCF/B,IAAAC,EAAiD,oBCG1C,IAAMC,EAAN,cAA6B,KAAM,CACxC,YAAYC,EAAiB,CAC3B,MAAMA,CAAO,EACb,KAAK,KAAO,gBACd,CACF,EAKaC,EAAN,cAAgCF,CAAe,CACpD,aAAc,CACZ,MAAM,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AAC,CAAS,CAAE,GAAG,CAEtH","names":["src_exports","__export","App","DisputeTransaction","IssueCard","__toCommonJS","import_react","import_react","CapitalOSError","message","InvalidTokenError","import_penpal","import_react","IFRAME_CONNECTION_TIMEOUT_MILLISECONDS","useIframeConnection","iframeRef","token","onError","methods","connection","error","import_iframe_resizer","import_react","IframeResizer","props","ref","title","iframeHTMLAttributes","resizerOptions","splitProps","iframeRef","iframe","__spreadValues","React","__spreadProps","resizerOptionsSet","acc","key","encodeRenderingContext","renderingContext","renderingContextJson","renderingContextBase64","decodeToken","token","urlDecodedToken","base64DecodedToken","error","InvalidTokenError","CapitalOS","props","token","className","enableLogging","onError","LoadingComponent","renderingContext","methods","isLoaded","setIsLoaded","iframeRef","url","encodedRenderingContext","encodeRenderingContext","tokenObject","decodeToken","path","InvalidTokenError","error","useIframeConnection","__spreadValues","React","IframeResizer","App","props","React","CapitalOS","__spreadValues","IssueCard","_a","_b","defaultValues","onDone","onCancel","restOfProps","__objRest","entryPoint","renderingContext","__spreadProps","DisputeTransaction","transactionId"]}
|
package/dist/src/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { App } from '../_tsup-dts-rollup';
|
|
2
2
|
export { IssueCard } from '../_tsup-dts-rollup';
|
|
3
3
|
export { DisputeTransaction } from '../_tsup-dts-rollup';
|
|
4
|
-
export { IssueCardDefaultValues } from '../_tsup-dts-rollup';
|
|
5
4
|
export { IssueCardProps } from '../_tsup-dts-rollup';
|
|
6
5
|
export { DisputeTransactionProps } from '../_tsup-dts-rollup';
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { App } from '../_tsup-dts-rollup';
|
|
2
2
|
export { IssueCard } from '../_tsup-dts-rollup';
|
|
3
3
|
export { DisputeTransaction } from '../_tsup-dts-rollup';
|
|
4
|
-
export { IssueCardDefaultValues } from '../_tsup-dts-rollup';
|
|
5
4
|
export { IssueCardProps } from '../_tsup-dts-rollup';
|
|
6
5
|
export { DisputeTransactionProps } from '../_tsup-dts-rollup';
|