@base44-preview/sdk 0.8.6-pr.52.d6f1bf2 → 0.8.6-pr.56.6f7d483

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 CHANGED
@@ -1,634 +1,81 @@
1
1
  # Base44 JavaScript SDK
2
2
 
3
- A modern JavaScript SDK for interacting with the Base44 API. Designed to work with both JavaScript and TypeScript projects.
3
+ The Base44 SDK provides a JavaScript interface for building apps on the Base44 platform. When Base44 generates your app, the generated code uses the SDK to authenticate users, manage your app's data, interact with AI agents, and more. You can then use the same SDK to modify and extend your app.
4
4
 
5
- ## Installation
5
+ ## Modules
6
6
 
7
- ```bash
8
- npm install @base44/sdk
9
- # or
10
- yarn add @base44/sdk
11
- ```
12
-
13
- ## Usage
14
-
15
- ### Basic Setup
16
-
17
- ```javascript
18
- import { createClient } from '@base44/sdk';
19
-
20
- // Create a client instance
21
- const base44 = createClient({
22
- serverUrl: 'https://base44.app', // Optional, defaults to 'https://base44.app'
23
- appId: 'your-app-id', // Required
24
- token: 'your-user-token', // Optional, for user authentication
25
- serviceToken: 'your-service-token', // Optional, for service role authentication
26
- autoInitAuth: true, // Optional, defaults to true - auto-detects tokens from URL or localStorage
27
- });
28
- ```
29
-
30
- ### Working with Entities
31
-
32
- ```javascript
33
- // List all products
34
- const products = await base44.entities.Product.list();
35
-
36
- // Filter products by category
37
- const filteredProducts = await base44.entities.Product.filter({
38
- category: ['electronics', 'computers']
39
- });
40
-
41
- // Get a specific product
42
- const product = await base44.entities.Product.get('product-id');
43
-
44
- // Create a new product
45
- const newProduct = await base44.entities.Product.create({
46
- name: 'New Product',
47
- price: 99.99,
48
- category: 'electronics'
49
- });
50
-
51
- // Update a product
52
- const updatedProduct = await base44.entities.Product.update('product-id', {
53
- price: 89.99
54
- });
55
-
56
- // Delete a product
57
- await base44.entities.Product.delete('product-id');
58
-
59
- // Bulk create products
60
- const newProducts = await base44.entities.Product.bulkCreate([
61
- { name: 'Product 1', price: 19.99 },
62
- { name: 'Product 2', price: 29.99 }
63
- ]);
64
- ```
65
-
66
- ### Service Role Authentication
67
-
68
- Service role authentication allows server-side applications to perform operations with elevated privileges. This is useful for administrative tasks, background jobs, and server-to-server communication.
69
-
70
- ```javascript
71
- import { createClient } from '@base44/sdk';
72
-
73
- // Create a client with service role token
74
- const base44 = createClient({
75
- appId: 'your-app-id',
76
- token: 'user-token', // For user operations
77
- serviceToken: 'service-token' // For service role operations
78
- });
79
-
80
- // User operations (uses user token)
81
- const userEntities = await base44.entities.User.list();
82
-
83
- // Service role operations (uses service token)
84
- const allEntities = await base44.asServiceRole.entities.User.list();
85
-
86
- // Service role has access to:
87
- // - base44.asServiceRole.entities
88
- // - base44.asServiceRole.integrations
89
- // - base44.asServiceRole.functions
90
- // Note: Service role does NOT have access to auth module for security
91
-
92
- // If no service token is provided, accessing asServiceRole throws an error
93
- const clientWithoutService = createClient({ appId: 'your-app-id' });
94
- try {
95
- await clientWithoutService.asServiceRole.entities.User.list();
96
- } catch (error) {
97
- // Error: Service token is required to use asServiceRole
98
- }
99
- ```
100
-
101
- ### Server-Side Usage
102
-
103
- For server-side applications, you can create a client from incoming HTTP requests:
104
-
105
- ```javascript
106
- import { createClientFromRequest } from '@base44/sdk';
107
-
108
- // In your server handler (Express, Next.js, etc.)
109
- app.get('/api/data', async (req, res) => {
110
- try {
111
- // Extract client configuration from request headers
112
- const base44 = createClientFromRequest(req);
113
-
114
- // Headers used:
115
- // - Authorization: Bearer <user-token>
116
- // - Base44-Service-Authorization: Bearer <service-token>
117
- // - Base44-App-Id: <app-id>
118
- // - Base44-Api-Url: <custom-api-url> (optional)
119
-
120
- // Use appropriate authentication based on available tokens
121
- let data;
122
- if (base44.asServiceRole) {
123
- // Service token available - use elevated privileges
124
- data = await base44.asServiceRole.entities.SensitiveData.list();
125
- } else {
126
- // Only user token available - use user permissions
127
- data = await base44.entities.PublicData.list();
128
- }
129
-
130
- res.json(data);
131
- } catch (error) {
132
- res.status(500).json({ error: error.message });
133
- }
134
- });
135
- ```
136
-
137
- ### Working with Integrations
138
-
139
- ```javascript
140
- // Send an email using the Core integration
141
- const emailResult = await base44.integrations.Core.SendEmail({
142
- to: 'user@example.com',
143
- subject: 'Hello from Base44',
144
- body: 'This is a test email sent via the Base44 SDK'
145
- });
146
-
147
- // Use a custom integration
148
- const result = await base44.integrations.CustomPackage.CustomEndpoint({
149
- param1: 'value1',
150
- param2: 'value2'
151
- });
152
-
153
- // Upload a file
154
- const fileInput = document.querySelector('input[type="file"]');
155
- const file = fileInput.files[0];
156
- const uploadResult = await base44.integrations.Core.UploadFile({
157
- file,
158
- metadata: { type: 'profile-picture' }
159
- });
160
- ```
161
-
162
- ## Authentication
163
-
164
- The SDK provides comprehensive authentication capabilities to help you build secure applications.
165
-
166
- ### Creating an Authenticated Client
167
-
168
- To create a client with authentication:
169
-
170
- ```javascript
171
- import { createClient } from '@base44/sdk';
172
- import { getAccessToken } from '@base44/sdk/utils/auth-utils';
173
-
174
- // Create a client with authentication
175
- const base44 = createClient({
176
- appId: 'your-app-id',
177
- token: getAccessToken() // Automatically retrieves token from localStorage or URL
178
- });
179
-
180
- // Check authentication status
181
- const isAuthenticated = await base44.auth.isAuthenticated();
182
- console.log('Authenticated:', isAuthenticated);
183
-
184
- // Get current user information (requires authentication)
185
- if (isAuthenticated) {
186
- const user = await base44.auth.me();
187
- console.log('Current user:', user);
188
- }
189
- ```
190
-
191
- ### Login and Logout
192
-
193
- ```javascript
194
- import { createClient } from '@base44/sdk';
195
- import { getAccessToken, saveAccessToken, removeAccessToken } from '@base44/sdk/utils/auth-utils';
196
-
197
- const base44 = createClient({ appId: 'your-app-id' });
198
-
199
- // Redirect to the login page
200
- // This will redirect to: base44.app/login?from_url=http://your-app.com/dashboard&app_id=your-app-id
201
- function handleLogin() {
202
- base44.auth.login('/dashboard');
203
- }
7
+ The SDK provides access to Base44's functionality through the following modules:
204
8
 
205
- // Handle successful login (on return from Base44 login)
206
- function handleLoginReturn() {
207
- const token = getAccessToken();
208
- if (token) {
209
- console.log('Successfully logged in with token:', token);
210
- // The token is automatically saved to localStorage and removed from URL
211
- }
212
- }
9
+ - **[`agents`](https://docs.base44.com/sdk-docs/interfaces/agents)**: Interact with AI agents and manage conversations.
10
+ - **[`app-logs`](https://docs.base44.com/sdk-docs/interfaces/app-logs)**: Access and query app logs.
11
+ - **[`auth`](https://docs.base44.com/sdk-docs/interfaces/auth)**: Manage user authentication, registration, and session handling.
12
+ - **[`connectors`](https://docs.base44.com/sdk-docs/interfaces/connectors)**: Manage OAuth connections and access tokens for third-party services.
13
+ - **[`entities`](https://docs.base44.com/sdk-docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
14
+ - **[`functions`](https://docs.base44.com/sdk-docs/interfaces/functions)**: Execute backend functions.
15
+ - **[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**: Access third-party integrations.
213
16
 
214
- // Logout
215
- function handleLogout() {
216
- removeAccessToken();
217
- window.location.href = '/login';
218
- }
219
- ```
220
-
221
- ### Real-World Authentication Example (React)
222
-
223
- Here's a complete example of implementing Base44 authentication in a React application:
224
-
225
- ```jsx
226
- import React, { createContext, useContext, useEffect, useState } from 'react';
227
- import { Navigate, Outlet, Route, Routes, useLocation } from 'react-router-dom';
228
- import { createClient } from '@base44/sdk';
229
- import { getAccessToken, removeAccessToken } from '@base44/sdk/utils/auth-utils';
230
-
231
- // Create AuthContext
232
- const AuthContext = createContext(null);
233
-
234
- // Auth Provider Component
235
- function AuthProvider({ children }) {
236
- const [user, setUser] = useState(null);
237
- const [loading, setLoading] = useState(true);
238
- const [client] = useState(() =>
239
- createClient({
240
- appId: 'your-app-id',
241
- token: getAccessToken()
242
- })
243
- );
244
-
245
- useEffect(() => {
246
- async function loadUser() {
247
- try {
248
- const isAuth = await client.auth.isAuthenticated();
249
- if (isAuth) {
250
- const userData = await client.auth.me();
251
- setUser(userData);
252
- }
253
- } catch (error) {
254
- console.error('Authentication error:', error);
255
- } finally {
256
- setLoading(false);
257
- }
258
- }
259
-
260
- loadUser();
261
- }, [client]);
262
-
263
- const login = () => {
264
- client.auth.login(window.location.pathname);
265
- };
266
-
267
- const logout = () => {
268
- removeAccessToken();
269
- setUser(null);
270
- window.location.href = '/login';
271
- };
272
-
273
- return (
274
- <AuthContext.Provider value={{ user, loading, client, login, logout }}>
275
- {children}
276
- </AuthContext.Provider>
277
- );
278
- }
279
-
280
- // Custom hook to use auth context
281
- function useAuth() {
282
- const context = useContext(AuthContext);
283
- if (!context) {
284
- throw new Error('useAuth must be used within an AuthProvider');
285
- }
286
- return context;
287
- }
288
-
289
- // Protected Route Component
290
- function ProtectedRoute() {
291
- const { user, loading, login } = useAuth();
292
- const location = useLocation();
293
-
294
- // Check if we're returning from login with a token in URL
295
- useEffect(() => {
296
- const token = getAccessToken(); // This will save token from URL if present
297
- if (token && !user && !loading) {
298
- window.location.reload(); // Reload to apply the new token
299
- }
300
- }, [location, user, loading]);
301
-
302
- if (loading) {
303
- return <div>Loading...</div>;
304
- }
305
-
306
- if (!user) {
307
- // If not authenticated, redirect to login
308
- login();
309
- return <div>Redirecting to login...</div>;
310
- }
17
+ ## Example
311
18
 
312
- // If authenticated, render the child routes
313
- return <Outlet />;
314
- }
315
-
316
- // Dashboard Component (protected)
317
- function Dashboard() {
318
- const { user, client, logout } = useAuth();
319
- const [todos, setTodos] = useState([]);
320
- const [loading, setLoading] = useState(true);
321
-
322
- useEffect(() => {
323
- async function loadTodos() {
324
- try {
325
- // Load user-specific data using the SDK
326
- const items = await client.entities.Todo.filter({
327
- assignee: user.id
328
- });
329
- setTodos(items);
330
- } catch (error) {
331
- console.error('Failed to load todos:', error);
332
- } finally {
333
- setLoading(false);
334
- }
335
- }
336
-
337
- loadTodos();
338
- }, [client, user]);
339
-
340
- return (
341
- <div>
342
- <h1>Welcome, {user.name}!</h1>
343
- <button onClick={logout}>Logout</button>
344
-
345
- <h2>Your Todos</h2>
346
- {loading ? (
347
- <div>Loading todos...</div>
348
- ) : (
349
- <ul>
350
- {todos.map(todo => (
351
- <li key={todo.id}>{todo.title}</li>
352
- ))}
353
- </ul>
354
- )}
355
- </div>
356
- );
357
- }
358
-
359
- // Login Page
360
- function LoginPage() {
361
- const { login, user } = useAuth();
362
-
363
- if (user) {
364
- return <Navigate to="/dashboard" />;
365
- }
366
-
367
- return (
368
- <div>
369
- <h1>Login Required</h1>
370
- <button onClick={login}>Login with Base44</button>
371
- </div>
372
- );
373
- }
374
-
375
- // App Component
376
- function App() {
377
- return (
378
- <AuthProvider>
379
- <Routes>
380
- <Route path="/login" element={<LoginPage />} />
381
- <Route element={<ProtectedRoute />}>
382
- <Route path="/dashboard" element={<Dashboard />} />
383
- <Route path="/profile" element={<ProfilePage />} />
384
- {/* Add more protected routes here */}
385
- </Route>
386
- <Route path="/" element={<Navigate to="/dashboard" />} />
387
- </Routes>
388
- </AuthProvider>
389
- );
390
- }
391
- ```
392
-
393
- ## TypeScript Support
394
-
395
- This SDK includes TypeScript definitions out of the box:
19
+ Here's a quick look at working with data in the SDK, using the `entities` module to create, update, and list records. In this example, we're working with a custom `Task` entity:
396
20
 
397
21
  ```typescript
398
- import { createClient, Base44Error } from '@base44/sdk';
399
- import type { Entity, Base44Client, AuthModule } from '@base44/sdk';
22
+ import { base44 } from "@/api/base44Client";
400
23
 
401
- // Create a typed client
402
- const base44: Base44Client = createClient({
403
- appId: 'your-app-id'
24
+ // Create a new task
25
+ const newTask = await base44.entities.Task.create({
26
+ title: "Complete project documentation",
27
+ status: "pending",
28
+ dueDate: "2024-12-31",
404
29
  });
405
30
 
406
- // Using the entities module with type safety
407
- async function fetchProducts() {
408
- try {
409
- const products: Entity[] = await base44.entities.Product.list();
410
- console.log(products.map(p => p.name));
411
-
412
- const product: Entity = await base44.entities.Product.get('product-id');
413
- console.log(product.name);
414
- } catch (error) {
415
- if (error instanceof Base44Error) {
416
- console.error(`Error ${error.status}: ${error.message}`);
417
- }
418
- }
419
- }
420
-
421
- // Service role operations with TypeScript
422
- async function adminOperations() {
423
- const base44 = createClient({
424
- appId: 'your-app-id',
425
- serviceToken: 'service-token'
426
- });
427
-
428
- // TypeScript knows asServiceRole requires a service token
429
- try {
430
- const allUsers: Entity[] = await base44.asServiceRole.entities.User.list();
431
- console.log(`Total users: ${allUsers.length}`);
432
- } catch (error) {
433
- if (error instanceof Error) {
434
- console.error(error.message); // Service token is required to use asServiceRole
435
- }
436
- }
437
- }
438
-
439
- // Authentication with TypeScript
440
- async function handleAuth(auth: AuthModule) {
441
- // Check authentication
442
- const isAuthenticated: boolean = await auth.isAuthenticated();
443
-
444
- if (isAuthenticated) {
445
- // Get user info
446
- const user: Entity = await auth.me();
447
- console.log(`Logged in as: ${user.name}, Role: ${user.role}`);
448
-
449
- // Update user
450
- const updatedUser: Entity = await auth.updateMe({
451
- preferences: { theme: 'dark' }
452
- });
453
- } else {
454
- // Redirect to login
455
- auth.login('/dashboard');
456
- }
457
- }
458
-
459
- // Execute with proper typing
460
- handleAuth(base44.auth);
461
- ```
462
-
463
- ### Advanced TypeScript Usage
464
-
465
- You can define your own entity interfaces for better type safety:
466
-
467
- ```typescript
468
- // Define custom entity interfaces
469
- interface User extends Entity {
470
- name: string;
471
- email: string;
472
- role: 'admin' | 'editor' | 'viewer';
473
- preferences?: {
474
- theme: 'light' | 'dark';
475
- notifications: boolean;
476
- };
477
- }
478
-
479
- interface Product extends Entity {
480
- name: string;
481
- price: number;
482
- category: string;
483
- inStock: boolean;
484
- }
485
-
486
- // Use your custom interfaces with the SDK
487
- async function getLoggedInUser(): Promise<User | null> {
488
- const base44 = createClient({ appId: 'your-app-id' });
489
-
490
- try {
491
- const user = await base44.auth.me() as User;
492
- return user;
493
- } catch (error) {
494
- console.error('Failed to get user:', error);
495
- return null;
496
- }
497
- }
498
-
499
- // Use with React hooks
500
- function useBase44User() {
501
- const [user, setUser] = useState<User | null>(null);
502
- const [loading, setLoading] = useState<boolean>(true);
503
-
504
- useEffect(() => {
505
- const base44 = createClient({ appId: 'your-app-id' });
506
-
507
- async function fetchUser() {
508
- try {
509
- const userData = await base44.auth.me() as User;
510
- setUser(userData);
511
- } catch (error) {
512
- console.error('Auth error:', error);
513
- } finally {
514
- setLoading(false);
515
- }
516
- }
517
-
518
- fetchUser();
519
- }, []);
520
-
521
- return { user, loading };
522
- }
523
- ```
524
-
525
- ## Error Handling
526
-
527
- The SDK provides a custom `Base44Error` class for error handling:
528
-
529
- ```javascript
530
- import { createClient, Base44Error } from '@base44/sdk';
531
-
532
- const base44 = createClient({ appId: 'your-app-id' });
31
+ // Update the task
32
+ await base44.entities.Task.update(newTask.id, {
33
+ status: "in-progress",
34
+ });
533
35
 
534
- try {
535
- const result = await base44.entities.NonExistentEntity.list();
536
- } catch (error) {
537
- if (error instanceof Base44Error) {
538
- console.error(`Status: ${error.status}`);
539
- console.error(`Message: ${error.message}`);
540
- console.error(`Code: ${error.code}`);
541
- console.error(`Data: ${JSON.stringify(error.data)}`);
542
- } else {
543
- console.error('Unexpected error:', error);
544
- }
545
- }
36
+ // List all tasks
37
+ const tasks = await base44.entities.Task.list();
546
38
  ```
547
39
 
548
- ## Functions
40
+ ## Learn more
549
41
 
550
- The SDK supports invoking custom functions:
42
+ For complete documentation, guides, and API reference, visit the **[Base44 SDK Documentation](https://docs.base44.com/sdk-getting-started/overview)**.
551
43
 
552
- ```javascript
553
- // Invoke a function without parameters
554
- const result = await base44.functions.myFunction();
44
+ ## Development
555
45
 
556
- // Invoke a function with parameters
557
- const result = await base44.functions.calculateTotal({
558
- items: ['item1', 'item2'],
559
- discount: 0.1
560
- });
46
+ ### Build the SDK
561
47
 
562
- // Functions are automatically authenticated with the user token
563
- // Service role can also invoke functions
564
- const serviceResult = await base44.asServiceRole.functions.adminFunction();
48
+ ```bash
49
+ npm install
50
+ npm run build
565
51
  ```
566
52
 
567
- ## Testing
568
-
569
- The SDK includes comprehensive tests to ensure reliability.
570
-
571
- ### Running Tests
53
+ ### Run tests
572
54
 
573
55
  ```bash
574
56
  # Run all tests
575
57
  npm test
576
58
 
577
- # Run unit tests only (no API calls)
59
+ # Run unit tests only
578
60
  npm run test:unit
579
61
 
580
- # Run end-to-end tests (requires API access)
581
- npm run test:e2e
582
-
583
- # Run tests with coverage report
62
+ # Run with coverage
584
63
  npm run test:coverage
585
64
  ```
586
65
 
587
- ### Setting Up E2E Tests
588
-
589
- E2E tests require access to a Base44 API. To run these tests:
590
-
591
- 1. Copy `tests/.env.example` to `tests/.env`
592
- 2. Fill in your Base44 API credentials in the `.env` file:
593
- ```
594
- BASE44_SERVER_URL=https://base44.app
595
- BASE44_APP_ID=your_app_id_here
596
- BASE44_AUTH_TOKEN=your_auth_token_here
597
- ```
598
-
599
- 3. Optionally, set `SKIP_E2E_TESTS=true` to skip E2E tests.
600
-
601
- ### Writing Your Own Tests
602
-
603
- You can use the provided test utilities for writing your own tests:
604
-
605
- ```javascript
606
- const { createClient } = require('@base44/sdk');
607
- const { getTestConfig } = require('@base44/sdk/tests/utils/test-config');
608
-
609
- describe('My Tests', () => {
610
- let base44;
611
-
612
- beforeAll(() => {
613
- const config = getTestConfig();
614
- base44 = createClient({
615
- serverUrl: config.serverUrl,
616
- appId: config.appId,
617
- });
618
-
619
- if (config.token) {
620
- base44.setToken(config.token);
621
- }
622
- });
623
-
624
- test('My test', async () => {
625
- const todos = await base44.entities.Todo.filter({}, 10);
626
- expect(Array.isArray(todos)).toBe(true);
627
- expect(todos.length).toBeGreaterThan(0);
628
- });
629
- });
66
+ For E2E tests, create a `tests/.env` file with:
630
67
  ```
68
+ BASE44_APP_ID=your_app_id
69
+ BASE44_AUTH_TOKEN=your_auth_token
70
+ ```
71
+
72
+ ### Generate documentation
631
73
 
632
- ## License
74
+ Generate API documentation locally:
633
75
 
634
- MIT
76
+ ```bash
77
+ # Process and preview locally
78
+ npm run create-docs
79
+ cd docs
80
+ mintlify dev
81
+ ```
package/dist/client.d.ts CHANGED
@@ -37,7 +37,6 @@ export declare function createClient(config: {
37
37
  serverUrl: string;
38
38
  appId: string;
39
39
  requiresAuth: boolean;
40
- token: string | undefined;
41
40
  };
42
41
  asServiceRole: {
43
42
  entities: {};
@@ -145,7 +144,6 @@ export declare function createClientFromRequest(request: Request): {
145
144
  serverUrl: string;
146
145
  appId: string;
147
146
  requiresAuth: boolean;
148
- token: string | undefined;
149
147
  };
150
148
  asServiceRole: {
151
149
  entities: {};
package/dist/client.js CHANGED
@@ -166,7 +166,6 @@ export function createClient(config) {
166
166
  serverUrl,
167
167
  appId,
168
168
  requiresAuth,
169
- token,
170
169
  };
171
170
  },
172
171
  /**
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { createClient, createClientFromRequest, type Base44Client } from "./client.js";
2
2
  import { Base44Error } from "./utils/axios-client.js";
3
3
  import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from "./utils/auth-utils.js";
4
- import { appParams } from "./utils/app-params.js";
5
- export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, appParams };
4
+ export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
6
5
  export type { Base44Client };
7
6
  export * from "./types.js";
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { createClient, createClientFromRequest } from "./client.js";
2
2
  import { Base44Error } from "./utils/axios-client.js";
3
3
  import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, } from "./utils/auth-utils.js";
4
- import { appParams } from "./utils/app-params.js";
5
- export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, appParams };
4
+ export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
6
5
  export * from "./types.js";
@@ -1,3 +1,2 @@
1
1
  export declare const isNode: boolean;
2
- export declare const isBrowser: boolean;
3
2
  export declare const isInIFrame: boolean;
@@ -1,3 +1,2 @@
1
1
  export const isNode = typeof window === "undefined";
2
- export const isBrowser = !isNode;
3
- export const isInIFrame = isBrowser && window.self !== window.top;
2
+ export const isInIFrame = !isNode && window.self !== window.top;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.6-pr.52.d6f1bf2",
3
+ "version": "0.8.6-pr.56.6f7d483",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,11 +0,0 @@
1
- export declare const appParams: {
2
- appId?: undefined;
3
- token?: undefined;
4
- fromUrl?: undefined;
5
- functionsVersion?: undefined;
6
- } | {
7
- appId: any;
8
- token: any;
9
- fromUrl: any;
10
- functionsVersion: any;
11
- };
@@ -1,43 +0,0 @@
1
- import { isBrowser } from './common';
2
- const toSnakeCase = (str) => {
3
- return str.replace(/([A-Z])/g, '_$1').toLowerCase();
4
- };
5
- const getAppParamValue = (paramName, { defaultValue = undefined, removeFromUrl = false } = {}) => {
6
- const storageKey = `base44_${toSnakeCase(paramName)}`;
7
- const urlParams = new URLSearchParams(window.location.search);
8
- const searchParam = urlParams.get(paramName);
9
- if (removeFromUrl) {
10
- urlParams.delete(paramName);
11
- const newUrl = `${window.location.pathname}${urlParams.toString() ? `?${urlParams.toString()}` : ""}${window.location.hash}`;
12
- window.history.replaceState({}, document.title, newUrl);
13
- }
14
- if (searchParam) {
15
- localStorage.setItem(storageKey, searchParam);
16
- return searchParam;
17
- }
18
- if (defaultValue) {
19
- localStorage.setItem(storageKey, defaultValue);
20
- return defaultValue;
21
- }
22
- const storedValue = localStorage.getItem(storageKey);
23
- if (storedValue) {
24
- return storedValue;
25
- }
26
- return null;
27
- };
28
- const getAppParams = () => {
29
- if (!isBrowser) {
30
- return {};
31
- }
32
- if (getAppParamValue("clear_access_token") === 'true') {
33
- localStorage.removeItem('base44_access_token');
34
- localStorage.removeItem('token');
35
- }
36
- return {
37
- appId: getAppParamValue("app_id"),
38
- token: getAppParamValue("access_token", { removeFromUrl: true }),
39
- fromUrl: getAppParamValue("from_url", { defaultValue: window.location.href }),
40
- functionsVersion: getAppParamValue("functions_version", { defaultValue: import.meta.env.VITE_BASE44_FUNCTIONS_VERSION }),
41
- };
42
- };
43
- export const appParams = getAppParams();