<commit_before>/* @flow */

import { config } from './config';
import { responder } from './responder';
import { isLatest, getVersion, isXComponent } from './component';
import { loadScript, warn } from './util';

export let integrationResponder = responder();

function getIntegrationURLs() : { latest : boolean, major : string, minor : string } {

    return {
        latest: isLatest(),
        major:  config.checkoutjs_url.replace('{version}', ''),
        minor:  config.checkoutjs_url.replace('{version}', `.${getVersion()}`)
    };
}

function loadCheckoutIntegration(callback : (err : ?Error, result : ?mixed) => void) : void {

    if (!isXComponent()) {
        return callback(null, null);
    }

    let urls = getIntegrationURLs();

    loadScript(urls.latest ? urls.major : urls.minor, config.xchild_global, (err, result) => {

        if (err && !urls.latest) {
            return loadScript(urls.major, config.xchild_global, callback);
        }

        return callback(err, result);
    });
}

loadCheckoutIntegration((err : ?Error, result : ?mixed) : void => {

    if (err) {
        warn('Failed to load checkout.js', err.stack || err.toString());
    }

    if (err || result) {
        return integrationResponder.respond(err, result);
    }
});<commit_msg>Cache-bust for retried child loader<commit_after>/* @flow */

import { config } from './config';
import { responder } from './responder';
import { isLatest, getVersion, isXComponent } from './component';
import { loadScript, warn } from './util';

export let integrationResponder = responder();

function getIntegrationURLs() : { latest : boolean, major : string, minor : string } {

    return {
        latest: isLatest(),
        major:  config.checkoutjs_url.replace('{version}', ''),
        minor:  config.checkoutjs_url.replace('{version}', `.${getVersion()}`)
    };
}

function loadCheckoutIntegration(callback : (err : ?Error, result : ?mixed) => void) : void {

    if (!isXComponent()) {
        return callback(null, null);
    }

    let urls = getIntegrationURLs();

    loadScript(urls.latest ? urls.major : urls.minor, config.xchild_global, (err, result) => {

        if (err && !urls.latest) {
            return loadScript(`${urls.major}?t=${Date.now()}`, config.xchild_global, callback);
        }

        return callback(err, result);
    });
}

loadCheckoutIntegration((err : ?Error, result : ?mixed) : void => {

    if (err) {
        warn('Failed to load checkout.js', err.stack || err.toString());
    }

    if (err || result) {
        return integrationResponder.respond(err, result);
    }
});
{'fraction_non_alphanumeric': 0.1611047180667434, 'fraction_numerical': 0.0, 'mean_word_length': 3.146263910969793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '722785', 'n_tokens_mistral': 808, 'n_tokens_neox': 789, 'n_words': 188}