@paypercut/checkout-js 1.4.0 → 1.4.1

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/README.md CHANGED
@@ -1708,7 +1708,7 @@ Tip: Prefer subscribing with the SdkEvent enum for stronger typing.
1708
1708
  <body>
1709
1709
  <div id="checkout"></div>
1710
1710
 
1711
- <script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.4.0/dist/paypercut-checkout.iife.min.js"></script>
1711
+ <script src="https://cdn.jsdelivr.net/npm/@paypercut/checkout-js@1.4.1/dist/paypercut-checkout.iife.min.js"></script>
1712
1712
  <script>
1713
1713
  const checkout = PaypercutCheckout({
1714
1714
  id: '01KB23M9EC960C50G3AH14FTTT',
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
4
- const SDK_VERSION = "1.4.0";
4
+ const SDK_VERSION = "1.4.1";
5
5
 
6
6
  const ELEMENTS_APPEARANCE_VARIABLE_NAMES = [
7
7
  'colorPrimary',
@@ -231,6 +231,7 @@ class DeveloperAssistantCoordinator {
231
231
  configurationIdentity: active.configurationIdentity,
232
232
  appearanceScopeId: active.appearanceScopeId,
233
233
  ...(presetTarget?.presets ? { presets: presetTarget.presets } : {}),
234
+ isVisible: () => identityTargets.some((target) => target.isVisible()),
234
235
  isAvailable: () => presetTarget?.isAvailable() ?? true,
235
236
  isAppearanceAvailable: () => appearanceTargets.every((target) => target.isAppearanceAvailable()),
236
237
  didLastAppearancePreviewClearTestData: () => this.lastAppearancePreviewClearedTestData,
@@ -2493,15 +2494,89 @@ function createStyle() {
2493
2494
  return style;
2494
2495
  }
2495
2496
 
2497
+ const DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT = 'paypercut-developer-assistance.iife.min.js';
2498
+ const DEVELOPER_ASSISTANCE_MODULE_ARTIFACT = 'developer-assistance.mjs';
2499
+ const DEVELOPER_ASSISTANCE_LOAD_DIAGNOSTIC = '[Paypercut Elements] developer_assistance_load_failed: Developer Assistant is unavailable. The SDK and Elements continue to work.';
2500
+ const IIFE_ARTIFACT_PATH = /\/paypercut-checkout(?:-dev)?\.iife\.min\.js$/;
2496
2501
  // Rollup rewrites import.meta.url for CommonJS and classic-script bundles, so
2497
2502
  // this remains the URL of the exact core artifact that owns the registration
2498
2503
  // boundary in every supported format.
2499
- typeof __filename === 'string' ? fileUrlFor(__filename) : (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('developer-assistance.cjs', document.baseURI).href));
2500
- typeof document === 'undefined' ? null : (document.currentScript?.getAttribute('src') ?? null);
2504
+ const coreArtifactUrl = typeof __filename === 'string' ? fileUrlFor(__filename) : (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('developer-assistance.cjs', document.baseURI).href));
2505
+ const classicScriptUrl = typeof document === 'undefined' ? null : (document.currentScript?.getAttribute('src') ?? null);
2506
+ let loadRequested = false;
2507
+ function requestDeveloperAssistance(isInstalled) {
2508
+ if (loadRequested || isInstalled())
2509
+ return;
2510
+ loadRequested = true;
2511
+ if (!canLoadDeveloperAssistance()) {
2512
+ warnDeveloperAssistanceUnavailable();
2513
+ return;
2514
+ }
2515
+ void Promise.resolve()
2516
+ .then(loadDeveloperAssistance)
2517
+ .then(() => {
2518
+ if (!isInstalled())
2519
+ throw new Error();
2520
+ })
2521
+ .catch(warnDeveloperAssistanceUnavailable);
2522
+ }
2523
+ function warnDeveloperAssistanceUnavailable() {
2524
+ console.warn(DEVELOPER_ASSISTANCE_LOAD_DIAGNOSTIC);
2525
+ }
2526
+ function canLoadDeveloperAssistance() {
2527
+ return (typeof document !== 'undefined' &&
2528
+ typeof document.createElement === 'function' &&
2529
+ Boolean(document.head || document.documentElement));
2530
+ }
2531
+ function loadDeveloperAssistance() {
2532
+ if (classicScriptUrl || isClassicScriptArtifact(coreArtifactUrl)) {
2533
+ return loadClassicScript(resolveBrowserArtifactUrl(coreArtifactUrl));
2534
+ }
2535
+ const moduleUrl = new URL(DEVELOPER_ASSISTANCE_MODULE_ARTIFACT, coreArtifactUrl).href;
2536
+ return import(/* @vite-ignore */ moduleUrl);
2537
+ }
2501
2538
  function fileUrlFor(filename) {
2502
2539
  const normalized = filename.replace(/\\/g, '/');
2503
2540
  return new URL(`file://${normalized.startsWith('/') ? '' : '/'}${normalized}`).href;
2504
2541
  }
2542
+ function resolveBrowserArtifactUrl(coreUrl) {
2543
+ const url = new URL(coreUrl);
2544
+ if (IIFE_ARTIFACT_PATH.test(url.pathname)) {
2545
+ const artifactUrl = new URL(DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT, url);
2546
+ artifactUrl.search = url.search;
2547
+ artifactUrl.hash = '';
2548
+ return artifactUrl.href;
2549
+ }
2550
+ if (/\.js$/.test(url.pathname)) {
2551
+ url.pathname = url.pathname.replace(/[^/]+$/, DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT);
2552
+ }
2553
+ else if (/\/cdn\/?$/.test(url.pathname)) {
2554
+ url.pathname = url.pathname.replace(/\/cdn\/?$/, `/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`);
2555
+ }
2556
+ else {
2557
+ url.pathname = `${url.pathname.replace(/\/$/, '')}/dist/${DEVELOPER_ASSISTANCE_BROWSER_ARTIFACT}`;
2558
+ }
2559
+ url.hash = '';
2560
+ return url.href;
2561
+ }
2562
+ function isClassicScriptArtifact(url) {
2563
+ try {
2564
+ return IIFE_ARTIFACT_PATH.test(new URL(url).pathname);
2565
+ }
2566
+ catch {
2567
+ return false;
2568
+ }
2569
+ }
2570
+ function loadClassicScript(src) {
2571
+ return new Promise((resolve, reject) => {
2572
+ const script = document.createElement('script');
2573
+ script.async = true;
2574
+ script.src = src;
2575
+ script.addEventListener('load', () => resolve(), { once: true });
2576
+ script.addEventListener('error', () => reject(new Error()), { once: true });
2577
+ (document.head || document.documentElement).appendChild(script);
2578
+ });
2579
+ }
2505
2580
 
2506
2581
  const registryKey = Symbol.for('paypercut.checkout-js.developer-assistance');
2507
2582
  function getRegistry() {
@@ -2522,6 +2597,45 @@ function safelyUnregister(entry) {
2522
2597
  }
2523
2598
  entry.delegate = null;
2524
2599
  }
2600
+ function safelyAttach(entry, provider) {
2601
+ if (!entry.registered || entry.delegate)
2602
+ return;
2603
+ try {
2604
+ entry.delegate = provider.register(entry.target);
2605
+ }
2606
+ catch {
2607
+ // A target can register before its hosted component is ready. Keep the
2608
+ // provider available for the other targets and retry this one on refresh.
2609
+ }
2610
+ }
2611
+ function isTargetVisible(entry) {
2612
+ try {
2613
+ return entry.target.isVisible?.() ?? true;
2614
+ }
2615
+ catch {
2616
+ // Developer Assistance is optional. A stale owner node must never make the
2617
+ // merchant page fail while its visibility is being reconciled.
2618
+ return false;
2619
+ }
2620
+ }
2621
+ function syncAttachment(entry, registry) {
2622
+ if (!entry.registered)
2623
+ return;
2624
+ if (!isTargetVisible(entry)) {
2625
+ safelyUnregister(entry);
2626
+ return;
2627
+ }
2628
+ if (registry.provider?.version === SDK_VERSION) {
2629
+ safelyAttach(entry, registry.provider);
2630
+ return;
2631
+ }
2632
+ requestDeveloperAssistance(() => hasAttachedDeveloperAssistant(registry));
2633
+ }
2634
+ function hasAttachedDeveloperAssistant(registry) {
2635
+ if (registry.provider?.version !== SDK_VERSION)
2636
+ return false;
2637
+ return Array.from(registry.registrations).some((entry) => entry.registered && entry.delegate !== null);
2638
+ }
2525
2639
  function installDeveloperAssistantProvider(provider) {
2526
2640
  const registry = getRegistry();
2527
2641
  const incompatibleCoreVersion = Array.from(registry.coreVersions).find((version) => version !== provider.version);
@@ -2534,21 +2648,8 @@ function installDeveloperAssistantProvider(provider) {
2534
2648
  throw new Error(`[Paypercut Elements] Developer Assistance ${provider.version} cannot replace ${registry.provider.version}.`);
2535
2649
  }
2536
2650
  registry.provider = provider;
2537
- const attached = [];
2538
- try {
2539
- for (const entry of registry.registrations) {
2540
- if (!entry.registered)
2541
- continue;
2542
- entry.delegate = provider.register(entry.target);
2543
- attached.push(entry);
2544
- }
2545
- }
2546
- catch (error) {
2547
- for (const entry of attached.reverse()) {
2548
- safelyUnregister(entry);
2549
- }
2550
- registry.provider = null;
2551
- throw error;
2651
+ for (const entry of registry.registrations) {
2652
+ syncAttachment(entry, registry);
2552
2653
  }
2553
2654
  }
2554
2655