@howone/sdk 0.2.6 → 0.2.8

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.d.mts CHANGED
@@ -444,7 +444,6 @@ interface HowOneProviderProps {
444
444
  defaultTheme?: Theme$1;
445
445
  themeStorageKey?: string;
446
446
  forceDefaultTheme?: boolean;
447
- authUrl?: string;
448
447
  redirectOnUnauthenticated?: boolean;
449
448
  }
450
449
  /**
@@ -462,7 +461,6 @@ interface HowOneProviderProps {
462
461
  * defaultTheme="dark"
463
462
  * themeStorageKey="my-app-theme"
464
463
  * showFloatingButton={true}
465
- * authUrl="https://howone.dev/auth"
466
464
  * redirectOnUnauthenticated={true}
467
465
  * >
468
466
  * <App />
package/dist/index.d.ts CHANGED
@@ -444,7 +444,6 @@ interface HowOneProviderProps {
444
444
  defaultTheme?: Theme$1;
445
445
  themeStorageKey?: string;
446
446
  forceDefaultTheme?: boolean;
447
- authUrl?: string;
448
447
  redirectOnUnauthenticated?: boolean;
449
448
  }
450
449
  /**
@@ -462,7 +461,6 @@ interface HowOneProviderProps {
462
461
  * defaultTheme="dark"
463
462
  * themeStorageKey="my-app-theme"
464
463
  * showFloatingButton={true}
465
- * authUrl="https://howone.dev/auth"
466
464
  * redirectOnUnauthenticated={true}
467
465
  * >
468
466
  * <App />
package/dist/index.js CHANGED
@@ -587,7 +587,7 @@ var UnifiedAuthService = class {
587
587
  }
588
588
  generateAppId() {
589
589
  const urlParams = new URLSearchParams(window.location.search);
590
- let appId = urlParams.get("appId");
590
+ let appId = urlParams.get("appId") || urlParams.get("project_id");
591
591
  return appId || "app";
592
592
  }
593
593
  /**
@@ -3157,6 +3157,7 @@ var ErrorTracking = class {
3157
3157
  this.setupGlobalErrorListeners();
3158
3158
  this.setupConsoleInterception();
3159
3159
  this.setupNetworkMonitoring();
3160
+ this.setupResourceLoadMonitoring();
3160
3161
  this.initialized = true;
3161
3162
  setTimeout(() => {
3162
3163
  this.fullyInitialized = true;
@@ -3167,7 +3168,7 @@ var ErrorTracking = class {
3167
3168
  */
3168
3169
  setupGlobalErrorListeners() {
3169
3170
  window.addEventListener("error", (event) => {
3170
- event.preventDefault();
3171
+ this.internalLog("warn", "\u{1F3AF}\u{1F3AF}\u{1F3AF} window.error \u4E8B\u4EF6\u89E6\u53D1:", event.message || event.error?.message);
3171
3172
  this.handleError(event.error || new Error(event.message), {
3172
3173
  filename: event.filename,
3173
3174
  lineno: event.lineno,
@@ -3177,8 +3178,8 @@ var ErrorTracking = class {
3177
3178
  });
3178
3179
  });
3179
3180
  window.addEventListener("unhandledrejection", (event) => {
3180
- event.preventDefault();
3181
3181
  const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
3182
+ this.internalLog("warn", "\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u6355\u83B7 unhandledrejection:", error.message);
3182
3183
  this.handleError(error, {
3183
3184
  type: "promise",
3184
3185
  source: "unhandledrejection"
@@ -3213,7 +3214,12 @@ var ErrorTracking = class {
3213
3214
  */
3214
3215
  safeForwardConsoleToParent(method, args) {
3215
3216
  if (window.parent === window) return;
3216
- if (!this.fullyInitialized) return;
3217
+ const argsStr = args.map((arg) => String(arg)).join(" ").toLowerCase();
3218
+ const is504Error = argsStr.includes("504") || argsStr.includes("gateway timeout");
3219
+ if (is504Error) {
3220
+ this.internalLog("warn", "\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}[ErrorTracking] \u63A7\u5236\u53F0\u6355\u83B7 504 \u9519\u8BEF:", argsStr.substring(0, 100));
3221
+ }
3222
+ if (!is504Error && !this.fullyInitialized) return;
3217
3223
  try {
3218
3224
  let stack = null;
3219
3225
  if (method === "warn" || method === "error") {
@@ -3289,6 +3295,43 @@ var ErrorTracking = class {
3289
3295
  this.internalLog("error", "[ErrorTracking] \u63A7\u5236\u53F0\u8F6C\u53D1\u5931\u8D25:", error);
3290
3296
  }
3291
3297
  }
3298
+ /**
3299
+ * 设置资源加载监控(使用 PerformanceObserver 监控 504 错误)
3300
+ */
3301
+ setupResourceLoadMonitoring() {
3302
+ if (!window.PerformanceObserver) {
3303
+ this.internalLog("warn", "\u274C\u274C\u274CPerformanceObserver \u4E0D\u652F\u6301\u274C\u274C\u274C");
3304
+ return;
3305
+ }
3306
+ try {
3307
+ const observer = new PerformanceObserver((list) => {
3308
+ for (const entry of list.getEntries()) {
3309
+ console.log("\u{1F30D}\u{1F30D}entry---------entry\u{1F30D}\u{1F30D}", entry);
3310
+ if (entry.entryType === "resource") {
3311
+ const resourceEntry = entry;
3312
+ if (resourceEntry.transferSize === 0 && !resourceEntry.duration) {
3313
+ const url = resourceEntry.name;
3314
+ console.log("\u{1F30D}\u{1F30D}url--------------url\u{1F30D}\u{1F30D}", url);
3315
+ if (url.includes(".js") || url.includes(".mjs")) {
3316
+ this.internalLog("error", "\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u68C0\u6D4B\u5230\u8D44\u6E90\u52A0\u8F7D\u5931\u8D25\uFF08\u53EF\u80FD\u662F 504\uFF09:", url);
3317
+ this.handleError(new Error(`Resource load failed (possibly 504): ${url}`), {
3318
+ type: "resource",
3319
+ resourceUrl: url,
3320
+ source: "PerformanceObserver",
3321
+ transferSize: resourceEntry.transferSize,
3322
+ duration: resourceEntry.duration
3323
+ });
3324
+ }
3325
+ }
3326
+ }
3327
+ }
3328
+ });
3329
+ observer.observe({ entryTypes: ["resource"] });
3330
+ this.internalLog("log", "\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u5DF2\u542F\u52A8\uFF0C\u76D1\u63A7\u8D44\u6E90\u52A0\u8F7D");
3331
+ } catch (error) {
3332
+ this.internalLog("error", "\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274CPerformanceObserver \u8BBE\u7F6E\u5931\u8D25:", error);
3333
+ }
3334
+ }
3292
3335
  /**
3293
3336
  * 设置网络监控
3294
3337
  */
@@ -3422,11 +3465,18 @@ var ErrorTracking = class {
3422
3465
  return false;
3423
3466
  }
3424
3467
  /**
3425
- * 判断是否是 504 错误,需要立即发送
3468
+ * 判断是否是 504 错误或资源加载失败,需要立即发送
3426
3469
  */
3427
3470
  isCriticalNetworkError(error, details) {
3428
3471
  const message = error.message?.toLowerCase() || "";
3429
- return message.includes("504") || message.includes("gateway timeout");
3472
+ console.log("\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705", message, details);
3473
+ if (message.includes("504") || message.includes("gateway timeout")) {
3474
+ return true;
3475
+ }
3476
+ if (details.type === "resource" && details.source === "PerformanceObserver") {
3477
+ return true;
3478
+ }
3479
+ return false;
3430
3480
  }
3431
3481
  /**
3432
3482
  * 发送统一格式的错误
@@ -3434,6 +3484,11 @@ var ErrorTracking = class {
3434
3484
  sendUnifiedError(error, details = {}) {
3435
3485
  if (window.parent === window) return;
3436
3486
  const isCriticalError = this.isCriticalNetworkError(error, details);
3487
+ console.log("\u53D1\u73B0504\u9519\u8BEF\u4E86\u5417\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", isCriticalError);
3488
+ if (isCriticalError) {
3489
+ this.internalLog("warn", "\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u68C0\u6D4B\u5230 504 \u9519\u8BEF\uFF0C\u7ACB\u5373\u53D1\u9001:", error.message);
3490
+ }
3491
+ console.log("\u7B2C\u4E8C\u4E2A\u5224\u65AD\u662F\u4EC0\u4E48\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", this.fullyInitialized);
3437
3492
  if (!isCriticalError && !this.fullyInitialized) {
3438
3493
  return;
3439
3494
  }
@@ -4808,6 +4863,7 @@ var ErrorHandler = class {
4808
4863
  };
4809
4864
 
4810
4865
  // src/components/auth/HowoneProvider.tsx
4866
+ init_config();
4811
4867
  var import_jsx_runtime7 = require("react/jsx-runtime");
4812
4868
  var globalErrorHandler = null;
4813
4869
  var initializeErrorHandler = () => {
@@ -4831,7 +4887,6 @@ var HowOneProvider = ({
4831
4887
  defaultTheme = "system",
4832
4888
  themeStorageKey = "howone-theme",
4833
4889
  forceDefaultTheme = false,
4834
- authUrl = "https://howone.dev/auth",
4835
4890
  redirectOnUnauthenticated = true
4836
4891
  }) => {
4837
4892
  const [user, setUser] = (0, import_react8.useState)(() => parseUserFromToken(getToken()));
@@ -4862,6 +4917,18 @@ var HowOneProvider = ({
4862
4917
  setHasCheckedUrlToken(true);
4863
4918
  }
4864
4919
  }, []);
4920
+ const resolvedAuthUrl = (0, import_react8.useMemo)(() => {
4921
+ const env2 = getGlobalEnvironment() ?? "dev";
4922
+ switch (env2) {
4923
+ case "local":
4924
+ return "http://localhost:3000/auth";
4925
+ case "prod":
4926
+ return "https://howone.ai/auth";
4927
+ case "dev":
4928
+ default:
4929
+ return "https://howone.dev/auth";
4930
+ }
4931
+ }, []);
4865
4932
  (0, import_react8.useEffect)(() => {
4866
4933
  if (!hasCheckedUrlToken) {
4867
4934
  return;
@@ -4870,7 +4937,7 @@ var HowOneProvider = ({
4870
4937
  const currentUrl = new URL(window.location.href);
4871
4938
  if (!currentUrl.pathname.includes("/auth")) {
4872
4939
  try {
4873
- const authUrlObj = new URL(authUrl);
4940
+ const authUrlObj = new URL(resolvedAuthUrl);
4874
4941
  const redirectUri = window.location.href;
4875
4942
  authUrlObj.searchParams.set("redirect_uri", redirectUri);
4876
4943
  if (projectId) {
@@ -4879,11 +4946,11 @@ var HowOneProvider = ({
4879
4946
  window.location.href = authUrlObj.toString();
4880
4947
  } catch (error) {
4881
4948
  console.error("[HowOneProvider] Failed to build auth URL:", error);
4882
- window.location.href = authUrl;
4949
+ window.location.href = resolvedAuthUrl;
4883
4950
  }
4884
4951
  }
4885
4952
  }
4886
- }, [token, user, redirectOnUnauthenticated, authUrl, projectId, hasCheckedUrlToken]);
4953
+ }, [token, user, redirectOnUnauthenticated, resolvedAuthUrl, projectId, hasCheckedUrlToken]);
4887
4954
  const logout = () => {
4888
4955
  try {
4889
4956
  setToken(null);