@manta-eu/horns-client 0.1.0 → 0.1.2
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/component-api.d.ts +7 -0
- package/dist/app/coverage-run.js +4 -3
- package/dist/app/globals.css +2 -0
- package/dist/app/home-page.js +6 -4
- package/dist/app/horn-page.js +7 -10
- package/dist/app/horn-studio.js +63 -10
- package/dist/app/horn-view-page.js +13 -9
- package/dist/app/horns-page.js +6 -9
- package/dist/app/new-horn-page.js +52 -10
- package/dist/app/paths.d.ts +15 -10
- package/dist/app/paths.js +18 -29
- package/dist/app/plans-page.d.ts +1 -0
- package/dist/app/plans-page.js +59 -0
- package/dist/app/reference-page.d.ts +1 -0
- package/dist/app/reference-page.js +55 -0
- package/dist/app/routes.js +7 -5
- package/dist/app/rule-page.js +18 -11
- package/dist/app/rules-page.js +12 -12
- package/dist/app/shape-entity-page.js +7 -9
- package/dist/app/shape-zoo-page.js +9 -10
- package/dist/app/shapes-page.js +13 -15
- package/dist/app/showcase-page.js +8 -11
- package/dist/components/app-shell.js +8 -7
- package/dist/components/catalog-card-view.js +4 -5
- package/dist/components/explain-dialog.d.ts +5 -0
- package/dist/components/explain-dialog.js +26 -0
- package/dist/components/plan-runs.js +2 -2
- package/dist/components/read-the-code.d.ts +19 -0
- package/dist/components/read-the-code.js +17 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/lib/horn-review.d.ts +7 -0
- package/dist/lib/horn-review.js +15 -0
- package/dist/lib/horn-variables.d.ts +8 -0
- package/dist/lib/horn-variables.js +39 -0
- package/dist/lib/manta/sign-in.d.ts +2 -0
- package/dist/lib/manta/sign-in.js +9 -0
- package/dist/lib/manta/sparql-select.d.ts +6 -2
- package/dist/lib/manta/sparql-select.js +17 -14
- package/dist/lib/reference/fake-sparql.d.ts +4 -0
- package/dist/lib/reference/fake-sparql.js +216 -0
- package/dist/lib/shapes/ldkit-source.d.ts +1 -1
- package/dist/lib/shapes/ldkit-source.js +1 -1
- package/dist/lib/studio-progress.js +3 -1
- package/dist/lib/surface/declarations.d.ts +5 -0
- package/dist/lib/surface/declarations.js +77 -0
- package/dist/lib/written-surface.js +13 -2
- package/dist/reference/supply-chain-360.horn.json +413 -0
- package/dist/standalone/app.d.ts +2 -0
- package/dist/standalone/app.js +57 -0
- package/dist/standalone/client.d.ts +15 -0
- package/dist/{client.js → standalone/client.js} +12 -8
- package/dist/standalone/gates.d.ts +10 -0
- package/dist/standalone/gates.js +15 -0
- package/dist/styles.css +1 -1
- package/dist/vite/component-api.d.ts +8 -0
- package/dist/vite/component-api.js +24 -0
- package/dist/vite/index.d.ts +3 -0
- package/dist/vite/index.js +3 -0
- package/dist/vite/shape-catalog.d.ts +10 -0
- package/dist/vite/shape-catalog.js +35 -0
- package/dist/vite/typecheck-fs.d.ts +6 -0
- package/dist/vite/typecheck-fs.js +68 -0
- package/package.json +58 -20
- package/shape-catalog.d.ts +9 -0
- package/typecheck-fs.d.ts +6 -0
- package/dist/app/session-gate.d.ts +0 -6
- package/dist/app/session-gate.js +0 -19
- package/dist/client.d.ts +0 -10
- package/dist/lib/manta/providers.d.ts +0 -10
- package/dist/lib/manta/providers.js +0 -48
- package/dist/lib/manta/session.d.ts +0 -47
- package/dist/lib/manta/session.js +0 -204
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, use, useCallback, useEffect, useMemo, useState } from "react";
|
|
3
|
-
import { isPresent } from "@manta-eu/lib/present";
|
|
4
|
-
import { isRecord, isString } from "@manta-eu/horns";
|
|
5
|
-
import { signedInParam } from "@manta-eu/horns-server/shared";
|
|
6
|
-
export function signInHref(redirect) {
|
|
7
|
-
const params = new URLSearchParams();
|
|
8
|
-
if (isPresent(redirect) && redirect !== "/")
|
|
9
|
-
params.set("redirect", redirect);
|
|
10
|
-
const query = params.toString();
|
|
11
|
-
return `/login${query ? `?${query}` : ""}`;
|
|
12
|
-
}
|
|
13
|
-
export async function readJsonError(response, fallback) {
|
|
14
|
-
const body = await response.json().catch(() => undefined);
|
|
15
|
-
if (typeof body === "object" && isPresent(body) && "error" in body && typeof body.error === "string") {
|
|
16
|
-
return body.error;
|
|
17
|
-
}
|
|
18
|
-
return fallback;
|
|
19
|
-
}
|
|
20
|
-
export class RequestFailed extends Error {
|
|
21
|
-
status;
|
|
22
|
-
constructor(status, message) {
|
|
23
|
-
super(message);
|
|
24
|
-
this.name = "RequestFailed";
|
|
25
|
-
this.status = status;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export function statusOf(caught) {
|
|
29
|
-
return caught instanceof RequestFailed ? caught.status : undefined;
|
|
30
|
-
}
|
|
31
|
-
// 204 responses are success, not a parse failure. The body is untrusted until `parse` has checked it.
|
|
32
|
-
export async function requestJson(path, init, fallback, parse) {
|
|
33
|
-
const response = await fetch(path, { credentials: "same-origin", ...init });
|
|
34
|
-
if (!response.ok)
|
|
35
|
-
throw new RequestFailed(response.status, await readJsonError(response, fallback));
|
|
36
|
-
const text = await response.text();
|
|
37
|
-
if (!isPresent(text.trim()))
|
|
38
|
-
return undefined;
|
|
39
|
-
const body = JSON.parse(text);
|
|
40
|
-
return parse(body);
|
|
41
|
-
}
|
|
42
|
-
const readJson = (path, fallback, parse) => requestJson(path, { headers: { accept: "application/json" } }, fallback, parse);
|
|
43
|
-
function parseDatastore(value) {
|
|
44
|
-
if (!isRecord(value) || typeof value.id !== "string" || typeof value.name !== "string")
|
|
45
|
-
return undefined;
|
|
46
|
-
return {
|
|
47
|
-
id: value.id,
|
|
48
|
-
name: value.name,
|
|
49
|
-
...(typeof value.depth === "number" ? { depth: value.depth } : {}),
|
|
50
|
-
...(typeof value.selectable === "boolean" ? { selectable: value.selectable } : {}),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function parseLoginStatus(body) {
|
|
54
|
-
if (!isRecord(body) || typeof body.valid !== "boolean")
|
|
55
|
-
throw new Error("Sign-in status is malformed.");
|
|
56
|
-
return {
|
|
57
|
-
valid: body.valid,
|
|
58
|
-
canSwitchDatastore: body.canSwitchDatastore === true,
|
|
59
|
-
allowedModels: Array.isArray(body.allowedModels) ? body.allowedModels.filter(isString) : [],
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function parseUserContext(body) {
|
|
63
|
-
if (!isRecord(body) || !isRecord(body.user))
|
|
64
|
-
throw new Error("User context is malformed.");
|
|
65
|
-
const { user } = body;
|
|
66
|
-
if (typeof user.id !== "string" || typeof user.email !== "string")
|
|
67
|
-
throw new Error("User context is malformed.");
|
|
68
|
-
const datastore = parseDatastore(user.datastore);
|
|
69
|
-
return {
|
|
70
|
-
user: {
|
|
71
|
-
id: user.id,
|
|
72
|
-
email: user.email,
|
|
73
|
-
isOperator: user.isOperator === true,
|
|
74
|
-
...(typeof user.name === "string" ? { name: user.name } : {}),
|
|
75
|
-
...(datastore ? { datastore } : {}),
|
|
76
|
-
},
|
|
77
|
-
datastores: Array.isArray(body.datastores) ? body.datastores.flatMap((entry) => parseDatastore(entry) ?? []) : [],
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
export function sessionGate(value) {
|
|
81
|
-
if (isPresent(value.authError))
|
|
82
|
-
return "blocked";
|
|
83
|
-
if (value.status === "loading")
|
|
84
|
-
return "loading";
|
|
85
|
-
if (value.status === "error")
|
|
86
|
-
return "blocked";
|
|
87
|
-
if (value.status === "signed-out")
|
|
88
|
-
return value.justSignedIn ? "looped" : "sign-in";
|
|
89
|
-
return "ready";
|
|
90
|
-
}
|
|
91
|
-
// The realm's own top-level datastore is the one with no depth that cannot be picked.
|
|
92
|
-
export function realmDatastore(value) {
|
|
93
|
-
return value.datastores.find((datastore) => !isPresent(datastore.depth) && datastore.selectable !== true);
|
|
94
|
-
}
|
|
95
|
-
export function activeDatastore(value) {
|
|
96
|
-
if (isPresent(value.user?.datastore))
|
|
97
|
-
return value.user.datastore;
|
|
98
|
-
if (!value.isOperator)
|
|
99
|
-
return undefined;
|
|
100
|
-
return realmDatastore(value);
|
|
101
|
-
}
|
|
102
|
-
const MantaSessionContext = createContext(undefined);
|
|
103
|
-
function readAuthError() {
|
|
104
|
-
const raw = new URLSearchParams(window.location.search).get("auth_error");
|
|
105
|
-
return isPresent(raw) ? raw : undefined;
|
|
106
|
-
}
|
|
107
|
-
function readJustSignedIn() {
|
|
108
|
-
return new URLSearchParams(window.location.search).get(signedInParam) === "1";
|
|
109
|
-
}
|
|
110
|
-
export function MantaSessionProvider({ children }) {
|
|
111
|
-
const [status, setStatus] = useState("loading");
|
|
112
|
-
const [context, setContext] = useState();
|
|
113
|
-
const [canSwitchDatastore, setCanSwitchDatastore] = useState(false);
|
|
114
|
-
const [error, setError] = useState();
|
|
115
|
-
const [reloads, setReloads] = useState(0);
|
|
116
|
-
const [revision, setRevision] = useState(0);
|
|
117
|
-
const [authError, setAuthError] = useState(readAuthError);
|
|
118
|
-
const [justSignedIn] = useState(readJustSignedIn);
|
|
119
|
-
useEffect(() => {
|
|
120
|
-
if (!isPresent(authError) && !justSignedIn)
|
|
121
|
-
return;
|
|
122
|
-
const url = new URL(window.location.href);
|
|
123
|
-
url.searchParams.delete("auth_error");
|
|
124
|
-
url.searchParams.delete(signedInParam);
|
|
125
|
-
window.history.replaceState(window.history.state, "", url.pathname + url.search);
|
|
126
|
-
}, [authError, justSignedIn]);
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
let live = true;
|
|
129
|
-
void (async () => {
|
|
130
|
-
if (reloads === 0)
|
|
131
|
-
setStatus("loading");
|
|
132
|
-
setError(undefined);
|
|
133
|
-
try {
|
|
134
|
-
const login = await readJson("/api/login", "Sign-in status is unavailable.", parseLoginStatus);
|
|
135
|
-
if (!live)
|
|
136
|
-
return;
|
|
137
|
-
if (!isPresent(login))
|
|
138
|
-
throw new Error("Sign-in status is unavailable.");
|
|
139
|
-
setCanSwitchDatastore(login.canSwitchDatastore);
|
|
140
|
-
if (!login.valid) {
|
|
141
|
-
setContext(undefined);
|
|
142
|
-
setStatus("signed-out");
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const loaded = await readJson("/api/data/context", "User context is unavailable.", parseUserContext);
|
|
146
|
-
if (!live)
|
|
147
|
-
return;
|
|
148
|
-
if (!isPresent(loaded))
|
|
149
|
-
throw new Error("User context is unavailable.");
|
|
150
|
-
setContext(loaded);
|
|
151
|
-
setStatus("ready");
|
|
152
|
-
setRevision((count) => count + 1);
|
|
153
|
-
}
|
|
154
|
-
catch (caught) {
|
|
155
|
-
if (!live)
|
|
156
|
-
return;
|
|
157
|
-
// The upstream session can expire between the /api/login check and this fetch.
|
|
158
|
-
if (statusOf(caught) === 401) {
|
|
159
|
-
setContext(undefined);
|
|
160
|
-
setStatus("signed-out");
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
setError(caught instanceof Error ? caught.message : "Manta Horns is unavailable.");
|
|
164
|
-
setStatus("error");
|
|
165
|
-
}
|
|
166
|
-
})();
|
|
167
|
-
return () => {
|
|
168
|
-
live = false;
|
|
169
|
-
};
|
|
170
|
-
}, [reloads]);
|
|
171
|
-
const reload = useCallback(() => {
|
|
172
|
-
setAuthError(undefined);
|
|
173
|
-
setReloads((count) => count + 1);
|
|
174
|
-
}, []);
|
|
175
|
-
const value = useMemo(() => {
|
|
176
|
-
const isOperator = context?.user.isOperator ?? false;
|
|
177
|
-
const datastore = activeDatastore({
|
|
178
|
-
isOperator,
|
|
179
|
-
...(isPresent(context) ? { user: context.user } : {}),
|
|
180
|
-
datastores: context?.datastores ?? [],
|
|
181
|
-
});
|
|
182
|
-
return {
|
|
183
|
-
status,
|
|
184
|
-
isLive: status === "ready",
|
|
185
|
-
...(isPresent(context) ? { user: context.user } : {}),
|
|
186
|
-
...(isPresent(datastore) ? { datastore } : {}),
|
|
187
|
-
datastores: context?.datastores ?? [],
|
|
188
|
-
isOperator,
|
|
189
|
-
canSwitchDatastore,
|
|
190
|
-
...(isPresent(error) ? { error } : {}),
|
|
191
|
-
...(isPresent(authError) ? { authError } : {}),
|
|
192
|
-
justSignedIn,
|
|
193
|
-
revision,
|
|
194
|
-
reload,
|
|
195
|
-
};
|
|
196
|
-
}, [status, context, canSwitchDatastore, error, authError, justSignedIn, revision, reload]);
|
|
197
|
-
return _jsx(MantaSessionContext.Provider, { value: value, children: children });
|
|
198
|
-
}
|
|
199
|
-
export function useMantaSession() {
|
|
200
|
-
const value = use(MantaSessionContext);
|
|
201
|
-
if (!isPresent(value))
|
|
202
|
-
throw new Error("useMantaSession must be used inside MantaSessionProvider");
|
|
203
|
-
return value;
|
|
204
|
-
}
|