@capgo/cli 1.1.0 → 1.1.8

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/.cz.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [tool.commitizen]
2
2
  name = "cz_conventional_commits"
3
3
  tag_format = "$major.$minor.$patch$prerelease"
4
- version = "1.1.0"
4
+ version = "1.1.8"
5
5
  version_files = [
6
6
  "package.json:version",
7
7
  ".cz.toml"
@@ -3,8 +3,8 @@ name: Build source code and send to Capgo
3
3
  on:
4
4
  push:
5
5
  tags:
6
- - '*'
7
-
6
+ - "*"
7
+
8
8
  jobs:
9
9
  deploy:
10
10
  runs-on: ubuntu-latest
@@ -14,10 +14,10 @@ jobs:
14
14
  uses: actions/checkout@v2
15
15
  - uses: pnpm/action-setup@v2.0.1
16
16
  with:
17
- version: 6.22.2
17
+ version: 7
18
18
  - name: Install dependencies
19
19
  id: install_code
20
- run: pnpm i
20
+ run: pnpm i
21
21
  - name: Lint
22
22
  id: lint_code
23
23
  run: pnpm lint
@@ -27,5 +27,3 @@ jobs:
27
27
  - uses: JS-DevTools/npm-publish@v1
28
28
  with:
29
29
  token: ${{ secrets.NPM_TOKEN }}
30
-
31
-
package/CHANGELOG.md CHANGED
@@ -1,3 +1,51 @@
1
+ ## 1.1.8 (2022-11-09)
2
+
3
+ ### Fix
4
+
5
+ - lock file
6
+
7
+ ## 1.1.7 (2022-11-09)
8
+
9
+ ### Fix
10
+
11
+ - pnpm version
12
+
13
+ ## 1.1.6 (2022-11-09)
14
+
15
+ ### Fix
16
+
17
+ - pnpm build
18
+
19
+ ## 1.1.5 (2022-11-09)
20
+
21
+ ### Fix
22
+
23
+ - build issue + update deps
24
+
25
+ ## 1.1.4 (2022-11-09)
26
+
27
+ ### Fix
28
+
29
+ - upgrade commander from 9.2.0 to 9.4.1
30
+
31
+ ## 1.1.3 (2022-11-09)
32
+
33
+ ### Fix
34
+
35
+ - upgrade cli-progress from 3.11.0 to 3.11.2
36
+
37
+ ## 1.1.2 (2022-11-07)
38
+
39
+ ### Fix
40
+
41
+ - update to new is_good_plan + use is_paying
42
+
43
+ ## 1.1.1 (2022-11-07)
44
+
45
+ ### Fix
46
+
47
+ - doc + require option
48
+
1
49
  ## 1.1.0 (2022-11-07)
2
50
 
3
51
  ### Feat
package/README.md CHANGED
@@ -34,6 +34,7 @@ Optionally you can give:
34
34
  - icon with `--path /path/to/my/dist/folder` to send your code to the cloud
35
35
  - name with `--name test` to have a custom name in the list
36
36
  - channel with `--channel prod` to link this version to channel
37
+
37
38
  ### Send version to Cloud channel
38
39
  `npx @capgo/cli set [appId] [version] [channel]`
39
40
  `[appId]` your app ID the format is explained [here](https://capacitorjs.com/docs/cli/init)
@@ -44,6 +45,23 @@ Optionally you can give:
44
45
  `npx @capgo/cli delete [appId]`
45
46
  `[appId]` your app ID present in the Cloud
46
47
 
48
+ ### Configure channel
49
+ `npx @capgo/cli set [appId] --channel dev
50
+ `
51
+ Optionally, you can give:
52
+ [appId] your app ID the format is explained here
53
+ --bundle your app bundle already sent to the cloud to
54
+ --state set the channel state, can be normal or default. To use in your app, one channel need to be "default".
55
+ --downgrade allow the channel to send downgrade version to devices.
56
+ --no-downgrade disallow the channel to send downgrade version to devices.
57
+ --upgrade allow the channel to send upgrade (major) version to devices.
58
+ --no-upgrade disallow the channel to send upgrade (major) version to devices.
59
+ --ios allow the channel to send version to iOS devices.
60
+ --no-ios disallow the channel to send version to iOS devices.
61
+ --android allow the channel to send version to android devices.
62
+ --no-android disallow the channel to send version to android devices.
63
+ --self-assign allow devices to self assign to this channel.
64
+ --no-self-assign disallow devices to self assign to this channel.
47
65
 
48
66
  ## Dev contribution
49
67
 
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- (()=>{"use strict";var e={548:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const t=r(304),a=r(113),i=r(147),s=r(470),p=r(11),d=r(233),l="assets/icon.png";o.addApp=(e,o)=>n(void 0,void 0,void 0,(function*(){var r,n;let{name:c,icon:u}=o;const g=o.apikey||(0,d.findSavedKey)(),f=yield(0,d.getConfig)(),v=(0,d.useLogSnag)();e=e||(null===(r=null==f?void 0:f.app)||void 0===r?void 0:r.appId),c=c||(null===(n=null==f?void 0:f.app)||void 0===n?void 0:n.appName)||"Unknown",u=u||"resources/icon.png",g||t.program.error("Missing API key, you need to provide a API key to add your app"),e&&c||t.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${e} to Capgo`);const m=(0,d.createSupabaseClient)(g),y=yield(0,d.verifyUser)(m,g,["write","all"]);let h,b;yield(0,d.checkPlan)(m,y),console.log("Adding..."),u&&(0,s.existsSync)(u)?(h=(0,i.readFileSync)(u),b=(0,p.getType)(u)||"image/png",console.warn(`Found app icon ${u}`)):(0,s.existsSync)(l)?(h=(0,i.readFileSync)(l),b=(0,p.getType)(l)||"image/png",console.warn(`Found app icon ${l}`)):console.warn(`Cannot find app icon in any of the following locations: ${u}, ${l}`);const{data:_,error:$}=yield m.rpc("exist_app",{appid:e,apikey:g});(_||$)&&t.program.error(`App already exists ${(0,d.formatError)($)}`);const w=`icon_${(0,a.randomUUID)()}`;let k="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(h&&b){const{error:o}=yield m.storage.from(`images/${y}/${e}`).upload(w,h,{contentType:b});o&&t.program.error(`Could not add app ${(0,d.formatError)(o)}`);const{data:r}=yield m.storage.from(`images/${y}/${e}`).getPublicUrl(w);k=(null==r?void 0:r.publicURL)||k}const{error:x}=yield m.from("apps").insert({icon_url:k,user_id:y,name:c,app_id:e},{returning:"minimal"});x&&t.program.error(`Could not add app ${(0,d.formatError)(x)}`);const{error:C}=yield m.from("app_versions").insert([{user_id:y,deleted:!0,name:"unknown",app_id:e},{user_id:y,deleted:!0,name:"builtin",app_id:e}],{returning:"minimal"});C&&t.program.error(`Could not add app ${(0,d.formatError)(C)}`),v.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":y,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now")}))},453:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const t=r(304),a=r(233);o.deleteApp=(e,o)=>n(void 0,void 0,void 0,(function*(){var r;const{bundle:n}=o,i=o.apikey||(0,a.findSavedKey)(),s=yield(0,a.getConfig)(),p=(0,a.useLogSnag)();e=e||(null===(r=null==s?void 0:s.app)||void 0===r?void 0:r.appId),i||t.program.error("Missing API key, you need to provide an API key to delete your app"),e||t.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const d=(0,a.createSupabaseClient)(i),l=yield(0,a.verifyUser)(d,i),{data:c,error:u}=yield d.rpc("exist_app",{appid:e,apikey:i});if(c&&!u||t.program.error("No permission to delete"),n){console.log(`Delete ${e}@${n} from Capgo`);const{data:o,error:r}=yield d.from("app_versions").select().eq("app_id",e).eq("user_id",l).eq("name",n).eq("deleted",!1).single();o&&!r||t.program.error(`Version ${e}@${n} doesn't exist ${(0,a.formatError)(r)}`);const{data:i,error:s}=yield d.from("channels").select().eq("app_id",e).eq("created_by",l).eq("version",o.id);(i&&i.length||s)&&t.program.error(`Version ${e}@${n} is used in a channel, unlink it first ${(0,a.formatError)(s)}`);const{data:p,error:c}=yield d.from("devices_override").select().eq("app_id",e).eq("version",o.id);(p&&p.length||c)&&t.program.error(`Version ${e} @${n} is used in a device override, unlink it first ${(0,a.formatError)(c)}`);const{error:u}=yield d.storage.from("apps").remove([`${l}/${e}/versions/${o.bucket_id} `]);u&&t.program.error(`Something went wrong when trying to delete ${e} @${n} ${u} `);const{error:g}=yield d.from("app_versions").update({deleted:!0}).eq("app_id",e).eq("user_id",l).eq("name",n);return g&&t.program.error(`App ${e}@${n} not found in database '${g}'`),void console.log(`${e}@${n} deleted from server`)}console.log(`Delete ${e} from Capgo`);const{data:g,error:f}=yield d.from("app_versions").select().eq("app_id",e).eq("user_id",l);if(f&&t.program.error(`App ${e} not found in database ${f} `),g&&g.length){const o=g.map((o=>`${l}/${e}/versions/${o.bucket_id} `)),{error:r}=yield d.storage.from("apps").remove(o);r&&t.program.error(`Cannot delete stored version for app ${e} from storage ${r} `)}const{error:v}=yield d.from("app_versions").delete().eq("app_id",e).eq("user_id",l);v&&t.program.error(`Cannot delete version for app ${e} from database ${v} `);const{error:m}=yield d.from("apps").delete().eq("app_id",e).eq("user_id",l);m&&t.program.error(`Cannot delete from database ${m} `),p.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":l,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`)}))},473:function(e,o,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0});const t=r(304),a=r(548),i=r(453),s=r(666),p=r(310),d=n(r(598)),l=r(937),c=r(546);t.program.version(d.default.version).command("add [appid]").alias("a").action(a.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),t.program.version(d.default.version).command("login [apikey]").alias("l").action(l.login).option("--local","Only save in local folder"),t.program.command("upload [appid]").alias("u").action(p.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the file to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to capgo cloud").option("-f, --format <base64|hex|binary|utf8>","choose the upload format default base64").option("-b, --bundle <bundle>","bundle version number of the file to upload"),t.program.command("set [appid]").alias("s").action(s.setChannel).option("-c, --channel <channel>","channel to link to").option("-b, --bundle <bundle>","bundle version number of the file to set").option("-s, --state <state>","set the state of the channel, default or normal").option("--downgrade","Allow to downgrade to version under native one").option("--no-downgrade","Disable downgrade to version under native one").option("--upgrade","Allow to upgrade to version above native one").option("--no-upgrade","Disable upgrade to version above native one").option("--ios","Allow sending update to ios devices").option("--no-ios","Disable sending update to ios devices").option("--android","Allow sending update to android devices").option("--no-android","Disable sending update to android devices").option("--self-assign","Allow to device to self assign to this channel").option("--no-self-assign","Disable devices to self assign to this channel").option("-a, --apikey <apikey>","apikey to link to your account"),t.program.description("Manage package and version in capgo Cloud").command("delete [appid]").alias("d").action(i.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the app to delete"),t.program.description("List versions in capgo Cloud").command("list [appid]").alias("ls").action(c.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),t.program.parse(process.argv)},546:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const t=r(304),a=r(233);o.listApp=(e,o)=>n(void 0,void 0,void 0,(function*(){var r;const n=o.apikey||(0,a.findSavedKey)(),i=yield(0,a.getConfig)();e=e||(null===(r=null==i?void 0:i.app)||void 0===r?void 0:r.appId),n||t.program.error("Missing API key, you need to provide an API key to delete your app"),e||t.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),console.log("Querying available versions in Capgo");const s=(0,a.createSupabaseClient)(n),p=yield(0,a.verifyUser)(s,n),{data:d,error:l}=yield s.rpc("exist_app",{appid:e,apikey:n});d&&!l||t.program.error("No permission for this app");const{data:c,error:u}=yield s.from("app_versions").select().eq("app_id",e).eq("user_id",p).eq("deleted",!1);console.log(`Active versions in Capgo: ${null==c?void 0:c.length}`),null==c||c.forEach((e=>{const o=new Date(e.created_at||"").toLocaleString();console.log(`${e.name} created on ${o}`)})),u&&t.program.error(`App ${e} not found in database ${u} `)}))},937:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.login=void 0;const a=r(304),i=t(r(147)),s=t(r(37)),p=r(233);o.login=(e,o)=>n(void 0,void 0,void 0,(function*(){const{local:r}=o,n=(0,p.useLogSnag)();if(r)i.default.existsSync(".git")||a.program.error("To use local you should be in a git repository"),i.default.writeFileSync(".capgo",`${e}\n`),i.default.appendFileSync(".gitignore",".capgo\n");else{const o=s.default.homedir();i.default.writeFileSync(`${o}/.capgo`,`${e}\n`)}const t=(0,p.createSupabaseClient)(e),d=yield(0,p.verifyUser)(t,e,["write","all","upload"]);n.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":d},notify:!1}).catch(),console.log(`login saved into .capgo file in ${r?"local":"home"} directory`)}))},666:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const t=r(304),a=r(233);o.setChannel=(e,o)=>n(void 0,void 0,void 0,(function*(){var r;const{bundle:n,downgrade:i,upgrade:s,ios:p,android:d,selfAssign:l,channel:c,state:u}=o,g=o.apikey||(0,a.findSavedKey)(),f=yield(0,a.getConfig)(),v=(0,a.useLogSnag)();e=e||(null===(r=null==f?void 0:f.app)||void 0===r?void 0:r.appId),g||t.program.error("Missing API key, you need to provide a API key to add your app"),e||t.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),c||t.program.error("Missing argument, you need to provide a channel"),void 0===n&&void 0===u&&void 0===i&&void 0===s&&void 0===p&&void 0===d&&void 0===l&&t.program.error("Missing argument, you need to provide a option to set");try{const o=(0,a.createSupabaseClient)(g),r=yield(0,a.verifyUser)(o,g,["write","all"]);yield(0,a.checkPlan)(o,r);const f={created_by:r,app_id:e,name:c};if(n){console.log(`Set ${e} channel: ${c} to @${n}`);const{data:a,error:i}=yield o.from("app_versions").select().eq("app_id",e).eq("name",n).eq("user_id",r).eq("deleted",!1);!i&&a&&a.length||t.program.error(`Cannot find version ${n}`),f.version=a[0].id}void 0!==u&&("public"!==u&&"private"!==u||console.log(`Set ${e} channel: ${c} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${c} to ${"public"===u||"default"===u?"default":"normal"}`),f.public="public"===u||"default"===u),void 0!==i&&(console.log(`Set ${e} channel: ${c} to ${i?"allow":"disallow"} downgrade`),f.disableAutoUpdateUnderNative=!i),void 0!==s&&(console.log(`Set ${e} channel: ${c} to ${s?"allow":"disallow"} upgrade`),f.disableAutoUpdateToMajor=!s),void 0!==p&&(console.log(`Set ${e} channel: ${c} to ${p?"allow":"disallow"} ios update`),f.ios=!!p),void 0!==d&&(console.log(`Set ${e} channel: ${c} to ${d?"allow":"disallow"} android update`),f.android=!!d),void 0!==l&&(console.log(`Set ${e} channel: ${c} to ${l?"allow":"disallow"} self assign to this channel`),f.allow_device_self_set=!!l);try{const{error:e}=yield(0,a.updateOrCreateChannel)(o,f,g);e&&t.program.error(`Cannot set channel ${(0,a.formatError)(e)}`)}catch(e){t.program.error(`Cannot set channel ${(0,a.formatError)(e)}`)}v.publish({channel:"app",event:"Set app",icon:"✅",tags:{"user-id":r,"app-id":e},notify:!1}).catch()}catch(e){t.program.error(`Unknow error ${(0,a.formatError)(e)}`)}console.log("Done ✅")}))},310:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadVersion=void 0;const a=t(r(844)),i=r(304),s=r(113),p=t(r(295)),d=r(906),l=r(233);o.uploadVersion=(e,o)=>n(void 0,void 0,void 0,(function*(){var r,n,t,c;let{bundle:u,path:g,channel:f}=o;const{external:v}=o,m=o.apikey||(0,l.findSavedKey)(),y=(0,l.useLogSnag)();f=f||"dev";const h=yield(0,l.getConfig)();e=e||(null===(r=null==h?void 0:h.app)||void 0===r?void 0:r.appId),u=u||(null===(t=null===(n=null==h?void 0:h.app)||void 0===n?void 0:n.package)||void 0===t?void 0:t.version),l.regexSemver.test(u)||i.program.error(`Your bundle name ${u}, is not valid it should follow semver convention : https://semver.org/`),g=g||(null===(c=null==h?void 0:h.app)||void 0===c?void 0:c.webDir),m||i.program.error("Missing API key, you need to provide a API key to add your app"),e&&u&&g||i.program.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),console.log(`Upload ${e}@${u} started from path "${g}" to Capgo cloud`);const b=(0,l.createSupabaseClient)(m),_=yield(0,l.verifyUser)(b,m,["write","all","upload"]);yield(0,l.checkPlan)(b,_,!1);const $=new p.default.MultiBar({clearOnComplete:!1,hideCursor:!0},p.default.Presets.shades_grey),w=$.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},p.default.Presets.shades_grey);w.start(7,0,{speed:"N/A"});const{data:k,error:x}=yield b.rpc("exist_app_versions",{apikey:m,name_version:u,appid:e});(k||x)&&($.stop(),i.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,l.formatError)(x)}`)),w.increment();const{data:C,error:A}=yield b.rpc("is_trial",{userid:_}).single();(C&&C>0||A)&&$.log(`WARNING !!\nTrial expires in ${C} days, upgrade here: ${l.hostWeb}/dashboard/settings/plans\n`),w.increment();const{data:S,error:q}=yield b.rpc("exist_app",{appid:e,apikey:m});S&&!q||($.stop(),i.program.error(`Cannot find app ${e} in your account \n${(0,l.formatError)(q)}`)),w.increment();const{data:P,error:I}=yield b.rpc("exist_app_versions",{appid:e,apikey:m,name_version:u});(P||I)&&i.program.error(`Version already exists ${(0,l.formatError)(I)}`),w.increment();const j=(0,s.randomUUID)();let M="";if(v)v&&!v.startsWith("https://")&&($.stop(),i.program.error(`External link should should start with "https://" current is "${v}"`));else{const o=new a.default;o.addLocalFolder(g);const r=o.toBuffer();M=yield(0,d.checksum)(r,"crc32");const n=Math.floor(r.byteLength/1024/1024),t=`apps/${_}/${e}/versions`;w.increment(),n>20&&($.log(`WARNING !!\nThe app size is ${n} Mb, this may take a while to download for users\n`),y.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":_,"app-id":e},notify:!1}).catch());const{error:s}=yield b.storage.from(t).upload(j,r,{contentType:"application/zip"});s&&($.stop(),i.program.error(`Cannot upload ${(0,l.formatError)(s)}`))}w.increment();const{data:U,error:E}=yield(0,l.updateOrCreateVersion)(b,{bucket_id:v?void 0:j,user_id:_,name:u,app_id:e,external_url:v,checksum:M},m);if(E&&($.stop(),i.program.error(`Cannot add bundle ${(0,l.formatError)(E)}`)),w.increment(),U&&U.length){const{error:o}=yield(0,l.updateOrCreateChannel)(b,{name:f,app_id:e,created_by:_,version:U[0].id},m);o&&$.log("Cannot set bundle with upload key, use key with more rights for that\n")}else $.log("Cannot set bundle with upload key, use key with more rights for that\n");$.stop();const O=e.replace(/\./g,"--");console.log("App uploaded to server"),console.log(`Try it in mobile app: ${l.host}/app_mobile`),console.log(`Or set the channel ${f} as public here: ${l.hostWeb}/app/package/${O}`),console.log("To use with live update in your own app"),console.log(`You can link specific device to this bundle to make user try it first, here: ${l.hostWeb}/app/p/${O}/devices`),y.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":_,"app-id":e},notify:!1}).catch()}))},233:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.verifyUser=o.useLogSnag=o.updateOrCreateChannel=o.updateOrCreateVersion=o.getConfig=o.formatError=o.findSavedKey=o.checkPlan=o.isTrial=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.supaAnon=o.hostSupa=o.hostWeb=o.host=void 0;const a=r(778),i=r(304),s=r(885),p=t(r(867)),d=t(r(147)),l=t(r(37)),c=r(133);o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostSupa="https://xvwzpoazmxkqosrdewyv.supabase.co",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w",o.createSupabaseClient=e=>(0,s.createClient)(o.hostSupa,o.supaAnon,{headers:{capgkey:e}}),o.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-]+)*))?$/,o.checkKey=(e,r,t)=>n(void 0,void 0,void 0,(function*(){const{data:n,error:a}=yield e.rpc("is_allowed_capgkey",{apikey:r,keymode:t});n&&!a||i.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(a)}`)})),o.isGoodPlan=(e,o)=>n(void 0,void 0,void 0,(function*(){const{data:r,error:n}=yield e.rpc("is_good_plan",{userid:o}).single();if(n)throw n;return r||!1})),o.isTrial=(e,o)=>n(void 0,void 0,void 0,(function*(){const{data:r,error:n}=yield e.rpc("is_trial",{userid:o}).single();if(n)throw n;return r||0})),o.checkPlan=(e,r,t=!0)=>n(void 0,void 0,void 0,(function*(){let n=yield(0,o.isGoodPlan)(e,r);const a=yield(0,o.isTrial)(e,r);a>0&&(n=!0),n||i.program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),a>0&&t&&console.log(`WARNING !!\nTrial expires in ${a} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e=`${l.default.homedir()}/.capgo`;return d.default.existsSync(e)?d.default.readFileSync(e,"utf8").trim():(e=".capgo",d.default.existsSync(e)?d.default.readFileSync(e,"utf8").trim():null)},o.formatError=e=>e?`\n${p.default.render(e)}`:"",o.getConfig=()=>n(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,a.loadConfig)()}catch(e){i.program.error("No capacitor config file found, run `cap init` first")}return e})),o.updateOrCreateVersion=(e,o,r)=>n(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("exist_app_versions",{appid:o.app_id,name_version:o.name,apikey:r});return n&&!t?(o.deleted=!1,e.from("app_versions").update(o).eq("app_id",o.app_id).eq("name",o.name)):e.from("app_versions").insert(o)})),o.updateOrCreateChannel=(e,o,r)=>n(void 0,void 0,void 0,(function*(){if(!o.app_id||!o.name||!o.created_by)return console.error("missing app_id, name, or created_by"),Promise.reject(new Error("missing app_id, name, or created_by"));const{data:n,error:t}=yield e.rpc("exist_channel",{appid:o.app_id,name_channel:o.name,apikey:r});return n&&!t?e.from("channels").update(o,{returning:"minimal"}).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by):e.from("channels").insert(o,{returning:"minimal"})})),o.useLogSnag=()=>new c.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.verifyUser=(e,r,t=["all"])=>n(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,r,t);const{data:n,error:a}=yield e.rpc("get_user_id",{apikey:r}),s=n?n.toString():"";return s&&!a||i.program.error(`Cannot verify user ${(0,o.formatError)(a)}`),s}))},778:e=>{e.exports=require("@capacitor/cli/dist/config")},885:e=>{e.exports=require("@supabase/supabase-js")},906:e=>{e.exports=require("@tomasklaen/checksum")},844:e=>{e.exports=require("adm-zip")},295:e=>{e.exports=require("cli-progress")},304:e=>{e.exports=require("commander")},470:e=>{e.exports=require("fs-extra")},133:e=>{e.exports=require("logsnag")},11:e=>{e.exports=require("mime")},867:e=>{e.exports=require("prettyjson")},113:e=>{e.exports=require("crypto")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},598:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"1.1.0","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"keywords":["appflow alternative","ionic","capacitor","auto update","live update","capgo","cli","upload","capgo-cli"],"scripts":{"dev":"set NODE_ENV=development && npx webpack --config webpack.config.js","no-debug":"node dist/index.js","build":"npx webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","test_rls":"ts-node ./test/test_headers_rls.ts","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"3.5.1","@supabase/supabase-js":"^1.35.3","@tomasklaen/checksum":"^1.1.0","adm-zip":"^0.5.9","cli-progress":"3.11.0","commander":"9.2.0","form-data":"^4.0.0","fs-extra":"10.1.0","logsnag":"^0.1.2","mime":"^3.0.0","node-stream-zip":"^1.15.0","prettyjson":"^1.2.5","upath":"^2.0.1"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/cli-progress":"^3.11.0","@types/fs-extra":"^9.0.13","@types/mime":"^2.0.3","@types/node":"^17.0.31","@types/prettyjson":"^0.0.30","@types/semver":"^7.3.10","@typescript-eslint/eslint-plugin":"5.22.0","@typescript-eslint/parser":"5.22.0","eslint":"8.14.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"2.7.1","eslint-plugin-import":"2.26.0","eslint-plugin-prettier":"^4.0.0","git-format-staged":"3.0.0","husky":"^7.0.4","nodemon":"2.0.16","pkg":"5.6.0","prettier":"2.6.2","ts-loader":"^9.3.0","ts-node":"^10.7.0","tsconfig-paths":"4.0.0","typescript":"4.6.4","webpack":"5.72.0","webpack-cli":"^4.9.2","webpack-node-externals":"^3.0.0"}}')}},o={};!function r(n){var t=o[n];if(void 0!==t)return t.exports;var a=o[n]={exports:{}};return e[n].call(a.exports,a,a.exports,r),a.exports}(473)})();
2
+ (()=>{"use strict";var e={107:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const t=r(304),a=r(113),i=r(147),s=r(470),p=r(11),d=r(771),l="assets/icon.png";o.addApp=(e,o)=>n(void 0,void 0,void 0,(function*(){var r,n;let{name:c,icon:u}=o;const g=o.apikey||(0,d.findSavedKey)(),f=yield(0,d.getConfig)(),v=(0,d.useLogSnag)();e=e||(null===(r=null==f?void 0:f.app)||void 0===r?void 0:r.appId),c=c||(null===(n=null==f?void 0:f.app)||void 0===n?void 0:n.appName)||"Unknown",u=u||"resources/icon.png",g||t.program.error("Missing API key, you need to provide a API key to add your app"),e&&c||t.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${e} to Capgo`);const y=(0,d.createSupabaseClient)(g),m=yield(0,d.verifyUser)(y,g,["write","all"]);let h,b;yield(0,d.checkPlan)(y,m),console.log("Adding..."),u&&(0,s.existsSync)(u)?(h=(0,i.readFileSync)(u),b=(0,p.getType)(u)||"image/png",console.warn(`Found app icon ${u}`)):(0,s.existsSync)(l)?(h=(0,i.readFileSync)(l),b=(0,p.getType)(l)||"image/png",console.warn(`Found app icon ${l}`)):console.warn(`Cannot find app icon in any of the following locations: ${u}, ${l}`);const{data:_,error:$}=yield y.rpc("exist_app",{appid:e,apikey:g});(_||$)&&t.program.error(`App already exists ${(0,d.formatError)($)}`);const w=`icon_${(0,a.randomUUID)()}`;let k="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(h&&b){const{error:o}=yield y.storage.from(`images/${m}/${e}`).upload(w,h,{contentType:b});o&&t.program.error(`Could not add app ${(0,d.formatError)(o)}`);const{data:r}=yield y.storage.from(`images/${m}/${e}`).getPublicUrl(w);k=(null==r?void 0:r.publicURL)||k}const{error:x}=yield y.from("apps").insert({icon_url:k,user_id:m,name:c,app_id:e},{returning:"minimal"});x&&t.program.error(`Could not add app ${(0,d.formatError)(x)}`);const{error:C}=yield y.from("app_versions").insert([{user_id:m,deleted:!0,name:"unknown",app_id:e},{user_id:m,deleted:!0,name:"builtin",app_id:e}],{returning:"minimal"});C&&t.program.error(`Could not add app ${(0,d.formatError)(C)}`),v.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":m,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now")}))},605:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const t=r(304),a=r(771);o.deleteApp=(e,o)=>n(void 0,void 0,void 0,(function*(){var r;const{bundle:n}=o,i=o.apikey||(0,a.findSavedKey)(),s=yield(0,a.getConfig)(),p=(0,a.useLogSnag)();e=e||(null===(r=null==s?void 0:s.app)||void 0===r?void 0:r.appId),i||t.program.error("Missing API key, you need to provide an API key to delete your app"),e||t.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const d=(0,a.createSupabaseClient)(i),l=yield(0,a.verifyUser)(d,i),{data:c,error:u}=yield d.rpc("exist_app",{appid:e,apikey:i});if(c&&!u||t.program.error("No permission to delete"),n){console.log(`Delete ${e}@${n} from Capgo`);const{data:o,error:r}=yield d.from("app_versions").select().eq("app_id",e).eq("user_id",l).eq("name",n).eq("deleted",!1).single();o&&!r||t.program.error(`Version ${e}@${n} doesn't exist ${(0,a.formatError)(r)}`);const{data:i,error:s}=yield d.from("channels").select().eq("app_id",e).eq("created_by",l).eq("version",o.id);(i&&i.length||s)&&t.program.error(`Version ${e}@${n} is used in a channel, unlink it first ${(0,a.formatError)(s)}`);const{data:p,error:c}=yield d.from("devices_override").select().eq("app_id",e).eq("version",o.id);(p&&p.length||c)&&t.program.error(`Version ${e} @${n} is used in a device override, unlink it first ${(0,a.formatError)(c)}`);const{error:u}=yield d.storage.from("apps").remove([`${l}/${e}/versions/${o.bucket_id} `]);u&&t.program.error(`Something went wrong when trying to delete ${e} @${n} ${u} `);const{error:g}=yield d.from("app_versions").update({deleted:!0}).eq("app_id",e).eq("user_id",l).eq("name",n);return g&&t.program.error(`App ${e}@${n} not found in database '${g}'`),void console.log(`${e}@${n} deleted from server`)}console.log(`Delete ${e} from Capgo`);const{data:g,error:f}=yield d.from("app_versions").select().eq("app_id",e).eq("user_id",l);if(f&&t.program.error(`App ${e} not found in database ${f} `),g&&g.length){const o=g.map((o=>`${l}/${e}/versions/${o.bucket_id} `)),{error:r}=yield d.storage.from("apps").remove(o);r&&t.program.error(`Cannot delete stored version for app ${e} from storage ${r} `)}const{error:v}=yield d.from("app_versions").delete().eq("app_id",e).eq("user_id",l);v&&t.program.error(`Cannot delete version for app ${e} from database ${v} `);const{error:y}=yield d.from("apps").delete().eq("app_id",e).eq("user_id",l);y&&t.program.error(`Cannot delete from database ${y} `),p.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":l,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`)}))},250:function(e,o,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0});const t=r(304),a=r(107),i=r(605),s=r(327),p=r(823),d=n(r(598)),l=r(829),c=r(501);t.program.version(d.default.version).command("add [appid]").alias("a").action(a.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),t.program.version(d.default.version).command("login [apikey]").alias("l").action(l.login).option("--local","Only save in local folder"),t.program.command("upload [appid]").alias("u").action(p.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the file to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to capgo cloud").option("-f, --format <base64|hex|binary|utf8>","choose the upload format default base64").option("-b, --bundle <bundle>","bundle version number of the file to upload"),t.program.command("set [appid]").alias("s").action(s.setChannel).requiredOption("-c, --channel <channel>","channel to link to").option("-b, --bundle <bundle>","bundle version number of the file to set").option("-s, --state <state>","set the state of the channel, default or normal").option("--downgrade","Allow to downgrade to version under native one").option("--no-downgrade","Disable downgrade to version under native one").option("--upgrade","Allow to upgrade to version above native one").option("--no-upgrade","Disable upgrade to version above native one").option("--ios","Allow sending update to ios devices").option("--no-ios","Disable sending update to ios devices").option("--android","Allow sending update to android devices").option("--no-android","Disable sending update to android devices").option("--self-assign","Allow to device to self assign to this channel").option("--no-self-assign","Disable devices to self assign to this channel").option("-a, --apikey <apikey>","apikey to link to your account"),t.program.description("Manage package and version in capgo Cloud").command("delete [appid]").alias("d").action(i.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the app to delete"),t.program.description("List versions in capgo Cloud").command("list [appid]").alias("ls").action(c.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),t.program.parse(process.argv)},501:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const t=r(304),a=r(771);o.listApp=(e,o)=>n(void 0,void 0,void 0,(function*(){var r;const n=o.apikey||(0,a.findSavedKey)(),i=yield(0,a.getConfig)();e=e||(null===(r=null==i?void 0:i.app)||void 0===r?void 0:r.appId),n||t.program.error("Missing API key, you need to provide an API key to delete your app"),e||t.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),console.log("Querying available versions in Capgo");const s=(0,a.createSupabaseClient)(n),p=yield(0,a.verifyUser)(s,n),{data:d,error:l}=yield s.rpc("exist_app",{appid:e,apikey:n});d&&!l||t.program.error("No permission for this app");const{data:c,error:u}=yield s.from("app_versions").select().eq("app_id",e).eq("user_id",p).eq("deleted",!1);console.log(`Active versions in Capgo: ${null==c?void 0:c.length}`),null==c||c.forEach((e=>{const o=new Date(e.created_at||"").toLocaleString();console.log(`${e.name} created on ${o}`)})),u&&t.program.error(`App ${e} not found in database ${u} `)}))},829:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.login=void 0;const a=r(304),i=t(r(147)),s=t(r(37)),p=r(771);o.login=(e,o)=>n(void 0,void 0,void 0,(function*(){const{local:r}=o,n=(0,p.useLogSnag)();if(r)i.default.existsSync(".git")||a.program.error("To use local you should be in a git repository"),i.default.writeFileSync(".capgo",`${e}\n`),i.default.appendFileSync(".gitignore",".capgo\n");else{const o=s.default.homedir();i.default.writeFileSync(`${o}/.capgo`,`${e}\n`)}const t=(0,p.createSupabaseClient)(e),d=yield(0,p.verifyUser)(t,e,["write","all","upload"]);n.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":d},notify:!1}).catch(),console.log(`login saved into .capgo file in ${r?"local":"home"} directory`)}))},327:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const t=r(304),a=r(771);o.setChannel=(e,o)=>n(void 0,void 0,void 0,(function*(){var r;const{bundle:n,downgrade:i,upgrade:s,ios:p,android:d,selfAssign:l,channel:c,state:u}=o,g=o.apikey||(0,a.findSavedKey)(),f=yield(0,a.getConfig)(),v=(0,a.useLogSnag)();e=e||(null===(r=null==f?void 0:f.app)||void 0===r?void 0:r.appId),g||t.program.error("Missing API key, you need to provide a API key to add your app"),e||t.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),void 0===n&&void 0===u&&void 0===i&&void 0===s&&void 0===p&&void 0===d&&void 0===l&&t.program.error("Missing argument, you need to provide a option to set");try{const o=(0,a.createSupabaseClient)(g),r=yield(0,a.verifyUser)(o,g,["write","all"]);yield(0,a.checkPlan)(o,r);const f={created_by:r,app_id:e,name:c};if(n){console.log(`Set ${e} channel: ${c} to @${n}`);const{data:a,error:i}=yield o.from("app_versions").select().eq("app_id",e).eq("name",n).eq("user_id",r).eq("deleted",!1);!i&&a&&a.length||t.program.error(`Cannot find version ${n}`),f.version=a[0].id}void 0!==u&&("public"!==u&&"private"!==u||console.log(`Set ${e} channel: ${c} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${c} to ${"public"===u||"default"===u?"default":"normal"}`),f.public="public"===u||"default"===u),void 0!==i&&(console.log(`Set ${e} channel: ${c} to ${i?"allow":"disallow"} downgrade`),f.disableAutoUpdateUnderNative=!i),void 0!==s&&(console.log(`Set ${e} channel: ${c} to ${s?"allow":"disallow"} upgrade`),f.disableAutoUpdateToMajor=!s),void 0!==p&&(console.log(`Set ${e} channel: ${c} to ${p?"allow":"disallow"} ios update`),f.ios=!!p),void 0!==d&&(console.log(`Set ${e} channel: ${c} to ${d?"allow":"disallow"} android update`),f.android=!!d),void 0!==l&&(console.log(`Set ${e} channel: ${c} to ${l?"allow":"disallow"} self assign to this channel`),f.allow_device_self_set=!!l);try{const{error:e}=yield(0,a.updateOrCreateChannel)(o,f,g);e&&t.program.error(`Cannot set channel ${(0,a.formatError)(e)}`)}catch(e){t.program.error(`Cannot set channel ${(0,a.formatError)(e)}`)}v.publish({channel:"app",event:"Set app",icon:"✅",tags:{"user-id":r,"app-id":e},notify:!1}).catch()}catch(e){t.program.error(`Unknow error ${(0,a.formatError)(e)}`)}console.log("Done ✅")}))},823:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadVersion=void 0;const a=t(r(844)),i=r(304),s=r(113),p=t(r(295)),d=r(906),l=r(771);o.uploadVersion=(e,o)=>n(void 0,void 0,void 0,(function*(){var r,n,t,c;let{bundle:u,path:g,channel:f}=o;const{external:v}=o,y=o.apikey||(0,l.findSavedKey)(),m=(0,l.useLogSnag)();f=f||"dev";const h=yield(0,l.getConfig)();e=e||(null===(r=null==h?void 0:h.app)||void 0===r?void 0:r.appId),u=u||(null===(t=null===(n=null==h?void 0:h.app)||void 0===n?void 0:n.package)||void 0===t?void 0:t.version),l.regexSemver.test(u)||i.program.error(`Your bundle name ${u}, is not valid it should follow semver convention : https://semver.org/`),g=g||(null===(c=null==h?void 0:h.app)||void 0===c?void 0:c.webDir),y||i.program.error("Missing API key, you need to provide a API key to add your app"),e&&u&&g||i.program.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),console.log(`Upload ${e}@${u} started from path "${g}" to Capgo cloud`);const b=(0,l.createSupabaseClient)(y),_=yield(0,l.verifyUser)(b,y,["write","all","upload"]);yield(0,l.checkPlan)(b,_,!1);const $=new p.default.MultiBar({clearOnComplete:!1,hideCursor:!0},p.default.Presets.shades_grey),w=$.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},p.default.Presets.shades_grey);w.start(7,0,{speed:"N/A"});const{data:k,error:x}=yield b.rpc("exist_app_versions",{apikey:y,name_version:u,appid:e});(k||x)&&($.stop(),i.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,l.formatError)(x)}`)),w.increment();const{data:C,error:A}=yield b.rpc("is_trial",{userid:_}).single();(C&&C>0||A)&&$.log(`WARNING !!\nTrial expires in ${C} days, upgrade here: ${l.hostWeb}/dashboard/settings/plans\n`),w.increment();const{data:S,error:q}=yield b.rpc("exist_app",{appid:e,apikey:y});S&&!q||($.stop(),i.program.error(`Cannot find app ${e} in your account \n${(0,l.formatError)(q)}`)),w.increment();const{data:P,error:I}=yield b.rpc("exist_app_versions",{appid:e,apikey:y,name_version:u});(P||I)&&i.program.error(`Version already exists ${(0,l.formatError)(I)}`),w.increment();const j=(0,s.randomUUID)();let M="";if(v)v&&!v.startsWith("https://")&&($.stop(),i.program.error(`External link should should start with "https://" current is "${v}"`));else{const o=new a.default;o.addLocalFolder(g);const r=o.toBuffer();M=yield(0,d.checksum)(r,"crc32");const n=Math.floor(r.byteLength/1024/1024),t=`apps/${_}/${e}/versions`;w.increment(),n>20&&($.log(`WARNING !!\nThe app size is ${n} Mb, this may take a while to download for users\n`),m.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":_,"app-id":e},notify:!1}).catch());const{error:s}=yield b.storage.from(t).upload(j,r,{contentType:"application/zip"});s&&($.stop(),i.program.error(`Cannot upload ${(0,l.formatError)(s)}`))}w.increment();const{data:U,error:E}=yield(0,l.updateOrCreateVersion)(b,{bucket_id:v?void 0:j,user_id:_,name:u,app_id:e,external_url:v,checksum:M},y);if(E&&($.stop(),i.program.error(`Cannot add bundle ${(0,l.formatError)(E)}`)),w.increment(),U&&U.length){const{error:o}=yield(0,l.updateOrCreateChannel)(b,{name:f,app_id:e,created_by:_,version:U[0].id},y);o&&$.log("Cannot set bundle with upload key, use key with more rights for that\n")}else $.log("Cannot set bundle with upload key, use key with more rights for that\n");$.stop();const O=e.replace(/\./g,"--");console.log("App uploaded to server"),console.log(`Try it in mobile app: ${l.host}/app_mobile`),console.log(`Or set the channel ${f} as public here: ${l.hostWeb}/app/package/${O}`),console.log("To use with live update in your own app"),console.log(`You can link specific device to this bundle to make user try it first, here: ${l.hostWeb}/app/p/${O}/devices`),m.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":_,"app-id":e},notify:!1}).catch()}))},771:function(e,o,r){var n=this&&this.__awaiter||function(e,o,r,n){return new(r||(r=Promise))((function(t,a){function i(e){try{p(n.next(e))}catch(e){a(e)}}function s(e){try{p(n.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof r?o:new r((function(e){e(o)}))).then(i,s)}p((n=n.apply(e,o||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.verifyUser=o.useLogSnag=o.updateOrCreateChannel=o.updateOrCreateVersion=o.getConfig=o.formatError=o.findSavedKey=o.checkPlan=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.supaAnon=o.hostSupa=o.hostWeb=o.host=void 0;const a=r(778),i=r(304),s=r(885),p=t(r(867)),d=t(r(147)),l=t(r(37)),c=r(133);o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostSupa="https://xvwzpoazmxkqosrdewyv.supabase.co",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w",o.createSupabaseClient=e=>(0,s.createClient)(o.hostSupa,o.supaAnon,{headers:{capgkey:e}}),o.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-]+)*))?$/,o.checkKey=(e,r,t)=>n(void 0,void 0,void 0,(function*(){const{data:n,error:a}=yield e.rpc("is_allowed_capgkey",{apikey:r,keymode:t});n&&!a||i.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(a)}`)})),o.isGoodPlan=(e,o)=>n(void 0,void 0,void 0,(function*(){const{data:r,error:n}=yield e.rpc("is_good_plan_v2",{userid:o}).single();if(n)throw n;return r||!1})),o.isPaying=(e,o)=>n(void 0,void 0,void 0,(function*(){const{data:r,error:n}=yield e.rpc("is_paying",{userid:o}).single();if(n)throw n;return r||!1})),o.isTrial=(e,o)=>n(void 0,void 0,void 0,(function*(){const{data:r,error:n}=yield e.rpc("is_trial",{userid:o}).single();if(n)throw n;return r||0})),o.checkPlan=(e,r,t=!0)=>n(void 0,void 0,void 0,(function*(){const n=yield(0,o.isGoodPlan)(e,r),a=yield(0,o.isPaying)(e,r),s=yield(0,o.isTrial)(e,r);a&&n||!(s<0)||i.program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),s>0&&t&&!a&&console.log(`WARNING !!\nTrial expires in ${s} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e=`${l.default.homedir()}/.capgo`;return d.default.existsSync(e)?d.default.readFileSync(e,"utf8").trim():(e=".capgo",d.default.existsSync(e)?d.default.readFileSync(e,"utf8").trim():null)},o.formatError=e=>e?`\n${p.default.render(e)}`:"",o.getConfig=()=>n(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,a.loadConfig)()}catch(e){i.program.error("No capacitor config file found, run `cap init` first")}return e})),o.updateOrCreateVersion=(e,o,r)=>n(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("exist_app_versions",{appid:o.app_id,name_version:o.name,apikey:r});return n&&!t?(o.deleted=!1,e.from("app_versions").update(o).eq("app_id",o.app_id).eq("name",o.name)):e.from("app_versions").insert(o)})),o.updateOrCreateChannel=(e,o,r)=>n(void 0,void 0,void 0,(function*(){if(!o.app_id||!o.name||!o.created_by)return console.error("missing app_id, name, or created_by"),Promise.reject(new Error("missing app_id, name, or created_by"));const{data:n,error:t}=yield e.rpc("exist_channel",{appid:o.app_id,name_channel:o.name,apikey:r});return n&&!t?e.from("channels").update(o,{returning:"minimal"}).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by):e.from("channels").insert(o,{returning:"minimal"})})),o.useLogSnag=()=>new c.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.verifyUser=(e,r,t=["all"])=>n(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,r,t);const{data:n,error:a}=yield e.rpc("get_user_id",{apikey:r}),s=n?n.toString():"";return s&&!a||i.program.error(`Cannot verify user ${(0,o.formatError)(a)}`),s}))},778:e=>{e.exports=require("@capacitor/cli/dist/config")},885:e=>{e.exports=require("@supabase/supabase-js")},906:e=>{e.exports=require("@tomasklaen/checksum")},844:e=>{e.exports=require("adm-zip")},295:e=>{e.exports=require("cli-progress")},304:e=>{e.exports=require("commander")},470:e=>{e.exports=require("fs-extra")},133:e=>{e.exports=require("logsnag")},11:e=>{e.exports=require("mime")},867:e=>{e.exports=require("prettyjson")},113:e=>{e.exports=require("crypto")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},598:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"1.1.8","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"keywords":["appflow alternative","ionic","capacitor","auto update","live update","capgo","cli","upload","capgo-cli"],"scripts":{"dev":"set NODE_ENV=development && npx webpack --config webpack.config.js","no-debug":"node dist/index.js","build":"npx webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","test_rls":"ts-node ./test/test_headers_rls.ts","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"4.4.0","@supabase/supabase-js":"^1.35.7","@tomasklaen/checksum":"^1.1.0","adm-zip":"^0.5.9","cli-progress":"3.11.2","commander":"9.4.1","fs-extra":"10.1.0","logsnag":"^0.1.5","mime":"^3.0.0","prettyjson":"^1.2.5"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/cli-progress":"^3.11.0","@types/fs-extra":"^9.0.13","@types/mime":"^3.0.1","@types/node":"^18.11.9","@types/prettyjson":"^0.0.30","@types/semver":"^7.3.13","@typescript-eslint/eslint-plugin":"5.42.1","@typescript-eslint/parser":"5.42.1","eslint":"8.27.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"3.5.2","eslint-plugin-import":"2.25.1","eslint-plugin-prettier":"^4.2.1","git-format-staged":"3.0.0","husky":"^8.0.2","nodemon":"2.0.20","pkg":"5.8.0","prettier":"2.7.1","ts-loader":"^9.4.1","ts-node":"^10.9.1","tsconfig-paths":"4.1.0","typescript":"4.8.4","webpack":"5.74.0","webpack-cli":"^4.10.0","webpack-node-externals":"^3.0.0"}}')}},o={};!function r(n){var t=o[n];if(void 0!==t)return t.exports;var a=o[n]={exports:{}};return e[n].call(a.exports,a,a.exports,r),a.exports}(250)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.8",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -36,47 +36,44 @@
36
36
  "author": "github.com/riderx",
37
37
  "license": "Apache 2.0",
38
38
  "dependencies": {
39
- "@capacitor/cli": "3.5.1",
40
- "@supabase/supabase-js": "^1.35.3",
39
+ "@capacitor/cli": "4.4.0",
40
+ "@supabase/supabase-js": "^1.35.7",
41
41
  "@tomasklaen/checksum": "^1.1.0",
42
42
  "adm-zip": "^0.5.9",
43
- "cli-progress": "3.11.0",
44
- "commander": "9.2.0",
45
- "form-data": "^4.0.0",
43
+ "cli-progress": "3.11.2",
44
+ "commander": "9.4.1",
46
45
  "fs-extra": "10.1.0",
47
- "logsnag": "^0.1.2",
46
+ "logsnag": "^0.1.5",
48
47
  "mime": "^3.0.0",
49
- "node-stream-zip": "^1.15.0",
50
- "prettyjson": "^1.2.5",
51
- "upath": "^2.0.1"
48
+ "prettyjson": "^1.2.5"
52
49
  },
53
50
  "devDependencies": {
54
51
  "@types/adm-zip": "0.5.0",
55
52
  "@types/cli-progress": "^3.11.0",
56
53
  "@types/fs-extra": "^9.0.13",
57
- "@types/mime": "^2.0.3",
58
- "@types/node": "^17.0.31",
54
+ "@types/mime": "^3.0.1",
55
+ "@types/node": "^18.11.9",
59
56
  "@types/prettyjson": "^0.0.30",
60
- "@types/semver": "^7.3.10",
61
- "@typescript-eslint/eslint-plugin": "5.22.0",
62
- "@typescript-eslint/parser": "5.22.0",
63
- "eslint": "8.14.0",
57
+ "@types/semver": "^7.3.13",
58
+ "@typescript-eslint/eslint-plugin": "5.42.1",
59
+ "@typescript-eslint/parser": "5.42.1",
60
+ "eslint": "8.27.0",
64
61
  "eslint-config-airbnb-base": "^15.0.0",
65
62
  "eslint-config-prettier": "^8.5.0",
66
- "eslint-import-resolver-typescript": "2.7.1",
67
- "eslint-plugin-import": "2.26.0",
68
- "eslint-plugin-prettier": "^4.0.0",
63
+ "eslint-import-resolver-typescript": "3.5.2",
64
+ "eslint-plugin-import": "2.25.1",
65
+ "eslint-plugin-prettier": "^4.2.1",
69
66
  "git-format-staged": "3.0.0",
70
- "husky": "^7.0.4",
71
- "nodemon": "2.0.16",
72
- "pkg": "5.6.0",
73
- "prettier": "2.6.2",
74
- "ts-loader": "^9.3.0",
75
- "ts-node": "^10.7.0",
76
- "tsconfig-paths": "4.0.0",
77
- "typescript": "4.6.4",
78
- "webpack": "5.72.0",
79
- "webpack-cli": "^4.9.2",
67
+ "husky": "^8.0.2",
68
+ "nodemon": "2.0.20",
69
+ "pkg": "5.8.0",
70
+ "prettier": "2.7.1",
71
+ "ts-loader": "^9.4.1",
72
+ "ts-node": "^10.9.1",
73
+ "tsconfig-paths": "4.1.0",
74
+ "typescript": "4.8.4",
75
+ "webpack": "5.74.0",
76
+ "webpack-cli": "^4.10.0",
80
77
  "webpack-node-externals": "^3.0.0"
81
78
  }
82
79
  }
package/src/bin/index.ts CHANGED
@@ -34,7 +34,7 @@ program
34
34
  program
35
35
  .command('set [appid]').alias('s')
36
36
  .action(setChannel)
37
- .option('-c, --channel <channel>', 'channel to link to')
37
+ .requiredOption('-c, --channel <channel>', 'channel to link to')
38
38
  .option('-b, --bundle <bundle>', 'bundle version number of the file to set')
39
39
  .option('-s, --state <state>', 'set the state of the channel, default or normal')
40
40
  .option('--downgrade', 'Allow to downgrade to version under native one')
package/src/bin/set.ts CHANGED
@@ -30,9 +30,6 @@ export const setChannel = async (appid: string, options: Options) => {
30
30
  if (!appid) {
31
31
  program.error("Missing argument, you need to provide a appid, or be in a capacitor project");
32
32
  }
33
- if (!channel) {
34
- program.error("Missing argument, you need to provide a channel");
35
- }
36
33
  if (bundle === undefined &&
37
34
  state === undefined &&
38
35
  downgrade === undefined &&
package/src/bin/utils.ts CHANGED
@@ -30,7 +30,6 @@ export const createSupabaseClient = (apikey: string) => createClient(hostSupa, s
30
30
  // eslint-disable-next-line max-len
31
31
  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-]+)*))?$/
32
32
 
33
-
34
33
  export const checkKey = async (supabase: SupabaseClient, apikey: string, keymode: string[]) => {
35
34
  const { data: apiAccess, error: apiAccessError } = await supabase
36
35
  .rpc('is_allowed_capgkey', { apikey, keymode })
@@ -42,7 +41,17 @@ export const checkKey = async (supabase: SupabaseClient, apikey: string, keymode
42
41
 
43
42
  export const isGoodPlan = async (supabase: SupabaseClient, userId: string): Promise<boolean> => {
44
43
  const { data, error } = await supabase
45
- .rpc<boolean>('is_good_plan', { userid: userId })
44
+ .rpc<boolean>('is_good_plan_v2', { userid: userId })
45
+ .single()
46
+ if (error) {
47
+ throw error
48
+ }
49
+ return data || false
50
+ }
51
+
52
+ export const isPaying = async (supabase: SupabaseClient, userId: string): Promise<boolean> => {
53
+ const { data, error } = await supabase
54
+ .rpc<boolean>('is_paying', { userid: userId })
46
55
  .single()
47
56
  if (error) {
48
57
  throw error
@@ -61,15 +70,13 @@ export const isTrial = async (supabase: SupabaseClient, userId: string): Promise
61
70
  }
62
71
 
63
72
  export const checkPlan = async (supabase: SupabaseClient, userId: string, warning = true) => {
64
- let validPlan = await isGoodPlan(supabase, userId)
73
+ const validPlan = await isGoodPlan(supabase, userId)
74
+ const paying = await isPaying(supabase, userId)
65
75
  const trialDays = await isTrial(supabase, userId)
66
- if (trialDays > 0) {
67
- validPlan = true
68
- }
69
- if (!validPlan) {
76
+ if ((!paying || !validPlan) && trialDays < 0) {
70
77
  program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${hostWeb}/dashboard/settings/plans\n`);
71
78
  }
72
- if (trialDays > 0 && warning) {
79
+ if (trialDays > 0 && warning && !paying) {
73
80
  console.log(`WARNING !!\nTrial expires in ${trialDays} days, upgrade here: ${hostWeb}/dashboard/settings/plans\n`);
74
81
  }
75
82
  }