@paypal/checkout-components 5.0.433 → 5.0.435

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paypal/checkout-components",
3
- "version": "5.0.433",
3
+ "version": "5.0.435",
4
4
  "description": "PayPal Checkout components, for integrating checkout products.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,58 @@
1
+ /* @flow */
2
+
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import { FUNDING_BRAND_LABEL } from "@paypal/sdk-constants/src";
5
+
6
+ import { getButtonsComponent } from "./component";
7
+
8
+ // component.jsx reads the bare global __ENV__ (not build-time inlined like
9
+ // __PAYPAL_CHECKOUT__), so it must be defined before getButtonsComponent() runs.
10
+ window.__ENV__ = "test";
11
+
12
+ // Capture the config object component.jsx passes to zoid's create() so we can
13
+ // exercise the real (un-exported) attributes() logic instead of re-implementing it.
14
+ const { createMock } = vi.hoisted(() => ({
15
+ createMock: vi.fn((options) => options),
16
+ }));
17
+
18
+ vi.mock("@krakenjs/zoid/src", () => ({
19
+ create: createMock,
20
+ EVENT: { PRERENDERED: "prerendered" },
21
+ }));
22
+
23
+ vi.mock("@paypal/sdk-client/src", async (importOriginal) => ({
24
+ ...(await importOriginal()),
25
+ getLogger: vi.fn(() => ({
26
+ metricCounter: vi.fn(),
27
+ track: vi.fn(),
28
+ info: vi.fn(),
29
+ error: vi.fn(),
30
+ })),
31
+ getPayPalDomainRegex: vi.fn(() => /paypal\.com/),
32
+ getEnv: vi.fn(() => "test"),
33
+ }));
34
+
35
+ vi.mock("./util", async (importOriginal) => ({
36
+ ...(await importOriginal()),
37
+ getButtonExperiments: vi.fn(() => ({})),
38
+ }));
39
+
40
+ describe("getButtonsComponent iframe title", () => {
41
+ it("uses the plain PayPal label when no funding source is set", () => {
42
+ getButtonsComponent();
43
+ const { attributes } = createMock.mock.calls[0][0];
44
+
45
+ expect(attributes({ props: {} }).iframe.title).toBe(
46
+ FUNDING_BRAND_LABEL.PAYPAL,
47
+ );
48
+ });
49
+
50
+ it("appends the funding source to the label when one is set", () => {
51
+ getButtonsComponent();
52
+ const { attributes } = createMock.mock.calls[0][0];
53
+
54
+ expect(attributes({ props: { fundingSource: "venmo" } }).iframe.title).toBe(
55
+ `${FUNDING_BRAND_LABEL.PAYPAL}-venmo`,
56
+ );
57
+ });
58
+ });
@@ -25,6 +25,7 @@ import {
25
25
  noop,
26
26
  supportsPopups,
27
27
  inlineMemoize,
28
+ stringifyError,
28
29
  } from "@krakenjs/belter/src";
29
30
  import { FUNDING } from "@paypal/sdk-constants/src";
30
31
  import {
@@ -42,6 +43,50 @@ import { DEFAULT_POPUP_SIZE } from "./config";
42
43
 
43
44
  export type CheckoutComponent = ZoidComponent<CheckoutPropsType>;
44
45
 
46
+ const WINDOW_NAME_LOG_TRUNCATION_LENGTH = 50;
47
+ // Matches window names zoid itself writes, eg `__zoid__paypal_checkout__<payload>__`.
48
+ // See buildChildWindowName in @krakenjs/zoid.
49
+ const ZOID_WINDOW_NAME_PATTERN = /^__zoid__.+__$/;
50
+
51
+ function spyOnWindowNameAssignment(): void {
52
+ try {
53
+ let currentWindowName = window.name;
54
+
55
+ Object.defineProperty(window, "name", {
56
+ configurable: true,
57
+ get(): string {
58
+ return currentWindowName;
59
+ },
60
+ set(value: string): void {
61
+ if (ZOID_WINDOW_NAME_PATTERN.test(value)) {
62
+ currentWindowName = value;
63
+ return;
64
+ }
65
+
66
+ getLogger().error("checkout_window_name_overwritten", {
67
+ err: stringifyError(
68
+ new Error(
69
+ `window.name was overwritten: ${String(value).slice(
70
+ 0,
71
+ WINDOW_NAME_LOG_TRUNCATION_LENGTH,
72
+ )}`,
73
+ ),
74
+ ),
75
+ originalValue: String(currentWindowName).slice(
76
+ 0,
77
+ WINDOW_NAME_LOG_TRUNCATION_LENGTH,
78
+ ),
79
+ });
80
+ currentWindowName = value;
81
+ },
82
+ });
83
+ } catch (error) {
84
+ getLogger().error("checkout_window_name_spy_error", {
85
+ err: stringifyError(error),
86
+ });
87
+ }
88
+ }
89
+
45
90
  export function getCheckoutComponent(): CheckoutComponent {
46
91
  return inlineMemoize(getCheckoutComponent, () => {
47
92
  const component = create({
@@ -382,6 +427,8 @@ export function getCheckoutComponent(): CheckoutComponent {
382
427
  });
383
428
 
384
429
  if (component.isChild()) {
430
+ spyOnWindowNameAssignment();
431
+
385
432
  window.xchild = {
386
433
  props: component.xprops,
387
434
  show: noop,