| 109 | const cookieOf = (identity: Identity): string => identity.headers?.["cookie"] ?? ""; |
| 110 | |
| 111 | const 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 | |
| 128 | const withRefreshedSession = (identity: Identity, response: Response): Identity => { |
| 129 | const refreshed = (response.headers.getSetCookie?.() ?? []) |