diff --git a/frontend/spa/src/utils/ftch.js b/frontend/spa/src/utils/ftch.js index 426cc1c..55df3ee 100644 --- a/frontend/spa/src/utils/ftch.js +++ b/frontend/spa/src/utils/ftch.js @@ -1,6 +1,7 @@ import {ofetch} from "ofetch"; const BASE_URL = '/'; +const isDev = import.meta.env.DEV; function encodeBase64Unicode(str) { return btoa(new TextEncoder().encode(str).reduce((data, byte) => data + String.fromCharCode(byte), '')); @@ -14,6 +15,7 @@ export const apiFetch = ofetch.create({ if (data) { const encoded = encodeBase64Unicode(data); options.headers = { + ...(isDev && { 'XDEBUG_TRIGGER': 'PHPSTORM' }), ...options.headers, 'X-Telegram-InitData': encoded, }; @@ -28,7 +30,16 @@ async function ftch(action, query = null, json = null) { if (query) options.query = query; if (json) options.body = json; - return await apiFetch(`${BASE_URL}index.php?route=extension/tgshop/handle&api_action=${action}`, options); + const xDebugTrigger = isDev ? '&XDEBUG_TRIGGER=phpstorm' : ''; + + return await apiFetch( + `${BASE_URL}index.php?route=extension/tgshop/handle&api_action=${action}${xDebugTrigger}`, + options + ); +} + +async function ftchPost(action, json = {}) { + return ftch(action, null, json); } export async function storeOrder(data) { @@ -115,4 +126,8 @@ export async function userPrivacyConsent() { return await ftch('userPrivacyConsent'); } +export async function ingest(data) { + return await ftchPost('ingest', data); +} + export default ftch;