dexie-cloud-addon 4.2.4 → 4.3.0

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.
Files changed (35) hide show
  1. package/TODO-SOCIALAUTH.md +545 -0
  2. package/dexie-cloud-import.json +2 -1
  3. package/dist/modern/DexieCloudAPI.d.ts +4 -0
  4. package/dist/modern/DexieCloudOptions.d.ts +20 -0
  5. package/dist/modern/authentication/exchangeOAuthCode.d.ts +23 -0
  6. package/dist/modern/authentication/fetchAuthProviders.d.ts +14 -0
  7. package/dist/modern/authentication/handleOAuthCallback.d.ts +57 -0
  8. package/dist/modern/authentication/interactWithUser.d.ts +19 -0
  9. package/dist/modern/authentication/oauthLogin.d.ts +37 -0
  10. package/dist/modern/default-ui/AuthProviderButton.d.ts +21 -0
  11. package/dist/modern/default-ui/LoginDialog.d.ts +5 -2
  12. package/dist/modern/default-ui/ProviderSelectionDialog.d.ts +7 -0
  13. package/dist/modern/dexie-cloud-addon.js +719 -169
  14. package/dist/modern/dexie-cloud-addon.js.map +1 -1
  15. package/dist/modern/dexie-cloud-addon.min.js +1 -1
  16. package/dist/modern/dexie-cloud-addon.min.js.gz +0 -0
  17. package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
  18. package/dist/modern/errors/OAuthError.d.ts +10 -0
  19. package/dist/modern/service-worker.js +720 -170
  20. package/dist/modern/service-worker.js.map +1 -1
  21. package/dist/modern/service-worker.min.js +1 -1
  22. package/dist/modern/service-worker.min.js.map +1 -1
  23. package/dist/modern/types/DXCUserInteraction.d.ts +24 -1
  24. package/dist/umd/dexie-cloud-addon.js +2181 -2444
  25. package/dist/umd/dexie-cloud-addon.js.gz +0 -0
  26. package/dist/umd/dexie-cloud-addon.js.map +1 -1
  27. package/dist/umd/dexie-cloud-addon.min.js +1 -1
  28. package/dist/umd/dexie-cloud-addon.min.js.gz +0 -0
  29. package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
  30. package/dist/umd/service-worker.js +2029 -2292
  31. package/dist/umd/service-worker.js.map +1 -1
  32. package/dist/umd/service-worker.min.js +1 -1
  33. package/dist/umd/service-worker.min.js.map +1 -1
  34. package/oauth_flow.md +299 -0
  35. package/package.json +10 -7
@@ -0,0 +1,57 @@
1
+ /** Parsed OAuth callback parameters */
2
+ export interface OAuthCallbackParams {
3
+ /** The Dexie Cloud authorization code */
4
+ code: string;
5
+ /** The OAuth provider that was used */
6
+ provider: string;
7
+ /** The state parameter for CSRF validation */
8
+ state: string;
9
+ }
10
+ /**
11
+ * Parses OAuth callback parameters from the current URL.
12
+ *
13
+ * Use this on your OAuth callback page (for redirect/deep link flows)
14
+ * to extract the authorization code and complete the login.
15
+ *
16
+ * @param url - The URL to parse (defaults to window.location.href)
17
+ * @returns OAuthCallbackParams if valid callback, null otherwise
18
+ * @throws OAuthError if there's an error in the callback
19
+ */
20
+ export declare function parseOAuthCallback(url?: string): OAuthCallbackParams | null;
21
+ /**
22
+ * Validates the OAuth state parameter against the stored state.
23
+ *
24
+ * @param receivedState - The state from the callback URL
25
+ * @returns true if valid, false otherwise
26
+ */
27
+ export declare function validateOAuthState(receivedState: string): boolean;
28
+ /**
29
+ * Gets the OAuth provider from sessionStorage (for redirect flows).
30
+ */
31
+ export declare function getStoredOAuthProvider(): string | null;
32
+ /**
33
+ * Cleans up OAuth-related query parameters from the URL.
34
+ * Call this after successfully handling the callback to clean up the browser URL.
35
+ */
36
+ export declare function cleanupOAuthUrl(): void;
37
+ /**
38
+ * Complete handler for OAuth callback pages.
39
+ *
40
+ * Parses the callback URL, validates state, and returns the parameters
41
+ * needed to complete the login flow.
42
+ *
43
+ * @param url - The callback URL (defaults to window.location.href)
44
+ * @returns OAuthCallbackParams if valid callback, null otherwise
45
+ * @throws OAuthError on validation failure or if callback contains an error
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // On your OAuth callback page:
50
+ * const callback = handleOAuthCallback();
51
+ * if (callback) {
52
+ * await db.cloud.login({ oauthCode: callback.code, provider: callback.provider });
53
+ * cleanupOAuthUrl();
54
+ * }
55
+ * ```
56
+ */
57
+ export declare function handleOAuthCallback(url?: string): OAuthCallbackParams | null;
@@ -1,3 +1,4 @@
1
+ import type { OAuthProviderInfo } from 'dexie-cloud-common';
1
2
  import { BehaviorSubject } from 'rxjs';
2
3
  import { DXCAlert } from '../types/DXCAlert';
3
4
  import { DXCInputField } from '../types/DXCInputField';
@@ -19,3 +20,21 @@ export declare function alertUser(userInteraction: BehaviorSubject<DXCUserIntera
19
20
  export declare function promptForEmail(userInteraction: BehaviorSubject<DXCUserInteraction | undefined>, title: string, emailHint?: string): Promise<string>;
20
21
  export declare function promptForOTP(userInteraction: BehaviorSubject<DXCUserInteraction | undefined>, email: string, alert?: DXCAlert): Promise<string>;
21
22
  export declare function confirmLogout(userInteraction: BehaviorSubject<DXCUserInteraction | undefined>, currentUserId: string, numUnsyncedChanges: number): Promise<boolean>;
23
+ /** Result from provider selection prompt */
24
+ export type ProviderSelectionResult = {
25
+ type: 'provider';
26
+ provider: string;
27
+ } | {
28
+ type: 'otp';
29
+ };
30
+ /**
31
+ * Prompts the user to select an authentication method (OAuth provider or OTP).
32
+ *
33
+ * @param userInteraction - The user interaction BehaviorSubject
34
+ * @param providers - Available OAuth providers
35
+ * @param otpEnabled - Whether OTP is available
36
+ * @param title - Dialog title
37
+ * @param alerts - Optional alerts to display
38
+ * @returns Promise resolving to the user's selection
39
+ */
40
+ export declare function promptForProvider(userInteraction: BehaviorSubject<DXCUserInteraction | undefined>, providers: OAuthProviderInfo[], otpEnabled: boolean, title?: string, alerts?: DXCAlert[]): Promise<ProviderSelectionResult>;
@@ -0,0 +1,37 @@
1
+ /** Options for OAuth login */
2
+ export interface OAuthLoginOptions {
3
+ /** The Dexie Cloud database URL */
4
+ databaseUrl: string;
5
+ /** The OAuth provider name */
6
+ provider: string;
7
+ /** Optional redirect URI for non-popup flows */
8
+ redirectUri?: string;
9
+ /** Whether to use popup (default: true) */
10
+ usePopup?: boolean;
11
+ }
12
+ /** Result from OAuth login */
13
+ export interface OAuthLoginResult {
14
+ /** The Dexie Cloud authorization code */
15
+ code: string;
16
+ /** The provider that was used */
17
+ provider: string;
18
+ /** The state parameter */
19
+ state: string;
20
+ }
21
+ /**
22
+ * Initiates OAuth login flow using a popup window.
23
+ *
24
+ * Opens a popup to the OAuth provider, listens for postMessage with the result,
25
+ * and returns the Dexie Cloud authorization code.
26
+ *
27
+ * @param options - OAuth login options
28
+ * @returns Promise resolving to OAuthLoginResult
29
+ * @throws OAuthError on failure
30
+ */
31
+ export declare function oauthLogin(options: OAuthLoginOptions): Promise<OAuthLoginResult>;
32
+ /**
33
+ * Initiates OAuth login via redirect (non-popup flow).
34
+ * The page will navigate to the OAuth provider and redirect back to the app.
35
+ * Use handleOAuthCallback on the callback page to complete the flow.
36
+ */
37
+ export declare function startOAuthRedirect(options: OAuthLoginOptions): void;
@@ -0,0 +1,21 @@
1
+ import { h } from 'preact';
2
+ import type { OAuthProviderInfo } from 'dexie-cloud-common';
3
+ export interface AuthProviderButtonProps {
4
+ provider: OAuthProviderInfo;
5
+ onClick: () => void;
6
+ }
7
+ /**
8
+ * Button component for OAuth provider login.
9
+ * Displays the provider's icon and name following provider branding guidelines.
10
+ */
11
+ export declare function AuthProviderButton({ provider, onClick }: AuthProviderButtonProps): h.JSX.Element;
12
+ /**
13
+ * Button for email/OTP authentication option.
14
+ */
15
+ export declare function OtpButton({ onClick }: {
16
+ onClick: () => void;
17
+ }): h.JSX.Element;
18
+ /**
19
+ * Visual divider with "or" text.
20
+ */
21
+ export declare function Divider(): h.JSX.Element;
@@ -1,3 +1,6 @@
1
1
  import { h } from 'preact';
2
- import { DXCUserInteraction } from '../types/DXCUserInteraction';
3
- export declare function LoginDialog({ title, type, alerts, fields, submitLabel, cancelLabel, onCancel, onSubmit, }: DXCUserInteraction): h.JSX.Element;
2
+ import { DXCUserInteraction, DXCProviderSelection } from '../types/DXCUserInteraction';
3
+ /** User interactions that have the standard form-based structure */
4
+ type FormBasedInteraction = Exclude<DXCUserInteraction, DXCProviderSelection>;
5
+ export declare function LoginDialog({ title, type, alerts, fields, submitLabel, cancelLabel, onCancel, onSubmit, }: FormBasedInteraction): h.JSX.Element;
6
+ export {};
@@ -0,0 +1,7 @@
1
+ import { h } from 'preact';
2
+ import { DXCProviderSelection } from '../types/DXCUserInteraction';
3
+ /**
4
+ * Dialog component for OAuth provider selection.
5
+ * Displays available OAuth providers as buttons and optionally an email/OTP option.
6
+ */
7
+ export declare function ProviderSelectionDialog({ title, alerts, providers, otpEnabled, cancelLabel, onSelectProvider, onSelectOtp, onCancel, }: DXCProviderSelection): h.JSX.Element;