@howone/sdk 0.1.16 → 0.1.18

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
@@ -254,7 +254,7 @@ var FloatingButton = ({
254
254
  // src/services/unified-oauth.ts
255
255
  var UnifiedAuthService = class {
256
256
  constructor() {
257
- this.API_BASE_URL = "https://create-x-backend-dev";
257
+ this.API_BASE_URL = "https://create-x-backend-dev.fly.dev";
258
258
  }
259
259
  /**
260
260
  * 初始化 Google 登录流程
@@ -328,10 +328,8 @@ var UnifiedAuthService = class {
328
328
  };
329
329
  popupCheckInterval = window.setInterval(checkPopupStatus, 1e3);
330
330
  const messageHandler = (event) => {
331
- const validOrigins = [
332
- window.location.origin,
333
- "https://create-x-backend-dev"
334
- ];
331
+ console.log("messageHandler", event);
332
+ const validOrigins = [window.location.origin, "https://create-x-backend-dev.fly.dev"];
335
333
  const isValidOrigin = validOrigins.some(
336
334
  (origin) => event.origin === origin || event.origin.includes("localhost") || event.origin.includes("127.0.0.1") || event.origin.includes("fly.dev")
337
335
  );
@@ -591,7 +589,7 @@ var UnifiedAuthService = class {
591
589
  const response = await fetch(`${this.API_BASE_URL}/api/auth/verify`, {
592
590
  method: "GET",
593
591
  headers: {
594
- "Authorization": `Bearer ${token}`
592
+ Authorization: `Bearer ${token}`
595
593
  }
596
594
  });
597
595
  if (response.ok) {
@@ -622,8 +620,8 @@ var UnifiedAuthService = class {
622
620
  }
623
621
  }
624
622
  /**
625
- * 保存认证数据到本地存储
626
- */
623
+ * 保存认证数据到本地存储
624
+ */
627
625
  saveAuthData(token) {
628
626
  try {
629
627
  try {
@@ -644,7 +642,7 @@ var UnifiedAuthService = class {
644
642
  await fetch(`${this.API_BASE_URL}/api/auth/logout`, {
645
643
  method: "POST",
646
644
  headers: {
647
- "Authorization": `Bearer ${token}`
645
+ Authorization: `Bearer ${token}`
648
646
  }
649
647
  });
650
648
  } catch (error) {
@@ -992,12 +990,25 @@ function setupClearUrlTokenListener(opts) {
992
990
  }
993
991
 
994
992
  // src/services/index.ts
993
+ function getGlobalAvailableToken() {
994
+ try {
995
+ return getToken() || null;
996
+ } catch {
997
+ return null;
998
+ }
999
+ }
995
1000
  var request = new request_default({
996
- baseURL: "https://create-x-backend-dev/api",
1001
+ baseURL: "https://create-x-backend-dev.fly.dev/api",
997
1002
  timeout: 6e4,
998
1003
  interceptors: {
999
1004
  requestInterceptor: (config) => {
1000
1005
  config.headers = config.headers || {};
1006
+ if (!config.headers["Authorization"]) {
1007
+ const availableToken = getGlobalAvailableToken();
1008
+ if (availableToken) {
1009
+ config.headers["Authorization"] = `Bearer ${availableToken}`;
1010
+ }
1011
+ }
1001
1012
  return config;
1002
1013
  },
1003
1014
  requestInterceptorCatch: (err) => {
@@ -1017,6 +1028,12 @@ var aiRequest = new request_default({
1017
1028
  interceptors: {
1018
1029
  requestInterceptor: (config) => {
1019
1030
  config.headers = config.headers || {};
1031
+ if (!config.headers["Authorization"]) {
1032
+ const availableToken = getGlobalAvailableToken();
1033
+ if (availableToken) {
1034
+ config.headers["Authorization"] = `Bearer ${availableToken}`;
1035
+ }
1036
+ }
1020
1037
  return config;
1021
1038
  },
1022
1039
  requestInterceptorCatch: (err) => {
@@ -1072,6 +1089,12 @@ function createClient(opts) {
1072
1089
  interceptors: {
1073
1090
  requestInterceptor: (config) => {
1074
1091
  config.headers = config.headers || {};
1092
+ if (!config.headers["Authorization"]) {
1093
+ const availableToken = getAvailableToken();
1094
+ if (availableToken) {
1095
+ config.headers["Authorization"] = `Bearer ${availableToken}`;
1096
+ }
1097
+ }
1075
1098
  return config;
1076
1099
  },
1077
1100
  requestInterceptorCatch: (err) => Promise.reject(err),
@@ -1084,12 +1107,23 @@ function createClient(opts) {
1084
1107
  const ai = opts?.aiRequestInstance || makeRequestFromBase(opts?.aiBaseUrl) || aiRequest;
1085
1108
  const bizWrapped = wrapRequestWithProjectPrefix(biz, opts?.projectId);
1086
1109
  let token = null;
1110
+ function getAvailableToken() {
1111
+ return token || getGlobalAvailableToken();
1112
+ }
1087
1113
  try {
1088
1114
  if (opts?.projectId) {
1089
1115
  setDefaultProjectId(String(opts.projectId));
1090
1116
  }
1091
1117
  } catch {
1092
1118
  }
1119
+ try {
1120
+ const existingToken = getToken();
1121
+ if (existingToken) {
1122
+ token = existingToken;
1123
+ applyToken(token);
1124
+ }
1125
+ } catch {
1126
+ }
1093
1127
  function applyToken(t) {
1094
1128
  try {
1095
1129
  try {
@@ -1109,7 +1143,8 @@ function createClient(opts) {
1109
1143
  const runtimeMode = (() => {
1110
1144
  if (opts?.mode) return opts.mode;
1111
1145
  try {
1112
- if (typeof window !== "undefined") return window.self !== window.top ? "embedded" : "standalone";
1146
+ if (typeof window !== "undefined")
1147
+ return window.self !== window.top ? "embedded" : "standalone";
1113
1148
  } catch (_e) {
1114
1149
  return "standalone";
1115
1150
  }
@@ -1219,7 +1254,7 @@ function createClient(opts) {
1219
1254
  if (typeof window === "undefined") return;
1220
1255
  const loc = redirect || window.location.href;
1221
1256
  try {
1222
- const root = getAuthRoot() || "https://create-x-backend-dev";
1257
+ const root = getAuthRoot() || "https://create-x-backend-dev.fly.dev";
1223
1258
  const authUrl = new URL("/auth", String(root));
1224
1259
  authUrl.searchParams.set("redirect_uri", String(loc));
1225
1260
  if (opts?.projectId) authUrl.searchParams.set("project_id", String(opts.projectId));
@@ -1227,7 +1262,7 @@ function createClient(opts) {
1227
1262
  } catch {
1228
1263
  const encoded = encodeURIComponent(String(loc));
1229
1264
  const pid = opts?.projectId ? `&project_id=${encodeURIComponent(String(opts.projectId))}` : "";
1230
- const root = "https://create-x-backend-dev";
1265
+ const root = "https://create-x-backend-dev.fly.dev";
1231
1266
  window.location.href = `${root}/auth?redirect_uri=${encoded}${pid}`;
1232
1267
  }
1233
1268
  },
@@ -1646,7 +1681,7 @@ var HowoneAuthClient = class {
1646
1681
  }
1647
1682
  // Simple redirect-based login trigger (consumer can override)
1648
1683
  login() {
1649
- const root = getAuthRoot() || "https://create-x-backend-dev";
1684
+ const root = getAuthRoot() || "https://create-x-backend-dev.fly.dev";
1650
1685
  try {
1651
1686
  const loc = window.location.href;
1652
1687
  const authUrl = new URL("/auth", String(root));