@capgo/cli 5.0.0-alpha.3 → 5.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +139 -5
- package/README.md +4 -0
- package/bun.lockb +0 -0
- package/dist/index.js +31453 -807
- package/package.json +2 -1
- package/src/api/channels.ts +2 -4
- package/src/api/versions.ts +14 -11
- package/src/app/add.ts +43 -6
- package/src/app/debug.ts +9 -3
- package/src/app/delete.ts +44 -6
- package/src/app/list.ts +4 -0
- package/src/app/set.ts +4 -4
- package/src/bundle/cleanup.ts +5 -6
- package/src/bundle/compatibility.ts +3 -3
- package/src/bundle/delete.ts +3 -3
- package/src/bundle/list.ts +3 -3
- package/src/bundle/unlink.ts +13 -7
- package/src/bundle/upload.ts +105 -23
- package/src/bundle/zip.ts +11 -9
- package/src/channel/add.ts +4 -4
- package/src/channel/currentBundle.ts +4 -5
- package/src/channel/delete.ts +3 -3
- package/src/channel/list.ts +3 -3
- package/src/channel/set.ts +7 -4
- package/src/index.ts +12 -7
- package/src/types/supabase.types.ts +589 -183
- package/src/utils.ts +36 -17
package/src/utils.ts
CHANGED
|
@@ -18,6 +18,7 @@ export const baseKeyPub = `${baseKey}.pub`
|
|
|
18
18
|
export const defaultHost = 'https://capgo.app'
|
|
19
19
|
export const defaultApiHost = 'https://api.capgo.app'
|
|
20
20
|
export const defaultHostWeb = 'https://web.capgo.app'
|
|
21
|
+
export const EMPTY_UUID = '00000000-0000-0000-0000-000000000000'
|
|
21
22
|
|
|
22
23
|
export const regexSemver = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
|
|
23
24
|
export const formatError = (error: any) => error ? `\n${prettyjson.render(error)}` : ''
|
|
@@ -133,23 +134,23 @@ export async function isGoodPlan(supabase: SupabaseClient<Database>, userId: str
|
|
|
133
134
|
return data || false
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
export async function
|
|
137
|
+
export async function isPayingOrg(supabase: SupabaseClient<Database>, orgId: string): Promise<boolean> {
|
|
137
138
|
const { data } = await supabase
|
|
138
|
-
.rpc('
|
|
139
|
+
.rpc('is_paying_org', { orgid: orgId })
|
|
139
140
|
.single()
|
|
140
141
|
return data || false
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
export async function
|
|
144
|
+
export async function isTrialOrg(supabase: SupabaseClient<Database>, orgId: string): Promise<number> {
|
|
144
145
|
const { data } = await supabase
|
|
145
|
-
.rpc('
|
|
146
|
+
.rpc('is_trial_org', { orgid: orgId })
|
|
146
147
|
.single()
|
|
147
148
|
return data || 0
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
export async function
|
|
151
|
+
export async function isAllowedActionOrg(supabase: SupabaseClient<Database>, orgId: string): Promise<boolean> {
|
|
151
152
|
const { data } = await supabase
|
|
152
|
-
.rpc('
|
|
153
|
+
.rpc('is_allowed_action_org', { orgid: orgId })
|
|
153
154
|
.single()
|
|
154
155
|
return !!data
|
|
155
156
|
}
|
|
@@ -192,7 +193,7 @@ export enum OrganizationPerm {
|
|
|
192
193
|
upload = 2,
|
|
193
194
|
write = 3,
|
|
194
195
|
admin = 4,
|
|
195
|
-
|
|
196
|
+
super_admin = 5,
|
|
196
197
|
}
|
|
197
198
|
|
|
198
199
|
export const hasOrganizationPerm = (perm: OrganizationPerm, required: OrganizationPerm): boolean => (perm as number) >= (required as number)
|
|
@@ -234,7 +235,7 @@ export async function isAllowedAppOrg(supabase: SupabaseClient<Database>, apikey
|
|
|
234
235
|
break
|
|
235
236
|
}
|
|
236
237
|
case 'perm_owner': {
|
|
237
|
-
perm = OrganizationPerm.
|
|
238
|
+
perm = OrganizationPerm.super_admin
|
|
238
239
|
break
|
|
239
240
|
}
|
|
240
241
|
default: {
|
|
@@ -282,10 +283,11 @@ export async function isAllowedAppOrg(supabase: SupabaseClient<Database>, apikey
|
|
|
282
283
|
}
|
|
283
284
|
}
|
|
284
285
|
|
|
285
|
-
export async function checkPlanValid(supabase: SupabaseClient<Database>,
|
|
286
|
+
export async function checkPlanValid(supabase: SupabaseClient<Database>, orgId: string, apikey: string, appId?: string, warning = true) {
|
|
286
287
|
const config = await getRemoteConfig()
|
|
287
288
|
|
|
288
|
-
|
|
289
|
+
// isAllowedActionAppIdApiKey was updated in the orgs_v3 migration to work with the new system
|
|
290
|
+
const validPlan = await (appId ? isAllowedActionAppIdApiKey(supabase, appId, apikey) : isAllowedActionOrg(supabase, orgId))
|
|
289
291
|
if (!validPlan) {
|
|
290
292
|
p.log.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${config.hostWeb}/dashboard/settings/plans\n`)
|
|
291
293
|
wait(100)
|
|
@@ -296,8 +298,10 @@ export async function checkPlanValid(supabase: SupabaseClient<Database>, userId:
|
|
|
296
298
|
wait(500)
|
|
297
299
|
program.error('')
|
|
298
300
|
}
|
|
299
|
-
const trialDays = await
|
|
300
|
-
|
|
301
|
+
const [trialDays, ispaying] = await Promise.all([
|
|
302
|
+
isTrialOrg(supabase, orgId),
|
|
303
|
+
isPayingOrg(supabase, orgId),
|
|
304
|
+
])
|
|
301
305
|
if (trialDays > 0 && warning && !ispaying)
|
|
302
306
|
p.log.warn(`WARNING !!\nTrial expires in ${trialDays} days, upgrade here: ${config.hostWeb}/dashboard/settings/plans\n`)
|
|
303
307
|
}
|
|
@@ -427,10 +431,10 @@ export async function updateOrCreateVersion(supabase: SupabaseClient<Database>,
|
|
|
427
431
|
.eq('name', update.name)
|
|
428
432
|
}
|
|
429
433
|
|
|
430
|
-
export async function uploadUrl(supabase: SupabaseClient<Database>, appId: string,
|
|
434
|
+
export async function uploadUrl(supabase: SupabaseClient<Database>, appId: string, name: string): Promise<string> {
|
|
431
435
|
const data = {
|
|
432
436
|
app_id: appId,
|
|
433
|
-
|
|
437
|
+
name,
|
|
434
438
|
}
|
|
435
439
|
try {
|
|
436
440
|
const pathUploadLink = 'private/upload_link'
|
|
@@ -454,7 +458,7 @@ export async function updateOrCreateChannel(supabase: SupabaseClient<Database>,
|
|
|
454
458
|
.select('enable_progressive_deploy, secondaryVersionPercentage, secondVersion')
|
|
455
459
|
.eq('app_id', update.app_id)
|
|
456
460
|
.eq('name', update.name)
|
|
457
|
-
|
|
461
|
+
// .eq('created_by', update.created_by)
|
|
458
462
|
.single()
|
|
459
463
|
|
|
460
464
|
if (data && !error) {
|
|
@@ -480,7 +484,7 @@ export async function updateOrCreateChannel(supabase: SupabaseClient<Database>,
|
|
|
480
484
|
.update(update)
|
|
481
485
|
.eq('app_id', update.app_id)
|
|
482
486
|
.eq('name', update.name)
|
|
483
|
-
|
|
487
|
+
// .eq('created_by', update.created_by)
|
|
484
488
|
.select()
|
|
485
489
|
.single()
|
|
486
490
|
}
|
|
@@ -518,11 +522,26 @@ export async function verifyUser(supabase: SupabaseClient<Database>, apikey: str
|
|
|
518
522
|
return userId
|
|
519
523
|
}
|
|
520
524
|
|
|
521
|
-
export async function
|
|
525
|
+
export async function getOrganizationId(supabase: SupabaseClient<Database>, appId: string) {
|
|
526
|
+
const { data, error } = await supabase.from('apps')
|
|
527
|
+
.select('owner_org')
|
|
528
|
+
.eq('app_id', appId)
|
|
529
|
+
.single()
|
|
530
|
+
|
|
531
|
+
if (!data || error) {
|
|
532
|
+
p.log.error(`Cannot get organization id for app id ${appId}`)
|
|
533
|
+
formatError(error)
|
|
534
|
+
program.error('')
|
|
535
|
+
}
|
|
536
|
+
return data.owner_org
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export async function requireUpdateMetadata(supabase: SupabaseClient<Database>, channel: string, appId: string): Promise<boolean> {
|
|
522
540
|
const { data, error } = await supabase
|
|
523
541
|
.from('channels')
|
|
524
542
|
.select('disableAutoUpdate')
|
|
525
543
|
.eq('name', channel)
|
|
544
|
+
.eq('app_id', appId)
|
|
526
545
|
.limit(1)
|
|
527
546
|
|
|
528
547
|
if (error) {
|