@lark-apaas/client-toolkit-lite 1.1.16-alpha.8 → 1.1.16-beta.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.
package/dist/index.cjs CHANGED
@@ -3235,12 +3235,41 @@ function getAxiosForBackend() {
3235
3235
  __name(getAxiosForBackend, "getAxiosForBackend");
3236
3236
  var axiosForBackend = getAxiosForBackend();
3237
3237
 
3238
+ // src/utils/url.ts
3239
+ function splitWorkspaceUrl(fullUrl) {
3240
+ try {
3241
+ const url = new URL(fullUrl);
3242
+ const pathParts = url.pathname.split("/");
3243
+ const workspacesIndex = pathParts.findIndex((part) => part === "workspaces");
3244
+ if (workspacesIndex === -1) {
3245
+ throw new Error("Invalid workspace URL format");
3246
+ }
3247
+ const basePathParts = pathParts.slice(0, workspacesIndex);
3248
+ const workspace = pathParts[workspacesIndex + 1];
3249
+ return {
3250
+ baseUrl: `${url.origin}${basePathParts.join("/")}`,
3251
+ workspace
3252
+ };
3253
+ } catch (error) {
3254
+ console.error("Error splitting workspace URL:", error);
3255
+ }
3256
+ return {
3257
+ baseUrl: fullUrl,
3258
+ // 兜底给一个,不要给空字符串,不然 createClient 都直接挂了,页面会白屏,体感不太好
3259
+ workspace: "workspace"
3260
+ };
3261
+ }
3262
+ __name(splitWorkspaceUrl, "splitWorkspaceUrl");
3263
+
3238
3264
  // src/integrations/dataloom.ts
3239
3265
  var import_dataloom = require("@lark-apaas/dataloom");
3240
3266
  var import_auth_sdk3 = require("@lark-apaas/auth-sdk");
3241
- var createDataLoomClient = /* @__PURE__ */ __name(() => {
3267
+ var createDataLoomClient = /* @__PURE__ */ __name((url, pat) => {
3268
+ const { baseUrl } = url ? splitWorkspaceUrl(url) : {
3269
+ baseUrl: ""
3270
+ };
3242
3271
  const appId = getAppId() ?? "";
3243
- return (0, import_dataloom.createClient)({
3272
+ return (0, import_dataloom.createClient)(baseUrl, pat ?? "", {
3244
3273
  global: {
3245
3274
  enableDataloomLog: process.env.NODE_ENV !== "production",
3246
3275
  requestRateLimit: process.env.NODE_ENV !== "production" ? 100 : void 0,
@@ -3262,8 +3291,10 @@ function getDataloom() {
3262
3291
  if (pendingPromise3) {
3263
3292
  return pendingPromise3;
3264
3293
  }
3265
- pendingPromise3 = getInitialInfo().then(() => {
3266
- dataloom = createDataLoomClient();
3294
+ pendingPromise3 = getInitialInfo().then((info) => {
3295
+ const DATALOOM_CLIENT_URL = info?.app_runtime_extra?.url;
3296
+ const DATALOOM_PAT = info?.app_runtime_extra?.token;
3297
+ dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
3267
3298
  return dataloom;
3268
3299
  }).finally(() => {
3269
3300
  pendingPromise3 = null;