1/** 2 * Woo Fraud Protection - Blackbox Initialization 3 * 4 * Configures the Blackbox JS SDK and exposes shared utilities on 5 * window.wcFraudProtection for checkout integration scripts. 6 * Only set when the SDK is present and configured. 7 */ 8( function () { 9 'use strict'; 10 11 const fraudProtection = window.wcFraudProtection; 12 if ( ! fraudProtection || ! fraudProtection.config ) { 13 return; 14 } 15 16 if ( 17 ! window.Blackbox || 18 ! window.Blackbox.configure || 19 ! window.Blackbox.init 20 ) { 21 return; 22 } 23 24 window.Blackbox.configure( { 25 apiKey: fraudProtection.config.apiKey, 26 identityKey: fraudProtection.config.identityKey, 27 } ); 28 29 // Fire-and-forget: the SDK wraps errors into a returned BlackboxError rather than 30 // throwing, and downstream consumers already fail open on empty session IDs. 31 window.Blackbox.init(); 32 33 /** 34 * Acquire a Blackbox session ID (fail-open: empty string on timeout/error). 35 * 36 * @return {Promise<string>} Session ID or empty string. 37 */ 38 fraudProtection.acquireSessionId = function () { 39 if ( ! window.Blackbox || ! window.Blackbox.getSessionId ) { 40 return Promise.resolve( '' ); 41 } 42 43 const timeout = new Promise( function ( resolve ) { 44 setTimeout( function () { 45 resolve( '' ); 46 }, fraudProtection.config.timeout ); 47 } ); 48 49 return Promise.race( [ window.Blackbox.getSessionId(), timeout ] ) 50 .then( function ( result ) { 51 return typeof result === 'string' ? result : ''; 52 } ) 53 .catch( function () { 54 return ''; 55 } ); 56 }; 57 58 /** 59 * Reset Blackbox state. Silently no-ops if reset is unavailable. 60 */ 61 fraudProtection.reset = function () { 62 if ( window.Blackbox && window.Blackbox.reset ) { 63 window.Blackbox.reset().catch( function () {} ); 64 } 65 }; 66} )();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.