@tacoreai/web-sdk 1.1.0 → 1.3.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.
@@ -20,9 +20,9 @@ const registerAppServerAPI = (appServerAPIName, appServerAPIHandler) => {
20
20
  /**
21
21
  * 调用一个 App Server API。
22
22
  * - 在开发态浏览器中:本地执行。
23
- * - 在生产态浏览器中:发起 API 调用。
23
+ * - 在生产态浏览器中:统一走平台转发(/apps/invokeAppServerAPI)。
24
24
  * - 在后端云函数中:本地执行 (由云函数入口调用)。
25
- * - 跨应用调用:如果存在 this.config.appServerBaseUrl this.config.appServerApiKey,则直接发起 HTTP 请求。
25
+ * - 跨应用调用:仅后端场景可直连目标 AppServer(需 appServerBaseUrl + appServerApiKey)。
26
26
  * @param {string} appServerAPIName - 要调用的服务名称。
27
27
  * @param {Object} payload - 传递给服务的负载数据。
28
28
  * @returns {Promise<any>} 服务处理后的结果。
@@ -30,7 +30,7 @@ const registerAppServerAPI = (appServerAPIName, appServerAPIHandler) => {
30
30
  const invokeAppServerAPI = async function(appServerAPIName, payload) {
31
31
  console.log(`[AppServer][${this.appId}] Invoking "${appServerAPIName}" with payload:`, payload);
32
32
  // 场景零:跨应用调用,在源应用的 appserver 云函数调用目标应用的 appserver 云函数
33
- if (this.config.appServerBaseUrl && this.config.appServerApiKey) {
33
+ if (isBackend && this.config.appServerBaseUrl && this.config.appServerApiKey) {
34
34
  const endpoint = `${this.config.appServerBaseUrl}/invokeAppServerAPI?apiName=${appServerAPIName}`;
35
35
  try {
36
36
  const response = await fetch(endpoint, {
@@ -63,15 +63,15 @@ const invokeAppServerAPI = async function(appServerAPIName, payload) {
63
63
 
64
64
  // 场景一:生产环境的浏览器,必须发起网络请求
65
65
  if (isProductionBrowser) {
66
-
67
- // stone 手动注释:给自己前端用的,走平台转发(因为没有地方存 api key),如果是 服务器之间 API调用,则携带 api key直连云函数
68
- const endpoint = `/apps/invokeAppServerAPI?appId=${this.appId}&apiName=${appServerAPIName}`;
66
+ // 浏览器端统一走平台转发,由平台负责组织/应用上下文与内部鉴权链路
67
+ const endpoint = `/apps/invokeAppServerAPI?appId=${encodeURIComponent(this.appId)}&apiName=${encodeURIComponent(appServerAPIName)}`;
69
68
 
70
69
  try {
71
70
  const res = await this._post(endpoint, payload);
72
71
  if (res.success) {
73
72
  return res.data;
74
73
  }
74
+ throw new Error(res.error || res.message || `AppServer invocation failed: ${res.code || "UNKNOWN_ERROR"}`);
75
75
  } catch (error) {
76
76
  console.error(`[AppServer-Prod] Failed to invoke "${appServerAPIName}" via appsClient:`, error);
77
77
  throw error;
@@ -89,4 +89,4 @@ const invokeAppServerAPI = async function(appServerAPIName, payload) {
89
89
  export const appsClientAppServerMethods = {
90
90
  registerAppServerAPI,
91
91
  invokeAppServerAPI,
92
- };
92
+ };
@@ -1,4 +1,4 @@
1
- import { getAppsApiBaseUrl, isBrowser, isBackend, isProductionBrowser, getGlobalOptions } from "../../../utils/index.js";
1
+ import { getAppsApiBaseUrl, isBrowser, isBackend, getGlobalOptions } from "../../../utils/index.js";
2
2
 
3
3
  /**
4
4
  * Apps SDK 基类
@@ -13,7 +13,8 @@ export class BaseAppsClient {
13
13
 
14
14
  const globalOptions = getGlobalOptions();
15
15
  const defaultConfig = {
16
- apiBaseUrl: (isProductionBrowser && config.appServerBaseUrl) ? `${config.appServerBaseUrl}/apiProxy` : getAppsApiBaseUrl(),
16
+ // 默认统一走平台接口;如需特殊链路可显式传入 apiBaseUrl 覆盖。
17
+ apiBaseUrl: getAppsApiBaseUrl(),
17
18
  };
18
19
 
19
20
  this.config = {
@@ -212,4 +213,4 @@ export class BaseAppsClient {
212
213
  getConfig() {
213
214
  return { ...this.config };
214
215
  }
215
- }
216
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
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.1.0",
4
+ "version": "1.3.0",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
+ "access": "public",
7
8
  "registry": "https://registry.npmjs.com"
8
9
  },
9
10
  "exports": {
@@ -11,6 +12,6 @@
11
12
  "./utils": "./utils/index.js"
12
13
  },
13
14
  "scripts": {
14
- "release": "npm version minor && git commit -am \"web-sdk update version\" && git push && npm publish"
15
+ "release": "npm version minor && git commit -am \"web-sdk update version\" && npm publish"
15
16
  }
16
17
  }
package/amd-config.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "name": "@tacoreai/web-sdk",
3
- "version": "1.57.0",
4
- "entry": "index.js",
5
- "externals": [],
6
- "buildOptions": {
7
- "minify": true,
8
- "sourcemap": false,
9
- "format": "esm"
10
- }
11
- }