@capgo/cli 2.6.4 → 2.6.5

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,8 @@
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.6.5](https://github.com/Cap-go/capgo-cli/compare/v2.6.4...v2.6.5) (2023-02-13)
6
+
5
7
  ### [2.6.4](https://github.com/Cap-go/capgo-cli/compare/v2.6.3...v2.6.4) (2023-02-13)
6
8
 
7
9
  ### [2.6.3](https://github.com/Cap-go/capgo-cli/compare/v2.6.2...v2.6.3) (2023-02-13)
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- (()=>{"use strict";var e={642:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,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")}))},860: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(541);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)}`)}}))},213:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createRSA=o.encryptSource=o.decryptSource=void 0;const t=n(113),i="aes-128-cbc",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"})}}},933: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(541);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)}`)}}))},350: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(541);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)} `)}))},89: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(541),s=n(860),p=n(933),l=n(350);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}))},657: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(541),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 x="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);x=(null==n?void 0:n.publicUrl)||x}const{error:$}=yield f.from("apps").insert({icon_url:x,user_id:h,name:d,app_id:e});$&&i.program.error(`Could not add app ${(0,l.formatError)($)}`);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)}`),yield 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"),process.exit()}))},203: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(399),a=n(642),s=n(541);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 ✅"),yield 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 ✅"),yield 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)");process.exit()}))},30: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(541),c=n(89),d=n(642),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),process.exit()}else console.log("Nothing to be removed, aborting removal...")}))},729: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(213),s=n(541);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),process.exit()}))},721: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(541),a=n(89);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)} `),yield l.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":d,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`),process.exit()}))},154: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(213),s=n(541);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),process.exit()}))},462: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(729),a=n(154),s=n(657),p=n(380),l=n(801),c=n(203),d=n(721),u=n(399),y=n(991),g=t(n(598)),v=n(418),f=n(296),h=n(30);i.program.description("Manage packages and bundle versions in capgo Cloud").version(g.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("doctor").description("Get info about your Capgo install").action(p.getInfo),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(v.login).option("--local","Only save in local folder"),i.program.command("upload [appid]").alias("u").description("Upload a new bundle to capgo Cloud").action(y.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(u.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(d.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(f.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(h.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(c.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(l.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.parseAsync()},380: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.getInfo=void 0;const r=n(147),a=i(n(362)),s=n(17),p=i(n(176)),l=i(n(598));o.getInfo=()=>t(void 0,void 0,void 0,(function*(){console.log(" 💊 Capgo Doctor 💊"),console.log("\n"),console.log(" Installed Dependencies:"),console.log("\n");const e=yield t(void 0,void 0,void 0,(function*(){const{dependencies:e}=yield t(void 0,void 0,void 0,(function*(){const e=(0,r.readFileSync)((0,s.join)(process.cwd(),"package.json"));return JSON.parse(e)})),o={"@capgo/cli":l.default.version};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&n.startsWith("@capgo/")&&(o[n]=e[n]);return o}));0===Object.keys(e).length&&(console.log("\n"),console.log("%s","🚨 No dependencies found"),process.exit(1));for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const n=e[o];console.log(` ${o}: ${n}`)}console.log("\n");const o=new p.default;o.add("loading",{text:"Loading latest dependencies"});const n=yield(e=>t(void 0,void 0,void 0,(function*(){const o={},n=[];for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.push((0,a.default)(o));return yield Promise.all(n).then((n=>{const t=Object.keys(e);for(let e=0;e<n.length;e+=1){const i=n[e];i&&(o[t[e]]=i)}})),o})))(e);o.succeed("loading",{text:"Latest Dependencies:"}),console.log("\n");for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const o=n[e];console.log(` ${e}: ${o}`)}JSON.stringify(e)!==JSON.stringify(n)&&(console.log("\n"),console.log("%s","🚨 Some dependencies are not up to date"),process.exit(1)),console.log("\n"),console.log("%s","✅ All dependencies are up to date"),process.exit()}))},801: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(213),p=n(541);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)"),process.exit()}))},296: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(541),a=n(642),s=n(89);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),process.exit()}))},418: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(541);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"]);yield 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)}process.exit()}))},399: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(642),a=n(541);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)}`)}yield 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)}))},991: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(642),u=n(213),y=n(541);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 x=yield(0,y.getConfig)();e=e||(null===(n=null==x?void 0:x.app)||void 0===n?void 0:n.appId),v=v||(null===(i=null===(t=null==x?void 0:x.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==x?void 0:x.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 $=(0,y.createSupabaseClient)(k),C=yield(0,y.verifyUser)($,k,["write","all","upload"]);yield(0,y.checkPlanValid)($,C,!1),yield(0,d.checkAppExistsAndHasPermission)($,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 $.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 $.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:j,error:K}=yield $.rpc("exist_app",{appid:e,apikey:k}).single();j&&!K||(S.stop(),a.program.error(`Cannot find app ${e} in your account \n${(0,y.formatError)(K)}`)),A.increment();const{data:O,error:M}=yield $.rpc("exist_app_versions",{appid:e,apikey:k,name_version:v}).single();(O||M)&&a.program.error(`Version already exists ${(0,y.formatError)(M)}`),A.increment();const E=(0,s.randomUUID)();let U,V="";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(V=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());U=t.ivSessionKey,_&&S.log(`Your Iv Session key is ${U},\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`),S.log("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield w.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":C,"app-id":e},notify:!1}).catch());const{error:s}=yield $.storage.from(i).upload(E,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)($,{bucket_id:m?void 0:E,user_id:C,name:v,app_id:e,session_key:U,external_url:m,checksum:V},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)($,{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`),yield w.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":C,"app-id":e},notify:!1}).catch(),process.exit()}))},541: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")},176:e=>{e.exports=require("@trufflesuite/spinnies")},844:e=>{e.exports=require("adm-zip")},295:e=>{e.exports=require("cli-progress")},304:e=>{e.exports=require("commander")},847:e=>{e.exports=require("console-table-printer")},470:e=>{e.exports=require("fs-extra")},362:e=>{e.exports=require("get-latest-version")},133:e=>{e.exports=require("logsnag")},11:e=>{e.exports=require("mime")},867:e=>{e.exports=require("prettyjson")},616:e=>{e.exports=require("prompt-sync")},505:e=>{e.exports=require("semver/preload")},113:e=>{e.exports=require("crypto")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},17:e=>{e.exports=require("path")},598:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"2.6.4","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.3","@supabase/supabase-js":"^2.5.0","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","cli-progress":"3.11.2","commander":"10.0.0","console-table-printer":"^2.11.1","fs-extra":"11.1.0","get-latest-version":"^5.0.0","logsnag":"^0.1.6","mime":"^3.0.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","semver":"^7.3.8"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/cli-progress":"^3.11.0","@types/fs-extra":"^9.0.13","@types/mime":"^3.0.1","@types/node":"^18.11.18","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/semver":"^7.3.13","@typescript-eslint/eslint-plugin":"5.47.1","@typescript-eslint/parser":"5.47.1","eslint":"8.33.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.6.0","eslint-import-resolver-typescript":"3.5.3","eslint-plugin-import":"2.27.5","eslint-plugin-prettier":"^4.2.1","git-format-staged":"3.0.0","husky":"^8.0.3","nodemon":"2.0.20","pkg":"5.8.0","prettier":"2.8.4","ts-loader":"^9.4.2","ts-node":"^10.9.1","tsconfig-paths":"4.1.2","typescript":"4.9.5","webpack":"5.75.0","webpack-cli":"^5.0.1","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t].call(r.exports,r,r.exports,n),r.exports}(462)})();
2
+ (()=>{"use strict";var e={642:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,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")}))},860: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(541);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)}`)}}))},213:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createRSA=o.encryptSource=o.decryptSource=void 0;const t=n(113),i="aes-128-cbc",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"})}}},933: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(541);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)}`)}}))},350: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(541);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)} `)}))},89: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(541),s=n(860),p=n(933),l=n(350);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}))},657: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(541),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 x="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);x=(null==n?void 0:n.publicUrl)||x}const{error:$}=yield f.from("apps").insert({icon_url:x,user_id:h,name:d,app_id:e});$&&i.program.error(`Could not add app ${(0,l.formatError)($)}`);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)}`),yield 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"),process.exit()}))},203: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(399),a=n(642),s=n(541);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 ✅"),yield 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 ✅"),yield 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)");process.exit()}))},30: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(541),c=n(89),d=n(642),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),process.exit()}else console.log("Nothing to be removed, aborting removal...")}))},729: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(213),s=n(541);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),process.exit()}))},721: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(541),a=n(89);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)} `),yield l.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":d,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`),process.exit()}))},154: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(213),s=n(541);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),process.exit()}))},462: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(729),a=n(154),s=n(657),p=n(380),l=n(801),c=n(203),d=n(721),u=n(399),y=n(991),g=t(n(598)),v=n(418),f=n(296),h=n(30);i.program.description("Manage packages and bundle versions in capgo Cloud").version(g.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("doctor").description("Get info about your Capgo install").action(p.getInfo),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(v.login).option("--local","Only save in local folder"),i.program.command("upload [appid]").alias("u").description("Upload a new bundle to capgo Cloud").action(y.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(u.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(d.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(f.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(h.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(c.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(l.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.parseAsync()},380: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.getInfo=void 0;const r=n(147),a=i(n(362)),s=n(17),p=i(n(176)),l=i(n(598));o.getInfo=()=>t(void 0,void 0,void 0,(function*(){console.log(" 💊 Capgo Doctor 💊"),console.log("\n"),console.log(" Installed Dependencies:"),console.log("\n");const e=yield t(void 0,void 0,void 0,(function*(){const{dependencies:e}=yield t(void 0,void 0,void 0,(function*(){const e=(0,r.readFileSync)((0,s.join)(process.cwd(),"package.json"));return JSON.parse(e)})),o={"@capgo/cli":l.default.version};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&n.startsWith("@capgo/")&&(o[n]=e[n]);return o}));0===Object.keys(e).length&&(console.log("\n"),console.log("%s","🚨 No dependencies found"),process.exit(1));for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const n=e[o];console.log(` ${o}: ${n}`)}console.log("\n");const o=new p.default;o.add("loading",{text:"Loading latest dependencies"});const n=yield(e=>t(void 0,void 0,void 0,(function*(){const o={},n=[];for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.push((0,a.default)(o));return yield Promise.all(n).then((n=>{const t=Object.keys(e);for(let e=0;e<n.length;e+=1){const i=n[e];i&&(o[t[e]]=i)}})),o})))(e);o.succeed("loading",{text:"Latest Dependencies:"}),console.log("\n");for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const o=n[e];console.log(` ${e}: ${o}`)}JSON.stringify(e)!==JSON.stringify(n)&&(console.log("\n"),console.log("%s","🚨 Some dependencies are not up to date"),process.exit(1)),console.log("\n"),console.log("%s","✅ All dependencies are up to date"),process.exit()}))},801: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(213),p=n(541);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)"),process.exit()}))},296: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(541),a=n(642),s=n(89);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),process.exit()}))},418: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(541);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"]);yield 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)}process.exit()}))},399: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(642),a=n(541);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)}`)}yield 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)}))},991: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(642),u=n(213),y=n(541);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 x=yield(0,y.getConfig)();e=e||(null===(n=null==x?void 0:x.app)||void 0===n?void 0:n.appId),v=v||(null===(i=null===(t=null==x?void 0:x.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==x?void 0:x.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 $=(0,y.createSupabaseClient)(k),C=yield(0,y.verifyUser)($,k,["write","all","upload"]);yield(0,y.checkPlanValid)($,C,!1),yield(0,d.checkAppExistsAndHasPermission)($,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 $.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 $.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:j,error:K}=yield $.rpc("exist_app",{appid:e,apikey:k}).single();j&&!K||(S.stop(),a.program.error(`Cannot find app ${e} in your account \n${(0,y.formatError)(K)}`)),A.increment();const{data:O,error:M}=yield $.rpc("exist_app_versions",{appid:e,apikey:k,name_version:v}).single();(O||M)&&a.program.error(`Version already exists ${(0,y.formatError)(M)}`),A.increment();const E=(0,s.randomUUID)();let U,V="";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(V=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());U=t.ivSessionKey,_&&S.log(`Your Iv Session key is ${U},\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`),S.log("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield w.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":C,"app-id":e},notify:!1}).catch());const{error:s}=yield $.storage.from(i).upload(E,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)($,{bucket_id:m?void 0:E,user_id:C,name:v,app_id:e,session_key:U,external_url:m,checksum:V},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)($,{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`),yield w.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":C,"app-id":e},notify:!1}).catch(),process.exit()}))},541: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")},176:e=>{e.exports=require("@trufflesuite/spinnies")},844:e=>{e.exports=require("adm-zip")},295:e=>{e.exports=require("cli-progress")},304:e=>{e.exports=require("commander")},847:e=>{e.exports=require("console-table-printer")},470:e=>{e.exports=require("fs-extra")},362:e=>{e.exports=require("get-latest-version")},133:e=>{e.exports=require("logsnag")},11:e=>{e.exports=require("mime")},867:e=>{e.exports=require("prettyjson")},616:e=>{e.exports=require("prompt-sync")},505:e=>{e.exports=require("semver/preload")},113:e=>{e.exports=require("crypto")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},17:e=>{e.exports=require("path")},598:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"2.6.5","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.3","@supabase/supabase-js":"^2.5.0","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","cli-progress":"3.11.2","commander":"10.0.0","console-table-printer":"^2.11.1","fs-extra":"11.1.0","get-latest-version":"^5.0.0","logsnag":"^0.1.6","mime":"^3.0.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","semver":"^7.3.8"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/cli-progress":"^3.11.0","@types/fs-extra":"^9.0.13","@types/mime":"^3.0.1","@types/node":"^18.11.18","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/semver":"^7.3.13","@typescript-eslint/eslint-plugin":"5.47.1","@typescript-eslint/parser":"5.47.1","eslint":"8.34.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.6.0","eslint-import-resolver-typescript":"3.5.3","eslint-plugin-import":"2.27.5","eslint-plugin-prettier":"^4.2.1","git-format-staged":"3.0.0","husky":"^8.0.3","nodemon":"2.0.20","pkg":"5.8.0","prettier":"2.8.4","ts-loader":"^9.4.2","ts-node":"^10.9.1","tsconfig-paths":"4.1.2","typescript":"4.9.5","webpack":"5.75.0","webpack-cli":"^5.0.1","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t].call(r.exports,r,r.exports,n),r.exports}(462)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "2.6.4",
3
+ "version": "2.6.5",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -69,7 +69,7 @@
69
69
  "@types/semver": "^7.3.13",
70
70
  "@typescript-eslint/eslint-plugin": "5.47.1",
71
71
  "@typescript-eslint/parser": "5.47.1",
72
- "eslint": "8.33.0",
72
+ "eslint": "8.34.0",
73
73
  "eslint-config-airbnb-base": "^15.0.0",
74
74
  "eslint-config-prettier": "^8.6.0",
75
75
  "eslint-import-resolver-typescript": "3.5.3",