import '../chunk-BJTO5JO5.mjs';

// src/request/adapters/web-adapter.ts
var WebRequestAdapter = class {
  async request(config) {
    const { url, method = "GET", headers = {}, body, params } = config;
    let fullUrl = url;
    if (params) {
      const searchParams = new URLSearchParams();
      Object.entries(params).forEach(([key, value]) => {
        if (value !== void 0 && value !== null) {
          searchParams.append(key, String(value));
        }
      });
      const queryString = searchParams.toString();
      if (queryString) {
        fullUrl += (url.includes("?") ? "&" : "?") + queryString;
      }
    }
    const response = await fetch(fullUrl, {
      method,
      headers: {
        "Content-Type": "application/json",
        ...headers
      },
      body: body ? JSON.stringify(body) : void 0,
      credentials: "include"
      // 🔐 自动发送和接收 Cookie（支持 httpOnly Cookie 认证）
    });
    const data = await response.json();
    if (!response.ok) {
      return {
        success: false,
        error: data.error || "\u8BF7\u6C42\u5931\u8D25: " + response.status
      };
    }
    return data;
  }
};

// src/request/adapters/miniapp-adapter.ts
var MiniappRequestAdapter = class {
  constructor(taro) {
    if (!taro) {
      throw new Error("MiniappRequestAdapter requires Taro instance");
    }
    this.taro = taro;
  }
  async request(config) {
    const { url, method = "GET", headers = {}, body, params } = config;
    try {
      const response = await this.taro.request({
        url,
        method,
        header: {
          "Content-Type": "application/json",
          ...headers
        },
        data: method === "GET" ? params : body
      });
      const data = response.data;
      if (response.statusCode >= 200 && response.statusCode < 300) {
        return data;
      } else {
        return {
          success: false,
          error: data.error || "\u8BF7\u6C42\u5931\u8D25: " + response.statusCode
        };
      }
    } catch (error) {
      console.error("[MiniappRequestAdapter] request error:", error);
      return {
        success: false,
        error: error instanceof Error ? error.message : "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"
      };
    }
  }
};

export { MiniappRequestAdapter, WebRequestAdapter };
//# sourceMappingURL=index.mjs.map
//# sourceMappingURL=index.mjs.map