Skip to content

Commit 89ff843

Browse files
Chore: update v6 type exports (#802)
* rename some types for session hooks and export them * chore: add changeset * fix doc comment
1 parent aa89d81 commit 89ff843

10 files changed

+110
-60
lines changed

.changeset/cold-glasses-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@paypal/react-paypal-js": patch
3+
---
4+
5+
Export v6 session hook argument types and rename some types.

packages/react-paypal-js/src/v6/components/PayLaterOneTimePaymentButton.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { usePayLaterOneTimePaymentSession } from "../hooks/usePayLaterOneTimePay
44
import { usePayPal } from "../hooks/usePayPal";
55
import { isServer } from "../utils";
66

7-
import type { PayLaterOneTimePaymentSessionProps } from "../hooks/usePayLaterOneTimePaymentSession";
7+
import type { UsePayLaterOneTimePaymentSessionProps } from "../hooks/usePayLaterOneTimePaymentSession";
88

9-
type PayLaterOneTimePaymentButtonProps = PayLaterOneTimePaymentSessionProps & {
10-
autoRedirect?: never;
11-
disabled?: boolean;
12-
};
9+
type PayLaterOneTimePaymentButtonProps =
10+
UsePayLaterOneTimePaymentSessionProps & {
11+
autoRedirect?: never;
12+
disabled?: boolean;
13+
};
1314

1415
/**
1516
* `PayLaterOneTimePaymentButton` is a button that provides a PayLater payment flow.

packages/react-paypal-js/src/v6/components/PayPalSavePaymentButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { usePayPalSavePaymentSession } from "../hooks/usePayPalSavePaymentSessio
44
import { isServer } from "../utils";
55

66
import type { ButtonProps } from "../types";
7-
import type { PayPalSavePaymentSessionProps } from "../hooks/usePayPalSavePaymentSession";
7+
import type { UsePayPalSavePaymentSessionProps } from "../hooks/usePayPalSavePaymentSession";
88

9-
type PayPalSavePaymentButtonProps = PayPalSavePaymentSessionProps &
9+
type PayPalSavePaymentButtonProps = UsePayPalSavePaymentSessionProps &
1010
ButtonProps & {
1111
autoRedirect?: never;
1212
};
@@ -15,7 +15,7 @@ type PayPalSavePaymentButtonProps = PayPalSavePaymentSessionProps &
1515
* `PayPalSavePaymentButton` is a button that provides a PayPal vault/save payment flow
1616
* (without purchase).
1717
*
18-
* `PayPalSavePaymentButtonProps` combines the arguments for {@link PayPalSavePaymentSessionProps}
18+
* `PayPalSavePaymentButtonProps` combines the arguments for {@link UsePayPalSavePaymentSessionProps}
1919
* and {@link ButtonProps}.
2020
*
2121
* Note, `autoRedirect` is not allowed because if given a `presentationMode` of `"redirect"` the button

packages/react-paypal-js/src/v6/hooks/usePayLaterOneTimePaymentSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
PayPalPresentationModeOptions,
1515
} from "../types";
1616

17-
export type PayLaterOneTimePaymentSessionProps = (
17+
export type UsePayLaterOneTimePaymentSessionProps = (
1818
| (Omit<PayLaterOneTimePaymentSessionOptions, "orderId"> & {
1919
createOrder: CreateOrderCallback;
2020
orderId?: never;
@@ -33,7 +33,7 @@ export function usePayLaterOneTimePaymentSession({
3333
createOrder,
3434
orderId,
3535
...callbacks
36-
}: PayLaterOneTimePaymentSessionProps): BasePaymentSessionReturn {
36+
}: UsePayLaterOneTimePaymentSessionProps): BasePaymentSessionReturn {
3737
const { sdkInstance, loadingStatus } = usePayPal();
3838
const isMountedRef = useIsMountedRef();
3939
const sessionRef = useRef<OneTimePaymentSession | null>(null);

packages/react-paypal-js/src/v6/hooks/usePayPalCardFieldsOneTimePaymentSession.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { toError } from "../utils";
88
import type { SubmitOptions, OneTimePaymentFlowResponse } from "../types";
99
import type { PayPalCardFieldsProvider } from "../components/PayPalCardFieldsProvider";
1010

11-
export type usePayPalCardFieldsOneTimePaymentSessionResult = {
11+
export type UsePayPalCardFieldsOneTimePaymentSessionResult = {
1212
submit: SubmitPayPalCardFieldsOneTimePayment;
1313
submitResponse: OneTimePaymentFlowResponse | null;
1414
error: Error | null;
@@ -25,9 +25,9 @@ type SubmitPayPalCardFieldsOneTimePayment = (
2525
* This hook must be used within a {@link PayPalCardFieldsProvider} to initialize
2626
* a one-time payment session.
2727
*
28-
* @returns {usePayPalCardFieldsOneTimePaymentSessionResult}
28+
* @returns {UsePayPalCardFieldsOneTimePaymentSessionResult}
2929
*/
30-
export function usePayPalCardFieldsOneTimePaymentSession(): usePayPalCardFieldsOneTimePaymentSessionResult {
30+
export function usePayPalCardFieldsOneTimePaymentSession(): UsePayPalCardFieldsOneTimePaymentSessionResult {
3131
const { cardFieldsSession, setCardFieldsSessionType } =
3232
usePayPalCardFieldsSession();
3333
const [submitResponse, setSubmitResponse] =

packages/react-paypal-js/src/v6/hooks/usePayPalCardFieldsSavePaymentSession.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { toError } from "../utils";
88
import type { SavePaymentFlowResponse, SubmitOptions } from "../types";
99
import type { PayPalCardFieldsProvider } from "../components/PayPalCardFieldsProvider";
1010

11-
export type usePayPalCardFieldsSavePaymentSessionResult = {
11+
export type UsePayPalCardFieldsSavePaymentSessionResult = {
1212
submit: SubmitPayPalCardFieldsSavePayment;
1313
submitResponse: SavePaymentFlowResponse | null;
1414
error: Error | null;
@@ -25,9 +25,9 @@ type SubmitPayPalCardFieldsSavePayment = (
2525
* This hook must be used within a {@link PayPalCardFieldsProvider} to initialize
2626
* a save payment session.
2727
*
28-
* @returns {usePayPalCardFieldsSavePaymentSessionResult}
28+
* @returns {UsePayPalCardFieldsSavePaymentSessionResult}
2929
*/
30-
export function usePayPalCardFieldsSavePaymentSession(): usePayPalCardFieldsSavePaymentSessionResult {
30+
export function usePayPalCardFieldsSavePaymentSession(): UsePayPalCardFieldsSavePaymentSessionResult {
3131
const { cardFieldsSession, setCardFieldsSessionType } =
3232
usePayPalCardFieldsSession();
3333
const [submitResponse, setSubmitResponse] =

packages/react-paypal-js/src/v6/hooks/usePayPalCreditSavePaymentSession.test.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { usePayPal } from "./usePayPal";
66
import { useProxyProps } from "../utils";
77
import { INSTANCE_LOADING_STATE, type SavePaymentSession } from "../types";
88

9-
import type { PayPalCreditSavePaymentSessionProps } from "./usePayPalCreditSavePaymentSession";
9+
import type { UsePayPalCreditSavePaymentSessionProps } from "./usePayPalCreditSavePaymentSession";
1010

1111
jest.mock("./usePayPal");
1212

@@ -67,7 +67,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
6767
error: null,
6868
});
6969

70-
const props: PayPalCreditSavePaymentSessionProps = {
70+
const props: UsePayPalCreditSavePaymentSessionProps = {
7171
presentationMode: "popup",
7272
vaultSetupToken: "test-vault-token",
7373
onApprove: jest.fn(),
@@ -97,7 +97,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
9797
error: null,
9898
});
9999

100-
const props: PayPalCreditSavePaymentSessionProps = {
100+
const props: UsePayPalCreditSavePaymentSessionProps = {
101101
presentationMode: "popup",
102102
vaultSetupToken: "test-vault-token",
103103
onApprove: jest.fn(),
@@ -123,7 +123,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
123123
error: null,
124124
});
125125

126-
const props: PayPalCreditSavePaymentSessionProps = {
126+
const props: UsePayPalCreditSavePaymentSessionProps = {
127127
presentationMode: "popup",
128128
vaultSetupToken: "test-vault-token",
129129
onApprove: jest.fn(),
@@ -165,7 +165,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
165165
error: null,
166166
});
167167

168-
const props: PayPalCreditSavePaymentSessionProps = {
168+
const props: UsePayPalCreditSavePaymentSessionProps = {
169169
presentationMode: "popup",
170170
vaultSetupToken: "test-vault-token",
171171
onApprove: jest.fn(),
@@ -184,7 +184,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
184184
const onCancel = jest.fn();
185185
const onError = jest.fn();
186186

187-
const props: PayPalCreditSavePaymentSessionProps = {
187+
const props: UsePayPalCreditSavePaymentSessionProps = {
188188
presentationMode: "popup",
189189
vaultSetupToken: "test-vault-token",
190190
onApprove,
@@ -226,7 +226,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
226226
const onCancel = jest.fn();
227227
const onError = jest.fn();
228228

229-
const props: PayPalCreditSavePaymentSessionProps = {
229+
const props: UsePayPalCreditSavePaymentSessionProps = {
230230
presentationMode: "popup",
231231
createVaultToken: mockCreateVaultToken,
232232
onApprove,
@@ -261,7 +261,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
261261

262262
describe("session lifecycle", () => {
263263
test("should destroy session on unmount", () => {
264-
const props: PayPalCreditSavePaymentSessionProps = {
264+
const props: UsePayPalCreditSavePaymentSessionProps = {
265265
presentationMode: "popup",
266266
vaultSetupToken: "test-vault-token",
267267
onApprove: jest.fn(),
@@ -310,7 +310,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
310310
});
311311

312312
test("should destroy the previous session when the hook re-runs with a new sdkInstance", () => {
313-
const props: PayPalCreditSavePaymentSessionProps = {
313+
const props: UsePayPalCreditSavePaymentSessionProps = {
314314
presentationMode: "popup",
315315
vaultSetupToken: "test-vault-token",
316316
onApprove: jest.fn(),
@@ -386,7 +386,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
386386
error: null,
387387
});
388388

389-
const props: PayPalCreditSavePaymentSessionProps = {
389+
const props: UsePayPalCreditSavePaymentSessionProps = {
390390
presentationMode: "redirect",
391391
vaultSetupToken: "test-vault-token",
392392
onApprove: jest.fn(),
@@ -413,7 +413,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
413413
error: null,
414414
});
415415

416-
const props: PayPalCreditSavePaymentSessionProps = {
416+
const props: UsePayPalCreditSavePaymentSessionProps = {
417417
presentationMode: "direct-app-switch",
418418
vaultSetupToken: "test-vault-token",
419419
onApprove: jest.fn(),
@@ -440,7 +440,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
440440
error: null,
441441
});
442442

443-
const props: PayPalCreditSavePaymentSessionProps = {
443+
const props: UsePayPalCreditSavePaymentSessionProps = {
444444
presentationMode: "redirect",
445445
vaultSetupToken: "test-vault-token",
446446
onApprove: jest.fn(),
@@ -455,7 +455,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
455455
});
456456

457457
test("should NOT check hasReturned when presentationMode is popup", () => {
458-
const props: PayPalCreditSavePaymentSessionProps = {
458+
const props: UsePayPalCreditSavePaymentSessionProps = {
459459
presentationMode: "popup",
460460
vaultSetupToken: "test-vault-token",
461461
onApprove: jest.fn(),
@@ -482,7 +482,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
482482
error: null,
483483
});
484484

485-
const props: PayPalCreditSavePaymentSessionProps = {
485+
const props: UsePayPalCreditSavePaymentSessionProps = {
486486
presentationMode: "redirect",
487487
vaultSetupToken: "test-vault-token",
488488
onApprove: jest.fn(),
@@ -499,7 +499,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
499499

500500
describe("handleClick", () => {
501501
test("should provide a click handler that calls session start with presentation mode", async () => {
502-
const props: PayPalCreditSavePaymentSessionProps = {
502+
const props: UsePayPalCreditSavePaymentSessionProps = {
503503
presentationMode: "popup",
504504
vaultSetupToken: "test-vault-token",
505505
onApprove: jest.fn(),
@@ -529,7 +529,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
529529
Promise.resolve({ vaultSetupToken: "created-vault-token" }),
530530
);
531531

532-
const props: PayPalCreditSavePaymentSessionProps = {
532+
const props: UsePayPalCreditSavePaymentSessionProps = {
533533
presentationMode: "popup",
534534
createVaultToken: mockCreateVaultToken,
535535
onApprove: jest.fn(),
@@ -557,7 +557,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
557557
});
558558

559559
test("should do nothing if the click handler is called and there is no session", async () => {
560-
const props: PayPalCreditSavePaymentSessionProps = {
560+
const props: UsePayPalCreditSavePaymentSessionProps = {
561561
presentationMode: "popup",
562562
vaultSetupToken: "test-vault-token",
563563
onApprove: jest.fn(),
@@ -593,7 +593,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
593593
] as const;
594594

595595
for (const mode of presentationModes) {
596-
const props: PayPalCreditSavePaymentSessionProps = {
596+
const props: UsePayPalCreditSavePaymentSessionProps = {
597597
presentationMode: mode,
598598
vaultSetupToken: "test-vault-token",
599599
onApprove: jest.fn(),
@@ -629,7 +629,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
629629
});
630630

631631
test("should pass autoRedirect option when specified", async () => {
632-
const props: PayPalCreditSavePaymentSessionProps = {
632+
const props: UsePayPalCreditSavePaymentSessionProps = {
633633
presentationMode: "redirect",
634634
vaultSetupToken: "test-vault-token",
635635
autoRedirect: { enabled: true },
@@ -652,7 +652,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
652652
});
653653

654654
test("should pass fullPageOverlay option when specified", async () => {
655-
const props: PayPalCreditSavePaymentSessionProps = {
655+
const props: UsePayPalCreditSavePaymentSessionProps = {
656656
presentationMode: "popup",
657657
vaultSetupToken: "test-vault-token",
658658
fullPageOverlay: { enabled: true },
@@ -677,7 +677,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
677677

678678
describe("handleCancel", () => {
679679
test("should provide a cancel handler that cancels the session", () => {
680-
const props: PayPalCreditSavePaymentSessionProps = {
680+
const props: UsePayPalCreditSavePaymentSessionProps = {
681681
presentationMode: "popup",
682682
vaultSetupToken: "test-vault-token",
683683
onApprove: jest.fn(),
@@ -697,7 +697,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
697697
});
698698

699699
test("should not throw error when session is not available", () => {
700-
const props: PayPalCreditSavePaymentSessionProps = {
700+
const props: UsePayPalCreditSavePaymentSessionProps = {
701701
presentationMode: "popup",
702702
vaultSetupToken: "test-vault-token",
703703
onApprove: jest.fn(),
@@ -721,7 +721,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
721721

722722
describe("handleDestroy", () => {
723723
test("should provide a destroy handler that destroys the session", () => {
724-
const props: PayPalCreditSavePaymentSessionProps = {
724+
const props: UsePayPalCreditSavePaymentSessionProps = {
725725
presentationMode: "popup",
726726
vaultSetupToken: "test-vault-token",
727727
onApprove: jest.fn(),
@@ -741,7 +741,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
741741
});
742742

743743
test("should not throw error when session is not available", () => {
744-
const props: PayPalCreditSavePaymentSessionProps = {
744+
const props: UsePayPalCreditSavePaymentSessionProps = {
745745
presentationMode: "popup",
746746
vaultSetupToken: "test-vault-token",
747747
onApprove: jest.fn(),
@@ -763,7 +763,7 @@ describe("usePayPalCreditSavePaymentSession", () => {
763763
});
764764

765765
test("should handle manually destroyed session gracefully", async () => {
766-
const props: PayPalCreditSavePaymentSessionProps = {
766+
const props: UsePayPalCreditSavePaymentSessionProps = {
767767
presentationMode: "popup",
768768
vaultSetupToken: "test-vault-token",
769769
onApprove: jest.fn(),

packages/react-paypal-js/src/v6/hooks/usePayPalCreditSavePaymentSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
BasePaymentSessionReturn,
1414
} from "../types";
1515

16-
export type PayPalCreditSavePaymentSessionProps = (
16+
export type UsePayPalCreditSavePaymentSessionProps = (
1717
| (Omit<SavePaymentSessionOptions, "vaultSetupToken"> & {
1818
createVaultToken: () => Promise<{ vaultSetupToken: string }>;
1919
vaultSetupToken?: never;
@@ -52,7 +52,7 @@ export function usePayPalCreditSavePaymentSession({
5252
createVaultToken,
5353
vaultSetupToken,
5454
...callbacks
55-
}: PayPalCreditSavePaymentSessionProps): BasePaymentSessionReturn {
55+
}: UsePayPalCreditSavePaymentSessionProps): BasePaymentSessionReturn {
5656
const { sdkInstance, loadingStatus } = usePayPal();
5757
const isMountedRef = useIsMountedRef();
5858
const sessionRef = useRef<SavePaymentSession | null>(null);

packages/react-paypal-js/src/v6/hooks/usePayPalSavePaymentSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
BasePaymentSessionReturn,
1414
} from "../types";
1515

16-
export type PayPalSavePaymentSessionProps = (
16+
export type UsePayPalSavePaymentSessionProps = (
1717
| (Omit<SavePaymentSessionOptions, "vaultSetupToken"> & {
1818
createVaultToken: () => Promise<{ vaultSetupToken: string }>;
1919
vaultSetupToken?: never;
@@ -51,7 +51,7 @@ export function usePayPalSavePaymentSession({
5151
createVaultToken,
5252
vaultSetupToken,
5353
...callbacks
54-
}: PayPalSavePaymentSessionProps): BasePaymentSessionReturn {
54+
}: UsePayPalSavePaymentSessionProps): BasePaymentSessionReturn {
5555
const { sdkInstance, loadingStatus } = usePayPal();
5656
const isMountedRef = useIsMountedRef();
5757
const sessionRef = useRef<SavePaymentSession | null>(null);

0 commit comments

Comments
 (0)