@capgo/cli 3.0.0-alpha.0 → 3.0.0

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.
@@ -19,7 +19,7 @@ jobs:
19
19
  uses: actions/setup-node@v3
20
20
  with:
21
21
  node-version: 18
22
- cache: 'pnpm'
22
+ cache: "pnpm"
23
23
  - name: Install dependencies
24
24
  id: install_code
25
25
  run: pnpm install --frozen-lockfile
@@ -29,6 +29,12 @@ jobs:
29
29
  - name: Build
30
30
  id: build_code
31
31
  run: pnpm build
32
- - uses: JS-DevTools/npm-publish@v1
32
+ - uses: rxfork/npm-publish@v1
33
+ if: "!contains(github.ref, '-alpha.')"
33
34
  with:
34
35
  token: ${{ secrets.NPM_TOKEN }}
36
+ - uses: rxfork/npm-publish@v1
37
+ if: "contains(github.ref, '-alpha.')"
38
+ with:
39
+ token: ${{ secrets.NPM_TOKEN }}
40
+ tag: next
package/CHANGELOG.md CHANGED
@@ -2,6 +2,82 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [3.0.0](https://github.com/Cap-go/capgo-cli/compare/v2.7.0...v3.0.0) (2023-02-20)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * add back upload to suport old usages ([d658200](https://github.com/Cap-go/capgo-cli/commit/d6582003b5b21467c57cf8a862ec115dcac8602d))
11
+ * lint ([20f27bd](https://github.com/Cap-go/capgo-cli/commit/20f27bd60da883815100e6be142664b42d332da0))
12
+
13
+ ## [3.0.0-alpha.2](https://github.com/Cap-go/capgo-cli/compare/v2.6.2...v3.0.0-alpha.2) (2023-02-10)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * file path ([228913f](https://github.com/Cap-go/capgo-cli/commit/228913ff779c9a027a6fbba528bf7bfaf6470436))
19
+
20
+ ## [3.0.0-alpha.1](https://github.com/Cap-go/capgo-cli/compare/v2.5.10-alpha.0...v3.0.0-alpha.1) (2023-02-04)
21
+
22
+
23
+ ### ⚠ BREAKING CHANGES
24
+
25
+ * trigger ci
26
+
27
+ ### Bug Fixes
28
+
29
+ * trigger ci ([7c4c35f](https://github.com/Cap-go/capgo-cli/commit/7c4c35f8f095a9c67843fbd2343d90d96720cc72))
30
+ * trigger ci ([d28daa5](https://github.com/Cap-go/capgo-cli/commit/d28daa5e79dce68d2b3f23e4e94985140005ffac))
31
+ * trigger ci ([51e2914](https://github.com/Cap-go/capgo-cli/commit/51e291419101f8c8f362e03b765948280b533fb8))
32
+
33
+ ### [2.5.10-alpha.0](https://github.com/Cap-go/capgo-cli/compare/v2.5.10...v2.5.10-alpha.0) (2023-02-04)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * npm publish ([1249213](https://github.com/Cap-go/capgo-cli/commit/124921324bde43dce24562ed369e77f604f3d5e8))
39
+ * trigger ci ([464dd6a](https://github.com/Cap-go/capgo-cli/commit/464dd6a650266e5b5bb0a46049a917d26af1d22a))
40
+
41
+ ## [3.0.0-alpha.0](https://github.com/Cap-go/capgo-cli/compare/v2.5.8...v3.0.0-alpha.0) (2023-02-03)
42
+
43
+
44
+ ### ⚠ BREAKING CHANGES
45
+
46
+ * add new commands and refactor for sub commands
47
+
48
+ ### Features
49
+
50
+ * add new commands and refactor for sub commands ([c3aab3a](https://github.com/Cap-go/capgo-cli/commit/c3aab3afa6b86c5b2ca3864c196a3c02ea258991))
51
+
52
+ ## [3.0.0-alpha.2](https://github.com/Cap-go/capgo-cli/compare/v2.6.1...v3.0.0-alpha.2) (2023-02-10)
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * file path ([228913f](https://github.com/Cap-go/capgo-cli/commit/228913ff779c9a027a6fbba528bf7bfaf6470436))
58
+ * list the cli as well ([c704222](https://github.com/Cap-go/capgo-cli/commit/c704222d8f9b4568983ea6ecb776775371b10a3d))
59
+
60
+ ## [3.0.0-alpha.1](https://github.com/Cap-go/capgo-cli/compare/v2.5.10-alpha.0...v3.0.0-alpha.1) (2023-02-04)
61
+
62
+
63
+ ### ⚠ BREAKING CHANGES
64
+
65
+ * trigger ci
66
+
67
+ ### Bug Fixes
68
+
69
+ * trigger ci ([7c4c35f](https://github.com/Cap-go/capgo-cli/commit/7c4c35f8f095a9c67843fbd2343d90d96720cc72))
70
+ * trigger ci ([d28daa5](https://github.com/Cap-go/capgo-cli/commit/d28daa5e79dce68d2b3f23e4e94985140005ffac))
71
+ * trigger ci ([51e2914](https://github.com/Cap-go/capgo-cli/commit/51e291419101f8c8f362e03b765948280b533fb8))
72
+
73
+ ### [2.5.10-alpha.0](https://github.com/Cap-go/capgo-cli/compare/v2.5.10...v2.5.10-alpha.0) (2023-02-04)
74
+
75
+
76
+ ### Bug Fixes
77
+
78
+ * npm publish ([1249213](https://github.com/Cap-go/capgo-cli/commit/124921324bde43dce24562ed369e77f604f3d5e8))
79
+ * trigger ci ([464dd6a](https://github.com/Cap-go/capgo-cli/commit/464dd6a650266e5b5bb0a46049a917d26af1d22a))
80
+
5
81
  ## [3.0.0-alpha.0](https://github.com/Cap-go/capgo-cli/compare/v2.5.8...v3.0.0-alpha.0) (2023-02-03)
6
82
 
7
83
 
@@ -13,6 +89,59 @@ All notable changes to this project will be documented in this file. See [standa
13
89
 
14
90
  * add new commands and refactor for sub commands ([c3aab3a](https://github.com/Cap-go/capgo-cli/commit/c3aab3afa6b86c5b2ca3864c196a3c02ea258991))
15
91
 
92
+ ## [3.0.0-alpha.1](https://github.com/Cap-go/capgo-cli/compare/v2.5.10-alpha.0...v3.0.0-alpha.1) (2023-02-04)
93
+
94
+
95
+ ### ⚠ BREAKING CHANGES
96
+
97
+ * trigger ci
98
+
99
+ ### Bug Fixes
100
+
101
+ * trigger ci ([7c4c35f](https://github.com/Cap-go/capgo-cli/commit/7c4c35f8f095a9c67843fbd2343d90d96720cc72))
102
+ * trigger ci ([d28daa5](https://github.com/Cap-go/capgo-cli/commit/d28daa5e79dce68d2b3f23e4e94985140005ffac))
103
+ * trigger ci ([51e2914](https://github.com/Cap-go/capgo-cli/commit/51e291419101f8c8f362e03b765948280b533fb8))
104
+
105
+ ### [2.5.10-alpha.0](https://github.com/Cap-go/capgo-cli/compare/v3.0.0-alpha.0...v2.5.10-alpha.0) (2023-02-04)
106
+ ### [2.6.1](https://github.com/Cap-go/capgo-cli/compare/v2.6.0...v2.6.1) (2023-02-10)
107
+
108
+
109
+ ### Bug Fixes
110
+
111
+ * npm publish ([1249213](https://github.com/Cap-go/capgo-cli/commit/124921324bde43dce24562ed369e77f604f3d5e8))
112
+ * trigger ci ([464dd6a](https://github.com/Cap-go/capgo-cli/commit/464dd6a650266e5b5bb0a46049a917d26af1d22a))
113
+ * change happy path and command name ([8113a78](https://github.com/Cap-go/capgo-cli/commit/8113a78363297e5ad4c69a8c9dd7deabef500bf0))
114
+
115
+ ## [2.6.0](https://github.com/Cap-go/capgo-cli/compare/v2.5.12...v2.6.0) (2023-02-10)
116
+
117
+
118
+ ### Features
119
+
120
+ * add info command ([9b0c193](https://github.com/Cap-go/capgo-cli/commit/9b0c193e6b647e144b44775fef96296db0327b37))
121
+
122
+ ### [2.5.12](https://github.com/Cap-go/capgo-cli/compare/v2.5.11...v2.5.12) (2023-02-06)
123
+
124
+
125
+ ### Bug Fixes
126
+
127
+ * **deps:** update dependency @capacitor/cli to v4.6.3 ([fc3be28](https://github.com/Cap-go/capgo-cli/commit/fc3be28827a399df4693f45d92ec0c9b2e93fd79))
128
+
129
+ ### [2.5.11](https://github.com/Cap-go/capgo-cli/compare/v2.5.10...v2.5.11) (2023-02-06)
130
+
131
+ ### [2.5.10](https://github.com/Cap-go/capgo-cli/compare/v2.5.9...v2.5.10) (2023-02-04)
132
+
133
+
134
+ ### Bug Fixes
135
+
136
+ * npm publish ([0b06d6e](https://github.com/Cap-go/capgo-cli/commit/0b06d6ea25534ddd795120b6fdb38dd2f8ba9de3))
137
+
138
+ ### [2.5.9](https://github.com/Cap-go/capgo-cli/compare/v2.5.8...v2.5.9) (2023-02-04)
139
+
140
+
141
+ ### Bug Fixes
142
+
143
+ * trigger ci ([1354219](https://github.com/Cap-go/capgo-cli/commit/13542197f1a4e0cf37cbcbcac7912670bf226958))
144
+
16
145
  ### [2.5.8](https://github.com/Cap-go/capgo-cli/compare/v2.5.7...v2.5.8) (2023-01-30)
17
146
 
18
147
  ### [2.5.7](https://github.com/Cap-go/capgo-cli/compare/v2.5.6...v2.5.7) (2023-01-30)
package/README.md CHANGED
@@ -106,6 +106,10 @@ Optionally, you can give:
106
106
  `npx @capgo/cli list [appId] `
107
107
  `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init).
108
108
 
109
+ ### Doctor installed package
110
+ `npx @capgo/cli doctor`
111
+ Learn info about the Capgo package installed on your project and see if update are available.
112
+
109
113
  ### Delete package to Cloud
110
114
  `npx @capgo/cli delete [appId]`
111
115
  `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init).
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- (()=>{"use strict";var e={266:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.newIconPath=o.checkAppExistsAndHasPermission=void 0;const t=n(304);o.checkAppExistsAndHasPermission=(e,o,n)=>i(void 0,void 0,void 0,(function*(){const{data:i,error:a}=yield e.rpc("exist_app",{appid:o,apikey:n}).single();i&&!a||t.program.error("No permission for this app")})),o.newIconPath="assets/icon.png"},34:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getActiveChannels=o.displayChannels=o.delChannel=o.createChannel=o.findUnknownVersion=o.checkVersionNotUsedInChannel=void 0;const t=n(304),a=n(847),r=n(584);o.checkVersionNotUsedInChannel=(e,o,n,a)=>i(void 0,void 0,void 0,(function*(){const{data:i,error:s}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).eq("version",a.id);if(s&&t.program.error(`Cannot check Version ${o}@${a.name} ${(0,r.formatError)(s)}`),i&&i.length>0){const e=(0,r.convertAppName)(o);t.program.error(`❌ Version ${o}@${a.name} is used in channel ${i[0].name}, unlink it first:\nhttps://web.capgo.app/app/p/${e}/channel/${i[0].id}\nClick on top right button and unlink.\n${(0,r.formatError)(s)}`)}})),o.findUnknownVersion=(e,o)=>e.from("app_versions").select("id").eq("app_id",o).eq("name","unknown").single(),o.createChannel=(e,o)=>e.from("channels").insert(o).select().single(),o.delChannel=(e,o,n,i)=>e.from("channels").delete().eq("name",o).eq("app_id",n).eq("user_id",i).single(),o.displayChannels=e=>{const o=new a.Table({title:"Channels",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,r.getHumanDate)(e.created_at),Public:e.public?"✅":"❌"})})),o.printTable()},o.getActiveChannels=(e,o,n)=>i(void 0,void 0,void 0,(function*(){const{data:i,error:a}=yield e.from("channels").select().eq("app_id",o).eq("user_id",n).order("created_at",{ascending:!1});return a&&t.program.error(`App ${o} not found in database ${(0,r.formatError)(a)} `),i}))},518:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createRSA=o.encryptSource=o.decryptSource=void 0;const i=n(113),t="aes-128-cbc",a="sha256",r="base64",s=i.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[p,c]=o.split(":"),l=(0,i.privateDecrypt)({key:n,padding:s,oaepHash:a},Buffer.from(c,r)),d=Buffer.from(p,r),u=l.toString(r);console.log("\nSessionB64",u);const y=(0,i.createDecipheriv)(t,l,d);return y.setAutoPadding(!0),Buffer.concat([y.update(e),y.final()])},o.encryptSource=(e,o)=>{const n=(0,i.randomBytes)(16),p=(0,i.randomBytes)(16),c=(0,i.createCipheriv)(t,p,n);c.setAutoPadding(!0);const l=`${n.toString(r)}:${(0,i.publicEncrypt)({key:o,padding:s,oaepHash:a},p).toString(r)}`;return{encryptedData:Buffer.concat([c.update(e),c.final()]),ivSessionKey:l}},o.createRSA=()=>{const{publicKey:e,privateKey:o}=(0,i.generateKeyPairSync)("rsa",{modulusLength:2048});return{publicKey:e.export({type:"pkcs1",format:"pem"}),privateKey:o.export({type:"pkcs1",format:"pem"})}}},795:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const t=n(304),a=n(584);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>i(void 0,void 0,void 0,(function*(){const{data:i,error:r}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);if(r&&t.program.error(`Cannot check Device override ${o}@${n.name} ${(0,a.formatError)(r)}`),i&&i.length>0){const e=(0,a.convertAppName)(o);t.program.error(`❌ Version ${o} @${n.name} is used in a device override, unlink it first:\nhttps://web.capgo.app/app/p/${e}/d/${i[0].device_id}\n${(0,a.formatError)(r)}`)}}))},442:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const t=n(304),a=n(584);o.deleteFromStorage=(e,o,n,r,s)=>i(void 0,void 0,void 0,(function*(){const{error:i}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${r.bucket_id} `]);i&&t.program.error(`Something went wrong when trying to delete ${n} @${s} ${(0,a.formatError)(i)} `)}))},224:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getVersionData=o.getActiveAppVersions=o.displayBundles=o.deleteSpecificVersion=o.deleteAppVersion=void 0;const t=n(304),a=n(847),r=n(584),s=n(34),p=n(795),c=n(442);o.deleteAppVersion=(e,o,n,a)=>i(void 0,void 0,void 0,(function*(){const{error:i}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("deleted",!1).eq("user_id",n).eq("name",a);i&&t.program.error(`App Version ${o}@${a} not found in database '${(0,r.formatError)(i)}'`)})),o.deleteSpecificVersion=(e,n,t,a)=>i(void 0,void 0,void 0,(function*(){const i=yield(0,o.getVersionData)(e,n,t,a);yield(0,s.checkVersionNotUsedInChannel)(e,n,t,i),yield(0,p.checkVersionNotUsedInDeviceOverride)(e,n,i),yield(0,c.deleteFromStorage)(e,t,n,i,a),yield(0,o.deleteAppVersion)(e,n,t,a)})),o.displayBundles=e=>{const o=new a.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,r.getHumanDate)(e.created_at)},null!=e.keep?{Keep:e.keep}:{}))})),o.printTable()},o.getActiveAppVersions=(e,o,n)=>i(void 0,void 0,void 0,(function*(){const{data:i,error:a}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return a&&t.program.error(`App ${o} not found in database ${(0,r.formatError)(a)} `),i})),o.getVersionData=(e,o,n,a)=>i(void 0,void 0,void 0,(function*(){const{data:i,error:s}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("name",a).eq("deleted",!1).single();return i&&!s||t.program.error(`App Version ${o}@${a} doesn't exist ${(0,r.formatError)(s)}`),i}))},140:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const t=n(11),a=n(304),r=n(113),s=n(470),p=n(266),c=n(584);o.addApp=(e,o)=>i(void 0,void 0,void 0,(function*(){var n,i,l;o.apikey=o.apikey||(0,c.findSavedKey)()||"";const d=yield(0,c.getConfig)();e=e||(null===(n=null==d?void 0:d.app)||void 0===n?void 0:n.appId);const u=(0,c.useLogSnag)();o.apikey||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||a.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const y=(0,c.createSupabaseClient)(o.apikey),g=yield(0,c.verifyUser)(y,o.apikey,["write","all"]);yield(0,p.checkAppExistsAndHasPermission)(y,e,o.apikey);let v,f,{name:h,icon:m}=o;e=e||(null===(i=null==d?void 0:d.app)||void 0===i?void 0:i.appId),h=h||(null===(l=null==d?void 0:d.app)||void 0===l?void 0:l.appName)||"Unknown",m=m||"resources/icon.png",m&&h||a.program.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project"),console.log(`Adding ${e} to Capgo`),m&&(0,s.existsSync)(m)?(v=(0,s.readFileSync)(m),f=(0,t.getType)(m)||"image/png",console.warn(`Found app icon ${m}`)):(0,s.existsSync)(p.newIconPath)?(v=(0,s.readFileSync)(p.newIconPath),f=(0,t.getType)(p.newIconPath)||"image/png",console.warn(`Found app icon ${p.newIconPath}`)):console.warn(`Cannot find app icon in any of the following locations: ${m}, ${p.newIconPath}`);const{data:b,error:k}=yield y.rpc("exist_app_v2",{appid:e}).single();(b||k)&&a.program.error(`App ${e} already exists ${(0,c.formatError)(k)}`);const w=`icon_${(0,r.randomUUID)()}`;let _="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(v&&f){const{error:o}=yield y.storage.from(`images/${g}/${e}`).upload(w,v,{contentType:f});o&&a.program.error(`Could not add app ${(0,c.formatError)(o)}`);const{data:n}=yield y.storage.from(`images/${g}/${e}`).getPublicUrl(w);_=(null==n?void 0:n.publicUrl)||_}const{error:x}=yield y.from("apps").insert({icon_url:_,user_id:g,name:h,app_id:e});x&&a.program.error(`Could not add app ${(0,c.formatError)(x)}`);const{error:C}=yield y.from("app_versions").insert([{user_id:g,deleted:!0,name:"unknown",app_id:e},{user_id:g,deleted:!0,name:"builtin",app_id:e}]);C&&a.program.error(`Could not add app ${(0,c.formatError)(C)}`),yield u.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":g,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now"),console.log("Done ✅"),process.exit()}))},321:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const t=n(304),a=n(266),r=n(584);o.deleteApp=(e,o,n)=>i(void 0,void 0,void 0,(function*(){var i;n.apikey=n.apikey||(0,r.findSavedKey)()||"";const s=yield(0,r.getConfig)();e=e||(null===(i=null==s?void 0:s.app)||void 0===i?void 0:i.appId);const p=(0,r.useLogSnag)();n.apikey||t.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||t.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const c=(0,r.createSupabaseClient)(n.apikey);yield(0,r.verifyUser)(c,n.apikey,["write","all"]),yield(0,a.checkAppExistsAndHasPermission)(c,e,n.apikey);const{error:l}=yield c.storage.from(`images/${o}`).remove([e]);l&&t.program.error(`Could not add app ${(0,r.formatError)(l)}`);const{error:d}=yield c.storage.from(`apps/${e}/${o}`).remove(["versions"]);d&&t.program.error(`Could not delete app version ${(0,r.formatError)(d)}`);const{error:u}=yield c.from("apps").delete().eq("app_id",e).eq("user_id",o);u&&t.program.error(`Could not delete app ${(0,r.formatError)(u)}`),yield p.publish({channel:"app",event:"App Deleted",icon:"🗑️",tags:{"user-id":o,"app-id":e},notify:!1}).catch(),console.log("App deleted in Capgo"),console.log("Done ✅"),process.exit()}))},465:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const t=n(304),a=n(266),r=n(224),s=n(584);o.listApp=(e,o)=>i(void 0,void 0,void 0,(function*(){var n;const i=o.apikey||(0,s.findSavedKey)(),p=yield(0,s.getConfig)();console.log('COMMAND DEPRECATED, use "app list" instead'),e=e||(null===(n=null==p?void 0:p.app)||void 0===n?void 0:n.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"),console.log("Querying available versions in Capgo");const c=(0,s.createSupabaseClient)(i),l=yield(0,s.verifyUser)(c,i);console.log("Querying available versions in Capgo"),yield(0,a.checkAppExistsAndHasPermission)(c,e,o.apikey);const d=yield(0,r.getActiveAppVersions)(c,e,l);console.log(`Active versions in Capgo: ${null==d?void 0:d.length}`),(0,r.displayBundles)(d),console.log("Done ✅"),process.exit()}))},515:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setApp=void 0;const t=n(11),a=n(304),r=n(113),s=n(470),p=n(266),c=n(584);o.setApp=(e,o,n)=>i(void 0,void 0,void 0,(function*(){var i;n.apikey=n.apikey||(0,c.findSavedKey)()||"";const l=yield(0,c.getConfig)();e=e||(null===(i=null==l?void 0:l.app)||void 0===i?void 0:i.appId),n.apikey||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||a.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const d=(0,c.createSupabaseClient)(n.apikey);yield(0,c.verifyUser)(d,n.apikey,["write","all"]),yield(0,p.checkAppExistsAndHasPermission)(d,e,n.apikey);const{name:u,icon:y}=n;let g,v;const f=`icon_${(0,r.randomUUID)()}`;let h="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(y&&(0,s.existsSync)(y)?(g=(0,s.readFileSync)(y),v=(0,t.getType)(y)||"image/png",console.warn(`Found app icon ${y}`)):(0,s.existsSync)(p.newIconPath)?(g=(0,s.readFileSync)(p.newIconPath),v=(0,t.getType)(p.newIconPath)||"image/png",console.warn(`Found app icon ${p.newIconPath}`)):console.warn(`Cannot find app icon in any of the following locations: ${y}, ${p.newIconPath}`),g&&v){const{error:n}=yield d.storage.from(`images/${o}/${e}`).upload(f,g,{contentType:v});n&&a.program.error(`Could not add app ${(0,c.formatError)(n)}`);const{data:i}=yield d.storage.from(`images/${o}/${e}`).getPublicUrl(f);h=(null==i?void 0:i.publicUrl)||h}const{error:m}=yield d.from("apps").update({icon_url:h,name:u}).eq("app_id",e).eq("user_id",o);m&&a.program.error(`Could not add app ${(0,c.formatError)(m)}`),console.log("Done ✅"),process.exit()}))},61:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))},t=this&&this.__asyncValues||function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o);function i(n){o[n]=e[n]&&function(o){return new Promise((function(i,t){!function(e,o,n,i){Promise.resolve(i).then((function(o){e({value:o,done:n})}),o)}(i,t,(o=e[n](o)).done,o.value)}))}}},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupApp=void 0;const r=n(304),s=a(n(505)),p=a(n(616)),c=n(584),l=n(224),d=n(266),u=(0,p.default)();o.cleanupApp=(e,o)=>i(void 0,void 0,void 0,(function*(){var n;const a=o.apikey||(0,c.findSavedKey)(),{bundle:p,keep:y=4}=o,g=o.force||!1,v=yield(0,c.getConfig)();e=e||(null===(n=null==v?void 0:v.app)||void 0===n?void 0:n.appId),a||r.program.error("Missing API key, you need to provide an API key to delete your app"),e||r.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const f=(0,c.createSupabaseClient)(a),h=yield(0,c.verifyUser)(f,a);yield(0,d.checkAppExistsAndHasPermission)(f,e,a),console.log("Querying all available versions in Capgo");let m=yield(0,l.getActiveAppVersions)(f,e,h);if(console.log(`Total active versions in Capgo: ${null==m?void 0:m.length}`),0===(null==m?void 0:m.length))return void console.log("No versions found, aborting cleanup");if(p){const e=`${s.default.inc(p,"major")}`;console.log(`Querying available versions in Capgo between ${p} and ${e}`),m=((e,o,n)=>{const i=[];return null==e||e.forEach((e=>{s.default.gte(e.name,o)&&s.default.lt(e.name,`${n}`)&&i.push(e)})),i})(m,p,e),console.log(`Active versions in Capgo between ${p} and ${e}: ${null==m?void 0:m.length}`)}const b=[];if(m.forEach(((e,o)=>{o<y?e.keep="✅":(e.keep="❌",b.push(e))})),0!==b.length){if((0,l.displayBundles)(m),!g&&"yes"!==u("Do you want to continue removing the versions specified? Type yes to confirm: "))return void console.log("Not confirmed, aborting removal...");console.log("You have confirmed removal, removing versions now"),yield((e,o,n,a)=>{var r,s,p;return i(void 0,void 0,void 0,(function*(){var i,d,u,y;try{for(r=!0,s=t(e);!(i=(p=yield s.next()).done);){y=p.value,r=!1;try{const e=y;console.log(`Removing ${e.name} created on ${(0,c.getHumanDate)(e.created_at)}`),yield(0,l.deleteSpecificVersion)(o,n,a,e.name)}finally{r=!0}}}catch(e){d={error:e}}finally{try{r||i||!(u=s.return)||(yield u.call(s))}finally{if(d)throw d.error}}}))})(b,f,e,h),console.log("Done ✅"),process.exit()}else console.log("Nothing to be removed, aborting removal...")}))},405:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const t=n(304),a=n(147),r=n(518),s=n(584);o.decryptZip=(e,o,n)=>i(void 0,void 0,void 0,(function*(){var i,p,c;(0,a.existsSync)(e)||t.program.error(`Zip not found at the path ${e}`);const l=yield(0,s.getConfig)(),{extConfig:d}=l.app;n.key||(0,a.existsSync)(s.baseKey)||(null===(p=null===(i=d.plugins)||void 0===i?void 0:i.CapacitorUpdater)||void 0===p?void 0:p.privateKey)||t.program.error(`Private Key not found at the path ${s.baseKey} or in ${l.app.extConfigFilePath}`);const u=n.key||s.baseKey;let{privateKey:y}=n.keyData||(null===(c=null==d?void 0:d.plugins)||void 0===c?void 0:c.CapacitorUpdater)||"";(0,a.existsSync)(u)||y?(0,a.existsSync)(u)&&(y=(0,a.readFileSync)(u).toString()):t.program.error(`Cannot find public key ${u} or as keyData option or in ${l.app.extConfigFilePath}`);const g=(0,a.readFileSync)(e),v=(0,r.decryptSource)(g,o,y);(0,a.writeFileSync)(`${e}_decrypted.zip`,v),console.log("Done ✅"),process.exit()}))},178:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteVersion=void 0;const t=n(304),a=n(266),r=n(584),s=n(224);o.deleteVersion=(e,o,n)=>i(void 0,void 0,void 0,(function*(){var i,p;n.apikey=n.apikey||(0,r.findSavedKey)()||"";const c=yield(0,r.getConfig)();e=e||(null===(i=null==c?void 0:c.app)||void 0===i?void 0:i.appId),n.apikey||t.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||t.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,r.createSupabaseClient)(n.apikey),d=yield(0,r.verifyUser)(l,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(l,e,n.apikey);const u=n.apikey||(0,r.findSavedKey)();e=e||(null===(p=null==c?void 0:c.app)||void 0===p?void 0:p.appId),u||t.program.error("Missing API key, you need to provide an API key to delete your app"),o||t.program.error("Missing argument, you need to provide a bundleId, or be in a capacitor project"),e||t.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const{data:y,error:g}=yield l.rpc("exist_app",{appid:e,apikey:u}).single();y&&!g||t.program.error("No permission to delete"),console.log(`Delete ${e}@${o} from Capgo`),yield(0,s.deleteSpecificVersion)(l,e,d,o),console.log(`${e}@${o} deleted from server`),console.log("Done ✅"),process.exit()}))},107:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const t=n(304),a=n(147),r=n(518),s=n(584);o.encryptZip=(e,o)=>i(void 0,void 0,void 0,(function*(){(0,a.existsSync)(e)||t.program.error(`Zip not found at the path ${e}`);const n=o.key||s.baseKeyPub;let i=o.keyData||"";(0,a.existsSync)(n)||i?(0,a.existsSync)(n)&&(i=(0,a.readFileSync)(n).toString()):t.program.error(`Cannot find public key ${n} or as keyData option`);const p=(0,a.readFileSync)(e),c=(0,r.encryptSource)(p,i);console.log("ivSessionKey",c.ivSessionKey),(0,a.writeFileSync)(`${e}_encrypted.zip`,c.encryptedData),console.log("Done ✅"),process.exit()}))},925:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.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(n(844)),r=n(304),s=n(113),p=t(n(295)),c=n(147),l=n(906),d=n(266),u=n(518),y=n(584);o.uploadVersion=(e,o)=>i(void 0,void 0,void 0,(function*(){var n,i,t,g;let{bundle:v,path:f,channel:h}=o;const{external:m,key:b=!1,displayIvSession:k}=o,w=o.apikey||(0,y.findSavedKey)(),_=(0,y.useLogSnag)();h=h||"dev";const x=yield(0,y.getConfig)();e=e||(null===(n=null==x?void 0:x.app)||void 0===n?void 0:n.appId),v=v||(null===(t=null===(i=null==x?void 0:x.app)||void 0===i?void 0:i.package)||void 0===t?void 0:t.version),y.regexSemver.test(v)||r.program.error(`Your bundle name ${v}, is not valid it should follow semver convention : https://semver.org/`),f=f||(null===(g=null==x?void 0:x.app)||void 0===g?void 0:g.webDir),w||r.program.error("Missing API key, you need to provide a API key to upload your bundle"),e&&v&&f||r.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}@${v} started from path "${f}" to Capgo cloud`);const C=(0,y.createSupabaseClient)(w),$=yield(0,y.verifyUser)(C,w,["write","all","upload"]);yield(0,y.checkPlanValid)(C,$,!1),yield(0,d.checkAppExistsAndHasPermission)(C,e,w);const A=new p.default.MultiBar({clearOnComplete:!1,hideCursor:!0},p.default.Presets.shades_grey),S=A.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},p.default.Presets.shades_grey);S.start(7,0,{speed:"N/A"});const{data:P,error:I}=yield C.rpc("exist_app_versions",{apikey:w,name_version:v,appid:e}).single();(P||I)&&(A.stop(),r.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,y.formatError)(I)}`)),S.increment();const{data:D,error:M}=yield C.rpc("is_trial",{userid:$}).single();(D&&D>0||M)&&A.log(`WARNING !!\nTrial expires in ${D} days, upgrade here: ${y.hostWeb}/dashboard/settings/plans\n`),S.increment();const{data:E,error:j}=yield C.rpc("exist_app",{appid:e,apikey:w}).single();E&&!j||(A.stop(),r.program.error(`Cannot find app ${e} in your account \n${(0,y.formatError)(j)}`)),S.increment();const{data:K,error:q}=yield C.rpc("exist_app_versions",{appid:e,apikey:w,name_version:v}).single();(K||q)&&r.program.error(`Version already exists ${(0,y.formatError)(q)}`),S.increment();const U=(0,s.randomUUID)();let V,O="";if(m)m&&!m.startsWith("https://")&&(A.stop(),r.program.error(`External link should should start with "https://" current is "${m}"`));else{const o=new a.default;o.addLocalFolder(f);let n=o.toBuffer();if(O=yield(0,l.checksum)(n,"crc32"),b||(0,c.existsSync)(y.baseKeyPub)){const e="string"==typeof b?b:y.baseKeyPub;(0,c.existsSync)(e)||r.program.error(`Cannot find public key ${e}`);const o=(0,c.readFileSync)(e);A.log("Encrypting your bundle\n");const i=(0,u.encryptSource)(n,o.toString());V=i.ivSessionKey,k&&A.log(`Your Iv Session key is ${V},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),n=i.encryptedData}const i=Math.floor(n.byteLength/1024/1024),t=`apps/${$}/${e}/versions`;S.increment(),i>20&&(A.log(`WARNING !!\nThe app size is ${i} Mb, this may take a while to download for users\n`),A.log("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield _.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":$,"app-id":e},notify:!1}).catch());const{error:s}=yield C.storage.from(t).upload(U,n,{contentType:"application/zip",cacheControl:"2592000"});s&&(A.stop(),r.program.error(`Cannot upload ${(0,y.formatError)(s)}`))}S.increment();const{data:N,error:z}=yield(0,y.updateOrCreateVersion)(C,{bucket_id:m?void 0:U,user_id:$,name:v,app_id:e,session_key:V,external_url:m,checksum:O},w);if(z&&(A.stop(),r.program.error(`Cannot add bundle ${(0,y.formatError)(z)}`)),S.increment(),N){const{error:o}=yield(0,y.updateOrCreateChannel)(C,{name:h,app_id:e,created_by:$,version:N.id},w);o&&A.log("Cannot set bundle with upload key, use key with more rights for that\n")}else A.log("Cannot set bundle with upload key, use key with more rights for that\n");A.stop();const T=(0,y.convertAppName)(e);console.log("App uploaded to server"),console.log(`Try it in mobile app: ${y.host}/app_mobile`),console.log(`Or set the channel ${h} as public here: ${y.hostWeb}/app/package/${T}`),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: ${y.hostWeb}/app/p/${T}/devices`),yield _.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":$,"app-id":e},notify:!1}).catch(),console.log("Done ✅"),process.exit()}))},250:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addChannel=void 0;const t=n(304),a=n(266),r=n(34),s=n(584);o.addChannel=(e,o,n)=>i(void 0,void 0,void 0,(function*(){var i;n.apikey=n.apikey||(0,s.findSavedKey)()||"";const p=yield(0,s.getConfig)();o=o||(null===(i=null==p?void 0:p.app)||void 0===i?void 0:i.appId);const c=(0,s.useLogSnag)();n.apikey||t.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||t.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,s.createSupabaseClient)(n.apikey),d=yield(0,s.verifyUser)(l,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(l,o,n.apikey),console.log(`Create channel ${o}#${e} to Capgo cloud`);try{const{data:n}=yield(0,r.findUnknownVersion)(l,o);n||t.program.error("Cannot find default version for channel creation, please contact Capgo support 🤨"),yield(0,r.createChannel)(l,{name:e,app_id:o,version:n.id,created_by:d}),console.log("Channel created ✅"),yield c.publish({channel:"app",event:"Create channel",icon:"✅",tags:{"user-id":d,"app-id":o,channel:e},notify:!1}).catch()}catch(e){console.log("Cannot create Channel 🙀",e)}console.log("Done ✅"),process.exit()}))},577:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteChannel=void 0;const t=n(304),a=n(266),r=n(34),s=n(584);o.deleteChannel=(e,o,n)=>i(void 0,void 0,void 0,(function*(){var i;n.apikey=n.apikey||(0,s.findSavedKey)()||"";const p=yield(0,s.getConfig)();o=o||(null===(i=null==p?void 0:p.app)||void 0===i?void 0:i.appId);const c=(0,s.useLogSnag)();n.apikey||t.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||t.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,s.createSupabaseClient)(n.apikey),d=yield(0,s.verifyUser)(l,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(l,o,n.apikey),console.log(`Delete channel ${o}#${e} to Capgo cloud`);try{yield(0,r.delChannel)(l,e,o,d),console.log("Channel Delete ✅"),yield c.publish({channel:"app",event:"Delete channel",icon:"✅",tags:{"user-id":d,"app-id":o,channel:e},notify:!1}).catch()}catch(e){console.log("Cannot delete Channel 🙀",e)}console.log("Done ✅"),process.exit()}))},245:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listChannels=void 0;const t=n(304),a=n(266),r=n(34),s=n(584);o.listChannels=(e,o)=>i(void 0,void 0,void 0,(function*(){var n;o.apikey=o.apikey||(0,s.findSavedKey)()||"";const i=yield(0,s.getConfig)();e=e||(null===(n=null==i?void 0:i.app)||void 0===n?void 0:n.appId),o.apikey||t.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||t.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const p=(0,s.createSupabaseClient)(o.apikey),c=yield(0,s.verifyUser)(p,o.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(p,e,o.apikey),console.log("Querying available versions in Capgo"),yield(0,a.checkAppExistsAndHasPermission)(p,e,o.apikey);const l=yield(0,r.getActiveChannels)(p,e,c);console.log(`Active channels in Capgo: ${null==l?void 0:l.length}`),(0,r.displayChannels)(l),console.log("Done ✅"),process.exit()}))},552:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const t=n(304),a=n(266),r=n(584);o.setChannel=(e,o)=>i(void 0,void 0,void 0,(function*(){var n,i,s;o.apikey=o.apikey||(0,r.findSavedKey)()||"";const p=yield(0,r.getConfig)();e=e||(null===(n=null==p?void 0:p.app)||void 0===n?void 0:n.appId);const c=(0,r.useLogSnag)();o.apikey||t.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||t.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,r.createSupabaseClient)(o.apikey),d=yield(0,r.verifyUser)(l,o.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(l,e,o.apikey);const{bundle:u,latest:y,downgrade:g,upgrade:v,ios:f,android:h,selfAssign:m,channel:b,state:k}=o;b||t.program.error("Missing argument, you need to provide a channel"),y&&u&&t.program.error("Cannot set latest and bundle at the same time"),null==u&&null==k&&null==y&&null==g&&null==v&&null==f&&null==h&&null==m&&t.program.error("Missing argument, you need to provide a option to set");try{yield(0,r.checkPlanValid)(l,d),yield(0,a.checkAppExistsAndHasPermission)(l,e,o.apikey);const n={created_by:d,app_id:e,name:b,version:void 0},w=y?null===(s=null===(i=null==p?void 0:p.app)||void 0===i?void 0:i.package)||void 0===s?void 0:s.version:u;if(null!=w){const{data:o,error:i}=yield l.from("app_versions").select().eq("app_id",e).eq("name",w).eq("user_id",d).eq("deleted",!1).single();!i&&o||t.program.error(`Cannot find version ${w}`),console.log(`Set ${e} channel: ${b} to @${w}`),n.version=o.id}null!=k&&("public"!==k&&"private"!==k||console.log(`Set ${e} channel: ${b} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${b} to ${"public"===k||"default"===k?"default":"normal"}`),n.public="public"===k||"default"===k),null!=g&&(console.log(`Set ${e} channel: ${b} to ${g?"allow":"disallow"} downgrade`),n.disableAutoUpdateUnderNative=!g),null!=v&&(console.log(`Set ${e} channel: ${b} to ${v?"allow":"disallow"} upgrade`),n.disableAutoUpdateToMajor=!v),null!=f&&(console.log(`Set ${e} channel: ${b} to ${f?"allow":"disallow"} ios update`),n.ios=!!f),null!=h&&(console.log(`Set ${e} channel: ${b} to ${h?"allow":"disallow"} android update`),n.android=!!h),null!=m&&(console.log(`Set ${e} channel: ${b} to ${m?"allow":"disallow"} self assign to this channel`),n.allow_device_self_set=!!m);try{const{error:e}=yield(0,r.updateOrCreateChannel)(l,n,o.apikey);e&&t.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}catch(e){t.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}yield c.publish({channel:"app",event:"Set app",icon:"✅",tags:{"user-id":d,"app-id":e},notify:!1}).catch()}catch(e){t.program.error(`Unknow error ${(0,r.formatError)(e)}`)}console.log("Done ✅"),process.exit()}))},908:function(e,o,n){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0});const t=n(304),a=n(405),r=n(107),s=n(140),p=n(683),c=n(178),l=n(552),d=n(925),u=i(n(598)),y=n(794),g=n(465),v=n(61),f=n(250),h=n(577),m=n(245),b=n(515),k=n(321);t.program.description("Manage packages and bundle versions in capgo Cloud").version(u.default.version),t.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(y.login).option("--local","Only save in local folder");const w=t.program.command("app").description("Manage app");w.command("add [appid]").alias("a").description("Add a new app in capgo Cloud").action(s.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),w.command("delete [appid]").alias("d").description("Delete an app in capgo Cloud").action(k.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account"),w.command("list [appid]").alias("l").description("list apps in capgo Cloud").action(g.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),w.command("set [appid]").alias("s").description("Set an app in capgo Cloud").action(b.setApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account");const _=t.program.command("bundle").description("Manage bundle");_.command("upload [appid]").alias("u").description("Upload a new bundle in capgo Cloud").action(d.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder 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("--key <key>","custom path for public signing key").option("--keyData <keyData>","base64 public signing key").option("--no-key","ignore signing key and send clear update").option("--display-iv-session","Show in the console the iv and session key used to encrypt the update").option("-b, --bundle <bundle>","bundle version number of the file to upload"),_.command("delete [appid]").alias("d").description("Delete a bundle in capgo Cloud").action(c.deleteVersion).option("-a, --apikey <apikey>","apikey to link to your account"),_.command("list [appid]").alias("l").description("List bundle in capgo Cloud").action(g.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),_.command("cleanup [appid]").alias("c").action(v.cleanupApp).description("Cleanup bundle in capgo Cloud").option("-b, --bundle <bundle>","bundle version number of the app to delete").option("-a, --apikey <apikey>","apikey to link to your account").option("-k, --keep <keep>","number of version to keep").option("-f, --force","force removal"),_.command("decrypt [zipPath] [sessionKey]").alias("l").description("Decrypt a signed zip bundle").action(a.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),_.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(r.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key");const x=t.program.command("channel").description("Manage channel");x.command("add [channelid] [appid]").alias("a").description("Create channel").action(f.addChannel),x.command("delete [channelid] [appid]").alias("d").description("Delete channel").action(h.deleteChannel),x.command("list [appid]").alias("l").description("List channel").action(m.listChannels),x.command("set [channelid] [appid]").alias("s").description("Set channel").action(l.setChannel).option("-a, --apikey <apikey>","apikey to link to your account").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("--latest","get the latest version key in the package.json to set it to the channel").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"),t.program.command("key [option]").description("Save base64 signing key in capacitor config, usefull for CI").action(p.manageKey).option("-f, --force","force generate a new one"),t.program.parseAsync()},683:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.manageKey=void 0;const t=n(304),a=n(147),r=n(778),s=n(518),p=n(584);o.manageKey=(e,o)=>i(void 0,void 0,void 0,(function*(){var n,c;"save"===e?(n=o.key,c=o.keyData,i(void 0,void 0,void 0,(function*(){(0,a.existsSync)(".git")||t.program.error("To use local you should be in a git repository");const e=yield(0,p.getConfig)(),{extConfig:o}=e.app,i=n||p.baseKey;let s=c||"";(0,a.existsSync)(i)||s?(0,a.existsSync)(i)&&(s=(0,a.readFileSync)(i).toString()):t.program.error(`Cannot find public key ${i} or as keyData option or in ${e.app.extConfigFilePath}`),o&&(o.plugins||(o.plugins={}),o.plugins.CapacitorUpdater||(o.plugins.CapacitorUpdater={}),o.plugins.CapacitorUpdater.privateKey=s,(0,r.writeConfig)(o,e.app.extConfigFilePath)),console.log(`private key saved into ${e.app.extConfigFilePath} file in local directory`),console.log("your app will decode the zip archive with this key\n")}))):"create"===e?(e=>{i(void 0,void 0,void 0,(function*(){(0,a.existsSync)(".git")||t.program.error("To use local you should be in a git repository");const{publicKey:o,privateKey:n}=(0,s.createRSA)();(0,a.existsSync)(p.baseKeyPub)&&!e.force&&t.program.error("Public Key already exists, use --force to overwrite"),(0,a.writeFileSync)(p.baseKeyPub,o),(0,a.existsSync)(p.baseKey)&&!e.force&&t.program.error("Private Key already exists, use --force to overwrite"),(0,a.writeFileSync)(p.baseKey,n);const i=yield(0,p.getConfig)(),{extConfig:c}=i.app;c&&(c.plugins||(c.plugins={}),c.plugins.CapacitorUpdater||(c.plugins.CapacitorUpdater={}),c.plugins.CapacitorUpdater.privateKey=n,(0,r.writeConfig)(c,i.app.extConfigFilePath)),console.log("Your RSA key has been generated using node-rsa with this settings:\n\n- encryptionScheme — 'pkcs1_oaep'.\n- signingScheme — 'pkcs8-sha256'.\n- bits — 2048.\n- exp — 65537.\n"),console.log(`public key saved into ${p.baseKeyPub} file in local directory\n`),console.log("This key will be use to encode your zipped bundle before sending it to Capgo,\nthan make them unreadable by Capgo and unmodifiable by anyone\n"),console.log(`Private key saved into ${i.app.extConfigFilePath} file in local directory`),console.log("Your app will decode with this key the zipped bundle\n")}))})(o):t.program.error("You should provide a valid option (create or save)"),process.exit()}))},794:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.login=void 0;const t=n(304),a=n(147),r=n(37),s=n(584);o.login=(e,o)=>i(void 0,void 0,void 0,(function*(){try{const{local:n}=o,i=(0,s.useLogSnag)();if(n)(0,a.existsSync)(".git")||t.program.error("To use local you should be in a git repository"),(0,a.writeFileSync)(".capgo",`${e}\n`),(0,a.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,r.homedir)();(0,a.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const p=(0,s.createSupabaseClient)(e),c=yield(0,s.verifyUser)(p,e,["write","all","upload"]);yield i.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":c},notify:!1}).catch(),console.log(`login saved into .capgo file in ${n?"local":"home"} directory`)}catch(e){console.error(e),process.exit(1)}process.exit()}))},584:function(e,o,n){var i=this&&this.__awaiter||function(e,o,n,i){return new(n||(n=Promise))((function(t,a){function r(e){try{p(i.next(e))}catch(e){a(e)}}function s(e){try{p(i.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?t(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((i=i.apply(e,o||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getHumanDate=o.verifyUser=o.convertAppName=o.useLogSnag=o.updateOrCreateChannel=o.updateOrCreateVersion=o.getConfig=o.formatError=o.findSavedKey=o.checkPlanValid=o.isAllowedAction=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.supaAnon=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=void 0;const a=n(778),r=n(304),s=n(885),p=t(n(867)),c=n(147),l=n(37),d=n(133);o.baseKey=".capgo_key",o.baseKeyPub=`${o.baseKey}.pub`,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,{global:{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,n,t)=>i(void 0,void 0,void 0,(function*(){const{data:i,error:a}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:t}).single();i&&!a||r.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(a)}`)})),o.isGoodPlan=(e,o)=>i(void 0,void 0,void 0,(function*(){const{data:n,error:i}=yield e.rpc("is_good_plan_v2",{userid:o}).single();if(i)throw i;return n||!1})),o.isPaying=(e,o)=>i(void 0,void 0,void 0,(function*(){const{data:n,error:i}=yield e.rpc("is_paying",{userid:o}).single();if(i)throw i;return n||!1})),o.isTrial=(e,o)=>i(void 0,void 0,void 0,(function*(){const{data:n,error:i}=yield e.rpc("is_trial",{userid:o}).single();if(i)throw i;return n||0})),o.isAllowedAction=(e,o)=>i(void 0,void 0,void 0,(function*(){const{data:n,error:i}=yield e.rpc("is_allowed_action_user",{userid:o}).single();if(i)throw i;return n})),o.checkPlanValid=(e,n,t=!0)=>i(void 0,void 0,void 0,(function*(){(yield(0,o.isAllowedAction)(e,n))||r.program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`);const i=yield(0,o.isTrial)(e,n);i>0&&t&&console.log(`WARNING !!\nTrial expires in ${i} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e=`${(0,l.homedir)()}/.capgo`;return(0,c.existsSync)(e)?(console.log(`Use global apy key ${e}`),(0,c.readFileSync)(e,"utf8").trim()):(e=".capgo",(0,c.existsSync)(e)?(console.log(`Use local apy key ${e}`),(0,c.readFileSync)(e,"utf8").trim()):null)},o.formatError=e=>e?`\n${p.default.render(e)}`:"",o.getConfig=()=>i(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,a.loadConfig)()}catch(e){r.program.error("No capacitor config file found, run `cap init` first")}return e})),o.updateOrCreateVersion=(e,o,n)=>i(void 0,void 0,void 0,(function*(){const{data:i,error:t}=yield e.rpc("exist_app_versions",{appid:o.app_id,name_version:o.name,apikey:n}).single();return i&&!t?(o.deleted=!1,e.from("app_versions").update(o).eq("app_id",o.app_id).eq("name",o.name).single()):e.from("app_versions").insert(o).select().single()})),o.updateOrCreateChannel=(e,o,n)=>i(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:i,error:t}=yield e.rpc("exist_channel",{appid:o.app_id,name_channel:o.name,apikey:n}).single();return i&&!t?e.from("channels").update(o).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by).single():e.from("channels").insert(o).select().single()})),o.useLogSnag=()=>new d.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.convertAppName=e=>e.replace(/\./g,"--"),o.verifyUser=(e,n,t=["all"])=>i(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,n,t);const{data:i,error:a}=yield e.rpc("get_user_id",{apikey:n}).single(),s=i?i.toString():"";return s&&!a||r.program.error(`Cannot verify user ${(0,o.formatError)(a)}`),s})),o.getHumanDate=e=>new Date(e||"").toLocaleString()},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")},847:e=>{e.exports=require("console-table-printer")},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")},616:e=>{e.exports=require("prompt-sync")},505:e=>{e.exports=require("semver/preload")},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":"3.0.0-alpha.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"},"engines":{"npm":">=7.0.0","node":">=16.0.0"},"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","test":"npx --yes ts-node -T src/index.ts","build":"npx --yes webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","types":"npx --yes supabase gen types typescript --project-id=xvwzpoazmxkqosrdewyv > src/types/supabase.types.ts","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.6.2","@supabase/supabase-js":"^2.5.0","@tomasklaen/checksum":"^1.1.0","adm-zip":"^0.5.10","cli-progress":"3.11.2","commander":"10.0.0","console-table-printer":"^2.11.1","fs-extra":"11.1.0","logsnag":"^0.1.6","mime":"^3.0.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","semver":"^7.3.8"},"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.18","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/semver":"^7.3.13","@typescript-eslint/eslint-plugin":"5.47.1","@typescript-eslint/parser":"5.47.1","eslint":"8.33.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.6.0","eslint-import-resolver-typescript":"3.5.3","eslint-plugin-import":"2.27.5","eslint-plugin-prettier":"^4.2.1","git-format-staged":"3.0.0","husky":"^8.0.3","nodemon":"2.0.20","pkg":"5.8.0","prettier":"2.8.3","ts-loader":"^9.4.2","ts-node":"^10.9.1","tsconfig-paths":"4.1.2","typescript":"4.9.4","webpack":"5.75.0","webpack-cli":"^5.0.1","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(i){var t=o[i];if(void 0!==t)return t.exports;var a=o[i]={exports:{}};return e[i].call(a.exports,a,a.exports,n),a.exports}(908)})();
2
+ (()=>{"use strict";var e={642:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.newIconPath=o.checkAppExistsAndHasPermission=void 0;const i=n(304);o.checkAppExistsAndHasPermission=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.rpc("exist_app",{appid:o,apikey:n}).single();t&&!a||i.program.error("No permission for this app")})),o.newIconPath="assets/icon.png"},860:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getActiveChannels=o.displayChannels=o.delChannel=o.createChannel=o.findUnknownVersion=o.checkVersionNotUsedInChannel=void 0;const i=n(304),a=n(847),r=n(246);o.checkVersionNotUsedInChannel=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:s}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).eq("version",a.id);if(s&&i.program.error(`Cannot check Version ${o}@${a.name} ${(0,r.formatError)(s)}`),t&&t.length>0){const e=(0,r.convertAppName)(o);i.program.error(`❌ Version ${o}@${a.name} is used in channel ${t[0].name}, unlink it first:\nhttps://web.capgo.app/app/p/${e}/channel/${t[0].id}\nClick on top right button and unlink.\n${(0,r.formatError)(s)}`)}})),o.findUnknownVersion=(e,o)=>e.from("app_versions").select("id").eq("app_id",o).eq("name","unknown").single(),o.createChannel=(e,o)=>e.from("channels").insert(o).select().single(),o.delChannel=(e,o,n,t)=>e.from("channels").delete().eq("name",o).eq("app_id",n).eq("user_id",t).single(),o.displayChannels=e=>{const o=new a.Table({title:"Channels",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,r.getHumanDate)(e.created_at),Public:e.public?"✅":"❌"})})),o.printTable()},o.getActiveChannels=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.from("channels").select().eq("app_id",o).eq("user_id",n).order("created_at",{ascending:!1});return a&&i.program.error(`App ${o} not found in database ${(0,r.formatError)(a)} `),t}))},213:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createRSA=o.encryptSource=o.decryptSource=void 0;const t=n(113),i="aes-128-cbc",a="sha256",r="base64",s=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[p,c]=o.split(":"),l=(0,t.privateDecrypt)({key:n,padding:s,oaepHash:a},Buffer.from(c,r)),d=Buffer.from(p,r),u=l.toString(r);console.log("\nSessionB64",u);const y=(0,t.createDecipheriv)(i,l,d);return y.setAutoPadding(!0),Buffer.concat([y.update(e),y.final()])},o.encryptSource=(e,o)=>{const n=(0,t.randomBytes)(16),p=(0,t.randomBytes)(16),c=(0,t.createCipheriv)(i,p,n);c.setAutoPadding(!0);const l=`${n.toString(r)}:${(0,t.publicEncrypt)({key:o,padding:s,oaepHash:a},p).toString(r)}`;return{encryptedData:Buffer.concat([c.update(e),c.final()]),ivSessionKey:l}},o.createRSA=()=>{const{publicKey:e,privateKey:o}=(0,t.generateKeyPairSync)("rsa",{modulusLength:2048});return{publicKey:e.export({type:"pkcs1",format:"pem"}),privateKey:o.export({type:"pkcs1",format:"pem"})}}},933:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const i=n(304),a=n(246);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:r}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);if(r&&i.program.error(`Cannot check Device override ${o}@${n.name} ${(0,a.formatError)(r)}`),t&&t.length>0){const e=(0,a.convertAppName)(o);i.program.error(`❌ Version ${o} @${n.name} is used in a device override, unlink it first:\nhttps://web.capgo.app/app/p/${e}/d/${t[0].device_id}\n${(0,a.formatError)(r)}`)}}))},350:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(304),a=n(246);o.deleteFromStorage=(e,o,n,r,s)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${r.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${s} ${(0,a.formatError)(t)} `)}))},484:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.checkLatest=void 0;const a=i(n(362)),r=i(n(598));o.checkLatest=()=>t(void 0,void 0,void 0,(function*(){const e=yield(0,a.default)("@capgo/cli");e!==r.default.version&&console.log("%s",`🚨 You are using @capgo/cli@${r.default.version} it's not the latest version.\nPlease use @capgo/cli@${e}" or @capgo/cli@latest to keep up to date with the latest features and bug fixes.`)}))},89:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getVersionData=o.getActiveAppVersions=o.displayBundles=o.deleteSpecificVersion=o.deleteAppVersion=void 0;const i=n(304),a=n(847),r=n(246),s=n(860),p=n(933),c=n(350);o.deleteAppVersion=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("deleted",!1).eq("user_id",n).eq("name",a);t&&i.program.error(`App Version ${o}@${a} not found in database '${(0,r.formatError)(t)}'`)})),o.deleteSpecificVersion=(e,n,i,a)=>t(void 0,void 0,void 0,(function*(){const t=yield(0,o.getVersionData)(e,n,i,a);yield(0,s.checkVersionNotUsedInChannel)(e,n,i,t),yield(0,p.checkVersionNotUsedInDeviceOverride)(e,n,t),yield(0,c.deleteFromStorage)(e,i,n,t,a),yield(0,o.deleteAppVersion)(e,n,i,a)})),o.displayBundles=e=>{const o=new a.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,r.getHumanDate)(e.created_at)},null!=e.keep?{Keep:e.keep}:{}))})),o.printTable()},o.getActiveAppVersions=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return a&&i.program.error(`App ${o} not found in database ${(0,r.formatError)(a)} `),t})),o.getVersionData=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:s}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("name",a).eq("deleted",!1).single();return t&&!s||i.program.error(`App Version ${o}@${a} doesn't exist ${(0,r.formatError)(s)}`),t}))},124:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const i=n(11),a=n(304),r=n(113),s=n(470),p=n(484),c=n(642),l=n(246);o.addApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,d;yield(0,p.checkLatest)(),o.apikey=o.apikey||(0,l.findSavedKey)()||"";const u=yield(0,l.getConfig)();e=e||(null===(n=null==u?void 0:u.app)||void 0===n?void 0:n.appId);const y=(0,l.useLogSnag)();o.apikey||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||a.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const g=(0,l.createSupabaseClient)(o.apikey),v=yield(0,l.verifyUser)(g,o.apikey,["write","all"]);yield(0,c.checkAppExistsAndHasPermission)(g,e,o.apikey);let f,h,{name:m,icon:k}=o;e=e||(null===(t=null==u?void 0:u.app)||void 0===t?void 0:t.appId),m=m||(null===(d=null==u?void 0:u.app)||void 0===d?void 0:d.appName)||"Unknown",k=k||"resources/icon.png",k&&m||a.program.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project"),console.log(`Adding ${e} to Capgo`),k&&(0,s.existsSync)(k)?(f=(0,s.readFileSync)(k),h=(0,i.getType)(k)||"image/png",console.warn(`Found app icon ${k}`)):(0,s.existsSync)(c.newIconPath)?(f=(0,s.readFileSync)(c.newIconPath),h=(0,i.getType)(c.newIconPath)||"image/png",console.warn(`Found app icon ${c.newIconPath}`)):console.warn(`Cannot find app icon in any of the following locations: ${k}, ${c.newIconPath}`);const{data:b,error:w}=yield g.rpc("exist_app_v2",{appid:e}).single();(b||w)&&a.program.error(`App ${e} already exists ${(0,l.formatError)(w)}`);const _=`icon_${(0,r.randomUUID)()}`;let x="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(f&&h){const{error:o}=yield g.storage.from(`images/${v}/${e}`).upload(_,f,{contentType:h});o&&a.program.error(`Could not add app ${(0,l.formatError)(o)}`);const{data:n}=yield g.storage.from(`images/${v}/${e}`).getPublicUrl(_);x=(null==n?void 0:n.publicUrl)||x}const{error:C}=yield g.from("apps").insert({icon_url:x,user_id:v,name:m,app_id:e});C&&a.program.error(`Could not add app ${(0,l.formatError)(C)}`);const{error:$}=yield g.from("app_versions").insert([{user_id:v,deleted:!0,name:"unknown",app_id:e},{user_id:v,deleted:!0,name:"builtin",app_id:e}]);$&&a.program.error(`Could not add app ${(0,l.formatError)($)}`),yield y.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":v,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now"),console.log("Done ✅"),process.exit()}))},10:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const i=n(304),a=n(642),r=n(246);o.deleteApp=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t;n.apikey=n.apikey||(0,r.findSavedKey)()||"";const s=yield(0,r.getConfig)();e=e||(null===(t=null==s?void 0:s.app)||void 0===t?void 0:t.appId);const p=(0,r.useLogSnag)();n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const c=(0,r.createSupabaseClient)(n.apikey);yield(0,r.verifyUser)(c,n.apikey,["write","all"]),yield(0,a.checkAppExistsAndHasPermission)(c,e,n.apikey);const{error:l}=yield c.storage.from(`images/${o}`).remove([e]);l&&i.program.error(`Could not add app ${(0,r.formatError)(l)}`);const{error:d}=yield c.storage.from(`apps/${e}/${o}`).remove(["versions"]);d&&i.program.error(`Could not delete app version ${(0,r.formatError)(d)}`);const{error:u}=yield c.from("apps").delete().eq("app_id",e).eq("user_id",o);u&&i.program.error(`Could not delete app ${(0,r.formatError)(u)}`),yield p.publish({channel:"app",event:"App Deleted",icon:"🗑️",tags:{"user-id":o,"app-id":e},notify:!1}).catch(),console.log("App deleted in Capgo"),console.log("Done ✅"),process.exit()}))},90:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getInfo=void 0;const a=n(147),r=i(n(362)),s=n(17),p=i(n(176)),c=i(n(598));o.getInfo=()=>t(void 0,void 0,void 0,(function*(){console.log(" 💊 Capgo Doctor 💊"),console.log("\n"),console.log(" Installed Dependencies:"),console.log("\n");const e=yield t(void 0,void 0,void 0,(function*(){const{dependencies:e}=yield t(void 0,void 0,void 0,(function*(){const e=(0,a.readFileSync)((0,s.join)(process.cwd(),"package.json"));return JSON.parse(e)})),o={"@capgo/cli":c.default.version};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&n.startsWith("@capgo/")&&(o[n]=e[n]);return o}));0===Object.keys(e).length&&(console.log("\n"),console.log("%s","🚨 No dependencies found"),process.exit(1));for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const n=e[o];console.log(` ${o}: ${n}`)}console.log("\n");const o=new p.default;o.add("loading",{text:"Loading latest dependencies"});const n=yield(e=>t(void 0,void 0,void 0,(function*(){const o={},n=[];for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.push((0,r.default)(o));return yield Promise.all(n).then((n=>{const t=Object.keys(e);for(let e=0;e<n.length;e+=1){const i=n[e];i&&(o[t[e]]=i)}})),o})))(e);o.succeed("loading",{text:"Latest Dependencies:"}),console.log("\n");for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const o=n[e];console.log(` ${e}: ${o}`)}JSON.stringify(e)!==JSON.stringify(n)&&(console.log("\n"),console.log("%s","🚨 Some dependencies are not up to date"),process.exit(1)),console.log("\n"),console.log("%s","✅ All dependencies are up to date"),process.exit()}))},367:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const i=n(304),a=n(642),r=n(89),s=n(246),p=n(484);o.listApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;yield(0,p.checkLatest)();const t=o.apikey||(0,s.findSavedKey)(),c=yield(0,s.getConfig)();console.log('COMMAND DEPRECATED, use "app list" instead'),e=e||(null===(n=null==c?void 0:c.app)||void 0===n?void 0:n.appId),t||i.program.error("Missing API key, you need to provide an API key to delete your app"),e||i.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),console.log("Querying available versions in Capgo");const l=(0,s.createSupabaseClient)(t),d=yield(0,s.verifyUser)(l,t);console.log("Querying available versions in Capgo"),yield(0,a.checkAppExistsAndHasPermission)(l,e,o.apikey);const u=yield(0,r.getActiveAppVersions)(l,e,d);console.log(`Active versions in Capgo: ${null==u?void 0:u.length}`),(0,r.displayBundles)(u),console.log("Done ✅"),process.exit()}))},444:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setApp=void 0;const i=n(11),a=n(304),r=n(113),s=n(470),p=n(642),c=n(246);o.setApp=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t;n.apikey=n.apikey||(0,c.findSavedKey)()||"";const l=yield(0,c.getConfig)();e=e||(null===(t=null==l?void 0:l.app)||void 0===t?void 0:t.appId),n.apikey||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||a.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const d=(0,c.createSupabaseClient)(n.apikey);yield(0,c.verifyUser)(d,n.apikey,["write","all"]),yield(0,p.checkAppExistsAndHasPermission)(d,e,n.apikey);const{name:u,icon:y}=n;let g,v;const f=`icon_${(0,r.randomUUID)()}`;let h="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(y&&(0,s.existsSync)(y)?(g=(0,s.readFileSync)(y),v=(0,i.getType)(y)||"image/png",console.warn(`Found app icon ${y}`)):(0,s.existsSync)(p.newIconPath)?(g=(0,s.readFileSync)(p.newIconPath),v=(0,i.getType)(p.newIconPath)||"image/png",console.warn(`Found app icon ${p.newIconPath}`)):console.warn(`Cannot find app icon in any of the following locations: ${y}, ${p.newIconPath}`),g&&v){const{error:n}=yield d.storage.from(`images/${o}/${e}`).upload(f,g,{contentType:v});n&&a.program.error(`Could not add app ${(0,c.formatError)(n)}`);const{data:t}=yield d.storage.from(`images/${o}/${e}`).getPublicUrl(f);h=(null==t?void 0:t.publicUrl)||h}const{error:m}=yield d.from("apps").update({icon_url:h,name:u}).eq("app_id",e).eq("user_id",o);m&&a.program.error(`Could not add app ${(0,c.formatError)(m)}`),console.log("Done ✅"),process.exit()}))},957:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))},i=this&&this.__asyncValues||function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),o={},t("next"),t("throw"),t("return"),o[Symbol.asyncIterator]=function(){return this},o);function t(n){o[n]=e[n]&&function(o){return new Promise((function(t,i){!function(e,o,n,t){Promise.resolve(t).then((function(o){e({value:o,done:n})}),o)}(t,i,(o=e[n](o)).done,o.value)}))}}},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupApp=void 0;const r=n(304),s=a(n(505)),p=a(n(616)),c=n(246),l=n(89),d=n(642),u=n(484),y=(0,p.default)();o.cleanupApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;yield(0,u.checkLatest)();const a=o.apikey||(0,c.findSavedKey)(),{bundle:p,keep:g=4}=o,v=o.force||!1,f=yield(0,c.getConfig)();e=e||(null===(n=null==f?void 0:f.app)||void 0===n?void 0:n.appId),a||r.program.error("Missing API key, you need to provide an API key to delete your app"),e||r.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const h=(0,c.createSupabaseClient)(a),m=yield(0,c.verifyUser)(h,a);yield(0,d.checkAppExistsAndHasPermission)(h,e,a),console.log("Querying all available versions in Capgo");let k=yield(0,l.getActiveAppVersions)(h,e,m);if(console.log(`Total active versions in Capgo: ${null==k?void 0:k.length}`),0===(null==k?void 0:k.length))return void console.log("No versions found, aborting cleanup");if(p){const e=`${s.default.inc(p,"major")}`;console.log(`Querying available versions in Capgo between ${p} and ${e}`),k=((e,o,n)=>{const t=[];return null==e||e.forEach((e=>{s.default.gte(e.name,o)&&s.default.lt(e.name,`${n}`)&&t.push(e)})),t})(k,p,e),console.log(`Active versions in Capgo between ${p} and ${e}: ${null==k?void 0:k.length}`)}const b=[];if(k.forEach(((e,o)=>{o<g?e.keep="✅":(e.keep="❌",b.push(e))})),0!==b.length){if((0,l.displayBundles)(k),!v&&"yes"!==y("Do you want to continue removing the versions specified? Type yes to confirm: "))return void console.log("Not confirmed, aborting removal...");console.log("You have confirmed removal, removing versions now"),yield((e,o,n,a)=>{var r,s,p;return t(void 0,void 0,void 0,(function*(){var t,d,u,y;try{for(r=!0,s=i(e);!(t=(p=yield s.next()).done);){y=p.value,r=!1;try{const e=y;console.log(`Removing ${e.name} created on ${(0,c.getHumanDate)(e.created_at)}`),yield(0,l.deleteSpecificVersion)(o,n,a,e.name)}finally{r=!0}}}catch(e){d={error:e}}finally{try{r||t||!(u=s.return)||(yield u.call(s))}finally{if(d)throw d.error}}}))})(b,h,e,m),console.log("Done ✅"),process.exit()}else console.log("Nothing to be removed, aborting removal...")}))},628:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const i=n(304),a=n(147),r=n(213),s=n(246),p=n(484);o.decryptZip=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,c,l;yield(0,p.checkLatest)(),(0,a.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const d=yield(0,s.getConfig)(),{extConfig:u}=d.app;n.key||(0,a.existsSync)(s.baseKey)||(null===(c=null===(t=u.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===c?void 0:c.privateKey)||i.program.error(`Private Key not found at the path ${s.baseKey} or in ${d.app.extConfigFilePath}`);const y=n.key||s.baseKey;let{privateKey:g}=n.keyData||(null===(l=null==u?void 0:u.plugins)||void 0===l?void 0:l.CapacitorUpdater)||"";(0,a.existsSync)(y)||g?(0,a.existsSync)(y)&&(g=(0,a.readFileSync)(y).toString()):i.program.error(`Cannot find public key ${y} or as keyData option or in ${d.app.extConfigFilePath}`);const v=(0,a.readFileSync)(e),f=(0,r.decryptSource)(v,o,g);(0,a.writeFileSync)(`${e}_decrypted.zip`,f),console.log("Done ✅"),process.exit()}))},6:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteVersion=void 0;const i=n(304),a=n(642),r=n(246),s=n(89);o.deleteVersion=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,p;n.apikey=n.apikey||(0,r.findSavedKey)()||"";const c=yield(0,r.getConfig)();e=e||(null===(t=null==c?void 0:c.app)||void 0===t?void 0:t.appId),n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,r.createSupabaseClient)(n.apikey),d=yield(0,r.verifyUser)(l,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(l,e,n.apikey);const u=n.apikey||(0,r.findSavedKey)();e=e||(null===(p=null==c?void 0:c.app)||void 0===p?void 0:p.appId),u||i.program.error("Missing API key, you need to provide an API key to delete your app"),o||i.program.error("Missing argument, you need to provide a bundleId, or be in a capacitor project"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const{data:y,error:g}=yield l.rpc("exist_app",{appid:e,apikey:u}).single();y&&!g||i.program.error("No permission to delete"),console.log(`Delete ${e}@${o} from Capgo`),yield(0,s.deleteSpecificVersion)(l,e,d,o),console.log(`${e}@${o} deleted from server`),console.log("Done ✅"),process.exit()}))},278:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const i=n(304),a=n(147),r=n(484),s=n(213),p=n(246);o.encryptZip=(e,o)=>t(void 0,void 0,void 0,(function*(){yield(0,r.checkLatest)(),(0,a.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const n=o.key||p.baseKeyPub;let t=o.keyData||"";(0,a.existsSync)(n)||t?(0,a.existsSync)(n)&&(t=(0,a.readFileSync)(n).toString()):i.program.error(`Cannot find public key ${n} or as keyData option`);const c=(0,a.readFileSync)(e),l=(0,s.encryptSource)(c,t);console.log("ivSessionKey",l.ivSessionKey),(0,a.writeFileSync)(`${e}_encrypted.zip`,l.encryptedData),console.log("Done ✅"),process.exit()}))},883:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadVersion=void 0;const a=i(n(844)),r=n(304),s=n(113),p=i(n(295)),c=n(147),l=n(906),d=n(484),u=n(642),y=n(213),g=n(246);o.uploadVersion=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,i,v;yield(0,d.checkLatest)();let{bundle:f,path:h,channel:m}=o;const{external:k,key:b=!1,displayIvSession:w}=o,_=o.apikey||(0,g.findSavedKey)(),x=(0,g.useLogSnag)();m=m||"dev";const C=yield(0,g.getConfig)();e=e||(null===(n=null==C?void 0:C.app)||void 0===n?void 0:n.appId),f=f||(null===(i=null===(t=null==C?void 0:C.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version),g.regexSemver.test(f)||r.program.error(`Your bundle name ${f}, is not valid it should follow semver convention : https://semver.org/`),h=h||(null===(v=null==C?void 0:C.app)||void 0===v?void 0:v.webDir),_||r.program.error("Missing API key, you need to provide a API key to upload your bundle"),e&&f&&h||r.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}@${f} started from path "${h}" to Capgo cloud`);const $=(0,g.createSupabaseClient)(_),A=yield(0,g.verifyUser)($,_,["write","all","upload"]);yield(0,g.checkPlanValid)($,A,!1),yield(0,u.checkAppExistsAndHasPermission)($,e,_);const S=new p.default.MultiBar({clearOnComplete:!1,hideCursor:!0},p.default.Presets.shades_grey),P=S.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},p.default.Presets.shades_grey);P.start(7,0,{speed:"N/A"});const{data:I,error:D}=yield $.rpc("exist_app_versions",{apikey:_,name_version:f,appid:e}).single();(I||D)&&(S.stop(),r.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,g.formatError)(D)}`)),P.increment();const{data:M,error:j}=yield $.rpc("is_trial",{userid:A}).single();(M&&M>0||j)&&S.log(`WARNING !!\nTrial expires in ${M} days, upgrade here: ${g.hostWeb}/dashboard/settings/plans\n`),P.increment();const{data:E,error:q}=yield $.rpc("exist_app",{appid:e,apikey:_}).single();E&&!q||(S.stop(),r.program.error(`Cannot find app ${e} in your account \n${(0,g.formatError)(q)}`)),P.increment();const{data:K,error:O}=yield $.rpc("exist_app_versions",{appid:e,apikey:_,name_version:f}).single();(K||O)&&r.program.error(`Version already exists ${(0,g.formatError)(O)}`),P.increment();const U=(0,s.randomUUID)();let V,N="";if(k)k&&!k.startsWith("https://")&&(S.stop(),r.program.error(`External link should should start with "https://" current is "${k}"`));else{const o=new a.default;o.addLocalFolder(h);let n=o.toBuffer();if(N=yield(0,l.checksum)(n,"crc32"),b||(0,c.existsSync)(g.baseKeyPub)){const e="string"==typeof b?b:g.baseKeyPub;(0,c.existsSync)(e)||r.program.error(`Cannot find public key ${e}`);const o=(0,c.readFileSync)(e);S.log("Encrypting your bundle\n");const t=(0,y.encryptSource)(n,o.toString());V=t.ivSessionKey,w&&S.log(`Your Iv Session key is ${V},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),n=t.encryptedData}const t=Math.floor(n.byteLength/1024/1024),i=`apps/${A}/${e}/versions`;P.increment(),t>20&&(S.log(`WARNING !!\nThe app size is ${t} Mb, this may take a while to download for users\n`),S.log("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield x.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":A,"app-id":e},notify:!1}).catch());const{error:s}=yield $.storage.from(i).upload(U,n,{contentType:"application/zip",cacheControl:"2592000"});s&&(S.stop(),r.program.error(`Cannot upload ${(0,g.formatError)(s)}`))}P.increment();const{data:z,error:F}=yield(0,g.updateOrCreateVersion)($,{bucket_id:k?void 0:U,user_id:A,name:f,app_id:e,session_key:V,external_url:k,checksum:N},_);if(F&&(S.stop(),r.program.error(`Cannot add bundle ${(0,g.formatError)(F)}`)),P.increment(),z){const{error:o}=yield(0,g.updateOrCreateChannel)($,{name:m,app_id:e,created_by:A,version:z.id},_);o&&S.log("Cannot set bundle with upload key, use key with more rights for that\n")}else S.log("Cannot set bundle with upload key, use key with more rights for that\n");S.stop();const T=(0,g.convertAppName)(e);console.log("App uploaded to server"),console.log(`Try it in mobile app: ${g.host}/app_mobile`),console.log(`Or set the channel ${m} as public here: ${g.hostWeb}/app/package/${T}`),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: ${g.hostWeb}/app/p/${T}/devices`),yield x.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":A,"app-id":e},notify:!1}).catch(),console.log("Done ✅"),process.exit()}))},339:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addChannel=void 0;const i=n(304),a=n(642),r=n(860),s=n(246);o.addChannel=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t;n.apikey=n.apikey||(0,s.findSavedKey)()||"";const p=yield(0,s.getConfig)();o=o||(null===(t=null==p?void 0:p.app)||void 0===t?void 0:t.appId);const c=(0,s.useLogSnag)();n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,s.createSupabaseClient)(n.apikey),d=yield(0,s.verifyUser)(l,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(l,o,n.apikey),console.log(`Create channel ${o}#${e} to Capgo cloud`);try{const{data:n}=yield(0,r.findUnknownVersion)(l,o);n||i.program.error("Cannot find default version for channel creation, please contact Capgo support 🤨"),yield(0,r.createChannel)(l,{name:e,app_id:o,version:n.id,created_by:d}),console.log("Channel created ✅"),yield c.publish({channel:"app",event:"Create channel",icon:"✅",tags:{"user-id":d,"app-id":o,channel:e},notify:!1}).catch()}catch(e){console.log("Cannot create Channel 🙀",e)}console.log("Done ✅"),process.exit()}))},879:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteChannel=void 0;const i=n(304),a=n(642),r=n(860),s=n(246);o.deleteChannel=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t;n.apikey=n.apikey||(0,s.findSavedKey)()||"";const p=yield(0,s.getConfig)();o=o||(null===(t=null==p?void 0:p.app)||void 0===t?void 0:t.appId);const c=(0,s.useLogSnag)();n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,s.createSupabaseClient)(n.apikey),d=yield(0,s.verifyUser)(l,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(l,o,n.apikey),console.log(`Delete channel ${o}#${e} to Capgo cloud`);try{yield(0,r.delChannel)(l,e,o,d),console.log("Channel Delete ✅"),yield c.publish({channel:"app",event:"Delete channel",icon:"✅",tags:{"user-id":d,"app-id":o,channel:e},notify:!1}).catch()}catch(e){console.log("Cannot delete Channel 🙀",e)}console.log("Done ✅"),process.exit()}))},416:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listChannels=void 0;const i=n(304),a=n(642),r=n(860),s=n(246);o.listChannels=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;o.apikey=o.apikey||(0,s.findSavedKey)()||"";const t=yield(0,s.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const p=(0,s.createSupabaseClient)(o.apikey),c=yield(0,s.verifyUser)(p,o.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(p,e,o.apikey),console.log("Querying available versions in Capgo"),yield(0,a.checkAppExistsAndHasPermission)(p,e,o.apikey);const l=yield(0,r.getActiveChannels)(p,e,c);console.log(`Active channels in Capgo: ${null==l?void 0:l.length}`),(0,r.displayChannels)(l),console.log("Done ✅"),process.exit()}))},687:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const i=n(304),a=n(642),r=n(246);o.setChannel=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,s;o.apikey=o.apikey||(0,r.findSavedKey)()||"";const p=yield(0,r.getConfig)();e=e||(null===(n=null==p?void 0:p.app)||void 0===n?void 0:n.appId);const c=(0,r.useLogSnag)();o.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,r.createSupabaseClient)(o.apikey),d=yield(0,r.verifyUser)(l,o.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermission)(l,e,o.apikey);const{bundle:u,latest:y,downgrade:g,upgrade:v,ios:f,android:h,selfAssign:m,channel:k,state:b}=o;k||i.program.error("Missing argument, you need to provide a channel"),y&&u&&i.program.error("Cannot set latest and bundle at the same time"),null==u&&null==b&&null==y&&null==g&&null==v&&null==f&&null==h&&null==m&&i.program.error("Missing argument, you need to provide a option to set");try{yield(0,r.checkPlanValid)(l,d),yield(0,a.checkAppExistsAndHasPermission)(l,e,o.apikey);const n={created_by:d,app_id:e,name:k,version:void 0},w=y?null===(s=null===(t=null==p?void 0:p.app)||void 0===t?void 0:t.package)||void 0===s?void 0:s.version:u;if(null!=w){const{data:o,error:t}=yield l.from("app_versions").select().eq("app_id",e).eq("name",w).eq("user_id",d).eq("deleted",!1).single();!t&&o||i.program.error(`Cannot find version ${w}`),console.log(`Set ${e} channel: ${k} to @${w}`),n.version=o.id}null!=b&&("public"!==b&&"private"!==b||console.log(`Set ${e} channel: ${k} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${k} to ${"public"===b||"default"===b?"default":"normal"}`),n.public="public"===b||"default"===b),null!=g&&(console.log(`Set ${e} channel: ${k} to ${g?"allow":"disallow"} downgrade`),n.disableAutoUpdateUnderNative=!g),null!=v&&(console.log(`Set ${e} channel: ${k} to ${v?"allow":"disallow"} upgrade`),n.disableAutoUpdateToMajor=!v),null!=f&&(console.log(`Set ${e} channel: ${k} to ${f?"allow":"disallow"} ios update`),n.ios=!!f),null!=h&&(console.log(`Set ${e} channel: ${k} to ${h?"allow":"disallow"} android update`),n.android=!!h),null!=m&&(console.log(`Set ${e} channel: ${k} to ${m?"allow":"disallow"} self assign to this channel`),n.allow_device_self_set=!!m);try{const{error:e}=yield(0,r.updateOrCreateChannel)(l,n,o.apikey);e&&i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}catch(e){i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}yield c.publish({channel:"app",event:"Set app",icon:"✅",tags:{"user-id":d,"app-id":e},notify:!1}).catch()}catch(e){i.program.error(`Unknow error ${(0,r.formatError)(e)}`)}console.log("Done ✅"),process.exit()}))},714:function(e,o,n){var t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0});const i=n(304),a=n(628),r=n(278),s=n(124),p=n(90),c=n(285),l=n(6),d=n(687),u=n(883),y=t(n(598)),g=n(640),v=n(367),f=n(957),h=n(339),m=n(879),k=n(416),b=n(444),w=n(10);i.program.description("Manage packages and bundle versions in capgo Cloud").version(y.default.version),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(g.login).option("--local","Only save in local folder"),i.program.command("doctor").description("Get info about your Capgo app install").action(p.getInfo);const _=i.program.command("app").description("Manage app");_.command("add [appid]").alias("a").description("Add a new app in capgo Cloud").action(s.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),_.command("delete [appid]").alias("d").description("Delete an app in capgo Cloud").action(w.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account"),_.command("list [appid]").alias("l").description("list apps in capgo Cloud").action(v.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),_.command("set [appid]").alias("s").description("Set an app in capgo Cloud").action(b.setApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account");const x=i.program.command("bundle").description("Manage bundle");x.command("upload [appid]").alias("u").description("Upload a new bundle in capgo Cloud").action(u.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder 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("--key <key>","custom path for public signing key").option("--keyData <keyData>","base64 public signing key").option("--no-key","ignore signing key and send clear update").option("--display-iv-session","Show in the console the iv and session key used to encrypt the update").option("-b, --bundle <bundle>","bundle version number of the file to upload"),x.command("delete [appid]").alias("d").description("Delete a bundle in capgo Cloud").action(l.deleteVersion).option("-a, --apikey <apikey>","apikey to link to your account"),x.command("list [appid]").alias("l").description("List bundle in capgo Cloud").action(v.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),x.command("cleanup [appid]").alias("c").action(f.cleanupApp).description("Cleanup bundle in capgo Cloud").option("-b, --bundle <bundle>","bundle version number of the app to delete").option("-a, --apikey <apikey>","apikey to link to your account").option("-k, --keep <keep>","number of version to keep").option("-f, --force","force removal"),x.command("decrypt [zipPath] [sessionKey]").alias("l").description("Decrypt a signed zip bundle").action(a.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),x.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(r.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key");const C=i.program.command("channel").description("Manage channel");C.command("add [channelid] [appid]").alias("a").description("Create channel").action(h.addChannel),C.command("delete [channelid] [appid]").alias("d").description("Delete channel").action(m.deleteChannel),C.command("list [appid]").alias("l").description("List channel").action(k.listChannels),C.command("set [channelid] [appid]").alias("s").description("Set channel").action(d.setChannel).option("-a, --apikey <apikey>","apikey to link to your account").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("--latest","get the latest version key in the package.json to set it to the channel").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"),i.program.command("key [option]").description("Save base64 signing key in capacitor config, usefull for CI").action(c.manageKey).option("-f, --force","force generate a new one"),i.program.command("upload [appid]").alias("u").description("(Deprecated) Upload a new bundle to capgo Cloud").action(u.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder 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("--key <key>","custom path for public signing key").option("--keyData <keyData>","base64 public signing key").option("--no-key","ignore signing key and send clear update").option("--display-iv-session","Show in the console the iv and session key used to encrypt the update").option("-b, --bundle <bundle>","bundle version number of the file to upload"),i.program.parseAsync()},285:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.manageKey=void 0;const i=n(304),a=n(147),r=n(778),s=n(213),p=n(246),c=n(484);o.manageKey=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,l;yield(0,c.checkLatest)(),"save"===e?(n=o.key,l=o.keyData,t(void 0,void 0,void 0,(function*(){(0,a.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const e=yield(0,p.getConfig)(),{extConfig:o}=e.app,t=n||p.baseKey;let s=l||"";(0,a.existsSync)(t)||s?(0,a.existsSync)(t)&&(s=(0,a.readFileSync)(t).toString()):i.program.error(`Cannot find public key ${t} or as keyData option or in ${e.app.extConfigFilePath}`),o&&(o.plugins||(o.plugins={}),o.plugins.CapacitorUpdater||(o.plugins.CapacitorUpdater={}),o.plugins.CapacitorUpdater.privateKey=s,(0,r.writeConfig)(o,e.app.extConfigFilePath)),console.log(`private key saved into ${e.app.extConfigFilePath} file in local directory`),console.log("your app will decode the zip archive with this key\n")}))):"create"===e?(e=>{t(void 0,void 0,void 0,(function*(){(0,a.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const{publicKey:o,privateKey:n}=(0,s.createRSA)();(0,a.existsSync)(p.baseKeyPub)&&!e.force&&i.program.error("Public Key already exists, use --force to overwrite"),(0,a.writeFileSync)(p.baseKeyPub,o),(0,a.existsSync)(p.baseKey)&&!e.force&&i.program.error("Private Key already exists, use --force to overwrite"),(0,a.writeFileSync)(p.baseKey,n);const t=yield(0,p.getConfig)(),{extConfig:c}=t.app;c&&(c.plugins||(c.plugins={}),c.plugins.CapacitorUpdater||(c.plugins.CapacitorUpdater={}),c.plugins.CapacitorUpdater.privateKey=n,(0,r.writeConfig)(c,t.app.extConfigFilePath)),console.log("Your RSA key has been generated using node-rsa with this settings:\n\n- encryptionScheme — 'pkcs1_oaep'.\n- signingScheme — 'pkcs8-sha256'.\n- bits — 2048.\n- exp — 65537.\n"),console.log(`public key saved into ${p.baseKeyPub} file in local directory\n`),console.log("This key will be use to encode your zipped bundle before sending it to Capgo,\nthan make them unreadable by Capgo and unmodifiable by anyone\n"),console.log(`Private key saved into ${t.app.extConfigFilePath} file in local directory`),console.log("Your app will decode with this key the zipped bundle\n")}))})(o):i.program.error("You should provide a valid option (create or save)"),process.exit()}))},640:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.login=void 0;const i=n(304),a=n(147),r=n(37),s=n(246),p=n(484);o.login=(e,o)=>t(void 0,void 0,void 0,(function*(){yield(0,p.checkLatest)();try{const{local:n}=o,t=(0,s.useLogSnag)();if(n)(0,a.existsSync)(".git")||i.program.error("To use local you should be in a git repository"),(0,a.writeFileSync)(".capgo",`${e}\n`),(0,a.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,r.homedir)();(0,a.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const p=(0,s.createSupabaseClient)(e),c=yield(0,s.verifyUser)(p,e,["write","all","upload"]);yield t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":c},notify:!1}).catch(),console.log(`login saved into .capgo file in ${n?"local":"home"} directory`)}catch(e){console.error(e),process.exit(1)}process.exit()}))},246:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{p(t.next(e))}catch(e){a(e)}}function s(e){try{p(t.throw(e))}catch(e){a(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}p((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getHumanDate=o.verifyUser=o.convertAppName=o.useLogSnag=o.updateOrCreateChannel=o.updateOrCreateVersion=o.getConfig=o.formatError=o.findSavedKey=o.checkPlanValid=o.isAllowedAction=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.supaAnon=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=void 0;const a=n(778),r=n(304),s=n(885),p=i(n(867)),c=n(147),l=n(37),d=n(133);o.baseKey=".capgo_key",o.baseKeyPub=`${o.baseKey}.pub`,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,{global:{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,n,i)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:i}).single();t&&!a||r.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(a)}`)})),o.isGoodPlan=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_good_plan_v2",{userid:o}).single();if(t)throw t;return n||!1})),o.isPaying=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_paying",{userid:o}).single();if(t)throw t;return n||!1})),o.isTrial=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_trial",{userid:o}).single();if(t)throw t;return n||0})),o.isAllowedAction=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_allowed_action_user",{userid:o}).single();if(t)throw t;return n})),o.checkPlanValid=(e,n,i=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.isAllowedAction)(e,n))||r.program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`);const t=yield(0,o.isTrial)(e,n);t>0&&i&&console.log(`WARNING !!\nTrial expires in ${t} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e=`${(0,l.homedir)()}/.capgo`;return(0,c.existsSync)(e)?(console.log(`Use global apy key ${e}`),(0,c.readFileSync)(e,"utf8").trim()):(e=".capgo",(0,c.existsSync)(e)?(console.log(`Use local apy key ${e}`),(0,c.readFileSync)(e,"utf8").trim()):null)},o.formatError=e=>e?`\n${p.default.render(e)}`:"",o.getConfig=()=>t(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,a.loadConfig)()}catch(e){r.program.error("No capacitor config file found, run `cap init` first")}return e})),o.updateOrCreateVersion=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.rpc("exist_app_versions",{appid:o.app_id,name_version:o.name,apikey:n}).single();return t&&!i?(o.deleted=!1,e.from("app_versions").update(o).eq("app_id",o.app_id).eq("name",o.name).single()):e.from("app_versions").insert(o).select().single()})),o.updateOrCreateChannel=(e,o,n)=>t(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:t,error:i}=yield e.rpc("exist_channel",{appid:o.app_id,name_channel:o.name,apikey:n}).single();return t&&!i?e.from("channels").update(o).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by).single():e.from("channels").insert(o).select().single()})),o.useLogSnag=()=>new d.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.convertAppName=e=>e.replace(/\./g,"--"),o.verifyUser=(e,n,i=["all"])=>t(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,n,i);const{data:t,error:a}=yield e.rpc("get_user_id",{apikey:n}).single(),s=t?t.toString():"";return s&&!a||r.program.error(`Cannot verify user ${(0,o.formatError)(a)}`),s})),o.getHumanDate=e=>new Date(e||"").toLocaleString()},778:e=>{e.exports=require("@capacitor/cli/dist/config")},885:e=>{e.exports=require("@supabase/supabase-js")},906:e=>{e.exports=require("@tomasklaen/checksum")},176:e=>{e.exports=require("@trufflesuite/spinnies")},844:e=>{e.exports=require("adm-zip")},295:e=>{e.exports=require("cli-progress")},304:e=>{e.exports=require("commander")},847:e=>{e.exports=require("console-table-printer")},470:e=>{e.exports=require("fs-extra")},362:e=>{e.exports=require("get-latest-version")},133:e=>{e.exports=require("logsnag")},11:e=>{e.exports=require("mime")},867:e=>{e.exports=require("prettyjson")},616:e=>{e.exports=require("prompt-sync")},505:e=>{e.exports=require("semver/preload")},113:e=>{e.exports=require("crypto")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},17:e=>{e.exports=require("path")},598:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"3.0.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"},"engines":{"npm":">=7.0.0","node":">=16.0.0"},"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","test":"npx --yes ts-node -T src/index.ts","build":"npx --yes webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","types":"npx --yes supabase gen types typescript --project-id=xvwzpoazmxkqosrdewyv > src/types/supabase.types.ts","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.6.3","@supabase/supabase-js":"^2.5.0","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","cli-progress":"3.11.2","commander":"10.0.0","console-table-printer":"^2.11.1","fs-extra":"11.1.0","get-latest-version":"^5.0.0","logsnag":"^0.1.6","mime":"^3.0.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","semver":"^7.3.8"},"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.18","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/semver":"^7.3.13","@typescript-eslint/eslint-plugin":"5.47.1","@typescript-eslint/parser":"5.47.1","eslint":"8.34.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.6.0","eslint-import-resolver-typescript":"3.5.3","eslint-plugin-import":"2.27.5","eslint-plugin-prettier":"^4.2.1","git-format-staged":"3.0.0","husky":"^8.0.3","nodemon":"2.0.20","pkg":"5.8.0","prettier":"2.8.4","ts-loader":"^9.4.2","ts-node":"^10.9.1","tsconfig-paths":"4.1.2","typescript":"4.9.5","webpack":"5.75.0","webpack-cli":"^5.0.1","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var a=o[t]={exports:{}};return e[t].call(a.exports,a,a.exports,n),a.exports}(714)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -42,14 +42,16 @@
42
42
  "author": "github.com/riderx",
43
43
  "license": "Apache 2.0",
44
44
  "dependencies": {
45
- "@capacitor/cli": "4.6.2",
45
+ "@capacitor/cli": "4.6.3",
46
46
  "@supabase/supabase-js": "^2.5.0",
47
47
  "@tomasklaen/checksum": "^1.1.0",
48
+ "@trufflesuite/spinnies": "^0.1.1",
48
49
  "adm-zip": "^0.5.10",
49
50
  "cli-progress": "3.11.2",
50
51
  "commander": "10.0.0",
51
52
  "console-table-printer": "^2.11.1",
52
53
  "fs-extra": "11.1.0",
54
+ "get-latest-version": "^5.0.0",
53
55
  "logsnag": "^0.1.6",
54
56
  "mime": "^3.0.0",
55
57
  "prettyjson": "^1.2.5",
@@ -67,7 +69,7 @@
67
69
  "@types/semver": "^7.3.13",
68
70
  "@typescript-eslint/eslint-plugin": "5.47.1",
69
71
  "@typescript-eslint/parser": "5.47.1",
70
- "eslint": "8.33.0",
72
+ "eslint": "8.34.0",
71
73
  "eslint-config-airbnb-base": "^15.0.0",
72
74
  "eslint-config-prettier": "^8.6.0",
73
75
  "eslint-import-resolver-typescript": "3.5.3",
@@ -77,11 +79,11 @@
77
79
  "husky": "^8.0.3",
78
80
  "nodemon": "2.0.20",
79
81
  "pkg": "5.8.0",
80
- "prettier": "2.8.3",
82
+ "prettier": "2.8.4",
81
83
  "ts-loader": "^9.4.2",
82
84
  "ts-node": "^10.9.1",
83
85
  "tsconfig-paths": "4.1.2",
84
- "typescript": "4.9.4",
86
+ "typescript": "4.9.5",
85
87
  "webpack": "5.75.0",
86
88
  "webpack-cli": "^5.0.1",
87
89
  "webpack-node-externals": "^3.0.0"
@@ -0,0 +1,10 @@
1
+ import getLatest from "get-latest-version"
2
+ import pack from '../../package.json'
3
+
4
+ export const checkLatest = async () => {
5
+ const latest = await getLatest('@capgo/cli')
6
+ if (latest !== pack.version) {
7
+ console.log('\x1b[31m%s\x1b[0m', `🚨 You are using @capgo/cli@${pack.version} it's not the latest version.
8
+ Please use @capgo/cli@${latest}" or @capgo/cli@latest to keep up to date with the latest features and bug fixes.`)
9
+ }
10
+ }
package/src/app/add.ts CHANGED
@@ -2,6 +2,7 @@ import { getType } from 'mime';
2
2
  import { program } from 'commander';
3
3
  import { randomUUID } from 'crypto';
4
4
  import { existsSync, readFileSync } from 'fs-extra';
5
+ import { checkLatest } from '../api/update';
5
6
  import { checkAppExistsAndHasPermission, newIconPath, Options } from '../api/app';
6
7
  import {
7
8
  getConfig, createSupabaseClient,
@@ -9,6 +10,7 @@ import {
9
10
  } from '../utils';
10
11
 
11
12
  export const addApp = async (appId: string, options: Options) => {
13
+ await checkLatest();
12
14
  options.apikey = options.apikey || findSavedKey() || ''
13
15
  const config = await getConfig();
14
16
  appId = appId || config?.app?.appId
@@ -0,0 +1,87 @@
1
+ import { readFileSync } from "fs"
2
+ import getLatest from "get-latest-version"
3
+ import { join } from "path"
4
+ import Spinnies from '@trufflesuite/spinnies';
5
+ import pack from '../../package.json'
6
+
7
+ const getLatestDependencies = async (installedDependencies: { [key: string]: string }) => {
8
+ const latestDependencies: { [key: string]: string } = {}
9
+ const all = []
10
+ for (const dependency in installedDependencies) {
11
+ if (Object.prototype.hasOwnProperty.call(installedDependencies, dependency)) {
12
+ // get in npm the last version of the dependency
13
+ all.push(getLatest(dependency))
14
+ }
15
+ }
16
+ await Promise.all(all)
17
+ .then((values) => {
18
+ const keys = Object.keys(installedDependencies)
19
+ for (let i = 0; i < values.length; i += 1) {
20
+ const v = values[i]
21
+ if (v) {
22
+ latestDependencies[keys[i]] = v
23
+ }
24
+ }
25
+ })
26
+ return latestDependencies
27
+ }
28
+
29
+ const readPackageJson = async () => {
30
+ const packageJson = readFileSync(join(process.cwd(), 'package.json'))
31
+ return JSON.parse(packageJson as any)
32
+ }
33
+
34
+ const getInstalledDependencies = async () => {
35
+ const { dependencies } = await readPackageJson()
36
+ const installedDependencies: { [key: string]: string } = {
37
+ '@capgo/cli': pack.version,
38
+ }
39
+ for (const dependency in dependencies) {
40
+ if (Object.prototype.hasOwnProperty.call(dependencies, dependency) && dependency.startsWith('@capgo/')) {
41
+ installedDependencies[dependency] = dependencies[dependency]
42
+ }
43
+ }
44
+ return installedDependencies
45
+ }
46
+
47
+ export const getInfo = async () => {
48
+ console.log(' 💊 Capgo Doctor 💊')
49
+ console.log('\n')
50
+ console.log(' Installed Dependencies:')
51
+ console.log('\n')
52
+ const installedDependencies = await getInstalledDependencies()
53
+ if (Object.keys(installedDependencies).length === 0) {
54
+ console.log('\n')
55
+ // display in red color in shell with console log
56
+ console.log('\x1b[31m%s\x1b[0m', '🚨 No dependencies found')
57
+ process.exit(1)
58
+ }
59
+ for (const dependency in installedDependencies) {
60
+ if (Object.prototype.hasOwnProperty.call(installedDependencies, dependency)) {
61
+ const installedVersion = (installedDependencies as any)[dependency]
62
+ console.log(` ${dependency}: ${installedVersion}`)
63
+ }
64
+ }
65
+ console.log('\n')
66
+ const spinnies = new Spinnies();
67
+ spinnies.add('loading', { text: 'Loading latest dependencies' });
68
+ const latestDependencies = await getLatestDependencies(installedDependencies)
69
+ spinnies.succeed('loading', { text: 'Latest Dependencies:' });
70
+ console.log('\n')
71
+ for (const dependency in latestDependencies) {
72
+ if (Object.prototype.hasOwnProperty.call(latestDependencies, dependency)) {
73
+ const latestVersion = (latestDependencies as any)[dependency]
74
+ console.log(` ${dependency}: ${latestVersion}`)
75
+ }
76
+ }
77
+ if (JSON.stringify(installedDependencies) !== JSON.stringify(latestDependencies)) {
78
+ console.log('\n')
79
+ // display in red color in shell with console log
80
+ console.log('\x1b[31m%s\x1b[0m', '🚨 Some dependencies are not up to date')
81
+ process.exit(1)
82
+ }
83
+ console.log('\n')
84
+ // display in green color in shell with console log
85
+ console.log('\x1b[32m%s\x1b[0m', '✅ All dependencies are up to date')
86
+ process.exit()
87
+ }
package/src/app/list.ts CHANGED
@@ -3,8 +3,10 @@ import { checkAppExistsAndHasPermission } from '../api/app';
3
3
  import { OptionsBase } from '../api/utils';
4
4
  import { getActiveAppVersions, displayBundles } from '../api/versions';
5
5
  import { createSupabaseClient, findSavedKey, getConfig, verifyUser } from '../utils';
6
+ import { checkLatest } from '../api/update';
6
7
 
7
8
  export const listApp = async (appId: string, options: OptionsBase) => {
9
+ await checkLatest();
8
10
  const apikey = options.apikey || findSavedKey()
9
11
  const config = await getConfig();
10
12
 
@@ -7,6 +7,8 @@ import { OptionsBase } from '../api/utils';
7
7
  import { createSupabaseClient, findSavedKey, getConfig, getHumanDate, verifyUser } from '../utils';
8
8
  import { deleteSpecificVersion, displayBundles, getActiveAppVersions } from '../api/versions';
9
9
  import { checkAppExistsAndHasPermission } from '../api/app';
10
+ import { checkLatest } from '../api/update';
11
+
10
12
  // import { definitions } from '../types/types_supabase';
11
13
 
12
14
  interface Options extends OptionsBase {
@@ -41,6 +43,7 @@ const getRemovableVersionsInSemverRange = (data: Database['public']['Tables']['a
41
43
  }
42
44
 
43
45
  export const cleanupApp = async (appid: string, options: Options) => {
46
+ await checkLatest();
44
47
  const apikey = options.apikey || findSavedKey()
45
48
  const { bundle, keep = 4 } = options;
46
49
  const force = options.force || false;
@@ -2,6 +2,7 @@ import { program } from 'commander'
2
2
  import { existsSync, readFileSync, writeFileSync } from 'fs'
3
3
  import { decryptSource } from '../api/crypto';
4
4
  import { baseKey, getConfig } from '../utils';
5
+ import { checkLatest } from '../api/update';
5
6
 
6
7
  interface Options {
7
8
  key?: string
@@ -9,6 +10,7 @@ interface Options {
9
10
  }
10
11
 
11
12
  export const decryptZip = async (zipPath: string, ivsessionKey: string, options: Options) => {
13
+ await checkLatest();
12
14
  // write in file .capgo the apikey in home directory
13
15
 
14
16
  if (!existsSync(zipPath)) {
@@ -1,5 +1,6 @@
1
1
  import { program } from 'commander'
2
2
  import { existsSync, readFileSync, writeFileSync } from 'fs'
3
+ import { checkLatest } from '../api/update';
3
4
  import { encryptSource } from '../api/crypto';
4
5
  import { baseKeyPub } from '../utils';
5
6
 
@@ -9,6 +10,7 @@ interface Options {
9
10
  }
10
11
 
11
12
  export const encryptZip = async (zipPath: string, options: Options) => {
13
+ await checkLatest();
12
14
  // write in file .capgo the apikey in home directory
13
15
 
14
16
  if (!existsSync(zipPath)) {
@@ -4,6 +4,7 @@ import { randomUUID } from 'crypto';
4
4
  import cliProgress from 'cli-progress';
5
5
  import { existsSync, readFileSync } from 'fs';
6
6
  import { checksum as getChecksum } from '@tomasklaen/checksum';
7
+ import { checkLatest } from '../api/update';
7
8
  import { OptionsBase } from '../api/utils';
8
9
  import { checkAppExistsAndHasPermission } from "../api/app";
9
10
  import { encryptSource } from '../api/crypto';
@@ -26,6 +27,7 @@ interface Options extends OptionsBase {
26
27
  }
27
28
 
28
29
  export const uploadVersion = async (appid: string, options: Options) => {
30
+ await checkLatest();
29
31
  let { bundle, path, channel } = options;
30
32
  const { external, key = false, displayIvSession } = options;
31
33
  const apikey = options.apikey || findSavedKey()
@@ -7,6 +7,7 @@ import {
7
7
  formatError, findSavedKey, checkPlanValid, useLogSnag, verifyUser
8
8
  } from '../utils';
9
9
  // import { definitions } from '../types/types_supabase';
10
+ import { checkLatest } from '../api/update';
10
11
 
11
12
  interface Options extends OptionsBase {
12
13
  bundle: string;
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import { program } from 'commander';
2
2
  import { decryptZip } from './bundle/decrypt';
3
3
  import { encryptZip } from './bundle/encrypt';
4
4
  import { addApp } from './app/add';
5
+ import { getInfo } from './app/info';
5
6
  import { manageKey } from './key';
6
7
  import { deleteVersion } from './bundle/delete';
7
8
  import { setChannel } from './channel/set';
@@ -27,6 +28,11 @@ program
27
28
  .action(login)
28
29
  .option('--local', 'Only save in local folder');
29
30
 
31
+ program
32
+ .command('doctor')
33
+ .description('Get info about your Capgo app install')
34
+ .action(getInfo);
35
+
30
36
  const app = program
31
37
  .command('app')
32
38
  .description('Manage app');
@@ -169,4 +175,19 @@ program
169
175
  .action(manageKey)
170
176
  .option('-f, --force', 'force generate a new one');
171
177
 
178
+ program
179
+ .command('upload [appid]')
180
+ .alias('u')
181
+ .description('(Deprecated) Upload a new bundle to capgo Cloud')
182
+ .action(uploadVersion)
183
+ .option('-a, --apikey <apikey>', 'apikey to link to your account')
184
+ .option('-p, --path <path>', 'path of the folder to upload')
185
+ .option('-c, --channel <channel>', 'channel to link to')
186
+ .option('-e, --external <url>', 'link to external url intead of upload to capgo cloud')
187
+ .option('--key <key>', 'custom path for public signing key')
188
+ .option('--keyData <keyData>', 'base64 public signing key')
189
+ .option('--no-key', 'ignore signing key and send clear update')
190
+ .option('--display-iv-session', 'Show in the console the iv and session key used to encrypt the update')
191
+ .option('-b, --bundle <bundle>', 'bundle version number of the file to upload');
192
+
172
193
  program.parseAsync();
package/src/key.ts CHANGED
@@ -3,6 +3,7 @@ import { existsSync, readFileSync, writeFileSync } from 'fs'
3
3
  import { writeConfig } from '@capacitor/cli/dist/config';
4
4
  import { createRSA } from './api/crypto';
5
5
  import { baseKey, baseKeyPub, getConfig } from './utils';
6
+ import { checkLatest } from './api/update';
6
7
 
7
8
  interface Options {
8
9
  force?: boolean;
@@ -93,7 +94,7 @@ than make them unreadable by Capgo and unmodifiable by anyone\n`);
93
94
  }
94
95
 
95
96
  export const manageKey = async (option: string, options: Options) => {
96
-
97
+ await checkLatest();
97
98
  if (option === 'save') {
98
99
  saveKey(options.key, options.keyData);
99
100
  } else
package/src/login.ts CHANGED
@@ -2,11 +2,13 @@ import { program } from 'commander';
2
2
  import { existsSync, writeFileSync, appendFileSync } from 'fs'
3
3
  import { homedir } from 'os'
4
4
  import { createSupabaseClient, useLogSnag, verifyUser } from './utils';
5
+ import { checkLatest } from './api/update';
5
6
 
6
7
  interface Options {
7
8
  local: boolean;
8
9
  }
9
10
  export const login = async (apikey: string, options: Options) => {
11
+ await checkLatest();
10
12
  // write in file .capgo the apikey in home directory
11
13
  try {
12
14
  const { local } = options;