| 65 | * `AccountNoOrganization` when the org selector header is absent, because the |
| 66 | * session's own org is only a default and is never fallen back to. */ |
| 67 | export const postJson = ( |
| 68 | target: TargetShape, |
| 69 | path: string, |
| 70 | identity: Identity, |
| 71 | body: unknown, |
| 72 | ): Effect.Effect<Response> => |
| 73 | Effect.promise(async () => { |
| 74 | const response = await fetch(new URL(path, target.baseUrl), { |
| 75 | method: "POST", |
| 76 | headers: { |
| 77 | ...(identity.headers ?? {}), |
| 78 | "content-type": "application/json", |
| 79 | origin: new URL(target.baseUrl).origin, |
| 80 | }, |
| 81 | body: JSON.stringify(body), |
| 82 | }); |
| 83 | if (!response.ok) { |
| 84 | throw new Error(`${path} failed (${response.status}): ${await response.text()}`); |
| 85 | } |
| 86 | return response; |
| 87 | }); |
| 88 | |
| 89 | /** The identity re-bound to the refreshed session cookie a response set, and |
| 90 | * scoped to `orgSelector` — carrying the cookie alone would leave every |