dexie-cloud-addon 4.3.0 → 4.3.3
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/TODO-SOCIALAUTH.md +129 -400
- package/dist/modern/DexieCloudOptions.d.ts +8 -11
- package/dist/modern/authentication/handleOAuthCallback.d.ts +20 -14
- package/dist/modern/authentication/interactWithUser.d.ts +3 -0
- package/dist/modern/authentication/oauthLogin.d.ts +28 -27
- package/dist/modern/default-ui/LoginDialog.d.ts +29 -4
- package/dist/modern/default-ui/OptionButton.d.ts +21 -0
- package/dist/modern/default-ui/SelectDialog.d.ts +10 -0
- package/dist/modern/dexie-cloud-addon.js +454 -305
- package/dist/modern/dexie-cloud-addon.js.map +1 -1
- package/dist/modern/dexie-cloud-addon.min.js +1 -1
- package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
- package/dist/modern/errors/OAuthError.d.ts +1 -1
- package/dist/modern/errors/OAuthRedirectError.d.ts +11 -0
- package/dist/modern/service-worker.js +454 -305
- package/dist/modern/service-worker.js.map +1 -1
- package/dist/modern/service-worker.min.js +1 -1
- package/dist/modern/service-worker.min.js.map +1 -1
- package/dist/modern/types/DXCUserInteraction.d.ts +33 -25
- package/dist/umd/dexie-cloud-addon.js +454 -305
- package/dist/umd/dexie-cloud-addon.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.min.js +1 -1
- package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
- package/dist/umd/service-worker.js +454 -305
- package/dist/umd/service-worker.js.map +1 -1
- package/dist/umd/service-worker.min.js +1 -1
- package/dist/umd/service-worker.min.js.map +1 -1
- package/oauth_flow.md +84 -76
- package/package.json +3 -3
|
@@ -29,19 +29,16 @@ export interface DexieCloudOptions {
|
|
|
29
29
|
* - false: Disable OAuth, always use OTP flow
|
|
30
30
|
*
|
|
31
31
|
* Use `false` for backward compatibility if your custom login UI
|
|
32
|
-
* doesn't handle the `
|
|
32
|
+
* doesn't handle the `DXCSelect` interaction type yet.
|
|
33
33
|
*/
|
|
34
34
|
socialAuth?: boolean;
|
|
35
|
-
/** Redirect URI for OAuth callback
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
35
|
+
/** Redirect URI for OAuth callback.
|
|
36
|
+
* Defaults to window.location.href for web SPAs.
|
|
37
|
+
*
|
|
38
|
+
* For Capacitor/native apps, set this to a custom URL scheme:
|
|
39
|
+
* ```
|
|
40
|
+
* oauthRedirectUri: 'myapp://'
|
|
41
|
+
* ```
|
|
40
42
|
*/
|
|
41
43
|
oauthRedirectUri?: string;
|
|
42
|
-
/** Use popup window for OAuth flow.
|
|
43
|
-
* - true (default for web): Opens OAuth in popup, uses postMessage
|
|
44
|
-
* - false: Opens OAuth in same window or system browser (Capacitor)
|
|
45
|
-
*/
|
|
46
|
-
oauthPopup?: boolean;
|
|
47
44
|
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
/** Parsed OAuth callback parameters */
|
|
1
|
+
/** Parsed OAuth callback parameters from dxc-auth query parameter */
|
|
2
2
|
export interface OAuthCallbackParams {
|
|
3
3
|
/** The Dexie Cloud authorization code */
|
|
4
4
|
code: string;
|
|
5
5
|
/** The OAuth provider that was used */
|
|
6
6
|
provider: string;
|
|
7
|
-
/** The state parameter
|
|
7
|
+
/** The state parameter */
|
|
8
8
|
state: string;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Parses OAuth callback parameters from the
|
|
11
|
+
* Parses OAuth callback parameters from the dxc-auth query parameter.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* The dxc-auth parameter contains base64url-encoded JSON with the following structure:
|
|
14
|
+
* - On success: { "code": "...", "provider": "...", "state": "..." }
|
|
15
|
+
* - On error: { "error": "...", "provider": "...", "state": "..." }
|
|
15
16
|
*
|
|
16
17
|
* @param url - The URL to parse (defaults to window.location.href)
|
|
17
18
|
* @returns OAuthCallbackParams if valid callback, null otherwise
|
|
@@ -30,28 +31,33 @@ export declare function validateOAuthState(receivedState: string): boolean;
|
|
|
30
31
|
*/
|
|
31
32
|
export declare function getStoredOAuthProvider(): string | null;
|
|
32
33
|
/**
|
|
33
|
-
* Cleans up
|
|
34
|
+
* Cleans up the dxc-auth query parameter from the URL.
|
|
34
35
|
* Call this after successfully handling the callback to clean up the browser URL.
|
|
35
36
|
*/
|
|
36
37
|
export declare function cleanupOAuthUrl(): void;
|
|
37
38
|
/**
|
|
38
|
-
* Complete handler for OAuth callback
|
|
39
|
+
* Complete handler for OAuth callback.
|
|
39
40
|
*
|
|
40
|
-
* Parses the
|
|
41
|
+
* Parses the dxc-auth query parameter, validates state, and returns the parameters
|
|
41
42
|
* needed to complete the login flow.
|
|
42
43
|
*
|
|
44
|
+
* Note: For web SPAs using full page redirect, the dexie-cloud-addon automatically
|
|
45
|
+
* detects and processes the dxc-auth parameter when db.cloud.configure() is called.
|
|
46
|
+
* This function is primarily useful for Capacitor/native apps handling deep links.
|
|
47
|
+
*
|
|
43
48
|
* @param url - The callback URL (defaults to window.location.href)
|
|
44
49
|
* @returns OAuthCallbackParams if valid callback, null otherwise
|
|
45
50
|
* @throws OAuthError on validation failure or if callback contains an error
|
|
46
51
|
*
|
|
47
52
|
* @example
|
|
48
53
|
* ```typescript
|
|
49
|
-
* //
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
54
|
+
* // Capacitor deep link handler:
|
|
55
|
+
* App.addListener('appUrlOpen', async ({ url }) => {
|
|
56
|
+
* const callback = handleOAuthCallback(url);
|
|
57
|
+
* if (callback) {
|
|
58
|
+
* await db.cloud.login({ oauthCode: callback.code, provider: callback.provider });
|
|
59
|
+
* }
|
|
60
|
+
* });
|
|
55
61
|
* ```
|
|
56
62
|
*/
|
|
57
63
|
export declare function handleOAuthCallback(url?: string): OAuthCallbackParams | null;
|
|
@@ -30,6 +30,9 @@ export type ProviderSelectionResult = {
|
|
|
30
30
|
/**
|
|
31
31
|
* Prompts the user to select an authentication method (OAuth provider or OTP).
|
|
32
32
|
*
|
|
33
|
+
* This function converts OAuth providers and OTP option into generic DXCOption[]
|
|
34
|
+
* for the DXCSelect interaction, handling icon fetching and style hints.
|
|
35
|
+
*
|
|
33
36
|
* @param userInteraction - The user interaction BehaviorSubject
|
|
34
37
|
* @param providers - Available OAuth providers
|
|
35
38
|
* @param otpEnabled - Whether OTP is available
|
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { OAuthError } from '../errors/OAuthError';
|
|
2
|
+
/** Options for initiating OAuth redirect */
|
|
3
|
+
export interface OAuthRedirectOptions {
|
|
3
4
|
/** The Dexie Cloud database URL */
|
|
4
5
|
databaseUrl: string;
|
|
5
6
|
/** The OAuth provider name */
|
|
6
7
|
provider: string;
|
|
7
|
-
/** Optional redirect URI
|
|
8
|
+
/** Optional redirect URI override.
|
|
9
|
+
* Defaults to window.location.href for web apps.
|
|
10
|
+
* For Capacitor/native apps, use a custom URL scheme like 'myapp://'
|
|
11
|
+
*/
|
|
8
12
|
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
13
|
}
|
|
21
14
|
/**
|
|
22
|
-
* Initiates OAuth login
|
|
15
|
+
* Initiates OAuth login via full page redirect.
|
|
23
16
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
17
|
+
* The page will navigate to the OAuth provider. After authentication,
|
|
18
|
+
* the user is redirected back to the app with a `dxc-auth` query parameter
|
|
19
|
+
* containing base64url-encoded JSON with the authorization code.
|
|
26
20
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
21
|
+
* The dexie-cloud-addon automatically detects and processes this parameter
|
|
22
|
+
* when db.cloud.configure() is called on page load.
|
|
23
|
+
*
|
|
24
|
+
* @param options - OAuth redirect options
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // Initiate OAuth login
|
|
29
|
+
* startOAuthRedirect({
|
|
30
|
+
* databaseUrl: 'https://mydb.dexie.cloud',
|
|
31
|
+
* provider: 'google'
|
|
32
|
+
* });
|
|
33
|
+
* // Page navigates away, user authenticates, then returns with auth code
|
|
34
|
+
* ```
|
|
36
35
|
*/
|
|
37
|
-
export declare function startOAuthRedirect(options:
|
|
36
|
+
export declare function startOAuthRedirect(options: OAuthRedirectOptions): void;
|
|
37
|
+
/** Map OAuth error strings to error codes */
|
|
38
|
+
export declare function mapOAuthError(error: string): OAuthError['code'];
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { h } from 'preact';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { DXCOption } from '../types/DXCUserInteraction';
|
|
3
|
+
import { DXCInputField } from '../types/DXCInputField';
|
|
4
|
+
import { DXCAlert } from '../types/DXCAlert';
|
|
5
|
+
/** Props for LoginDialog - accepts any user interaction */
|
|
6
|
+
interface LoginDialogProps {
|
|
7
|
+
title: string;
|
|
8
|
+
alerts: DXCAlert[];
|
|
9
|
+
fields: {
|
|
10
|
+
[name: string]: DXCInputField;
|
|
11
|
+
};
|
|
12
|
+
options?: DXCOption[];
|
|
13
|
+
submitLabel?: string;
|
|
14
|
+
cancelLabel?: string | null;
|
|
15
|
+
onSubmit: (params: {
|
|
16
|
+
[paramName: string]: string;
|
|
17
|
+
}) => void;
|
|
18
|
+
onCancel: () => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generic dialog that can render:
|
|
22
|
+
* - Form fields (text inputs)
|
|
23
|
+
* - Selectable options (buttons)
|
|
24
|
+
* - Or both together
|
|
25
|
+
*
|
|
26
|
+
* When an option is clicked, calls onSubmit({ [option.name]: option.value }).
|
|
27
|
+
* This unified approach means the same callback handles both form submission
|
|
28
|
+
* and option selection.
|
|
29
|
+
*/
|
|
30
|
+
export declare function LoginDialog({ title, alerts, fields, options, submitLabel, cancelLabel, onCancel, onSubmit, }: LoginDialogProps): h.JSX.Element;
|
|
6
31
|
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
import { DXCOption } from '../types/DXCUserInteraction';
|
|
3
|
+
export interface OptionButtonProps {
|
|
4
|
+
option: DXCOption;
|
|
5
|
+
onClick: () => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Generic button component for selectable options.
|
|
9
|
+
* Displays the option's icon and display name.
|
|
10
|
+
*
|
|
11
|
+
* The icon can be:
|
|
12
|
+
* - Inline SVG (iconSvg) - rendered directly with dangerouslySetInnerHTML
|
|
13
|
+
* - Image URL (iconUrl) - rendered as an img tag
|
|
14
|
+
*
|
|
15
|
+
* Style is determined by the styleHint property for branding purposes.
|
|
16
|
+
*/
|
|
17
|
+
export declare function OptionButton({ option, onClick }: OptionButtonProps): h.JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* Visual divider with "or" text.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Divider(): h.JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
import { DXCSelect } from '../types/DXCUserInteraction';
|
|
3
|
+
/**
|
|
4
|
+
* Dialog component for generic option selection.
|
|
5
|
+
* Displays available options as buttons.
|
|
6
|
+
*
|
|
7
|
+
* This component is UI-agnostic and works with any DXCSelect interaction,
|
|
8
|
+
* whether for authentication, settings, or other selection purposes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function SelectDialog({ title, alerts, options, cancelLabel, onSelect, onCancel, }: DXCSelect): h.JSX.Element;
|