From 356f94122a302906567dc56008da9ac6d7545342 Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:27:22 +0330 Subject: [PATCH] Import source: global/src/lib/api Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- global/src/lib/api.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 global/src/lib/api.js diff --git a/global/src/lib/api.js b/global/src/lib/api.js new file mode 100644 index 0000000..997f17a --- /dev/null +++ b/global/src/lib/api.js @@ -0,0 +1,23 @@ +// Fetch wrapper for Teknav Global — proxies to same backend as teknav.ir +const BASE = '/api/v1'; + +async function request(path, options = {}) { + const url = `${BASE}${path}`; + const res = await fetch(url, { + credentials: 'include', + headers: { 'Content-Type': 'application/json', ...options.headers }, + ...options, + }); + if (!res.ok) { + const err = await res.json().catch(() => ({ error: res.statusText })); + throw Object.assign(new Error(err.error || res.statusText), { status: res.status, data: err }); + } + return res.json(); +} + +export const api = { + get: (path) => request(path), + post: (path, body) => request(path, { method: 'POST', body: JSON.stringify(body) }), + patch: (path, body) => request(path, { method: 'PATCH', body: JSON.stringify(body) }), + del: (path) => request(path, { method: 'DELETE' }), +};