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

Function postJson

e2e/cloud/spec-update-convergence.test.ts:111–126  ·  view source on GitHub ↗
(target: TargetShape, path: string, identity: Identity, body: unknown)

Source from the content-addressed store, hash-verified

109const cookieOf = (identity: Identity): string => identity.headers?.["cookie"] ?? "";
110
111const postJson = (target: TargetShape, path: string, identity: Identity, body: unknown) =>
112 Effect.promise(async () => {
113 const response = await fetch(new URL(path, target.baseUrl), {
114 method: "POST",
115 headers: {
116 "content-type": "application/json",
117 origin: new URL(target.baseUrl).origin,
118 cookie: cookieOf(identity),
119 },
120 body: JSON.stringify(body),
121 });
122 if (!response.ok) {
123 throw new Error(`${path} failed (${response.status}): ${await response.text()}`);
124 }
125 return response;
126 });
127
128const withRefreshedSession = (identity: Identity, response: Response): Identity => {
129 const refreshed = (response.headers.getSetCookie?.() ?? [])

Callers 1

joinOrgFunction · 0.70

Calls 3

cookieOfFunction · 0.70
textMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected