@capgo/cli 4.2.2-alpha.0 → 4.2.3

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/dist/index.js CHANGED
@@ -61137,7 +61137,7 @@ var {
61137
61137
  // package.json
61138
61138
  var package_default = {
61139
61139
  name: "@capgo/cli",
61140
- version: "4.2.2-alpha.0",
61140
+ version: "4.2.3",
61141
61141
  description: "A CLI to upload to capgo servers",
61142
61142
  main: "dist/index.js",
61143
61143
  bin: {
@@ -62312,6 +62312,11 @@ var defaultHostWeb = "https://web.capgo.app";
62312
62312
  var 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-]+)*))?$/;
62313
62313
  var formatError = (error) => error ? `
62314
62314
  ${import_prettyjson.default.render(error)}` : "";
62315
+ function wait(ms) {
62316
+ return new Promise((resolve2) => {
62317
+ setTimeout(resolve2, ms);
62318
+ });
62319
+ }
62315
62320
  async function getConfig() {
62316
62321
  let config;
62317
62322
  try {
@@ -62388,6 +62393,10 @@ async function isTrial(supabase, userId) {
62388
62393
  const { data } = await supabase.rpc("is_trial", { userid: userId }).single();
62389
62394
  return data || 0;
62390
62395
  }
62396
+ async function isAllowedAction(supabase, userId) {
62397
+ const { data } = await supabase.rpc("is_allowed_action_user", { userid: userId }).single();
62398
+ return !!data;
62399
+ }
62391
62400
  async function isAllowedActionAppIdApiKey(supabase, appId, apikey) {
62392
62401
  const { data } = await supabase.rpc("is_allowed_action", { apikey, appid: appId }).single();
62393
62402
  return !!data;
@@ -62489,19 +62498,19 @@ async function isAllowedAppOrg(supabase, apikey, appId) {
62489
62498
  error: functionError
62490
62499
  };
62491
62500
  }
62492
- async function checkPlanValid(supabase, userId, appId, apikey, warning = true) {
62501
+ async function checkPlanValid(supabase, userId, apikey, appId, warning = true) {
62493
62502
  const config = await getRemoteConfig();
62494
- const validPlan = await isAllowedActionAppIdApiKey(supabase, appId, apikey);
62503
+ const validPlan = await (appId ? isAllowedActionAppIdApiKey(supabase, appId, apikey) : isAllowedAction(supabase, userId));
62495
62504
  if (!validPlan) {
62496
62505
  f2.error(`You need to upgrade your plan to continue to use capgo.
62497
62506
  Upgrade here: ${config.hostWeb}/dashboard/settings/plans
62498
62507
  `);
62499
- setTimeout(() => {
62500
- Promise.resolve().then(() => (init_open(), open_exports)).then((module2) => {
62501
- module2.default(`${config.hostWeb}/dashboard/settings/plans`);
62502
- });
62503
- program.error("");
62504
- }, 1e3);
62508
+ wait(100);
62509
+ Promise.resolve().then(() => (init_open(), open_exports)).then((module2) => {
62510
+ module2.default(`${config.hostWeb}/dashboard/settings/plans`);
62511
+ });
62512
+ wait(500);
62513
+ program.error("");
62505
62514
  }
62506
62515
  const trialDays = await isTrial(supabase, userId);
62507
62516
  const ispaying = await isPaying(supabase, userId);
@@ -62979,11 +62988,6 @@ async function checkAppExistsAndHasPermissionOrgErr(supabase, apikey, appid, req
62979
62988
  var newIconPath = "assets/icon.png";
62980
62989
 
62981
62990
  // src/app/debug.ts
62982
- function wait(ms) {
62983
- return new Promise((resolve2) => {
62984
- setTimeout(resolve2, ms);
62985
- });
62986
- }
62987
62991
  async function markSnag(channel2, userId, snag, event, icon = "\u2705") {
62988
62992
  await snag.track({
62989
62993
  channel: channel2,
@@ -63504,7 +63508,7 @@ async function uploadBundle(appid, options, shouldExit = true) {
63504
63508
  const supabase = await createSupabaseClient(options.apikey);
63505
63509
  const userId = await verifyUser(supabase, options.apikey, ["write", "all", "upload"]);
63506
63510
  const permissions = await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appid, 2 /* upload */);
63507
- await checkPlanValid(supabase, userId, appid, options.apikey, false);
63511
+ await checkPlanValid(supabase, userId, options.apikey, appid, true);
63508
63512
  const updateMetadataRequired = await requireUpdateMetadata(supabase, channel2);
63509
63513
  const { data: channelData, error: channelError } = await supabase.from("channels").select("version ( minUpdateVersion, native_packages )").eq("name", channel2).eq("app_id", appid).single();
63510
63514
  let localDependencies = void 0;
@@ -63942,6 +63946,7 @@ async function addApp(appId, options, throwErr = true) {
63942
63946
  }
63943
63947
  const supabase = await createSupabaseClient(options.apikey);
63944
63948
  const userId = await verifyUser(supabase, options.apikey, ["write", "all"]);
63949
+ await checkPlanValid(supabase, userId, options.apikey, void 0, false);
63945
63950
  const appExist = await checkAppExists(supabase, appId);
63946
63951
  if (throwErr && appExist) {
63947
63952
  f2.error(`App ${appId} already exist`);
@@ -64620,7 +64625,7 @@ async function setChannel(channel2, appId, options) {
64620
64625
  program.error("");
64621
64626
  }
64622
64627
  try {
64623
- await checkPlanValid(supabase, userId, appId, options.apikey);
64628
+ await checkPlanValid(supabase, userId, options.apikey, appId);
64624
64629
  const channelPayload = {
64625
64630
  created_by: userId,
64626
64631
  app_id: appId,
@@ -64990,7 +64995,7 @@ async function setApp(appId, options) {
64990
64995
  contentType: iconType
64991
64996
  });
64992
64997
  if (error) {
64993
- f2.error(`Could not add app ${formatError(error)}`);
64998
+ f2.error(`Could not set app ${formatError(error)}`);
64994
64999
  program.error(``);
64995
65000
  }
64996
65001
  const { data: signedURLData } = await supabase.storage.from(`images/${userId}/${appId}`).getPublicUrl(fileName);
@@ -65002,7 +65007,7 @@ async function setApp(appId, options) {
65002
65007
  retention: !retention ? void 0 : retention * 24 * 60 * 60
65003
65008
  }).eq("app_id", appId).eq("user_id", userId);
65004
65009
  if (dbError) {
65005
- f2.error(`Could not add app ${formatError(dbError)}`);
65010
+ f2.error(`Could not set app ${formatError(dbError)}`);
65006
65011
  program.error(``);
65007
65012
  }
65008
65013
  $e(`Done \u2705`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "4.2.2-alpha.0",
3
+ "version": "4.2.3",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/app/add.ts CHANGED
@@ -8,6 +8,7 @@ import { checkLatest } from '../api/update'
8
8
  import type { Options } from '../api/app'
9
9
  import { checkAppExists, newIconPath } from '../api/app'
10
10
  import {
11
+ checkPlanValid,
11
12
  createSupabaseClient,
12
13
  findSavedKey,
13
14
  formatError,
@@ -37,6 +38,9 @@ export async function addApp(appId: string, options: Options, throwErr = true) {
37
38
  const supabase = await createSupabaseClient(options.apikey)
38
39
 
39
40
  const userId = await verifyUser(supabase, options.apikey, ['write', 'all'])
41
+
42
+ await checkPlanValid(supabase, userId, options.apikey, undefined, false)
43
+
40
44
  // Check we have app access to this appId
41
45
  const appExist = await checkAppExists(supabase, appId)
42
46
  if (throwErr && appExist) {
package/src/app/debug.ts CHANGED
@@ -6,13 +6,7 @@ import type LogSnag from 'logsnag'
6
6
  import type { Database } from '../types/supabase.types'
7
7
  import { checkAppExistsAndHasPermissionErr } from '../api/app'
8
8
  import { checkLatest } from '../api/update'
9
- import { convertAppName, createSupabaseClient, findSavedKey, formatError, getConfig, getLocalConfig, useLogSnag, verifyUser } from '../utils'
10
-
11
- function wait(ms: number) {
12
- return new Promise((resolve) => {
13
- setTimeout(resolve, ms)
14
- })
15
- }
9
+ import { convertAppName, createSupabaseClient, findSavedKey, formatError, getConfig, getLocalConfig, useLogSnag, verifyUser, wait } from '../utils'
16
10
 
17
11
  export interface OptionsBaseDebug {
18
12
  apikey: string
package/src/app/set.ts CHANGED
@@ -66,7 +66,7 @@ export async function setApp(appId: string, options: Options) {
66
66
  contentType: iconType,
67
67
  })
68
68
  if (error) {
69
- p.log.error(`Could not add app ${formatError(error)}`)
69
+ p.log.error(`Could not set app ${formatError(error)}`)
70
70
  program.error(``)
71
71
  }
72
72
  const { data: signedURLData } = await supabase
@@ -86,7 +86,7 @@ export async function setApp(appId: string, options: Options) {
86
86
  .eq('app_id', appId)
87
87
  .eq('user_id', userId)
88
88
  if (dbError) {
89
- p.log.error(`Could not add app ${formatError(dbError)}`)
89
+ p.log.error(`Could not set app ${formatError(dbError)}`)
90
90
  program.error(``)
91
91
  }
92
92
  p.outro(`Done ✅`)
@@ -55,7 +55,7 @@ export async function unlinkDevice(channel: string, appId: string, options: Opti
55
55
  program.error('')
56
56
  }
57
57
  try {
58
- await checkPlanValid(supabase, userId, appId, options.apikey)
58
+ await checkPlanValid(supabase, userId, options.apikey, appId)
59
59
 
60
60
  const versionData = await getVersionData(supabase, appId, userId, bundle)
61
61
  await checkVersionNotUsedInChannel(supabase, appId, userId, versionData)
@@ -118,7 +118,7 @@ export async function uploadBundle(appid: string, options: Options, shouldExit =
118
118
  // await checkAppExistsAndHasPermissionErr(supabase, options.apikey, appid);
119
119
 
120
120
  const permissions = await checkAppExistsAndHasPermissionOrgErr(supabase, options.apikey, appid, OrganizationPerm.upload)
121
- await checkPlanValid(supabase, userId, appid, options.apikey, false)
121
+ await checkPlanValid(supabase, userId, options.apikey, appid, true)
122
122
 
123
123
  const updateMetadataRequired = await requireUpdateMetadata(supabase, channel)
124
124
 
@@ -75,7 +75,7 @@ export async function setChannel(channel: string, appId: string, options: Option
75
75
  program.error('')
76
76
  }
77
77
  try {
78
- await checkPlanValid(supabase, userId, appId, options.apikey)
78
+ await checkPlanValid(supabase, userId, options.apikey, appId)
79
79
  const channelPayload: Database['public']['Tables']['channels']['Insert'] = {
80
80
  created_by: userId,
81
81
  app_id: appId,
@@ -1280,6 +1280,13 @@ export interface Database {
1280
1280
  count: number
1281
1281
  }[]
1282
1282
  }
1283
+ count_all_plans_v2: {
1284
+ Args: Record<PropertyKey, never>
1285
+ Returns: {
1286
+ plan_name: string
1287
+ count: number
1288
+ }[]
1289
+ }
1283
1290
  count_all_trial: {
1284
1291
  Args: Record<PropertyKey, never>
1285
1292
  Returns: number
@@ -1299,13 +1306,6 @@ export interface Database {
1299
1306
  Args: Record<PropertyKey, never>
1300
1307
  Returns: undefined
1301
1308
  }
1302
- exist_app: {
1303
- Args: {
1304
- appid: string
1305
- apikey: string
1306
- }
1307
- Returns: boolean
1308
- }
1309
1309
  exist_app_v2: {
1310
1310
  Args: {
1311
1311
  appid: string
@@ -1474,16 +1474,6 @@ export interface Database {
1474
1474
  }
1475
1475
  Returns: string
1476
1476
  }
1477
- get_orgs: {
1478
- Args: {
1479
- userid: string
1480
- }
1481
- Returns: {
1482
- id: string
1483
- logo: string
1484
- name: string
1485
- }[]
1486
- }
1487
1477
  get_orgs_v2: {
1488
1478
  Args: {
1489
1479
  userid: string
@@ -1512,17 +1502,12 @@ export interface Database {
1512
1502
  is_canceled: boolean
1513
1503
  }[]
1514
1504
  }
1515
- get_plan_usage_percent:
1516
- | {
1517
- Args: Record<PropertyKey, never>
1518
- Returns: number
1519
- }
1520
- | {
1521
- Args: {
1522
- userid: string
1523
- }
1524
- Returns: number
1505
+ get_plan_usage_percent: {
1506
+ Args: {
1507
+ userid: string
1525
1508
  }
1509
+ Returns: number
1510
+ }
1526
1511
  get_total_app_storage_size:
1527
1512
  | {
1528
1513
  Args: {
@@ -1537,57 +1522,6 @@ export interface Database {
1537
1522
  }
1538
1523
  Returns: number
1539
1524
  }
1540
- get_total_stats_v2:
1541
- | {
1542
- Args: {
1543
- dateid: string
1544
- }
1545
- Returns: {
1546
- mau: number
1547
- bandwidth: number
1548
- storage: number
1549
- }[]
1550
- }
1551
- | {
1552
- Args: {
1553
- userid: string
1554
- dateid: string
1555
- }
1556
- Returns: {
1557
- mau: number
1558
- bandwidth: number
1559
- storage: number
1560
- }[]
1561
- }
1562
- get_total_stats_v3:
1563
- | {
1564
- Args: Record<PropertyKey, never>
1565
- Returns: {
1566
- mau: number
1567
- bandwidth: number
1568
- storage: number
1569
- }[]
1570
- }
1571
- | {
1572
- Args: {
1573
- userid: string
1574
- }
1575
- Returns: {
1576
- mau: number
1577
- bandwidth: number
1578
- storage: number
1579
- }[]
1580
- }
1581
- get_total_stats_v4: {
1582
- Args: {
1583
- userid: string
1584
- }
1585
- Returns: {
1586
- mau: number
1587
- bandwidth: number
1588
- storage: number
1589
- }[]
1590
- }
1591
1525
  get_total_stats_v5: {
1592
1526
  Args: {
1593
1527
  userid: string
@@ -1827,28 +1761,18 @@ export interface Database {
1827
1761
  }
1828
1762
  Returns: boolean
1829
1763
  }
1830
- is_good_plan_v3:
1831
- | {
1832
- Args: Record<PropertyKey, never>
1833
- Returns: boolean
1834
- }
1835
- | {
1836
- Args: {
1837
- userid: string
1838
- }
1839
- Returns: boolean
1840
- }
1841
- is_good_plan_v4:
1842
- | {
1843
- Args: Record<PropertyKey, never>
1844
- Returns: boolean
1764
+ is_good_plan_v3: {
1765
+ Args: {
1766
+ userid: string
1845
1767
  }
1846
- | {
1847
- Args: {
1848
- userid: string
1849
- }
1850
- Returns: boolean
1768
+ Returns: boolean
1769
+ }
1770
+ is_good_plan_v5: {
1771
+ Args: {
1772
+ userid: string
1851
1773
  }
1774
+ Returns: boolean
1775
+ }
1852
1776
  is_member_of_org: {
1853
1777
  Args: {
1854
1778
  user_id: string
@@ -1862,12 +1786,6 @@ export interface Database {
1862
1786
  }
1863
1787
  Returns: boolean
1864
1788
  }
1865
- is_not_deleted_v2: {
1866
- Args: {
1867
- email_check: string
1868
- }
1869
- Returns: boolean
1870
- }
1871
1789
  is_onboarded:
1872
1790
  | {
1873
1791
  Args: Record<PropertyKey, never>
package/src/utils.ts CHANGED
@@ -26,6 +26,12 @@ export interface OptionsBase {
26
26
  apikey: string
27
27
  }
28
28
 
29
+ export function wait(ms: number) {
30
+ return new Promise((resolve) => {
31
+ setTimeout(resolve, ms)
32
+ })
33
+ }
34
+
29
35
  export async function getConfig() {
30
36
  let config: Config
31
37
  try {
@@ -276,18 +282,19 @@ export async function isAllowedAppOrg(supabase: SupabaseClient<Database>, apikey
276
282
  }
277
283
  }
278
284
 
279
- export async function checkPlanValid(supabase: SupabaseClient<Database>, userId: string, appId: string, apikey: string, warning = true) {
285
+ export async function checkPlanValid(supabase: SupabaseClient<Database>, userId: string, apikey: string, appId?: string, warning = true) {
280
286
  const config = await getRemoteConfig()
281
- const validPlan = await isAllowedActionAppIdApiKey(supabase, appId, apikey)
287
+
288
+ const validPlan = await (appId ? isAllowedActionAppIdApiKey(supabase, appId, apikey) : isAllowedAction(supabase, userId))
282
289
  if (!validPlan) {
283
290
  p.log.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${config.hostWeb}/dashboard/settings/plans\n`)
284
- setTimeout(() => {
285
- import('open')
286
- .then((module) => {
287
- module.default(`${config.hostWeb}/dashboard/settings/plans`)
288
- })
289
- program.error('')
290
- }, 1000)
291
+ wait(100)
292
+ import('open')
293
+ .then((module) => {
294
+ module.default(`${config.hostWeb}/dashboard/settings/plans`)
295
+ })
296
+ wait(500)
297
+ program.error('')
291
298
  }
292
299
  const trialDays = await isTrial(supabase, userId)
293
300
  const ispaying = await isPaying(supabase, userId)