@indietabletop/appkit 3.2.0-0 → 3.2.0-10
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/lib/ExternalLink.tsx +10 -0
- package/lib/FormSubmitButton.tsx +58 -0
- package/lib/FullscreenDismissBlocker.tsx +23 -0
- package/lib/IndieTabletopClubLogo.tsx +44 -0
- package/lib/IndieTabletopClubSymbol.tsx +37 -0
- package/lib/Letterhead/index.tsx +85 -0
- package/lib/Letterhead/stories.tsx +45 -0
- package/lib/Letterhead/style.css.ts +141 -0
- package/lib/LetterheadForm/LetterheadReadonlyTextField.stories.tsx +21 -0
- package/lib/LetterheadForm/LetterheadSubmitError.stories.tsx +23 -0
- package/lib/LetterheadForm/LetterheadTextField.stories.tsx +23 -0
- package/lib/LetterheadForm/index.tsx +94 -0
- package/lib/LetterheadForm/style.css.ts +80 -0
- package/lib/LoadingIndicator.tsx +39 -0
- package/lib/ServiceWorkerHandler.tsx +53 -0
- package/lib/animations.css.ts +17 -0
- package/lib/append-copy-to-text.test.ts +29 -0
- package/lib/append-copy-to-text.ts +35 -0
- package/lib/async-op.ts +246 -0
- package/lib/atomic.css.ts +11 -0
- package/{dist/caught-value.js → lib/caught-value.ts} +10 -8
- package/lib/class-names.ts +33 -0
- package/lib/client.ts +288 -0
- package/lib/common.css.ts +48 -0
- package/lib/failureMessages.test.ts +138 -0
- package/lib/failureMessages.ts +76 -0
- package/lib/globals.css.ts +45 -0
- package/{dist/index.d.ts → lib/index.ts} +9 -1
- package/lib/internal.css.ts +10 -0
- package/lib/media.ts +50 -0
- package/lib/storybook/decorators.tsx +10 -0
- package/lib/structs.ts +17 -0
- package/{dist/types.d.ts → lib/types.ts} +11 -6
- package/lib/use-async-op.ts +16 -0
- package/lib/use-document-background-color.ts +16 -0
- package/lib/use-form.ts +73 -0
- package/{dist/use-is-installed.js → lib/use-is-installed.ts} +7 -3
- package/lib/use-media-query.ts +21 -0
- package/lib/use-reverting-state.ts +32 -0
- package/lib/use-scroll-restoration.ts +99 -0
- package/lib/validations.ts +25 -0
- package/lib/vars.css.ts +9 -0
- package/package.json +15 -7
- package/dist/ExternalLink.d.ts +0 -3
- package/dist/ExternalLink.js +0 -4
- package/dist/FormSubmitButton.d.ts +0 -7
- package/dist/FormSubmitButton.js +0 -16
- package/dist/FullscreenDismissBlocker.d.ts +0 -5
- package/dist/FullscreenDismissBlocker.js +0 -19
- package/dist/IndieTabletopClubFooter.d.ts +0 -1
- package/dist/IndieTabletopClubFooter.js +0 -17
- package/dist/IndieTabletopClubLogo.d.ts +0 -7
- package/dist/IndieTabletopClubLogo.js +0 -6
- package/dist/IndieTabletopClubSymbol.d.ts +0 -7
- package/dist/IndieTabletopClubSymbol.js +0 -5
- package/dist/Letterhead.d.ts +0 -6
- package/dist/Letterhead.js +0 -14
- package/dist/LetterheadFooter.d.ts +0 -1
- package/dist/LetterheadFooter.js +0 -17
- package/dist/LoadingIndicator.d.ts +0 -3
- package/dist/LoadingIndicator.js +0 -17
- package/dist/ServiceWorkerHandler.d.ts +0 -11
- package/dist/ServiceWorkerHandler.js +0 -42
- package/dist/animations.css.d.ts +0 -3
- package/dist/animations.css.js +0 -14
- package/dist/append-copy-to-text.d.ts +0 -10
- package/dist/append-copy-to-text.js +0 -29
- package/dist/async-op.d.ts +0 -87
- package/dist/async-op.js +0 -223
- package/dist/caught-value.d.ts +0 -15
- package/dist/class-names.d.ts +0 -4
- package/dist/class-names.js +0 -6
- package/dist/client.d.ts +0 -117
- package/dist/client.js +0 -201
- package/dist/common.css.d.ts +0 -5
- package/dist/common.css.js +0 -38
- package/dist/defineNetlifyConfig.d.ts +0 -34
- package/dist/defineNetlifyConfig.js +0 -35
- package/dist/external-link.d.ts +0 -4
- package/dist/external-link.js +0 -4
- package/dist/form-submit-button.d.ts +0 -7
- package/dist/form-submit-button.js +0 -16
- package/dist/fullscreen-dismiss-blocker.d.ts +0 -5
- package/dist/fullscreen-dismiss-blocker.js +0 -19
- package/dist/globals.css.d.ts +0 -1
- package/dist/globals.css.js +0 -35
- package/dist/index.js +0 -25
- package/dist/internal.css.d.ts +0 -4
- package/dist/internal.css.js +0 -21
- package/dist/media.d.ts +0 -39
- package/dist/media.js +0 -49
- package/dist/service-worker-handler.d.ts +0 -11
- package/dist/service-worker-handler.js +0 -42
- package/dist/structs.d.ts +0 -20
- package/dist/structs.js +0 -15
- package/dist/types.js +0 -1
- package/dist/use-async-op.d.ts +0 -6
- package/dist/use-async-op.js +0 -12
- package/dist/use-document-background-color.d.ts +0 -4
- package/dist/use-document-background-color.js +0 -14
- package/dist/use-form.d.ts +0 -29
- package/dist/use-form.js +0 -33
- package/dist/use-is-installed.d.ts +0 -8
- package/dist/use-media-query.d.ts +0 -1
- package/dist/use-media-query.js +0 -15
- package/dist/use-reverting-state.d.ts +0 -5
- package/dist/use-reverting-state.js +0 -26
- package/dist/use-scroll-restoration.d.ts +0 -25
- package/dist/use-scroll-restoration.js +0 -67
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
/**
|
|
4
|
-
* This component handles the installation of a service worker.
|
|
5
|
-
*
|
|
6
|
-
* Currently it doesn't do much, but, eventually, it should provide context
|
|
7
|
-
* to nested components communicating the status of the service worker installation.
|
|
8
|
-
*/
|
|
9
|
-
export function ServiceWorkerHandler(props) {
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
async function registerWorker() {
|
|
12
|
-
// Although modern browsers all support service workers, native app's
|
|
13
|
-
// web views (eg. the Facebook app's embedded browsers) do not.
|
|
14
|
-
if ("serviceWorker" in navigator) {
|
|
15
|
-
try {
|
|
16
|
-
const registration = await navigator.serviceWorker.register(props.path);
|
|
17
|
-
console.info("Service worker registration obtained.");
|
|
18
|
-
registration.addEventListener("updatefound", () => {
|
|
19
|
-
const worker = registration.installing;
|
|
20
|
-
console.info("Installing new service worker.");
|
|
21
|
-
worker?.addEventListener("statechange", ({ target }) => {
|
|
22
|
-
if (target instanceof ServiceWorker) {
|
|
23
|
-
console.info(`Service worker state changed: '${target.state}'.`);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
// In rare cases, service worker installation can fail, e.g. due to network
|
|
30
|
-
// connectivity. There is no need to report the error as there is nothing
|
|
31
|
-
// that can be done to prevent this from occassionally happening.
|
|
32
|
-
console.error(error);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
void registerWorker();
|
|
37
|
-
// Note that it is not necessary to 'cleanup' the registration in
|
|
38
|
-
// the useEffect hook. Calling register() multiple times is a no-op.
|
|
39
|
-
// See https://web.dev/articles/service-workers-registration#subsequent_visits
|
|
40
|
-
}, [props.path]);
|
|
41
|
-
return _jsx(_Fragment, { children: props.children });
|
|
42
|
-
}
|
package/dist/animations.css.d.ts
DELETED
package/dist/animations.css.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { keyframes } from "@vanilla-extract/css";
|
|
2
|
-
export const fadeIn = keyframes({
|
|
3
|
-
from: { opacity: 0 },
|
|
4
|
-
to: { opacity: 1 },
|
|
5
|
-
});
|
|
6
|
-
export const slideUp = keyframes({
|
|
7
|
-
from: { transform: `translateY(100%)` },
|
|
8
|
-
to: { transform: `translateY(0)` },
|
|
9
|
-
});
|
|
10
|
-
export const bounce = keyframes({
|
|
11
|
-
"0%": { transform: "translateY(0)" },
|
|
12
|
-
"20%": { transform: "translateY(-20%)" },
|
|
13
|
-
"50%": { transform: "translateY(0)" },
|
|
14
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Appends " (Copy)" to the end of the input string if it doesn't already end
|
|
3
|
-
* with " (Copy)", otherwise it appends a number after "Copy", incrementing it
|
|
4
|
-
* if necessary.
|
|
5
|
-
*/
|
|
6
|
-
export declare function appendCopyToText(input: string): string;
|
|
7
|
-
/**
|
|
8
|
-
* Works like {@link appendCopyToText}, but ignores empty strings.
|
|
9
|
-
*/
|
|
10
|
-
export declare function maybeAppendCopyToText(input: string): string;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Appends " (Copy)" to the end of the input string if it doesn't already end
|
|
3
|
-
* with " (Copy)", otherwise it appends a number after "Copy", incrementing it
|
|
4
|
-
* if necessary.
|
|
5
|
-
*/
|
|
6
|
-
export function appendCopyToText(input) {
|
|
7
|
-
const regex = /^(?<value>.*) \(Copy(?: (?<count>\d+))?\)$/;
|
|
8
|
-
const match = input.match(regex);
|
|
9
|
-
// If there isn't a match, we directly append to the input.
|
|
10
|
-
if (!match) {
|
|
11
|
-
return `${input.trim()} (Copy)`;
|
|
12
|
-
}
|
|
13
|
-
const { value, count } = match.groups ?? {};
|
|
14
|
-
// If `count` capturing group is not present, it means that the input ends
|
|
15
|
-
// with the copy suffix, but it doesn't contain count.
|
|
16
|
-
const nextCount = !count ? 2 : parseInt(count, 10) + 1;
|
|
17
|
-
return `${value.trim()} (Copy ${nextCount})`;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Works like {@link appendCopyToText}, but ignores empty strings.
|
|
21
|
-
*/
|
|
22
|
-
export function maybeAppendCopyToText(input) {
|
|
23
|
-
// If input is falsy (i.e. empty string) then we don't want to append
|
|
24
|
-
// anything to it.
|
|
25
|
-
if (!input) {
|
|
26
|
-
return "";
|
|
27
|
-
}
|
|
28
|
-
return appendCopyToText(input);
|
|
29
|
-
}
|
package/dist/async-op.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
type Falsy = null | undefined | false | 0 | 0n | "";
|
|
2
|
-
type Truthy<T> = Exclude<T, Falsy>;
|
|
3
|
-
interface Operation<SuccessValue, FailureValue> {
|
|
4
|
-
readonly type: "SUCCESS" | "FAILURE" | "PENDING";
|
|
5
|
-
readonly isPending: boolean;
|
|
6
|
-
readonly isSuccess: boolean;
|
|
7
|
-
readonly isFailure: boolean;
|
|
8
|
-
val: SuccessValue | FailureValue | null;
|
|
9
|
-
valueOrNull(): SuccessValue | null;
|
|
10
|
-
valueOrThrow(): SuccessValue;
|
|
11
|
-
hasTruthyValue(): boolean;
|
|
12
|
-
failureValueOrNull(): FailureValue | null;
|
|
13
|
-
failureValueOrThrow(): FailureValue;
|
|
14
|
-
flatMap<T extends AsyncOp<unknown, unknown>>(mappingFn: (value: SuccessValue) => T): T | Failure<FailureValue> | Pending;
|
|
15
|
-
mapSuccess<MappedSuccess>(mappingFn: (value: SuccessValue) => MappedSuccess): Operation<MappedSuccess, FailureValue>;
|
|
16
|
-
mapFailure<MappedFailure>(mappingFn: (value: FailureValue) => MappedFailure): Operation<SuccessValue, MappedFailure>;
|
|
17
|
-
unpack<S, F, P>(mapS: (value: SuccessValue) => S, mapF: (failure: FailureValue) => F, mapP: () => P): S | F | P;
|
|
18
|
-
}
|
|
19
|
-
export declare class Pending implements Operation<never, never> {
|
|
20
|
-
readonly type: "PENDING";
|
|
21
|
-
readonly isPending: true;
|
|
22
|
-
readonly isSuccess: false;
|
|
23
|
-
readonly isFailure: false;
|
|
24
|
-
val: null;
|
|
25
|
-
valueOrNull(): null;
|
|
26
|
-
valueOrThrow(): never;
|
|
27
|
-
hasTruthyValue(): false;
|
|
28
|
-
failureValueOrNull(): null;
|
|
29
|
-
failureValueOrThrow(): never;
|
|
30
|
-
flatMap(): Pending;
|
|
31
|
-
mapSuccess(): Pending;
|
|
32
|
-
mapFailure(): Pending;
|
|
33
|
-
unpack<S, F, P>(_mapS: (value: never) => S, _mapF: (failure: never) => F, mapP: () => P): S | F | P;
|
|
34
|
-
}
|
|
35
|
-
export declare class Success<SuccessValue> implements Operation<SuccessValue, never> {
|
|
36
|
-
readonly type: "SUCCESS";
|
|
37
|
-
readonly isPending: false;
|
|
38
|
-
readonly isSuccess: true;
|
|
39
|
-
readonly isFailure: false;
|
|
40
|
-
readonly value: SuccessValue;
|
|
41
|
-
readonly val: SuccessValue;
|
|
42
|
-
constructor(value: SuccessValue);
|
|
43
|
-
valueOrNull(): SuccessValue;
|
|
44
|
-
valueOrThrow(): SuccessValue;
|
|
45
|
-
hasTruthyValue(): this is Success<Truthy<SuccessValue>>;
|
|
46
|
-
failureValueOrNull(): null;
|
|
47
|
-
failureValueOrThrow(): never;
|
|
48
|
-
flatMap<T extends AsyncOp<unknown, unknown>>(mappingFn: (value: SuccessValue) => T): T;
|
|
49
|
-
mapSuccess<MappedValue>(mappingFn: (value: SuccessValue) => MappedValue): Success<MappedValue>;
|
|
50
|
-
mapFailure(): Success<SuccessValue>;
|
|
51
|
-
unpack<S, F, P>(mapS: (value: SuccessValue) => S, _mapF: (failure: never) => F, _mapP: () => P): S | F | P;
|
|
52
|
-
}
|
|
53
|
-
export declare class Failure<FailureValue> implements Operation<never, FailureValue> {
|
|
54
|
-
readonly type: "FAILURE";
|
|
55
|
-
readonly isPending: false;
|
|
56
|
-
readonly isSuccess: false;
|
|
57
|
-
readonly isFailure: true;
|
|
58
|
-
readonly failure: FailureValue;
|
|
59
|
-
readonly val: FailureValue;
|
|
60
|
-
constructor(failure: FailureValue);
|
|
61
|
-
valueOrNull(): null;
|
|
62
|
-
valueOrThrow(): never;
|
|
63
|
-
hasTruthyValue(): false;
|
|
64
|
-
failureValueOrNull(): FailureValue;
|
|
65
|
-
failureValueOrThrow(): FailureValue;
|
|
66
|
-
flatMap(): Failure<FailureValue>;
|
|
67
|
-
mapSuccess(): Failure<FailureValue>;
|
|
68
|
-
mapFailure<MappedFailure>(mappingFn: (value: FailureValue) => MappedFailure): Failure<MappedFailure>;
|
|
69
|
-
unpack<S, F, P>(_mapS: (value: never) => S, mapF: (failure: FailureValue) => F, _mapP: () => P): S | F | P;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Folds multiple ops into a single op.
|
|
73
|
-
*
|
|
74
|
-
* To return a Success, all ops provided must be a Success. If any Failures are
|
|
75
|
-
* encountered, will return the first one found.
|
|
76
|
-
*
|
|
77
|
-
* If neither of these conditions is true, will return Pending.
|
|
78
|
-
*
|
|
79
|
-
* Note that if passed an empty array, will always return a Success (with an
|
|
80
|
-
* empty array as value). This mimics the semantics of many JS constructs, like
|
|
81
|
-
* Promise.all or Array.prototype.every.
|
|
82
|
-
*/
|
|
83
|
-
export declare function fold<Ops extends readonly AsyncOp<unknown, unknown>[] | []>(ops: Ops): AsyncOp<{
|
|
84
|
-
-readonly [Index in keyof Ops]: Ops[Index] extends AsyncOp<infer S, unknown> ? S : never;
|
|
85
|
-
}, Ops[number] extends AsyncOp<unknown, infer F> ? F : never>;
|
|
86
|
-
export type AsyncOp<SuccessValue, FailureValue> = Pending | Success<SuccessValue> | Failure<FailureValue>;
|
|
87
|
-
export {};
|
package/dist/async-op.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
export class Pending {
|
|
2
|
-
constructor() {
|
|
3
|
-
Object.defineProperty(this, "type", {
|
|
4
|
-
enumerable: true,
|
|
5
|
-
configurable: true,
|
|
6
|
-
writable: true,
|
|
7
|
-
value: "PENDING"
|
|
8
|
-
});
|
|
9
|
-
Object.defineProperty(this, "isPending", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: true
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(this, "isSuccess", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: false
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, "isFailure", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: false
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "val", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: null
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
valueOrNull() {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
valueOrThrow() {
|
|
38
|
-
throw new Error(`AsyncOp value was accessed but the op is in Pending state.`);
|
|
39
|
-
}
|
|
40
|
-
hasTruthyValue() {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
failureValueOrNull() {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
failureValueOrThrow() {
|
|
47
|
-
throw new Error(`AsyncOp failure value was accessed but the op is in Pending state.`);
|
|
48
|
-
}
|
|
49
|
-
flatMap() {
|
|
50
|
-
return new Pending();
|
|
51
|
-
}
|
|
52
|
-
mapSuccess() {
|
|
53
|
-
return new Pending();
|
|
54
|
-
}
|
|
55
|
-
mapFailure() {
|
|
56
|
-
return new Pending();
|
|
57
|
-
}
|
|
58
|
-
unpack(_mapS, _mapF, mapP) {
|
|
59
|
-
return mapP();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export class Success {
|
|
63
|
-
constructor(value) {
|
|
64
|
-
Object.defineProperty(this, "type", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
configurable: true,
|
|
67
|
-
writable: true,
|
|
68
|
-
value: "SUCCESS"
|
|
69
|
-
});
|
|
70
|
-
Object.defineProperty(this, "isPending", {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true,
|
|
73
|
-
writable: true,
|
|
74
|
-
value: false
|
|
75
|
-
});
|
|
76
|
-
Object.defineProperty(this, "isSuccess", {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
configurable: true,
|
|
79
|
-
writable: true,
|
|
80
|
-
value: true
|
|
81
|
-
});
|
|
82
|
-
Object.defineProperty(this, "isFailure", {
|
|
83
|
-
enumerable: true,
|
|
84
|
-
configurable: true,
|
|
85
|
-
writable: true,
|
|
86
|
-
value: false
|
|
87
|
-
});
|
|
88
|
-
Object.defineProperty(this, "value", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
configurable: true,
|
|
91
|
-
writable: true,
|
|
92
|
-
value: void 0
|
|
93
|
-
});
|
|
94
|
-
Object.defineProperty(this, "val", {
|
|
95
|
-
enumerable: true,
|
|
96
|
-
configurable: true,
|
|
97
|
-
writable: true,
|
|
98
|
-
value: void 0
|
|
99
|
-
});
|
|
100
|
-
this.value = value;
|
|
101
|
-
this.val = value;
|
|
102
|
-
}
|
|
103
|
-
valueOrNull() {
|
|
104
|
-
return this.value;
|
|
105
|
-
}
|
|
106
|
-
valueOrThrow() {
|
|
107
|
-
return this.value;
|
|
108
|
-
}
|
|
109
|
-
hasTruthyValue() {
|
|
110
|
-
return !!this.value;
|
|
111
|
-
}
|
|
112
|
-
failureValueOrNull() {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
failureValueOrThrow() {
|
|
116
|
-
throw new Error(`AsyncOp failure value was accessed but the op is in Success state.`);
|
|
117
|
-
}
|
|
118
|
-
flatMap(mappingFn) {
|
|
119
|
-
return mappingFn(this.value);
|
|
120
|
-
}
|
|
121
|
-
mapSuccess(mappingFn) {
|
|
122
|
-
return new Success(mappingFn(this.value));
|
|
123
|
-
}
|
|
124
|
-
mapFailure() {
|
|
125
|
-
return new Success(this.value);
|
|
126
|
-
}
|
|
127
|
-
unpack(mapS, _mapF, _mapP) {
|
|
128
|
-
return mapS(this.value);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
export class Failure {
|
|
132
|
-
constructor(failure) {
|
|
133
|
-
Object.defineProperty(this, "type", {
|
|
134
|
-
enumerable: true,
|
|
135
|
-
configurable: true,
|
|
136
|
-
writable: true,
|
|
137
|
-
value: "FAILURE"
|
|
138
|
-
});
|
|
139
|
-
Object.defineProperty(this, "isPending", {
|
|
140
|
-
enumerable: true,
|
|
141
|
-
configurable: true,
|
|
142
|
-
writable: true,
|
|
143
|
-
value: false
|
|
144
|
-
});
|
|
145
|
-
Object.defineProperty(this, "isSuccess", {
|
|
146
|
-
enumerable: true,
|
|
147
|
-
configurable: true,
|
|
148
|
-
writable: true,
|
|
149
|
-
value: false
|
|
150
|
-
});
|
|
151
|
-
Object.defineProperty(this, "isFailure", {
|
|
152
|
-
enumerable: true,
|
|
153
|
-
configurable: true,
|
|
154
|
-
writable: true,
|
|
155
|
-
value: true
|
|
156
|
-
});
|
|
157
|
-
Object.defineProperty(this, "failure", {
|
|
158
|
-
enumerable: true,
|
|
159
|
-
configurable: true,
|
|
160
|
-
writable: true,
|
|
161
|
-
value: void 0
|
|
162
|
-
});
|
|
163
|
-
Object.defineProperty(this, "val", {
|
|
164
|
-
enumerable: true,
|
|
165
|
-
configurable: true,
|
|
166
|
-
writable: true,
|
|
167
|
-
value: void 0
|
|
168
|
-
});
|
|
169
|
-
this.failure = failure;
|
|
170
|
-
this.val = failure;
|
|
171
|
-
}
|
|
172
|
-
valueOrNull() {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
valueOrThrow() {
|
|
176
|
-
throw new Error(`AsyncOp value was accessed but the op is in Failure state.`);
|
|
177
|
-
}
|
|
178
|
-
hasTruthyValue() {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
failureValueOrNull() {
|
|
182
|
-
return this.failure;
|
|
183
|
-
}
|
|
184
|
-
failureValueOrThrow() {
|
|
185
|
-
return this.failure;
|
|
186
|
-
}
|
|
187
|
-
flatMap() {
|
|
188
|
-
return new Failure(this.failure);
|
|
189
|
-
}
|
|
190
|
-
mapSuccess() {
|
|
191
|
-
return new Failure(this.failure);
|
|
192
|
-
}
|
|
193
|
-
mapFailure(mappingFn) {
|
|
194
|
-
return new Failure(mappingFn(this.failure));
|
|
195
|
-
}
|
|
196
|
-
unpack(_mapS, mapF, _mapP) {
|
|
197
|
-
return mapF(this.failure);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Folds multiple ops into a single op.
|
|
202
|
-
*
|
|
203
|
-
* To return a Success, all ops provided must be a Success. If any Failures are
|
|
204
|
-
* encountered, will return the first one found.
|
|
205
|
-
*
|
|
206
|
-
* If neither of these conditions is true, will return Pending.
|
|
207
|
-
*
|
|
208
|
-
* Note that if passed an empty array, will always return a Success (with an
|
|
209
|
-
* empty array as value). This mimics the semantics of many JS constructs, like
|
|
210
|
-
* Promise.all or Array.prototype.every.
|
|
211
|
-
*/
|
|
212
|
-
export function fold(ops) {
|
|
213
|
-
// Note that due to the semantics of `every`, if the array provided to `fold`
|
|
214
|
-
// is empty, the result will be a Success with an empty array.
|
|
215
|
-
if (ops.every((v) => v.isSuccess)) {
|
|
216
|
-
return new Success(ops.map((op) => op.value));
|
|
217
|
-
}
|
|
218
|
-
const firstFail = ops.find((op) => op.isFailure);
|
|
219
|
-
if (firstFail) {
|
|
220
|
-
return firstFail;
|
|
221
|
-
}
|
|
222
|
-
return new Pending();
|
|
223
|
-
}
|
package/dist/caught-value.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Safely returns a string from an unknown value.
|
|
3
|
-
*
|
|
4
|
-
* This function is intended to be used when handling values caught
|
|
5
|
-
* in try/catch blocks.
|
|
6
|
-
*
|
|
7
|
-
* In JS/TS, unless errors are returned, they cannot be properly typed
|
|
8
|
-
* because any code within the try block can throw. Additionally, thrown
|
|
9
|
-
* values do not have to be Errors.
|
|
10
|
-
*
|
|
11
|
-
* This function makes sure to first assert if an Error was caught, and
|
|
12
|
-
* if so, returns its message. If a string was caught, it returns that.
|
|
13
|
-
* Otherwise, it returns "Unknown error".
|
|
14
|
-
*/
|
|
15
|
-
export declare function caughtValueToString(value: unknown): string;
|
package/dist/class-names.d.ts
DELETED
package/dist/class-names.js
DELETED
package/dist/client.d.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { Failure, Success } from "@indietabletop/appkit/async-op";
|
|
2
|
-
import { type Infer, Struct } from "superstruct";
|
|
3
|
-
import type { CurrentUser, FailurePayload, SessionInfo } from "./types.js";
|
|
4
|
-
export declare class IndieTabletopClient {
|
|
5
|
-
origin: string;
|
|
6
|
-
private onCurrentUser?;
|
|
7
|
-
private onSessionInfo?;
|
|
8
|
-
private onSessionExpired?;
|
|
9
|
-
private refreshTokenPromise?;
|
|
10
|
-
constructor(props: {
|
|
11
|
-
apiOrigin: string;
|
|
12
|
-
/**
|
|
13
|
-
* Runs every time the current user is fetched from the API. Typically, this
|
|
14
|
-
* happens during login, signup, and when the current user is fetched.
|
|
15
|
-
*/
|
|
16
|
-
onCurrentUser?: (currentUser: CurrentUser) => void;
|
|
17
|
-
/**
|
|
18
|
-
* Runs ever time new session info is fetched from the API. Typically, this
|
|
19
|
-
* happends during login, signup, and when tokens are refreshed.
|
|
20
|
-
*/
|
|
21
|
-
onSessionInfo?: (sessionInfo: SessionInfo) => void;
|
|
22
|
-
/**
|
|
23
|
-
* Runs when token refresh is attempted, but fails due to 401 error.
|
|
24
|
-
*/
|
|
25
|
-
onSessionExpired?: () => void;
|
|
26
|
-
});
|
|
27
|
-
protected fetch<T, S>(path: string, struct: Struct<T, S>, init?: RequestInit & {
|
|
28
|
-
json?: object;
|
|
29
|
-
}): Promise<Success<Infer<Struct<T, S>>> | Failure<FailurePayload>>;
|
|
30
|
-
/**
|
|
31
|
-
* Fetches data and retries 401 failures after attempting to refresh tokens.
|
|
32
|
-
*/
|
|
33
|
-
protected fetchWithAuth<T, S>(path: string, struct: Struct<T, S>, init?: RequestInit & {
|
|
34
|
-
json?: object;
|
|
35
|
-
}): Promise<Success<Infer<Struct<T, S>>> | Failure<FailurePayload>>;
|
|
36
|
-
login(payload: {
|
|
37
|
-
email: string;
|
|
38
|
-
password: string;
|
|
39
|
-
}): Promise<Failure<FailurePayload> | Success<{
|
|
40
|
-
sessionInfo: {
|
|
41
|
-
expiresTs: number;
|
|
42
|
-
createdTs: number;
|
|
43
|
-
};
|
|
44
|
-
currentUser: {
|
|
45
|
-
id: string;
|
|
46
|
-
email: string;
|
|
47
|
-
isVerified: boolean;
|
|
48
|
-
prefersScrollbarVisibility?: "ALWAYS" | undefined;
|
|
49
|
-
};
|
|
50
|
-
}>>;
|
|
51
|
-
logout(): Promise<Failure<FailurePayload> | Success<{
|
|
52
|
-
message: string;
|
|
53
|
-
}>>;
|
|
54
|
-
join(payload: {
|
|
55
|
-
email: string;
|
|
56
|
-
password: string;
|
|
57
|
-
acceptedTos: boolean;
|
|
58
|
-
subscribedToNewsletter: boolean;
|
|
59
|
-
}): Promise<Failure<FailurePayload> | Success<{
|
|
60
|
-
sessionInfo: {
|
|
61
|
-
expiresTs: number;
|
|
62
|
-
createdTs: number;
|
|
63
|
-
};
|
|
64
|
-
currentUser: {
|
|
65
|
-
id: string;
|
|
66
|
-
email: string;
|
|
67
|
-
isVerified: boolean;
|
|
68
|
-
prefersScrollbarVisibility?: "ALWAYS" | undefined;
|
|
69
|
-
};
|
|
70
|
-
tokenId: string;
|
|
71
|
-
}>>;
|
|
72
|
-
/**
|
|
73
|
-
* Triggers token refresh process.
|
|
74
|
-
*
|
|
75
|
-
* Note that we do not want to perform multiple concurrent token refresh
|
|
76
|
-
* actions, as that will result in unnecessary 401s. For this reason, a
|
|
77
|
-
* reference to t
|
|
78
|
-
*/
|
|
79
|
-
refreshTokens(): Promise<Success<{
|
|
80
|
-
sessionInfo: SessionInfo;
|
|
81
|
-
}> | Failure<FailurePayload>>;
|
|
82
|
-
requestPasswordReset(payload: {
|
|
83
|
-
email: string;
|
|
84
|
-
}): Promise<Failure<FailurePayload> | Success<{
|
|
85
|
-
message: string;
|
|
86
|
-
tokenId: string;
|
|
87
|
-
}>>;
|
|
88
|
-
checkPasswordResetCode(payload: {
|
|
89
|
-
tokenId: string;
|
|
90
|
-
code: string;
|
|
91
|
-
}): Promise<Failure<FailurePayload> | Success<{
|
|
92
|
-
message: string;
|
|
93
|
-
}>>;
|
|
94
|
-
setNewPassword(payload: {
|
|
95
|
-
tokenId: string;
|
|
96
|
-
code: string;
|
|
97
|
-
password: string;
|
|
98
|
-
}): Promise<Failure<FailurePayload> | Success<{
|
|
99
|
-
message: string;
|
|
100
|
-
}>>;
|
|
101
|
-
requestUserVerification(): Promise<Failure<FailurePayload> | Success<{
|
|
102
|
-
message: string;
|
|
103
|
-
tokenId: string;
|
|
104
|
-
}>>;
|
|
105
|
-
verifyUser(payload: {
|
|
106
|
-
tokenId: string;
|
|
107
|
-
code: string;
|
|
108
|
-
}): Promise<Failure<FailurePayload> | Success<{
|
|
109
|
-
message: string;
|
|
110
|
-
}>>;
|
|
111
|
-
getCurrentUser(): Promise<Failure<FailurePayload> | Success<{
|
|
112
|
-
id: string;
|
|
113
|
-
email: string;
|
|
114
|
-
isVerified: boolean;
|
|
115
|
-
prefersScrollbarVisibility?: "ALWAYS" | undefined;
|
|
116
|
-
}>>;
|
|
117
|
-
}
|