@capgo/cli 4.2.12 → 4.3.2
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 +11 -0
- package/README.md +4 -0
- package/bun.lockb +0 -0
- package/dist/index.js +31308 -712
- package/package.json +2 -1
- package/src/app/add.ts +2 -2
- package/src/bundle/unlink.ts +7 -2
- package/src/bundle/upload.ts +75 -4
- package/src/channel/set.ts +3 -1
- package/src/index.ts +4 -0
- package/src/types/supabase.types.ts +381 -361
- package/src/utils.ts +27 -10
package/src/utils.ts
CHANGED
|
@@ -134,23 +134,23 @@ export async function isGoodPlan(supabase: SupabaseClient<Database>, userId: str
|
|
|
134
134
|
return data || false
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
export async function
|
|
137
|
+
export async function isPayingOrg(supabase: SupabaseClient<Database>, orgId: string): Promise<boolean> {
|
|
138
138
|
const { data } = await supabase
|
|
139
|
-
.rpc('
|
|
139
|
+
.rpc('is_paying_org', { orgid: orgId })
|
|
140
140
|
.single()
|
|
141
141
|
return data || false
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
export async function
|
|
144
|
+
export async function isTrialOrg(supabase: SupabaseClient<Database>, orgId: string): Promise<number> {
|
|
145
145
|
const { data } = await supabase
|
|
146
|
-
.rpc('
|
|
146
|
+
.rpc('is_trial_org', { orgid: orgId })
|
|
147
147
|
.single()
|
|
148
148
|
return data || 0
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
export async function
|
|
151
|
+
export async function isAllowedActionOrg(supabase: SupabaseClient<Database>, orgId: string): Promise<boolean> {
|
|
152
152
|
const { data } = await supabase
|
|
153
|
-
.rpc('
|
|
153
|
+
.rpc('is_allowed_action_org', { orgid: orgId })
|
|
154
154
|
.single()
|
|
155
155
|
return !!data
|
|
156
156
|
}
|
|
@@ -283,10 +283,11 @@ export async function isAllowedAppOrg(supabase: SupabaseClient<Database>, apikey
|
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
export async function checkPlanValid(supabase: SupabaseClient<Database>,
|
|
286
|
+
export async function checkPlanValid(supabase: SupabaseClient<Database>, orgId: string, apikey: string, appId?: string, warning = true) {
|
|
287
287
|
const config = await getRemoteConfig()
|
|
288
288
|
|
|
289
|
-
|
|
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))
|
|
290
291
|
if (!validPlan) {
|
|
291
292
|
p.log.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${config.hostWeb}/dashboard/settings/plans\n`)
|
|
292
293
|
wait(100)
|
|
@@ -297,8 +298,10 @@ export async function checkPlanValid(supabase: SupabaseClient<Database>, userId:
|
|
|
297
298
|
wait(500)
|
|
298
299
|
program.error('')
|
|
299
300
|
}
|
|
300
|
-
const trialDays = await
|
|
301
|
-
|
|
301
|
+
const [trialDays, ispaying] = await Promise.all([
|
|
302
|
+
isTrialOrg(supabase, orgId),
|
|
303
|
+
isPayingOrg(supabase, orgId),
|
|
304
|
+
])
|
|
302
305
|
if (trialDays > 0 && warning && !ispaying)
|
|
303
306
|
p.log.warn(`WARNING !!\nTrial expires in ${trialDays} days, upgrade here: ${config.hostWeb}/dashboard/settings/plans\n`)
|
|
304
307
|
}
|
|
@@ -498,6 +501,20 @@ export async function verifyUser(supabase: SupabaseClient<Database>, apikey: str
|
|
|
498
501
|
return userId
|
|
499
502
|
}
|
|
500
503
|
|
|
504
|
+
export async function getOrganizationId(supabase: SupabaseClient<Database>, appId: string) {
|
|
505
|
+
const { data, error } = await supabase.from('apps')
|
|
506
|
+
.select('owner_org')
|
|
507
|
+
.eq('app_id', appId)
|
|
508
|
+
.single()
|
|
509
|
+
|
|
510
|
+
if (!data || error) {
|
|
511
|
+
p.log.error(`Cannot get organization id for app id ${appId}`)
|
|
512
|
+
formatError(error)
|
|
513
|
+
program.error('')
|
|
514
|
+
}
|
|
515
|
+
return data.owner_org
|
|
516
|
+
}
|
|
517
|
+
|
|
501
518
|
export async function requireUpdateMetadata(supabase: SupabaseClient<Database>, channel: string, appId: string): Promise<boolean> {
|
|
502
519
|
const { data, error } = await supabase
|
|
503
520
|
.from('channels')
|