@base44-preview/sdk 0.8.17-pr.49.b78ce52 → 0.8.17-pr.73.e88f2f7
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 +130 -0
- package/dist/client.js +3 -0
- package/dist/client.types.d.ts +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/modules/auth.js +0 -10
- package/dist/modules/auth.types.d.ts +0 -21
- package/dist/modules/mobile.d.ts +16 -0
- package/dist/modules/mobile.js +39 -0
- package/dist/modules/mobile.types.d.ts +86 -0
- package/dist/modules/mobile.types.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ The SDK provides access to Base44's functionality through the following modules:
|
|
|
13
13
|
- **[`entities`](https://docs.base44.com/sdk-docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
|
|
14
14
|
- **[`functions`](https://docs.base44.com/sdk-docs/interfaces/functions)**: Execute backend functions.
|
|
15
15
|
- **[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**: Pre-built server-side functions for external services.
|
|
16
|
+
- **[`mobile`](#mobile-native-features)**: Send push notifications and access mobile native capabilities.
|
|
16
17
|
|
|
17
18
|
## Example
|
|
18
19
|
|
|
@@ -37,6 +38,135 @@ await base44.entities.Task.update(newTask.id, {
|
|
|
37
38
|
const tasks = await base44.entities.Task.list();
|
|
38
39
|
```
|
|
39
40
|
|
|
41
|
+
## Mobile Native Features
|
|
42
|
+
|
|
43
|
+
The SDK provides mobile native capabilities through the `mobile` module, allowing you to send push notifications to your app users.
|
|
44
|
+
|
|
45
|
+
### Push Notifications
|
|
46
|
+
|
|
47
|
+
Send push notifications to users on mobile devices:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { base44 } from "@/api/base44Client";
|
|
51
|
+
|
|
52
|
+
// Send a push notification to a user
|
|
53
|
+
await base44.mobile.sendNotification({
|
|
54
|
+
userId: "user_123",
|
|
55
|
+
title: "New Message!",
|
|
56
|
+
content: "You have a new message from John",
|
|
57
|
+
actionLabel: "View Message",
|
|
58
|
+
actionUrl: "/messages/456",
|
|
59
|
+
channels: ["mobile_push"], // Mobile push only
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Send to both mobile push and in-app notifications (default)
|
|
63
|
+
await base44.mobile.sendNotification({
|
|
64
|
+
userId: "user_456",
|
|
65
|
+
title: "Order Shipped",
|
|
66
|
+
content: "Your order #12345 has been shipped and is on its way!",
|
|
67
|
+
actionLabel: "Track Order",
|
|
68
|
+
actionUrl: "/orders/12345",
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Notification Channels
|
|
73
|
+
|
|
74
|
+
The `mobile` module supports two notification channels:
|
|
75
|
+
|
|
76
|
+
- **`mobile_push`**: Sends a push notification to the user's mobile device (iOS/Android)
|
|
77
|
+
- **`in_app`**: Sends an in-app notification visible in the web interface
|
|
78
|
+
|
|
79
|
+
By default, notifications are sent to both channels. You can specify specific channels using the `channels` parameter:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Mobile push only - user will receive push notification on their phone
|
|
83
|
+
await base44.mobile.sendNotification({
|
|
84
|
+
userId: "user_123",
|
|
85
|
+
title: "Time-sensitive alert",
|
|
86
|
+
content: "Your session will expire in 5 minutes",
|
|
87
|
+
channels: ["mobile_push"],
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// In-app only - notification visible only in the web interface
|
|
91
|
+
await base44.mobile.sendNotification({
|
|
92
|
+
userId: "user_789",
|
|
93
|
+
title: "System Update",
|
|
94
|
+
content: "We've updated the dashboard with new features",
|
|
95
|
+
channels: ["in_app"],
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Common Use Cases
|
|
100
|
+
|
|
101
|
+
**Order & Delivery Updates**:
|
|
102
|
+
```typescript
|
|
103
|
+
// Notify user when order is ready
|
|
104
|
+
await base44.mobile.sendNotification({
|
|
105
|
+
userId: order.userId,
|
|
106
|
+
title: "Order Ready for Pickup",
|
|
107
|
+
content: `Your order #${order.id} is ready at ${store.name}`,
|
|
108
|
+
actionLabel: "View Order",
|
|
109
|
+
actionUrl: `/orders/${order.id}`,
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Chat & Messaging**:
|
|
114
|
+
```typescript
|
|
115
|
+
// Notify user of new messages
|
|
116
|
+
await base44.mobile.sendNotification({
|
|
117
|
+
userId: recipient.id,
|
|
118
|
+
title: `New message from ${sender.name}`,
|
|
119
|
+
content: message.preview,
|
|
120
|
+
actionLabel: "Reply",
|
|
121
|
+
actionUrl: `/chats/${conversation.id}`,
|
|
122
|
+
channels: ["mobile_push"], // Mobile only, avoid duplicate with in-app chat
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Reminders & Events**:
|
|
127
|
+
```typescript
|
|
128
|
+
// Send event reminder
|
|
129
|
+
await base44.mobile.sendNotification({
|
|
130
|
+
userId: attendee.userId,
|
|
131
|
+
title: "Event Starting Soon",
|
|
132
|
+
content: `${event.name} starts in 30 minutes`,
|
|
133
|
+
actionLabel: "View Details",
|
|
134
|
+
actionUrl: `/events/${event.id}`,
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Error Handling
|
|
139
|
+
|
|
140
|
+
The notification API handles errors gracefully:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
try {
|
|
144
|
+
const result = await base44.mobile.sendNotification({
|
|
145
|
+
userId: "user_123",
|
|
146
|
+
title: "Test Notification",
|
|
147
|
+
content: "This is a test",
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (result.success) {
|
|
151
|
+
console.log("Notification sent successfully");
|
|
152
|
+
console.log("Notification ID:", result.notificationId);
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (error.status === 404) {
|
|
156
|
+
console.error("User not found");
|
|
157
|
+
} else if (error.status === 403) {
|
|
158
|
+
console.error("Not authorized to send notifications");
|
|
159
|
+
} else {
|
|
160
|
+
console.error("Failed to send notification:", error.message);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Graceful Degradation**:
|
|
166
|
+
- If a user doesn't have mobile push enabled, the notification is still sent to other channels
|
|
167
|
+
- If one channel fails, other channels still receive the notification
|
|
168
|
+
- Notifications are queued and retried automatically for temporary failures
|
|
169
|
+
|
|
40
170
|
## Learn more
|
|
41
171
|
|
|
42
172
|
For complete documentation, guides, and API reference, visit the **[Base44 SDK Documentation](https://docs.base44.com/sdk-getting-started/overview)**.
|
package/dist/client.js
CHANGED
|
@@ -9,6 +9,7 @@ import { createFunctionsModule } from "./modules/functions.js";
|
|
|
9
9
|
import { createAgentsModule } from "./modules/agents.js";
|
|
10
10
|
import { createAppLogsModule } from "./modules/app-logs.js";
|
|
11
11
|
import { createUsersModule } from "./modules/users.js";
|
|
12
|
+
import { createMobileModule } from "./modules/mobile.js";
|
|
12
13
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
13
14
|
import { createAnalyticsModule } from "./modules/analytics.js";
|
|
14
15
|
/**
|
|
@@ -121,6 +122,7 @@ export function createClient(config) {
|
|
|
121
122
|
}),
|
|
122
123
|
appLogs: createAppLogsModule(axiosClient, appId),
|
|
123
124
|
users: createUsersModule(axiosClient, appId),
|
|
125
|
+
mobile: createMobileModule(axiosClient, appId),
|
|
124
126
|
analytics: createAnalyticsModule({
|
|
125
127
|
axiosClient,
|
|
126
128
|
serverUrl,
|
|
@@ -152,6 +154,7 @@ export function createClient(config) {
|
|
|
152
154
|
token,
|
|
153
155
|
}),
|
|
154
156
|
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
|
|
157
|
+
mobile: createMobileModule(serviceRoleAxiosClient, appId),
|
|
155
158
|
cleanup: () => {
|
|
156
159
|
if (socket) {
|
|
157
160
|
socket.disconnect();
|
package/dist/client.types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { ConnectorsModule } from "./modules/connectors.types.js";
|
|
|
6
6
|
import type { FunctionsModule } from "./modules/functions.types.js";
|
|
7
7
|
import type { AgentsModule } from "./modules/agents.types.js";
|
|
8
8
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
9
|
+
import type { MobileModule } from "./modules/mobile.types.js";
|
|
9
10
|
import type { AnalyticsModule } from "./modules/analytics.types.js";
|
|
10
11
|
/**
|
|
11
12
|
* Options for creating a Base44 client.
|
|
@@ -83,6 +84,8 @@ export interface Base44Client {
|
|
|
83
84
|
agents: AgentsModule;
|
|
84
85
|
/** {@link AppLogsModule | App logs module} for tracking app usage. */
|
|
85
86
|
appLogs: AppLogsModule;
|
|
87
|
+
/** {@link MobileModule | Mobile module} for mobile native capabilities like push notifications. */
|
|
88
|
+
mobile: MobileModule;
|
|
86
89
|
/** {@link AnalyticsModule | Analytics module} for tracking app usage. */
|
|
87
90
|
analytics: AnalyticsModule;
|
|
88
91
|
/** Cleanup function to disconnect WebSocket connections. Call when you're done with the client. */
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type { IntegrationsModule, IntegrationPackage, IntegrationEndpointFunctio
|
|
|
10
10
|
export type { FunctionsModule } from "./modules/functions.types.js";
|
|
11
11
|
export type { AgentsModule, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
12
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
13
|
+
export type { MobileModule, SendNotificationParams, NotificationResult, NotificationChannel, ChannelResult, } from "./modules/mobile.types.js";
|
|
13
14
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
14
15
|
export type { ConnectorsModule } from "./modules/connectors.types.js";
|
|
15
16
|
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
package/dist/modules/auth.js
CHANGED
|
@@ -34,16 +34,6 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
34
34
|
// Redirect to the login page
|
|
35
35
|
window.location.href = loginUrl;
|
|
36
36
|
},
|
|
37
|
-
// Redirects the user to a provider's login page
|
|
38
|
-
loginWithProvider(provider, fromUrl = "/") {
|
|
39
|
-
// Build the full redirect URL
|
|
40
|
-
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
|
|
41
|
-
// Build the provider login URL (google is the default, so no provider path needed)
|
|
42
|
-
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
43
|
-
const loginUrl = `${options.serverUrl}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
|
|
44
|
-
// Redirect to the provider login page
|
|
45
|
-
window.location.href = loginUrl;
|
|
46
|
-
},
|
|
47
37
|
// Logout the current user
|
|
48
38
|
// Removes the token from localStorage and optionally redirects to a URL or reloads the page
|
|
49
39
|
logout(redirectUrl) {
|
|
@@ -171,27 +171,6 @@ export interface AuthModule {
|
|
|
171
171
|
* ```
|
|
172
172
|
*/
|
|
173
173
|
redirectToLogin(nextUrl: string): void;
|
|
174
|
-
/**
|
|
175
|
-
* Redirects the user to a third-party authentication provider's login page.
|
|
176
|
-
*
|
|
177
|
-
* Initiates OAuth/SSO login flow with providers like Google, Microsoft, etc. Requires a browser environment and can't be used in the backend.
|
|
178
|
-
*
|
|
179
|
-
* @param provider - Name of the supported authentication provider (e.g., 'google', 'microsoft').
|
|
180
|
-
* @param fromUrl - URL to redirect to after successful authentication. Defaults to '/'.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* ```typescript
|
|
184
|
-
* // Login with Google and return to current page
|
|
185
|
-
* base44.auth.loginWithProvider('google', window.location.pathname);
|
|
186
|
-
* ```
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* ```typescript
|
|
190
|
-
* // Login with GitHub and redirect to dashboard
|
|
191
|
-
* base44.auth.loginWithProvider('microsoft', '/dashboard');
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
loginWithProvider(provider: string, fromUrl?: string): void;
|
|
195
174
|
/**
|
|
196
175
|
* Logs out the current user.
|
|
197
176
|
*
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mobile module for Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides mobile native capabilities like push notifications.
|
|
5
|
+
*/
|
|
6
|
+
import { AxiosInstance } from "axios";
|
|
7
|
+
import { MobileModule } from "./mobile.types";
|
|
8
|
+
/**
|
|
9
|
+
* Creates the mobile module for the Base44 SDK.
|
|
10
|
+
*
|
|
11
|
+
* @param axios - Axios instance for API requests
|
|
12
|
+
* @param appId - Application ID
|
|
13
|
+
* @returns Mobile module with native mobile capabilities
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function createMobileModule(axios: AxiosInstance, appId: string): MobileModule;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mobile module for Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides mobile native capabilities like push notifications.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Validates notification parameters against character limits.
|
|
8
|
+
* @param params - Notification parameters to validate
|
|
9
|
+
* @throws Error if any parameter exceeds its limit
|
|
10
|
+
*/
|
|
11
|
+
function validateNotificationParams(params) {
|
|
12
|
+
if (params.title.length > 100) {
|
|
13
|
+
throw new Error(`Title must be 100 characters or less (current: ${params.title.length})`);
|
|
14
|
+
}
|
|
15
|
+
if (params.content.length > 500) {
|
|
16
|
+
throw new Error(`Content must be 500 characters or less (current: ${params.content.length})`);
|
|
17
|
+
}
|
|
18
|
+
if (params.actionLabel && params.actionLabel.length > 50) {
|
|
19
|
+
throw new Error(`Action label must be 50 characters or less (current: ${params.actionLabel.length})`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates the mobile module for the Base44 SDK.
|
|
24
|
+
*
|
|
25
|
+
* @param axios - Axios instance for API requests
|
|
26
|
+
* @param appId - Application ID
|
|
27
|
+
* @returns Mobile module with native mobile capabilities
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function createMobileModule(axios, appId) {
|
|
31
|
+
return {
|
|
32
|
+
async sendNotification(params) {
|
|
33
|
+
// Validate input parameters
|
|
34
|
+
validateNotificationParams(params);
|
|
35
|
+
const response = await axios.post(`/api/apps/${appId}/mobile/notifications`, params);
|
|
36
|
+
return response.data;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for Base44 Mobile SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides mobile native capabilities like push notifications
|
|
5
|
+
* for apps built with Base44.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Channel type for notifications.
|
|
9
|
+
* - "mobile_push": Send via mobile push notification (Ping service)
|
|
10
|
+
* - "in_app": Send via in-app notification (WebSocket + MongoDB)
|
|
11
|
+
*/
|
|
12
|
+
export type NotificationChannel = "mobile_push" | "in_app";
|
|
13
|
+
/**
|
|
14
|
+
* Parameters for sending a notification to an app user.
|
|
15
|
+
*/
|
|
16
|
+
export interface SendNotificationParams {
|
|
17
|
+
/** App user ID to notify */
|
|
18
|
+
userId: string;
|
|
19
|
+
/** Notification title (max 100 characters) */
|
|
20
|
+
title: string;
|
|
21
|
+
/** Notification content (max 500 characters, supports HTML) */
|
|
22
|
+
content: string;
|
|
23
|
+
/** Optional button text (max 50 characters) */
|
|
24
|
+
actionLabel?: string;
|
|
25
|
+
/** Optional button link */
|
|
26
|
+
actionUrl?: string;
|
|
27
|
+
/** Optional list of channels. If not specified, uses all channels (mobile_push + in_app) */
|
|
28
|
+
channels?: NotificationChannel[];
|
|
29
|
+
/** Optional custom metadata */
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Result from a single notification channel.
|
|
34
|
+
*/
|
|
35
|
+
export interface ChannelResult {
|
|
36
|
+
/** Whether the notification was sent successfully through this channel */
|
|
37
|
+
success: boolean;
|
|
38
|
+
/** Error message if the channel failed */
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Response from sending a notification.
|
|
43
|
+
*/
|
|
44
|
+
export interface NotificationResult {
|
|
45
|
+
/** Overall success status */
|
|
46
|
+
success: boolean;
|
|
47
|
+
/** Notification ID if in_app channel was used */
|
|
48
|
+
notificationId?: string;
|
|
49
|
+
/** Results per channel */
|
|
50
|
+
channels: {
|
|
51
|
+
in_app?: ChannelResult;
|
|
52
|
+
mobile_push?: ChannelResult;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Mobile module interface providing mobile native capabilities.
|
|
57
|
+
*/
|
|
58
|
+
export interface MobileModule {
|
|
59
|
+
/**
|
|
60
|
+
* Send a notification to an app user.
|
|
61
|
+
*
|
|
62
|
+
* @param params - Notification parameters
|
|
63
|
+
* @returns Promise resolving to notification result
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // Send mobile push notification only
|
|
68
|
+
* await base44.mobile.sendNotification({
|
|
69
|
+
* userId: 'app_user_123',
|
|
70
|
+
* title: 'New Message!',
|
|
71
|
+
* content: 'You have a new message from John',
|
|
72
|
+
* actionLabel: 'View Message',
|
|
73
|
+
* actionUrl: '/messages/456',
|
|
74
|
+
* channels: ['mobile_push']
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // Send to both channels (default)
|
|
78
|
+
* await base44.mobile.sendNotification({
|
|
79
|
+
* userId: 'app_user_123',
|
|
80
|
+
* title: 'Order Shipped',
|
|
81
|
+
* content: 'Your order #12345 has been shipped'
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
sendNotification(params: SendNotificationParams): Promise<NotificationResult>;
|
|
86
|
+
}
|