@verft/sdk 0.0.0-stage → 1.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.
@@ -0,0 +1,25 @@
1
+ import type { Caller, IdentityFailure } from "./protocol.js";
2
+ export type EmailedLink = "signIn" | "verification" | "passwordReset" | "invitation";
3
+ export type Landing = {
4
+ readonly state: "none";
5
+ } | {
6
+ readonly state: "redeeming";
7
+ readonly link: EmailedLink;
8
+ } | {
9
+ readonly state: "signedIn";
10
+ readonly link: EmailedLink;
11
+ readonly caller: Caller;
12
+ } | {
13
+ readonly state: "refused";
14
+ readonly link: EmailedLink;
15
+ readonly failure: IdentityFailure;
16
+ } | {
17
+ readonly state: "newPassword";
18
+ readonly emailed: string;
19
+ };
20
+ export interface Landed {
21
+ readonly link: EmailedLink;
22
+ readonly emailed: string;
23
+ readonly url: string;
24
+ }
25
+ export declare function landed(url: string): Landed | null;
@@ -0,0 +1,19 @@
1
+ const paths = new Map([
2
+ ["sign-in", "signIn"],
3
+ ["verify", "verification"],
4
+ ["reset", "passwordReset"],
5
+ ["invite", "invitation"],
6
+ ]);
7
+ export function landed(url) {
8
+ const [address = "", ...hashes] = url.split("#");
9
+ const [path = "", ...queries] = address.split("?");
10
+ const parameters = queries.join("?").split("&").filter((parameter) => parameter !== "");
11
+ const token = parameters.find((parameter) => parameter.startsWith("token="));
12
+ const link = paths.get(path.slice(path.lastIndexOf("/") + 1));
13
+ if (token === undefined || link === undefined)
14
+ return null;
15
+ const kept = parameters.filter((parameter) => !parameter.startsWith("token="));
16
+ const query = kept.length > 0 ? `?${kept.join("&")}` : "";
17
+ const hash = hashes.length > 0 ? `#${hashes.join("#")}` : "";
18
+ return { link, emailed: token.slice("token=".length), url: `${path}${query}${hash}` };
19
+ }
@@ -0,0 +1,70 @@
1
+ import type { Storage } from "./storage.js";
2
+ export interface Socket {
3
+ binaryType: string;
4
+ onopen: (() => void) | null;
5
+ onmessage: ((event: {
6
+ readonly data: unknown;
7
+ }) => void) | null;
8
+ onclose: (() => void) | null;
9
+ onerror: (() => void) | null;
10
+ send(data: Uint8Array): void;
11
+ close(): void;
12
+ }
13
+ export interface Authenticator {
14
+ create(options: unknown): Promise<unknown>;
15
+ get(options: unknown): Promise<unknown>;
16
+ }
17
+ export interface BlobLike {
18
+ readonly size: number;
19
+ readonly type: string;
20
+ arrayBuffer(): Promise<ArrayBuffer>;
21
+ text(): Promise<string>;
22
+ slice(start: number, end: number): BlobLike;
23
+ }
24
+ export interface FormLike {
25
+ append(name: string, value: string | BlobLike): void;
26
+ }
27
+ interface Answer {
28
+ readonly ok: boolean;
29
+ readonly status: number;
30
+ blob(): Promise<BlobLike>;
31
+ json(): Promise<unknown>;
32
+ }
33
+ type Sent = {
34
+ readonly method: string;
35
+ readonly headers?: Record<string, string>;
36
+ readonly body?: BlobLike | FormLike | string;
37
+ };
38
+ interface Platform {
39
+ readonly WebSocket: new (url: string) => Socket;
40
+ fetch(url: string, init?: Sent): Promise<Answer>;
41
+ readonly FormData: new () => FormLike;
42
+ readonly localStorage?: Storage;
43
+ readonly location?: {
44
+ readonly href: string;
45
+ readonly hostname: string;
46
+ };
47
+ readonly navigator?: {
48
+ readonly credentials?: {
49
+ create(options: {
50
+ readonly publicKey: unknown;
51
+ }): Promise<unknown>;
52
+ get(options: {
53
+ readonly publicKey: unknown;
54
+ }): Promise<unknown>;
55
+ };
56
+ };
57
+ readonly PublicKeyCredential?: {
58
+ parseCreationOptionsFromJSON(options: unknown): unknown;
59
+ parseRequestOptionsFromJSON(options: unknown): unknown;
60
+ };
61
+ readonly history?: {
62
+ readonly state: unknown;
63
+ replaceState(state: unknown, unused: string, url: string): void;
64
+ };
65
+ setTimeout(run: () => void, milliseconds: number): unknown;
66
+ clearTimeout(timer: unknown): void;
67
+ }
68
+ export declare const platform: Platform;
69
+ export declare function browserAuthenticator(): Authenticator | undefined;
70
+ export {};
@@ -0,0 +1,11 @@
1
+ export const platform = globalThis;
2
+ export function browserAuthenticator() {
3
+ const { navigator, PublicKeyCredential: parsing } = platform;
4
+ const credentials = navigator?.credentials;
5
+ if (credentials === undefined || parsing === undefined)
6
+ return undefined;
7
+ return {
8
+ create: (options) => credentials.create({ publicKey: parsing.parseCreationOptionsFromJSON(options) }),
9
+ get: (options) => credentials.get({ publicKey: parsing.parseRequestOptionsFromJSON(options) }),
10
+ };
11
+ }