@indietabletop/appkit 3.2.0-2 → 3.2.0-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/lib/ExternalLink.tsx +10 -0
- package/lib/FormSubmitButton.tsx +48 -0
- package/lib/FullscreenDismissBlocker.tsx +23 -0
- package/lib/IndieTabletopClubLogo.tsx +44 -0
- package/lib/IndieTabletopClubSymbol.tsx +37 -0
- package/lib/Letterhead.tsx +33 -0
- package/lib/LetterheadFooter.tsx +36 -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.ts +35 -0
- package/lib/async-op.ts +246 -0
- package/{dist/caught-value.js → lib/caught-value.ts} +10 -8
- package/lib/class-names.ts +8 -0
- package/lib/client.ts +288 -0
- package/lib/common.css.ts +46 -0
- package/lib/globals.css.ts +42 -0
- package/{dist/index.d.ts → lib/index.ts} +5 -0
- package/lib/internal.css.ts +26 -0
- package/lib/media.ts +50 -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/package.json +3 -4
- 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/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/globals.css.d.ts +0 -1
- package/dist/globals.css.js +0 -35
- package/dist/index.js +0 -26
- 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/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
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 { type Infer, Struct } from "superstruct";
|
|
2
|
-
import { Failure, Success } from "./async-op.js";
|
|
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
|
-
}
|
package/dist/client.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { mask, object, string, Struct } from "superstruct";
|
|
2
|
-
import { Failure, Success } from "./async-op.js";
|
|
3
|
-
import { currentUser, sessionInfo } from "./structs.js";
|
|
4
|
-
export class IndieTabletopClient {
|
|
5
|
-
constructor(props) {
|
|
6
|
-
Object.defineProperty(this, "origin", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true,
|
|
10
|
-
value: void 0
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(this, "onCurrentUser", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: void 0
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(this, "onSessionInfo", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "onSessionExpired", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: void 0
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(this, "refreshTokenPromise", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
this.origin = props.apiOrigin;
|
|
37
|
-
this.onCurrentUser = props.onCurrentUser;
|
|
38
|
-
this.onSessionInfo = props.onSessionInfo;
|
|
39
|
-
this.onSessionExpired = props.onSessionExpired;
|
|
40
|
-
}
|
|
41
|
-
async fetch(path, struct, init) {
|
|
42
|
-
// If json was provided, we stringify it. Otherwise we use body.
|
|
43
|
-
const body = init?.json ? JSON.stringify(init.json) : init?.body;
|
|
44
|
-
// If json was provided, we make sure that content type is correctly set.
|
|
45
|
-
const headers = init?.json
|
|
46
|
-
? { ...init?.headers, "Content-Type": "application/json" }
|
|
47
|
-
: init?.headers;
|
|
48
|
-
try {
|
|
49
|
-
const res = await fetch(`${this.origin}${path}`, {
|
|
50
|
-
// Defaults
|
|
51
|
-
credentials: "include",
|
|
52
|
-
// Overrides
|
|
53
|
-
...init,
|
|
54
|
-
body,
|
|
55
|
-
headers,
|
|
56
|
-
});
|
|
57
|
-
if (!res.ok) {
|
|
58
|
-
console.error(res);
|
|
59
|
-
return new Failure({ type: "API_ERROR", code: res.status });
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
const data = mask(await res.json(), struct);
|
|
63
|
-
return new Success(data);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
console.error(error);
|
|
67
|
-
return new Failure({ type: "VALIDATION_ERROR" });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
console.error(error);
|
|
72
|
-
if (error instanceof Error) {
|
|
73
|
-
return new Failure({ type: "NETWORK_ERROR" });
|
|
74
|
-
}
|
|
75
|
-
return new Failure({ type: "UNKNOWN_ERROR" });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Fetches data and retries 401 failures after attempting to refresh tokens.
|
|
80
|
-
*/
|
|
81
|
-
async fetchWithAuth(path, struct, init) {
|
|
82
|
-
const op = await this.fetch(path, struct, init);
|
|
83
|
-
if (op.isSuccess) {
|
|
84
|
-
return op;
|
|
85
|
-
}
|
|
86
|
-
if (op.failure.type === "API_ERROR" && op.failure.code === 401) {
|
|
87
|
-
console.info("API request failed with error 401. Refreshing tokens.");
|
|
88
|
-
const refreshOp = await this.refreshTokens();
|
|
89
|
-
if (refreshOp.isSuccess) {
|
|
90
|
-
console.info("Tokens refreshed. Retrying request.");
|
|
91
|
-
return await this.fetch(path, struct, init);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
console.info("Could not refresh tokens.");
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return op;
|
|
98
|
-
}
|
|
99
|
-
async login(payload) {
|
|
100
|
-
const result = await this.fetch("/v1/sessions", object({
|
|
101
|
-
currentUser: currentUser(),
|
|
102
|
-
sessionInfo: sessionInfo(),
|
|
103
|
-
}), {
|
|
104
|
-
method: "POST",
|
|
105
|
-
json: { email: payload.email, plaintextPassword: payload.password },
|
|
106
|
-
});
|
|
107
|
-
if (result.isSuccess) {
|
|
108
|
-
this.onCurrentUser?.(result.value.currentUser);
|
|
109
|
-
this.onSessionInfo?.(result.value.sessionInfo);
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
async logout() {
|
|
114
|
-
return await this.fetch("/v1/sessions", object({ message: string() }), {
|
|
115
|
-
method: "DELETE",
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
async join(payload) {
|
|
119
|
-
const res = await this.fetch("/v1/users", object({
|
|
120
|
-
currentUser: currentUser(),
|
|
121
|
-
sessionInfo: sessionInfo(),
|
|
122
|
-
tokenId: string(),
|
|
123
|
-
}), {
|
|
124
|
-
method: "POST",
|
|
125
|
-
json: {
|
|
126
|
-
email: payload.email,
|
|
127
|
-
plaintextPassword: payload.password,
|
|
128
|
-
acceptedTos: payload.acceptedTos,
|
|
129
|
-
subscribedToNewsletter: payload.subscribedToNewsletter,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
if (res.isSuccess) {
|
|
133
|
-
this.onCurrentUser?.(res.value.currentUser);
|
|
134
|
-
this.onSessionInfo?.(res.value.sessionInfo);
|
|
135
|
-
}
|
|
136
|
-
return res;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Triggers token refresh process.
|
|
140
|
-
*
|
|
141
|
-
* Note that we do not want to perform multiple concurrent token refresh
|
|
142
|
-
* actions, as that will result in unnecessary 401s. For this reason, a
|
|
143
|
-
* reference to t
|
|
144
|
-
*/
|
|
145
|
-
async refreshTokens() {
|
|
146
|
-
// If there is an ongoing token refresh in progress return that. This should
|
|
147
|
-
// only deal the response payload, none of the side-effects and cleanup,
|
|
148
|
-
// which will be handled by the initial invocation.
|
|
149
|
-
const ongoingRequest = this.refreshTokenPromise;
|
|
150
|
-
if (ongoingRequest) {
|
|
151
|
-
console.info("Token refresh ongoing. Reusing existing promise.");
|
|
152
|
-
return await ongoingRequest;
|
|
153
|
-
}
|
|
154
|
-
// Cache the promise on an instance property to share a reference from
|
|
155
|
-
// other potential invocations.
|
|
156
|
-
this.refreshTokenPromise = this.fetch("/v1/sessions/access-tokens", object({ sessionInfo: sessionInfo() }), { method: "POST" });
|
|
157
|
-
const result = await this.refreshTokenPromise;
|
|
158
|
-
if (result.isSuccess) {
|
|
159
|
-
this.onSessionInfo?.(result.value.sessionInfo);
|
|
160
|
-
}
|
|
161
|
-
if (result.isFailure &&
|
|
162
|
-
result.failure.type === "API_ERROR" &&
|
|
163
|
-
result.failure.code === 401) {
|
|
164
|
-
this.onSessionExpired?.();
|
|
165
|
-
}
|
|
166
|
-
// Make sure to reset the shared reference so that subsequent invocations
|
|
167
|
-
// once again initiate token refresh.
|
|
168
|
-
delete this.refreshTokenPromise;
|
|
169
|
-
return result;
|
|
170
|
-
}
|
|
171
|
-
async requestPasswordReset(payload) {
|
|
172
|
-
return await this.fetch(`/v1/password-reset-tokens`, object({ message: string(), tokenId: string() }), { method: "POST", json: payload });
|
|
173
|
-
}
|
|
174
|
-
async checkPasswordResetCode(payload) {
|
|
175
|
-
const queryParams = new URLSearchParams({ plaintextCode: payload.code });
|
|
176
|
-
return await this.fetch(`/v1/password-reset-tokens/${payload.tokenId}?${queryParams}`, object({ message: string() }), { method: "GET" });
|
|
177
|
-
}
|
|
178
|
-
async setNewPassword(payload) {
|
|
179
|
-
const queryParams = new URLSearchParams({ plaintextCode: payload.code });
|
|
180
|
-
return await this.fetch(`/v1/password-reset-tokens/${payload.tokenId}?${queryParams}`, object({ message: string() }), { method: "PUT", json: { plaintextPassword: payload.password } });
|
|
181
|
-
}
|
|
182
|
-
async requestUserVerification() {
|
|
183
|
-
return await this.fetch(`/v1/user-verification-tokens`, object({ message: string(), tokenId: string() }), { method: "POST" });
|
|
184
|
-
}
|
|
185
|
-
async verifyUser(payload) {
|
|
186
|
-
const queryParams = new URLSearchParams({ plaintextCode: payload.code });
|
|
187
|
-
const req = await this.fetch(`/v1/user-verification-tokens/${payload.tokenId}?${queryParams}`, object({ message: string() }), { method: "PUT" });
|
|
188
|
-
if (req.isSuccess) {
|
|
189
|
-
await this.refreshTokens();
|
|
190
|
-
await this.getCurrentUser();
|
|
191
|
-
}
|
|
192
|
-
return req;
|
|
193
|
-
}
|
|
194
|
-
async getCurrentUser() {
|
|
195
|
-
const result = await this.fetchWithAuth(`/v1/users/me`, currentUser());
|
|
196
|
-
if (result.isSuccess) {
|
|
197
|
-
this.onCurrentUser?.(result.value);
|
|
198
|
-
}
|
|
199
|
-
return result;
|
|
200
|
-
}
|
|
201
|
-
}
|
package/dist/common.css.d.ts
DELETED
package/dist/common.css.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { style } from "@vanilla-extract/css";
|
|
2
|
-
import { Hover, MinWidth } from "./media.js";
|
|
3
|
-
export const itcSymbol = style({
|
|
4
|
-
inlineSize: "2.5rem",
|
|
5
|
-
blockSize: "2.5rem",
|
|
6
|
-
margin: "0rem auto 0.75rem",
|
|
7
|
-
"@media": {
|
|
8
|
-
[MinWidth.MEDIUM]: {
|
|
9
|
-
marginBlock: "-1rem 1.5rem",
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
export const manofa = style({
|
|
14
|
-
fontFamily: `"manofa", sans-serif`,
|
|
15
|
-
});
|
|
16
|
-
export const minion = style({
|
|
17
|
-
fontFamily: `"minion-pro", serif`,
|
|
18
|
-
});
|
|
19
|
-
export const itcCard = style([
|
|
20
|
-
minion,
|
|
21
|
-
{
|
|
22
|
-
backgroundColor: "white",
|
|
23
|
-
},
|
|
24
|
-
]);
|
|
25
|
-
export const interactiveText = style({
|
|
26
|
-
display: "inline",
|
|
27
|
-
textDecoration: "underline",
|
|
28
|
-
textDecorationColor: "hsl(from currentcolor h s l / 0.3)",
|
|
29
|
-
textUnderlineOffset: "0.15em",
|
|
30
|
-
"@media": {
|
|
31
|
-
[Hover.HOVER]: {
|
|
32
|
-
transition: "text-decoration-color 200ms",
|
|
33
|
-
":hover": {
|
|
34
|
-
textDecorationColor: "hsl(from currentcolor h s l / 1)",
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
});
|
package/dist/globals.css.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/globals.css.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { globalStyle } from "@vanilla-extract/css";
|
|
2
|
-
globalStyle(":root", {
|
|
3
|
-
fontSynthesis: "none",
|
|
4
|
-
textRendering: "optimizeLegibility",
|
|
5
|
-
WebkitFontSmoothing: "antialiased",
|
|
6
|
-
MozOsxFontSmoothing: "grayscale",
|
|
7
|
-
});
|
|
8
|
-
globalStyle("*", {
|
|
9
|
-
boxSizing: "border-box",
|
|
10
|
-
});
|
|
11
|
-
globalStyle("img, picture, svg", {
|
|
12
|
-
display: "block",
|
|
13
|
-
});
|
|
14
|
-
globalStyle("a", {
|
|
15
|
-
display: "block",
|
|
16
|
-
color: "inherit",
|
|
17
|
-
textDecoration: "none",
|
|
18
|
-
});
|
|
19
|
-
globalStyle("input, textarea", {
|
|
20
|
-
fontFamily: "inherit",
|
|
21
|
-
});
|
|
22
|
-
globalStyle("button", {
|
|
23
|
-
display: "block",
|
|
24
|
-
fontSize: "inherit",
|
|
25
|
-
fontFamily: "inherit",
|
|
26
|
-
backgroundColor: "transparent",
|
|
27
|
-
border: "none",
|
|
28
|
-
color: "inherit",
|
|
29
|
-
cursor: "pointer",
|
|
30
|
-
padding: 0,
|
|
31
|
-
});
|
|
32
|
-
globalStyle("body, h1, h2, h3, h4, h5, h6, p, ul, li, ol", {
|
|
33
|
-
margin: 0,
|
|
34
|
-
padding: 0,
|
|
35
|
-
});
|
package/dist/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// Components
|
|
2
|
-
export * from "./ExternalLink.js";
|
|
3
|
-
export * from "./FormSubmitButton.js";
|
|
4
|
-
export * from "./FullscreenDismissBlocker.js";
|
|
5
|
-
export * from "./IndieTabletopClubSymbol.js";
|
|
6
|
-
export * from "./Letterhead.js";
|
|
7
|
-
export * from "./LetterheadFooter.js";
|
|
8
|
-
export * from "./LoadingIndicator.js";
|
|
9
|
-
export * from "./ServiceWorkerHandler.js";
|
|
10
|
-
// Hooks
|
|
11
|
-
export * from "./use-async-op.js";
|
|
12
|
-
export * from "./use-document-background-color.js";
|
|
13
|
-
export * from "./use-form.js";
|
|
14
|
-
export * from "./use-is-installed.js";
|
|
15
|
-
export * from "./use-media-query.js";
|
|
16
|
-
export * from "./use-reverting-state.js";
|
|
17
|
-
export * from "./use-scroll-restoration.js";
|
|
18
|
-
// Utils
|
|
19
|
-
export * from "./append-copy-to-text.js";
|
|
20
|
-
export * from "./async-op.js";
|
|
21
|
-
export * from "./caught-value.js";
|
|
22
|
-
export * from "./class-names.js";
|
|
23
|
-
export * from "./client.js";
|
|
24
|
-
export * from "./media.js";
|
|
25
|
-
export * from "./structs.js";
|
|
26
|
-
export * from "./types.js";
|
package/dist/internal.css.d.ts
DELETED