Skip to content

Commit 9e187dd

Browse files
committed
move to trpc client
1 parent 637de01 commit 9e187dd

2 files changed

Lines changed: 27 additions & 57 deletions

File tree

auth.ts

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -221,42 +221,19 @@ export async function authedFetch(
221221
const url = new URL(endpoint, deployUrl);
222222

223223
let fallbackBody: ReadableStream | undefined;
224-
try {
225-
if (init.body instanceof ReadableStream) {
226-
const [a, b] = init.body.tee();
227-
init.body = a;
228-
fallbackBody = b;
229-
}
230-
231-
const res = await fetch(url, {
232-
...init,
233-
headers,
234-
});
235-
236-
if (res.status === 401) {
237-
token_storage.remove();
238-
auth = await getAuth(deployUrl);
224+
if (init.body instanceof ReadableStream) {
225+
const [a, b] = init.body.tee();
226+
init.body = a;
227+
fallbackBody = b;
228+
}
239229

240-
const headers = new Headers(init.headers);
241-
headers.set(
242-
"cookie",
243-
`token=${auth}; deno_auth_ghid=force`,
244-
);
245-
const res = await fetch(url, {
246-
...init,
247-
headers,
248-
});
230+
const res = await fetch(url, {
231+
...init,
232+
headers,
233+
});
249234

250-
if (res.status === 401) {
251-
const err = await res.json();
252-
error(`unexpected authentication failure\n${err.message}`);
253-
} else {
254-
return res;
255-
}
256-
} else {
257-
return res;
258-
}
259-
} catch {
235+
if (res.status === 401) {
236+
console.log(await res.text());
260237
token_storage.remove();
261238
auth = await getAuth(deployUrl);
262239

@@ -265,17 +242,19 @@ export async function authedFetch(
265242
"cookie",
266243
`token=${auth}; deno_auth_ghid=force`,
267244
);
268-
const res = await fetch(url, {
245+
const retryRes = await fetch(url, {
269246
...init,
270247
headers,
271248
body: init.body instanceof ReadableStream ? fallbackBody : init.body,
272249
});
273250

274-
if (res.status === 401) {
275-
const err = await res.json();
251+
if (retryRes.status === 401) {
252+
const err = await retryRes.json();
276253
error(`unexpected authentication failure\n${err.message}`);
277254
} else {
278-
return res;
255+
return retryRes;
279256
}
257+
} else {
258+
return res;
280259
}
281260
}

publish.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,20 @@ export async function publish(
105105
hashesSpinner.stop();
106106
console.log(`${green("✔")} Generated hashes`);
107107

108-
const initiatedBuildRes = await authedFetch(
109-
deployUrl,
110-
"api/initiate_cli_build",
111-
{
112-
method: "POST",
113-
headers: {
114-
"content-type": "application/json",
115-
},
116-
body: JSON.stringify({
117-
org,
118-
app,
119-
production: prod,
120-
manifest,
121-
}),
122-
},
123-
);
108+
const trpcClient = createTrpcClient(deployUrl);
109+
110+
// deno-lint-ignore no-explicit-any
111+
const revisionId: string = await (trpcClient.apps as any).initiateCliRevision.mutate({
112+
org,
113+
app,
114+
production: prod,
115+
manifest,
116+
});
124117

125-
const { revisionId }: { revisionId: string } = await initiatedBuildRes.json();
118+
console.log(revisionId);
126119

127120
const missingHashesPromise = Promise.withResolvers<string[]>();
128121

129-
const trpcClient = createTrpcClient(deployUrl);
130-
131122
// deno-lint-ignore no-explicit-any
132123
const sub = await (trpcClient.revisions as any).watchUntilReady.subscribe({
133124
org,

0 commit comments

Comments
 (0)