@easypayment/medusa-paypal-ui 1.2.7 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- package/dist/order.cjs +1 -3
- package/dist/order.cjs.map +1 -1
- package/dist/order.d.cts +3 -1
- package/dist/order.d.ts +3 -1
- package/dist/order.mjs +1 -3
- package/dist/order.mjs.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +6 -4
package/dist/order.d.ts
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
declare const PAYPAL_WALLET_PROVIDER_ID: "pp_paypal_paypal";
|
|
9
9
|
declare const PAYPAL_CARD_PROVIDER_ID: "pp_paypal_card_paypal_card";
|
|
10
|
+
declare const PAYPAL_PROVIDER_IDS: readonly ["pp_paypal_paypal", "pp_paypal_card_paypal_card"];
|
|
11
|
+
type PayPalProviderId = (typeof PAYPAL_PROVIDER_IDS)[number];
|
|
10
12
|
/** True when the provider id belongs to this PayPal plugin. */
|
|
11
|
-
declare function isPayPalProviderId(providerId?: string | null):
|
|
13
|
+
declare function isPayPalProviderId(providerId?: string | null): providerId is PayPalProviderId;
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Server-safe helpers for displaying PayPal payments on order / confirmation
|
package/dist/order.mjs
CHANGED
package/dist/order.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/order.ts"],"sourcesContent":["/**\n * Provider ids registered by `@easypayment/medusa-payment-paypal`.\n *\n * Single source of truth — `PayPalPaymentSection`, `MedusaNextPayPalAdapter`,\n * and the server-safe `order` entrypoint all re-export from here so the ids\n * can never drift between entrypoints.\n */\nexport const PAYPAL_WALLET_PROVIDER_ID = \"pp_paypal_paypal\" as const\nexport const PAYPAL_CARD_PROVIDER_ID = \"pp_paypal_card_paypal_card\" as const\n\nexport const PAYPAL_PROVIDER_IDS = [\n PAYPAL_WALLET_PROVIDER_ID,\n PAYPAL_CARD_PROVIDER_ID,\n] as const\n\n/** True when the provider id belongs to this PayPal plugin. */\nexport function isPayPalProviderId(providerId?: string | null):
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/order.ts"],"sourcesContent":["/**\n * Provider ids registered by `@easypayment/medusa-payment-paypal`.\n *\n * Single source of truth — `PayPalPaymentSection`, `MedusaNextPayPalAdapter`,\n * and the server-safe `order` entrypoint all re-export from here so the ids\n * can never drift between entrypoints.\n */\nexport const PAYPAL_WALLET_PROVIDER_ID = \"pp_paypal_paypal\" as const\nexport const PAYPAL_CARD_PROVIDER_ID = \"pp_paypal_card_paypal_card\" as const\n\nexport const PAYPAL_PROVIDER_IDS = [\n PAYPAL_WALLET_PROVIDER_ID,\n PAYPAL_CARD_PROVIDER_ID,\n] as const\n\nexport type PayPalProviderId = (typeof PAYPAL_PROVIDER_IDS)[number]\n\n/** True when the provider id belongs to this PayPal plugin. */\nexport function isPayPalProviderId(\n providerId?: string | null\n): providerId is PayPalProviderId {\n if (!providerId) return false\n return PAYPAL_PROVIDER_IDS.includes(providerId as PayPalProviderId)\n}\n","/**\n * Server-safe helpers for displaying PayPal payments on order / confirmation\n * pages.\n *\n * This module is intentionally free of React and any client-only code, so it\n * can be imported from Next.js **server components** (e.g. the order\n * confirmation page) without pulling in the checkout UI.\n *\n * @example\n * import { getPaymentLabel, fetchPayPalConfig } from \"@easypayment/medusa-paypal-ui/order\"\n *\n * // In the (async) server component that renders the payment method:\n * const titles = await fetchPayPalConfig({\n * baseUrl: process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL!,\n * publishableApiKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,\n * })\n *\n * <Text>\n * {getPaymentLabel(\n * payment.provider_id,\n * paymentInfoMap[payment.provider_id]?.title,\n * titles\n * )}\n * </Text>\n */\n\nimport {\n PAYPAL_WALLET_PROVIDER_ID,\n PAYPAL_CARD_PROVIDER_ID,\n isPayPalProviderId,\n} from \"./constants\"\n\nexport {\n PAYPAL_WALLET_PROVIDER_ID,\n PAYPAL_CARD_PROVIDER_ID,\n isPayPalProviderId,\n}\n\nexport type PayPalPaymentInfo = { title: string }\n\n/** Built-in fallback titles, used only when admin titles aren't supplied. */\nexport const paypalPaymentInfoMap: Record<string, PayPalPaymentInfo> = {\n [PAYPAL_WALLET_PROVIDER_ID]: { title: \"PayPal\" },\n [PAYPAL_CARD_PROVIDER_ID]: { title: \"Credit or Debit Card\" },\n}\n\n/** Admin-configured titles, as returned by `GET /store/paypal/config`. */\nexport type PayPalConfigTitles = {\n paypal_title?: string | null\n card_title?: string | null\n}\n\n/**\n * Null-safe payment label resolver for order / confirmation pages.\n *\n * Precedence for the PayPal providers: **admin-configured title** (`titles`,\n * from {@link fetchPayPalConfig}) → built-in default. For any other provider:\n * `fallback` → raw id. Never throws on an unknown / missing provider, which is\n * what causes the common `Cannot read properties of undefined (reading 'title')`\n * crash on the order confirmation page.\n *\n * @param titles Admin titles so the order page shows the same labels configured\n * in Medusa Admin → Settings → PayPal (e.g. a custom \"Credit or Debit Card\").\n */\nexport function getPaymentLabel(\n providerId: string | undefined | null,\n fallback?: string,\n titles?: PayPalConfigTitles\n): string {\n if (!providerId) {\n return fallback ?? \"\"\n }\n if (providerId === PAYPAL_WALLET_PROVIDER_ID) {\n return (\n titles?.paypal_title?.trim() ||\n paypalPaymentInfoMap[PAYPAL_WALLET_PROVIDER_ID].title\n )\n }\n if (providerId === PAYPAL_CARD_PROVIDER_ID) {\n return (\n titles?.card_title?.trim() ||\n paypalPaymentInfoMap[PAYPAL_CARD_PROVIDER_ID].title\n )\n }\n return fallback ?? providerId\n}\n\n/**\n * Fetch the admin-configured PayPal titles from the storefront API\n * (`GET /store/paypal/config`). Server-safe (uses the global `fetch`).\n *\n * Returns `{}` on any error/network failure so callers can fall back to the\n * built-in defaults without their own try/catch.\n */\nexport async function fetchPayPalConfig(opts: {\n baseUrl: string\n publishableApiKey?: string\n signal?: AbortSignal\n}): Promise<PayPalConfigTitles> {\n const { baseUrl, publishableApiKey, signal } = opts\n if (!baseUrl) {\n return {}\n }\n try {\n const timeoutMs = 30_000\n let effectiveSignal = signal\n let timeoutId: ReturnType<typeof setTimeout> | undefined\n if (!signal) {\n const controller = new AbortController()\n timeoutId = setTimeout(() => controller.abort(), timeoutMs)\n effectiveSignal = controller.signal\n }\n let res: Response\n try {\n res = await fetch(`${baseUrl.replace(/\\/$/, \"\")}/store/paypal/config`, {\n headers: {\n accept: \"application/json\",\n ...(publishableApiKey\n ? { \"x-publishable-api-key\": publishableApiKey }\n : {}),\n },\n signal: effectiveSignal,\n })\n } finally {\n if (timeoutId !== undefined) clearTimeout(timeoutId)\n }\n if (!res.ok) {\n return {}\n }\n const cfg = (await res.json()) as Record<string, unknown>\n return {\n paypal_title:\n typeof cfg.paypal_title === \"string\" ? cfg.paypal_title : undefined,\n card_title:\n typeof cfg.card_title === \"string\" ? cfg.card_title : undefined,\n }\n } catch {\n return {}\n }\n}\n"],"mappings":";AAOO,IAAM,4BAA4B;AAClC,IAAM,0BAA0B;AAEhC,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA;AACF;AAKO,SAAS,mBACd,YACgC;AAChC,MAAI,CAAC,WAAY,QAAO;AACxB,SAAO,oBAAoB,SAAS,UAA8B;AACpE;;;ACkBO,IAAM,uBAA0D;AAAA,EACrE,CAAC,yBAAyB,GAAG,EAAE,OAAO,SAAS;AAAA,EAC/C,CAAC,uBAAuB,GAAG,EAAE,OAAO,uBAAuB;AAC7D;AAoBO,SAAS,gBACd,YACA,UACA,QACQ;AACR,MAAI,CAAC,YAAY;AACf,WAAO,YAAY;AAAA,EACrB;AACA,MAAI,eAAe,2BAA2B;AAC5C,WACE,QAAQ,cAAc,KAAK,KAC3B,qBAAqB,yBAAyB,EAAE;AAAA,EAEpD;AACA,MAAI,eAAe,yBAAyB;AAC1C,WACE,QAAQ,YAAY,KAAK,KACzB,qBAAqB,uBAAuB,EAAE;AAAA,EAElD;AACA,SAAO,YAAY;AACrB;AASA,eAAsB,kBAAkB,MAIR;AAC9B,QAAM,EAAE,SAAS,mBAAmB,OAAO,IAAI;AAC/C,MAAI,CAAC,SAAS;AACZ,WAAO,CAAC;AAAA,EACV;AACA,MAAI;AACF,UAAM,YAAY;AAClB,QAAI,kBAAkB;AACtB,QAAI;AACJ,QAAI,CAAC,QAAQ;AACX,YAAM,aAAa,IAAI,gBAAgB;AACvC,kBAAY,WAAW,MAAM,WAAW,MAAM,GAAG,SAAS;AAC1D,wBAAkB,WAAW;AAAA,IAC/B;AACA,QAAI;AACJ,QAAI;AACF,YAAM,MAAM,MAAM,GAAG,QAAQ,QAAQ,OAAO,EAAE,CAAC,wBAAwB;AAAA,QACrE,SAAS;AAAA,UACP,QAAQ;AAAA,UACR,GAAI,oBACA,EAAE,yBAAyB,kBAAkB,IAC7C,CAAC;AAAA,QACP;AAAA,QACA,QAAQ;AAAA,MACV,CAAC;AAAA,IACH,UAAE;AACA,UAAI,cAAc,OAAW,cAAa,SAAS;AAAA,IACrD;AACA,QAAI,CAAC,IAAI,IAAI;AACX,aAAO,CAAC;AAAA,IACV;AACA,UAAM,MAAO,MAAM,IAAI,KAAK;AAC5B,WAAO;AAAA,MACL,cACE,OAAO,IAAI,iBAAiB,WAAW,IAAI,eAAe;AAAA,MAC5D,YACE,OAAO,IAAI,eAAe,WAAW,IAAI,aAAa;AAAA,IAC1D;AAAA,EACF,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -13,10 +13,12 @@ export const PAYPAL_PROVIDER_IDS = [
|
|
|
13
13
|
PAYPAL_CARD_PROVIDER_ID,
|
|
14
14
|
] as const
|
|
15
15
|
|
|
16
|
+
export type PayPalProviderId = (typeof PAYPAL_PROVIDER_IDS)[number]
|
|
17
|
+
|
|
16
18
|
/** True when the provider id belongs to this PayPal plugin. */
|
|
17
|
-
export function isPayPalProviderId(
|
|
19
|
+
export function isPayPalProviderId(
|
|
20
|
+
providerId?: string | null
|
|
21
|
+
): providerId is PayPalProviderId {
|
|
18
22
|
if (!providerId) return false
|
|
19
|
-
return PAYPAL_PROVIDER_IDS.includes(
|
|
20
|
-
providerId as (typeof PAYPAL_PROVIDER_IDS)[number]
|
|
21
|
-
)
|
|
23
|
+
return PAYPAL_PROVIDER_IDS.includes(providerId as PayPalProviderId)
|
|
22
24
|
}
|