-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathdelete.ts
More file actions
66 lines (54 loc) · 2.34 KB
/
delete.ts
File metadata and controls
66 lines (54 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { BundleDeleteOptions } from '../schemas/bundle'
import { intro, log, outro } from '@clack/prompts'
import { check2FAComplianceForApp, checkAppExistsAndHasPermissionOrgErr } from '../api/app'
import { deleteSpecificVersion } from '../api/versions'
import { createSupabaseClient, findSavedKey, getAppId, getConfig, getOrganizationId, OrganizationPerm, resolveUserIdFromApiKey, sendEvent } from '../utils'
export async function deleteBundleInternal(bundleId: string, appId: string, options: BundleDeleteOptions, silent = false) {
if (!silent)
intro('Delete bundle')
options.apikey = options.apikey || findSavedKey()
const extConfig = await getConfig()
appId = getAppId(appId, extConfig?.config)
if (!options.apikey) {
if (!silent)
log.error('Missing API key, you need to provide an API key to upload your bundle')
throw new Error('Missing API key')
}
if (!appId) {
if (!silent)
log.error('Missing argument, you need to provide a appId, or be in a capacitor project')
throw new Error('Missing appId')
}
if (!bundleId) {
if (!silent)
log.error('Missing argument, you need to provide a bundleId, or be in a capacitor project')
throw new Error('Missing bundleId')
}
const supabase = await createSupabaseClient(options.apikey, options.supaHost, options.supaAnon)
await check2FAComplianceForApp(supabase, appId, silent)
await resolveUserIdFromApiKey(supabase, options.apikey)
await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appId, OrganizationPerm.write, silent, true)
if (!silent) {
log.info(`Deleting bundle ${appId}@${bundleId} from Capgo`)
log.info(`Keep in mind that you will not be able to reuse this bundle version, it's gone forever`)
}
await deleteSpecificVersion(supabase, appId, bundleId)
const orgId = await getOrganizationId(supabase, appId)
await sendEvent(options.apikey, {
channel: 'app',
event: 'Bundle Deleted',
icon: '🗑️',
user_id: orgId,
tags: { 'app-id': appId, 'bundle': bundleId },
notify: false,
notifyConsole: true,
}).catch(() => {})
if (!silent) {
log.success(`Bundle ${appId}@${bundleId} deleted in Capgo`)
outro('Done')
}
return true
}
export async function deleteBundle(bundleId: string, appId: string, options: BundleDeleteOptions) {
return deleteBundleInternal(bundleId, appId, options)
}