Skip to content

Commit

Permalink
feat: add compatibility with window alias strategy (#202)
Browse files Browse the repository at this point in the history
Co-authored-by: Dustin Jones <[email protected]>
  • Loading branch information
dtjones404 and dtjones404 authored May 21, 2024
1 parent 9ca0ae4 commit 089a4bb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { destroyElement } from "@krakenjs/belter/src";

import { getVersion } from "./global";
import { getSDKScript, getNamespace } from "./script";
import { getLogger } from "./logger";

export type SetupComponent<T> = {|
name: string,
Expand All @@ -21,7 +22,13 @@ export function setupSDK(components: $ReadOnlyArray<SetupComponent<mixed>>) {
const existingVersion = existingNamespace && existingNamespace.version;

if (existingNamespace) {
if (existingNamespace[INTERNAL_DESTROY_KEY]) {
if (existingVersion.startsWith("6.")) {
getLogger().info("setup_sdk_v6_integration_found", {
v5Version: version,
v6Version: existingVersion,
});
delete window[namespace];
} else if (existingNamespace[INTERNAL_DESTROY_KEY]) {
existingNamespace[INTERNAL_DESTROY_KEY](
new Error(
`New SDK instance loaded, existing instance destroyed (${namespace} / ${version})`
Expand All @@ -42,6 +49,10 @@ export function setupSDK(components: $ReadOnlyArray<SetupComponent<mixed>>) {
window[namespace] = window[namespace] || {};
window[namespace].version = version;

if (namespace === "paypal" && window.__paypal_sdk__?.v6) {
window.paypal.v6 = window.__paypal_sdk__.v6;
}

const destroyers = [];

for (const { name, requirer, setupHandler } of components) {
Expand Down

0 comments on commit 089a4bb

Please sign in to comment.