@lark-apaas/client-toolkit-lite 1.1.11-alpha.1 → 1.1.11-alpha.2

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.cjs CHANGED
@@ -2814,21 +2814,46 @@ function getAxiosForBackend() {
2814
2814
  __name(getAxiosForBackend, "getAxiosForBackend");
2815
2815
  var axiosForBackend = getAxiosForBackend();
2816
2816
 
2817
+ // src/utils/url.ts
2818
+ function splitWorkspaceUrl(fullUrl) {
2819
+ try {
2820
+ const url = new URL(fullUrl);
2821
+ const pathParts = url.pathname.split("/");
2822
+ const workspacesIndex = pathParts.findIndex((part) => part === "workspaces");
2823
+ if (workspacesIndex === -1) {
2824
+ throw new Error("Invalid workspace URL format");
2825
+ }
2826
+ const basePathParts = pathParts.slice(0, workspacesIndex);
2827
+ const workspace = pathParts[workspacesIndex + 1];
2828
+ return {
2829
+ baseUrl: `${url.origin}${basePathParts.join("/")}`,
2830
+ workspace
2831
+ };
2832
+ } catch (error) {
2833
+ console.error("Error splitting workspace URL:", error);
2834
+ }
2835
+ return {
2836
+ baseUrl: fullUrl,
2837
+ // 兜底给一个,不要给空字符串,不然 createClient 都直接挂了,页面会白屏,体感不太好
2838
+ workspace: "workspace"
2839
+ };
2840
+ }
2841
+ __name(splitWorkspaceUrl, "splitWorkspaceUrl");
2842
+
2817
2843
  // src/integrations/dataloom.ts
2818
2844
  var import_dataloom = require("@lark-apaas/dataloom");
2819
2845
  var import_auth_sdk3 = require("@lark-apaas/auth-sdk");
2820
- var createDataLoomClient = /* @__PURE__ */ __name(() => {
2846
+ var createDataLoomClient = /* @__PURE__ */ __name((url, pat) => {
2847
+ const { baseUrl } = url ? splitWorkspaceUrl(url) : {
2848
+ baseUrl: ""
2849
+ };
2821
2850
  const appId = getAppId() ?? "";
2822
- return (0, import_dataloom.createClient)({
2851
+ return (0, import_dataloom.createClient)(baseUrl, pat ?? "", {
2823
2852
  global: {
2824
2853
  enableDataloomLog: process.env.NODE_ENV !== "production",
2825
2854
  requestRateLimit: process.env.NODE_ENV !== "production" ? 100 : void 0,
2826
2855
  brandName: "miaoda",
2827
2856
  appId,
2828
- // 同源网关下不会触发预检;CSRF token 仅用于 POST/PUT/DELETE 防护。
2829
- headers: {
2830
- "X-Suda-Csrf-Token": getCsrfToken() ?? ""
2831
- },
2832
2857
  accountServices: {
2833
2858
  user: import_auth_sdk3.authClient.user,
2834
2859
  session: import_auth_sdk3.authClient.session
@@ -2845,8 +2870,10 @@ function getDataloom() {
2845
2870
  if (pendingPromise3) {
2846
2871
  return pendingPromise3;
2847
2872
  }
2848
- pendingPromise3 = getInitialInfo().then(() => {
2849
- dataloom = createDataLoomClient();
2873
+ pendingPromise3 = getInitialInfo().then((info) => {
2874
+ const DATALOOM_CLIENT_URL = info?.app_runtime_extra?.url;
2875
+ const DATALOOM_PAT = info?.app_runtime_extra?.token;
2876
+ dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
2850
2877
  return dataloom;
2851
2878
  }).finally(() => {
2852
2879
  pendingPromise3 = null;