@tacoreai/web-sdk 1.11.0 → 1.13.0

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.
@@ -7,6 +7,10 @@ const previewSessionPromiseCache = new Map();
7
7
  const PREVIEW_TOKEN_HEADER = "X-Tacore-AppServer-Preview-Token";
8
8
  const APPSERVER_REQUEST_DATA_FIELD = "requestData";
9
9
  const DEFAULT_FILE_FIELD_NAME = "file";
10
+ const REMOTE_REQUEST_HEADER_MODE = {
11
+ ACCESS_TOKEN_ONLY: "access-token-only",
12
+ APPS_CLIENT: "apps-client",
13
+ };
10
14
 
11
15
  const isBrowserPreviewRuntime = () => {
12
16
  if (typeof window === "undefined") {
@@ -304,15 +308,34 @@ const normalizeAppServerFiles = (files) => {
304
308
  return normalizeSingleFileInput(files, DEFAULT_FILE_FIELD_NAME);
305
309
  };
306
310
 
307
- const buildRemoteRequestInit = function(payload, options = {}, extraHeaders = {}) {
308
- const requestPayload = typeof payload === "undefined" ? {} : payload;
309
- const normalizedFiles = normalizeAppServerFiles(options.files);
311
+ const buildRemoteRequestHeaders = function(extraHeaders = {}, headerMode = REMOTE_REQUEST_HEADER_MODE.ACCESS_TOKEN_ONLY) {
312
+ if (headerMode === REMOTE_REQUEST_HEADER_MODE.APPS_CLIENT && typeof this._getRequestHeaders === "function") {
313
+ return this._getRequestHeaders(extraHeaders);
314
+ }
315
+
310
316
  const headers = { ...extraHeaders };
311
317
  const authorizationHeader = getAccessTokenHeaderValue.call(this);
312
318
  if (authorizationHeader && !headers.Authorization && !headers.authorization) {
313
319
  headers.Authorization = authorizationHeader;
314
320
  }
315
321
 
322
+ return headers;
323
+ };
324
+
325
+ const buildRemoteRequestInit = function(
326
+ payload,
327
+ options = {},
328
+ extraHeaders = {},
329
+ requestOptions = {}
330
+ ) {
331
+ const requestPayload = typeof payload === "undefined" ? {} : payload;
332
+ const normalizedFiles = normalizeAppServerFiles(options.files);
333
+ const headers = buildRemoteRequestHeaders.call(
334
+ this,
335
+ extraHeaders,
336
+ requestOptions.headerMode || REMOTE_REQUEST_HEADER_MODE.ACCESS_TOKEN_ONLY
337
+ );
338
+
316
339
  if (normalizedFiles.length === 0) {
317
340
  headers["Content-Type"] = "application/json";
318
341
  return {
@@ -345,7 +368,12 @@ const buildRemoteRequestInit = function(payload, options = {}, extraHeaders = {}
345
368
 
346
369
  const invokeByPlatformProxy = async function(appServerAPIName, payload, options = {}) {
347
370
  const endpoint = `/apps/invokeAppServerAPI?appId=${encodeURIComponent(this.appId)}&apiName=${encodeURIComponent(appServerAPIName)}`;
348
- const response = await fetch(`${this.config.apiBaseUrl}${endpoint}`, buildRemoteRequestInit.call(this, payload, options));
371
+ const response = await fetch(
372
+ `${this.config.apiBaseUrl}${endpoint}`,
373
+ buildRemoteRequestInit.call(this, payload, options, {}, {
374
+ headerMode: REMOTE_REQUEST_HEADER_MODE.APPS_CLIENT,
375
+ })
376
+ );
349
377
  return await unwrapAppServerResponse(response, "[AppServer-PlatformProxy]");
350
378
  };
351
379
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tacoreai/web-sdk",
3
3
  "description": "This file is for app server package, not the real npm package",
4
- "version": "1.11.0",
4
+ "version": "1.13.0",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public",
package/utils/index.js CHANGED
@@ -47,6 +47,10 @@ export function getRouterBasename() {
47
47
  }
48
48
 
49
49
  export function getAppsApiBaseUrl() {
50
+ // stone手动: 标准构建 ssr 环境,直接返回生产环境地址
51
+ if (process.env.MODE === 'production' && process.env.SSR === 'true') {
52
+ return `https://api.tacore.chat`;
53
+ }
50
54
  // 后端环境逻辑
51
55
  if (isBackend) {
52
56
  // stone 手动: tacore server 内网地址