* * @param {object} obj - the object to serialize * @param {string} prefix - The prefix to use for the key * @returns {string} - string as a query **/function t_store__serializeData(obj, prefix) { var str = []; for (var property in obj) { if (Object.prototype.hasOwnProperty.call(obj, property)) { var key = prefix ? prefix + '[' + property + ']' : property; var value = obj[property]; var stringifyValue = JSON.stringify(value); if (stringifyValue !== '{}' && value !== null) { str.push( value !== null && typeof value === 'object' ? t_store__serializeData(value, key) : encodeURIComponent(key) + '=' + encodeURIComponent(value) ); } } } return str.join('&');}/** * If the error is a timeout, the endpoint is changed to store2.tildacdn.com * * @param {object} error - The error object. * @param {Function} callback - A function that will be called when the request is complete. **/function t_store_changeEndpoint(error, callback) { if ( error && (error.status >= 500 || error.status == 408 || error.status == 410 || error.status == 429 || error.type === 'timeout') && window.t_store_endpoint.indexOf('store.tilda') !== -1 ) { const rootzoneapi = t_store__getRootZone(); window.t_store_endpoint = 'store2.tildaapi.' + rootzoneapi; if (typeof callback === 'function') { callback(); } } else { var text; if (error && error.responseText > '') { text = '[' + error.status + '] ' + error.responseText; } else if (error && error.statusText) { text = 'Error [' + error.status + ', ' + error.statusText + ']'; } else { text = 'Error type [' + error.type + ']'; } console.error(text + '. Please, try again later.'); }}/** * Обрабатывает ответ запроса и если в нем есть редирект на другую зону, обновляет конечную точку API * @param {string | object} responseData * @param {string} previousEndpoint - конечная точка API, которая была до выполнения запроса. Из нее извлекается рутзона * @returns {boolean} была ли изменена рутзона */function t_store__handleRootzoneRedirect(responseData, previousEndpoint) { let json = responseData; if (typeof responseData === 'string') { try { json = JSON.parse(responseData); } catch (error) { return false; } } const newRootZone = json?.redirectto; if (!newRootZone) { return false; } const previousRootZone = t_store__getRootZoneFromEndpoint(previousEndpoint); const isRootzoneChanged = previousRootZone !== newRootZone; if (isRootzoneChanged) { window.t_store_endpoint = window.t_store_endpoint.split('.').slice(0, -1).join('.') + '.' + newRootZone; } t_store__setRootZone(newRootZone); return isRootzoneChanged;}