feat: send xdebug trigger from frontend

This commit is contained in:
2025-11-30 11:47:21 +03:00
committed by Nikita Kiselev
parent 51f462922e
commit 2743b83a2c

View File

@@ -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;