@tensile-tools/auth-client 0.0.0-stage → 0.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 (44) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +62 -2
  3. package/dist/client.d.ts +569 -0
  4. package/dist/client.js +637 -0
  5. package/dist/devtools.d.ts +12 -0
  6. package/dist/devtools.js +44 -0
  7. package/dist/elements/account.d.ts +63 -0
  8. package/dist/elements/account.js +331 -0
  9. package/dist/elements/approvals.d.ts +61 -0
  10. package/dist/elements/approvals.js +252 -0
  11. package/dist/elements/auth.d.ts +48 -0
  12. package/dist/elements/auth.js +238 -0
  13. package/dist/elements/base.d.ts +176 -0
  14. package/dist/elements/base.js +540 -0
  15. package/dist/elements/config.d.ts +70 -0
  16. package/dist/elements/config.js +119 -0
  17. package/dist/elements/format.d.ts +32 -0
  18. package/dist/elements/format.js +67 -0
  19. package/dist/elements/index.d.ts +21 -0
  20. package/dist/elements/index.js +31 -0
  21. package/dist/elements/qr.d.ts +9 -0
  22. package/dist/elements/qr.js +302 -0
  23. package/dist/elements/returnto.d.ts +17 -0
  24. package/dist/elements/returnto.js +63 -0
  25. package/dist/elements/setup.d.ts +70 -0
  26. package/dist/elements/setup.js +316 -0
  27. package/dist/elements/styles.d.ts +3 -0
  28. package/dist/elements/styles.js +194 -0
  29. package/dist/elements/text.d.ts +21 -0
  30. package/dist/elements/text.js +302 -0
  31. package/dist/fonts/OFL-geist-mono.txt +93 -0
  32. package/dist/fonts/OFL-geist.txt +93 -0
  33. package/dist/fonts/OFL-inter.txt +93 -0
  34. package/dist/fonts/README.md +18 -0
  35. package/dist/fonts/geist-mono.woff2 +0 -0
  36. package/dist/fonts/geist.woff2 +0 -0
  37. package/dist/fonts/inter.woff2 +0 -0
  38. package/dist/index.d.ts +4 -0
  39. package/dist/index.js +5 -0
  40. package/dist/problem.d.ts +54 -0
  41. package/dist/problem.js +40 -0
  42. package/dist/webauthn.d.ts +46 -0
  43. package/dist/webauthn.js +102 -0
  44. package/package.json +51 -4
@@ -0,0 +1,176 @@
1
+ import { type AuthClient, type Outcome } from '../client.ts';
2
+ import { type Options } from './config.ts';
3
+ import { fill } from './text.ts';
4
+ /** HTML that is already safe to insert. */
5
+ export declare class Html {
6
+ readonly s: string;
7
+ constructor(s: string);
8
+ toString(): string;
9
+ }
10
+ /** Escapes text for HTML. */
11
+ export declare const esc: (s: string) => string;
12
+ /** A template tag that escapes every value that isn't Html. */
13
+ export declare function html(strings: TemplateStringsArray, ...vals: unknown[]): Html;
14
+ /** Values for a text template: text, which is escaped, or Html. */
15
+ export type Vars = Record<string, string | number | Html>;
16
+ /** Renders a text template: [join] grey, *ok* green, !warn! orange, and values. */
17
+ export declare function rich(template: string, vars: Vars): Html;
18
+ /** The options and client every element starts from. */
19
+ export interface GlobalConfig extends Partial<Options> {
20
+ /** The client every element uses, unless it has its own. Default: `createAuthClient()`. */
21
+ client?: AuthClient;
22
+ }
23
+ /**
24
+ * Sets options for every element on the page, and the client they share.
25
+ * An element's own `config`, properties, and attributes win over these.
26
+ * Calling it again merges, and every element renders again.
27
+ */
28
+ export declare function configure(c: GlobalConfig): void;
29
+ /** The element-specific attributes each element observes, besides the options. */
30
+ export type ElementAttrs = readonly string[];
31
+ /** The base class of the elements. */
32
+ export declare abstract class TensileElement extends HTMLElement {
33
+ /** Attributes this element reads besides the options. */
34
+ static attrs: ElementAttrs;
35
+ static get observedAttributes(): string[];
36
+ /** The state the element shows, such as `start` or `done`. */
37
+ protected state: string;
38
+ /** An error to show, or empty. */
39
+ protected error: string;
40
+ /** A message that isn't an error, such as "a link is on its way", or empty. */
41
+ protected notice: string;
42
+ /** What the person typed, by input name. */
43
+ protected values: Record<string, string>;
44
+ /** True while a request runs; actions wait. */
45
+ protected busy: boolean;
46
+ protected readonly root: ShadowRoot;
47
+ private readonly view;
48
+ private readonly liveRegion;
49
+ private readonly dyn;
50
+ private focusNext;
51
+ /** True after the session ended, until the next sign-in. */
52
+ private lost;
53
+ /** The load generation: every session change bumps it, so a load that started before drops its result. */
54
+ private gen;
55
+ private started;
56
+ /** Options set as properties. */
57
+ _props: Partial<Record<keyof Options, unknown>>;
58
+ private ownConfig;
59
+ private ownClient;
60
+ constructor();
61
+ /** Options for this element only, as one object. */
62
+ get config(): Partial<Options> | undefined;
63
+ set config(c: Partial<Options> | undefined);
64
+ /** The auth client this element uses. Default: the one `configure` set, or `createAuthClient()`. */
65
+ get client(): AuthClient;
66
+ set client(c: AuthClient);
67
+ /** The options in force: defaults, then configure(), then `config`, then properties, then attributes. */
68
+ get options(): Options;
69
+ connectedCallback(): void;
70
+ disconnectedCallback(): void;
71
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
72
+ /** Whether the element shows at all under o; a section turned off hides it. */
73
+ protected on(_o: Options): boolean;
74
+ /** Loads again, for example after the client changes. It does nothing while signed out. */
75
+ reload(): void;
76
+ /**
77
+ * Follows the session. When it ends, by sign-out, expiry, or a
78
+ * revocation in any tab, the element forgets what it loaded at once and
79
+ * shows the signed-out state. It never fetches then: a fetch would get
80
+ * 401 and report the lost session again. It loads once more only after
81
+ * the next sign-in, which clears the flag.
82
+ */
83
+ private sessionChanged;
84
+ /** True while this element would show the signed-out prompt, if it owned it. */
85
+ wantsPrompt(): boolean;
86
+ /** True while the session that the element showed has ended. */
87
+ protected get signedOut(): boolean;
88
+ /** The load generation now. A load reads it before it awaits, and passes it to `stale` after. */
89
+ protected get generation(): number;
90
+ /** Whether a load that started at generation g must drop its result: the session changed since, or ended. */
91
+ protected stale(g: number): boolean;
92
+ /** Drops every piece of the person's data that the element loaded. */
93
+ protected forget(): void;
94
+ /** The signed-out state: what ended, and a way to sign in. */
95
+ protected signedOutBody(o: Options): Html;
96
+ /**
97
+ * The ways to sign in from a signed-out state: a passkey, unless the
98
+ * app turned passkeys off, and a link to `sign-in-href` when it is set.
99
+ */
100
+ protected signInActions(o: Options, fine?: string): Html;
101
+ /** The state before the first load: the element's title, and a quiet line that says it is loading. */
102
+ protected loadingBody(o: Options, title: string): Html;
103
+ /** Signs in again with a passkey from the signed-out state. */
104
+ private signInAgain;
105
+ /** Loads what the element shows. */
106
+ protected load(): Promise<void>;
107
+ /** Runs action `name`, started by `from`. */
108
+ protected abstract act(name: string, from: HTMLElement): Promise<void>;
109
+ /** Renders the element's content under the frame. */
110
+ protected abstract body(o: Options): Html;
111
+ /** True for elements that turn into a page section when wide. */
112
+ protected wide: boolean;
113
+ /** True for elements that load the signed-in person's data again when the session changes, in any tab. */
114
+ protected followsSession: boolean;
115
+ private offSession;
116
+ private run;
117
+ /** Renders again with the options in force. */
118
+ update(): void;
119
+ /** Runs after each render, for measuring. */
120
+ protected rendered(): void;
121
+ /** Moves to state s, clears the error, renders, and moves focus to the new content. */
122
+ protected go(s: string): void;
123
+ /** Shows an error, announced by its role="alert". */
124
+ protected fail(msg: string): void;
125
+ /** Announces msg to screen readers without moving focus. */
126
+ protected announce(msg: string): void;
127
+ /**
128
+ * Dispatches a DOM event that bubbles out of the shadow root. It
129
+ * returns false when a listener called preventDefault on a cancelable
130
+ * event.
131
+ */
132
+ protected emit(name: string, detail?: unknown, cancelable?: boolean): boolean;
133
+ /** The template for key, from the `text` option or English. */
134
+ protected tpl(key: string): string;
135
+ /** The plain text for key, with {appName} and vars filled. */
136
+ protected t(key: string, vars?: Record<string, string | number>): string;
137
+ /** The rendered text for key. */
138
+ protected r(key: string, vars?: Vars): Html;
139
+ /** Renders a template that isn't a key, such as one chosen at run time. */
140
+ protected rt(template: string, vars?: Vars): Html;
141
+ protected app(): string;
142
+ /** What to show for an outcome that isn't ok. */
143
+ protected explain(r: Outcome<unknown>): string;
144
+ /** Shows a failed outcome and dispatches `problem`. */
145
+ protected failWith(r: Outcome<unknown>): void;
146
+ /** The frame: the app header, then the body. */
147
+ private frame;
148
+ /** The headline: the large sentence, or a quiet title with an optional lead. */
149
+ protected heading(o: Options, sentence: Html, title: string, lead?: Html | string): Html;
150
+ /** The error paragraph, or a notice that isn't an error, when there is one. */
151
+ protected err(): Html | string;
152
+ /** A finished state: a chip, a sentence, and an optional link. */
153
+ protected done(chip: string, tone: string, text: Html | string, back?: {
154
+ label: string;
155
+ action: string;
156
+ }): Html;
157
+ /** A labelled input. */
158
+ protected field(name: string, label: string, attrs: Html, opts?: {
159
+ hint?: string;
160
+ after?: Html;
161
+ invalid?: boolean;
162
+ }): Html;
163
+ }
164
+ /** A same-origin URL to go to, or undefined for anything else. */
165
+ export declare function sameOrigin(url: string | null): string | undefined;
166
+ /** Glyphs, drawn in currentColor. */
167
+ export declare const glyph: {
168
+ key: Html;
169
+ agent: Html;
170
+ laptop: Html;
171
+ phone: Html;
172
+ token: Html;
173
+ app: Html;
174
+ you: Html;
175
+ };
176
+ export { fill };