Skip to content

Commit

Permalink
fix(types): export all public types (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregjopa committed Aug 26, 2021
1 parent d664679 commit 9e8c39b
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/components/PayPalButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
PayPalButtonsComponent,
OnInitActions,
} from "@paypal/paypal-js/types/components/buttons";
import type { PayPalButtonsComponentProps } from "../types/paypalButtonTypes";
import type { PayPalButtonsComponentProps } from "../types";

/**
This `<PayPalButtons />` component renders the [Smart Payment Buttons](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-reference/#buttons).
Expand Down
4 changes: 2 additions & 2 deletions src/components/PayPalScriptProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { FC, useEffect, useReducer } from "react";
import { loadScript } from "@paypal/paypal-js";

import type { ScriptProviderProps } from "../types/scriptProviderTypes";
import { SCRIPT_LOADING_STATE, DISPATCH_ACTION } from "../types/enums";
import {
getScriptID,
ScriptContext,
scriptReducer,
} from "../context/scriptProviderContext";
import { SCRIPT_ID } from "../constants";
import type { ScriptProviderProps } from "../types";
import { SCRIPT_LOADING_STATE, DISPATCH_ACTION } from "../types";

export const PayPalScriptProvider: FC<ScriptProviderProps> = ({
options = { "client-id": "test" },
Expand Down
4 changes: 2 additions & 2 deletions src/components/braintree/BraintreePayPalButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
BRAINTREE_SOURCE,
BRAINTREE_PAYPAL_CHECKOUT_SOURCE,
} from "../../constants";
import type { BraintreePayPalButtonsComponentProps } from "../../types/braintreePayPalButtonTypes";
import { PayPalButtons } from "../PayPalButtons";
import { useBraintreeProviderContext } from "../../hooks/braintreeProviderHooks";
import { getBraintreeWindowNamespace } from "../../utils";
import { DISPATCH_ACTION } from "../../types/enums";
import { decorateActions } from "./utils";
import type { BraintreePayPalButtonsComponentProps } from "../../types";
import { DISPATCH_ACTION } from "../../types";

/**
This `<BraintreePayPalButtons />` component renders the [Braintree PayPal Buttons](https://developer.paypal.com/braintree/docs/guides/paypal/overview) for Braintree Merchants.
Expand Down
6 changes: 4 additions & 2 deletions src/components/braintree/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { BraintreePayPalCheckout } from "../../types/braintree/paypalCheckout";
import type { BraintreePayPalButtonsComponentProps } from "../../types/braintreePayPalButtonTypes";
import type { PayPalButtonsComponentProps } from "../../types/paypalButtonTypes";
import type {
PayPalButtonsComponentProps,
BraintreePayPalButtonsComponentProps,
} from "../../types";

/**
* Override the createOrder callback to send the PayPal checkout instance as argument
Expand Down
13 changes: 7 additions & 6 deletions src/context/scriptProviderContext.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { createContext } from "react";
//Internal dependencies

import { hashStr } from "../utils";
import { SCRIPT_ID } from "../constants";

import type {
ScriptContextState,
ReactPayPalScriptOptions,
ScriptReducerAction,
} from "../types/scriptProviderTypes";
import { DISPATCH_ACTION, SCRIPT_LOADING_STATE } from "../types/enums";
import type { PayPalScriptOptions } from "@paypal/paypal-js/types/script-options";
} from "../types";
import type { BraintreePayPalCheckout } from "../types/braintree/paypalCheckout";
import { hashStr } from "../utils";
import { SCRIPT_ID } from "../constants";
import { DISPATCH_ACTION, SCRIPT_LOADING_STATE } from "../types";
import type { PayPalScriptOptions } from "@paypal/paypal-js/types/script-options";

/**
* Generate a new random identifier for react-paypal-js
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/braintreeProviderHooks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useContext } from "react";

import type { ScriptContextState } from "../types/scriptProviderTypes";
import type { ScriptReducerAction } from "../types/scriptProviderTypes";
import { ScriptContext } from "../context/scriptProviderContext";
import {
contextNotEmptyValidator,
contextOptionClientTokenNotEmptyValidator,
} from "./contextValidator";
import type { ScriptContextState, ScriptReducerAction } from "../types";

/**
* Custom hook to get access to the ScriptProvider context
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/contextValidator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type {
ScriptContextState,
StrictScriptContextState,
} from "../types/scriptProviderTypes";
import {
DATA_CLIENT_TOKEN,
EMPTY_PROVIDER_CONTEXT_ERROR_MESSAGE,
EMPTY_PROVIDER_CONTEXT_CLIENT_TOKEN_ERROR_MESSAGE,
} from "../constants";
import type { ScriptContextState, StrictScriptContextState } from "../types";

/**
* Check if the context is available checking the state and dispatch function
Expand Down
7 changes: 2 additions & 5 deletions src/hooks/scriptProviderHooks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { useContext } from "react";

import type {
ScriptContextDerivedState,
ScriptReducerAction,
} from "../types/scriptProviderTypes";
import { SCRIPT_LOADING_STATE } from "../types/enums";
import { ScriptContext } from "../context/scriptProviderContext";
import { contextNotEmptyValidator } from "./contextValidator";
import type { ScriptContextDerivedState, ScriptReducerAction } from "../types";
import { SCRIPT_LOADING_STATE } from "../types";

/**
* Custom hook to get access to the Script context and
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from "./types/scriptProviderTypes";
export * from "./types/enums";
export * from "./types";
export * from "./context/scriptProviderContext";
export * from "./hooks/scriptProviderHooks";
export * from "./components/PayPalButtons";
Expand Down
28 changes: 12 additions & 16 deletions src/stories/BraintreePayPalButtons.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import type { FC } from "react";

import type { PayPalScriptOptions } from "@paypal/paypal-js/types/script-options";
import type {
CreateBraintreeActions,
CreateOrderBraintreeActions,
OnApproveBraintreeActions,
} from "../types/braintreePayPalButtonTypes";
import type { BraintreePayPalCheckoutTokenizationOptions } from "../types/braintree/paypalCheckout";
import { OnApproveData } from "../types/braintreePayPalButtonTypes";
OnApproveBraintreeData,
} from "../types";

import { PayPalScriptProvider } from "../index";
import { BraintreePayPalButtons } from "../components/braintree/BraintreePayPalButtons";
import {
Expand Down Expand Up @@ -74,7 +74,7 @@ export const Default: FC = () => {
<BraintreePayPalButtons
createOrder={(
data: Record<string, unknown>,
actions: CreateBraintreeActions
actions: CreateOrderBraintreeActions
) =>
actions.braintree.createPayment({
flow: "checkout",
Expand All @@ -96,19 +96,15 @@ export const Default: FC = () => {
})
}
onApprove={(
data: OnApproveData,
data: OnApproveBraintreeData,
actions: OnApproveBraintreeActions
) =>
actions.braintree
.tokenizePayment(
data as BraintreePayPalCheckoutTokenizationOptions
)
.then((payload) => {
approveSale(payload.nonce, AMOUNT).then((data) => {
alert(JSON.stringify(data));
// Call server-side endpoint to finish the sale
});
})
actions.braintree.tokenizePayment(data).then((payload) => {
approveSale(payload.nonce, AMOUNT).then((data) => {
alert(JSON.stringify(data));
// Call server-side endpoint to finish the sale
});
})
}
/>
);
Expand Down
11 changes: 7 additions & 4 deletions src/types/braintree/paypalCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ export interface BraintreePayPalCheckoutCreatePaymentOptions {
}

export interface BraintreePayPalCheckoutTokenizationOptions {
payerId: string;
paymentId?: string | undefined;
billingToken?: string | undefined;
vault?: boolean | undefined;
payerID: string;
orderID: string;
paymentID?: string;
paymentToken?: string;
billingToken?: string;
shippingOptionsId?: string;
vault?: boolean;
}

export interface BraintreePayPalCheckout {
Expand Down
21 changes: 8 additions & 13 deletions src/types/braintreePayPalButtonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@ import {
OnApproveActions,
} from "@paypal/paypal-js/types/components/buttons";
import type { BraintreeClient } from "./braintree/clientTypes";
import type { BraintreePayPalCheckout } from "./braintree/paypalCheckout";
import type {
BraintreePayPalCheckout,
BraintreePayPalCheckoutTokenizationOptions,
} from "./braintree/paypalCheckout";

export type CreateBraintreeActions = CreateOrderActions & {
export type CreateOrderBraintreeActions = CreateOrderActions & {
braintree: BraintreePayPalCheckout;
};

export type OnApproveBraintreeActions = OnApproveActions & {
braintree: BraintreePayPalCheckout;
};

export type OnApproveData = {
billingToken?: string | null;
facilitatorAccessToken: string;
orderId: string;
payerId?: string | null;
paymentId?: string | null;
subscriptionId?: string | null;
authCode?: string | null;
};
export type OnApproveBraintreeData = BraintreePayPalCheckoutTokenizationOptions;

export interface BraintreePayPalButtonsComponentProps
extends Omit<PayPalButtonsComponentProps, "createOrder" | "onApprove"> {
Expand All @@ -31,13 +26,13 @@ export interface BraintreePayPalButtonsComponentProps
*/
createOrder?: (
data: Record<string, unknown>,
actions: CreateBraintreeActions
actions: CreateOrderBraintreeActions
) => Promise<string>;
/**
* The onApprove actions include the braintree sdk paypalCheckoutInstance as `actions.braintree`
*/
onApprove?: (
data: OnApproveData,
data: OnApproveBraintreeData,
actions: OnApproveBraintreeActions
) => Promise<void>;
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./braintreePayPalButtonTypes";
export * from "./enums";
export * from "./paypalButtonTypes";
export * from "./scriptProviderTypes";
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
DEFAULT_BRAINTREE_NAMESPACE,
} from "./constants";
import type { PayPalNamespace } from "@paypal/paypal-js";
import type { BraintreeNamespace } from "./types/braintreePayPalButtonTypes";
import type { BraintreeNamespace } from "./types";

/**
* Get the namespace from the window in the browser
Expand Down

0 comments on commit 9e8c39b

Please sign in to comment.