@auth-link/web 2.0.0 → 3.0.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.
- package/CHANGELOG.md +21 -0
- package/README.md +120 -129
- package/dist/index.js +203 -658
- package/dist/index.js.map +4 -4
- package/dist/react.js +227 -584
- package/dist/react.js.map +4 -4
- package/dist/types/core.d.ts +4 -38
- package/dist/types/index.d.ts +3 -7
- package/dist/types/modal.d.ts +3 -19
- package/dist/types/react.d.ts +4 -15
- package/dist/types/types.d.ts +35 -59
- package/dist/types/view.d.ts +6 -10
- package/dist/types/vue.d.ts +5 -16
- package/dist/vue.js +231 -626
- package/dist/vue.js.map +4 -4
- package/docs/README.en.md +41 -44
- package/docs/README.ja.md +41 -44
- package/docs/README.zh-CN.md +41 -44
- package/examples/react-client.tsx +9 -21
- package/examples/vue-client.vue +9 -26
- package/package.json +2 -2
- package/dist/types/passcode.d.ts +0 -28
package/dist/types/core.d.ts
CHANGED
|
@@ -1,42 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BindingTicket } from './types.js';
|
|
2
2
|
export declare class AuthLinkError extends Error {
|
|
3
3
|
readonly code: string;
|
|
4
4
|
constructor(code: string);
|
|
5
5
|
}
|
|
6
|
-
export declare function
|
|
7
|
-
|
|
8
|
-
export declare function
|
|
9
|
-
export interface ClientOptions {
|
|
10
|
-
/** Application backend URL, never the AuthLink tenant API. Defaults to /api/authlink. */
|
|
11
|
-
baseUrl?: string;
|
|
12
|
-
/** Explicit extra backend origins, e.g. https://api.example.com (no path or wildcard). */
|
|
13
|
-
allowedBackendOrigins?: readonly string[];
|
|
14
|
-
/** Defaults to same-origin, or omit when accessToken is provided. */
|
|
15
|
-
credentials?: RequestCredentials;
|
|
16
|
-
/** Required for cookie/session authentication, including mixed cookie + Bearer mode. */
|
|
17
|
-
csrfToken?: () => string | Promise<string>;
|
|
18
|
-
/** Defaults to X-CSRF-Token; adapt this to your backend framework. */
|
|
19
|
-
csrfHeaderName?: string;
|
|
20
|
-
/** Current website login token, read on each request. Never an AuthLink tenant key. */
|
|
21
|
-
accessToken?: () => string | Promise<string>;
|
|
22
|
-
/** Extra headers. SDK-controlled authentication and protocol headers cannot be replaced. */
|
|
23
|
-
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
24
|
-
authLinkOrigin?: string;
|
|
25
|
-
fetch?: typeof fetch;
|
|
26
|
-
}
|
|
27
|
-
export declare function createBackendCall(options: ClientOptions): (path: string, body: unknown, signal?: AbortSignal, key?: string) => Promise<unknown>;
|
|
28
|
-
export declare function createAuthLinkClient(options: ClientOptions): AuthLinkClient;
|
|
29
|
-
export declare function requestKey(): string;
|
|
30
|
-
export declare function initialSnapshot(): Snapshot;
|
|
31
|
-
export interface ObserveOptions extends Events {
|
|
32
|
-
onReady?: (submit: (confirmationCode: string) => Promise<void>) => void;
|
|
33
|
-
/** Presentation-only timing from the same monotonic clock as code expiry. */
|
|
34
|
-
onCodeTiming?: (remainingMs: number) => void;
|
|
35
|
-
expectedMode?: Mode;
|
|
36
|
-
client: AuthLinkClient;
|
|
37
|
-
signal: AbortSignal;
|
|
38
|
-
intervalMs?: number;
|
|
39
|
-
onUpdate: (value: Snapshot) => void;
|
|
40
|
-
}
|
|
41
|
-
/** Observe a request CREATED BY your backend. Mounting widgets never creates requests. */
|
|
42
|
-
export declare function observeRequest(input: Ticket, options: ObserveOptions): Promise<void>;
|
|
6
|
+
export declare function deadline(value: string): number;
|
|
7
|
+
/** Public QR validation and local rendering only; no network requests. */
|
|
8
|
+
export declare function bindingImage(ticket: BindingTicket, expectedOrigin?: string): string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { AuthLinkError
|
|
1
|
+
export type { Locale, Submit, SubmitContext, VerifyOptions, BindOptions, BindingTicket, AuthLinkModal } from './types.js';
|
|
2
|
+
export { AuthLinkError } from './core.js';
|
|
3
3
|
export { supportedLocales } from './i18n.js';
|
|
4
|
-
export {
|
|
5
|
-
export type { AuthLinkModal, AuthLinkModalOptions } from './modal.js';
|
|
6
|
-
export type { ClientOptions } from './core.js';
|
|
7
|
-
export { openPasscode, createPasscodeClient } from './passcode.js';
|
|
8
|
-
export type { OTPVerification, PasscodeClient, PasscodeOptions } from './passcode.js';
|
|
4
|
+
export { openBind, openVerify } from './modal.js';
|
package/dist/types/modal.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
className?: string;
|
|
5
|
-
onClose?: () => void;
|
|
6
|
-
}
|
|
7
|
-
export interface AuthLinkModal {
|
|
8
|
-
/** Close the UI and abort observation. Does not reject or delete the server request. */
|
|
9
|
-
close(): void;
|
|
10
|
-
/** Component cleanup: close without delivering a user-close callback. */
|
|
11
|
-
destroy(): void;
|
|
12
|
-
setLocale(locale?: Locale): void;
|
|
13
|
-
retry(): void;
|
|
14
|
-
}
|
|
15
|
-
export declare function element(value: ViewNode | string, svg?: boolean): Node;
|
|
16
|
-
/** Show a backend-created request. This function never creates or authorizes a request. */
|
|
17
|
-
export declare function openAuthLink(options: AuthLinkModalOptions): AuthLinkModal;
|
|
18
|
-
export declare const openAuthLinkBind: (options: AuthLinkModalOptions) => AuthLinkModal;
|
|
19
|
-
export declare const openAuthLinkConfirm: (options: AuthLinkModalOptions) => AuthLinkModal;
|
|
1
|
+
import type { AuthLinkModal, BindOptions, VerifyOptions } from './types.js';
|
|
2
|
+
export declare const openVerify: (options: VerifyOptions) => AuthLinkModal;
|
|
3
|
+
export declare const openBind: (options: BindOptions) => AuthLinkModal;
|
package/dist/types/react.d.ts
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export declare function AuthLinkPasscode(props: PasscodeOptions): null;
|
|
6
|
-
export type { Ticket, Confirmation, Rejection, Snapshot, AuthLinkClient, Locale } from './types.js';
|
|
7
|
-
export declare function useAuthLink(options: WidgetOptions): {
|
|
8
|
-
snapshot: Snapshot;
|
|
9
|
-
retry: () => void;
|
|
10
|
-
submitCode: (code: string) => Promise<void>;
|
|
11
|
-
};
|
|
12
|
-
export interface AuthLinkWidgetProps extends AuthLinkModalOptions {
|
|
13
|
-
}
|
|
14
|
-
export declare function AuthLinkBind(props: AuthLinkWidgetProps): import("react").JSX.Element;
|
|
15
|
-
export declare function AuthLinkConfirm(props: AuthLinkWidgetProps): import("react").JSX.Element;
|
|
1
|
+
import type { BindOptions, VerifyOptions } from './types.js';
|
|
2
|
+
export type { BindOptions, VerifyOptions, Submit, SubmitContext, Locale } from './types.js';
|
|
3
|
+
export declare function AuthLinkVerify(props: VerifyOptions): import("react").JSX.Element;
|
|
4
|
+
export declare function AuthLinkBind(props: BindOptions): import("react").JSX.Element;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,69 +1,45 @@
|
|
|
1
|
-
export type Mode = 'bind' | 'confirm';
|
|
2
|
-
export type Status = 'idle' | 'pending' | 'confirmed' | 'rejected' | 'expired' | 'error';
|
|
3
1
|
export type Locale = 'en' | 'zh-CN' | 'zh-TW' | 'ja' | 'bn' | 'es' | 'fil' | 'hi' | 'id' | 'ms' | 'pt' | 'th' | 'vi';
|
|
4
|
-
|
|
5
|
-
export interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export type Status = 'pending' | 'confirmed' | 'expired' | 'error';
|
|
3
|
+
export interface SubmitContext {
|
|
4
|
+
signal: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
/** Resolve only after the CMS has verified and committed its operation.
|
|
7
|
+
* Throw on HTTP OR business failure. No AuthLink receipt is required here. */
|
|
8
|
+
export type Submit = (passcode: string, context: SubmitContext) => Promise<void>;
|
|
9
|
+
export interface VerifyOptions {
|
|
10
|
+
submit: Submit;
|
|
11
|
+
/** Optional CMS action deadline, NOT the App code lifetime. */
|
|
12
|
+
expiresAt?: string;
|
|
13
|
+
locale?: Locale;
|
|
14
|
+
onSuccess?: () => void | Promise<void>;
|
|
15
|
+
onClose?: () => void;
|
|
16
|
+
onExpired?: () => void | Promise<void>;
|
|
17
|
+
onError?: (error: Error) => void;
|
|
10
18
|
}
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
purpose: Mode;
|
|
19
|
+
export interface BindingTicket {
|
|
20
|
+
/** CMS-returned QR payload, not an image URL. */
|
|
14
21
|
qr: string;
|
|
15
|
-
|
|
22
|
+
/** Original server deadline; at most 60 minutes from creation. */
|
|
16
23
|
expiresAt: string;
|
|
17
|
-
displayCode?: DisplayCode;
|
|
18
|
-
}
|
|
19
|
-
export interface Confirmation {
|
|
20
|
-
status: 'confirmed';
|
|
21
|
-
requestId: string;
|
|
22
|
-
verificationId: string;
|
|
23
|
-
authenticationPolicy: 'device-presence.v1';
|
|
24
|
-
purpose: Mode;
|
|
25
|
-
expiresAt: string;
|
|
26
|
-
}
|
|
27
|
-
/** Business result delivered when the phone rejects a request. Not an HTTP status. */
|
|
28
|
-
export interface Rejection {
|
|
29
|
-
status: 'rejected';
|
|
30
|
-
code: 'REJECTED';
|
|
31
|
-
requestId: string;
|
|
32
|
-
purpose: Mode;
|
|
33
24
|
}
|
|
34
|
-
export interface
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export interface
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
export interface BindOptions extends Omit<VerifyOptions, 'expiresAt'>, BindingTicket {
|
|
26
|
+
/** Expected AuthLink API origin. Never a CMS backend URL. */
|
|
27
|
+
authLinkOrigin?: string;
|
|
28
|
+
/** Explicit user refresh only; no automatic QR creation. */
|
|
29
|
+
onRefresh?: (context: SubmitContext) => Promise<BindingTicket>;
|
|
30
|
+
}
|
|
31
|
+
export interface AuthLinkModal {
|
|
32
|
+
/** Abort browser work; does not roll back CMS operations. */
|
|
33
|
+
close(): void;
|
|
34
|
+
/** Unmount without onClose. */
|
|
35
|
+
destroy(): void;
|
|
36
|
+
setLocale(locale?: Locale): void;
|
|
37
|
+
/** Clear errors without submitting or making requests. */
|
|
38
|
+
retry(): void;
|
|
46
39
|
}
|
|
47
40
|
export interface Snapshot {
|
|
48
41
|
status: Status;
|
|
49
|
-
submitting
|
|
50
|
-
|
|
51
|
-
secondsRemaining: number;
|
|
52
|
-
codeSecondsRemaining: number;
|
|
42
|
+
submitting: boolean;
|
|
43
|
+
secondsRemaining?: number;
|
|
53
44
|
error: Error | null;
|
|
54
45
|
}
|
|
55
|
-
export interface Events {
|
|
56
|
-
onConfirmed?: (result: Confirmation) => void | Promise<void>;
|
|
57
|
-
onRejected?: (result: Rejection) => void | Promise<void>;
|
|
58
|
-
onExpired?: () => void | Promise<void>;
|
|
59
|
-
onError?: (error: Error) => void;
|
|
60
|
-
}
|
|
61
|
-
export interface WidgetOptions extends Events {
|
|
62
|
-
mode?: Mode;
|
|
63
|
-
ticket: Ticket;
|
|
64
|
-
client: AuthLinkClient;
|
|
65
|
-
locale?: Locale;
|
|
66
|
-
showQr?: boolean;
|
|
67
|
-
intervalMs?: number;
|
|
68
|
-
onRefresh?: () => void;
|
|
69
|
-
}
|
package/dist/types/view.d.ts
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import type { Locale,
|
|
1
|
+
import type { Locale, Snapshot } from './types.js';
|
|
2
2
|
export interface ViewNode {
|
|
3
3
|
tag: string;
|
|
4
4
|
props: Record<string, unknown>;
|
|
5
5
|
children: (ViewNode | string)[];
|
|
6
6
|
}
|
|
7
7
|
export declare function widgetView(options: {
|
|
8
|
-
mode:
|
|
8
|
+
mode: 'bind' | 'confirm';
|
|
9
9
|
locale?: Locale;
|
|
10
10
|
snapshot: Snapshot;
|
|
11
|
-
passcodeMode?: boolean;
|
|
12
11
|
qr?: string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
retry: () => void;
|
|
18
|
-
refresh?: () => void;
|
|
19
|
-
className?: string;
|
|
12
|
+
inputCode: string;
|
|
13
|
+
setCode: (code: string) => void;
|
|
14
|
+
submitCode: (code: string) => Promise<void>;
|
|
15
|
+
refresh?: () => Promise<void>;
|
|
20
16
|
}): ViewNode;
|
package/dist/types/vue.d.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
import type { DefineComponent
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export declare const AuthLinkPasscode: DefineComponent<PasscodeOptions>;
|
|
7
|
-
export type { Ticket, Confirmation, Rejection, Snapshot, AuthLinkClient, Locale } from './types.js';
|
|
8
|
-
export declare function useAuthLink(getOptions: () => WidgetOptions): {
|
|
9
|
-
snapshot: ShallowRef<Snapshot>;
|
|
10
|
-
retry: () => void;
|
|
11
|
-
submitCode: (code: string) => Promise<void>;
|
|
12
|
-
};
|
|
13
|
-
export interface AuthLinkWidgetProps extends Omit<AuthLinkModalOptions, 'mode'> {
|
|
14
|
-
}
|
|
15
|
-
export declare const AuthLinkBind: DefineComponent<AuthLinkWidgetProps>;
|
|
16
|
-
export declare const AuthLinkConfirm: DefineComponent<AuthLinkWidgetProps>;
|
|
1
|
+
import type { DefineComponent } from 'vue';
|
|
2
|
+
import type { BindOptions, VerifyOptions } from './types.js';
|
|
3
|
+
export type { BindOptions, VerifyOptions, Submit, SubmitContext, Locale } from './types.js';
|
|
4
|
+
export declare const AuthLinkVerify: DefineComponent<VerifyOptions>;
|
|
5
|
+
export declare const AuthLinkBind: DefineComponent<BindOptions>;
|