@howone/sdk 0.2.6 → 0.2.7

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.mjs CHANGED
@@ -894,7 +894,7 @@ var LoginForm = ({
894
894
 
895
895
  // src/components/auth/HowoneProvider.tsx
896
896
  init_auth();
897
- import { createContext as createContext2, useContext as useContext2, useState as useState7, useEffect as useEffect6 } from "react";
897
+ import { createContext as createContext2, useContext as useContext2, useState as useState7, useEffect as useEffect6, useMemo } from "react";
898
898
 
899
899
  // src/components/theme/ThemeProvider.tsx
900
900
  import { createContext, useContext, useEffect as useEffect3, useState as useState3 } from "react";
@@ -3108,6 +3108,7 @@ var ErrorTracking = class {
3108
3108
  window.addEventListener("unhandledrejection", (event) => {
3109
3109
  event.preventDefault();
3110
3110
  const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
3111
+ 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);
3111
3112
  this.handleError(error, {
3112
3113
  type: "promise",
3113
3114
  source: "unhandledrejection"
@@ -3142,7 +3143,12 @@ var ErrorTracking = class {
3142
3143
  */
3143
3144
  safeForwardConsoleToParent(method, args) {
3144
3145
  if (window.parent === window) return;
3145
- if (!this.fullyInitialized) return;
3146
+ const argsStr = args.map((arg) => String(arg)).join(" ").toLowerCase();
3147
+ const is504Error = argsStr.includes("504") || argsStr.includes("gateway timeout");
3148
+ if (is504Error) {
3149
+ 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));
3150
+ }
3151
+ if (!is504Error && !this.fullyInitialized) return;
3146
3152
  try {
3147
3153
  let stack = null;
3148
3154
  if (method === "warn" || method === "error") {
@@ -3363,6 +3369,9 @@ var ErrorTracking = class {
3363
3369
  sendUnifiedError(error, details = {}) {
3364
3370
  if (window.parent === window) return;
3365
3371
  const isCriticalError = this.isCriticalNetworkError(error, details);
3372
+ if (isCriticalError) {
3373
+ 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);
3374
+ }
3366
3375
  if (!isCriticalError && !this.fullyInitialized) {
3367
3376
  return;
3368
3377
  }
@@ -4737,6 +4746,7 @@ var ErrorHandler = class {
4737
4746
  };
4738
4747
 
4739
4748
  // src/components/auth/HowoneProvider.tsx
4749
+ init_config();
4740
4750
  import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
4741
4751
  var globalErrorHandler = null;
4742
4752
  var initializeErrorHandler = () => {
@@ -4760,7 +4770,6 @@ var HowOneProvider = ({
4760
4770
  defaultTheme = "system",
4761
4771
  themeStorageKey = "howone-theme",
4762
4772
  forceDefaultTheme = false,
4763
- authUrl = "https://howone.dev/auth",
4764
4773
  redirectOnUnauthenticated = true
4765
4774
  }) => {
4766
4775
  const [user, setUser] = useState7(() => parseUserFromToken(getToken()));
@@ -4791,6 +4800,18 @@ var HowOneProvider = ({
4791
4800
  setHasCheckedUrlToken(true);
4792
4801
  }
4793
4802
  }, []);
4803
+ const resolvedAuthUrl = useMemo(() => {
4804
+ const env2 = getGlobalEnvironment() ?? "dev";
4805
+ switch (env2) {
4806
+ case "local":
4807
+ return "http://localhost:3000/auth";
4808
+ case "prod":
4809
+ return "https://howone.ai/auth";
4810
+ case "dev":
4811
+ default:
4812
+ return "https://howone.dev/auth";
4813
+ }
4814
+ }, []);
4794
4815
  useEffect6(() => {
4795
4816
  if (!hasCheckedUrlToken) {
4796
4817
  return;
@@ -4799,7 +4820,7 @@ var HowOneProvider = ({
4799
4820
  const currentUrl = new URL(window.location.href);
4800
4821
  if (!currentUrl.pathname.includes("/auth")) {
4801
4822
  try {
4802
- const authUrlObj = new URL(authUrl);
4823
+ const authUrlObj = new URL(resolvedAuthUrl);
4803
4824
  const redirectUri = window.location.href;
4804
4825
  authUrlObj.searchParams.set("redirect_uri", redirectUri);
4805
4826
  if (projectId) {
@@ -4808,11 +4829,11 @@ var HowOneProvider = ({
4808
4829
  window.location.href = authUrlObj.toString();
4809
4830
  } catch (error) {
4810
4831
  console.error("[HowOneProvider] Failed to build auth URL:", error);
4811
- window.location.href = authUrl;
4832
+ window.location.href = resolvedAuthUrl;
4812
4833
  }
4813
4834
  }
4814
4835
  }
4815
- }, [token, user, redirectOnUnauthenticated, authUrl, projectId, hasCheckedUrlToken]);
4836
+ }, [token, user, redirectOnUnauthenticated, resolvedAuthUrl, projectId, hasCheckedUrlToken]);
4816
4837
  const logout = () => {
4817
4838
  try {
4818
4839
  setToken(null);