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'
4
6
import { SUPABASE_FUNCTIONS_URL } from '../constants.ts'
5
7
import { Arkive , Deployment } from '../../src/arkiver/types.ts'
6
8
import { formatDistanceToNow } from 'npm:date-fns'
9
+ import { spinner } from '../spinner.ts'
7
10
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' > [ ]
13
13
// deno-lint-ignore ban-types
14
14
environment : 'staging' | 'prod' | string & { }
15
+ username : string
15
16
}
16
17
17
18
export const action = async ( options : {
@@ -22,34 +23,23 @@ export const action = async (options: {
22
23
23
24
if ( dev ) return listDev ( )
24
25
25
- let spinner = wait ( 'Fetching your arkives...' ) . start ( )
26
+ spinner ( 'Fetching your arkives...' )
26
27
27
28
try {
28
29
// 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 ( )
37
31
38
32
const userRes = await supabase . auth . getUser ( )
39
33
if ( userRes . error ) {
40
34
throw userRes . error
41
35
}
42
36
43
- if ( ! sessionRes . data . session ) {
44
- throw new Error ( 'Not logged in' )
45
- }
46
-
47
37
const username = await getUsername ( userRes . data . user . id )
48
38
49
39
const headers = new Headers ( )
50
40
headers . append (
51
41
'Authorization' ,
52
- `Bearer ${ sessionRes . data . session . access_token } ` ,
42
+ `Bearer ${ session . access_token } ` ,
53
43
)
54
44
55
45
const listRes = await fetch (
@@ -64,23 +54,25 @@ export const action = async (options: {
64
54
throw new Error ( await listRes . text ( ) )
65
55
}
66
56
67
- spinner . stop ( )
57
+ spinner ( ) . stop ( )
68
58
69
59
const rawArkives = await listRes . json ( )
70
60
61
+ console . log ( rawArkives )
62
+
71
63
if ( options . all ) {
72
64
const arkives = ( rawArkives as RawArkive [ ] ) . flatMap ( ( arkive ) =>
73
65
arkive . deployments . map ( ( deployment ) => ( {
74
66
name : arkive . name ,
75
67
deployed : `${
76
68
formatDistanceToNow (
77
- new Date ( deployment . deployment_created_at ) ,
69
+ new Date ( deployment . created_at ) ,
78
70
)
79
71
} ago`,
80
72
version : `${ deployment . major_version } .${ deployment . minor_version } ` ,
81
73
status : deployment . status ,
82
74
arkive_id : arkive . id ,
83
- deployment_id : deployment . deployment_id . toString ( ) ,
75
+ deployment_id : deployment . id . toString ( ) ,
84
76
} ) ) . filter ( ( deployment ) =>
85
77
options . status ? deployment . status === options . status : true
86
78
)
@@ -91,14 +83,14 @@ export const action = async (options: {
91
83
} else {
92
84
const arkives = ( rawArkives as RawArkive [ ] ) . map ( ( arkive ) => {
93
85
const latestDeployment = arkive . deployments . sort ( ( a , b ) =>
94
- a . deployment_id - b . deployment_id
86
+ a . id - b . id
95
87
) [ 0 ]
96
88
97
89
return {
98
90
name : arkive . name ,
99
91
deployed : `${
100
92
formatDistanceToNow (
101
- new Date ( latestDeployment . deployment_created_at ) ,
93
+ new Date ( latestDeployment . created_at ) ,
102
94
)
103
95
} ago`,
104
96
version :
@@ -119,7 +111,7 @@ export const action = async (options: {
119
111
console . table ( arkives )
120
112
}
121
113
} catch ( error ) {
122
- spinner . fail ( 'Listing arkives failed: ' + error . message )
114
+ spinner ( ) . fail ( 'Listing arkives failed: ' + error . message )
123
115
return
124
116
}
125
117
}
0 commit comments