react-cheminfo 0.58.0 → 0.60.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/README.md +7 -2
- package/lib/about/ui/AboutBuildDetails.d.ts +15 -0
- package/lib/about/ui/AboutBuildDetails.d.ts.map +1 -0
- package/lib/about/ui/AboutBuildDetails.js +17 -0
- package/lib/about/ui/AboutBuildDetails.js.map +1 -0
- package/lib/about/ui/AboutPage.d.ts +8 -0
- package/lib/about/ui/AboutPage.d.ts.map +1 -1
- package/lib/about/ui/AboutPage.js +12 -3
- package/lib/about/ui/AboutPage.js.map +1 -1
- package/lib/about/ui/AboutSignIn.d.ts +33 -0
- package/lib/about/ui/AboutSignIn.d.ts.map +1 -0
- package/lib/about/ui/AboutSignIn.js +28 -0
- package/lib/about/ui/AboutSignIn.js.map +1 -0
- package/lib/about/ui/AboutVersion.d.ts +4 -2
- package/lib/about/ui/AboutVersion.d.ts.map +1 -1
- package/lib/about/ui/AboutVersion.js +21 -3
- package/lib/about/ui/AboutVersion.js.map +1 -1
- package/lib/about/ui/index.d.ts +2 -2
- package/lib/about/ui/index.d.ts.map +1 -1
- package/lib/about/ui/index.js +1 -1
- package/lib/about/ui/index.js.map +1 -1
- package/lib/chart/ui/ChartTrackingLayer.js +3 -1
- package/lib/chart/ui/ChartTrackingLayer.js.map +1 -1
- package/lib/chart/ui/useChartSize.d.ts +16 -0
- package/lib/chart/ui/useChartSize.d.ts.map +1 -1
- package/lib/chart/ui/useChartSize.js +34 -1
- package/lib/chart/ui/useChartSize.js.map +1 -1
- package/lib/chrome/ui/NavEntry.d.ts +16 -0
- package/lib/chrome/ui/NavEntry.d.ts.map +1 -0
- package/lib/chrome/ui/NavEntry.js +27 -0
- package/lib/chrome/ui/NavEntry.js.map +1 -0
- package/lib/chrome/ui/SiteHeader.d.ts +11 -4
- package/lib/chrome/ui/SiteHeader.d.ts.map +1 -1
- package/lib/chrome/ui/SiteHeader.js +4 -26
- package/lib/chrome/ui/SiteHeader.js.map +1 -1
- package/lib/core.d.ts +2 -0
- package/lib/core.d.ts.map +1 -1
- package/lib/core.js +2 -0
- package/lib/core.js.map +1 -1
- package/lib/ecosystem/core/types.d.ts +1 -1
- package/lib/ecosystem/core/types.d.ts.map +1 -1
- package/lib/ecosystem/core/unlistedSites.d.ts.map +1 -1
- package/lib/ecosystem/core/unlistedSites.js +14 -0
- package/lib/ecosystem/core/unlistedSites.js.map +1 -1
- package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
- package/lib/ecosystem/ui/glyphs.js +3 -0
- package/lib/ecosystem/ui/glyphs.js.map +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +36 -3
- package/lib/locales/en.json +36 -3
- package/lib/locales/es.json +36 -3
- package/lib/locales/fr.json +36 -3
- package/lib/locales/it.json +36 -3
- package/lib/moleculesSources/core/index.d.ts +3 -0
- package/lib/moleculesSources/core/index.d.ts.map +1 -0
- package/lib/moleculesSources/core/index.js +2 -0
- package/lib/moleculesSources/core/index.js.map +1 -0
- package/lib/moleculesSources/core/moleculesSources.d.ts +55 -0
- package/lib/moleculesSources/core/moleculesSources.d.ts.map +1 -0
- package/lib/moleculesSources/core/moleculesSources.js +63 -0
- package/lib/moleculesSources/core/moleculesSources.js.map +1 -0
- package/lib/moleculesSources/ui/MoleculesSourceBadge.d.ts +18 -0
- package/lib/moleculesSources/ui/MoleculesSourceBadge.d.ts.map +1 -0
- package/lib/moleculesSources/ui/MoleculesSourceBadge.js +22 -0
- package/lib/moleculesSources/ui/MoleculesSourceBadge.js.map +1 -0
- package/lib/moleculesSources/ui/SourceBadge.d.ts +57 -0
- package/lib/moleculesSources/ui/SourceBadge.d.ts.map +1 -0
- package/lib/moleculesSources/ui/SourceBadge.js +29 -0
- package/lib/moleculesSources/ui/SourceBadge.js.map +1 -0
- package/lib/moleculesSources/ui/index.d.ts +7 -0
- package/lib/moleculesSources/ui/index.d.ts.map +1 -0
- package/lib/moleculesSources/ui/index.js +4 -0
- package/lib/moleculesSources/ui/index.js.map +1 -0
- package/lib/moleculesSources/ui/useSourceLooks.d.ts +24 -0
- package/lib/moleculesSources/ui/useSourceLooks.d.ts.map +1 -0
- package/lib/moleculesSources/ui/useSourceLooks.js +53 -0
- package/lib/moleculesSources/ui/useSourceLooks.js.map +1 -0
- package/lib/moleculesToken/core/index.d.ts +4 -0
- package/lib/moleculesToken/core/index.d.ts.map +1 -0
- package/lib/moleculesToken/core/index.js +3 -0
- package/lib/moleculesToken/core/index.js.map +1 -0
- package/lib/moleculesToken/core/moleculesToken.d.ts +101 -0
- package/lib/moleculesToken/core/moleculesToken.d.ts.map +1 -0
- package/lib/moleculesToken/core/moleculesToken.js +137 -0
- package/lib/moleculesToken/core/moleculesToken.js.map +1 -0
- package/lib/moleculesToken/core/tokenFix.d.ts +18 -0
- package/lib/moleculesToken/core/tokenFix.d.ts.map +1 -0
- package/lib/moleculesToken/core/tokenFix.js +27 -0
- package/lib/moleculesToken/core/tokenFix.js.map +1 -0
- package/lib/moleculesToken/ui/MoleculesTokenFix.d.ts +22 -0
- package/lib/moleculesToken/ui/MoleculesTokenFix.d.ts.map +1 -0
- package/lib/moleculesToken/ui/MoleculesTokenFix.js +35 -0
- package/lib/moleculesToken/ui/MoleculesTokenFix.js.map +1 -0
- package/lib/moleculesToken/ui/MoleculesTokenTable.d.ts +37 -0
- package/lib/moleculesToken/ui/MoleculesTokenTable.d.ts.map +1 -0
- package/lib/moleculesToken/ui/MoleculesTokenTable.js +56 -0
- package/lib/moleculesToken/ui/MoleculesTokenTable.js.map +1 -0
- package/lib/moleculesToken/ui/index.d.ts +5 -0
- package/lib/moleculesToken/ui/index.d.ts.map +1 -0
- package/lib/moleculesToken/ui/index.js +3 -0
- package/lib/moleculesToken/ui/index.js.map +1 -0
- package/lib/moleculesToken/ui/tokenDetails.d.ts +13 -0
- package/lib/moleculesToken/ui/tokenDetails.d.ts.map +1 -0
- package/lib/moleculesToken/ui/tokenDetails.js +73 -0
- package/lib/moleculesToken/ui/tokenDetails.js.map +1 -0
- package/lib/ui.d.ts +2 -0
- package/lib/ui.d.ts.map +1 -1
- package/lib/ui.js +2 -0
- package/lib/ui.js.map +1 -1
- package/package.json +1 -1
- package/src/about/ui/AboutBuildDetails.tsx +45 -0
- package/src/about/ui/AboutPage.tsx +27 -13
- package/src/about/ui/AboutSignIn.tsx +63 -0
- package/src/about/ui/AboutVersion.tsx +27 -9
- package/src/about/ui/index.ts +2 -2
- package/src/chart/ui/ChartTrackingLayer.tsx +3 -1
- package/src/chart/ui/useChartSize.ts +44 -1
- package/src/chrome/ui/NavEntry.tsx +41 -0
- package/src/chrome/ui/SiteHeader.tsx +15 -41
- package/src/core.ts +2 -0
- package/src/ecosystem/core/types.ts +2 -1
- package/src/ecosystem/core/unlistedSites.ts +14 -0
- package/src/ecosystem/ui/glyphs.tsx +10 -0
- package/src/locales/de.json +36 -3
- package/src/locales/en.json +36 -3
- package/src/locales/es.json +36 -3
- package/src/locales/fr.json +36 -3
- package/src/locales/it.json +36 -3
- package/src/moleculesSources/core/index.ts +11 -0
- package/src/moleculesSources/core/moleculesSources.ts +102 -0
- package/src/moleculesSources/ui/MoleculesSourceBadge.tsx +44 -0
- package/src/moleculesSources/ui/SourceBadge.tsx +117 -0
- package/src/moleculesSources/ui/index.ts +6 -0
- package/src/moleculesSources/ui/useSourceLooks.ts +70 -0
- package/src/moleculesToken/core/index.ts +12 -0
- package/src/moleculesToken/core/moleculesToken.ts +256 -0
- package/src/moleculesToken/core/tokenFix.ts +37 -0
- package/src/moleculesToken/ui/MoleculesTokenFix.tsx +95 -0
- package/src/moleculesToken/ui/MoleculesTokenTable.tsx +175 -0
- package/src/moleculesToken/ui/index.ts +4 -0
- package/src/moleculesToken/ui/tokenDetails.tsx +91 -0
- package/src/ui.ts +2 -0
- package/styles/chrome.css +194 -0
- package/lib/about/ui/AboutBuild.d.ts +0 -18
- package/lib/about/ui/AboutBuild.d.ts.map +0 -1
- package/lib/about/ui/AboutBuild.js +0 -37
- package/lib/about/ui/AboutBuild.js.map +0 -1
- package/src/about/ui/AboutBuild.tsx +0 -54
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { trimTrailingSlash } from '../../router/core/address.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What molecules.cheminfo.org says of a token a site holds:
|
|
5
|
+
*
|
|
6
|
+
* - `ok`: issued for a source the site writes, and not revoked;
|
|
7
|
+
* - `otherSource`: valid, but issued for another source, so what the site
|
|
8
|
+
* sends is credited to that one;
|
|
9
|
+
* - `refused`: never issued, or revoked;
|
|
10
|
+
* - `unset`: the site holds none;
|
|
11
|
+
* - `uncheckable`: molecules.cheminfo.org answers, but cannot check a token
|
|
12
|
+
* yet;
|
|
13
|
+
* - `unanswered`: it did not answer, or failed.
|
|
14
|
+
*/
|
|
15
|
+
export type MoleculesTokenVerdict =
|
|
16
|
+
'ok' | 'otherSource' | 'refused' | 'unset' | 'uncheckable' | 'unanswered';
|
|
17
|
+
|
|
18
|
+
/** A token a site holds, to be checked. */
|
|
19
|
+
export interface MoleculesTokenToCheck {
|
|
20
|
+
/** The environment variable it is read from, e.g. `MOLECULES_TOKEN_LOTUS`. */
|
|
21
|
+
variable: string;
|
|
22
|
+
/** The token, or undefined when the variable is unset or blank. */
|
|
23
|
+
token: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The sources it may have been issued for, as molecules.cheminfo.org names
|
|
26
|
+
* them: any one of them is right, whatever its case.
|
|
27
|
+
* @default [] — any source
|
|
28
|
+
*/
|
|
29
|
+
sources?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A token, as molecules.cheminfo.org checked it. Never the token itself. */
|
|
33
|
+
export interface MoleculesTokenCheck {
|
|
34
|
+
/** The environment variable it is read from. */
|
|
35
|
+
variable: string;
|
|
36
|
+
/** The sources it may have been issued for; empty for any source. */
|
|
37
|
+
sources: string[];
|
|
38
|
+
/** What molecules.cheminfo.org says of it. */
|
|
39
|
+
verdict: MoleculesTokenVerdict;
|
|
40
|
+
/**
|
|
41
|
+
* What molecules.cheminfo.org said, or why it could not be asked; null when
|
|
42
|
+
* the verdict says it all.
|
|
43
|
+
*/
|
|
44
|
+
message: string | null;
|
|
45
|
+
/** The source molecules.cheminfo.org knows it for, once it answered. */
|
|
46
|
+
source: string | null;
|
|
47
|
+
/**
|
|
48
|
+
* Its first characters, as molecules.cheminfo.org shows them: what tells two
|
|
49
|
+
* tokens apart without showing either.
|
|
50
|
+
*/
|
|
51
|
+
hint: string | null;
|
|
52
|
+
/** Who it was issued to. */
|
|
53
|
+
email: string | null;
|
|
54
|
+
/** When it was issued, in epoch milliseconds. */
|
|
55
|
+
issuedAt: number | null;
|
|
56
|
+
/** When it last read or wrote, in epoch milliseconds, to within a minute. */
|
|
57
|
+
lastUsedAt: number | null;
|
|
58
|
+
/** When it was checked, in epoch milliseconds. */
|
|
59
|
+
checkedAt: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Where molecules.cheminfo.org answers, and how patiently it is asked. */
|
|
63
|
+
export interface CheckMoleculesTokenOptions {
|
|
64
|
+
/** Where it answers, e.g. `https://molecules.cheminfo.org`. */
|
|
65
|
+
baseUrl: string;
|
|
66
|
+
/**
|
|
67
|
+
* How long one check may take.
|
|
68
|
+
* @default 5000
|
|
69
|
+
*/
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
/**
|
|
72
|
+
* The fetch to use, for tests.
|
|
73
|
+
* @default globalThis.fetch
|
|
74
|
+
*/
|
|
75
|
+
fetch?: typeof fetch;
|
|
76
|
+
/**
|
|
77
|
+
* The clock the checks are stamped with, for tests.
|
|
78
|
+
* @default Date.now
|
|
79
|
+
*/
|
|
80
|
+
now?: () => number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Ask molecules.cheminfo.org about a token: `GET /v1/token`, which says which
|
|
85
|
+
* source it was issued for and never counts as using it. A token pasted in
|
|
86
|
+
* another source's place, revoked, or never issued shows here before an import
|
|
87
|
+
* sends anything with it. Never throws: a molecules.cheminfo.org that does not
|
|
88
|
+
* answer is a verdict too.
|
|
89
|
+
* @param entry - The token, where it is read from, and the sources it may be for.
|
|
90
|
+
* @param options - Where molecules.cheminfo.org answers, and how patiently.
|
|
91
|
+
* @returns What it says of the token.
|
|
92
|
+
*/
|
|
93
|
+
export async function checkMoleculesToken(
|
|
94
|
+
entry: MoleculesTokenToCheck,
|
|
95
|
+
options: CheckMoleculesTokenOptions,
|
|
96
|
+
): Promise<MoleculesTokenCheck> {
|
|
97
|
+
const {
|
|
98
|
+
baseUrl,
|
|
99
|
+
timeoutMs = 5000,
|
|
100
|
+
fetch: fetchImplementation = globalThis.fetch,
|
|
101
|
+
now = Date.now,
|
|
102
|
+
} = options;
|
|
103
|
+
const sources = entry.sources === undefined ? [] : [...entry.sources];
|
|
104
|
+
const verdict = (
|
|
105
|
+
value: MoleculesTokenVerdict,
|
|
106
|
+
message: string | null = null,
|
|
107
|
+
): MoleculesTokenCheck => ({
|
|
108
|
+
variable: entry.variable,
|
|
109
|
+
sources,
|
|
110
|
+
verdict: value,
|
|
111
|
+
message,
|
|
112
|
+
source: null,
|
|
113
|
+
hint: null,
|
|
114
|
+
email: null,
|
|
115
|
+
issuedAt: null,
|
|
116
|
+
lastUsedAt: null,
|
|
117
|
+
checkedAt: now(),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const token = entry.token?.trim();
|
|
121
|
+
if (!token) return verdict('unset');
|
|
122
|
+
|
|
123
|
+
let response: Response;
|
|
124
|
+
try {
|
|
125
|
+
response = await fetchImplementation(
|
|
126
|
+
`${trimTrailingSlash(baseUrl)}/v1/token`,
|
|
127
|
+
{
|
|
128
|
+
headers: {
|
|
129
|
+
accept: 'application/json',
|
|
130
|
+
authorization: `Bearer ${token}`,
|
|
131
|
+
},
|
|
132
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
} catch (error: unknown) {
|
|
136
|
+
return verdict('unanswered', whyUnanswered(error, timeoutMs));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (response.status === 401) {
|
|
140
|
+
return verdict('refused', await messageOf(response));
|
|
141
|
+
}
|
|
142
|
+
if (response.status === 404) {
|
|
143
|
+
await response.body?.cancel();
|
|
144
|
+
return verdict('uncheckable', 'GET /v1/token answered 404');
|
|
145
|
+
}
|
|
146
|
+
if (!response.ok) {
|
|
147
|
+
await response.body?.cancel();
|
|
148
|
+
return verdict('unanswered', `GET /v1/token answered ${response.status}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const record = await recordOf(response);
|
|
152
|
+
if (record === null) {
|
|
153
|
+
return verdict('unanswered', 'GET /v1/token answered no token');
|
|
154
|
+
}
|
|
155
|
+
const known = {
|
|
156
|
+
source: record.source,
|
|
157
|
+
hint: record.hint,
|
|
158
|
+
email: record.email,
|
|
159
|
+
issuedAt: record.createdAt * 1000,
|
|
160
|
+
lastUsedAt: record.lastUsedAt === null ? null : record.lastUsedAt * 1000,
|
|
161
|
+
};
|
|
162
|
+
if (record.revokedAt !== null) {
|
|
163
|
+
return { ...verdict('refused', 'this token was revoked'), ...known };
|
|
164
|
+
}
|
|
165
|
+
const wanted = record.source.toLowerCase();
|
|
166
|
+
const expected =
|
|
167
|
+
sources.length === 0 ||
|
|
168
|
+
sources.some((source) => source.toLowerCase() === wanted);
|
|
169
|
+
return { ...verdict(expected ? 'ok' : 'otherSource'), ...known };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Check every token a site holds, all at once.
|
|
174
|
+
* @param entries - The tokens. See {@link checkMoleculesToken}.
|
|
175
|
+
* @param options - See {@link CheckMoleculesTokenOptions}.
|
|
176
|
+
* @returns What molecules.cheminfo.org says of each, in the order given.
|
|
177
|
+
*/
|
|
178
|
+
export async function checkMoleculesTokens(
|
|
179
|
+
entries: readonly MoleculesTokenToCheck[],
|
|
180
|
+
options: CheckMoleculesTokenOptions,
|
|
181
|
+
): Promise<MoleculesTokenCheck[]> {
|
|
182
|
+
return Promise.all(
|
|
183
|
+
entries.map((entry) => checkMoleculesToken(entry, options)),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* What a page anyone can open may show of a check: the verdict and the source,
|
|
189
|
+
* without who the token was issued to or its first characters.
|
|
190
|
+
* @param check - The check.
|
|
191
|
+
* @returns The check, without them.
|
|
192
|
+
*/
|
|
193
|
+
export function publicTokenCheck(
|
|
194
|
+
check: MoleculesTokenCheck,
|
|
195
|
+
): MoleculesTokenCheck {
|
|
196
|
+
return { ...check, email: null, hint: null };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** What `GET /v1/token` answers, as far as a check reads it. */
|
|
200
|
+
interface TokenRecord {
|
|
201
|
+
source: string;
|
|
202
|
+
email: string;
|
|
203
|
+
hint: string;
|
|
204
|
+
createdAt: number;
|
|
205
|
+
lastUsedAt: number | null;
|
|
206
|
+
revokedAt: number | null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async function recordOf(response: Response): Promise<TokenRecord | null> {
|
|
210
|
+
let body: unknown;
|
|
211
|
+
try {
|
|
212
|
+
body = await response.json();
|
|
213
|
+
} catch {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
if (typeof body !== 'object' || body === null) return null;
|
|
217
|
+
const record = body as Partial<Record<keyof TokenRecord, unknown>>;
|
|
218
|
+
if (
|
|
219
|
+
typeof record.source !== 'string' ||
|
|
220
|
+
typeof record.email !== 'string' ||
|
|
221
|
+
typeof record.hint !== 'string' ||
|
|
222
|
+
typeof record.createdAt !== 'number' ||
|
|
223
|
+
!isOptionalNumber(record.lastUsedAt) ||
|
|
224
|
+
!isOptionalNumber(record.revokedAt)
|
|
225
|
+
) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
source: record.source,
|
|
230
|
+
email: record.email,
|
|
231
|
+
hint: record.hint,
|
|
232
|
+
createdAt: record.createdAt,
|
|
233
|
+
lastUsedAt: record.lastUsedAt,
|
|
234
|
+
revokedAt: record.revokedAt,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function isOptionalNumber(value: unknown): value is number | null {
|
|
239
|
+
return value === null || typeof value === 'number';
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function messageOf(response: Response): Promise<string | null> {
|
|
243
|
+
try {
|
|
244
|
+
const body = (await response.json()) as { message?: unknown };
|
|
245
|
+
return typeof body.message === 'string' ? body.message : null;
|
|
246
|
+
} catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function whyUnanswered(error: unknown, timeoutMs: number): string {
|
|
252
|
+
if ((error as { name?: unknown } | null)?.name === 'TimeoutError') {
|
|
253
|
+
return `no answer within ${timeoutMs} ms`;
|
|
254
|
+
}
|
|
255
|
+
return error instanceof Error ? error.message : String(error);
|
|
256
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MoleculesTokenCheck,
|
|
3
|
+
MoleculesTokenVerdict,
|
|
4
|
+
} from './moleculesToken.ts';
|
|
5
|
+
|
|
6
|
+
/** The verdicts only a new token, written in the server's `.env`, fixes. */
|
|
7
|
+
const NEEDS_NEW_TOKEN: ReadonlySet<MoleculesTokenVerdict> = new Set([
|
|
8
|
+
'unset',
|
|
9
|
+
'refused',
|
|
10
|
+
'otherSource',
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The checks whose token has to be replaced: none is set, molecules.cheminfo.org
|
|
15
|
+
* refuses it, or it was issued for another source. A token that could not be
|
|
16
|
+
* checked is not among them, since nothing written in the `.env` fixes that.
|
|
17
|
+
* @param checks - The last checks.
|
|
18
|
+
* @returns Those to fix, in the order given.
|
|
19
|
+
*/
|
|
20
|
+
export function tokensToFix(
|
|
21
|
+
checks: readonly MoleculesTokenCheck[],
|
|
22
|
+
): MoleculesTokenCheck[] {
|
|
23
|
+
return checks.filter((check) => NEEDS_NEW_TOKEN.has(check.verdict));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The command molecules.cheminfo.org issues a check's token with, on its
|
|
28
|
+
* server. The source is quoted, since a name like `NP Atlas` holds a space;
|
|
29
|
+
* the email is left for the reader to write.
|
|
30
|
+
* @param check - The check, whose first source the token is issued for.
|
|
31
|
+
* @returns The command.
|
|
32
|
+
*/
|
|
33
|
+
export function issueTokenCommand(
|
|
34
|
+
check: Pick<MoleculesTokenCheck, 'sources'>,
|
|
35
|
+
): string {
|
|
36
|
+
return `npm run tokens -- issue '${check.sources[0] ?? 'SOURCE'}' EMAIL`;
|
|
37
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Callout } from '@blueprintjs/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
import { CodeBlock } from '../../clipboard/ui/CodeBlock.tsx';
|
|
5
|
+
import { useLanguage } from '../../i18n/ui/useLanguage.ts';
|
|
6
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
7
|
+
import { trimTrailingSlash } from '../../router/core/address.ts';
|
|
8
|
+
import type { MoleculesTokenCheck } from '../core/moleculesToken.ts';
|
|
9
|
+
import { issueTokenCommand, tokensToFix } from '../core/tokenFix.ts';
|
|
10
|
+
|
|
11
|
+
/** Where molecules.cheminfo.org answers when the site names no other. */
|
|
12
|
+
const DEFAULT_MOLECULES_URL = 'https://molecules.cheminfo.org';
|
|
13
|
+
|
|
14
|
+
/** What {@link MoleculesTokenFix} shows. */
|
|
15
|
+
export interface MoleculesTokenFixProps {
|
|
16
|
+
/** The last checks. */
|
|
17
|
+
checks: readonly MoleculesTokenCheck[];
|
|
18
|
+
/**
|
|
19
|
+
* Where molecules.cheminfo.org answers, whose Admin page issues tokens.
|
|
20
|
+
* @default 'https://molecules.cheminfo.org'
|
|
21
|
+
*/
|
|
22
|
+
moleculesUrl?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* What to do about the tokens that have to be replaced — none set, refused, or
|
|
27
|
+
* issued for another source — in the three steps it takes: issue one on
|
|
28
|
+
* molecules.cheminfo.org, write it in the server's `.env`, restart. Nothing
|
|
29
|
+
* when every token is fine.
|
|
30
|
+
* @param props - See {@link MoleculesTokenFixProps}.
|
|
31
|
+
* @returns The steps, or null.
|
|
32
|
+
*/
|
|
33
|
+
export function MoleculesTokenFix(
|
|
34
|
+
props: MoleculesTokenFixProps,
|
|
35
|
+
): ReactElement | null {
|
|
36
|
+
const { checks, moleculesUrl = DEFAULT_MOLECULES_URL } = props;
|
|
37
|
+
const t = useChromeT();
|
|
38
|
+
const language = useLanguage();
|
|
39
|
+
const toFix = tokensToFix(checks);
|
|
40
|
+
if (toFix.length === 0) return null;
|
|
41
|
+
|
|
42
|
+
const one = toFix.length === 1;
|
|
43
|
+
const variables = new Intl.ListFormat(language, {
|
|
44
|
+
type: 'conjunction',
|
|
45
|
+
}).format(toFix.map((check) => check.variable));
|
|
46
|
+
const admin = `${trimTrailingSlash(moleculesUrl)}/admin`;
|
|
47
|
+
const unsetOnly = toFix.every((check) => check.verdict === 'unset');
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Callout
|
|
51
|
+
intent={unsetOnly ? 'warning' : 'danger'}
|
|
52
|
+
icon="key"
|
|
53
|
+
title={t('moleculesToken.fix.title', { variables })}
|
|
54
|
+
className="molecules-tokens__fix"
|
|
55
|
+
data-testid="molecules-tokens-fix"
|
|
56
|
+
>
|
|
57
|
+
<ol>
|
|
58
|
+
<li>
|
|
59
|
+
<p>
|
|
60
|
+
{t(
|
|
61
|
+
one
|
|
62
|
+
? 'moleculesToken.fix.issueOne'
|
|
63
|
+
: 'moleculesToken.fix.issueMany',
|
|
64
|
+
)}{' '}
|
|
65
|
+
<a href={admin} target="_blank" rel="noreferrer">
|
|
66
|
+
{admin}
|
|
67
|
+
</a>
|
|
68
|
+
</p>
|
|
69
|
+
<p>{t('moleculesToken.fix.issueOnServer')}</p>
|
|
70
|
+
<CodeBlock
|
|
71
|
+
tone="muted"
|
|
72
|
+
copyable
|
|
73
|
+
code={[...new Set(toFix.map(issueTokenCommand))].join('\n')}
|
|
74
|
+
/>
|
|
75
|
+
</li>
|
|
76
|
+
<li>
|
|
77
|
+
<p>
|
|
78
|
+
{t(
|
|
79
|
+
one ? 'moleculesToken.fix.envOne' : 'moleculesToken.fix.envMany',
|
|
80
|
+
)}
|
|
81
|
+
</p>
|
|
82
|
+
<CodeBlock
|
|
83
|
+
tone="muted"
|
|
84
|
+
copyable
|
|
85
|
+
code={toFix.map((check) => `${check.variable}=mct_…`).join('\n')}
|
|
86
|
+
/>
|
|
87
|
+
</li>
|
|
88
|
+
<li>
|
|
89
|
+
<p>{t('moleculesToken.fix.restart')}</p>
|
|
90
|
+
<CodeBlock tone="muted" copyable code="docker compose up -d" />
|
|
91
|
+
</li>
|
|
92
|
+
</ol>
|
|
93
|
+
</Callout>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { Intent } from '@blueprintjs/core';
|
|
2
|
+
import { Button, Callout, HTMLTable, Tag } from '@blueprintjs/core';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
import type { ChromeKey } from '../../i18n/core/chromeCatalog.ts';
|
|
6
|
+
import { useLanguage } from '../../i18n/ui/useLanguage.ts';
|
|
7
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
8
|
+
import type {
|
|
9
|
+
MoleculesTokenCheck,
|
|
10
|
+
MoleculesTokenVerdict,
|
|
11
|
+
} from '../core/moleculesToken.ts';
|
|
12
|
+
import { tokensToFix } from '../core/tokenFix.ts';
|
|
13
|
+
|
|
14
|
+
import { MoleculesTokenFix } from './MoleculesTokenFix.tsx';
|
|
15
|
+
import { tokenDetails } from './tokenDetails.tsx';
|
|
16
|
+
|
|
17
|
+
/** What {@link MoleculesTokenTable} shows. */
|
|
18
|
+
export interface MoleculesTokenTableProps {
|
|
19
|
+
/** The last checks, or null before the first one was made. */
|
|
20
|
+
checks: readonly MoleculesTokenCheck[] | null;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a check was asked for and is not made yet.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
pending?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Asks for every token to be checked again. Left out, there is no button:
|
|
28
|
+
* a page anyone can open shows the last checks and asks for none.
|
|
29
|
+
* @default undefined
|
|
30
|
+
*/
|
|
31
|
+
onCheckAgain?: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Why asking for a check failed.
|
|
34
|
+
* @default undefined
|
|
35
|
+
*/
|
|
36
|
+
error?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Where molecules.cheminfo.org answers, whose Admin page issues tokens.
|
|
39
|
+
* @default 'https://molecules.cheminfo.org'
|
|
40
|
+
*/
|
|
41
|
+
moleculesUrl?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const INTENT: Record<MoleculesTokenVerdict, Intent> = {
|
|
45
|
+
ok: 'success',
|
|
46
|
+
otherSource: 'danger',
|
|
47
|
+
refused: 'danger',
|
|
48
|
+
unset: 'warning',
|
|
49
|
+
uncheckable: 'warning',
|
|
50
|
+
unanswered: 'warning',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** How each verdict reads in the table. */
|
|
54
|
+
const LABEL: Record<MoleculesTokenVerdict, ChromeKey> = {
|
|
55
|
+
ok: 'moleculesToken.verdict.ok',
|
|
56
|
+
otherSource: 'moleculesToken.verdict.otherSource',
|
|
57
|
+
refused: 'moleculesToken.verdict.refused',
|
|
58
|
+
unset: 'moleculesToken.verdict.unset',
|
|
59
|
+
uncheckable: 'moleculesToken.verdict.uncheckable',
|
|
60
|
+
unanswered: 'moleculesToken.verdict.unanswered',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** The command a token is issued with, on molecules.cheminfo.org. */
|
|
64
|
+
const ISSUE_COMMAND = 'npm run tokens -- issue SOURCE EMAIL';
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The tokens a site holds for molecules.cheminfo.org, one row each, with what
|
|
68
|
+
* molecules.cheminfo.org said of it when it was last checked: valid, another
|
|
69
|
+
* source's, refused, not set. A token is changed in the server's `.env`, never
|
|
70
|
+
* here, so the table says where, and above it how, when one has to be.
|
|
71
|
+
* @param props - See {@link MoleculesTokenTableProps}.
|
|
72
|
+
* @returns The table.
|
|
73
|
+
*/
|
|
74
|
+
export function MoleculesTokenTable(props: MoleculesTokenTableProps) {
|
|
75
|
+
const { checks, pending = false, onCheckAgain, error, moleculesUrl } = props;
|
|
76
|
+
const t = useChromeT();
|
|
77
|
+
const language = useLanguage();
|
|
78
|
+
const formats = useMemo(
|
|
79
|
+
() => ({
|
|
80
|
+
instant: new Intl.DateTimeFormat(language, {
|
|
81
|
+
dateStyle: 'medium',
|
|
82
|
+
timeStyle: 'short',
|
|
83
|
+
}),
|
|
84
|
+
sources: new Intl.ListFormat(language, { type: 'disjunction' }),
|
|
85
|
+
}),
|
|
86
|
+
[language],
|
|
87
|
+
);
|
|
88
|
+
const checkedAt =
|
|
89
|
+
checks === null || checks.length === 0
|
|
90
|
+
? null
|
|
91
|
+
: Math.min(...checks.map((check) => check.checkedAt));
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<section
|
|
95
|
+
className="molecules-tokens"
|
|
96
|
+
aria-label={t('moleculesToken.title')}
|
|
97
|
+
data-testid="molecules-tokens"
|
|
98
|
+
>
|
|
99
|
+
<div className="molecules-tokens__head">
|
|
100
|
+
<span className="molecules-tokens__title">
|
|
101
|
+
{t('moleculesToken.title')}
|
|
102
|
+
</span>
|
|
103
|
+
{checkedAt !== null && (
|
|
104
|
+
<span className="molecules-tokens__muted">
|
|
105
|
+
{t('moleculesToken.checkedAt', {
|
|
106
|
+
when: formats.instant.format(checkedAt),
|
|
107
|
+
})}
|
|
108
|
+
</span>
|
|
109
|
+
)}
|
|
110
|
+
{onCheckAgain !== undefined && (
|
|
111
|
+
<Button
|
|
112
|
+
size="small"
|
|
113
|
+
variant="minimal"
|
|
114
|
+
icon="refresh"
|
|
115
|
+
loading={pending}
|
|
116
|
+
text={t('moleculesToken.checkAgain')}
|
|
117
|
+
onClick={onCheckAgain}
|
|
118
|
+
data-testid="molecules-tokens-check"
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
</div>
|
|
122
|
+
{error !== undefined && (
|
|
123
|
+
<Callout compact intent="danger">
|
|
124
|
+
{error}
|
|
125
|
+
</Callout>
|
|
126
|
+
)}
|
|
127
|
+
{checks !== null && (
|
|
128
|
+
<MoleculesTokenFix checks={checks} moleculesUrl={moleculesUrl} />
|
|
129
|
+
)}
|
|
130
|
+
{checks === null ? (
|
|
131
|
+
<p className="molecules-tokens__muted">
|
|
132
|
+
{t('moleculesToken.notChecked')}
|
|
133
|
+
</p>
|
|
134
|
+
) : (
|
|
135
|
+
<div className="molecules-tokens__scroll">
|
|
136
|
+
<HTMLTable compact striped className="molecules-tokens__table">
|
|
137
|
+
<thead>
|
|
138
|
+
<tr>
|
|
139
|
+
<th>{t('moleculesToken.column.variable')}</th>
|
|
140
|
+
<th>{t('moleculesToken.column.source')}</th>
|
|
141
|
+
<th>{t('moleculesToken.column.status')}</th>
|
|
142
|
+
<th>{t('moleculesToken.column.details')}</th>
|
|
143
|
+
</tr>
|
|
144
|
+
</thead>
|
|
145
|
+
<tbody>
|
|
146
|
+
{checks.map((check) => (
|
|
147
|
+
<tr key={check.variable} data-verdict={check.verdict}>
|
|
148
|
+
<td>
|
|
149
|
+
<code>{check.variable}</code>
|
|
150
|
+
</td>
|
|
151
|
+
<td>
|
|
152
|
+
{check.sources.length === 0
|
|
153
|
+
? t('moleculesToken.anySource')
|
|
154
|
+
: formats.sources.format(check.sources)}
|
|
155
|
+
</td>
|
|
156
|
+
<td>
|
|
157
|
+
<Tag minimal intent={INTENT[check.verdict]}>
|
|
158
|
+
{t(LABEL[check.verdict])}
|
|
159
|
+
</Tag>
|
|
160
|
+
</td>
|
|
161
|
+
<td>{tokenDetails(check, t, formats.instant)}</td>
|
|
162
|
+
</tr>
|
|
163
|
+
))}
|
|
164
|
+
</tbody>
|
|
165
|
+
</HTMLTable>
|
|
166
|
+
</div>
|
|
167
|
+
)}
|
|
168
|
+
{(checks === null || tokensToFix(checks).length === 0) && (
|
|
169
|
+
<p className="molecules-tokens__muted">
|
|
170
|
+
{t('moleculesToken.howToChange')} <code>{ISSUE_COMMAND}</code>
|
|
171
|
+
</p>
|
|
172
|
+
)}
|
|
173
|
+
</section>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { MoleculesTokenFixProps } from './MoleculesTokenFix.tsx';
|
|
2
|
+
export { MoleculesTokenFix } from './MoleculesTokenFix.tsx';
|
|
3
|
+
export type { MoleculesTokenTableProps } from './MoleculesTokenTable.tsx';
|
|
4
|
+
export { MoleculesTokenTable } from './MoleculesTokenTable.tsx';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { ChromeKey } from '../../i18n/core/chromeCatalog.ts';
|
|
4
|
+
import type { Translate } from '../../i18n/ui/useT.ts';
|
|
5
|
+
import type { MoleculesTokenCheck } from '../core/moleculesToken.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What a row says besides its verdict.
|
|
9
|
+
* @param check - The check.
|
|
10
|
+
* @param t - The chrome's translator.
|
|
11
|
+
* @param instant - How an instant is written.
|
|
12
|
+
* @returns The cell's content.
|
|
13
|
+
*/
|
|
14
|
+
export function tokenDetails(
|
|
15
|
+
check: MoleculesTokenCheck,
|
|
16
|
+
t: Translate<ChromeKey>,
|
|
17
|
+
instant: Intl.DateTimeFormat,
|
|
18
|
+
): ReactNode {
|
|
19
|
+
const hint: Fact | null =
|
|
20
|
+
check.hint === null
|
|
21
|
+
? null
|
|
22
|
+
: ['hint', <code key="hint">{check.hint}…</code>];
|
|
23
|
+
switch (check.verdict) {
|
|
24
|
+
case 'ok':
|
|
25
|
+
return facts([
|
|
26
|
+
check.sources.length === 1 || check.source === null
|
|
27
|
+
? null
|
|
28
|
+
: ['source', t('moleculesToken.forSource', { source: check.source })],
|
|
29
|
+
check.issuedAt === null
|
|
30
|
+
? null
|
|
31
|
+
: [
|
|
32
|
+
'issued',
|
|
33
|
+
check.email === null
|
|
34
|
+
? t('moleculesToken.issued', {
|
|
35
|
+
when: instant.format(check.issuedAt),
|
|
36
|
+
})
|
|
37
|
+
: t('moleculesToken.issuedTo', {
|
|
38
|
+
email: check.email,
|
|
39
|
+
when: instant.format(check.issuedAt),
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
'used',
|
|
44
|
+
check.lastUsedAt === null
|
|
45
|
+
? t('moleculesToken.neverUsed')
|
|
46
|
+
: t('moleculesToken.lastUsed', {
|
|
47
|
+
when: instant.format(check.lastUsedAt),
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
hint,
|
|
51
|
+
]);
|
|
52
|
+
case 'otherSource':
|
|
53
|
+
return facts([
|
|
54
|
+
[
|
|
55
|
+
'source',
|
|
56
|
+
t('moleculesToken.otherSourceDetail', {
|
|
57
|
+
source: check.source ?? '',
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
hint,
|
|
61
|
+
]);
|
|
62
|
+
case 'refused':
|
|
63
|
+
return check.message ?? t('moleculesToken.refusedDetail');
|
|
64
|
+
case 'unset':
|
|
65
|
+
return t('moleculesToken.unsetDetail', { variable: check.variable });
|
|
66
|
+
case 'uncheckable':
|
|
67
|
+
return t('moleculesToken.uncheckableDetail');
|
|
68
|
+
case 'unanswered':
|
|
69
|
+
return check.message;
|
|
70
|
+
default:
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** One fact about a token, and the key it is drawn under. */
|
|
76
|
+
type Fact = readonly [key: string, content: ReactNode];
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Facts about a token, one after the other.
|
|
80
|
+
* @param parts - The facts; null ones are left out.
|
|
81
|
+
* @returns The facts, separated by a middle dot.
|
|
82
|
+
*/
|
|
83
|
+
function facts(parts: ReadonlyArray<Fact | null>): ReactNode {
|
|
84
|
+
const shown = parts.filter((part) => part !== null);
|
|
85
|
+
return shown.map(([key, content], index) => (
|
|
86
|
+
<span key={key}>
|
|
87
|
+
{index > 0 && ' · '}
|
|
88
|
+
{content}
|
|
89
|
+
</span>
|
|
90
|
+
));
|
|
91
|
+
}
|
package/src/ui.ts
CHANGED
|
@@ -18,6 +18,8 @@ export * from './help/ui/index.ts';
|
|
|
18
18
|
export * from './hooks/ui/index.ts';
|
|
19
19
|
export * from './i18n/ui/index.ts';
|
|
20
20
|
export * from './language/ui/index.ts';
|
|
21
|
+
export * from './moleculesSources/ui/index.ts';
|
|
22
|
+
export * from './moleculesToken/ui/index.ts';
|
|
21
23
|
export * from './number/ui/index.ts';
|
|
22
24
|
export * from './overlay/ui/index.ts';
|
|
23
25
|
export * from './panel/ui/index.ts';
|