Skip to content

Commit 90a06c6

Browse files
Merge pull request #16 from RoboVault/fix/manifest-validator
Fix/manifest-validator
2 parents a69df5b + 8bb1698 commit 90a06c6

File tree

7 files changed

+141
-65
lines changed

7 files changed

+141
-65
lines changed

cli/deploy/upload.ts

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getSupabaseClient } from '../utils.ts'
2-
import { login } from '../login/mod.ts'
1+
import { getSupabaseClientAndLogin } from '../utils.ts'
32
import { SUPABASE_FUNCTIONS_URL } from '../constants.ts'
43
import { ArkiveManifest, JSONBigIntReplacer } from '../../mod.ts'
54
import { spinner } from '../spinner.ts'
@@ -11,17 +10,7 @@ export const upload = async (
1110
options: { public?: true; major?: true; env?: string },
1211
) => {
1312
spinner().text = 'Uploading...'
14-
const supabase = getSupabaseClient()
15-
const sessionRes = await supabase.auth.getSession()
16-
17-
if (!sessionRes.data.session) {
18-
spinner().info('Not logged in, logging in now...')
19-
await login({}, supabase)
20-
}
21-
22-
if (!sessionRes.data.session) {
23-
throw new Error('Not logged in')
24-
}
13+
const { session } = await getSupabaseClientAndLogin()
2514

2615
const formData = new FormData()
2716
formData.append('name', manifest.name)
@@ -49,7 +38,7 @@ export const upload = async (
4938
const headers = new Headers()
5039
headers.append(
5140
'Authorization',
52-
`Bearer ${sessionRes.data.session.access_token}`,
41+
`Bearer ${session.access_token}`,
5342
)
5443
const res = await fetch(
5544
new URL('/arkives', SUPABASE_FUNCTIONS_URL),

cli/list/mod.ts

+20-28
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import { wait } from '../deps.ts'
2-
import { craftEndpoint, getSupabaseClient } from '../utils.ts'
3-
import { login } from '../login/mod.ts'
1+
import {
2+
craftEndpoint,
3+
getSupabaseClient,
4+
getSupabaseClientAndLogin,
5+
} from '../utils.ts'
46
import { SUPABASE_FUNCTIONS_URL } from '../constants.ts'
57
import { Arkive, Deployment } from '../../src/arkiver/types.ts'
68
import { formatDistanceToNow } from 'npm:date-fns'
9+
import { spinner } from '../spinner.ts'
710

8-
type RawArkive = Omit<Arkive, 'deployment'> & {
9-
deployments: (Omit<Deployment, 'created_at' | 'id'> & {
10-
deployment_created_at: string
11-
deployment_id: number
12-
})[]
11+
type RawArkive = Omit<Arkive, 'deployment' | 'created_at'> & {
12+
deployments: Omit<Deployment, 'arkive_id'>[]
1313
// deno-lint-ignore ban-types
1414
environment: 'staging' | 'prod' | string & {}
15+
username: string
1516
}
1617

1718
export const action = async (options: {
@@ -22,34 +23,23 @@ export const action = async (options: {
2223

2324
if (dev) return listDev()
2425

25-
let spinner = wait('Fetching your arkives...').start()
26+
spinner('Fetching your arkives...')
2627

2728
try {
2829
// delete package
29-
const supabase = getSupabaseClient()
30-
const sessionRes = await supabase.auth.getSession()
31-
32-
if (!sessionRes.data.session) {
33-
spinner.info('Not logged in, logging in now...')
34-
await login({}, supabase)
35-
spinner = wait('Fetching your arkives...').start()
36-
}
30+
const { supabase, session } = await getSupabaseClientAndLogin()
3731

3832
const userRes = await supabase.auth.getUser()
3933
if (userRes.error) {
4034
throw userRes.error
4135
}
4236

43-
if (!sessionRes.data.session) {
44-
throw new Error('Not logged in')
45-
}
46-
4737
const username = await getUsername(userRes.data.user.id)
4838

4939
const headers = new Headers()
5040
headers.append(
5141
'Authorization',
52-
`Bearer ${sessionRes.data.session.access_token}`,
42+
`Bearer ${session.access_token}`,
5343
)
5444

5545
const listRes = await fetch(
@@ -64,23 +54,25 @@ export const action = async (options: {
6454
throw new Error(await listRes.text())
6555
}
6656

67-
spinner.stop()
57+
spinner().stop()
6858

6959
const rawArkives = await listRes.json()
7060

61+
console.log(rawArkives)
62+
7163
if (options.all) {
7264
const arkives = (rawArkives as RawArkive[]).flatMap((arkive) =>
7365
arkive.deployments.map((deployment) => ({
7466
name: arkive.name,
7567
deployed: `${
7668
formatDistanceToNow(
77-
new Date(deployment.deployment_created_at),
69+
new Date(deployment.created_at),
7870
)
7971
} ago`,
8072
version: `${deployment.major_version}.${deployment.minor_version}`,
8173
status: deployment.status,
8274
arkive_id: arkive.id,
83-
deployment_id: deployment.deployment_id.toString(),
75+
deployment_id: deployment.id.toString(),
8476
})).filter((deployment) =>
8577
options.status ? deployment.status === options.status : true
8678
)
@@ -91,14 +83,14 @@ export const action = async (options: {
9183
} else {
9284
const arkives = (rawArkives as RawArkive[]).map((arkive) => {
9385
const latestDeployment = arkive.deployments.sort((a, b) =>
94-
a.deployment_id - b.deployment_id
86+
a.id - b.id
9587
)[0]
9688

9789
return {
9890
name: arkive.name,
9991
deployed: `${
10092
formatDistanceToNow(
101-
new Date(latestDeployment.deployment_created_at),
93+
new Date(latestDeployment.created_at),
10294
)
10395
} ago`,
10496
version:
@@ -119,7 +111,7 @@ export const action = async (options: {
119111
console.table(arkives)
120112
}
121113
} catch (error) {
122-
spinner.fail('Listing arkives failed: ' + error.message)
114+
spinner().fail('Listing arkives failed: ' + error.message)
123115
return
124116
}
125117
}

cli/utils.ts

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { SUPABASE_ANON_PUBLIC_KEY, SUPABASE_URL } from './constants.ts'
22
import { createClient, Input, Secret, z } from './deps.ts'
3+
import { login } from './login/mod.ts'
4+
import { spinner } from './spinner.ts'
35

46
export const getEmail = async () => {
57
const email = await Input.prompt('✉️ Email:')
@@ -57,6 +59,30 @@ export const getSupabaseClient = () => {
5759
})
5860
}
5961

62+
export const getSupabaseClientAndLogin = async () => {
63+
let supabase = getSupabaseClient()
64+
let sessionRes = await supabase.auth.getSession()
65+
if (!sessionRes.data.session) {
66+
await login({}, supabase)
67+
} else {
68+
return { supabase, session: sessionRes.data.session }
69+
}
70+
supabase = getSupabaseClient()
71+
sessionRes = await supabase.auth.getSession()
72+
73+
if (sessionRes.error) {
74+
spinner().fail(sessionRes.error.message)
75+
Deno.exit(1)
76+
}
77+
78+
if (!sessionRes.data.session) {
79+
spinner().fail('Not logged in')
80+
Deno.exit(1)
81+
}
82+
83+
return { supabase, session: sessionRes.data.session }
84+
}
85+
6086
export const logHeader = (version: string) => {
6187
const colors = ['#8be9fd', '#50fa7b', '#ffb86c', '#ff79c6', '#bd93f9']
6288

deno.lock

+37-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)