MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / request

Function request

apps/cloud/src/web/components/admin-verification.tsx:37–65  ·  view source on GitHub ↗
(
  path: string,
  decode: (value: unknown) => Option.Option<A>,
  body?: Readonly<Record<string, string>>,
)

Source from the content-addressed store, hash-verified

35const decodeCanceled = Schema.decodeUnknownOption(Canceled);
36
37function request<A>(
38 path: string,
39 decode: (value: unknown) => Option.Option<A>,
40 body?: Readonly<Record<string, string>>,
41): Effect.Effect<A, VerificationError> {
42 return Effect.gen(function* () {
43 const { response, raw } = yield* Effect.gen(function* () {
44 const client = yield* HttpClient.HttpClient;
45 const url = `/api/auth/admin-mfa${path}`;
46 const base = body === undefined ? HttpClientRequest.get(url) : HttpClientRequest.post(url);
47 const payload = body === undefined ? base : yield* HttpClientRequest.bodyJson(base, body);
48 const response = yield* client.execute(
49 HttpClientRequest.setHeaders(payload, getExecutorOrganizationHeaders()),
50 );
51 const raw = yield* response.json;
52 return { response, raw };
53 }).pipe(
54 Effect.provide(FetchHttpClient.layer),
55 Effect.mapError(() => new VerificationError({ message: unavailable })),
56 );
57 if (response.status < 200 || response.status >= 300) {
58 const message = Option.getOrNull(decodeMessage(raw));
59 return yield* new VerificationError({ message: message?.message ?? unavailable });
60 }
61 const parsed = decode(raw);
62 if (Option.isNone(parsed)) return yield* new VerificationError({ message: unavailable });
63 return parsed.value;
64 });
65}
66
67/** Require a second factor before mounting the organization settings page. */
68export function AdminVerification({ children }: { readonly children: ReactNode }) {

Callers 2

loadFunction · 0.70
actFunction · 0.70

Calls 3

getMethod · 0.65
executeMethod · 0.65

Tested by

no test coverage detected