seacloud-sdk 0.12.3 → 0.12.4

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/dist/index.js CHANGED
@@ -114,9 +114,26 @@ async function getApiToken(providedApiKey) {
114
114
  }
115
115
  return "";
116
116
  }
117
+ function checkIsDevelopmentHost(host) {
118
+ const devHostPatterns = ["localhost", "127.0.0.1", ":3000", ":8080", "seaverse.dev"];
119
+ return devHostPatterns.some((pattern) => host.includes(pattern));
120
+ }
117
121
  function createConfig(options = {}) {
118
122
  const apiKey = options.apiKey;
119
- const baseUrl = options.baseUrl || (typeof process !== "undefined" ? process.env?.SEACLOUD_BASE_URL : void 0) || "https://proxy-rs.seaverse.ai";
123
+ let baseUrl;
124
+ if (options.baseUrl) {
125
+ baseUrl = options.baseUrl;
126
+ } else if (typeof process !== "undefined" && process.env?.SEACLOUD_BASE_URL) {
127
+ baseUrl = process.env.SEACLOUD_BASE_URL;
128
+ } else {
129
+ const currentHost = typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined" ? globalThis.window.location.host : "";
130
+ if (checkIsDevelopmentHost(currentHost)) {
131
+ baseUrl = "https://proxy-rs.sg.seaverse.dev";
132
+ console.log("[SeaCloud SDK] \u68C0\u6D4B\u5230\u5F00\u53D1\u73AF\u5883\uFF08currentHost\uFF09\uFF0C\u4F7F\u7528\u5F00\u53D1 baseUrl:", baseUrl);
133
+ } else {
134
+ baseUrl = "https://proxy-rs.seaverse.ai";
135
+ }
136
+ }
120
137
  const fetchImpl = options.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : void 0);
121
138
  if (!fetchImpl) {
122
139
  throw new Error("fetch is not available. Please provide a fetch implementation in config or upgrade to Node.js 18+");
@@ -288,10 +305,8 @@ async function initSeacloud(apiKeyOrConfig, options) {
288
305
  try {
289
306
  const parentHost = await getHostFromParent(3e3);
290
307
  if (parentHost) {
291
- const devHostPatterns = ["localhost", "127.0.0.1", ":3000", ":8080", "seaverse.dev"];
292
308
  const currentHost = typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined" ? globalThis.window.location.host : "";
293
- const checkIsDev = (host) => devHostPatterns.some((pattern) => host.includes(pattern));
294
- const isDevelopment = checkIsDev(currentHost) || checkIsDev(parentHost);
309
+ const isDevelopment = checkIsDevelopmentHost(currentHost) || checkIsDevelopmentHost(parentHost);
295
310
  if (isDevelopment) {
296
311
  config.baseUrl = "https://proxy-rs.sg.seaverse.dev";
297
312
  console.log("[SeaCloud SDK] \u68C0\u6D4B\u5230\u5F00\u53D1\u73AF\u5883\uFF0C\u4F7F\u7528\u5F00\u53D1 baseUrl:", config.baseUrl);