@base44-preview/sdk 0.8.19-pr.132.2bf3dc4 → 0.8.19-pr.134.6049a1e

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.
@@ -1,3 +1,50 @@
1
+ const POPUP_AUTH_DOMAIN_REGEX = /^(preview-sandbox--|preview--|checkpoint--)[^.]+\./;
2
+ function isPopupAuthDomain() {
3
+ if (typeof window === "undefined")
4
+ return false;
5
+ return POPUP_AUTH_DOMAIN_REGEX.test(window.location.hostname);
6
+ }
7
+ /**
8
+ * Opens a URL in a centered popup and, once the OAuth provider redirects
9
+ * back to our origin, mirrors that callback URL in the current window so the
10
+ * iframe processes the access_token query param exactly as a normal redirect
11
+ * would.
12
+ *
13
+ * @param url - The URL to open in the popup.
14
+ */
15
+ function loginViaPopup(url) {
16
+ const width = 500;
17
+ const height = 600;
18
+ const left = Math.round(window.screenX + (window.outerWidth - width) / 2);
19
+ const top = Math.round(window.screenY + (window.outerHeight - height) / 2);
20
+ const popup = window.open(url, "base44_auth", `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`);
21
+ if (!popup) {
22
+ return;
23
+ }
24
+ const pollTimer = setInterval(() => {
25
+ if (popup.closed) {
26
+ clearInterval(pollTimer);
27
+ return;
28
+ }
29
+ try {
30
+ // Accessing popup.location.href throws a cross-origin error while the
31
+ // OAuth provider's pages are open — that's expected and means the flow
32
+ // is still in progress. Once it stops throwing, the popup has landed
33
+ // back on our origin with the callback URL (e.g. ?access_token=...).
34
+ const callbackUrl = popup.location.href;
35
+ if (new URL(callbackUrl).origin === window.location.origin) {
36
+ clearInterval(pollTimer);
37
+ popup.close();
38
+ // Redirect the iframe to the same URL the popup landed on so it
39
+ // processes the token from the query params as it normally would.
40
+ window.location.href = callbackUrl;
41
+ }
42
+ }
43
+ catch (_a) {
44
+ // Still on the OAuth provider's domain — keep polling
45
+ }
46
+ }, 300);
47
+ }
1
48
  /**
2
49
  * Creates the auth module for the Base44 SDK.
3
50
  *
@@ -40,7 +87,12 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
40
87
  // Build the provider login URL (google is the default, so no provider path needed)
41
88
  const providerPath = provider === "google" ? "" : `/${provider}`;
42
89
  const loginUrl = `${options.appBaseUrl}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
43
- // Redirect to the provider login page
90
+ // On preview/sandbox/checkpoint domains the app runs inside an iframe —
91
+ // use a popup to avoid OAuth providers blocking iframe navigation.
92
+ if (isPopupAuthDomain()) {
93
+ return loginViaPopup(loginUrl);
94
+ }
95
+ // Default: full-page redirect
44
96
  window.location.href = loginUrl;
45
97
  },
46
98
  // Logout the current user
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.19-pr.132.2bf3dc4",
3
+ "version": "0.8.19-pr.134.6049a1e",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,66 +0,0 @@
1
- export type NotificationChannel = "email" | "sms" | "push" | "in_app";
2
- export type NotificationPriority = "low" | "normal" | "high" | "urgent";
3
- /**
4
- * A notification recipient.
5
- */
6
- export type NotificationRecipient = {
7
- userId: string;
8
- channels?: NotificationChannel[];
9
- };
10
- export type NotificationTemplate = {
11
- id: string;
12
- name: string;
13
- subject?: string;
14
- body: string;
15
- channel: NotificationChannel;
16
- };
17
- export type SendNotificationParams = {
18
- recipientId: string;
19
- templateId?: string;
20
- channel: NotificationChannel;
21
- subject?: string;
22
- body: string;
23
- priority?: NotificationPriority;
24
- metadata?: Record<string, string | number | boolean>;
25
- scheduledAt?: string;
26
- };
27
- export type BulkNotificationParams = {
28
- recipientIds: string[];
29
- templateId: string;
30
- channel: NotificationChannel;
31
- variables?: Record<string, string>;
32
- priority?: NotificationPriority;
33
- };
34
- export type NotificationResult = {
35
- id: string;
36
- status: "queued" | "sent" | "delivered" | "failed";
37
- sentAt?: string;
38
- error?: string;
39
- };
40
- export type NotificationPreferences = {
41
- userId: string;
42
- enabledChannels: NotificationChannel[];
43
- quietHoursStart?: string;
44
- quietHoursEnd?: string;
45
- unsubscribedTopics: string[];
46
- };
47
- export type ListNotificationsParams = {
48
- status?: "queued" | "sent" | "delivered" | "failed";
49
- channel?: NotificationChannel;
50
- limit?: number;
51
- skip?: number;
52
- };
53
- export interface NotificationsModule {
54
- send(params: SendNotificationParams): Promise<NotificationResult>;
55
- sendBulk(params: BulkNotificationParams): Promise<NotificationResult[]>;
56
- getPreferences(userId: string): Promise<NotificationPreferences>;
57
- updatePreferences(userId: string, preferences: Partial<Omit<NotificationPreferences, "userId">>): Promise<NotificationPreferences>;
58
- list(params?: ListNotificationsParams): Promise<NotificationResult[]>;
59
- /**
60
- * Cancels a scheduled notification before it is sent.
61
- *
62
- * @param notificationId - The ID of the notification to cancel.
63
- * @returns Promise resolving to `true` if the notification was successfully cancelled.
64
- */
65
- cancel(notificationId: string): Promise<boolean>;
66
- }
@@ -1 +0,0 @@
1
- export {};