@base44-preview/sdk 0.7.4-pr.31.074b22c → 0.7.8-pr.37.a0fad83

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/client.d.ts CHANGED
@@ -56,6 +56,7 @@ export declare function createClient(config: {
56
56
  }) => Promise<import("./types.js").AgentConversation>;
57
57
  addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
58
58
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
59
+ getWhatsAppConnectURL: (agentName: string) => string;
59
60
  };
60
61
  cleanup: () => void;
61
62
  };
@@ -108,6 +109,7 @@ export declare function createClient(config: {
108
109
  }) => Promise<import("./types.js").AgentConversation>;
109
110
  addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
110
111
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
112
+ getWhatsAppConnectURL: (agentName: string) => string;
111
113
  };
112
114
  cleanup: () => void;
113
115
  };
@@ -145,6 +147,7 @@ export declare function createClientFromRequest(request: Request): {
145
147
  }) => Promise<import("./types.js").AgentConversation>;
146
148
  addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
147
149
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
150
+ getWhatsAppConnectURL: (agentName: string) => string;
148
151
  };
149
152
  cleanup: () => void;
150
153
  };
@@ -197,6 +200,7 @@ export declare function createClientFromRequest(request: Request): {
197
200
  }) => Promise<import("./types.js").AgentConversation>;
198
201
  addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
199
202
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
203
+ getWhatsAppConnectURL: (agentName: string) => string;
200
204
  };
201
205
  cleanup: () => void;
202
206
  };
package/dist/client.js CHANGED
@@ -90,6 +90,8 @@ export function createClient(config) {
90
90
  axios: axiosClient,
91
91
  socket,
92
92
  appId,
93
+ serverUrl,
94
+ token,
93
95
  }),
94
96
  cleanup: () => {
95
97
  socket.disconnect();
@@ -104,6 +106,8 @@ export function createClient(config) {
104
106
  axios: serviceRoleAxiosClient,
105
107
  socket,
106
108
  appId,
109
+ serverUrl,
110
+ token
107
111
  }),
108
112
  cleanup: () => {
109
113
  socket.disconnect();
@@ -6,8 +6,10 @@ export type AgentsModuleConfig = {
6
6
  axios: AxiosInstance;
7
7
  socket: ReturnType<typeof RoomsSocket>;
8
8
  appId: string;
9
+ serverUrl?: string;
10
+ token?: string;
9
11
  };
10
- export declare function createAgentsModule({ axios, socket, appId, }: AgentsModuleConfig): {
12
+ export declare function createAgentsModule({ axios, socket, appId, serverUrl, token, }: AgentsModuleConfig): {
11
13
  getConversations: () => Promise<AgentConversation[]>;
12
14
  getConversation: (conversationId: string) => Promise<AgentConversation | undefined>;
13
15
  listConversations: (filterParams: ModelFilterParams) => Promise<AgentConversation[]>;
@@ -17,4 +19,5 @@ export declare function createAgentsModule({ axios, socket, appId, }: AgentsModu
17
19
  }) => Promise<AgentConversation>;
18
20
  addMessage: (conversation: AgentConversation, message: AgentMessage) => Promise<AgentMessage>;
19
21
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: AgentConversation) => void) => () => void;
22
+ getWhatsAppConnectURL: (agentName: string) => string;
20
23
  };
@@ -1,4 +1,5 @@
1
- export function createAgentsModule({ axios, socket, appId, }) {
1
+ import { getAccessToken } from "../utils/auth-utils.js";
2
+ export function createAgentsModule({ axios, socket, appId, serverUrl, token, }) {
2
3
  const baseURL = `/apps/${appId}/agents`;
3
4
  const getConversations = () => {
4
5
  return axios.get(`${baseURL}/conversations`);
@@ -32,6 +33,17 @@ export function createAgentsModule({ axios, socket, appId, }) {
32
33
  },
33
34
  });
34
35
  };
36
+ const getWhatsAppConnectURL = (agentName) => {
37
+ const baseUrl = `${serverUrl}/whatsapp/${appId}/${encodeURIComponent(agentName)}`;
38
+ const accessToken = token !== null && token !== void 0 ? token : getAccessToken();
39
+ if (accessToken) {
40
+ return `${baseUrl}?token=${accessToken}`;
41
+ }
42
+ else {
43
+ // No token - URL will redirect to login automatically
44
+ return baseUrl;
45
+ }
46
+ };
35
47
  return {
36
48
  getConversations,
37
49
  getConversation,
@@ -39,5 +51,6 @@ export function createAgentsModule({ axios, socket, appId, }) {
39
51
  createConversation,
40
52
  addMessage,
41
53
  subscribeToConversation,
54
+ getWhatsAppConnectURL,
42
55
  };
43
56
  }
@@ -90,6 +90,8 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
90
90
  window.localStorage) {
91
91
  try {
92
92
  window.localStorage.setItem("base44_access_token", token);
93
+ // Set "token" that is set by the built-in SDK of platform version 2
94
+ window.localStorage.setItem("token", token);
93
95
  }
94
96
  catch (e) {
95
97
  console.error("Failed to save token to localStorage:", e);
@@ -65,6 +65,8 @@ export function saveAccessToken(token, options) {
65
65
  }
66
66
  try {
67
67
  window.localStorage.setItem(storageKey, token);
68
+ // Set "token" that is set by the built-in SDK of platform version 2
69
+ window.localStorage.setItem("token", token);
68
70
  return true;
69
71
  }
70
72
  catch (e) {
@@ -1,5 +1,5 @@
1
1
  import axios from "axios";
2
- import { isInIFrame } from "./common";
2
+ import { isInIFrame } from "./common.js";
3
3
  import { v4 as uuidv4 } from "uuid";
4
4
  export class Base44Error extends Error {
5
5
  constructor(message, status, code, data, originalError) {
@@ -84,8 +84,9 @@ export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth =
84
84
  if (typeof window !== "undefined") {
85
85
  config.headers.set("X-Origin-URL", window.location.href);
86
86
  }
87
+ const requestId = uuidv4();
88
+ config.requestId = requestId;
87
89
  if (isInIFrame) {
88
- const requestId = uuidv4();
89
90
  try {
90
91
  window.parent.postMessage({
91
92
  type: "api-request-start",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.7.4-pr.31.074b22c",
3
+ "version": "0.7.8-pr.37.a0fad83",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",