@capgo/cli 2.4.7 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
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
+ ### [2.5.1](https://github.com/Cap-go/capgo-cli/compare/v2.5.0...v2.5.1) (2023-01-23)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **deps:** update dependency @capacitor/cli to v4.6.2 ([c34685f](https://github.com/Cap-go/capgo-cli/commit/c34685fc5eb2db5c902ecaac65ad5153a4f4da32))
11
+
12
+ ## [2.5.0](https://github.com/Cap-go/capgo-cli/compare/v2.4.7...v2.5.0) (2023-01-17)
13
+
14
+
15
+ ### Features
16
+
17
+ * add create delete channel ([695ea3b](https://github.com/Cap-go/capgo-cli/commit/695ea3b6046408519aba01921c63c1c5bc0c09e8))
18
+
5
19
  ### [2.4.7](https://github.com/Cap-go/capgo-cli/compare/v2.4.6...v2.4.7) (2023-01-16)
6
20
 
7
21
  ### [2.4.6](https://github.com/Cap-go/capgo-cli/compare/v2.4.5...v2.4.6) (2023-01-16)
package/README.md CHANGED
@@ -67,10 +67,25 @@ Example of `package.json` for version
67
67
  > ⛔ Version should be greater than “0.0.0”.
68
68
 
69
69
  >💡 Don't forget to update the version number each time you send one, or the device will don't see the update.
70
- ### Configure channel
71
- `npx @capgo/cli set [appId] --channel dev`
70
+
71
+ ### Channel
72
+
73
+ #### Create
74
+ `npx @capgo/cli channel create [channelId] [appId]`
75
+ `[channelId]` the name of your new channel.
76
+ `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init).
77
+
78
+ #### Delete
79
+ `npx @capgo/cli channel delete [channelId] [appId]`
80
+ `[channelId]` the name of your channel you want to delete.
72
81
  `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init).
73
82
 
83
+ ### Set
84
+ `npx @capgo/cli channel set [channelId] [appId]`
85
+ `[channelId]` the name of your channel you want to set.
86
+ `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init).
87
+
88
+
74
89
  Optionally, you can give:
75
90
  - `--bundle [1.2.3]` your app bundle already sent to the cloud, to link it to a channel.
76
91
  - `--latest` get the bundle version from `package.json:version`, cannot be used with `--bundle`.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- (()=>{"use strict";var e={550:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),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:r}=yield e.rpc("exist_app",{appid:o,apikey:n}).single();t&&!r||i.program.error("No permission for this app")}))},170:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInChannel=void 0;const i=n(304),r=n(693);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)}`)}}))},518:(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",r="sha256",a="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:r},Buffer.from(c,a)),d=Buffer.from(p,a),u=l.toString(a);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(a)}:${(0,t.publicEncrypt)({key:o,padding:s,oaepHash:r},p).toString(a)}`;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"})}}},471:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const i=n(304),r=n(693);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);if(a&&i.program.error(`Cannot check Device override ${o}@${n.name} ${(0,r.formatError)(a)}`),t&&t.length>0){const e=(0,r.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,r.formatError)(a)}`)}}))},843:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(304),r=n(693);o.deleteFromStorage=(e,o,n,a,s)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${a.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${s} ${(0,r.formatError)(t)} `)}))},971:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,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),r=n(847),a=n(693),s=n(170),p=n(471),c=n(843);o.deleteAppVersion=(e,o,n,r)=>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",r);t&&i.program.error(`App Version ${o}@${r} not found in database '${(0,a.formatError)(t)}'`)})),o.deleteSpecificVersion=(e,n,i,r)=>t(void 0,void 0,void 0,(function*(){const t=yield(0,o.getVersionData)(e,n,i,r);yield(0,s.checkVersionNotUsedInChannel)(e,n,i,t),yield(0,p.checkVersionNotUsedInDeviceOverride)(e,n,t),yield(0,c.deleteFromStorage)(e,i,n,t,r),yield(0,o.deleteAppVersion)(e,n,i,r)})),o.displayBundles=e=>{const o=new r.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,a.getHumanDate)(e)},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:r}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return r&&i.program.error(`App ${o} not found in database ${(0,a.formatError)(r)} `),t})),o.getVersionData=(e,o,n,r)=>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",r).eq("deleted",!1).single();return t&&!s||i.program.error(`App Version ${o}@${r} doesn't exist ${(0,a.formatError)(s)}`),t}))},174:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const i=n(304),r=n(113),a=n(147),s=n(470),p=n(11),c=n(693),l="assets/icon.png";o.addApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t;let{name:d,icon:u}=o;const y=o.apikey||(0,c.findSavedKey)(),g=yield(0,c.getConfig)(),v=(0,c.useLogSnag)();e=e||(null===(n=null==g?void 0:g.app)||void 0===n?void 0:n.appId),d=d||(null===(t=null==g?void 0:g.app)||void 0===t?void 0:t.appName)||"Unknown",u=u||"resources/icon.png",y||i.program.error("Missing API key, you need to provide a API key to add your app"),e&&d||i.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${e} to Capgo`);const f=(0,c.createSupabaseClient)(y),h=yield(0,c.verifyUser)(f,y,["write","all"]);let m,b;yield(0,c.checkPlanValid)(f,h),console.log("Adding..."),u&&(0,s.existsSync)(u)?(m=(0,a.readFileSync)(u),b=(0,p.getType)(u)||"image/png",console.warn(`Found app icon ${u}`)):(0,s.existsSync)(l)?(m=(0,a.readFileSync)(l),b=(0,p.getType)(l)||"image/png",console.warn(`Found app icon ${l}`)):console.warn(`Cannot find app icon in any of the following locations: ${u}, ${l}`);const{data:_,error:k}=yield f.rpc("exist_app_v2",{appid:e}).single();(_||k)&&i.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(m&&b){const{error:o}=yield f.storage.from(`images/${h}/${e}`).upload(w,m,{contentType:b});o&&i.program.error(`Could not add app ${(0,c.formatError)(o)}`);const{data:n}=yield f.storage.from(`images/${h}/${e}`).getPublicUrl(w);$=(null==n?void 0:n.publicUrl)||$}const{error:x}=yield f.from("apps").insert({icon_url:$,user_id:h,name:d,app_id:e});x&&i.program.error(`Could not add app ${(0,c.formatError)(x)}`);const{error:S}=yield f.from("app_versions").insert([{user_id:h,deleted:!0,name:"unknown",app_id:e},{user_id:h,deleted:!0,name:"builtin",app_id:e}]);S&&i.program.error(`Could not add app ${(0,c.formatError)(S)}`),v.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":h,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now")}))},327:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,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)}))}}},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupApp=void 0;const a=n(304),s=r(n(505)),p=r(n(616)),c=n(693),l=n(971),d=n(550),u=(0,p.default)();o.cleanupApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const r=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),r||a.program.error("Missing API key, you need to provide an API key to delete your app"),e||a.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const f=(0,c.createSupabaseClient)(r),h=yield(0,c.verifyUser)(f,r);yield(0,d.checkAppExistsAndHasPermission)(f,e,r),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 t=[];return null==e||e.forEach((e=>{s.default.gte(e.name,o)&&s.default.lt(e.name,`${n}`)&&t.push(e)})),t})(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,r)=>{var a,s,p;return t(void 0,void 0,void 0,(function*(){var t,d,u,y;try{for(a=!0,s=i(e);!(t=(p=yield s.next()).done);){y=p.value,a=!1;try{const e=y;console.log(`Removing ${e.name} created on ${(0,c.getHumanDate)(e)}`),yield(0,l.deleteSpecificVersion)(o,n,r,e.name)}finally{a=!0}}}catch(e){d={error:e}}finally{try{a||t||!(u=s.return)||(yield u.call(s))}finally{if(d)throw d.error}}}))})(b,f,e,h)}else console.log("Nothing to be removed, aborting removal...")}))},790:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const i=n(304),r=n(147),a=n(518),s=n(693);o.decryptZip=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,p,c;(0,r.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const l=yield(0,s.getConfig)(),{extConfig:d}=l.app;n.key||(0,r.existsSync)(s.baseKey)||(null===(p=null===(t=d.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===p?void 0:p.privateKey)||i.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,r.existsSync)(u)||y?(0,r.existsSync)(u)&&(y=(0,r.readFileSync)(u).toString()):i.program.error(`Cannot find public key ${u} or as keyData option or in ${l.app.extConfigFilePath}`);const g=(0,r.readFileSync)(e),v=(0,a.decryptSource)(g,o,y);(0,r.writeFileSync)(`${e}_decrypted.zip`,v)}))},513:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const i=n(304),r=n(693),a=n(971);o.deleteApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const{bundle:t}=o,s=o.apikey||(0,r.findSavedKey)(),p=yield(0,r.getConfig)(),c=(0,r.useLogSnag)();e=e||(null===(n=null==p?void 0:p.app)||void 0===n?void 0:n.appId),s||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");const l=(0,r.createSupabaseClient)(s),d=yield(0,r.verifyUser)(l,s),{data:u,error:y}=yield l.rpc("exist_app",{appid:e,apikey:s}).single();if(u&&!y||i.program.error("No permission to delete"),t)return console.log(`Delete ${e}@${t} from Capgo`),yield(0,a.deleteSpecificVersion)(l,e,d,t),void console.log(`${e}@${t} deleted from server`);console.log(`Delete ${e} from Capgo`);const{data:g,error:v}=yield l.from("app_versions").select().eq("app_id",e).eq("user_id",d);if(v&&i.program.error(`App ${e} not found in database ${(0,r.formatError)(v)} `),g&&g.length){const o=g.filter((e=>e.bucket_id&&!e.external_url)).map((o=>`${d}/${e}/versions/${o.bucket_id} `)),{error:n}=yield l.storage.from("apps").remove(o);n&&i.program.error(`Cannot delete stored version for app ${e} from storage ${(0,r.formatError)(n)} `)}const{error:f}=yield l.from("app_versions").delete().eq("app_id",e).eq("user_id",d);f&&i.program.error(`Cannot delete version for app ${e} from database ${(0,r.formatError)(f)} `);const{error:h}=yield l.from("apps").delete().eq("app_id",e).eq("user_id",d);h&&i.program.error(`Cannot delete from database ${(0,r.formatError)(h)} `),c.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":d,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`)}))},682:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const i=n(304),r=n(147),a=n(518),s=n(693);o.encryptZip=(e,o)=>t(void 0,void 0,void 0,(function*(){(0,r.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const n=o.key||s.baseKeyPub;let t=o.keyData||"";(0,r.existsSync)(n)||t?(0,r.existsSync)(n)&&(t=(0,r.readFileSync)(n).toString()):i.program.error(`Cannot find public key ${n} or as keyData option`);const p=(0,r.readFileSync)(e),c=(0,a.encryptSource)(p,t);console.log("ivSessionKey",c.ivSessionKey),(0,r.writeFileSync)(`${e}_encrypted.zip`,c.encryptedData)}))},213: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),r=n(790),a=n(682),s=n(174),p=n(69),c=n(513),l=n(131),d=n(658),u=t(n(598)),y=n(732),g=n(36),v=n(327);i.program.description("Manage packages and bundle versions in capgo Cloud").version(u.default.version),i.program.command("add [appid]").alias("a").description("Add a new app to 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"),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(y.login).option("--local","Only save in local folder"),i.program.command("upload [appid]").alias("u").description("Upload a new bundle to 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"),i.program.command("set [appid]").alias("s").description("Modify a channel configuration").action(l.setChannel).requiredOption("-c, --channel <channel>","channel to link to").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("--downgrade","Allow to downgrade to version under native one").option("--latest","get the latest version key in the package.json to set it to the channel").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("delete [appid]").alias("d").description("Delete an app from capgo Cloud").action(c.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the app to delete"),i.program.command("list [appid]").alias("ls").description("List versions in capgo Cloud").action(g.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),i.program.command("cleanup [appid]").alias("c").description("Cleanup versions in capgo Cloud").action(v.cleanupApp).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"),i.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"),i.program.command("decrypt [zipPath] [sessionKey]").description("Decrypt a signed zip update").action(r.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),i.program.command("encrypt [zipPath]").description("Encrypt a zip update").action(a.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),i.program.parse(process.argv)},69:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.manageKey=void 0;const i=n(304),r=n(147),a=n(778),s=n(518),p=n(693);o.manageKey=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,c;"save"===e?(n=o.key,c=o.keyData,t(void 0,void 0,void 0,(function*(){(0,r.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=c||"";(0,r.existsSync)(t)||s?(0,r.existsSync)(t)&&(s=(0,r.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,a.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,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const{publicKey:o,privateKey:n}=(0,s.createRSA)();(0,r.existsSync)(p.baseKeyPub)&&!e.force&&i.program.error("Public Key already exists, use --force to overwrite"),(0,r.writeFileSync)(p.baseKeyPub,o),(0,r.existsSync)(p.baseKey)&&!e.force&&i.program.error("Private Key already exists, use --force to overwrite"),(0,r.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,a.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)")}))},36:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const i=n(304),r=n(693),a=n(550),s=n(971);o.listApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,r.findSavedKey)(),p=yield(0,r.getConfig)();e=e||(null===(n=null==p?void 0:p.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 c=(0,r.createSupabaseClient)(t),l=yield(0,r.verifyUser)(c,t);yield(0,a.checkAppExistsAndHasPermission)(c,e,t);const d=yield(0,s.getActiveAppVersions)(c,e,l);console.log(`Active versions in Capgo: ${null==d?void 0:d.length}`),(0,s.displayBundles)(d)}))},732:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.login=void 0;const i=n(304),r=n(147),a=n(37),s=n(693);o.login=(e,o)=>t(void 0,void 0,void 0,(function*(){try{const{local:n}=o,t=(0,s.useLogSnag)();if(n)(0,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository"),(0,r.writeFileSync)(".capgo",`${e}\n`),(0,r.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,a.homedir)();(0,r.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const p=(0,s.createSupabaseClient)(e),c=yield(0,s.verifyUser)(p,e,["write","all","upload"]);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)}}))},131:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const i=n(304),r=n(550),a=n(693);o.setChannel=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,s;const{bundle:p,latest:c,downgrade:l,upgrade:d,ios:u,android:y,selfAssign:g,channel:v,state:f}=o,h=o.apikey||(0,a.findSavedKey)(),m=yield(0,a.getConfig)(),b=(0,a.useLogSnag)();e=e||(null===(n=null==m?void 0:m.app)||void 0===n?void 0:n.appId),h||i.program.error("Missing API key, you need to provide a API key to set your app"),e||i.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),v||i.program.error("Missing argument, you need to provide a channel"),c&&p&&i.program.error("Cannot set latest and bundle at the same time"),null==p&&null==f&&null==c&&null==l&&null==d&&null==u&&null==y&&null==g&&i.program.error("Missing argument, you need to provide a option to set");try{const o=(0,a.createSupabaseClient)(h),n=yield(0,a.verifyUser)(o,h,["write","all"]);yield(0,a.checkPlanValid)(o,n),yield(0,r.checkAppExistsAndHasPermission)(o,e,h);const _={created_by:n,app_id:e,name:v,version:void 0},k=c?null===(s=null===(t=null==m?void 0:m.app)||void 0===t?void 0:t.package)||void 0===s?void 0:s.version:p;if(null!=k){const{data:t,error:r}=yield o.from("app_versions").select().eq("app_id",e).eq("name",k).eq("user_id",n).eq("deleted",!1).single();!r&&t||i.program.error(`Cannot find version ${k}`),console.log(`Set ${e} channel: ${v} to @${k}`),_.version=t.id}null!=f&&("public"!==f&&"private"!==f||console.log(`Set ${e} channel: ${v} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${v} to ${"public"===f||"default"===f?"default":"normal"}`),_.public="public"===f||"default"===f),null!=l&&(console.log(`Set ${e} channel: ${v} to ${l?"allow":"disallow"} downgrade`),_.disableAutoUpdateUnderNative=!l),null!=d&&(console.log(`Set ${e} channel: ${v} to ${d?"allow":"disallow"} upgrade`),_.disableAutoUpdateToMajor=!d),null!=u&&(console.log(`Set ${e} channel: ${v} to ${u?"allow":"disallow"} ios update`),_.ios=!!u),null!=y&&(console.log(`Set ${e} channel: ${v} to ${y?"allow":"disallow"} android update`),_.android=!!y),null!=g&&(console.log(`Set ${e} channel: ${v} to ${g?"allow":"disallow"} self assign to this channel`),_.allow_device_self_set=!!g);try{const{error:e}=yield(0,a.updateOrCreateChannel)(o,_,h);e&&i.program.error(`Cannot set channel ${(0,a.formatError)(e)}`)}catch(e){i.program.error(`Cannot set channel ${(0,a.formatError)(e)}`)}b.publish({channel:"app",event:"Set app",icon:"✅",tags:{"user-id":n,"app-id":e},notify:!1}).catch()}catch(e){i.program.error(`Unknow error ${(0,a.formatError)(e)}`)}console.log("Done ✅")}))},658:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,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 r=i(n(844)),a=n(304),s=n(113),p=i(n(295)),c=n(147),l=n(906),d=n(550),u=n(518),y=n(693);o.uploadVersion=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,i,g;let{bundle:v,path:f,channel:h}=o;const{external:m,key:b=!1,displayIvSession:_}=o,k=o.apikey||(0,y.findSavedKey)(),w=(0,y.useLogSnag)();h=h||"dev";const $=yield(0,y.getConfig)();e=e||(null===(n=null==$?void 0:$.app)||void 0===n?void 0:n.appId),v=v||(null===(i=null===(t=null==$?void 0:$.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version),y.regexSemver.test(v)||a.program.error(`Your bundle name ${v}, is not valid it should follow semver convention : https://semver.org/`),f=f||(null===(g=null==$?void 0:$.app)||void 0===g?void 0:g.webDir),k||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e&&v&&f||a.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 x=(0,y.createSupabaseClient)(k),S=yield(0,y.verifyUser)(x,k,["write","all","upload"]);yield(0,y.checkPlanValid)(x,S,!1),yield(0,d.checkAppExistsAndHasPermission)(x,e,k);const C=new p.default.MultiBar({clearOnComplete:!1,hideCursor:!0},p.default.Presets.shades_grey),A=C.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},p.default.Presets.shades_grey);A.start(7,0,{speed:"N/A"});const{data:P,error:D}=yield x.rpc("exist_app_versions",{apikey:k,name_version:v,appid:e}).single();(P||D)&&(C.stop(),a.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,y.formatError)(D)}`)),A.increment();const{data:I,error:K}=yield x.rpc("is_trial",{userid:S}).single();(I&&I>0||K)&&C.log(`WARNING !!\nTrial expires in ${I} days, upgrade here: ${y.hostWeb}/dashboard/settings/plans\n`),A.increment();const{data:q,error:j}=yield x.rpc("exist_app",{appid:e,apikey:k}).single();q&&!j||(C.stop(),a.program.error(`Cannot find app ${e} in your account \n${(0,y.formatError)(j)}`)),A.increment();const{data:E,error:M}=yield x.rpc("exist_app_versions",{appid:e,apikey:k,name_version:v}).single();(E||M)&&a.program.error(`Version already exists ${(0,y.formatError)(M)}`),A.increment();const U=(0,s.randomUUID)();let V,O="";if(m)m&&!m.startsWith("https://")&&(C.stop(),a.program.error(`External link should should start with "https://" current is "${m}"`));else{const o=new r.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)||a.program.error(`Cannot find public key ${e}`);const o=(0,c.readFileSync)(e);C.log("Encrypting your bundle\n");const t=(0,u.encryptSource)(n,o.toString());V=t.ivSessionKey,_&&C.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/${S}/${e}/versions`;A.increment(),t>20&&(C.log(`WARNING !!\nThe app size is ${t} Mb, this may take a while to download for users\n`),w.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":S,"app-id":e},notify:!1}).catch());const{error:s}=yield x.storage.from(i).upload(U,n,{contentType:"application/zip",cacheControl:"2592000"});s&&(C.stop(),a.program.error(`Cannot upload ${(0,y.formatError)(s)}`))}A.increment();const{data:N,error:z}=yield(0,y.updateOrCreateVersion)(x,{bucket_id:m?void 0:U,user_id:S,name:v,app_id:e,session_key:V,external_url:m,checksum:O},k);if(z&&(C.stop(),a.program.error(`Cannot add bundle ${(0,y.formatError)(z)}`)),A.increment(),N){const{error:o}=yield(0,y.updateOrCreateChannel)(x,{name:h,app_id:e,created_by:S,version:N.id},k);o&&C.log("Cannot set bundle with upload key, use key with more rights for that\n")}else C.log("Cannot set bundle with upload key, use key with more rights for that\n");C.stop();const F=(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/${F}`),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/${F}/devices`),w.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":S,"app-id":e},notify:!1}).catch()}))},693:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,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 r=n(778),a=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:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:i}).single();t&&!r||a.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(r)}`)})),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))||a.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,r.loadConfig)()}catch(e){a.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:r}=yield e.rpc("get_user_id",{apikey:n}).single(),s=t?t.toString():"";return s&&!r||a.program.error(`Cannot verify user ${(0,o.formatError)(r)}`),s})),o.getHumanDate=e=>new Date(e.created_at||"").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":"2.4.7","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":">=14.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/bin/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.1","@supabase/supabase-js":"^2.1.2","@tomasklaen/checksum":"^1.1.0","adm-zip":"^0.5.9","cli-progress":"3.11.2","commander":"9.4.1","console-table-printer":"^2.11.1","fs-extra":"11.1.0","logsnag":"^0.1.5","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.9","@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.31.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"3.5.3","eslint-plugin-import":"2.26.0","eslint-plugin-prettier":"^4.2.1","git-format-staged":"3.0.0","husky":"^8.0.2","nodemon":"2.0.20","pkg":"5.8.0","prettier":"2.8.3","ts-loader":"^9.4.1","ts-node":"^10.9.1","tsconfig-paths":"4.1.2","typescript":"4.9.4","webpack":"5.75.0","webpack-cli":"^5.0.0","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t].call(r.exports,r,r.exports,n),r.exports}(213)})();
2
+ (()=>{"use strict";var e={550:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),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:r}=yield e.rpc("exist_app",{appid:o,apikey:n}).single();t&&!r||i.program.error("No permission for this app")}))},170:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInChannel=void 0;const i=n(304),r=n(693);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)}`)}}))},518:(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",r="sha256",a="base64",s=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[p,l]=o.split(":"),c=(0,t.privateDecrypt)({key:n,padding:s,oaepHash:r},Buffer.from(l,a)),d=Buffer.from(p,a),u=c.toString(a);console.log("\nSessionB64",u);const y=(0,t.createDecipheriv)(i,c,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),l=(0,t.createCipheriv)(i,p,n);l.setAutoPadding(!0);const c=`${n.toString(a)}:${(0,t.publicEncrypt)({key:o,padding:s,oaepHash:r},p).toString(a)}`;return{encryptedData:Buffer.concat([l.update(e),l.final()]),ivSessionKey:c}},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"})}}},471:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const i=n(304),r=n(693);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);if(a&&i.program.error(`Cannot check Device override ${o}@${n.name} ${(0,r.formatError)(a)}`),t&&t.length>0){const e=(0,r.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,r.formatError)(a)}`)}}))},843:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(304),r=n(693);o.deleteFromStorage=(e,o,n,a,s)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${a.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${s} ${(0,r.formatError)(t)} `)}))},971:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,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),r=n(847),a=n(693),s=n(170),p=n(471),l=n(843);o.deleteAppVersion=(e,o,n,r)=>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",r);t&&i.program.error(`App Version ${o}@${r} not found in database '${(0,a.formatError)(t)}'`)})),o.deleteSpecificVersion=(e,n,i,r)=>t(void 0,void 0,void 0,(function*(){const t=yield(0,o.getVersionData)(e,n,i,r);yield(0,s.checkVersionNotUsedInChannel)(e,n,i,t),yield(0,p.checkVersionNotUsedInDeviceOverride)(e,n,t),yield(0,l.deleteFromStorage)(e,i,n,t,r),yield(0,o.deleteAppVersion)(e,n,i,r)})),o.displayBundles=e=>{const o=new r.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,a.getHumanDate)(e)},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:r}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return r&&i.program.error(`App ${o} not found in database ${(0,a.formatError)(r)} `),t})),o.getVersionData=(e,o,n,r)=>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",r).eq("deleted",!1).single();return t&&!s||i.program.error(`App Version ${o}@${r} doesn't exist ${(0,a.formatError)(s)}`),t}))},174:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const i=n(304),r=n(113),a=n(147),s=n(470),p=n(11),l=n(693),c="assets/icon.png";o.addApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t;let{name:d,icon:u}=o;const y=o.apikey||(0,l.findSavedKey)(),g=yield(0,l.getConfig)(),v=(0,l.useLogSnag)();e=e||(null===(n=null==g?void 0:g.app)||void 0===n?void 0:n.appId),d=d||(null===(t=null==g?void 0:g.app)||void 0===t?void 0:t.appName)||"Unknown",u=u||"resources/icon.png",y||i.program.error("Missing API key, you need to provide a API key to add your app"),e&&d||i.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${e} to Capgo`);const f=(0,l.createSupabaseClient)(y),h=yield(0,l.verifyUser)(f,y,["write","all"]);let m,b;yield(0,l.checkPlanValid)(f,h),console.log("Adding..."),u&&(0,s.existsSync)(u)?(m=(0,a.readFileSync)(u),b=(0,p.getType)(u)||"image/png",console.warn(`Found app icon ${u}`)):(0,s.existsSync)(c)?(m=(0,a.readFileSync)(c),b=(0,p.getType)(c)||"image/png",console.warn(`Found app icon ${c}`)):console.warn(`Cannot find app icon in any of the following locations: ${u}, ${c}`);const{data:_,error:k}=yield f.rpc("exist_app_v2",{appid:e}).single();(_||k)&&i.program.error(`App ${e} already exists ${(0,l.formatError)(k)}`);const w=`icon_${(0,r.randomUUID)()}`;let $="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(m&&b){const{error:o}=yield f.storage.from(`images/${h}/${e}`).upload(w,m,{contentType:b});o&&i.program.error(`Could not add app ${(0,l.formatError)(o)}`);const{data:n}=yield f.storage.from(`images/${h}/${e}`).getPublicUrl(w);$=(null==n?void 0:n.publicUrl)||$}const{error:x}=yield f.from("apps").insert({icon_url:$,user_id:h,name:d,app_id:e});x&&i.program.error(`Could not add app ${(0,l.formatError)(x)}`);const{error:C}=yield f.from("app_versions").insert([{user_id:h,deleted:!0,name:"unknown",app_id:e},{user_id:h,deleted:!0,name:"builtin",app_id:e}]);C&&i.program.error(`Could not add app ${(0,l.formatError)(C)}`),v.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":h,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now")}))},552:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.manageChannel=void 0;const i=n(304),r=n(131),a=n(550),s=n(693);o.manageChannel=(e,o,n,p)=>t(void 0,void 0,void 0,(function*(){var t,l,c;const d=p.apikey||(0,s.findSavedKey)(),u=yield(0,s.getConfig)();n=n||(null===(t=null==u?void 0:u.app)||void 0===t?void 0:t.appId);const y=(0,s.useLogSnag)();d||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),n&&o||i.program.error("Missing argument, you need to provide a appid and a channel name, or be in a capacitor project");const g=(0,s.createSupabaseClient)(d),v=yield(0,s.verifyUser)(g,d,["write","all"]);if(yield(0,s.checkPlanValid)(g,v,!1),yield(0,a.checkAppExistsAndHasPermission)(g,n,d),"create"===e){console.log(`Create channel ${n}#${o} to Capgo cloud`);try{const{data:e}=yield((e,o)=>e.from("app_versions").select("id").eq("app_id",o).eq("name","unknown").single())(g,n);e||i.program.error("Cannot find default version for channel creation, please contact Capgo support 🤨"),yield((e,o)=>e.from("channels").insert(o).select().single())(g,{name:o,app_id:n,version:e.id,created_by:v}),console.log("Channel created ✅"),y.publish({channel:"app",event:"Create channel",icon:"✅",tags:{"user-id":v,"app-id":n,channel:o},notify:!1}).catch()}catch(e){console.log("Cannot create Channel 🙀",e)}}else if("delete"===e){console.log(`Delete channel ${n}#${o} to Capgo cloud`);try{yield((e,o,n,t)=>e.from("channels").delete().eq("name",o).eq("app_id",n).eq("user_id",t).single())(g,o,n,v),console.log("Channel Delete ✅"),y.publish({channel:"app",event:"Delete channel",icon:"✅",tags:{"user-id":v,"app-id":n,channel:o},notify:!1}).catch()}catch(e){console.log("Cannot delete Channel 🙀",e)}}else if("set"===e){console.log(`Set channel ${n}#${o} to Capgo cloud`);try{p.channel=o,yield(0,r.setChannelInternal)(n,d,null===(c=null===(l=null==u?void 0:u.app)||void 0===l?void 0:l.package)||void 0===c?void 0:c.version,y,p),console.log("Channel Set ✅")}catch(e){console.log("Cannot set Channel 🙀",e)}}else i.program.error("You should provide a valid option (create or delete)")}))},327:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,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)}))}}},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupApp=void 0;const a=n(304),s=r(n(505)),p=r(n(616)),l=n(693),c=n(971),d=n(550),u=(0,p.default)();o.cleanupApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const r=o.apikey||(0,l.findSavedKey)(),{bundle:p,keep:y=4}=o,g=o.force||!1,v=yield(0,l.getConfig)();e=e||(null===(n=null==v?void 0:v.app)||void 0===n?void 0:n.appId),r||a.program.error("Missing API key, you need to provide an API key to delete your app"),e||a.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const f=(0,l.createSupabaseClient)(r),h=yield(0,l.verifyUser)(f,r);yield(0,d.checkAppExistsAndHasPermission)(f,e,r),console.log("Querying all available versions in Capgo");let m=yield(0,c.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 t=[];return null==e||e.forEach((e=>{s.default.gte(e.name,o)&&s.default.lt(e.name,`${n}`)&&t.push(e)})),t})(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,c.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,r)=>{var a,s,p;return t(void 0,void 0,void 0,(function*(){var t,d,u,y;try{for(a=!0,s=i(e);!(t=(p=yield s.next()).done);){y=p.value,a=!1;try{const e=y;console.log(`Removing ${e.name} created on ${(0,l.getHumanDate)(e)}`),yield(0,c.deleteSpecificVersion)(o,n,r,e.name)}finally{a=!0}}}catch(e){d={error:e}}finally{try{a||t||!(u=s.return)||(yield u.call(s))}finally{if(d)throw d.error}}}))})(b,f,e,h)}else console.log("Nothing to be removed, aborting removal...")}))},790:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const i=n(304),r=n(147),a=n(518),s=n(693);o.decryptZip=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,p,l;(0,r.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const c=yield(0,s.getConfig)(),{extConfig:d}=c.app;n.key||(0,r.existsSync)(s.baseKey)||(null===(p=null===(t=d.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===p?void 0:p.privateKey)||i.program.error(`Private Key not found at the path ${s.baseKey} or in ${c.app.extConfigFilePath}`);const u=n.key||s.baseKey;let{privateKey:y}=n.keyData||(null===(l=null==d?void 0:d.plugins)||void 0===l?void 0:l.CapacitorUpdater)||"";(0,r.existsSync)(u)||y?(0,r.existsSync)(u)&&(y=(0,r.readFileSync)(u).toString()):i.program.error(`Cannot find public key ${u} or as keyData option or in ${c.app.extConfigFilePath}`);const g=(0,r.readFileSync)(e),v=(0,a.decryptSource)(g,o,y);(0,r.writeFileSync)(`${e}_decrypted.zip`,v)}))},513:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const i=n(304),r=n(693),a=n(971);o.deleteApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const{bundle:t}=o,s=o.apikey||(0,r.findSavedKey)(),p=yield(0,r.getConfig)(),l=(0,r.useLogSnag)();e=e||(null===(n=null==p?void 0:p.app)||void 0===n?void 0:n.appId),s||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");const c=(0,r.createSupabaseClient)(s),d=yield(0,r.verifyUser)(c,s),{data:u,error:y}=yield c.rpc("exist_app",{appid:e,apikey:s}).single();if(u&&!y||i.program.error("No permission to delete"),t)return console.log(`Delete ${e}@${t} from Capgo`),yield(0,a.deleteSpecificVersion)(c,e,d,t),void console.log(`${e}@${t} deleted from server`);console.log(`Delete ${e} from Capgo`);const{data:g,error:v}=yield c.from("app_versions").select().eq("app_id",e).eq("user_id",d);if(v&&i.program.error(`App ${e} not found in database ${(0,r.formatError)(v)} `),g&&g.length){const o=g.filter((e=>e.bucket_id&&!e.external_url)).map((o=>`${d}/${e}/versions/${o.bucket_id} `)),{error:n}=yield c.storage.from("apps").remove(o);n&&i.program.error(`Cannot delete stored version for app ${e} from storage ${(0,r.formatError)(n)} `)}const{error:f}=yield c.from("app_versions").delete().eq("app_id",e).eq("user_id",d);f&&i.program.error(`Cannot delete version for app ${e} from database ${(0,r.formatError)(f)} `);const{error:h}=yield c.from("apps").delete().eq("app_id",e).eq("user_id",d);h&&i.program.error(`Cannot delete from database ${(0,r.formatError)(h)} `),l.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":d,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`)}))},682:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const i=n(304),r=n(147),a=n(518),s=n(693);o.encryptZip=(e,o)=>t(void 0,void 0,void 0,(function*(){(0,r.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const n=o.key||s.baseKeyPub;let t=o.keyData||"";(0,r.existsSync)(n)||t?(0,r.existsSync)(n)&&(t=(0,r.readFileSync)(n).toString()):i.program.error(`Cannot find public key ${n} or as keyData option`);const p=(0,r.readFileSync)(e),l=(0,a.encryptSource)(p,t);console.log("ivSessionKey",l.ivSessionKey),(0,r.writeFileSync)(`${e}_encrypted.zip`,l.encryptedData)}))},213: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),r=n(790),a=n(682),s=n(174),p=n(69),l=n(552),c=n(513),d=n(131),u=n(658),y=t(n(598)),g=n(732),v=n(36),f=n(327);i.program.description("Manage packages and bundle versions in capgo Cloud").version(y.default.version),i.program.command("add [appid]").alias("a").description("Add a new app to 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"),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("upload [appid]").alias("u").description("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.command("set [appid]").alias("s").description("Modify a channel configuration").action(d.setChannel).requiredOption("-c, --channel <channel>","channel to link to").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("--downgrade","Allow to downgrade to version under native one").option("--latest","get the latest version key in the package.json to set it to the channel").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("delete [appid]").alias("d").description("Delete an app from capgo Cloud").action(c.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the app to delete"),i.program.command("list [appid]").alias("ls").description("List versions in capgo Cloud").action(v.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),i.program.command("cleanup [appid]").alias("c").description("Cleanup versions in capgo Cloud").action(f.cleanupApp).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"),i.program.command("channel [mode] [channelid] [appid]").description("Create, set or delete channel").action(l.manageChannel).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(p.manageKey).option("-f, --force","force generate a new one"),i.program.command("decrypt [zipPath] [sessionKey]").description("Decrypt a signed zip update").action(r.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),i.program.command("encrypt [zipPath]").description("Encrypt a zip update").action(a.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),i.program.parse(process.argv)},69:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.manageKey=void 0;const i=n(304),r=n(147),a=n(778),s=n(518),p=n(693);o.manageKey=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,l;"save"===e?(n=o.key,l=o.keyData,t(void 0,void 0,void 0,(function*(){(0,r.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,r.existsSync)(t)||s?(0,r.existsSync)(t)&&(s=(0,r.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,a.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,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const{publicKey:o,privateKey:n}=(0,s.createRSA)();(0,r.existsSync)(p.baseKeyPub)&&!e.force&&i.program.error("Public Key already exists, use --force to overwrite"),(0,r.writeFileSync)(p.baseKeyPub,o),(0,r.existsSync)(p.baseKey)&&!e.force&&i.program.error("Private Key already exists, use --force to overwrite"),(0,r.writeFileSync)(p.baseKey,n);const t=yield(0,p.getConfig)(),{extConfig:l}=t.app;l&&(l.plugins||(l.plugins={}),l.plugins.CapacitorUpdater||(l.plugins.CapacitorUpdater={}),l.plugins.CapacitorUpdater.privateKey=n,(0,a.writeConfig)(l,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)")}))},36:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const i=n(304),r=n(693),a=n(550),s=n(971);o.listApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,r.findSavedKey)(),p=yield(0,r.getConfig)();e=e||(null===(n=null==p?void 0:p.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,r.createSupabaseClient)(t),c=yield(0,r.verifyUser)(l,t);yield(0,a.checkAppExistsAndHasPermission)(l,e,t);const d=yield(0,s.getActiveAppVersions)(l,e,c);console.log(`Active versions in Capgo: ${null==d?void 0:d.length}`),(0,s.displayBundles)(d)}))},732:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.login=void 0;const i=n(304),r=n(147),a=n(37),s=n(693);o.login=(e,o)=>t(void 0,void 0,void 0,(function*(){try{const{local:n}=o,t=(0,s.useLogSnag)();if(n)(0,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository"),(0,r.writeFileSync)(".capgo",`${e}\n`),(0,r.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,a.homedir)();(0,r.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const p=(0,s.createSupabaseClient)(e),l=yield(0,s.verifyUser)(p,e,["write","all","upload"]);t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":l},notify:!1}).catch(),console.log(`login saved into .capgo file in ${n?"local":"home"} directory`)}catch(e){console.error(e),process.exit(1)}}))},131:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=o.setChannelInternal=void 0;const i=n(304),r=n(550),a=n(693);o.setChannelInternal=(e,o,n,s,p)=>t(void 0,void 0,void 0,(function*(){const{bundle:t,latest:l,downgrade:c,upgrade:d,ios:u,android:y,selfAssign:g,channel:v,state:f}=p;v||i.program.error("Missing argument, you need to provide a channel"),l&&t&&i.program.error("Cannot set latest and bundle at the same time"),null==t&&null==f&&null==l&&null==c&&null==d&&null==u&&null==y&&null==g&&i.program.error("Missing argument, you need to provide a option to set");try{const p=(0,a.createSupabaseClient)(o),h=yield(0,a.verifyUser)(p,o,["write","all"]);yield(0,a.checkPlanValid)(p,h),yield(0,r.checkAppExistsAndHasPermission)(p,e,o);const m={created_by:h,app_id:e,name:v,version:void 0},b=l?n:t;if(null!=b){const{data:o,error:n}=yield p.from("app_versions").select().eq("app_id",e).eq("name",b).eq("user_id",h).eq("deleted",!1).single();!n&&o||i.program.error(`Cannot find version ${b}`),console.log(`Set ${e} channel: ${v} to @${b}`),m.version=o.id}null!=f&&("public"!==f&&"private"!==f||console.log(`Set ${e} channel: ${v} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${v} to ${"public"===f||"default"===f?"default":"normal"}`),m.public="public"===f||"default"===f),null!=c&&(console.log(`Set ${e} channel: ${v} to ${c?"allow":"disallow"} downgrade`),m.disableAutoUpdateUnderNative=!c),null!=d&&(console.log(`Set ${e} channel: ${v} to ${d?"allow":"disallow"} upgrade`),m.disableAutoUpdateToMajor=!d),null!=u&&(console.log(`Set ${e} channel: ${v} to ${u?"allow":"disallow"} ios update`),m.ios=!!u),null!=y&&(console.log(`Set ${e} channel: ${v} to ${y?"allow":"disallow"} android update`),m.android=!!y),null!=g&&(console.log(`Set ${e} channel: ${v} to ${g?"allow":"disallow"} self assign to this channel`),m.allow_device_self_set=!!g);try{const{error:e}=yield(0,a.updateOrCreateChannel)(p,m,o);e&&i.program.error(`Cannot set channel ${(0,a.formatError)(e)}`)}catch(e){i.program.error(`Cannot set channel ${(0,a.formatError)(e)}`)}s.publish({channel:"app",event:"Set app",icon:"✅",tags:{"user-id":h,"app-id":e},notify:!1}).catch()}catch(e){i.program.error(`Unknow error ${(0,a.formatError)(e)}`)}console.log("Done ✅")})),o.setChannel=(e,n)=>t(void 0,void 0,void 0,(function*(){var t,r,s;const p=n.apikey||(0,a.findSavedKey)(),l=yield(0,a.getConfig)(),c=(0,a.useLogSnag)();return console.log('COMMAND DEPRECATED, use "channel set" instead'),e=e||(null===(t=null==l?void 0:l.app)||void 0===t?void 0:t.appId),p||i.program.error("Missing API key, you need to provide a API key to set your app"),e||i.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),(0,o.setChannelInternal)(e,p,null===(s=null===(r=null==l?void 0:l.app)||void 0===r?void 0:r.package)||void 0===s?void 0:s.version,c,n)}))},658:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,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 r=i(n(844)),a=n(304),s=n(113),p=i(n(295)),l=n(147),c=n(906),d=n(550),u=n(518),y=n(693);o.uploadVersion=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,i,g;let{bundle:v,path:f,channel:h}=o;const{external:m,key:b=!1,displayIvSession:_}=o,k=o.apikey||(0,y.findSavedKey)(),w=(0,y.useLogSnag)();h=h||"dev";const $=yield(0,y.getConfig)();e=e||(null===(n=null==$?void 0:$.app)||void 0===n?void 0:n.appId),v=v||(null===(i=null===(t=null==$?void 0:$.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version),y.regexSemver.test(v)||a.program.error(`Your bundle name ${v}, is not valid it should follow semver convention : https://semver.org/`),f=f||(null===(g=null==$?void 0:$.app)||void 0===g?void 0:g.webDir),k||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e&&v&&f||a.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 x=(0,y.createSupabaseClient)(k),C=yield(0,y.verifyUser)(x,k,["write","all","upload"]);yield(0,y.checkPlanValid)(x,C,!1),yield(0,d.checkAppExistsAndHasPermission)(x,e,k);const S=new p.default.MultiBar({clearOnComplete:!1,hideCursor:!0},p.default.Presets.shades_grey),A=S.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},p.default.Presets.shades_grey);A.start(7,0,{speed:"N/A"});const{data:P,error:D}=yield x.rpc("exist_app_versions",{apikey:k,name_version:v,appid:e}).single();(P||D)&&(S.stop(),a.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,y.formatError)(D)}`)),A.increment();const{data:I,error:q}=yield x.rpc("is_trial",{userid:C}).single();(I&&I>0||q)&&S.log(`WARNING !!\nTrial expires in ${I} days, upgrade here: ${y.hostWeb}/dashboard/settings/plans\n`),A.increment();const{data:K,error:E}=yield x.rpc("exist_app",{appid:e,apikey:k}).single();K&&!E||(S.stop(),a.program.error(`Cannot find app ${e} in your account \n${(0,y.formatError)(E)}`)),A.increment();const{data:j,error:M}=yield x.rpc("exist_app_versions",{appid:e,apikey:k,name_version:v}).single();(j||M)&&a.program.error(`Version already exists ${(0,y.formatError)(M)}`),A.increment();const U=(0,s.randomUUID)();let V,O="";if(m)m&&!m.startsWith("https://")&&(S.stop(),a.program.error(`External link should should start with "https://" current is "${m}"`));else{const o=new r.default;o.addLocalFolder(f);let n=o.toBuffer();if(O=yield(0,c.checksum)(n,"crc32"),b||(0,l.existsSync)(y.baseKeyPub)){const e="string"==typeof b?b:y.baseKeyPub;(0,l.existsSync)(e)||a.program.error(`Cannot find public key ${e}`);const o=(0,l.readFileSync)(e);S.log("Encrypting your bundle\n");const t=(0,u.encryptSource)(n,o.toString());V=t.ivSessionKey,_&&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/${C}/${e}/versions`;A.increment(),t>20&&(S.log(`WARNING !!\nThe app size is ${t} Mb, this may take a while to download for users\n`),w.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":C,"app-id":e},notify:!1}).catch());const{error:s}=yield x.storage.from(i).upload(U,n,{contentType:"application/zip",cacheControl:"2592000"});s&&(S.stop(),a.program.error(`Cannot upload ${(0,y.formatError)(s)}`))}A.increment();const{data:N,error:z}=yield(0,y.updateOrCreateVersion)(x,{bucket_id:m?void 0:U,user_id:C,name:v,app_id:e,session_key:V,external_url:m,checksum:O},k);if(z&&(S.stop(),a.program.error(`Cannot add bundle ${(0,y.formatError)(z)}`)),A.increment(),N){const{error:o}=yield(0,y.updateOrCreateChannel)(x,{name:h,app_id:e,created_by:C,version:N.id},k);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 F=(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/${F}`),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/${F}/devices`),w.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":C,"app-id":e},notify:!1}).catch()}))},693:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(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(a,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 r=n(778),a=n(304),s=n(885),p=i(n(867)),l=n(147),c=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:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:i}).single();t&&!r||a.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(r)}`)})),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))||a.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,c.homedir)()}/.capgo`;return(0,l.existsSync)(e)?(console.log(`Use global apy key ${e}`),(0,l.readFileSync)(e,"utf8").trim()):(e=".capgo",(0,l.existsSync)(e)?(console.log(`Use local apy key ${e}`),(0,l.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,r.loadConfig)()}catch(e){a.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:r}=yield e.rpc("get_user_id",{apikey:n}).single(),s=t?t.toString():"";return s&&!r||a.program.error(`Cannot verify user ${(0,o.formatError)(r)}`),s})),o.getHumanDate=e=>new Date(e.created_at||"").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":"2.5.1","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":">=14.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/bin/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.1.2","@tomasklaen/checksum":"^1.1.0","adm-zip":"^0.5.9","cli-progress":"3.11.2","commander":"9.4.1","console-table-printer":"^2.11.1","fs-extra":"11.1.0","logsnag":"^0.1.5","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.9","@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.31.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"3.5.3","eslint-plugin-import":"2.26.0","eslint-plugin-prettier":"^4.2.1","git-format-staged":"3.0.0","husky":"^8.0.2","nodemon":"2.0.20","pkg":"5.8.0","prettier":"2.8.3","ts-loader":"^9.4.1","ts-node":"^10.9.1","tsconfig-paths":"4.1.2","typescript":"4.9.4","webpack":"5.75.0","webpack-cli":"^5.0.0","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t].call(r.exports,r,r.exports,n),r.exports}(213)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "2.4.7",
3
+ "version": "2.5.1",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -42,7 +42,7 @@
42
42
  "author": "github.com/riderx",
43
43
  "license": "Apache 2.0",
44
44
  "dependencies": {
45
- "@capacitor/cli": "4.6.1",
45
+ "@capacitor/cli": "4.6.2",
46
46
  "@supabase/supabase-js": "^2.1.2",
47
47
  "@tomasklaen/checksum": "^1.1.0",
48
48
  "adm-zip": "^0.5.9",
@@ -0,0 +1,121 @@
1
+ import { SupabaseClient } from '@supabase/supabase-js'
2
+ import { program } from 'commander'
3
+ import { Database } from 'types/supabase.types'
4
+ import { setChannelInternal } from './set';
5
+ import { checkAppExistsAndHasPermission } from "../api/app";
6
+ import {
7
+ getConfig, createSupabaseClient,
8
+ findSavedKey, checkPlanValid,
9
+ verifyUser,
10
+ useLogSnag,
11
+ } from './utils';
12
+
13
+ interface Options {
14
+ apikey: string;
15
+ bundle: string;
16
+ state?: string;
17
+ downgrade?: boolean;
18
+ latest?: boolean;
19
+ upgrade?: boolean;
20
+ ios?: boolean;
21
+ android?: boolean;
22
+ selfAssign?: boolean;
23
+ channel?: string;
24
+ }
25
+
26
+ const findUnknownVersion = (supabase: SupabaseClient<Database>, appId: string) => supabase
27
+ .from('app_versions')
28
+ .select('id')
29
+ .eq('app_id', appId)
30
+ .eq('name', 'unknown')
31
+ .single()
32
+
33
+
34
+ const createChannel = (supabase: SupabaseClient<Database>, update: Database['public']['Tables']['channels']['Insert']) => supabase
35
+ .from('channels')
36
+ .insert(update)
37
+ .select()
38
+ .single()
39
+
40
+ const deleteChannel = (supabase: SupabaseClient<Database>, name: string, appId: string, userId: string) => supabase
41
+ .from('channels')
42
+ .delete()
43
+ .eq('name', name)
44
+ .eq('app_id', appId)
45
+ .eq('user_id', userId)
46
+ .single()
47
+
48
+ export const manageChannel = async (mode: string, channelId: string, appid: string, options: Options) => {
49
+ const apikey = options.apikey || findSavedKey()
50
+ const config = await getConfig();
51
+ appid = appid || config?.app?.appId
52
+ const snag = useLogSnag()
53
+
54
+ if (!apikey) {
55
+ program.error("Missing API key, you need to provide a API key to upload your bundle");
56
+ }
57
+ if (!appid || !channelId) {
58
+ program.error("Missing argument, you need to provide a appid and a channel name, or be in a capacitor project");
59
+ }
60
+ const supabase = createSupabaseClient(apikey)
61
+
62
+ const userId = await verifyUser(supabase, apikey, ['write', 'all']);
63
+ await checkPlanValid(supabase, userId, false)
64
+ // Check we have app access to this appId
65
+ await checkAppExistsAndHasPermission(supabase, appid, apikey);
66
+
67
+ if (mode === 'create') {
68
+ console.log(`Create channel ${appid}#${channelId} to Capgo cloud`);
69
+ try {
70
+ const { data } = await findUnknownVersion(supabase, appid)
71
+ if (!data) {
72
+ program.error(`Cannot find default version for channel creation, please contact Capgo support 🤨`);
73
+ }
74
+ await createChannel(supabase, { name: channelId, app_id: appid, version: data.id, created_by: userId });
75
+ console.log(`Channel created ✅`);
76
+ snag.publish({
77
+ channel: 'app',
78
+ event: 'Create channel',
79
+ icon: '✅',
80
+ tags: {
81
+ 'user-id': userId,
82
+ 'app-id': appid,
83
+ 'channel': channelId,
84
+ },
85
+ notify: false,
86
+ }).catch()
87
+ } catch (error) {
88
+ console.log(`Cannot create Channel 🙀`, error);
89
+ }
90
+ } else if (mode === 'delete') {
91
+ console.log(`Delete channel ${appid}#${channelId} to Capgo cloud`);
92
+ try {
93
+ await deleteChannel(supabase, channelId, appid, userId);
94
+ console.log(`Channel Delete ✅`);
95
+ snag.publish({
96
+ channel: 'app',
97
+ event: 'Delete channel',
98
+ icon: '✅',
99
+ tags: {
100
+ 'user-id': userId,
101
+ 'app-id': appid,
102
+ 'channel': channelId,
103
+ },
104
+ notify: false,
105
+ }).catch()
106
+ } catch (error) {
107
+ console.log(`Cannot delete Channel 🙀`, error);
108
+ }
109
+ } else if (mode === 'set') {
110
+ console.log(`Set channel ${appid}#${channelId} to Capgo cloud`);
111
+ try {
112
+ options.channel = channelId
113
+ await setChannelInternal(appid, apikey, config?.app?.package?.version, snag, options);
114
+ console.log(`Channel Set ✅`);
115
+ } catch (error) {
116
+ console.log(`Cannot set Channel 🙀`, error);
117
+ }
118
+ } else {
119
+ program.error('You should provide a valid option (create or delete)');
120
+ }
121
+ }
package/src/bin/index.ts CHANGED
@@ -3,6 +3,7 @@ import { decryptZip } from './decrypt';
3
3
  import { encryptZip } from './encrypt';
4
4
  import { addApp } from './add';
5
5
  import { manageKey } from './key';
6
+ import { manageChannel } from './channel';
6
7
  import { deleteApp } from './delete';
7
8
  import { setChannel } from './set';
8
9
  import { uploadVersion } from './upload';
@@ -92,6 +93,25 @@ program
92
93
  .option('-k, --keep <keep>', 'number of version to keep')
93
94
  .option('-f, --force', 'force removal');
94
95
 
96
+ program
97
+ .command('channel [mode] [channelid] [appid]')
98
+ .description('Create, set or delete channel')
99
+ .action(manageChannel)
100
+ .option('-a, --apikey <apikey>', 'apikey to link to your account')
101
+ .option('-b, --bundle <bundle>', 'bundle version number of the file to set')
102
+ .option('-s, --state <state>', 'set the state of the channel, default or normal')
103
+ .option('--latest', 'get the latest version key in the package.json to set it to the channel')
104
+ .option('--downgrade', 'Allow to downgrade to version under native one')
105
+ .option('--no-downgrade', 'Disable downgrade to version under native one')
106
+ .option('--upgrade', 'Allow to upgrade to version above native one')
107
+ .option('--no-upgrade', 'Disable upgrade to version above native one')
108
+ .option('--ios', 'Allow sending update to ios devices')
109
+ .option('--no-ios', 'Disable sending update to ios devices')
110
+ .option('--android', 'Allow sending update to android devices')
111
+ .option('--no-android', 'Disable sending update to android devices')
112
+ .option('--self-assign', 'Allow to device to self assign to this channel')
113
+ .option('--no-self-assign', 'Disable devices to self assign to this channel');
114
+
95
115
  program
96
116
  .command('key [option]')
97
117
  .description('Save base64 signing key in capacitor config, usefull for CI')
package/src/bin/set.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { program } from 'commander';
2
+ import { Console } from 'console';
3
+ import LogSnag from 'logsnag';
2
4
  import { Database } from 'types/supabase.types';
3
5
  import { checkAppExistsAndHasPermission } from "../api/app";
4
6
  import {
@@ -20,19 +22,8 @@ interface Options {
20
22
  channel?: string;
21
23
  }
22
24
 
23
- export const setChannel = async (appid: string, options: Options) => {
25
+ export const setChannelInternal = async (appid: string, apikey: string, defaulVersion: string, snag: LogSnag, options: Options) => {
24
26
  const { bundle, latest, downgrade, upgrade, ios, android, selfAssign, channel, state } = options;
25
- const apikey = options.apikey || findSavedKey()
26
- const config = await getConfig()
27
- const snag = useLogSnag()
28
-
29
- appid = appid || config?.app?.appId
30
- if (!apikey) {
31
- program.error("Missing API key, you need to provide a API key to set your app");
32
- }
33
- if (!appid) {
34
- program.error("Missing argument, you need to provide a appid, or be in a capacitor project");
35
- }
36
27
  if (!channel) {
37
28
  program.error("Missing argument, you need to provide a channel");
38
29
  }
@@ -61,7 +52,7 @@ export const setChannel = async (appid: string, options: Options) => {
61
52
  name: channel,
62
53
  version: undefined as any,
63
54
  }
64
- const bundleVersion = latest ? config?.app?.package?.version : bundle
55
+ const bundleVersion = latest ? defaulVersion : bundle
65
56
  if (bundleVersion != null) {
66
57
  const { data, error: vError } = await supabase
67
58
  .from('app_versions')
@@ -126,3 +117,19 @@ export const setChannel = async (appid: string, options: Options) => {
126
117
  }
127
118
  console.log(`Done ✅`);
128
119
  }
120
+
121
+ export const setChannel = async (appid: string, options: Options) => {
122
+ const apikey = options.apikey || findSavedKey()
123
+ const config = await getConfig()
124
+ const snag = useLogSnag()
125
+
126
+ console.log('COMMAND DEPRECATED, use "channel set" instead')
127
+ appid = appid || config?.app?.appId
128
+ if (!apikey) {
129
+ program.error("Missing API key, you need to provide a API key to set your app");
130
+ }
131
+ if (!appid) {
132
+ program.error("Missing argument, you need to provide a appid, or be in a capacitor project");
133
+ }
134
+ return setChannelInternal(appid, apikey, config?.app?.package?.version, snag, options)
135
+ }