@base44/sdk 0.7.3 → 0.7.5

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
@@ -19,6 +19,7 @@ export declare function createClient(config: {
19
19
  serviceToken?: string;
20
20
  requiresAuth?: boolean;
21
21
  functionsVersion?: string;
22
+ headers?: Record<string, string>;
22
23
  options?: CreateClientOptions;
23
24
  onRedirectToLogin?: () => void;
24
25
  }): {
@@ -55,6 +56,7 @@ export declare function createClient(config: {
55
56
  }) => Promise<import("./types.js").AgentConversation>;
56
57
  addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
57
58
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
59
+ generateUserWhatsAppLink: (agentName: string) => Promise<import("axios").AxiosResponse<any, any>>;
58
60
  };
59
61
  cleanup: () => void;
60
62
  };
@@ -71,6 +73,28 @@ export declare function createClient(config: {
71
73
  user: any;
72
74
  }>;
73
75
  isAuthenticated(): Promise<boolean>;
76
+ inviteUser(userEmail: string, role: string): Promise<import("axios").AxiosResponse<any, any>>;
77
+ register(payload: {
78
+ email: string;
79
+ password: string;
80
+ turnstile_token?: string | null;
81
+ referral_code?: string | null;
82
+ }): Promise<import("axios").AxiosResponse<any, any>>;
83
+ verifyOtp({ email, otpCode }: {
84
+ email: string;
85
+ otpCode: string;
86
+ }): Promise<import("axios").AxiosResponse<any, any>>;
87
+ resendOtp(email: string): Promise<import("axios").AxiosResponse<any, any>>;
88
+ resetPasswordRequest(email: string): Promise<import("axios").AxiosResponse<any, any>>;
89
+ resetPassword({ resetToken, newPassword, }: {
90
+ resetToken: string;
91
+ newPassword: string;
92
+ }): Promise<import("axios").AxiosResponse<any, any>>;
93
+ changePassword({ userId, currentPassword, newPassword, }: {
94
+ userId: string;
95
+ currentPassword: string;
96
+ newPassword: string;
97
+ }): Promise<import("axios").AxiosResponse<any, any>>;
74
98
  };
75
99
  functions: {
76
100
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
@@ -85,6 +109,7 @@ export declare function createClient(config: {
85
109
  }) => Promise<import("./types.js").AgentConversation>;
86
110
  addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
87
111
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
112
+ generateUserWhatsAppLink: (agentName: string) => Promise<import("axios").AxiosResponse<any, any>>;
88
113
  };
89
114
  cleanup: () => void;
90
115
  };
@@ -122,6 +147,7 @@ export declare function createClientFromRequest(request: Request): {
122
147
  }) => Promise<import("./types.js").AgentConversation>;
123
148
  addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
124
149
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
150
+ generateUserWhatsAppLink: (agentName: string) => Promise<import("axios").AxiosResponse<any, any>>;
125
151
  };
126
152
  cleanup: () => void;
127
153
  };
@@ -138,6 +164,28 @@ export declare function createClientFromRequest(request: Request): {
138
164
  user: any;
139
165
  }>;
140
166
  isAuthenticated(): Promise<boolean>;
167
+ inviteUser(userEmail: string, role: string): Promise<import("axios").AxiosResponse<any, any>>;
168
+ register(payload: {
169
+ email: string;
170
+ password: string;
171
+ turnstile_token?: string | null;
172
+ referral_code?: string | null;
173
+ }): Promise<import("axios").AxiosResponse<any, any>>;
174
+ verifyOtp({ email, otpCode }: {
175
+ email: string;
176
+ otpCode: string;
177
+ }): Promise<import("axios").AxiosResponse<any, any>>;
178
+ resendOtp(email: string): Promise<import("axios").AxiosResponse<any, any>>;
179
+ resetPasswordRequest(email: string): Promise<import("axios").AxiosResponse<any, any>>;
180
+ resetPassword({ resetToken, newPassword, }: {
181
+ resetToken: string;
182
+ newPassword: string;
183
+ }): Promise<import("axios").AxiosResponse<any, any>>;
184
+ changePassword({ userId, currentPassword, newPassword, }: {
185
+ userId: string;
186
+ currentPassword: string;
187
+ newPassword: string;
188
+ }): Promise<import("axios").AxiosResponse<any, any>>;
141
189
  };
142
190
  functions: {
143
191
  invoke(functionName: string, data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
@@ -152,6 +200,7 @@ export declare function createClientFromRequest(request: Request): {
152
200
  }) => Promise<import("./types.js").AgentConversation>;
153
201
  addMessage: (conversation: import("./types.js").AgentConversation, message: import("./types.js").AgentMessage) => Promise<import("./types.js").AgentMessage>;
154
202
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: import("./types.js").AgentConversation) => void) => () => void;
203
+ generateUserWhatsAppLink: (agentName: string) => Promise<import("axios").AxiosResponse<any, any>>;
155
204
  };
156
205
  cleanup: () => void;
157
206
  };
package/dist/client.js CHANGED
@@ -18,7 +18,7 @@ import { RoomsSocket } from "./utils/socket-utils.js";
18
18
  * @returns {Object} Base44 client instance
19
19
  */
20
20
  export function createClient(config) {
21
- const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, functionsVersion, onRedirectToLogin, } = config;
21
+ const { serverUrl = "https://base44.app", appId, token, serviceToken, requiresAuth = false, options, functionsVersion, onRedirectToLogin, headers: optionalHeaders, } = config;
22
22
  const socketConfig = {
23
23
  serverUrl,
24
24
  mountPath: "/ws-user-apps/socket.io/",
@@ -30,6 +30,7 @@ export function createClient(config) {
30
30
  config: socketConfig,
31
31
  });
32
32
  const headers = {
33
+ ...optionalHeaders,
33
34
  "X-App-Id": String(appId),
34
35
  };
35
36
  const functionHeaders = functionsVersion
@@ -17,4 +17,5 @@ export declare function createAgentsModule({ axios, socket, appId, }: AgentsModu
17
17
  }) => Promise<AgentConversation>;
18
18
  addMessage: (conversation: AgentConversation, message: AgentMessage) => Promise<AgentMessage>;
19
19
  subscribeToConversation: (conversationId: string, onUpdate?: (conversation: AgentConversation) => void) => () => void;
20
+ generateUserWhatsAppLink: (agentName: string) => Promise<import("axios").AxiosResponse<any, any>>;
20
21
  };
@@ -32,6 +32,9 @@ export function createAgentsModule({ axios, socket, appId, }) {
32
32
  },
33
33
  });
34
34
  };
35
+ const generateUserWhatsAppLink = (agentName) => {
36
+ return axios.post(`/whatsapp/generate-user-link`, { agent_name: agentName });
37
+ };
35
38
  return {
36
39
  getConversations,
37
40
  getConversation,
@@ -39,5 +42,6 @@ export function createAgentsModule({ axios, socket, appId, }) {
39
42
  createConversation,
40
43
  addMessage,
41
44
  subscribeToConversation,
45
+ generateUserWhatsAppLink,
42
46
  };
43
47
  }
@@ -56,4 +56,26 @@ export declare function createAuthModule(axios: AxiosInstance, functionsAxiosCli
56
56
  * @returns {Promise<boolean>} True if token is valid
57
57
  */
58
58
  isAuthenticated(): Promise<boolean>;
59
+ inviteUser(userEmail: string, role: string): Promise<import("axios").AxiosResponse<any, any>>;
60
+ register(payload: {
61
+ email: string;
62
+ password: string;
63
+ turnstile_token?: string | null;
64
+ referral_code?: string | null;
65
+ }): Promise<import("axios").AxiosResponse<any, any>>;
66
+ verifyOtp({ email, otpCode }: {
67
+ email: string;
68
+ otpCode: string;
69
+ }): Promise<import("axios").AxiosResponse<any, any>>;
70
+ resendOtp(email: string): Promise<import("axios").AxiosResponse<any, any>>;
71
+ resetPasswordRequest(email: string): Promise<import("axios").AxiosResponse<any, any>>;
72
+ resetPassword({ resetToken, newPassword, }: {
73
+ resetToken: string;
74
+ newPassword: string;
75
+ }): Promise<import("axios").AxiosResponse<any, any>>;
76
+ changePassword({ userId, currentPassword, newPassword, }: {
77
+ userId: string;
78
+ currentPassword: string;
79
+ newPassword: string;
80
+ }): Promise<import("axios").AxiosResponse<any, any>>;
59
81
  };
@@ -39,7 +39,7 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
39
39
  // If nextUrl is not provided, use the current URL
40
40
  const redirectUrl = nextUrl || window.location.href;
41
41
  // Build the login URL
42
- const loginUrl = `/login?from_url=${encodeURIComponent(redirectUrl)}`;
42
+ const loginUrl = `${options.serverUrl}/login?from_url=${encodeURIComponent(redirectUrl)}&app_id=${appId}`;
43
43
  // Redirect to the login page
44
44
  window.location.href = loginUrl;
45
45
  },
@@ -141,5 +141,41 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
141
141
  return false;
142
142
  }
143
143
  },
144
+ inviteUser(userEmail, role) {
145
+ return axios.post(`/apps/${appId}/users/invite-user`, {
146
+ user_email: userEmail,
147
+ role,
148
+ });
149
+ },
150
+ register(payload) {
151
+ return axios.post(`/apps/${appId}/auth/register`, payload);
152
+ },
153
+ verifyOtp({ email, otpCode }) {
154
+ return axios.post(`/apps/${appId}/auth/verify-otp`, {
155
+ email,
156
+ otp_code: otpCode,
157
+ });
158
+ },
159
+ resendOtp(email) {
160
+ return axios.post(`/apps/${appId}/auth/resend-otp`, { email });
161
+ },
162
+ resetPasswordRequest(email) {
163
+ return axios.post(`/apps/${appId}/auth/reset-password-request`, {
164
+ email,
165
+ });
166
+ },
167
+ resetPassword({ resetToken, newPassword, }) {
168
+ return axios.post(`/apps/${appId}/auth/reset-password`, {
169
+ reset_token: resetToken,
170
+ new_password: newPassword,
171
+ });
172
+ },
173
+ changePassword({ userId, currentPassword, newPassword, }) {
174
+ return axios.post(`/apps/${appId}/auth/change-password`, {
175
+ user_id: userId,
176
+ current_password: currentPassword,
177
+ new_password: newPassword,
178
+ });
179
+ },
144
180
  };
145
181
  }
@@ -1,4 +1,6 @@
1
1
  import axios from "axios";
2
+ import { isInIFrame } from "./common";
3
+ import { v4 as uuidv4 } from "uuid";
2
4
  export class Base44Error extends Error {
3
5
  constructor(message, status, code, data, originalError) {
4
6
  super(message);
@@ -82,11 +84,49 @@ export function createAxiosClient({ baseURL, headers = {}, token, requiresAuth =
82
84
  if (typeof window !== "undefined") {
83
85
  config.headers.set("X-Origin-URL", window.location.href);
84
86
  }
87
+ if (isInIFrame) {
88
+ const requestId = uuidv4();
89
+ try {
90
+ window.parent.postMessage({
91
+ type: "api-request-start",
92
+ requestId,
93
+ data: {
94
+ url: baseURL + config.url,
95
+ method: config.method,
96
+ body: config.data instanceof FormData
97
+ ? "[FormData object]"
98
+ : config.data,
99
+ },
100
+ }, "*");
101
+ }
102
+ catch (_a) {
103
+ /* skip the logging */
104
+ }
105
+ }
85
106
  return config;
86
107
  });
87
108
  // Handle responses
88
109
  if (interceptResponses) {
89
- client.interceptors.response.use((response) => response.data, (error) => {
110
+ client.interceptors.response.use((response) => {
111
+ var _a;
112
+ const requestId = (_a = response.config) === null || _a === void 0 ? void 0 : _a.requestId;
113
+ try {
114
+ if (isInIFrame && requestId) {
115
+ window.parent.postMessage({
116
+ type: "api-request-end",
117
+ requestId,
118
+ data: {
119
+ statusCode: response.status,
120
+ response: response.data,
121
+ },
122
+ }, "*");
123
+ }
124
+ }
125
+ catch (_b) {
126
+ /* do nothing */
127
+ }
128
+ return response.data;
129
+ }, (error) => {
90
130
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
91
131
  const message = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
92
132
  ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.detail) ||
@@ -0,0 +1,2 @@
1
+ export declare const isNode: boolean;
2
+ export declare const isInIFrame: boolean;
@@ -0,0 +1,2 @@
1
+ export const isNode = typeof window === "undefined";
2
+ export const isInIFrame = !isNode && window.self !== window.top;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44/sdk",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,17 +20,18 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "axios": "^1.6.2",
23
- "socket.io-client": "^4.7.5"
23
+ "socket.io-client": "^4.7.5",
24
+ "uuid": "^13.0.0"
24
25
  },
25
26
  "devDependencies": {
26
- "vitest": "^1.0.0",
27
- "@vitest/ui": "^1.0.0",
28
27
  "@vitest/coverage-istanbul": "^1.0.0",
29
28
  "@vitest/coverage-v8": "^1.0.0",
29
+ "@vitest/ui": "^1.0.0",
30
30
  "dotenv": "^16.3.1",
31
31
  "eslint": "^8.54.0",
32
32
  "nock": "^13.4.0",
33
- "typescript": "^5.3.2"
33
+ "typescript": "^5.3.2",
34
+ "vitest": "^1.0.0"
34
35
  },
35
36
  "keywords": [
36
37
  "base44",