@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.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import React, { Component, ReactNode } from 'react';
2
+ import * as axios from 'axios';
2
3
  import { AxiosResponse, InternalAxiosRequestConfig, AxiosRequestConfig, AxiosInstance } from 'axios';
3
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
5
 
@@ -161,8 +162,8 @@ declare class UnifiedAuthService {
161
162
  }>;
162
163
  private getSavedAuthData;
163
164
  /**
164
- * 保存认证数据到本地存储
165
- */
165
+ * 保存认证数据到本地存储
166
+ */
166
167
  private saveAuthData;
167
168
  /**
168
169
  * 退出登录
@@ -359,9 +360,9 @@ declare function createClient(opts?: {
359
360
  authRequired?: boolean;
360
361
  baseUrl?: string;
361
362
  aiBaseUrl?: string;
362
- mode?: 'auto' | 'standalone' | 'embedded';
363
+ mode?: "auto" | "standalone" | "embedded";
363
364
  auth?: {
364
- mode?: 'none' | 'managed' | 'headless';
365
+ mode?: "none" | "managed" | "headless";
365
366
  getToken?: () => Promise<string | null>;
366
367
  tokenInjection?: {
367
368
  allowedOrigins?: string[];
@@ -375,7 +376,17 @@ declare function createClient(opts?: {
375
376
  aiRequestInstance?: Request;
376
377
  }): {
377
378
  projectId: string | null;
378
- request: any;
379
+ request: {
380
+ instance: axios.AxiosInstance;
381
+ request: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
382
+ get: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
383
+ post: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
384
+ put: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
385
+ patch: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
386
+ delete: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
387
+ cancelRequest: (url: string) => void;
388
+ cancelAllRequests: () => void;
389
+ };
379
390
  aiRequest: Request;
380
391
  workflowRequest: Request;
381
392
  artifacts: {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import React, { Component, ReactNode } from 'react';
2
+ import * as axios from 'axios';
2
3
  import { AxiosResponse, InternalAxiosRequestConfig, AxiosRequestConfig, AxiosInstance } from 'axios';
3
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
5
 
@@ -161,8 +162,8 @@ declare class UnifiedAuthService {
161
162
  }>;
162
163
  private getSavedAuthData;
163
164
  /**
164
- * 保存认证数据到本地存储
165
- */
165
+ * 保存认证数据到本地存储
166
+ */
166
167
  private saveAuthData;
167
168
  /**
168
169
  * 退出登录
@@ -359,9 +360,9 @@ declare function createClient(opts?: {
359
360
  authRequired?: boolean;
360
361
  baseUrl?: string;
361
362
  aiBaseUrl?: string;
362
- mode?: 'auto' | 'standalone' | 'embedded';
363
+ mode?: "auto" | "standalone" | "embedded";
363
364
  auth?: {
364
- mode?: 'none' | 'managed' | 'headless';
365
+ mode?: "none" | "managed" | "headless";
365
366
  getToken?: () => Promise<string | null>;
366
367
  tokenInjection?: {
367
368
  allowedOrigins?: string[];
@@ -375,7 +376,17 @@ declare function createClient(opts?: {
375
376
  aiRequestInstance?: Request;
376
377
  }): {
377
378
  projectId: string | null;
378
- request: any;
379
+ request: {
380
+ instance: axios.AxiosInstance;
381
+ request: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
382
+ get: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
383
+ post: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
384
+ put: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
385
+ patch: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
386
+ delete: (config: RequestConfig) => Promise<AxiosResponse<any, any>>;
387
+ cancelRequest: (url: string) => void;
388
+ cancelAllRequests: () => void;
389
+ };
379
390
  aiRequest: Request;
380
391
  workflowRequest: Request;
381
392
  artifacts: {
package/dist/index.js CHANGED
@@ -309,7 +309,7 @@ var FloatingButton = ({
309
309
  // src/services/unified-oauth.ts
310
310
  var UnifiedAuthService = class {
311
311
  constructor() {
312
- this.API_BASE_URL = "https://create-x-backend-dev";
312
+ this.API_BASE_URL = "https://create-x-backend-dev.fly.dev";
313
313
  }
314
314
  /**
315
315
  * 初始化 Google 登录流程
@@ -383,10 +383,8 @@ var UnifiedAuthService = class {
383
383
  };
384
384
  popupCheckInterval = window.setInterval(checkPopupStatus, 1e3);
385
385
  const messageHandler = (event) => {
386
- const validOrigins = [
387
- window.location.origin,
388
- "https://create-x-backend-dev"
389
- ];
386
+ console.log("messageHandler", event);
387
+ const validOrigins = [window.location.origin, "https://create-x-backend-dev.fly.dev"];
390
388
  const isValidOrigin = validOrigins.some(
391
389
  (origin) => event.origin === origin || event.origin.includes("localhost") || event.origin.includes("127.0.0.1") || event.origin.includes("fly.dev")
392
390
  );
@@ -646,7 +644,7 @@ var UnifiedAuthService = class {
646
644
  const response = await fetch(`${this.API_BASE_URL}/api/auth/verify`, {
647
645
  method: "GET",
648
646
  headers: {
649
- "Authorization": `Bearer ${token}`
647
+ Authorization: `Bearer ${token}`
650
648
  }
651
649
  });
652
650
  if (response.ok) {
@@ -677,8 +675,8 @@ var UnifiedAuthService = class {
677
675
  }
678
676
  }
679
677
  /**
680
- * 保存认证数据到本地存储
681
- */
678
+ * 保存认证数据到本地存储
679
+ */
682
680
  saveAuthData(token) {
683
681
  try {
684
682
  try {
@@ -699,7 +697,7 @@ var UnifiedAuthService = class {
699
697
  await fetch(`${this.API_BASE_URL}/api/auth/logout`, {
700
698
  method: "POST",
701
699
  headers: {
702
- "Authorization": `Bearer ${token}`
700
+ Authorization: `Bearer ${token}`
703
701
  }
704
702
  });
705
703
  } catch (error) {
@@ -1047,12 +1045,25 @@ function setupClearUrlTokenListener(opts) {
1047
1045
  }
1048
1046
 
1049
1047
  // src/services/index.ts
1048
+ function getGlobalAvailableToken() {
1049
+ try {
1050
+ return getToken() || null;
1051
+ } catch {
1052
+ return null;
1053
+ }
1054
+ }
1050
1055
  var request = new request_default({
1051
- baseURL: "https://create-x-backend-dev/api",
1056
+ baseURL: "https://create-x-backend-dev.fly.dev/api",
1052
1057
  timeout: 6e4,
1053
1058
  interceptors: {
1054
1059
  requestInterceptor: (config) => {
1055
1060
  config.headers = config.headers || {};
1061
+ if (!config.headers["Authorization"]) {
1062
+ const availableToken = getGlobalAvailableToken();
1063
+ if (availableToken) {
1064
+ config.headers["Authorization"] = `Bearer ${availableToken}`;
1065
+ }
1066
+ }
1056
1067
  return config;
1057
1068
  },
1058
1069
  requestInterceptorCatch: (err) => {
@@ -1072,6 +1083,12 @@ var aiRequest = new request_default({
1072
1083
  interceptors: {
1073
1084
  requestInterceptor: (config) => {
1074
1085
  config.headers = config.headers || {};
1086
+ if (!config.headers["Authorization"]) {
1087
+ const availableToken = getGlobalAvailableToken();
1088
+ if (availableToken) {
1089
+ config.headers["Authorization"] = `Bearer ${availableToken}`;
1090
+ }
1091
+ }
1075
1092
  return config;
1076
1093
  },
1077
1094
  requestInterceptorCatch: (err) => {
@@ -1127,6 +1144,12 @@ function createClient(opts) {
1127
1144
  interceptors: {
1128
1145
  requestInterceptor: (config) => {
1129
1146
  config.headers = config.headers || {};
1147
+ if (!config.headers["Authorization"]) {
1148
+ const availableToken = getAvailableToken();
1149
+ if (availableToken) {
1150
+ config.headers["Authorization"] = `Bearer ${availableToken}`;
1151
+ }
1152
+ }
1130
1153
  return config;
1131
1154
  },
1132
1155
  requestInterceptorCatch: (err) => Promise.reject(err),
@@ -1139,12 +1162,23 @@ function createClient(opts) {
1139
1162
  const ai = opts?.aiRequestInstance || makeRequestFromBase(opts?.aiBaseUrl) || aiRequest;
1140
1163
  const bizWrapped = wrapRequestWithProjectPrefix(biz, opts?.projectId);
1141
1164
  let token = null;
1165
+ function getAvailableToken() {
1166
+ return token || getGlobalAvailableToken();
1167
+ }
1142
1168
  try {
1143
1169
  if (opts?.projectId) {
1144
1170
  setDefaultProjectId(String(opts.projectId));
1145
1171
  }
1146
1172
  } catch {
1147
1173
  }
1174
+ try {
1175
+ const existingToken = getToken();
1176
+ if (existingToken) {
1177
+ token = existingToken;
1178
+ applyToken(token);
1179
+ }
1180
+ } catch {
1181
+ }
1148
1182
  function applyToken(t) {
1149
1183
  try {
1150
1184
  try {
@@ -1164,7 +1198,8 @@ function createClient(opts) {
1164
1198
  const runtimeMode = (() => {
1165
1199
  if (opts?.mode) return opts.mode;
1166
1200
  try {
1167
- if (typeof window !== "undefined") return window.self !== window.top ? "embedded" : "standalone";
1201
+ if (typeof window !== "undefined")
1202
+ return window.self !== window.top ? "embedded" : "standalone";
1168
1203
  } catch (_e) {
1169
1204
  return "standalone";
1170
1205
  }
@@ -1274,7 +1309,7 @@ function createClient(opts) {
1274
1309
  if (typeof window === "undefined") return;
1275
1310
  const loc = redirect || window.location.href;
1276
1311
  try {
1277
- const root = getAuthRoot() || "https://create-x-backend-dev";
1312
+ const root = getAuthRoot() || "https://create-x-backend-dev.fly.dev";
1278
1313
  const authUrl = new URL("/auth", String(root));
1279
1314
  authUrl.searchParams.set("redirect_uri", String(loc));
1280
1315
  if (opts?.projectId) authUrl.searchParams.set("project_id", String(opts.projectId));
@@ -1282,7 +1317,7 @@ function createClient(opts) {
1282
1317
  } catch {
1283
1318
  const encoded = encodeURIComponent(String(loc));
1284
1319
  const pid = opts?.projectId ? `&project_id=${encodeURIComponent(String(opts.projectId))}` : "";
1285
- const root = "https://create-x-backend-dev";
1320
+ const root = "https://create-x-backend-dev.fly.dev";
1286
1321
  window.location.href = `${root}/auth?redirect_uri=${encoded}${pid}`;
1287
1322
  }
1288
1323
  },
@@ -1701,7 +1736,7 @@ var HowoneAuthClient = class {
1701
1736
  }
1702
1737
  // Simple redirect-based login trigger (consumer can override)
1703
1738
  login() {
1704
- const root = getAuthRoot() || "https://create-x-backend-dev";
1739
+ const root = getAuthRoot() || "https://create-x-backend-dev.fly.dev";
1705
1740
  try {
1706
1741
  const loc = window.location.href;
1707
1742
  const authUrl = new URL("/auth", String(root));