@base44/sdk 0.8.5 → 0.8.7
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/README.md +47 -600
- package/dist/client.d.ts +90 -237
- package/dist/client.js +161 -29
- package/dist/client.types.d.ts +134 -0
- package/dist/client.types.js +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +1 -1
- package/dist/modules/agents.d.ts +2 -23
- package/dist/modules/agents.js +3 -1
- package/dist/modules/agents.types.d.ts +330 -34
- package/dist/modules/analytics.d.ts +18 -0
- package/dist/modules/analytics.js +213 -0
- package/dist/modules/analytics.types.d.ts +42 -0
- package/dist/modules/analytics.types.js +1 -0
- package/dist/modules/app-logs.d.ts +8 -24
- package/dist/modules/app-logs.js +9 -19
- package/dist/modules/app-logs.types.d.ts +44 -0
- package/dist/modules/app-logs.types.js +1 -0
- package/dist/modules/app.types.d.ts +27 -0
- package/dist/modules/auth.d.ts +10 -78
- package/dist/modules/auth.js +24 -42
- package/dist/modules/auth.types.d.ts +436 -0
- package/dist/modules/auth.types.js +1 -0
- package/dist/modules/connectors.d.ts +6 -11
- package/dist/modules/connectors.js +6 -7
- package/dist/modules/connectors.types.d.ts +68 -2
- package/dist/modules/entities.d.ts +8 -5
- package/dist/modules/entities.js +22 -62
- package/dist/modules/entities.types.d.ts +293 -0
- package/dist/modules/entities.types.js +1 -0
- package/dist/modules/functions.d.ts +8 -7
- package/dist/modules/functions.js +7 -5
- package/dist/modules/functions.types.d.ts +50 -0
- package/dist/modules/functions.types.js +1 -0
- package/dist/modules/integrations.d.ts +8 -5
- package/dist/modules/integrations.js +7 -5
- package/dist/modules/integrations.types.d.ts +352 -0
- package/dist/modules/integrations.types.js +1 -0
- package/dist/modules/sso.d.ts +9 -14
- package/dist/modules/sso.js +9 -12
- package/dist/modules/sso.types.d.ts +44 -0
- package/dist/modules/sso.types.js +1 -0
- package/dist/modules/types.d.ts +1 -0
- package/dist/modules/types.js +1 -0
- package/dist/types.d.ts +65 -2
- package/dist/utils/auth-utils.d.ts +107 -45
- package/dist/utils/auth-utils.js +107 -33
- package/dist/utils/auth-utils.types.d.ts +146 -0
- package/dist/utils/auth-utils.types.js +1 -0
- package/dist/utils/axios-client.d.ts +84 -16
- package/dist/utils/axios-client.js +74 -13
- package/dist/utils/axios-client.types.d.ts +28 -0
- package/dist/utils/axios-client.types.js +1 -0
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.js +4 -0
- package/dist/utils/sharedInstance.d.ts +1 -0
- package/dist/utils/sharedInstance.js +15 -0
- package/dist/utils/socket-utils.d.ts +2 -2
- package/package.json +12 -3
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { getSharedInstance } from "../utils/sharedInstance";
|
|
2
|
+
import { generateUuid } from "../utils/common";
|
|
3
|
+
export const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
|
|
4
|
+
export const ANALYTICS_CONFIG_WINDOW_KEY = "base44_analytics_config";
|
|
5
|
+
export const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
|
|
6
|
+
const defaultConfiguration = {
|
|
7
|
+
enabled: true,
|
|
8
|
+
maxQueueSize: 1000,
|
|
9
|
+
throttleTime: 1000,
|
|
10
|
+
batchSize: 30,
|
|
11
|
+
heartBeatInterval: 60 * 1000,
|
|
12
|
+
};
|
|
13
|
+
///////////////////////////////////////////////
|
|
14
|
+
//// shared queue for analytics events ////
|
|
15
|
+
///////////////////////////////////////////////
|
|
16
|
+
const ANALYTICS_SHARED_STATE_NAME = "analytics";
|
|
17
|
+
// shared state//
|
|
18
|
+
const analyticsSharedState = getSharedInstance(ANALYTICS_SHARED_STATE_NAME, () => ({
|
|
19
|
+
requestsQueue: [],
|
|
20
|
+
isProcessing: false,
|
|
21
|
+
isHeartBeatProcessing: false,
|
|
22
|
+
sessionContext: null,
|
|
23
|
+
config: {
|
|
24
|
+
...defaultConfiguration,
|
|
25
|
+
...getAnalyticsModuleOptionsFromWindow(),
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
export const createAnalyticsModule = ({ axiosClient, serverUrl, appId, userAuthModule, }) => {
|
|
29
|
+
var _a;
|
|
30
|
+
// prevent overflow of events //
|
|
31
|
+
const { maxQueueSize, throttleTime, batchSize } = analyticsSharedState.config;
|
|
32
|
+
if (!((_a = analyticsSharedState.config) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
33
|
+
return {
|
|
34
|
+
track: () => { },
|
|
35
|
+
cleanup: () => { },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
let clearHeartBeatProcessor = undefined;
|
|
39
|
+
const trackBatchUrl = `${serverUrl}/api/apps/${appId}/analytics/track/batch`;
|
|
40
|
+
const batchRequestFallback = async (events) => {
|
|
41
|
+
await axiosClient.request({
|
|
42
|
+
method: "POST",
|
|
43
|
+
url: `/apps/${appId}/analytics/track/batch`,
|
|
44
|
+
data: { events },
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const flush = async (eventsData) => {
|
|
48
|
+
const sessionContext_ = await getSessionContext(userAuthModule);
|
|
49
|
+
const events = eventsData.map(transformEventDataToApiRequestData(sessionContext_));
|
|
50
|
+
const beaconPayload = JSON.stringify({ events });
|
|
51
|
+
try {
|
|
52
|
+
if (typeof navigator === "undefined" ||
|
|
53
|
+
beaconPayload.length > 60000 ||
|
|
54
|
+
!navigator.sendBeacon(trackBatchUrl, beaconPayload)) {
|
|
55
|
+
// beacon didn't work, fallback to axios
|
|
56
|
+
await batchRequestFallback(events);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (_a) {
|
|
60
|
+
// TODO: think about retries if needed
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const startProcessing = () => {
|
|
64
|
+
startAnalyticsProcessor(flush, {
|
|
65
|
+
throttleTime,
|
|
66
|
+
batchSize,
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const track = (params) => {
|
|
70
|
+
if (analyticsSharedState.requestsQueue.length >= maxQueueSize) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const intrinsicData = getEventIntrinsicData();
|
|
74
|
+
analyticsSharedState.requestsQueue.push({
|
|
75
|
+
...params,
|
|
76
|
+
...intrinsicData,
|
|
77
|
+
});
|
|
78
|
+
startProcessing();
|
|
79
|
+
};
|
|
80
|
+
const onDocVisible = () => {
|
|
81
|
+
startAnalyticsProcessor(flush, {
|
|
82
|
+
throttleTime,
|
|
83
|
+
batchSize,
|
|
84
|
+
});
|
|
85
|
+
clearHeartBeatProcessor = startHeartBeatProcessor(track);
|
|
86
|
+
};
|
|
87
|
+
const onDocHidden = () => {
|
|
88
|
+
stopAnalyticsProcessor();
|
|
89
|
+
// flush entire queue on visibility change and hope for the best //
|
|
90
|
+
const eventsData = analyticsSharedState.requestsQueue.splice(0);
|
|
91
|
+
flush(eventsData);
|
|
92
|
+
clearHeartBeatProcessor === null || clearHeartBeatProcessor === void 0 ? void 0 : clearHeartBeatProcessor();
|
|
93
|
+
};
|
|
94
|
+
const onVisibilityChange = () => {
|
|
95
|
+
if (typeof window === "undefined")
|
|
96
|
+
return;
|
|
97
|
+
if (document.visibilityState === "hidden") {
|
|
98
|
+
onDocHidden();
|
|
99
|
+
}
|
|
100
|
+
else if (document.visibilityState === "visible") {
|
|
101
|
+
onDocVisible();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const cleanup = () => {
|
|
105
|
+
stopAnalyticsProcessor();
|
|
106
|
+
clearHeartBeatProcessor === null || clearHeartBeatProcessor === void 0 ? void 0 : clearHeartBeatProcessor();
|
|
107
|
+
if (typeof window !== "undefined") {
|
|
108
|
+
window.removeEventListener("visibilitychange", onVisibilityChange);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
// start the flusing process ///
|
|
112
|
+
startProcessing();
|
|
113
|
+
// start the heart beat processor //
|
|
114
|
+
clearHeartBeatProcessor = startHeartBeatProcessor(track);
|
|
115
|
+
// start the visibility change listener //
|
|
116
|
+
if (typeof window !== "undefined") {
|
|
117
|
+
window.addEventListener("visibilitychange", onVisibilityChange);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
track,
|
|
121
|
+
cleanup,
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
function stopAnalyticsProcessor() {
|
|
125
|
+
analyticsSharedState.isProcessing = false;
|
|
126
|
+
}
|
|
127
|
+
async function startAnalyticsProcessor(handleTrack, options) {
|
|
128
|
+
if (analyticsSharedState.isProcessing) {
|
|
129
|
+
// only one instance of the analytics processor can be running at a time //
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
analyticsSharedState.isProcessing = true;
|
|
133
|
+
const { throttleTime = 1000, batchSize = 30 } = options !== null && options !== void 0 ? options : {};
|
|
134
|
+
while (analyticsSharedState.isProcessing &&
|
|
135
|
+
analyticsSharedState.requestsQueue.length > 0) {
|
|
136
|
+
const requests = analyticsSharedState.requestsQueue.splice(0, batchSize);
|
|
137
|
+
requests.length && (await handleTrack(requests));
|
|
138
|
+
await new Promise((resolve) => setTimeout(resolve, throttleTime));
|
|
139
|
+
}
|
|
140
|
+
analyticsSharedState.isProcessing = false;
|
|
141
|
+
}
|
|
142
|
+
function startHeartBeatProcessor(track) {
|
|
143
|
+
var _a;
|
|
144
|
+
if (analyticsSharedState.isHeartBeatProcessing ||
|
|
145
|
+
((_a = analyticsSharedState.config.heartBeatInterval) !== null && _a !== void 0 ? _a : 0) < 10) {
|
|
146
|
+
return () => { };
|
|
147
|
+
}
|
|
148
|
+
analyticsSharedState.isHeartBeatProcessing = true;
|
|
149
|
+
const interval = setInterval(() => {
|
|
150
|
+
track({ eventName: USER_HEARTBEAT_EVENT_NAME });
|
|
151
|
+
}, analyticsSharedState.config.heartBeatInterval);
|
|
152
|
+
return () => {
|
|
153
|
+
clearInterval(interval);
|
|
154
|
+
analyticsSharedState.isHeartBeatProcessing = false;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function getEventIntrinsicData() {
|
|
158
|
+
return {
|
|
159
|
+
timestamp: new Date().toISOString(),
|
|
160
|
+
pageUrl: typeof window !== "undefined" ? window.location.pathname : null,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function transformEventDataToApiRequestData(sessionContext) {
|
|
164
|
+
return (eventData) => ({
|
|
165
|
+
event_name: eventData.eventName,
|
|
166
|
+
properties: eventData.properties,
|
|
167
|
+
timestamp: eventData.timestamp,
|
|
168
|
+
page_url: eventData.pageUrl,
|
|
169
|
+
...sessionContext,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
let sessionContextPromise = null;
|
|
173
|
+
async function getSessionContext(userAuthModule) {
|
|
174
|
+
if (!analyticsSharedState.sessionContext) {
|
|
175
|
+
if (!sessionContextPromise) {
|
|
176
|
+
const sessionId = getAnalyticsSessionId();
|
|
177
|
+
sessionContextPromise = userAuthModule
|
|
178
|
+
.me()
|
|
179
|
+
.then((user) => ({
|
|
180
|
+
user_id: user.id,
|
|
181
|
+
session_id: sessionId,
|
|
182
|
+
}))
|
|
183
|
+
.catch(() => ({
|
|
184
|
+
user_id: null,
|
|
185
|
+
session_id: sessionId,
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
analyticsSharedState.sessionContext = await sessionContextPromise;
|
|
189
|
+
}
|
|
190
|
+
return analyticsSharedState.sessionContext;
|
|
191
|
+
}
|
|
192
|
+
export function getAnalyticsModuleOptionsFromWindow() {
|
|
193
|
+
if (typeof window === "undefined")
|
|
194
|
+
return undefined;
|
|
195
|
+
return window[ANALYTICS_CONFIG_WINDOW_KEY];
|
|
196
|
+
}
|
|
197
|
+
export function getAnalyticsSessionId() {
|
|
198
|
+
if (typeof window === "undefined") {
|
|
199
|
+
return generateUuid();
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const sessionId = localStorage.getItem(ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY);
|
|
203
|
+
if (!sessionId) {
|
|
204
|
+
const newSessionId = generateUuid();
|
|
205
|
+
localStorage.setItem(ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY, newSessionId);
|
|
206
|
+
return newSessionId;
|
|
207
|
+
}
|
|
208
|
+
return sessionId;
|
|
209
|
+
}
|
|
210
|
+
catch (_a) {
|
|
211
|
+
return generateUuid();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type TrackEventProperties = {
|
|
2
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
3
|
+
};
|
|
4
|
+
export type TrackEventParams = {
|
|
5
|
+
eventName: string;
|
|
6
|
+
properties?: TrackEventProperties;
|
|
7
|
+
};
|
|
8
|
+
export type TrackEventIntrinsicData = {
|
|
9
|
+
timestamp: string;
|
|
10
|
+
pageUrl?: string | null;
|
|
11
|
+
};
|
|
12
|
+
export type TrackEventData = {
|
|
13
|
+
properties?: TrackEventProperties;
|
|
14
|
+
eventName: string;
|
|
15
|
+
} & TrackEventIntrinsicData;
|
|
16
|
+
export type SessionContext = {
|
|
17
|
+
user_id?: string | null;
|
|
18
|
+
session_id?: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type AnalyticsApiRequestData = {
|
|
21
|
+
event_name: string;
|
|
22
|
+
properties?: TrackEventProperties;
|
|
23
|
+
timestamp?: string;
|
|
24
|
+
page_url?: string | null;
|
|
25
|
+
} & SessionContext;
|
|
26
|
+
export type AnalyticsApiBatchRequest = {
|
|
27
|
+
method: "POST";
|
|
28
|
+
url: `/apps/${string}/analytics/track/batch`;
|
|
29
|
+
data: {
|
|
30
|
+
events: AnalyticsApiRequestData[];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type AnalyticsModuleOptions = {
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
maxQueueSize?: number;
|
|
36
|
+
throttleTime?: number;
|
|
37
|
+
batchSize?: number;
|
|
38
|
+
heartBeatInterval?: number;
|
|
39
|
+
};
|
|
40
|
+
export type AnalyticsModule = {
|
|
41
|
+
track: (params: TrackEventParams) => void;
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
+
import { AppLogsModule } from "./app-logs.types";
|
|
2
3
|
/**
|
|
3
|
-
* Creates the app logs module for the Base44 SDK
|
|
4
|
-
*
|
|
5
|
-
* @param
|
|
6
|
-
* @
|
|
4
|
+
* Creates the app logs module for the Base44 SDK.
|
|
5
|
+
*
|
|
6
|
+
* @param axios - Axios instance
|
|
7
|
+
* @param appId - Application ID
|
|
8
|
+
* @returns App logs module with methods for tracking and analyzing app usage
|
|
9
|
+
* @internal
|
|
7
10
|
*/
|
|
8
|
-
export declare function createAppLogsModule(axios: AxiosInstance, appId: string):
|
|
9
|
-
/**
|
|
10
|
-
* Log user activity in the app
|
|
11
|
-
* @param {string} pageName - Name of the page being visited
|
|
12
|
-
* @returns {Promise<void>}
|
|
13
|
-
*/
|
|
14
|
-
logUserInApp(pageName: string): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Fetch app logs with optional parameters
|
|
17
|
-
* @param {Object} params - Query parameters for filtering logs
|
|
18
|
-
* @returns {Promise<any>} App logs data
|
|
19
|
-
*/
|
|
20
|
-
fetchLogs(params?: Record<string, any>): Promise<any>;
|
|
21
|
-
/**
|
|
22
|
-
* Get app statistics
|
|
23
|
-
* @param {Object} params - Query parameters for filtering stats
|
|
24
|
-
* @returns {Promise<any>} App statistics
|
|
25
|
-
*/
|
|
26
|
-
getStats(params?: Record<string, any>): Promise<any>;
|
|
27
|
-
};
|
|
11
|
+
export declare function createAppLogsModule(axios: AxiosInstance, appId: string): AppLogsModule;
|
package/dist/modules/app-logs.js
CHANGED
|
@@ -1,34 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates the app logs module for the Base44 SDK
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
2
|
+
* Creates the app logs module for the Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* @param axios - Axios instance
|
|
5
|
+
* @param appId - Application ID
|
|
6
|
+
* @returns App logs module with methods for tracking and analyzing app usage
|
|
7
|
+
* @internal
|
|
6
8
|
*/
|
|
7
9
|
export function createAppLogsModule(axios, appId) {
|
|
8
10
|
const baseURL = `/app-logs/${appId}`;
|
|
9
11
|
return {
|
|
10
|
-
|
|
11
|
-
* Log user activity in the app
|
|
12
|
-
* @param {string} pageName - Name of the page being visited
|
|
13
|
-
* @returns {Promise<void>}
|
|
14
|
-
*/
|
|
12
|
+
// Log user activity in the app
|
|
15
13
|
async logUserInApp(pageName) {
|
|
16
14
|
await axios.post(`${baseURL}/log-user-in-app/${pageName}`);
|
|
17
15
|
},
|
|
18
|
-
|
|
19
|
-
* Fetch app logs with optional parameters
|
|
20
|
-
* @param {Object} params - Query parameters for filtering logs
|
|
21
|
-
* @returns {Promise<any>} App logs data
|
|
22
|
-
*/
|
|
16
|
+
// Fetch app logs with optional parameters
|
|
23
17
|
async fetchLogs(params = {}) {
|
|
24
18
|
const response = await axios.get(baseURL, { params });
|
|
25
19
|
return response;
|
|
26
20
|
},
|
|
27
|
-
|
|
28
|
-
* Get app statistics
|
|
29
|
-
* @param {Object} params - Query parameters for filtering stats
|
|
30
|
-
* @returns {Promise<any>} App statistics
|
|
31
|
-
*/
|
|
21
|
+
// Get app statistics
|
|
32
22
|
async getStats(params = {}) {
|
|
33
23
|
const response = await axios.get(`${baseURL}/stats`, { params });
|
|
34
24
|
return response;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App Logs module for tracking and analyzing app usage.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a method to log user activity. The logs are reflected in the Analytics page in the app dashboard.
|
|
5
|
+
*
|
|
6
|
+
* This module is available to use with a client in all authentication modes.
|
|
7
|
+
*/
|
|
8
|
+
export interface AppLogsModule {
|
|
9
|
+
/**
|
|
10
|
+
* Log user activity in the app.
|
|
11
|
+
*
|
|
12
|
+
* Records when a user visits a specific page or section of the app. Useful for tracking user navigation patterns and popular features. The logs are reflected in the Analytics page in the app dashboard.
|
|
13
|
+
*
|
|
14
|
+
* The specified page name doesn't have to be the name of an actual page in the app, it can be any string you want to use to track the activity.
|
|
15
|
+
*
|
|
16
|
+
* @param pageName - Name of the page or section being visited.
|
|
17
|
+
* @returns Promise that resolves when the log is recorded.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Log page visit or feature usage
|
|
22
|
+
* await base44.appLogs.logUserInApp('home');
|
|
23
|
+
* await base44.appLogs.logUserInApp('features-section');
|
|
24
|
+
* await base44.appLogs.logUserInApp('button-click');
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
logUserInApp(pageName: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Fetch app logs with optional parameters.
|
|
30
|
+
*
|
|
31
|
+
* @param params - Optional query parameters for filtering logs.
|
|
32
|
+
* @returns Promise resolving to the logs data.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
fetchLogs(params?: Record<string, any>): Promise<any>;
|
|
36
|
+
/**
|
|
37
|
+
* Get app statistics.
|
|
38
|
+
*
|
|
39
|
+
* @param params - Optional query parameters for filtering stats.
|
|
40
|
+
* @returns Promise resolving to the stats data.
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
getStats(params?: Record<string, any>): Promise<any>;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
1
4
|
export interface AppMessageContent {
|
|
2
5
|
content?: string;
|
|
3
6
|
file_urls?: string[];
|
|
@@ -5,16 +8,25 @@ export interface AppMessageContent {
|
|
|
5
8
|
additional_message_params?: Record<string, unknown>;
|
|
6
9
|
[key: string]: unknown;
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
8
14
|
export interface AppConversationMessage extends AppMessageContent {
|
|
9
15
|
id?: string | null;
|
|
10
16
|
role?: "user" | "assistant" | string;
|
|
11
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
12
21
|
export interface AppConversationLike {
|
|
13
22
|
id?: string | null;
|
|
14
23
|
messages?: AppMessageContent[] | null;
|
|
15
24
|
model?: string;
|
|
16
25
|
functions_fail_silently?: boolean;
|
|
17
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
18
30
|
export interface DenoProjectLike {
|
|
19
31
|
project_id: string;
|
|
20
32
|
project_name: string;
|
|
@@ -24,6 +36,9 @@ export interface DenoProjectLike {
|
|
|
24
36
|
code: string;
|
|
25
37
|
}>;
|
|
26
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
27
42
|
export interface AppLike {
|
|
28
43
|
id?: string;
|
|
29
44
|
conversation?: AppConversationLike | null;
|
|
@@ -80,9 +95,15 @@ export interface AppLike {
|
|
|
80
95
|
app_code_hash?: string;
|
|
81
96
|
has_backend_functions_enabled?: boolean;
|
|
82
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
83
101
|
export interface UserLike {
|
|
84
102
|
id?: string | null;
|
|
85
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
86
107
|
export interface UserEntityLike {
|
|
87
108
|
type: string;
|
|
88
109
|
name: string;
|
|
@@ -104,6 +125,9 @@ export interface UserEntityLike {
|
|
|
104
125
|
};
|
|
105
126
|
required: string[];
|
|
106
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
107
131
|
export interface AuthConfigLike {
|
|
108
132
|
enable_username_password?: boolean;
|
|
109
133
|
enable_google_login?: boolean;
|
|
@@ -112,4 +136,7 @@ export interface AuthConfigLike {
|
|
|
112
136
|
sso_provider_name?: string;
|
|
113
137
|
enable_sso_login?: boolean;
|
|
114
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
115
142
|
export type LoginInfoResponse = Pick<AppLike, "id" | "name" | "slug" | "logo_url" | "user_description" | "updated_date" | "created_date" | "auth_config" | "platform_version">;
|
package/dist/modules/auth.d.ts
CHANGED
|
@@ -1,81 +1,13 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
+
import { AuthModule, AuthModuleOptions } from "./auth.types";
|
|
2
3
|
/**
|
|
3
|
-
* Creates the auth module for the Base44 SDK
|
|
4
|
-
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @
|
|
4
|
+
* Creates the auth module for the Base44 SDK.
|
|
5
|
+
*
|
|
6
|
+
* @param axios - Axios instance for API requests
|
|
7
|
+
* @param functionsAxiosClient - Axios instance for functions API requests
|
|
8
|
+
* @param appId - Application ID
|
|
9
|
+
* @param options - Configuration options including server URLs
|
|
10
|
+
* @returns Auth module with authentication and user management methods
|
|
11
|
+
* @internal
|
|
8
12
|
*/
|
|
9
|
-
export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options:
|
|
10
|
-
serverUrl: string;
|
|
11
|
-
appBaseUrl?: string;
|
|
12
|
-
}): {
|
|
13
|
-
/**
|
|
14
|
-
* Get current user information
|
|
15
|
-
* @returns {Promise<Object>} Current user data
|
|
16
|
-
*/
|
|
17
|
-
me(): Promise<import("axios").AxiosResponse<any, any>>;
|
|
18
|
-
/**
|
|
19
|
-
* Update current user data
|
|
20
|
-
* @param {Object} data - Updated user data
|
|
21
|
-
* @returns {Promise<Object>} Updated user
|
|
22
|
-
*/
|
|
23
|
-
updateMe(data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
24
|
-
/**
|
|
25
|
-
* Redirects the user to the app's login page
|
|
26
|
-
* @param {string} nextUrl - URL to redirect to after successful login
|
|
27
|
-
* @throws {Error} When not in a browser environment
|
|
28
|
-
*/
|
|
29
|
-
redirectToLogin(nextUrl: string): void;
|
|
30
|
-
/**
|
|
31
|
-
* Logout the current user
|
|
32
|
-
* Removes the token from localStorage and optionally redirects to a URL or reloads the page
|
|
33
|
-
* @param redirectUrl - Optional URL to redirect to after logout. Reloads the page if not provided
|
|
34
|
-
* @returns {Promise<void>}
|
|
35
|
-
*/
|
|
36
|
-
logout(redirectUrl?: string): void;
|
|
37
|
-
/**
|
|
38
|
-
* Set authentication token
|
|
39
|
-
* @param {string} token - Auth token
|
|
40
|
-
* @param {boolean} [saveToStorage=true] - Whether to save the token to localStorage
|
|
41
|
-
*/
|
|
42
|
-
setToken(token: string, saveToStorage?: boolean): void;
|
|
43
|
-
/**
|
|
44
|
-
* Login via username and password
|
|
45
|
-
* @param email - User email
|
|
46
|
-
* @param password - User password
|
|
47
|
-
* @param turnstileToken - Optional Turnstile captcha token
|
|
48
|
-
* @returns Login response with access_token and user
|
|
49
|
-
*/
|
|
50
|
-
loginViaEmailPassword(email: string, password: string, turnstileToken?: string): Promise<{
|
|
51
|
-
access_token: string;
|
|
52
|
-
user: any;
|
|
53
|
-
}>;
|
|
54
|
-
/**
|
|
55
|
-
* Verify if the current token is valid
|
|
56
|
-
* @returns {Promise<boolean>} True if token is valid
|
|
57
|
-
*/
|
|
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>>;
|
|
81
|
-
};
|
|
13
|
+
export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options: AuthModuleOptions): AuthModule;
|