( commit: Commit, /** URL to post to, e.g. https://atomicdata.dev/commit */ endpoint: string, )
| 88 | |
| 89 | /** Posts a Commit to some endpoint */ |
| 90 | export async function postCommit( |
| 91 | commit: Commit, |
| 92 | /** URL to post to, e.g. https://atomicdata.dev/commit */ |
| 93 | endpoint: string, |
| 94 | ): Promise<string> { |
| 95 | const serialized = serializeDeterministically(commit); |
| 96 | const requestHeaders: HeadersInit = new Headers(); |
| 97 | requestHeaders.set('Content-Type', 'application/ad+json'); |
| 98 | let response = null; |
| 99 | try { |
| 100 | response = await fetch(endpoint, { |
| 101 | headers: requestHeaders, |
| 102 | method: 'POST', |
| 103 | body: serialized, |
| 104 | }); |
| 105 | } catch (e) { |
| 106 | throw new Error(`Posting Commit to ${endpoint} failed: ${e}`); |
| 107 | } |
| 108 | const body = await response.text(); |
| 109 | if (response.status !== 200) { |
| 110 | throw new Error(body); |
| 111 | } |
| 112 | return body; |
| 113 | } |
| 114 | |
| 115 | /** Throws an error if the URL is not valid */ |
| 116 | export function tryValidURL(subject: string): void { |
no test coverage detected