itube-specs 0.0.483 → 0.0.484

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "itube-specs",
3
3
  "type": "module",
4
- "version": "0.0.483",
4
+ "version": "0.0.484",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "./types/index.d.ts",
7
7
  "scripts": {
@@ -1,29 +1,17 @@
1
1
  import type { H3Event } from "h3";
2
+ import { getHeaders } from "h3";
3
+ import type { FetchOptions } from "ofetch";
2
4
 
3
- /** Класс для работы с серверным API (бекенд) */
4
5
  export class ServerApiHelper {
5
- /**
6
- * Универсальный метод для запросов к бэкенду
7
- * Использует $fetch на сервере вызывает внутренние маршруты напрямую (без сети)
8
- */
9
- public static async fetch<T>(
10
- url: string,
11
- event: H3Event,
12
- requestOptions: RequestInit = {}
13
- ): Promise<T> {
14
- try {
15
- const response = await $fetch(url, {
16
- headers: getHeaders(event),
17
- ...requestOptions,
18
- });
19
-
20
- // Если бэкенд всегда возвращает { data: ... }
21
- return response?.data as T;
22
-
23
- // Альтернатива: если иногда просто объект — можно так
24
- // return response as T;
25
- } catch (err: any) {
26
- throw new Error(`Cannot fetch: ${err?.data || err?.message || err}`);
6
+ public static async fetch<T>(url: string, event: H3Event, requestOptions?: FetchOptions): Promise<T> {
7
+ try {
8
+ const response = await $fetch<{ data: T }>(url, {
9
+ headers: getHeaders(event),
10
+ ...requestOptions,
11
+ });
12
+ return response.data;
13
+ } catch (error: any) {
14
+ throw new Error(`Cannot fetch ${url}: ${error?.data ?? error?.message ?? error}`);
15
+ }
27
16
  }
28
- }
29
17
  }