Skip to content

Commit 1cf6892

Browse files
committed
fixes & CI
1 parent 267a33c commit 1cf6892

10 files changed

Lines changed: 225 additions & 108 deletions

File tree

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: ci
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
deno:
7+
if: |
8+
github.event_name == 'push' ||
9+
!startsWith(github.event.pull_request.head.label, 'denoland:')
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 30
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
submodules: true
17+
18+
- uses: denoland/setup-deno@v2
19+
20+
- name: fmt
21+
run: deno fmt --check
22+
23+
- name: lint
24+
run: deno lint
25+
26+
- name: check
27+
run: deno check
28+
29+
jsr:
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
id-token: write
34+
steps:
35+
- uses: actions/checkout@v4
36+
with:
37+
submodules: true
38+
- uses: denoland/setup-deno@v2
39+
- name: Publish to JSR on tag
40+
run: deno run -A jsr:@david/publish-on-tag@0.2.0

auth.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
createTRPCClient,
88
httpBatchStreamLink,
99
httpSubscriptionLink,
10+
retryLink,
1011
splitLink,
1112
} from "@trpc/client";
1213
import { Spinner } from "@std/cli/unstable-spinner";
@@ -15,7 +16,7 @@ import token_storage from "./token_storage.ts";
1516
import { EventSourcePolyfill } from "event-source-polyfill";
1617

1718
export function createTrpcClient(deployUrl: string) {
18-
const storedAuth = token_storage.get();
19+
let storedAuth = token_storage.get();
1920

2021
const transformer: TRPCCombinedDataTransformer = {
2122
input: {
@@ -28,15 +29,37 @@ export function createTrpcClient(deployUrl: string) {
2829
},
2930
};
3031

32+
let retryPromise: Promise<void> | undefined = undefined;
33+
3134
// deno-lint-ignore no-explicit-any
3235
return createTRPCClient<any>({
3336
links: [
37+
retryLink({
38+
retry() {
39+
// TODO: check its an auth error
40+
41+
if (typeof retryPromise !== "undefined") {
42+
return false;
43+
}
44+
45+
token_storage.remove();
46+
retryPromise = getAuth(deployUrl).then((auth) => {
47+
storedAuth = auth;
48+
});
49+
return true;
50+
},
51+
}),
3452
splitLink({
3553
// uses the httpSubscriptionLink for subscriptions
3654
condition: (op) => op.type === "subscription",
3755
false: httpBatchStreamLink({
3856
url: deployUrl + "/api",
39-
headers() {
57+
async headers() {
58+
if (retryPromise) {
59+
await retryPromise;
60+
retryPromise = undefined;
61+
}
62+
4063
if (storedAuth) {
4164
return {
4265
cookie: `token=${storedAuth}; deno_auth_ghid=force`,
@@ -50,7 +73,12 @@ export function createTrpcClient(deployUrl: string) {
5073
true: httpSubscriptionLink({
5174
url: deployUrl + "/api",
5275
EventSource: EventSourcePolyfill,
53-
eventSourceOptions: () => {
76+
async eventSourceOptions() {
77+
if (retryPromise) {
78+
await retryPromise;
79+
retryPromise = undefined;
80+
}
81+
5482
if (storedAuth) {
5583
return {
5684
headers: {
@@ -169,7 +197,6 @@ export async function authedFetch(
169197

170198
if (!auth) {
171199
auth = await getAuth(deployUrl);
172-
token_storage.set(auth);
173200
}
174201

175202
const headers = new Headers(init.headers);
@@ -196,7 +223,6 @@ export async function authedFetch(
196223
if (res.status === 401) {
197224
token_storage.remove();
198225
auth = await getAuth(deployUrl);
199-
token_storage.set(auth);
200226

201227
const headers = new Headers(init.headers);
202228
headers.set(
@@ -220,7 +246,6 @@ export async function authedFetch(
220246
} catch {
221247
token_storage.remove();
222248
auth = await getAuth(deployUrl);
223-
token_storage.set(auth);
224249

225250
const headers = new Headers(init.headers);
226251
headers.set(

deno.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"name": "@deno/deploy",
3-
"version": "0.0.23",
3+
"version": "0.0.25",
44
"license": "MIT",
55
"exports": "./main.ts",
66
"imports": {
77
"@cfa/gitignore-parser": "jsr:@cfa/gitignore-parser@^0.1.4",
88
"@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.8",
9-
"@std/cli": "jsr:@std/cli@1.0.15",
9+
"@std/cli": "jsr:@std/cli@1.0.21",
1010
"@std/encoding": "jsr:@std/encoding@^1.0.8",
1111
"@std/fmt": "jsr:@std/fmt@^1.0.8",
1212
"@std/fs": "jsr:@std/fs@^1.0.14",
1313
"@std/jsonc": "jsr:@std/jsonc@^1.0.1",
1414
"@std/path": "jsr:@std/path@^1.0.8",
15+
"@std/semver": "jsr:@std/semver@^1.0.5",
1516
"@std/tar": "jsr:@std/tar@^0.1.6",
1617
"@trpc/client": "npm:@trpc/client@^11.0.2",
1718
"@trpc/server": "npm:@trpc/server@^11.0.2",

deno.lock

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

env.ts

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ import { getAppFromConfig, readConfig } from "./config.ts";
33
import { withApp } from "./util.ts";
44
import { createTrpcClient } from "./auth.ts";
55

6+
interface EnvVar {
7+
id: string;
8+
key: string;
9+
value: string;
10+
context_ids: string[];
11+
}
12+
13+
interface Context {
14+
id: string;
15+
name: string;
16+
}
17+
618
type EnvCommandContext = {
719
endpoint: string;
820
org?: string;
@@ -20,12 +32,16 @@ export const envListCommand = new Command<EnvCommandContext>()
2032
const orgAndApp = await withApp(options.endpoint, false, org, app);
2133
const trpcClient = createTrpcClient(options.endpoint);
2234

23-
const envVars = await (trpcClient.envVarsContexts as any).list.query({
24-
org: orgAndApp.org,
25-
app: orgAndApp.app,
26-
});
35+
// deno-lint-ignore no-explicit-any
36+
const envVars: EnvVar[] = await (trpcClient.envVarsContexts as any).list
37+
.query({
38+
org: orgAndApp.org,
39+
app: orgAndApp.app,
40+
});
2741

28-
const contexts = await (trpcClient.envVarsContexts as any).listContexts
42+
// deno-lint-ignore no-explicit-any
43+
const contexts: Context[] = await (trpcClient.envVarsContexts as any)
44+
.listContexts
2945
.query({
3046
org: orgAndApp.org,
3147
});
@@ -90,11 +106,13 @@ export const envAddCommand = new Command<EnvCommandContext>()
90106
const orgAndApp = await withApp(options.endpoint, false, org, app);
91107
const trpcClient = createTrpcClient(options.endpoint);
92108

109+
// deno-lint-ignore no-explicit-any
93110
const fullApp = await (trpcClient.apps as any).get.query({
94111
org: orgAndApp.org,
95112
app: orgAndApp.app,
96113
});
97114

115+
// deno-lint-ignore no-explicit-any
98116
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
99117
org: orgAndApp.org,
100118
add: [
@@ -125,19 +143,20 @@ export const envUpdateValueCommand = new Command<EnvCommandContext>()
125143
const orgAndApp = await withApp(options.endpoint, false, org, app);
126144
const trpcClient = createTrpcClient(options.endpoint);
127145

128-
const envVars = await (trpcClient.envVarsContexts as any).list.query({
129-
org: orgAndApp.org,
130-
app: orgAndApp.app,
131-
});
146+
// deno-lint-ignore no-explicit-any
147+
const envVars: EnvVar[] = await (trpcClient.envVarsContexts as any).list
148+
.query({
149+
org: orgAndApp.org,
150+
app: orgAndApp.app,
151+
});
132152

133153
const envVar = envVars.find((envVar) => envVar.key === variable);
134154

135155
if (!envVar) {
136156
throw new Error(`Environment variable "${variable}" not found`);
137157
}
138158

139-
console.log(options.secret);
140-
159+
// deno-lint-ignore no-explicit-any
141160
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
142161
org: orgAndApp.org,
143162
add: [],
@@ -164,18 +183,22 @@ You can define no contexts and it will set the value to "All"`,
164183
const orgAndApp = await withApp(options.endpoint, false, org, app);
165184
const trpcClient = createTrpcClient(options.endpoint);
166185

167-
const envVars = await (trpcClient.envVarsContexts as any).list.query({
168-
org: orgAndApp.org,
169-
app: orgAndApp.app,
170-
});
186+
// deno-lint-ignore no-explicit-any
187+
const envVars: EnvVar[] = await (trpcClient.envVarsContexts as any).list
188+
.query({
189+
org: orgAndApp.org,
190+
app: orgAndApp.app,
191+
});
171192

172193
const envVar = envVars.find((envVar) => envVar.key === variable);
173194

174195
if (!envVar) {
175196
throw new Error(`Environment variable "${variable}" not found`);
176197
}
177198

178-
const contexts = await (trpcClient.envVarsContexts as any).listContexts
199+
// deno-lint-ignore no-explicit-any
200+
const contexts: Context[] = await (trpcClient.envVarsContexts as any)
201+
.listContexts
179202
.query({
180203
org: orgAndApp.org,
181204
});
@@ -191,6 +214,7 @@ You can define no contexts and it will set the value to "All"`,
191214
contextIds.push(context.id);
192215
}
193216

217+
// deno-lint-ignore no-explicit-any
194218
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
195219
org: orgAndApp.org,
196220
add: [],
@@ -214,17 +238,20 @@ export const envDeleteCommand = new Command<EnvCommandContext>()
214238
const orgAndApp = await withApp(options.endpoint, false, org, app);
215239
const trpcClient = createTrpcClient(options.endpoint);
216240

217-
const envVars = await (trpcClient.envVarsContexts as any).list.query({
218-
org: orgAndApp.org,
219-
app: orgAndApp.app,
220-
});
241+
// deno-lint-ignore no-explicit-any
242+
const envVars: EnvVar[] = await (trpcClient.envVarsContexts as any).list
243+
.query({
244+
org: orgAndApp.org,
245+
app: orgAndApp.app,
246+
});
221247

222248
const envVar = envVars.find((envVar) => envVar.key === variable);
223249

224250
if (!envVar) {
225251
throw new Error(`Environment variable "${variable}" not found`);
226252
}
227253

254+
// deno-lint-ignore no-explicit-any
228255
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
229256
org: orgAndApp.org,
230257
add: [],

0 commit comments

Comments
 (0)