@capgo/cli 3.9.0 → 3.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [3.9.1](https://github.com/Cap-go/capgo-cli/compare/v3.9.0...v3.9.1) (2023-04-12)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * better watch system ([eca70a0](https://github.com/Cap-go/capgo-cli/commit/eca70a0161691a22a4149d41fb83db74441eacae))
11
+
5
12
  ## [3.9.0](https://github.com/Cap-go/capgo-cli/compare/v3.8.5...v3.9.0) (2023-04-10)
6
13
 
7
14
 
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- (()=>{"use strict";var e={2235:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.newIconPath=o.checkAppExistsAndHasPermissionErr=o.checkAppExistsAndHasPermission=void 0;const i=n(7304);o.checkAppExistsAndHasPermission=(e,o,n,i=!0)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.rpc("exist_app",{appid:o,apikey:n}).single();return t!==i||a})),o.checkAppExistsAndHasPermissionErr=(e,n,a,r=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.checkAppExistsAndHasPermission)(e,n,a,r))&&i.program.error(`App ${n} does not exist or you don't have permission to access it`)})),o.newIconPath="assets/icon.png"},7213:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getActiveChannels=o.displayChannels=o.delChannel=o.createChannel=o.findUnknownVersion=o.checkVersionNotUsedInChannel=void 0;const s=n(7304),l=n(3847),d=a(n(552)),c=n(3866);o.checkVersionNotUsedInChannel=(e,n,t,i)=>r(void 0,void 0,void 0,(function*(){var a;const{data:r,error:l}=yield e.from("channels").select().eq("app_id",n).eq("created_by",t).eq("version",i.id);if(l&&s.program.error(`Cannot check Version ${n}@${i.name} ${(0,c.formatError)(l)}`),r&&r.length>0){if(d.intro(`❌ Version ${n}@${i.name} is used in ${r.length} channel`),yield d.confirm({message:"unlink it?"}))for(const t of r){const i=d.spinner();i.start(`Unlinking channel ${t.name}`);const{error:r}=yield e.from("channels").update({version:null===(a=yield(0,o.findUnknownVersion)(e,n))||void 0===a?void 0:a.id}).eq("id",t.id);r&&(i.stop(`Cannot update channel ${t.name} ${(0,c.formatError)(r)}`),process.exit(1)),i.stop(`✅ Channel ${t.name} unlinked`)}else s.program.error("unlink it first");d.outro(`Version unlinked from ${r.length} channel`)}})),o.findUnknownVersion=(e,o)=>e.from("app_versions").select("id").eq("app_id",o).eq("name","unknown").throwOnError().single().then((({data:e})=>e)),o.createChannel=(e,o)=>e.from("channels").insert(o).select().single(),o.delChannel=(e,o,n,t)=>e.from("channels").delete().eq("name",o).eq("app_id",n).eq("created_by",t).single(),o.displayChannels=e=>{const o=new l.Table({title:"Channels",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,c.getHumanDate)(e.created_at),Public:e.public?"✅":"❌"})})),o.printTable()},o.getActiveChannels=(e,o,n)=>r(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).order("created_at",{ascending:!1});return i&&s.program.error(`App ${o} not found in database ${(0,c.formatError)(i)} `),t}))},4201:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createRSA=o.encryptSource=o.decryptSource=void 0;const t=n(6113),i="aes-128-cbc",a="sha256",r="base64",s=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[l,d]=o.split(":"),c=(0,t.privateDecrypt)({key:n,padding:s,oaepHash:a},Buffer.from(d,r)),p=Buffer.from(l,r),u=c.toString(r);console.log("\nSessionB64",u);const y=(0,t.createDecipheriv)(i,c,p);return y.setAutoPadding(!0),Buffer.concat([y.update(e),y.final()])},o.encryptSource=(e,o)=>{const n=(0,t.randomBytes)(16),l=(0,t.randomBytes)(16),d=(0,t.createCipheriv)(i,l,n);d.setAutoPadding(!0);const c=`${n.toString(r)}:${(0,t.publicEncrypt)({key:o,padding:s,oaepHash:a},l).toString(r)}`;return{encryptedData:Buffer.concat([d.update(e),d.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"})}}},2035:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const s=n(7304),l=a(n(552)),d=n(3866);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>r(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);if(i&&s.program.error(`Cannot check Device override ${o}@${n.name} ${(0,d.formatError)(i)}`),t&&t.length>0)if(l.intro(`❌ Version ${o}@${n.name} is used in ${t.length} device override`),yield l.confirm({message:"unlink it?"}))for(const o of t){const n=l.spinner();n.start(`Unlinking device ${o.device_id}`);const{error:t}=yield e.from("devices_override").delete().eq("device_id",o.device_id);t&&(n.stop(`Cannot unlink device ${o.device_id} ${(0,d.formatError)(t)}`),process.exit(1)),n.stop(`✅ Device ${o.device_id} unlinked`)}else s.program.error("unlink it first")}))},8171:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(7304),a=n(3866);o.deleteFromStorage=(e,o,n,r,s)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${r.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${s} ${(0,a.formatError)(t)} `)}))},5995:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.checkLatest=void 0;const a=i(n(5362)),r=i(n(4147));o.checkLatest=()=>t(void 0,void 0,void 0,(function*(){const e=yield(0,a.default)("@capgo/cli");e!==r.default.version&&console.log("%s",`🚨 You are using @capgo/cli@${r.default.version} it's not the latest version.\nPlease use @capgo/cli@${e}" or @capgo/cli@latest to keep up to date with the latest features and bug fixes.`)}))},7937:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((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(7304),a=n(3847),r=n(3866),s=n(7213),l=n(2035),d=n(8171);o.deleteAppVersion=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("deleted",!1).eq("user_id",n).eq("name",a);t&&i.program.error(`App Version ${o}@${a} not found in database '${(0,r.formatError)(t)}'`)})),o.deleteSpecificVersion=(e,n,i,a)=>t(void 0,void 0,void 0,(function*(){const t=yield(0,o.getVersionData)(e,n,i,a);yield(0,s.checkVersionNotUsedInChannel)(e,n,i,t),yield(0,l.checkVersionNotUsedInDeviceOverride)(e,n,t),yield(0,d.deleteFromStorage)(e,i,n,t,a),yield(0,o.deleteAppVersion)(e,n,i,a)})),o.displayBundles=e=>{const o=new a.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,r.getHumanDate)(e.created_at)},null!=e.keep?{Keep:e.keep}:{}))})),o.printTable()},o.getActiveAppVersions=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return a&&i.program.error(`App ${o} not found in database ${(0,r.formatError)(a)} `),t})),o.getVersionData=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:s}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("name",a).eq("deleted",!1).single();return t&&!s||i.program.error(`App Version ${o}@${a} doesn't exist ${(0,r.formatError)(s)}`),t}))},4105:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addCommand=o.addApp=void 0;const i=n(9011),a=n(7304),r=n(6113),s=n(4470),l=n(5995),d=n(2235),c=n(3866);o.addApp=(e,o,n=!0)=>t(void 0,void 0,void 0,(function*(){var t,p,u;yield(0,l.checkLatest)(),o.apikey=o.apikey||(0,c.findSavedKey)();const y=yield(0,c.getConfig)();e=e||(null===(t=null==y?void 0:y.app)||void 0===t?void 0:t.appId);const f=(0,c.useLogSnag)();o.apikey||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||a.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const g=(0,c.createSupabaseClient)(o.apikey),v=yield(0,c.verifyUser)(g,o.apikey,["write","all"]);if(n)yield(0,d.checkAppExistsAndHasPermissionErr)(g,e,o.apikey,!1);else if(yield(0,d.checkAppExistsAndHasPermission)(g,e,o.apikey,!1))return!1;let h,m,{name:b,icon:k}=o;e=e||(null===(p=null==y?void 0:y.app)||void 0===p?void 0:p.appId),b=b||(null===(u=null==y?void 0:y.app)||void 0===u?void 0:u.appName)||"Unknown",k=k||"resources/icon.png",k&&b||a.program.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project"),n&&console.log(`Adding ${e} to Capgo`),k&&(0,s.existsSync)(k)?(h=(0,s.readFileSync)(k),m=(0,i.getType)(k)||"image/png",console.warn(`Found app icon ${k}`)):(0,s.existsSync)(d.newIconPath)?(h=(0,s.readFileSync)(d.newIconPath),m=(0,i.getType)(d.newIconPath)||"image/png",console.warn(`Found app icon ${d.newIconPath}`)):console.warn(`Cannot find app icon in any of the following locations: ${k}, ${d.newIconPath}`);const{data:w,error:_}=yield g.rpc("exist_app_v2",{appid:e}).single();(w||_)&&a.program.error(`App ${e} already exists ${(0,c.formatError)(_)}`);const x=`icon_${(0,r.randomUUID)()}`;let C="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(h&&m){const{error:o}=yield g.storage.from(`images/${v}/${e}`).upload(x,h,{contentType:m});o&&a.program.error(`Could not add app ${(0,c.formatError)(o)}`);const{data:n}=yield g.storage.from(`images/${v}/${e}`).getPublicUrl(x);C=(null==n?void 0:n.publicUrl)||C}const{error:$}=yield g.from("apps").insert({icon_url:C,user_id:v,name:b,app_id:e});$&&a.program.error(`Could not add app ${(0,c.formatError)($)}`);const{error:S}=yield g.from("app_versions").insert([{user_id:v,deleted:!0,name:"unknown",app_id:e},{user_id:v,deleted:!0,name:"builtin",app_id:e}]);return S&&a.program.error(`Could not add app ${(0,c.formatError)(S)}`),yield f.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":v,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now"),n&&(console.log("Done ✅"),process.exit()),!0})),o.addCommand=(e,n)=>t(void 0,void 0,void 0,(function*(){(0,o.addApp)(e,n,!0)}))},7591:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const i=n(7304),a=n(2235),r=n(3866);o.deleteApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;o.apikey=o.apikey||(0,r.findSavedKey)();const t=yield(0,r.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId);const s=(0,r.useLogSnag)();o.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,r.createSupabaseClient)(o.apikey),d=yield(0,r.verifyUser)(l,o.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(l,e,o.apikey);const{error:c}=yield l.storage.from(`images/${d}`).remove([e]);c&&i.program.error(`Could not add app ${(0,r.formatError)(c)}`);const{error:p}=yield l.storage.from(`apps/${e}/${d}`).remove(["versions"]);p&&i.program.error(`Could not delete app version ${(0,r.formatError)(p)}`);const{error:u}=yield l.from("apps").delete().eq("app_id",e).eq("user_id",d);u&&i.program.error(`Could not delete app ${(0,r.formatError)(u)}`),yield s.publish({channel:"app",event:"App Deleted",icon:"🗑️",tags:{"user-id":d,"app-id":e},notify:!1}).catch(),console.log("App deleted in Capgo"),console.log("Done ✅"),process.exit()}))},7239:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getInfo=void 0;const a=n(7147),r=i(n(5362)),s=n(1017),l=i(n(7176)),d=i(n(2037)),c=i(n(4147));o.getInfo=()=>t(void 0,void 0,void 0,(function*(){console.log(" 💊 Capgo Doctor 💊\n"),console.log(` OS: ${d.default.version()}\n`),console.log(" Installed Dependencies:\n");const e=yield t(void 0,void 0,void 0,(function*(){const{dependencies:e}=yield t(void 0,void 0,void 0,(function*(){const e=(0,a.readFileSync)((0,s.join)(process.cwd(),"package.json"));return JSON.parse(e)})),o={"@capgo/cli":c.default.version};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&n.startsWith("@capgo/")&&(o[n]=e[n]);return o}));0===Object.keys(e).length&&(console.log("\n"),console.log("%s","🚨 No dependencies found"),process.exit(1));for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const n=e[o];console.log(` ${o}: ${n}`)}console.log("\n");const o=new l.default;o.add("loading",{text:"Loading latest dependencies"});const n=yield(e=>t(void 0,void 0,void 0,(function*(){const o={},n=[];for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.push((0,r.default)(o));return yield Promise.all(n).then((n=>{const t=Object.keys(e);for(let e=0;e<n.length;e+=1){const i=n[e];i&&(o[t[e]]=i)}})),o})))(e);o.succeed("loading",{text:"Latest Dependencies:"}),console.log("\n");for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const o=n[e];console.log(` ${e}: ${o}`)}JSON.stringify(e)!==JSON.stringify(n)&&(console.log("\n"),console.log("%s","🚨 Some dependencies are not up to date"),process.exit(1)),console.log("\n"),console.log("%s","✅ All dependencies are up to date"),process.exit()}))},4430:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=o.getActiveApps=void 0;const i=n(7304),a=n(3847),r=n(2235),s=n(3866),l=n(5995);o.getActiveApps=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.from("apps").select().eq("user_id",o).order("created_at",{ascending:!1});return t&&i.program.error(`Apps not found in database ${(0,s.formatError)(t)} `),n})),o.listApp=(e,n)=>t(void 0,void 0,void 0,(function*(){var t;yield(0,l.checkLatest)(),n.apikey=n.apikey||(0,s.findSavedKey)();const d=yield(0,s.getConfig)();e=e||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId),n.apikey||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,s.createSupabaseClient)(n.apikey),p=yield(0,s.verifyUser)(c,n.apikey);console.log("Querying available versions in Capgo"),yield(0,r.checkAppExistsAndHasPermissionErr)(c,e,n.apikey);const u=yield(0,o.getActiveApps)(c,p);console.log(`Active app in Capgo: ${null==u?void 0:u.length}`),(e=>{const o=new a.Table({title:"Apps",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,s.getHumanDate)(e.created_at)})})),o.printTable()})(u),console.log("Done ✅"),process.exit()}))},1465:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setApp=void 0;const i=n(9011),a=n(7304),r=n(6113),s=n(4470),l=n(2235),d=n(3866);o.setApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;o.apikey=o.apikey||(0,d.findSavedKey)();const t=yield(0,d.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||a.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const c=(0,d.createSupabaseClient)(o.apikey),p=yield(0,d.verifyUser)(c,o.apikey,["write","all"]);yield(0,l.checkAppExistsAndHasPermissionErr)(c,e,o.apikey);const{name:u,icon:y}=o;let f,g;const v=`icon_${(0,r.randomUUID)()}`;let h="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(y&&(0,s.existsSync)(y)?(f=(0,s.readFileSync)(y),g=(0,i.getType)(y)||"image/png",console.warn(`Found app icon ${y}`)):(0,s.existsSync)(l.newIconPath)?(f=(0,s.readFileSync)(l.newIconPath),g=(0,i.getType)(l.newIconPath)||"image/png",console.warn(`Found app icon ${l.newIconPath}`)):console.warn(`Cannot find app icon in any of the following locations: ${y}, ${l.newIconPath}`),f&&g){const{error:o}=yield c.storage.from(`images/${p}/${e}`).upload(v,f,{contentType:g});o&&a.program.error(`Could not add app ${(0,d.formatError)(o)}`);const{data:n}=yield c.storage.from(`images/${p}/${e}`).getPublicUrl(v);h=(null==n?void 0:n.publicUrl)||h}const{error:m}=yield c.from("apps").update({icon_url:h,name:u}).eq("app_id",e).eq("user_id",p);m&&a.program.error(`Could not add app ${(0,d.formatError)(m)}`),console.log("Done ✅"),process.exit()}))},4992:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.watchApp=o.watch=void 0;const l=n(7304),d=a(n(552)),c=s(n(1121)),p=n(3422),u=n(3866),y=n(5995);o.watch=(e,o,n=!0)=>r(void 0,void 0,void 0,(function*(){if(o.apikey=o.apikey||(0,u.findSavedKey)(),!o.apikey)return n&&l.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,y.checkLatest)(),d.intro("Capgo tunnel init");try{const n=(0,u.useLogSnag)(),t=(0,u.createSupabaseClient)(o.apikey),i=yield(0,u.verifyUser)(t,o.apikey,["write","all","upload"]);yield n.publish({channel:"app",event:"live reload",icon:"🔄",tags:{"user-id":i},notify:!1}).catch();const{url:a,connections:r,stop:s}=(0,p.tunnel)({"--url":`localhost:${e}`}),l=yield a;yield Promise.all(r),d.log.info(`Tunnel ${l} connected to localhost:${e}`);const y=yield c.default.toString(l,{type:"terminal",small:!0});d.log.info(y),yield d.confirm({message:"When done say yes to close tunnel"}),yield s(),d.log.info("Tunnel closed")}catch(e){console.error(e),process.exit(1)}return n&&(console.log("Done ✅"),process.exit()),!0})),o.watchApp=(e,n)=>r(void 0,void 0,void 0,(function*(){(0,o.watch)(e,n,!0)}))},47:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},i=this&&this.__asyncValues||function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),o={},t("next"),t("throw"),t("return"),o[Symbol.asyncIterator]=function(){return this},o);function t(n){o[n]=e[n]&&function(o){return new Promise((function(t,i){!function(e,o,n,t){Promise.resolve(t).then((function(o){e({value:o,done:n})}),o)}(t,i,(o=e[n](o)).done,o.value)}))}}},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupBundle=void 0;const r=n(7304),s=a(n(1505)),l=a(n(1616)),d=n(3866),c=n(7937),p=n(2235),u=n(5995),y=(0,l.default)();o.cleanupBundle=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;yield(0,u.checkLatest)();const a=o.apikey||(0,d.findSavedKey)(),{bundle:l,keep:f=4}=o,g=o.force||!1,v=yield(0,d.getConfig)();e=e||(null===(n=null==v?void 0:v.app)||void 0===n?void 0:n.appId),a||r.program.error("Missing API key, you need to provide an API key to delete your app"),e||r.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const h=(0,d.createSupabaseClient)(a),m=yield(0,d.verifyUser)(h,a);yield(0,p.checkAppExistsAndHasPermissionErr)(h,e,a),console.log("Querying all available versions in Capgo");let b=yield(0,c.getActiveAppVersions)(h,e,m);if(console.log(`Total active versions in Capgo: ${null==b?void 0:b.length}`),0===(null==b?void 0:b.length))return void console.log("No versions found, aborting cleanup");if(l){const e=`${s.default.inc(l,"major")}`;console.log(`Querying available versions in Capgo between ${l} and ${e}`),b=((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})(b,l,e),console.log(`Active versions in Capgo between ${l} and ${e}: ${null==b?void 0:b.length}`)}const k=[];if(b.forEach(((e,o)=>{o<f?e.keep="✅":(e.keep="❌",k.push(e))})),0!==k.length){if((0,c.displayBundles)(b),!g&&"yes"!==y("Do you want to continue removing the versions specified? Type yes to confirm: "))return void console.log("Not confirmed, aborting removal...");console.log("You have confirmed removal, removing versions now"),yield((e,o,n,a)=>{var r,s,l;return t(void 0,void 0,void 0,(function*(){var t,p,u,y;try{for(r=!0,s=i(e);!(t=(l=yield s.next()).done);){y=l.value,r=!1;try{const e=y;console.log(`Removing ${e.name} created on ${(0,d.getHumanDate)(e.created_at)}`),yield(0,c.deleteSpecificVersion)(o,n,a,e.name)}finally{r=!0}}}catch(e){p={error:e}}finally{try{r||t||!(u=s.return)||(yield u.call(s))}finally{if(p)throw p.error}}}))})(k,h,e,m),console.log("Done ✅"),process.exit()}else console.log("Nothing to be removed, aborting removal...")}))},3832:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const i=n(7304),a=n(7147),r=n(4201),s=n(3866),l=n(5995);o.decryptZip=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,d,c;yield(0,l.checkLatest)(),(0,a.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const p=yield(0,s.getConfig)(),{extConfig:u}=p.app;n.key||(0,a.existsSync)(s.baseKey)||(null===(d=null===(t=u.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===d?void 0:d.privateKey)||i.program.error(`Private Key not found at the path ${s.baseKey} or in ${p.app.extConfigFilePath}`);const y=n.key||s.baseKey;let{privateKey:f}=n.keyData||(null===(c=null==u?void 0:u.plugins)||void 0===c?void 0:c.CapacitorUpdater)||"";(0,a.existsSync)(y)||f?(0,a.existsSync)(y)&&(f=(0,a.readFileSync)(y).toString()):i.program.error(`Cannot find public key ${y} or as keyData option or in ${p.app.extConfigFilePath}`);const g=(0,a.readFileSync)(e),v=(0,r.decryptSource)(g,o,f);(0,a.writeFileSync)(`${e}_decrypted.zip`,v),console.log("Done ✅"),process.exit()}))},1489:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteBundle=void 0;const i=n(7304),a=n(2235),r=n(3866),s=n(7937);o.deleteBundle=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,l;n.apikey=n.apikey||(0,r.findSavedKey)();const d=yield(0,r.getConfig)();e=e||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId),n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const c=(0,r.createSupabaseClient)(n.apikey),p=yield(0,r.verifyUser)(c,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(c,e,n.apikey);const u=n.apikey||(0,r.findSavedKey)();e=e||(null===(l=null==d?void 0:d.app)||void 0===l?void 0:l.appId),u||i.program.error("Missing API key, you need to provide an API key to delete your app"),o||i.program.error("Missing argument, you need to provide a bundleId, or be in a capacitor project"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project"),console.log(`Delete ${e}@${o} from Capgo`),yield(0,s.deleteSpecificVersion)(c,e,p,o),console.log(`${e}@${o} deleted from server`),console.log("Done ✅"),process.exit()}))},8329:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const i=n(7304),a=n(7147),r=n(5995),s=n(4201),l=n(3866);o.encryptZip=(e,o)=>t(void 0,void 0,void 0,(function*(){yield(0,r.checkLatest)(),(0,a.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const n=o.key||l.baseKeyPub;let t=o.keyData||"";(0,a.existsSync)(n)||t?(0,a.existsSync)(n)&&(t=(0,a.readFileSync)(n).toString()):i.program.error(`Cannot find public key ${n} or as keyData option`);const d=(0,a.readFileSync)(e),c=(0,s.encryptSource)(d,t);console.log("ivSessionKey",c.ivSessionKey),(0,a.writeFileSync)(`${e}_encrypted.zip`,c.encryptedData),console.log("Done ✅"),process.exit()}))},2959:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listBundle=void 0;const i=n(7304),a=n(2235),r=n(7937),s=n(3866),l=n(5995);o.listBundle=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;yield(0,l.checkLatest)(),o.apikey=o.apikey||(0,s.findSavedKey)();const t=yield(0,s.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||i.program.error("Missing API key, you need to provide 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 d=(0,s.createSupabaseClient)(o.apikey),c=yield(0,s.verifyUser)(d,o.apikey);console.log("Querying available versions in Capgo"),yield(0,a.checkAppExistsAndHasPermissionErr)(d,e,o.apikey);const p=yield(0,r.getActiveAppVersions)(d,e,c);console.log(`Active versions in Capgo: ${null==p?void 0:p.length}`),(0,r.displayBundles)(p),console.log("Done ✅"),process.exit()}))},3854:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadDeprecatedCommand=o.uploadCommand=o.uploadBundle=void 0;const l=s(n(3844)),d=n(7304),c=n(6113),p=a(n(552)),u=n(7147),y=n(5906),f=n(5995),g=n(2235),v=n(4201),h=n(3866);o.uploadBundle=(e,o,n=!0)=>r(void 0,void 0,void 0,(function*(){var t,i,a,r;yield(0,f.checkLatest)();let{bundle:s,path:m,channel:b}=o;const{external:k,key:w=!1,displayIvSession:_}=o,x=o.apikey||(0,h.findSavedKey)(),C=(0,h.useLogSnag)();b=b||"dev",p.intro("Uploading");const $=yield(0,h.getConfig)();e=e||(null===(t=null==$?void 0:$.app)||void 0===t?void 0:t.appId);const S=(0,c.randomUUID)().split("-")[0];s=s||(null===(a=null===(i=null==$?void 0:$.app)||void 0===i?void 0:i.package)||void 0===a?void 0:a.version)||`0.0.1-beta.${S}`,h.regexSemver.test(s)||(p.log.error(`Your bundle name ${s}, is not valid it should follow semver convention : https://semver.org/`),d.program.error("")),m=m||(null===(r=null==$?void 0:$.app)||void 0===r?void 0:r.webDir),x||(p.log.error("Missing API key, you need to provide a API key to upload your bundle"),d.program.error("")),e&&s&&m||(p.log.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),d.program.error("")),(0,u.existsSync)(m)||(p.log.error(`Path ${m} does not exist, build your app first, or provide a valid path`),d.program.error("")),p.log.info(`Upload ${e}@${s} started from path "${m}" to Capgo cloud`);const P=(0,h.createSupabaseClient)(x),A=yield(0,h.verifyUser)(P,x,["write","all","upload"]);yield(0,h.checkPlanValid)(P,A,!1),yield(0,g.checkAppExistsAndHasPermissionErr)(P,e,x);const{data:I,error:j}=yield P.rpc("exist_app_versions",{apikey:x,name_version:s,appid:e}).single();(I||j)&&(p.log.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,h.formatError)(j)}`),d.program.error(""));const{data:D,error:O}=yield P.rpc("is_trial",{userid:A}).single();(D&&D>0||O)&&(p.log.warn(`WARNING !!\nTrial expires in ${D} days`),p.log.warn(`Upgrade here: ${h.hostWeb}/dashboard/settings/plans`));const{data:M,error:E}=yield P.rpc("exist_app",{appid:e,apikey:x}).single();M&&!E||(p.log.error(`Cannot find app ${e} in your account ${(0,h.formatError)(E)}`),d.program.error(""));const{data:U,error:K}=yield P.rpc("exist_app_versions",{appid:e,apikey:x,name_version:s}).single();(U||K)&&(p.log.error(`Version already exists ${(0,h.formatError)(K)}`),d.program.error(""));const q=(0,c.randomUUID)();let L,z="";if(k)k&&!k.startsWith("https://")&&(p.log.error(`External link should should start with "https://" current is "${k}"`),d.program.error(""));else{const o=new l.default;o.addLocalFolder(m);let n=o.toBuffer();const t=p.spinner();if(t.start("Calculating checksum"),z=yield(0,y.checksum)(n,"crc32"),t.stop(`Checksum: ${z}`),w||(0,u.existsSync)(h.baseKeyPub)){const e="string"==typeof w?w:h.baseKeyPub;(0,u.existsSync)(e)||(p.log.error(`Cannot find public key ${e}`),d.program.error(""));const o=(0,u.readFileSync)(e);p.log.info("Encrypting your bundle");const t=(0,v.encryptSource)(n,o.toString());L=t.ivSessionKey,_&&p.log.info(`Your Iv Session key is ${L},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),n=t.encryptedData}const i=Math.floor(n.byteLength/1024/1024),a=`apps/${A}/${e}/versions`;i>20&&(p.log.warn(`WARNING !!\nThe app size is ${i} Mb, this may take a while to download for users\n`),p.log.info("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield C.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":A,"app-id":e},notify:!1}).catch());const r=p.spinner();r.start("Uploading Bundle");const{error:s}=yield P.storage.from(a).upload(q,n,{contentType:"application/zip",cacheControl:"2592000"});r.stop("Bundle Uploaded 💪"),s&&(p.log.error(`Cannot upload ${(0,h.formatError)(s)}`),d.program.error(""))}const{error:B}=yield(0,h.updateOrCreateVersion)(P,{bucket_id:k?void 0:q,user_id:A,name:s,app_id:e,session_key:L,external_url:k,checksum:z},x);B&&(p.log.error(`Cannot add bundle ${(0,h.formatError)(B)}`),d.program.error(""));const{data:F}=yield P.rpc("get_app_versions",{apikey:x,name_version:s,appid:e}).single();if(F){const{error:o,data:n}=yield(0,h.updateOrCreateChannel)(P,{name:b,app_id:e,created_by:A,version:F},x);o&&p.log.warn('Cannot set channel, the upload key is not allowed to do that, use the "all" for this.');const t=(0,h.convertAppName)(e);(null==n?void 0:n.public)?p.log.info("Your update is now available in your public channel 🎉"):(null==n?void 0:n.id)&&p.log.info(`Link device to this bundle to try it: ${h.hostWeb}/app/p/${t}/channel/${n.id}`)}else p.log.warn("Cannot set bundle with upload key, use key with more rights for that"),d.program.error("");return yield C.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":A,"app-id":e},notify:!1}).catch(),n&&(p.outro("Time to share your update to the world 🌍"),process.exit()),!0})),o.uploadCommand=(e,n)=>r(void 0,void 0,void 0,(function*(){(0,o.uploadBundle)(e,n,!0)})),o.uploadDeprecatedCommand=(e,n)=>r(void 0,void 0,void 0,(function*(){console.log('⚠️ This command is deprecated, use "npx @capgo/cli bundle upload" instead ⚠️'),(0,o.uploadBundle)(e,n,!0)}))},5902:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.zipBundle=void 0;const l=s(n(3844)),d=n(7304),c=n(6113),p=a(n(552)),u=n(5906),y=n(7147),f=n(5995),g=n(3866);o.zipBundle=(e,o)=>r(void 0,void 0,void 0,(function*(){var n,t,i,a;yield(0,f.checkLatest)();let{bundle:r,path:s}=o;const v=(0,g.useLogSnag)(),h=yield(0,g.getConfig)();e=e||(null===(n=null==h?void 0:h.app)||void 0===n?void 0:n.appId);const m=(0,c.randomUUID)().split("-")[0];r=r||(null===(i=null===(t=null==h?void 0:h.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version)||`0.0.1-beta.${m}`,p.intro(`Zipping ${e}@${r}`),g.regexSemver.test(r)||(p.log.error(`Your bundle name ${r}, is not valid it should follow semver convention : https://semver.org/`),d.program.error("")),s=s||(null===(a=null==h?void 0:h.app)||void 0===a?void 0:a.webDir),e&&r&&s||(p.log.error("Missing argument, you need to provide a appId and a bundle and a path, or be in a capacitor project"),d.program.error("")),p.log.info(`Started from path "${s}"`);const b=new l.default;b.addLocalFolder(s);const k=b.toBuffer();p.log.info(`Zipped ${k.byteLength} bytes`);const w=p.spinner();w.start("Calculating checksum");const _=yield(0,u.checksum)(k,"crc32");w.stop(`Checksum: ${_}`);const x=Math.floor(k.byteLength/1024/1024);x>20&&(p.log.warn(`WARNING !!\nThe app size is ${x} Mb, this may take a while to download for users\n`),p.log.warn("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield v.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"app-id":e},notify:!1}).catch());const C=p.spinner();C.start(`Saving to ${e}_${r}.zip`),(0,y.writeFileSync)(`${e}_${r}.zip`,k),C.stop(`Saved to ${e}_${r}.zip`),yield v.publish({channel:"app",event:"App zip",icon:"⏫",tags:{"app-id":e},notify:!1}).catch(),p.outro("Done ✅"),process.exit()}))},8210:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addChannelCommand=o.addChannel=void 0;const i=n(7304),a=n(2235),r=n(7213),s=n(3866);o.addChannel=(e,o,n,l=!0)=>t(void 0,void 0,void 0,(function*(){var t;n.apikey=n.apikey||(0,s.findSavedKey)();const d=yield(0,s.getConfig)();o=o||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId);const c=(0,s.useLogSnag)();n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const p=(0,s.createSupabaseClient)(n.apikey),u=yield(0,s.verifyUser)(p,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(p,o,n.apikey),console.log(`Create channel ${o}#${e} to Capgo cloud`);try{const n=yield(0,r.findUnknownVersion)(p,o);n||i.program.error("Cannot find default version for channel creation, please contact Capgo support 🤨"),yield(0,r.createChannel)(p,{name:e,app_id:o,version:n.id,created_by:u}),console.log("Channel created ✅"),yield c.publish({channel:"channel",event:"Create channel",icon:"✅",tags:{"user-id":u,"app-id":o,channel:e},notify:!1}).catch()}catch(e){return console.log("Cannot create Channel 🙀",e),!1}return l&&(console.log("Done ✅"),process.exit()),!0})),o.addChannelCommand=(e,n,i)=>t(void 0,void 0,void 0,(function*(){(0,o.addChannel)(e,n,i,!0)}))},963:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteChannel=void 0;const i=n(7304),a=n(2235),r=n(7213),s=n(3866);o.deleteChannel=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t;n.apikey=n.apikey||(0,s.findSavedKey)();const l=yield(0,s.getConfig)();o=o||(null===(t=null==l?void 0:l.app)||void 0===t?void 0:t.appId);const d=(0,s.useLogSnag)();n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const c=(0,s.createSupabaseClient)(n.apikey),p=yield(0,s.verifyUser)(c,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(c,o,n.apikey),console.log(`Delete channel ${o}#${e} to Capgo cloud`);try{yield(0,r.delChannel)(c,e,o,p),console.log("Channel Delete ✅"),yield d.publish({channel:"channel",event:"Delete channel",icon:"✅",tags:{"user-id":p,"app-id":o,channel:e},notify:!1}).catch()}catch(e){console.log("Cannot delete Channel 🙀",e)}console.log("Done ✅"),process.exit()}))},7534:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listChannels=void 0;const i=n(7304),a=n(2235),r=n(7213),s=n(3866);o.listChannels=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;o.apikey=o.apikey||(0,s.findSavedKey)();const t=yield(0,s.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId);const l=(0,s.useLogSnag)();o.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const d=(0,s.createSupabaseClient)(o.apikey),c=yield(0,s.verifyUser)(d,o.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(d,e,o.apikey),console.log("Querying available versions in Capgo"),yield(0,a.checkAppExistsAndHasPermissionErr)(d,e,o.apikey);const p=yield(0,r.getActiveChannels)(d,e,c);console.log(`Active channels in Capgo: ${null==p?void 0:p.length}`),(0,r.displayChannels)(p),yield l.publish({channel:"channel",event:"List channel",icon:"✅",tags:{"user-id":c,"app-id":e},notify:!1}).catch(),console.log("Done ✅"),process.exit()}))},331:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const i=n(7304),a=n(2235),r=n(3866);o.setChannel=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,s,l;n.apikey=n.apikey||(0,r.findSavedKey)();const d=yield(0,r.getConfig)();o=o||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId);const c=(0,r.useLogSnag)();n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const p=(0,r.createSupabaseClient)(n.apikey),u=yield(0,r.verifyUser)(p,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(p,o,n.apikey);const{bundle:y,latest:f,downgrade:g,upgrade:v,ios:h,android:m,selfAssign:b,state:k}=n;e||i.program.error("Missing argument, you need to provide a channel"),f&&y&&i.program.error("Cannot set latest and bundle at the same time"),null==y&&null==k&&null==f&&null==g&&null==v&&null==h&&null==m&&null==b&&i.program.error("Missing argument, you need to provide a option to set");try{yield(0,r.checkPlanValid)(p,u),yield(0,a.checkAppExistsAndHasPermissionErr)(p,o,n.apikey);const t={created_by:u,app_id:o,name:e,version:void 0},w=f?null===(l=null===(s=null==d?void 0:d.app)||void 0===s?void 0:s.package)||void 0===l?void 0:l.version:y;if(null!=w){const{data:n,error:a}=yield p.from("app_versions").select().eq("app_id",o).eq("name",w).eq("user_id",u).eq("deleted",!1).single();!a&&n||i.program.error(`Cannot find version ${w}`),console.log(`Set ${o} channel: ${e} to @${w}`),t.version=n.id}null!=k&&("public"!==k&&"private"!==k||console.log(`Set ${o} channel: ${e} to public or private is deprecated, use default or normal instead`),console.log(`Set ${o} channel: ${e} to ${"public"===k||"default"===k?"default":"normal"}`),t.public="public"===k||"default"===k),null!=g&&(console.log(`Set ${o} channel: ${e} to ${g?"allow":"disallow"} downgrade`),t.disableAutoUpdateUnderNative=!g),null!=v&&(console.log(`Set ${o} channel: ${e} to ${v?"allow":"disallow"} upgrade`),t.disableAutoUpdateToMajor=!v),null!=h&&(console.log(`Set ${o} channel: ${e} to ${h?"allow":"disallow"} ios update`),t.ios=!!h),null!=m&&(console.log(`Set ${o} channel: ${e} to ${m?"allow":"disallow"} android update`),t.android=!!m),null!=b&&(console.log(`Set ${o} channel: ${e} to ${b?"allow":"disallow"} self assign to this channel`),t.allow_device_self_set=!!b);try{const{error:e}=yield(0,r.updateOrCreateChannel)(p,t,n.apikey);e&&i.program.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.')}catch(e){i.program.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.')}yield c.publish({channel:"channel",event:"Set channel",icon:"✅",tags:{"user-id":u,"app-id":o},notify:!1}).catch()}catch(e){i.program.error(`Unknow error ${(0,r.formatError)(e)}`)}console.log("Done ✅"),process.exit()}))},4819: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(7304),a=n(5902),r=n(7099),s=n(2959),l=n(3832),d=n(8329),c=n(4105),p=n(7239),u=n(5564),y=n(1489),f=n(331),g=n(3854),v=t(n(4147)),h=n(8517),m=n(4430),b=n(47),k=n(8210),w=n(963),_=n(7534),x=n(1465),C=n(7591),$=n(4992);i.program.description("Manage packages and bundle versions in Capgo Cloud").version(v.default.version),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(h.loginCommand).option("--local","Only save in local folder"),i.program.command("doctor").description("Get info about your Capgo app install").action(p.getInfo),i.program.command("init [apikey] [appid]").description("Init a new app").action(r.initApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account");const S=i.program.command("app").description("Manage app");S.command("add [appid]").alias("a").description("Add a new app in Capgo Cloud").action(c.addCommand).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),S.command("delete [appid]").alias("d").description("Delete an app in Capgo Cloud").action(C.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account"),S.command("list [appid]").alias("l").description("list apps in Capgo Cloud").action(m.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),S.command("watch [port]").alias("w").description("watch for changes in your app and allow capgo app or your app to see changes in live").action($.watchApp),S.command("set [appid]").alias("s").description("Set an app in Capgo Cloud").action(x.setApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account");const P=i.program.command("bundle").description("Manage bundle");P.command("upload [appid]").alias("u").description("Upload a new bundle in Capgo Cloud").action(g.uploadCommand).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 bundle to upload"),P.command("delete [appid]").alias("d").description("Delete a bundle in Capgo Cloud").action(y.deleteBundle).option("-a, --apikey <apikey>","apikey to link to your account"),P.command("list [appid]").alias("l").description("List bundle in Capgo Cloud").action(s.listBundle).option("-a, --apikey <apikey>","apikey to link to your account"),P.command("unlink [appid]").alias("u").description("Unlink a bundle in Capgo Cloud").action(s.listBundle).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the bundle to unlink"),P.command("cleanup [appid]").alias("c").action(b.cleanupBundle).description("Cleanup bundle in Capgo Cloud").option("-b, --bundle <bundle>","bundle version number of the app to delete").option("-a, --apikey <apikey>","apikey to link to your account").option("-k, --keep <keep>","number of version to keep").option("-f, --force","force removal"),P.command("decrypt [zipPath] [sessionKey]").alias("l").description("Decrypt a signed zip bundle").action(l.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),P.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(d.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),P.command("zip [appid]").description("Zip a bundle").action(a.zipBundle).option("-p, --path <path>","path of the folder to upload").option("-b, --bundle <bundle>","bundle version number to name the zip file");const A=i.program.command("channel").description("Manage channel");A.command("add [channelid] [appid]").alias("a").description("Create channel").action(k.addChannelCommand).option("-d, --default","set the channel as default"),A.command("delete [channelid] [appid]").alias("d").description("Delete channel").action(w.deleteChannel),A.command("list [appid]").alias("l").description("List channel").action(_.listChannels),A.command("set [channelid] [appid]").alias("s").description("Set channel").action(f.setChannel).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the file to set").option("-s, --state <state>","set the state of the channel, default or normal").option("--latest","get the latest version key in the package.json to set it to the channel").option("--downgrade","Allow to downgrade to version under native one").option("--no-downgrade","Disable downgrade to version under native one").option("--upgrade","Allow to upgrade to version above native one").option("--no-upgrade","Disable upgrade to version above native one").option("--ios","Allow sending update to ios devices").option("--no-ios","Disable sending update to ios devices").option("--android","Allow sending update to android devices").option("--no-android","Disable sending update to android devices").option("--self-assign","Allow to device to self assign to this channel").option("--no-self-assign","Disable devices to self assign to this channel");const I=i.program.command("key").description("Manage key");I.command("save").description("Save base64 signing key in capacitor config, usefull for CI").action(u.saveKeyCommand).option("-f, --force","force generate a new one"),I.command("create").description("Create a new signing key").action(u.createKeyCommand).option("-f, --force","force generate a new one"),i.program.command("upload [appid]").alias("u").description("(Deprecated) Upload a new bundle to Capgo Cloud").action(g.uploadDeprecatedCommand).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to Capgo Cloud").option("--key <key>","custom path for public signing key").option("--keyData <keyData>","base64 public signing key").option("--no-key","ignore signing key and send clear update").option("--display-iv-session","Show in the console the iv and session key used to encrypt the update").option("-b, --bundle <bundle>","bundle version number of the file to upload"),i.program.parseAsync()},7099:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.initApp=void 0;const s=n(7147),l=n(6301),d=n(2081),c=a(n(552)),p=n(5564),u=n(8210),y=n(3854),f=n(8517),g=n(4105),v=n(5995),h=n(3866),m="import { CapacitorUpdater } from '@capgo/capacitor-updater'",b="CapacitorUpdater.notifyAppReady()",k=/import.*from.*/g,w="production",_={stdio:"pipe"},x=(e,o,n)=>r(void 0,void 0,void 0,(function*(){c.isCancel(e)&&(yield n.publish({channel:"onboarding-v2",event:"canceled",icon:"🤷",tags:{"user-id":o},notify:!1}).catch(),process.exit())})),C=(e,o,n,t="✅")=>r(void 0,void 0,void 0,(function*(){yield o.publish({channel:"onboarding-v2",event:n,icon:t,tags:{"user-id":e},notify:!1}).catch()})),$=(e,o,n)=>r(void 0,void 0,void 0,(function*(){return C(e,o,`onboarding-step-${n}`)})),S=e=>new Promise((o=>{setTimeout(o,e)}));o.initApp=(e,o,n)=>r(void 0,void 0,void 0,(function*(){var t;yield(0,v.checkLatest)();const i=(0,h.useLogSnag)(),a=yield(0,h.getConfig)();o=o||(null===(t=null==a?void 0:a.app)||void 0===t?void 0:t.appId),e=e||(0,h.findSavedKey)(),c.intro("Capgo init");const P=c.spinner();P.start("Running: npx @capgo/cli@latest login ***"),(yield(0,f.login)(e,n,!1))?P.stop("Login Done ✅"):P.stop("Login already done ✅");const A=(0,h.createSupabaseClient)(e),I=yield(0,h.verifyUser)(A,e,["upload","all","read","write"]);yield $(I,i,1),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const i=yield c.confirm({message:`Add ${n} in Capgo?`});if(yield x(i,e,o),i){const e=c.spinner();e.start(`Running: npx @capgo/cli@latest app add ${n}`),(yield(0,g.addApp)(n,t,!1))?e.stop("App add Done ✅"):e.stop("App already add ✅")}else c.log.info(`Run yourself "npx @capgo/cli@latest app add ${n}"`);yield $(e,o,2)})))(I,i,o,n),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const i=yield c.confirm({message:`Create default channel ${w} for ${t} in Capgo?`});if(yield x(i,e,o),i){const e=c.spinner();e.start(`Running: npx @capgo/cli@latest channel add ${w} ${t} --default`),(yield(0,u.addChannel)(w,t,{default:!0,apikey:n},!1))?e.stop("Channel add Done ✅"):e.stop("Channel already added ✅")}else c.log.info(`Run yourself "npx @capgo/cli@latest channel add ${w} ${t} --default"`);yield $(e,o,3)})))(I,i,e,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const n=yield c.confirm({message:`Automatic Install "@capgo/capacitor-updater" dependency in ${t}?`});if(yield x(n,e,o),n){const e=c.spinner();e.start("Checking if @capgo/capacitor-updater is installed");const o=JSON.parse((0,s.readFileSync)("package.json").toString()),n=(0,l.findPackageManagerType)();"unknown"===n&&(e.stop("Cannot reconize package manager, please run `capgo init` in a capacitor project with npm, pnpm or yarn"),process.exit());const t="yarn"===n?"add":"install";o.dependencies["@capgo/capacitor-updater"]?e.stop("Capgo already installed ✅"):(yield(0,d.execSync)(`${n} ${t} @capgo/capacitor-updater@latest`,_),e.stop("Install Done ✅"))}else c.log.info('Run yourself "npm i @capgo/capacitor-updater@latest"');yield $(e,o,4)})))(I,i,0,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const n=yield c.confirm({message:`Automatic Add "${b}" code and import in ${t}?`});if(yield x(n,e,o),n){const n=c.spinner();n.start("Adding @capacitor-updater to your main file");const t=yield(0,h.findMainFile)();t||(n.stop("No main.ts, main.js, index.ts or index.js file found, please run cap init first"),process.exit());const i=(0,s.readFileSync)(t).toString(),a=i.match(k),r=null==a?void 0:a.pop();if(r||(n.stop("Cannot find import line in main file, use manual installation: https://docs.capgo.app/plugin/installation"),process.exit()),i.includes(b))n.stop(`Code already added to ${t} ✅`);else{const e=i.replace(r,`${r}\n${m};\n\n${b};\n`);(0,s.writeFileSync)(t,e),n.stop(`Code added to ${t} ✅`)}yield $(e,o,5)}else c.log.info(`Add to your main file the following code:\n\n${m};\n\n${b};\n`)})))(I,i,0,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const n=yield c.confirm({message:`Automatic configure end-to-end encryption in ${t} updates?`});if(yield x(n,e,o),n){const n=c.spinner();n.start("Running: npx @capgo/cli@latest key create"),(yield(0,p.createKey)({},!1))?n.stop("key created 🔑"):(n.stop("Cannot create key ❌"),process.exit(1)),C(e,o,"Use encryption")}yield $(e,o,6)})))(I,i,0,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){var n;const i=yield c.confirm({message:`Automatic build ${t} with "npm run build" ?`});if(yield x(i,e,o),i){const e=c.spinner();e.start("Running: npm run build && npx cap sync"),(null===(n=JSON.parse((0,s.readFileSync)("package.json").toString()).scripts)||void 0===n?void 0:n.build)||(e.stop("Cannot find build script in package.json, please add it and run `capgo init` again"),process.exit()),(0,d.execSync)("npm run build && npx cap sync",_),e.stop("Build & Sync Done ✅")}else c.log.info("Build yourself with command: npm run build && npx cap sync");yield $(e,o,7)})))(I,i,0,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const i=yield c.confirm({message:`Automatic upload ${t} bundle to Capgo?`});if(yield x(i,e,o),i){const e=c.spinner();e.start("Running: npx @capgo/cli@latest bundle upload"),(yield(0,y.uploadBundle)(t,{channel:w,apikey:n},!1))?e.stop("Upload Done ✅"):(e.stop("Upload failed ❌"),process.exit())}else c.log.info("Upload yourself with command: npx @capgo/cli@latest bundle upload");yield $(e,o,8)})))(I,i,e,o),yield((e,o)=>r(void 0,void 0,void 0,(function*(){const n=yield c.confirm({message:"Run in device now ?"});if(yield x(n,e,o),n){const e=yield c.select({message:"Pick a platform to run your app",options:[{value:"ios",label:"IOS"},{value:"android",label:"Android"}]});c.isCancel(e)&&process.exit();const o=e,n=c.spinner();n.start(`Running: npx cap run ${o}`),yield(0,d.spawnSync)("npx",["cap","run",o],{stdio:"inherit"}),n.stop("Started Done ✅")}else c.log.info("Run yourself with command: npx cap run <ios|android>");yield $(e,o,9)})))(I,i),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const i=yield c.confirm({message:"Automatic check if update working in device ?"});if(yield x(i,e,o),i)c.log.info(`Wait logs sent to Capgo from ${t} device, Put the app in background and open it again.`),c.log.info("Waiting..."),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){let i=!0,a=(new Date).toISOString();for(yield C(t,n,"Use waitlog");i;){const{data:r,error:s}=yield e.from("stats").select("*").eq("app_id",o).order("id",{ascending:!1}).gte("created_at",a).limit(1).single();if(r&&!s){if(c.log.info(`Device: ${r.device_id}`),"get"===r.action)c.log.info("Update Sent your your device, wait until event download complete"),yield $(t,n,11);else if(r.action.startsWith("download_")){const e=r.action.split("_")[1];"complete"===e?(c.log.info("Your bundle has been downloaded on your device, background the app now and open it again to see the update"),yield $(t,n,12)):"fail"===e?(c.log.error("Your bundle has failed to download on your device."),c.log.error("Please check if you have network connection and try again")):c.log.info(`Your bundle is downloading ${e}% ...`)}else{if("set"===r.action)return c.log.info("Your bundle has been set on your device ❤️"),i=!1,yield $(t,n,13),Promise.resolve(r);"NoChannelOrOverride"===r.action?c.log.error("No default channel or override (channel/device) found, please create one"):"needPlanUpgrade"===r.action?c.log.error("Your are out of quota, please upgrade your plan"):"missingBundle"===r.action?c.log.error("Your bundle is missing, please check how you build your app"):"noNew"===r.action?c.log.error(`Your version in ${r.platform} is the same as your version uploaded, change it to see the update`):"disablePlatformIos"===r.action?c.log.error("iOS is disabled in the default channel and your device is an iOS device"):"disablePlatformAndroid"===r.action?c.log.error("Android is disabled in the default channel and your device is an Android device"):"disableAutoUpdateToMajor"===r.action?(c.log.error("Auto update to major version is disabled in the default channel."),c.log.error("Set your app to the same major version as the default channel")):"disableAutoUpdateUnderNative"===r.action?(c.log.error("Auto update under native version is disabled in the default channel."),c.log.error("Set your app to the same native version as the default channel.")):"disableDevBuild"===r.action?(c.log.error("Dev build is disabled in the default channel."),c.log.error("Set your channel to allow it if you wanna test your app")):"disableEmulator"===r.action?(c.log.error("Emulator is disabled in the default channel."),c.log.error("Set your channel to allow it if you wanna test your app")):"cannotGetBundle"===r.action?(c.log.error("We cannot get your bundle from the default channel."),c.log.error("Are you sure your default channel has a bundle set?")):"set_fail"===r.action?c.log.error("Your bundle seems to be corrupted, please check your code and send it again to Capgo"):"reset"===r.action?c.log.error("Your device has been reset to the builtin bundle"):"update_fail"===r.action?(c.log.error("Your bundle has been installed but failed to call notifyAppReady"),c.log.error("Please check if you have network connection and try again")):"checksum_fail"===r.action&&c.log.error("Your bundle has failed to validate checksum, please check your code and send it again to Capgo")}a=(new Date).toISOString()}yield S(1e3)}return Promise.resolve()})))(n,t,o,e);else{const e=(0,h.convertAppName)(t);c.log.info(`Check logs in https://web.capgo.app/app/p/${e}/logs to see if update works.`)}yield $(e,o,10)})))(I,i,A,o),yield $(I,i,0),c.outro("Welcome onboard ✈️!\nYour Capgo update system is setup"),process.exit()}))},5564:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.createKeyCommand=o.createKey=o.saveKeyCommand=o.saveKey=void 0;const i=n(7304),a=n(7147),r=n(7778),s=n(4201),l=n(3866),d=n(5995);o.saveKey=(e,o=!0)=>t(void 0,void 0,void 0,(function*(){(0,a.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const n=yield(0,l.getConfig)(),{extConfig:t}=n.app,s=e.key||l.baseKey;let d=e.keyData||"";if((0,a.existsSync)(s)||d)(0,a.existsSync)(s)&&(d=(0,a.readFileSync)(s).toString());else{if(!o)return!1;i.program.error(`Cannot find public key ${s} or as keyData option or in ${n.app.extConfigFilePath}`)}return t&&(t.plugins||(t.plugins={}),t.plugins.CapacitorUpdater||(t.plugins.CapacitorUpdater={}),t.plugins.CapacitorUpdater.privateKey=d,(0,r.writeConfig)(t,n.app.extConfigFilePath)),o&&(console.log(`private key saved into ${n.app.extConfigFilePath} file in local directory`),console.log("your app will decode the zip archive with this key\n")),!0})),o.saveKeyCommand=e=>t(void 0,void 0,void 0,(function*(){yield(0,d.checkLatest)(),yield(0,o.saveKey)(e)})),o.createKey=(e,o=!0)=>t(void 0,void 0,void 0,(function*(){(0,a.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const{publicKey:n,privateKey:t}=(0,s.createRSA)();if((0,a.existsSync)(l.baseKeyPub)&&!e.force){if(!o)return!1;i.program.error("Public Key already exists, use --force to overwrite")}if((0,a.writeFileSync)(l.baseKeyPub,n),(0,a.existsSync)(l.baseKey)&&!e.force){if(!o)return!1;i.program.error("Private Key already exists, use --force to overwrite")}(0,a.writeFileSync)(l.baseKey,t);const d=yield(0,l.getConfig)(),{extConfig:c}=d.app;return c&&(c.plugins||(c.plugins={}),c.plugins.CapacitorUpdater||(c.plugins.CapacitorUpdater={}),c.plugins.CapacitorUpdater.privateKey=t,(0,r.writeConfig)(c,d.app.extConfigFilePath)),o&&(console.log("Your RSA key has been generated\n"),console.log(`public key saved into ${l.baseKeyPub} file in local directory\n`),console.log("This key will be use to encode AES key used to crypt your zipped bundle before sending it to Capgo,\n than make them unreadable by Capgo and unmodifiable by anyone\n"),console.log(`Private key saved into ${d.app.extConfigFilePath} file in local directory`),console.log("Your app will decode with this RSA key the AES key and use it to decode the zipped bundle\n")),!0})),o.createKeyCommand=e=>t(void 0,void 0,void 0,(function*(){yield(0,d.checkLatest)(),yield(0,o.createKey)(e)}))},8517:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.loginCommand=o.login=void 0;const i=n(7304),a=n(7147),r=n(2037),s=n(3866),l=n(5995);o.login=(e,o,n=!0)=>t(void 0,void 0,void 0,(function*(){if(!e)return n&&i.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,l.checkLatest)();try{const{local:n}=o,t=(0,s.useLogSnag)();if(n)(0,a.existsSync)(".git")||i.program.error("To use local you should be in a git repository"),(0,a.writeFileSync)(".capgo",`${e}\n`),(0,a.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,r.homedir)();(0,a.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const l=(0,s.createSupabaseClient)(e),d=yield(0,s.verifyUser)(l,e,["write","all","upload"]);yield t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":d},notify:!1}).catch(),console.log(`login saved into .capgo file in ${n?"local":"home"} directory`)}catch(e){console.error(e),process.exit(1)}return n&&(console.log("Done ✅"),process.exit()),!0})),o.loginCommand=(e,n)=>t(void 0,void 0,void 0,(function*(){(0,o.login)(e,n,!0)}))},3866:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},i=this&&this.__await||function(e){return this instanceof i?(this.v=e,this):new i(e)},a=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.__asyncDelegator||function(e){var o,n;return o={},t("next"),t("throw",(function(e){throw e})),t("return"),o[Symbol.iterator]=function(){return this},o;function t(t,a){o[t]=e[t]?function(o){return(n=!n)?{value:i(e[t](o)),done:"return"===t}:a?a(o):o}:a}},s=this&&this.__asyncGenerator||function(e,o,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,a=n.apply(e,o||[]),r=[];return t={},s("next"),s("throw"),s("return"),t[Symbol.asyncIterator]=function(){return this},t;function s(e){a[e]&&(t[e]=function(o){return new Promise((function(n,t){r.push([e,o,n,t])>1||l(e,o)}))})}function l(e,o){try{(n=a[e](o)).value instanceof i?Promise.resolve(n.value.v).then(d,c):p(r[0][2],n)}catch(e){p(r[0][3],e)}var n}function d(e){l("next",e)}function c(e){l("throw",e)}function p(e,o){e(o),r.shift(),r.length&&l(r[0][0],r[0][1])}},l=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.findMainFile=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 d=n(7778),c=n(7304),p=n(2885),u=l(n(9867)),y=n(7147),f=n(2037),g=n(1133),v=n(1017),h=l(n(6634));function m(e){return s(this,arguments,(function*(){const o=yield i((0,y.readdirSync)(e,{withFileTypes:!0}));for(const n of o){const o=(0,v.resolve)(e,n.name);!n.isDirectory()||n.name.startsWith(".")||n.name.startsWith("node_modules")||n.name.startsWith("dist")?yield yield i(o):yield i(yield*r(a(m(o))))}}))}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,p.createClient)(o.hostSupa,o.supaAnon,{global:{headers:{capgkey:e}}}),o.regexSemver=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,o.checkKey=(e,n,i)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:i}).single();t&&!a||c.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(a)}`)})),o.isGoodPlan=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_good_plan_v3",{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))||(console.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),setTimeout((()=>{(0,h.default)(`${o.hostWeb}/dashboard/settings/plans`),c.program.error("")}),1e3));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,o=`${(0,f.homedir)()}/.capgo`;return(0,y.existsSync)(o)&&(console.log(`Use global apy key ${o}`),e=(0,y.readFileSync)(o,"utf8").trim()),o=".capgo",!e&&(0,y.existsSync)(o)&&(console.log(`Use local apy key ${o}`),e=(0,y.readFileSync)(o,"utf8").trim()),e||c.program.error("Key not found, please login first"),e},o.findMainFile=()=>t(void 0,void 0,void 0,(function*(){var e,o,n,t;const i=/(main|index)\.(ts|js)$/;let r="";const s=process.cwd(),l=s.split("/").length;try{for(var d,c=!0,p=a(m(s));!(e=(d=yield p.next()).done);){t=d.value,c=!1;try{const e=t;if(e.split("/").length-l<=2&&i.test(e)){r=e,console.log("Found main file here",e);break}}finally{c=!0}}}catch(e){o={error:e}}finally{try{c||e||!(n=p.return)||(yield n.call(p))}finally{if(o)throw o.error}}return r})),o.formatError=e=>e?`\n${u.default.render(e)}`:"",o.getConfig=()=>t(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,d.loadConfig)()}catch(e){c.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)):e.from("app_versions").insert(o).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).select().single():e.from("channels").insert(o).select().single()})),o.useLogSnag=()=>new g.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.convertAppName=e=>e.replace(/\./g,"--"),o.verifyUser=(e,n,i=["all"])=>t(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,n,i);const{data:t,error:a}=yield e.rpc("get_user_id",{apikey:n}).single(),r=t?t.toString():"";return r&&!a||c.program.error(`Cannot verify user ${(0,o.formatError)(a)}`),r})),o.getHumanDate=e=>new Date(e||"").toLocaleString()},7778:e=>{e.exports=require("@capacitor/cli/dist/config")},6301:e=>{e.exports=require("@capgo/find-package-manager")},552:e=>{e.exports=require("@clack/prompts")},2885:e=>{e.exports=require("@supabase/supabase-js")},5906:e=>{e.exports=require("@tomasklaen/checksum")},7176:e=>{e.exports=require("@trufflesuite/spinnies")},3844:e=>{e.exports=require("adm-zip")},3422:e=>{e.exports=require("cloudflared")},7304:e=>{e.exports=require("commander")},3847:e=>{e.exports=require("console-table-printer")},4470:e=>{e.exports=require("fs-extra")},5362:e=>{e.exports=require("get-latest-version")},1133:e=>{e.exports=require("logsnag")},9011:e=>{e.exports=require("mime")},6634:e=>{e.exports=require("open")},9867:e=>{e.exports=require("prettyjson")},1616:e=>{e.exports=require("prompt-sync")},1121:e=>{e.exports=require("qrcode")},1505:e=>{e.exports=require("semver/preload")},2081:e=>{e.exports=require("child_process")},6113:e=>{e.exports=require("crypto")},7147:e=>{e.exports=require("fs")},2037:e=>{e.exports=require("os")},1017:e=>{e.exports=require("path")},4147:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"3.9.0","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"engines":{"npm":">=7.0.0","node":">=16.0.0"},"keywords":["appflow alternative","ionic","capacitor","auto update","live update","capgo","cli","upload","capgo-cli"],"scripts":{"dev":"set NODE_ENV=development && npx webpack --config webpack.config.js","no-debug":"node dist/index.js","test":"npx --yes ts-node -T src/index.ts","build":"npx --yes webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","types":"npx --yes supabase gen types typescript --project-id=xvwzpoazmxkqosrdewyv > src/types/supabase.types.ts","test_rls":"ts-node ./test/test_headers_rls.ts","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"4.7.1","@capgo/find-package-manager":"^0.0.7","@clack/prompts":"^0.6.3","@supabase/supabase-js":"^2.12.1","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","cloudflared":"^0.3.4","commander":"10.0.0","console-table-printer":"^2.11.1","fs-extra":"11.1.1","get-latest-version":"^5.0.1","logsnag":"^0.1.6","mime":"^3.0.0","open":"^8.4.2","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","qrcode":"^1.5.1","semver":"^7.3.8"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/fs-extra":"^11.0.1","@types/mime":"^3.0.1","@types/node":"^18.15.5","@types/open":"^6.2.1","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/qrcode":"^1.5.0","@types/semver":"^7.3.13","@typescript-eslint/eslint-plugin":"5.56.0","@typescript-eslint/parser":"5.56.0","eslint":"8.36.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.8.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.22","pkg":"5.8.1","prettier":"2.8.6","ts-loader":"^9.4.2","ts-node":"^10.9.1","tsconfig-paths":"4.1.2","typescript":"4.9.5","webpack":"5.76.3","webpack-cli":"^5.0.1","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var a=o[t]={exports:{}};return e[t].call(a.exports,a,a.exports,n),a.exports}(4819)})();
2
+ (()=>{"use strict";var e={2235:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.newIconPath=o.checkAppExistsAndHasPermissionErr=o.checkAppExistsAndHasPermission=void 0;const i=n(7304);o.checkAppExistsAndHasPermission=(e,o,n,i=!0)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.rpc("exist_app",{appid:o,apikey:n}).single();return t!==i||a})),o.checkAppExistsAndHasPermissionErr=(e,n,a,r=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.checkAppExistsAndHasPermission)(e,n,a,r))&&i.program.error(`App ${n} does not exist or you don't have permission to access it`)})),o.newIconPath="assets/icon.png"},7213:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getActiveChannels=o.displayChannels=o.delChannel=o.createChannel=o.findUnknownVersion=o.checkVersionNotUsedInChannel=void 0;const s=n(7304),l=n(3847),d=a(n(552)),c=n(3866);o.checkVersionNotUsedInChannel=(e,n,t,i)=>r(void 0,void 0,void 0,(function*(){var a;const{data:r,error:l}=yield e.from("channels").select().eq("app_id",n).eq("created_by",t).eq("version",i.id);if(l&&s.program.error(`Cannot check Version ${n}@${i.name} ${(0,c.formatError)(l)}`),r&&r.length>0){if(d.intro(`❌ Version ${n}@${i.name} is used in ${r.length} channel`),yield d.confirm({message:"unlink it?"}))for(const t of r){const i=d.spinner();i.start(`Unlinking channel ${t.name}`);const{error:r}=yield e.from("channels").update({version:null===(a=yield(0,o.findUnknownVersion)(e,n))||void 0===a?void 0:a.id}).eq("id",t.id);r&&(i.stop(`Cannot update channel ${t.name} ${(0,c.formatError)(r)}`),process.exit(1)),i.stop(`✅ Channel ${t.name} unlinked`)}else s.program.error("unlink it first");d.outro(`Version unlinked from ${r.length} channel`)}})),o.findUnknownVersion=(e,o)=>e.from("app_versions").select("id").eq("app_id",o).eq("name","unknown").throwOnError().single().then((({data:e})=>e)),o.createChannel=(e,o)=>e.from("channels").insert(o).select().single(),o.delChannel=(e,o,n,t)=>e.from("channels").delete().eq("name",o).eq("app_id",n).eq("created_by",t).single(),o.displayChannels=e=>{const o=new l.Table({title:"Channels",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,c.getHumanDate)(e.created_at),Public:e.public?"✅":"❌"})})),o.printTable()},o.getActiveChannels=(e,o,n)=>r(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).order("created_at",{ascending:!1});return i&&s.program.error(`App ${o} not found in database ${(0,c.formatError)(i)} `),t}))},4201:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createRSA=o.encryptSource=o.decryptSource=void 0;const t=n(6113),i="aes-128-cbc",a="sha256",r="base64",s=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[l,d]=o.split(":"),c=(0,t.privateDecrypt)({key:n,padding:s,oaepHash:a},Buffer.from(d,r)),p=Buffer.from(l,r),u=c.toString(r);console.log("\nSessionB64",u);const y=(0,t.createDecipheriv)(i,c,p);return y.setAutoPadding(!0),Buffer.concat([y.update(e),y.final()])},o.encryptSource=(e,o)=>{const n=(0,t.randomBytes)(16),l=(0,t.randomBytes)(16),d=(0,t.createCipheriv)(i,l,n);d.setAutoPadding(!0);const c=`${n.toString(r)}:${(0,t.publicEncrypt)({key:o,padding:s,oaepHash:a},l).toString(r)}`;return{encryptedData:Buffer.concat([d.update(e),d.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"})}}},2035:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const s=n(7304),l=a(n(552)),d=n(3866);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>r(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);if(i&&s.program.error(`Cannot check Device override ${o}@${n.name} ${(0,d.formatError)(i)}`),t&&t.length>0)if(l.intro(`❌ Version ${o}@${n.name} is used in ${t.length} device override`),yield l.confirm({message:"unlink it?"}))for(const o of t){const n=l.spinner();n.start(`Unlinking device ${o.device_id}`);const{error:t}=yield e.from("devices_override").delete().eq("device_id",o.device_id);t&&(n.stop(`Cannot unlink device ${o.device_id} ${(0,d.formatError)(t)}`),process.exit(1)),n.stop(`✅ Device ${o.device_id} unlinked`)}else s.program.error("unlink it first")}))},8171:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(7304),a=n(3866);o.deleteFromStorage=(e,o,n,r,s)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${r.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${s} ${(0,a.formatError)(t)} `)}))},5995:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.checkLatest=void 0;const a=i(n(5362)),r=i(n(4147));o.checkLatest=()=>t(void 0,void 0,void 0,(function*(){const e=yield(0,a.default)("@capgo/cli");e!==r.default.version&&console.log("%s",`🚨 You are using @capgo/cli@${r.default.version} it's not the latest version.\nPlease use @capgo/cli@${e}" or @capgo/cli@latest to keep up to date with the latest features and bug fixes.`)}))},7937:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((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(7304),a=n(3847),r=n(3866),s=n(7213),l=n(2035),d=n(8171);o.deleteAppVersion=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("deleted",!1).eq("user_id",n).eq("name",a);t&&i.program.error(`App Version ${o}@${a} not found in database '${(0,r.formatError)(t)}'`)})),o.deleteSpecificVersion=(e,n,i,a)=>t(void 0,void 0,void 0,(function*(){const t=yield(0,o.getVersionData)(e,n,i,a);yield(0,s.checkVersionNotUsedInChannel)(e,n,i,t),yield(0,l.checkVersionNotUsedInDeviceOverride)(e,n,t),yield(0,d.deleteFromStorage)(e,i,n,t,a),yield(0,o.deleteAppVersion)(e,n,i,a)})),o.displayBundles=e=>{const o=new a.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,r.getHumanDate)(e.created_at)},null!=e.keep?{Keep:e.keep}:{}))})),o.printTable()},o.getActiveAppVersions=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return a&&i.program.error(`App ${o} not found in database ${(0,r.formatError)(a)} `),t})),o.getVersionData=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:s}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("name",a).eq("deleted",!1).single();return t&&!s||i.program.error(`App Version ${o}@${a} doesn't exist ${(0,r.formatError)(s)}`),t}))},4105:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addCommand=o.addApp=void 0;const i=n(9011),a=n(7304),r=n(6113),s=n(4470),l=n(5995),d=n(2235),c=n(3866);o.addApp=(e,o,n=!0)=>t(void 0,void 0,void 0,(function*(){var t,p,u;yield(0,l.checkLatest)(),o.apikey=o.apikey||(0,c.findSavedKey)();const y=yield(0,c.getConfig)();e=e||(null===(t=null==y?void 0:y.app)||void 0===t?void 0:t.appId);const f=(0,c.useLogSnag)();o.apikey||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||a.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const g=(0,c.createSupabaseClient)(o.apikey),v=yield(0,c.verifyUser)(g,o.apikey,["write","all"]);if(n)yield(0,d.checkAppExistsAndHasPermissionErr)(g,e,o.apikey,!1);else if(yield(0,d.checkAppExistsAndHasPermission)(g,e,o.apikey,!1))return!1;let h,m,{name:b,icon:k}=o;e=e||(null===(p=null==y?void 0:y.app)||void 0===p?void 0:p.appId),b=b||(null===(u=null==y?void 0:y.app)||void 0===u?void 0:u.appName)||"Unknown",k=k||"resources/icon.png",k&&b||a.program.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project"),n&&console.log(`Adding ${e} to Capgo`),k&&(0,s.existsSync)(k)?(h=(0,s.readFileSync)(k),m=(0,i.getType)(k)||"image/png",console.warn(`Found app icon ${k}`)):(0,s.existsSync)(d.newIconPath)?(h=(0,s.readFileSync)(d.newIconPath),m=(0,i.getType)(d.newIconPath)||"image/png",console.warn(`Found app icon ${d.newIconPath}`)):console.warn(`Cannot find app icon in any of the following locations: ${k}, ${d.newIconPath}`);const{data:w,error:_}=yield g.rpc("exist_app_v2",{appid:e}).single();(w||_)&&a.program.error(`App ${e} already exists ${(0,c.formatError)(_)}`);const x=`icon_${(0,r.randomUUID)()}`;let C="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(h&&m){const{error:o}=yield g.storage.from(`images/${v}/${e}`).upload(x,h,{contentType:m});o&&a.program.error(`Could not add app ${(0,c.formatError)(o)}`);const{data:n}=yield g.storage.from(`images/${v}/${e}`).getPublicUrl(x);C=(null==n?void 0:n.publicUrl)||C}const{error:$}=yield g.from("apps").insert({icon_url:C,user_id:v,name:b,app_id:e});$&&a.program.error(`Could not add app ${(0,c.formatError)($)}`);const{error:S}=yield g.from("app_versions").insert([{user_id:v,deleted:!0,name:"unknown",app_id:e},{user_id:v,deleted:!0,name:"builtin",app_id:e}]);return S&&a.program.error(`Could not add app ${(0,c.formatError)(S)}`),yield f.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":v,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now"),n&&(console.log("Done ✅"),process.exit()),!0})),o.addCommand=(e,n)=>t(void 0,void 0,void 0,(function*(){(0,o.addApp)(e,n,!0)}))},7591:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const i=n(7304),a=n(2235),r=n(3866);o.deleteApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;o.apikey=o.apikey||(0,r.findSavedKey)();const t=yield(0,r.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId);const s=(0,r.useLogSnag)();o.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const l=(0,r.createSupabaseClient)(o.apikey),d=yield(0,r.verifyUser)(l,o.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(l,e,o.apikey);const{error:c}=yield l.storage.from(`images/${d}`).remove([e]);c&&i.program.error(`Could not add app ${(0,r.formatError)(c)}`);const{error:p}=yield l.storage.from(`apps/${e}/${d}`).remove(["versions"]);p&&i.program.error(`Could not delete app version ${(0,r.formatError)(p)}`);const{error:u}=yield l.from("apps").delete().eq("app_id",e).eq("user_id",d);u&&i.program.error(`Could not delete app ${(0,r.formatError)(u)}`),yield s.publish({channel:"app",event:"App Deleted",icon:"🗑️",tags:{"user-id":d,"app-id":e},notify:!1}).catch(),console.log("App deleted in Capgo"),console.log("Done ✅"),process.exit()}))},7239:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getInfo=void 0;const a=n(7147),r=i(n(5362)),s=n(1017),l=i(n(7176)),d=i(n(2037)),c=i(n(4147));o.getInfo=()=>t(void 0,void 0,void 0,(function*(){console.log(" 💊 Capgo Doctor 💊\n"),console.log(` OS: ${d.default.version()}\n`),console.log(" Installed Dependencies:\n");const e=yield t(void 0,void 0,void 0,(function*(){const{dependencies:e}=yield t(void 0,void 0,void 0,(function*(){const e=(0,a.readFileSync)((0,s.join)(process.cwd(),"package.json"));return JSON.parse(e)})),o={"@capgo/cli":c.default.version};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&n.startsWith("@capgo/")&&(o[n]=e[n]);return o}));0===Object.keys(e).length&&(console.log("\n"),console.log("%s","🚨 No dependencies found"),process.exit(1));for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const n=e[o];console.log(` ${o}: ${n}`)}console.log("\n");const o=new l.default;o.add("loading",{text:"Loading latest dependencies"});const n=yield(e=>t(void 0,void 0,void 0,(function*(){const o={},n=[];for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.push((0,r.default)(o));return yield Promise.all(n).then((n=>{const t=Object.keys(e);for(let e=0;e<n.length;e+=1){const i=n[e];i&&(o[t[e]]=i)}})),o})))(e);o.succeed("loading",{text:"Latest Dependencies:"}),console.log("\n");for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const o=n[e];console.log(` ${e}: ${o}`)}JSON.stringify(e)!==JSON.stringify(n)&&(console.log("\n"),console.log("%s","🚨 Some dependencies are not up to date"),process.exit(1)),console.log("\n"),console.log("%s","✅ All dependencies are up to date"),process.exit()}))},4430:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=o.getActiveApps=void 0;const i=n(7304),a=n(3847),r=n(2235),s=n(3866),l=n(5995);o.getActiveApps=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.from("apps").select().eq("user_id",o).order("created_at",{ascending:!1});return t&&i.program.error(`Apps not found in database ${(0,s.formatError)(t)} `),n})),o.listApp=(e,n)=>t(void 0,void 0,void 0,(function*(){var t;yield(0,l.checkLatest)(),n.apikey=n.apikey||(0,s.findSavedKey)();const d=yield(0,s.getConfig)();e=e||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId),n.apikey||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,s.createSupabaseClient)(n.apikey),p=yield(0,s.verifyUser)(c,n.apikey);console.log("Querying available versions in Capgo"),yield(0,r.checkAppExistsAndHasPermissionErr)(c,e,n.apikey);const u=yield(0,o.getActiveApps)(c,p);console.log(`Active app in Capgo: ${null==u?void 0:u.length}`),(e=>{const o=new a.Table({title:"Apps",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,s.getHumanDate)(e.created_at)})})),o.printTable()})(u),console.log("Done ✅"),process.exit()}))},1465:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setApp=void 0;const i=n(9011),a=n(7304),r=n(6113),s=n(4470),l=n(2235),d=n(3866);o.setApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;o.apikey=o.apikey||(0,d.findSavedKey)();const t=yield(0,d.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||a.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||a.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const c=(0,d.createSupabaseClient)(o.apikey),p=yield(0,d.verifyUser)(c,o.apikey,["write","all"]);yield(0,l.checkAppExistsAndHasPermissionErr)(c,e,o.apikey);const{name:u,icon:y}=o;let f,g;const v=`icon_${(0,r.randomUUID)()}`;let h="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(y&&(0,s.existsSync)(y)?(f=(0,s.readFileSync)(y),g=(0,i.getType)(y)||"image/png",console.warn(`Found app icon ${y}`)):(0,s.existsSync)(l.newIconPath)?(f=(0,s.readFileSync)(l.newIconPath),g=(0,i.getType)(l.newIconPath)||"image/png",console.warn(`Found app icon ${l.newIconPath}`)):console.warn(`Cannot find app icon in any of the following locations: ${y}, ${l.newIconPath}`),f&&g){const{error:o}=yield c.storage.from(`images/${p}/${e}`).upload(v,f,{contentType:g});o&&a.program.error(`Could not add app ${(0,d.formatError)(o)}`);const{data:n}=yield c.storage.from(`images/${p}/${e}`).getPublicUrl(v);h=(null==n?void 0:n.publicUrl)||h}const{error:m}=yield c.from("apps").update({icon_url:h,name:u}).eq("app_id",e).eq("user_id",p);m&&a.program.error(`Could not add app ${(0,d.formatError)(m)}`),console.log("Done ✅"),process.exit()}))},4992:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.watchApp=o.watch=void 0;const l=n(7304),d=a(n(552)),c=s(n(1121)),p=n(3422),u=n(3866),y=n(5995);o.watch=(e,o,n=!0)=>r(void 0,void 0,void 0,(function*(){if(o.apikey=o.apikey||(0,u.findSavedKey)(),!o.apikey)return n&&l.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,y.checkLatest)(),d.intro("Capgo live reload");try{const n=(0,u.useLogSnag)(),t=(0,u.createSupabaseClient)(o.apikey),i=yield(0,u.verifyUser)(t,o.apikey,["write","all","upload"]);yield n.publish({channel:"app",event:"live reload",icon:"🔄",tags:{"user-id":i},notify:!1}).catch(),d.log.info("Init tunnel");const{url:a,connections:r,stop:s}=(0,p.tunnel)({"--url":`localhost:${e}`});d.log.info("Get URL");const l=yield a;d.log.info("Connection to tunnel"),yield Promise.all(r),d.log.info(`Tunnel ${l} connected to localhost:${e}`),yield t.from("app_live").upsert({id:i,url:l}).throwOnError();const y=yield c.default.toString(l,{type:"terminal",small:!0});d.log.info(y),yield d.confirm({message:"When done say yes to close tunnel"}),yield s(),yield t.from("app_live").delete().eq("id",i).throwOnError(),d.log.info("Tunnel closed")}catch(e){console.error("Error",e),process.exit(1)}return n&&(console.log("Done ✅"),process.exit()),!0})),o.watchApp=(e,n)=>r(void 0,void 0,void 0,(function*(){(0,o.watch)(e,n,!0)}))},47:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},i=this&&this.__asyncValues||function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),o={},t("next"),t("throw"),t("return"),o[Symbol.asyncIterator]=function(){return this},o);function t(n){o[n]=e[n]&&function(o){return new Promise((function(t,i){!function(e,o,n,t){Promise.resolve(t).then((function(o){e({value:o,done:n})}),o)}(t,i,(o=e[n](o)).done,o.value)}))}}},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupBundle=void 0;const r=n(7304),s=a(n(1505)),l=a(n(1616)),d=n(3866),c=n(7937),p=n(2235),u=n(5995),y=(0,l.default)();o.cleanupBundle=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;yield(0,u.checkLatest)();const a=o.apikey||(0,d.findSavedKey)(),{bundle:l,keep:f=4}=o,g=o.force||!1,v=yield(0,d.getConfig)();e=e||(null===(n=null==v?void 0:v.app)||void 0===n?void 0:n.appId),a||r.program.error("Missing API key, you need to provide an API key to delete your app"),e||r.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const h=(0,d.createSupabaseClient)(a),m=yield(0,d.verifyUser)(h,a);yield(0,p.checkAppExistsAndHasPermissionErr)(h,e,a),console.log("Querying all available versions in Capgo");let b=yield(0,c.getActiveAppVersions)(h,e,m);if(console.log(`Total active versions in Capgo: ${null==b?void 0:b.length}`),0===(null==b?void 0:b.length))return void console.log("No versions found, aborting cleanup");if(l){const e=`${s.default.inc(l,"major")}`;console.log(`Querying available versions in Capgo between ${l} and ${e}`),b=((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})(b,l,e),console.log(`Active versions in Capgo between ${l} and ${e}: ${null==b?void 0:b.length}`)}const k=[];if(b.forEach(((e,o)=>{o<f?e.keep="✅":(e.keep="❌",k.push(e))})),0!==k.length){if((0,c.displayBundles)(b),!g&&"yes"!==y("Do you want to continue removing the versions specified? Type yes to confirm: "))return void console.log("Not confirmed, aborting removal...");console.log("You have confirmed removal, removing versions now"),yield((e,o,n,a)=>{var r,s,l;return t(void 0,void 0,void 0,(function*(){var t,p,u,y;try{for(r=!0,s=i(e);!(t=(l=yield s.next()).done);){y=l.value,r=!1;try{const e=y;console.log(`Removing ${e.name} created on ${(0,d.getHumanDate)(e.created_at)}`),yield(0,c.deleteSpecificVersion)(o,n,a,e.name)}finally{r=!0}}}catch(e){p={error:e}}finally{try{r||t||!(u=s.return)||(yield u.call(s))}finally{if(p)throw p.error}}}))})(k,h,e,m),console.log("Done ✅"),process.exit()}else console.log("Nothing to be removed, aborting removal...")}))},3832:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const i=n(7304),a=n(7147),r=n(4201),s=n(3866),l=n(5995);o.decryptZip=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,d,c;yield(0,l.checkLatest)(),(0,a.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const p=yield(0,s.getConfig)(),{extConfig:u}=p.app;n.key||(0,a.existsSync)(s.baseKey)||(null===(d=null===(t=u.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===d?void 0:d.privateKey)||i.program.error(`Private Key not found at the path ${s.baseKey} or in ${p.app.extConfigFilePath}`);const y=n.key||s.baseKey;let{privateKey:f}=n.keyData||(null===(c=null==u?void 0:u.plugins)||void 0===c?void 0:c.CapacitorUpdater)||"";(0,a.existsSync)(y)||f?(0,a.existsSync)(y)&&(f=(0,a.readFileSync)(y).toString()):i.program.error(`Cannot find public key ${y} or as keyData option or in ${p.app.extConfigFilePath}`);const g=(0,a.readFileSync)(e),v=(0,r.decryptSource)(g,o,f);(0,a.writeFileSync)(`${e}_decrypted.zip`,v),console.log("Done ✅"),process.exit()}))},1489:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteBundle=void 0;const i=n(7304),a=n(2235),r=n(3866),s=n(7937);o.deleteBundle=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,l;n.apikey=n.apikey||(0,r.findSavedKey)();const d=yield(0,r.getConfig)();e=e||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId),n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const c=(0,r.createSupabaseClient)(n.apikey),p=yield(0,r.verifyUser)(c,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(c,e,n.apikey);const u=n.apikey||(0,r.findSavedKey)();e=e||(null===(l=null==d?void 0:d.app)||void 0===l?void 0:l.appId),u||i.program.error("Missing API key, you need to provide an API key to delete your app"),o||i.program.error("Missing argument, you need to provide a bundleId, or be in a capacitor project"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project"),console.log(`Delete ${e}@${o} from Capgo`),yield(0,s.deleteSpecificVersion)(c,e,p,o),console.log(`${e}@${o} deleted from server`),console.log("Done ✅"),process.exit()}))},8329:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const i=n(7304),a=n(7147),r=n(5995),s=n(4201),l=n(3866);o.encryptZip=(e,o)=>t(void 0,void 0,void 0,(function*(){yield(0,r.checkLatest)(),(0,a.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const n=o.key||l.baseKeyPub;let t=o.keyData||"";(0,a.existsSync)(n)||t?(0,a.existsSync)(n)&&(t=(0,a.readFileSync)(n).toString()):i.program.error(`Cannot find public key ${n} or as keyData option`);const d=(0,a.readFileSync)(e),c=(0,s.encryptSource)(d,t);console.log("ivSessionKey",c.ivSessionKey),(0,a.writeFileSync)(`${e}_encrypted.zip`,c.encryptedData),console.log("Done ✅"),process.exit()}))},2959:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listBundle=void 0;const i=n(7304),a=n(2235),r=n(7937),s=n(3866),l=n(5995);o.listBundle=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;yield(0,l.checkLatest)(),o.apikey=o.apikey||(0,s.findSavedKey)();const t=yield(0,s.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||i.program.error("Missing API key, you need to provide 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 d=(0,s.createSupabaseClient)(o.apikey),c=yield(0,s.verifyUser)(d,o.apikey);console.log("Querying available versions in Capgo"),yield(0,a.checkAppExistsAndHasPermissionErr)(d,e,o.apikey);const p=yield(0,r.getActiveAppVersions)(d,e,c);console.log(`Active versions in Capgo: ${null==p?void 0:p.length}`),(0,r.displayBundles)(p),console.log("Done ✅"),process.exit()}))},3854:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadDeprecatedCommand=o.uploadCommand=o.uploadBundle=void 0;const l=s(n(3844)),d=n(7304),c=n(6113),p=a(n(552)),u=n(7147),y=n(5906),f=n(5995),g=n(2235),v=n(4201),h=n(3866);o.uploadBundle=(e,o,n=!0)=>r(void 0,void 0,void 0,(function*(){var t,i,a,r;yield(0,f.checkLatest)();let{bundle:s,path:m,channel:b}=o;const{external:k,key:w=!1,displayIvSession:_}=o,x=o.apikey||(0,h.findSavedKey)(),C=(0,h.useLogSnag)();b=b||"dev",p.intro("Uploading");const $=yield(0,h.getConfig)();e=e||(null===(t=null==$?void 0:$.app)||void 0===t?void 0:t.appId);const S=(0,c.randomUUID)().split("-")[0];s=s||(null===(a=null===(i=null==$?void 0:$.app)||void 0===i?void 0:i.package)||void 0===a?void 0:a.version)||`0.0.1-beta.${S}`,h.regexSemver.test(s)||(p.log.error(`Your bundle name ${s}, is not valid it should follow semver convention : https://semver.org/`),d.program.error("")),m=m||(null===(r=null==$?void 0:$.app)||void 0===r?void 0:r.webDir),x||(p.log.error("Missing API key, you need to provide a API key to upload your bundle"),d.program.error("")),e&&s&&m||(p.log.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),d.program.error("")),(0,u.existsSync)(m)||(p.log.error(`Path ${m} does not exist, build your app first, or provide a valid path`),d.program.error("")),p.log.info(`Upload ${e}@${s} started from path "${m}" to Capgo cloud`);const P=(0,h.createSupabaseClient)(x),A=yield(0,h.verifyUser)(P,x,["write","all","upload"]);yield(0,h.checkPlanValid)(P,A,!1),yield(0,g.checkAppExistsAndHasPermissionErr)(P,e,x);const{data:I,error:j}=yield P.rpc("exist_app_versions",{apikey:x,name_version:s,appid:e}).single();(I||j)&&(p.log.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,h.formatError)(j)}`),d.program.error(""));const{data:O,error:D}=yield P.rpc("is_trial",{userid:A}).single();(O&&O>0||D)&&(p.log.warn(`WARNING !!\nTrial expires in ${O} days`),p.log.warn(`Upgrade here: ${h.hostWeb}/dashboard/settings/plans`));const{data:M,error:E}=yield P.rpc("exist_app",{appid:e,apikey:x}).single();M&&!E||(p.log.error(`Cannot find app ${e} in your account ${(0,h.formatError)(E)}`),d.program.error(""));const{data:U,error:q}=yield P.rpc("exist_app_versions",{appid:e,apikey:x,name_version:s}).single();(U||q)&&(p.log.error(`Version already exists ${(0,h.formatError)(q)}`),d.program.error(""));const K=(0,c.randomUUID)();let L,z="";if(k)k&&!k.startsWith("https://")&&(p.log.error(`External link should should start with "https://" current is "${k}"`),d.program.error(""));else{const o=new l.default;o.addLocalFolder(m);let n=o.toBuffer();const t=p.spinner();if(t.start("Calculating checksum"),z=yield(0,y.checksum)(n,"crc32"),t.stop(`Checksum: ${z}`),w||(0,u.existsSync)(h.baseKeyPub)){const e="string"==typeof w?w:h.baseKeyPub;(0,u.existsSync)(e)||(p.log.error(`Cannot find public key ${e}`),d.program.error(""));const o=(0,u.readFileSync)(e);p.log.info("Encrypting your bundle");const t=(0,v.encryptSource)(n,o.toString());L=t.ivSessionKey,_&&p.log.info(`Your Iv Session key is ${L},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),n=t.encryptedData}const i=Math.floor(n.byteLength/1024/1024),a=`apps/${A}/${e}/versions`;i>20&&(p.log.warn(`WARNING !!\nThe app size is ${i} Mb, this may take a while to download for users\n`),p.log.info("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield C.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":A,"app-id":e},notify:!1}).catch());const r=p.spinner();r.start("Uploading Bundle");const{error:s}=yield P.storage.from(a).upload(K,n,{contentType:"application/zip",cacheControl:"2592000"});r.stop("Bundle Uploaded 💪"),s&&(p.log.error(`Cannot upload ${(0,h.formatError)(s)}`),d.program.error(""))}const{error:B}=yield(0,h.updateOrCreateVersion)(P,{bucket_id:k?void 0:K,user_id:A,name:s,app_id:e,session_key:L,external_url:k,checksum:z},x);B&&(p.log.error(`Cannot add bundle ${(0,h.formatError)(B)}`),d.program.error(""));const{data:F}=yield P.rpc("get_app_versions",{apikey:x,name_version:s,appid:e}).single();if(F){const{error:o,data:n}=yield(0,h.updateOrCreateChannel)(P,{name:b,app_id:e,created_by:A,version:F},x);o&&p.log.warn('Cannot set channel, the upload key is not allowed to do that, use the "all" for this.');const t=(0,h.convertAppName)(e);(null==n?void 0:n.public)?p.log.info("Your update is now available in your public channel 🎉"):(null==n?void 0:n.id)&&p.log.info(`Link device to this bundle to try it: ${h.hostWeb}/app/p/${t}/channel/${n.id}`)}else p.log.warn("Cannot set bundle with upload key, use key with more rights for that"),d.program.error("");return yield C.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":A,"app-id":e},notify:!1}).catch(),n&&(p.outro("Time to share your update to the world 🌍"),process.exit()),!0})),o.uploadCommand=(e,n)=>r(void 0,void 0,void 0,(function*(){(0,o.uploadBundle)(e,n,!0)})),o.uploadDeprecatedCommand=(e,n)=>r(void 0,void 0,void 0,(function*(){console.log('⚠️ This command is deprecated, use "npx @capgo/cli bundle upload" instead ⚠️'),(0,o.uploadBundle)(e,n,!0)}))},5902:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.zipBundle=void 0;const l=s(n(3844)),d=n(7304),c=n(6113),p=a(n(552)),u=n(5906),y=n(7147),f=n(5995),g=n(3866);o.zipBundle=(e,o)=>r(void 0,void 0,void 0,(function*(){var n,t,i,a;yield(0,f.checkLatest)();let{bundle:r,path:s}=o;const v=(0,g.useLogSnag)(),h=yield(0,g.getConfig)();e=e||(null===(n=null==h?void 0:h.app)||void 0===n?void 0:n.appId);const m=(0,c.randomUUID)().split("-")[0];r=r||(null===(i=null===(t=null==h?void 0:h.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version)||`0.0.1-beta.${m}`,p.intro(`Zipping ${e}@${r}`),g.regexSemver.test(r)||(p.log.error(`Your bundle name ${r}, is not valid it should follow semver convention : https://semver.org/`),d.program.error("")),s=s||(null===(a=null==h?void 0:h.app)||void 0===a?void 0:a.webDir),e&&r&&s||(p.log.error("Missing argument, you need to provide a appId and a bundle and a path, or be in a capacitor project"),d.program.error("")),p.log.info(`Started from path "${s}"`);const b=new l.default;b.addLocalFolder(s);const k=b.toBuffer();p.log.info(`Zipped ${k.byteLength} bytes`);const w=p.spinner();w.start("Calculating checksum");const _=yield(0,u.checksum)(k,"crc32");w.stop(`Checksum: ${_}`);const x=Math.floor(k.byteLength/1024/1024);x>20&&(p.log.warn(`WARNING !!\nThe app size is ${x} Mb, this may take a while to download for users\n`),p.log.warn("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield v.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"app-id":e},notify:!1}).catch());const C=p.spinner();C.start(`Saving to ${e}_${r}.zip`),(0,y.writeFileSync)(`${e}_${r}.zip`,k),C.stop(`Saved to ${e}_${r}.zip`),yield v.publish({channel:"app",event:"App zip",icon:"⏫",tags:{"app-id":e},notify:!1}).catch(),p.outro("Done ✅"),process.exit()}))},8210:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addChannelCommand=o.addChannel=void 0;const i=n(7304),a=n(2235),r=n(7213),s=n(3866);o.addChannel=(e,o,n,l=!0)=>t(void 0,void 0,void 0,(function*(){var t;n.apikey=n.apikey||(0,s.findSavedKey)();const d=yield(0,s.getConfig)();o=o||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId);const c=(0,s.useLogSnag)();n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const p=(0,s.createSupabaseClient)(n.apikey),u=yield(0,s.verifyUser)(p,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(p,o,n.apikey),console.log(`Create channel ${o}#${e} to Capgo cloud`);try{const n=yield(0,r.findUnknownVersion)(p,o);n||i.program.error("Cannot find default version for channel creation, please contact Capgo support 🤨"),yield(0,r.createChannel)(p,{name:e,app_id:o,version:n.id,created_by:u}),console.log("Channel created ✅"),yield c.publish({channel:"channel",event:"Create channel",icon:"✅",tags:{"user-id":u,"app-id":o,channel:e},notify:!1}).catch()}catch(e){return console.log("Cannot create Channel 🙀",e),!1}return l&&(console.log("Done ✅"),process.exit()),!0})),o.addChannelCommand=(e,n,i)=>t(void 0,void 0,void 0,(function*(){(0,o.addChannel)(e,n,i,!0)}))},963:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteChannel=void 0;const i=n(7304),a=n(2235),r=n(7213),s=n(3866);o.deleteChannel=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t;n.apikey=n.apikey||(0,s.findSavedKey)();const l=yield(0,s.getConfig)();o=o||(null===(t=null==l?void 0:l.app)||void 0===t?void 0:t.appId);const d=(0,s.useLogSnag)();n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const c=(0,s.createSupabaseClient)(n.apikey),p=yield(0,s.verifyUser)(c,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(c,o,n.apikey),console.log(`Delete channel ${o}#${e} to Capgo cloud`);try{yield(0,r.delChannel)(c,e,o,p),console.log("Channel Delete ✅"),yield d.publish({channel:"channel",event:"Delete channel",icon:"✅",tags:{"user-id":p,"app-id":o,channel:e},notify:!1}).catch()}catch(e){console.log("Cannot delete Channel 🙀",e)}console.log("Done ✅"),process.exit()}))},7534:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listChannels=void 0;const i=n(7304),a=n(2235),r=n(7213),s=n(3866);o.listChannels=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;o.apikey=o.apikey||(0,s.findSavedKey)();const t=yield(0,s.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId);const l=(0,s.useLogSnag)();o.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const d=(0,s.createSupabaseClient)(o.apikey),c=yield(0,s.verifyUser)(d,o.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(d,e,o.apikey),console.log("Querying available versions in Capgo"),yield(0,a.checkAppExistsAndHasPermissionErr)(d,e,o.apikey);const p=yield(0,r.getActiveChannels)(d,e,c);console.log(`Active channels in Capgo: ${null==p?void 0:p.length}`),(0,r.displayChannels)(p),yield l.publish({channel:"channel",event:"List channel",icon:"✅",tags:{"user-id":c,"app-id":e},notify:!1}).catch(),console.log("Done ✅"),process.exit()}))},331:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const i=n(7304),a=n(2235),r=n(3866);o.setChannel=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,s,l;n.apikey=n.apikey||(0,r.findSavedKey)();const d=yield(0,r.getConfig)();o=o||(null===(t=null==d?void 0:d.app)||void 0===t?void 0:t.appId);const c=(0,r.useLogSnag)();n.apikey||i.program.error("Missing API key, you need to provide a API key to upload your bundle"),o||i.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const p=(0,r.createSupabaseClient)(n.apikey),u=yield(0,r.verifyUser)(p,n.apikey,["write","all"]);yield(0,a.checkAppExistsAndHasPermissionErr)(p,o,n.apikey);const{bundle:y,latest:f,downgrade:g,upgrade:v,ios:h,android:m,selfAssign:b,state:k}=n;e||i.program.error("Missing argument, you need to provide a channel"),f&&y&&i.program.error("Cannot set latest and bundle at the same time"),null==y&&null==k&&null==f&&null==g&&null==v&&null==h&&null==m&&null==b&&i.program.error("Missing argument, you need to provide a option to set");try{yield(0,r.checkPlanValid)(p,u),yield(0,a.checkAppExistsAndHasPermissionErr)(p,o,n.apikey);const t={created_by:u,app_id:o,name:e,version:void 0},w=f?null===(l=null===(s=null==d?void 0:d.app)||void 0===s?void 0:s.package)||void 0===l?void 0:l.version:y;if(null!=w){const{data:n,error:a}=yield p.from("app_versions").select().eq("app_id",o).eq("name",w).eq("user_id",u).eq("deleted",!1).single();!a&&n||i.program.error(`Cannot find version ${w}`),console.log(`Set ${o} channel: ${e} to @${w}`),t.version=n.id}null!=k&&("public"!==k&&"private"!==k||console.log(`Set ${o} channel: ${e} to public or private is deprecated, use default or normal instead`),console.log(`Set ${o} channel: ${e} to ${"public"===k||"default"===k?"default":"normal"}`),t.public="public"===k||"default"===k),null!=g&&(console.log(`Set ${o} channel: ${e} to ${g?"allow":"disallow"} downgrade`),t.disableAutoUpdateUnderNative=!g),null!=v&&(console.log(`Set ${o} channel: ${e} to ${v?"allow":"disallow"} upgrade`),t.disableAutoUpdateToMajor=!v),null!=h&&(console.log(`Set ${o} channel: ${e} to ${h?"allow":"disallow"} ios update`),t.ios=!!h),null!=m&&(console.log(`Set ${o} channel: ${e} to ${m?"allow":"disallow"} android update`),t.android=!!m),null!=b&&(console.log(`Set ${o} channel: ${e} to ${b?"allow":"disallow"} self assign to this channel`),t.allow_device_self_set=!!b);try{const{error:e}=yield(0,r.updateOrCreateChannel)(p,t,n.apikey);e&&i.program.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.')}catch(e){i.program.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.')}yield c.publish({channel:"channel",event:"Set channel",icon:"✅",tags:{"user-id":u,"app-id":o},notify:!1}).catch()}catch(e){i.program.error(`Unknow error ${(0,r.formatError)(e)}`)}console.log("Done ✅"),process.exit()}))},4819: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(7304),a=n(5902),r=n(7099),s=n(2959),l=n(3832),d=n(8329),c=n(4105),p=n(7239),u=n(5564),y=n(1489),f=n(331),g=n(3854),v=t(n(4147)),h=n(8517),m=n(4430),b=n(47),k=n(8210),w=n(963),_=n(7534),x=n(1465),C=n(7591),$=n(4992);i.program.description("Manage packages and bundle versions in Capgo Cloud").version(v.default.version),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(h.loginCommand).option("--local","Only save in local folder"),i.program.command("doctor").description("Get info about your Capgo app install").action(p.getInfo),i.program.command("init [apikey] [appid]").description("Init a new app").action(r.initApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account");const S=i.program.command("app").description("Manage app");S.command("add [appid]").alias("a").description("Add a new app in Capgo Cloud").action(c.addCommand).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),S.command("delete [appid]").alias("d").description("Delete an app in Capgo Cloud").action(C.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account"),S.command("list [appid]").alias("l").description("list apps in Capgo Cloud").action(m.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),S.command("watch [port]").alias("w").description("watch for changes in your app and allow capgo app or your app to see changes in live").action($.watchApp),S.command("set [appid]").alias("s").description("Set an app in Capgo Cloud").action(x.setApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account");const P=i.program.command("bundle").description("Manage bundle");P.command("upload [appid]").alias("u").description("Upload a new bundle in Capgo Cloud").action(g.uploadCommand).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 bundle to upload"),P.command("delete [appid]").alias("d").description("Delete a bundle in Capgo Cloud").action(y.deleteBundle).option("-a, --apikey <apikey>","apikey to link to your account"),P.command("list [appid]").alias("l").description("List bundle in Capgo Cloud").action(s.listBundle).option("-a, --apikey <apikey>","apikey to link to your account"),P.command("unlink [appid]").alias("u").description("Unlink a bundle in Capgo Cloud").action(s.listBundle).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the bundle to unlink"),P.command("cleanup [appid]").alias("c").action(b.cleanupBundle).description("Cleanup bundle in Capgo Cloud").option("-b, --bundle <bundle>","bundle version number of the app to delete").option("-a, --apikey <apikey>","apikey to link to your account").option("-k, --keep <keep>","number of version to keep").option("-f, --force","force removal"),P.command("decrypt [zipPath] [sessionKey]").alias("l").description("Decrypt a signed zip bundle").action(l.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),P.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(d.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),P.command("zip [appid]").description("Zip a bundle").action(a.zipBundle).option("-p, --path <path>","path of the folder to upload").option("-b, --bundle <bundle>","bundle version number to name the zip file");const A=i.program.command("channel").description("Manage channel");A.command("add [channelid] [appid]").alias("a").description("Create channel").action(k.addChannelCommand).option("-d, --default","set the channel as default"),A.command("delete [channelid] [appid]").alias("d").description("Delete channel").action(w.deleteChannel),A.command("list [appid]").alias("l").description("List channel").action(_.listChannels),A.command("set [channelid] [appid]").alias("s").description("Set channel").action(f.setChannel).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the file to set").option("-s, --state <state>","set the state of the channel, default or normal").option("--latest","get the latest version key in the package.json to set it to the channel").option("--downgrade","Allow to downgrade to version under native one").option("--no-downgrade","Disable downgrade to version under native one").option("--upgrade","Allow to upgrade to version above native one").option("--no-upgrade","Disable upgrade to version above native one").option("--ios","Allow sending update to ios devices").option("--no-ios","Disable sending update to ios devices").option("--android","Allow sending update to android devices").option("--no-android","Disable sending update to android devices").option("--self-assign","Allow to device to self assign to this channel").option("--no-self-assign","Disable devices to self assign to this channel");const I=i.program.command("key").description("Manage key");I.command("save").description("Save base64 signing key in capacitor config, usefull for CI").action(u.saveKeyCommand).option("-f, --force","force generate a new one"),I.command("create").description("Create a new signing key").action(u.createKeyCommand).option("-f, --force","force generate a new one"),i.program.command("upload [appid]").alias("u").description("(Deprecated) Upload a new bundle to Capgo Cloud").action(g.uploadDeprecatedCommand).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to Capgo Cloud").option("--key <key>","custom path for public signing key").option("--keyData <keyData>","base64 public signing key").option("--no-key","ignore signing key and send clear update").option("--display-iv-session","Show in the console the iv and session key used to encrypt the update").option("-b, --bundle <bundle>","bundle version number of the file to upload"),i.program.parseAsync()},7099:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},r=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.initApp=void 0;const s=n(7147),l=n(6301),d=n(2081),c=a(n(552)),p=n(5564),u=n(8210),y=n(3854),f=n(8517),g=n(4105),v=n(5995),h=n(3866),m="import { CapacitorUpdater } from '@capgo/capacitor-updater'",b="CapacitorUpdater.notifyAppReady()",k=/import.*from.*/g,w="production",_={stdio:"pipe"},x=(e,o,n)=>r(void 0,void 0,void 0,(function*(){c.isCancel(e)&&(yield n.publish({channel:"onboarding-v2",event:"canceled",icon:"🤷",tags:{"user-id":o},notify:!1}).catch(),process.exit())})),C=(e,o,n,t="✅")=>r(void 0,void 0,void 0,(function*(){yield o.publish({channel:"onboarding-v2",event:n,icon:t,tags:{"user-id":e},notify:!1}).catch()})),$=(e,o,n)=>r(void 0,void 0,void 0,(function*(){return C(e,o,`onboarding-step-${n}`)})),S=e=>new Promise((o=>{setTimeout(o,e)}));o.initApp=(e,o,n)=>r(void 0,void 0,void 0,(function*(){var t;yield(0,v.checkLatest)();const i=(0,h.useLogSnag)(),a=yield(0,h.getConfig)();o=o||(null===(t=null==a?void 0:a.app)||void 0===t?void 0:t.appId),e=e||(0,h.findSavedKey)(),c.intro("Capgo init");const P=c.spinner();P.start("Running: npx @capgo/cli@latest login ***"),(yield(0,f.login)(e,n,!1))?P.stop("Login Done ✅"):P.stop("Login already done ✅");const A=(0,h.createSupabaseClient)(e),I=yield(0,h.verifyUser)(A,e,["upload","all","read","write"]);yield $(I,i,1),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const i=yield c.confirm({message:`Add ${n} in Capgo?`});if(yield x(i,e,o),i){const e=c.spinner();e.start(`Running: npx @capgo/cli@latest app add ${n}`),(yield(0,g.addApp)(n,t,!1))?e.stop("App add Done ✅"):e.stop("App already add ✅")}else c.log.info(`Run yourself "npx @capgo/cli@latest app add ${n}"`);yield $(e,o,2)})))(I,i,o,n),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const i=yield c.confirm({message:`Create default channel ${w} for ${t} in Capgo?`});if(yield x(i,e,o),i){const e=c.spinner();e.start(`Running: npx @capgo/cli@latest channel add ${w} ${t} --default`),(yield(0,u.addChannel)(w,t,{default:!0,apikey:n},!1))?e.stop("Channel add Done ✅"):e.stop("Channel already added ✅")}else c.log.info(`Run yourself "npx @capgo/cli@latest channel add ${w} ${t} --default"`);yield $(e,o,3)})))(I,i,e,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const n=yield c.confirm({message:`Automatic Install "@capgo/capacitor-updater" dependency in ${t}?`});if(yield x(n,e,o),n){const e=c.spinner();e.start("Checking if @capgo/capacitor-updater is installed");const o=JSON.parse((0,s.readFileSync)("package.json").toString()),n=(0,l.findPackageManagerType)();"unknown"===n&&(e.stop("Cannot reconize package manager, please run `capgo init` in a capacitor project with npm, pnpm or yarn"),process.exit());const t="yarn"===n?"add":"install";o.dependencies["@capgo/capacitor-updater"]?e.stop("Capgo already installed ✅"):(yield(0,d.execSync)(`${n} ${t} @capgo/capacitor-updater@latest`,_),e.stop("Install Done ✅"))}else c.log.info('Run yourself "npm i @capgo/capacitor-updater@latest"');yield $(e,o,4)})))(I,i,0,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const n=yield c.confirm({message:`Automatic Add "${b}" code and import in ${t}?`});if(yield x(n,e,o),n){const n=c.spinner();n.start("Adding @capacitor-updater to your main file");const t=yield(0,h.findMainFile)();t||(n.stop("No main.ts, main.js, index.ts or index.js file found, please run cap init first"),process.exit());const i=(0,s.readFileSync)(t).toString(),a=i.match(k),r=null==a?void 0:a.pop();if(r||(n.stop("Cannot find import line in main file, use manual installation: https://docs.capgo.app/plugin/installation"),process.exit()),i.includes(b))n.stop(`Code already added to ${t} ✅`);else{const e=i.replace(r,`${r}\n${m};\n\n${b};\n`);(0,s.writeFileSync)(t,e),n.stop(`Code added to ${t} ✅`)}yield $(e,o,5)}else c.log.info(`Add to your main file the following code:\n\n${m};\n\n${b};\n`)})))(I,i,0,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const n=yield c.confirm({message:`Automatic configure end-to-end encryption in ${t} updates?`});if(yield x(n,e,o),n){const n=c.spinner();n.start("Running: npx @capgo/cli@latest key create"),(yield(0,p.createKey)({},!1))?n.stop("key created 🔑"):(n.stop("Cannot create key ❌"),process.exit(1)),C(e,o,"Use encryption")}yield $(e,o,6)})))(I,i,0,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){var n;const i=yield c.confirm({message:`Automatic build ${t} with "npm run build" ?`});if(yield x(i,e,o),i){const e=c.spinner();e.start("Running: npm run build && npx cap sync"),(null===(n=JSON.parse((0,s.readFileSync)("package.json").toString()).scripts)||void 0===n?void 0:n.build)||(e.stop("Cannot find build script in package.json, please add it and run `capgo init` again"),process.exit()),(0,d.execSync)("npm run build && npx cap sync",_),e.stop("Build & Sync Done ✅")}else c.log.info("Build yourself with command: npm run build && npx cap sync");yield $(e,o,7)})))(I,i,0,o),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const i=yield c.confirm({message:`Automatic upload ${t} bundle to Capgo?`});if(yield x(i,e,o),i){const e=c.spinner();e.start("Running: npx @capgo/cli@latest bundle upload"),(yield(0,y.uploadBundle)(t,{channel:w,apikey:n},!1))?e.stop("Upload Done ✅"):(e.stop("Upload failed ❌"),process.exit())}else c.log.info("Upload yourself with command: npx @capgo/cli@latest bundle upload");yield $(e,o,8)})))(I,i,e,o),yield((e,o)=>r(void 0,void 0,void 0,(function*(){const n=yield c.confirm({message:"Run in device now ?"});if(yield x(n,e,o),n){const e=yield c.select({message:"Pick a platform to run your app",options:[{value:"ios",label:"IOS"},{value:"android",label:"Android"}]});c.isCancel(e)&&process.exit();const o=e,n=c.spinner();n.start(`Running: npx cap run ${o}`),yield(0,d.spawnSync)("npx",["cap","run",o],{stdio:"inherit"}),n.stop("Started Done ✅")}else c.log.info("Run yourself with command: npx cap run <ios|android>");yield $(e,o,9)})))(I,i),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){const i=yield c.confirm({message:"Automatic check if update working in device ?"});if(yield x(i,e,o),i)c.log.info(`Wait logs sent to Capgo from ${t} device, Put the app in background and open it again.`),c.log.info("Waiting..."),yield((e,o,n,t)=>r(void 0,void 0,void 0,(function*(){let i=!0,a=(new Date).toISOString();for(yield C(t,n,"Use waitlog");i;){const{data:r,error:s}=yield e.from("stats").select("*").eq("app_id",o).order("id",{ascending:!1}).gte("created_at",a).limit(1).single();if(r&&!s){if(c.log.info(`Device: ${r.device_id}`),"get"===r.action)c.log.info("Update Sent your your device, wait until event download complete"),yield $(t,n,11);else if(r.action.startsWith("download_")){const e=r.action.split("_")[1];"complete"===e?(c.log.info("Your bundle has been downloaded on your device, background the app now and open it again to see the update"),yield $(t,n,12)):"fail"===e?(c.log.error("Your bundle has failed to download on your device."),c.log.error("Please check if you have network connection and try again")):c.log.info(`Your bundle is downloading ${e}% ...`)}else{if("set"===r.action)return c.log.info("Your bundle has been set on your device ❤️"),i=!1,yield $(t,n,13),Promise.resolve(r);"NoChannelOrOverride"===r.action?c.log.error("No default channel or override (channel/device) found, please create one"):"needPlanUpgrade"===r.action?c.log.error("Your are out of quota, please upgrade your plan"):"missingBundle"===r.action?c.log.error("Your bundle is missing, please check how you build your app"):"noNew"===r.action?c.log.error(`Your version in ${r.platform} is the same as your version uploaded, change it to see the update`):"disablePlatformIos"===r.action?c.log.error("iOS is disabled in the default channel and your device is an iOS device"):"disablePlatformAndroid"===r.action?c.log.error("Android is disabled in the default channel and your device is an Android device"):"disableAutoUpdateToMajor"===r.action?(c.log.error("Auto update to major version is disabled in the default channel."),c.log.error("Set your app to the same major version as the default channel")):"disableAutoUpdateUnderNative"===r.action?(c.log.error("Auto update under native version is disabled in the default channel."),c.log.error("Set your app to the same native version as the default channel.")):"disableDevBuild"===r.action?(c.log.error("Dev build is disabled in the default channel."),c.log.error("Set your channel to allow it if you wanna test your app")):"disableEmulator"===r.action?(c.log.error("Emulator is disabled in the default channel."),c.log.error("Set your channel to allow it if you wanna test your app")):"cannotGetBundle"===r.action?(c.log.error("We cannot get your bundle from the default channel."),c.log.error("Are you sure your default channel has a bundle set?")):"set_fail"===r.action?c.log.error("Your bundle seems to be corrupted, please check your code and send it again to Capgo"):"reset"===r.action?c.log.error("Your device has been reset to the builtin bundle"):"update_fail"===r.action?(c.log.error("Your bundle has been installed but failed to call notifyAppReady"),c.log.error("Please check if you have network connection and try again")):"checksum_fail"===r.action&&c.log.error("Your bundle has failed to validate checksum, please check your code and send it again to Capgo")}a=(new Date).toISOString()}yield S(1e3)}return Promise.resolve()})))(n,t,o,e);else{const e=(0,h.convertAppName)(t);c.log.info(`Check logs in https://web.capgo.app/app/p/${e}/logs to see if update works.`)}yield $(e,o,10)})))(I,i,A,o),yield $(I,i,0),c.outro("Welcome onboard ✈️!\nYour Capgo update system is setup"),process.exit()}))},5564:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.createKeyCommand=o.createKey=o.saveKeyCommand=o.saveKey=void 0;const i=n(7304),a=n(7147),r=n(7778),s=n(4201),l=n(3866),d=n(5995);o.saveKey=(e,o=!0)=>t(void 0,void 0,void 0,(function*(){(0,a.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const n=yield(0,l.getConfig)(),{extConfig:t}=n.app,s=e.key||l.baseKey;let d=e.keyData||"";if((0,a.existsSync)(s)||d)(0,a.existsSync)(s)&&(d=(0,a.readFileSync)(s).toString());else{if(!o)return!1;i.program.error(`Cannot find public key ${s} or as keyData option or in ${n.app.extConfigFilePath}`)}return t&&(t.plugins||(t.plugins={}),t.plugins.CapacitorUpdater||(t.plugins.CapacitorUpdater={}),t.plugins.CapacitorUpdater.privateKey=d,(0,r.writeConfig)(t,n.app.extConfigFilePath)),o&&(console.log(`private key saved into ${n.app.extConfigFilePath} file in local directory`),console.log("your app will decode the zip archive with this key\n")),!0})),o.saveKeyCommand=e=>t(void 0,void 0,void 0,(function*(){yield(0,d.checkLatest)(),yield(0,o.saveKey)(e)})),o.createKey=(e,o=!0)=>t(void 0,void 0,void 0,(function*(){(0,a.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const{publicKey:n,privateKey:t}=(0,s.createRSA)();if((0,a.existsSync)(l.baseKeyPub)&&!e.force){if(!o)return!1;i.program.error("Public Key already exists, use --force to overwrite")}if((0,a.writeFileSync)(l.baseKeyPub,n),(0,a.existsSync)(l.baseKey)&&!e.force){if(!o)return!1;i.program.error("Private Key already exists, use --force to overwrite")}(0,a.writeFileSync)(l.baseKey,t);const d=yield(0,l.getConfig)(),{extConfig:c}=d.app;return c&&(c.plugins||(c.plugins={}),c.plugins.CapacitorUpdater||(c.plugins.CapacitorUpdater={}),c.plugins.CapacitorUpdater.privateKey=t,(0,r.writeConfig)(c,d.app.extConfigFilePath)),o&&(console.log("Your RSA key has been generated\n"),console.log(`public key saved into ${l.baseKeyPub} file in local directory\n`),console.log("This key will be use to encode AES key used to crypt your zipped bundle before sending it to Capgo,\n than make them unreadable by Capgo and unmodifiable by anyone\n"),console.log(`Private key saved into ${d.app.extConfigFilePath} file in local directory`),console.log("Your app will decode with this RSA key the AES key and use it to decode the zipped bundle\n")),!0})),o.createKeyCommand=e=>t(void 0,void 0,void 0,(function*(){yield(0,d.checkLatest)(),yield(0,o.createKey)(e)}))},8517:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.loginCommand=o.login=void 0;const i=n(7304),a=n(7147),r=n(2037),s=n(3866),l=n(5995);o.login=(e,o,n=!0)=>t(void 0,void 0,void 0,(function*(){if(!e)return n&&i.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,l.checkLatest)();try{const{local:n}=o,t=(0,s.useLogSnag)();if(n)(0,a.existsSync)(".git")||i.program.error("To use local you should be in a git repository"),(0,a.writeFileSync)(".capgo",`${e}\n`),(0,a.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,r.homedir)();(0,a.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const l=(0,s.createSupabaseClient)(e),d=yield(0,s.verifyUser)(l,e,["write","all","upload"]);yield t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":d},notify:!1}).catch(),console.log(`login saved into .capgo file in ${n?"local":"home"} directory`)}catch(e){console.error(e),process.exit(1)}return n&&(console.log("Done ✅"),process.exit()),!0})),o.loginCommand=(e,n)=>t(void 0,void 0,void 0,(function*(){(0,o.login)(e,n,!0)}))},3866:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,a){function r(e){try{l(t.next(e))}catch(e){a(e)}}function s(e){try{l(t.throw(e))}catch(e){a(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(r,s)}l((t=t.apply(e,o||[])).next())}))},i=this&&this.__await||function(e){return this instanceof i?(this.v=e,this):new i(e)},a=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.__asyncDelegator||function(e){var o,n;return o={},t("next"),t("throw",(function(e){throw e})),t("return"),o[Symbol.iterator]=function(){return this},o;function t(t,a){o[t]=e[t]?function(o){return(n=!n)?{value:i(e[t](o)),done:"return"===t}:a?a(o):o}:a}},s=this&&this.__asyncGenerator||function(e,o,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,a=n.apply(e,o||[]),r=[];return t={},s("next"),s("throw"),s("return"),t[Symbol.asyncIterator]=function(){return this},t;function s(e){a[e]&&(t[e]=function(o){return new Promise((function(n,t){r.push([e,o,n,t])>1||l(e,o)}))})}function l(e,o){try{(n=a[e](o)).value instanceof i?Promise.resolve(n.value.v).then(d,c):p(r[0][2],n)}catch(e){p(r[0][3],e)}var n}function d(e){l("next",e)}function c(e){l("throw",e)}function p(e,o){e(o),r.shift(),r.length&&l(r[0][0],r[0][1])}},l=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.findMainFile=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 d=n(7778),c=n(7304),p=n(2885),u=l(n(9867)),y=n(7147),f=n(2037),g=n(1133),v=n(1017),h=l(n(6634));function m(e){return s(this,arguments,(function*(){const o=yield i((0,y.readdirSync)(e,{withFileTypes:!0}));for(const n of o){const o=(0,v.resolve)(e,n.name);!n.isDirectory()||n.name.startsWith(".")||n.name.startsWith("node_modules")||n.name.startsWith("dist")?yield yield i(o):yield i(yield*r(a(m(o))))}}))}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,p.createClient)(o.hostSupa,o.supaAnon,{global:{headers:{capgkey:e}}}),o.regexSemver=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,o.checkKey=(e,n,i)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:a}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:i}).single();t&&!a||c.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(a)}`)})),o.isGoodPlan=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_good_plan_v3",{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))||(console.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),setTimeout((()=>{(0,h.default)(`${o.hostWeb}/dashboard/settings/plans`),c.program.error("")}),1e3));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,o=`${(0,f.homedir)()}/.capgo`;return(0,y.existsSync)(o)&&(console.log(`Use global apy key ${o}`),e=(0,y.readFileSync)(o,"utf8").trim()),o=".capgo",!e&&(0,y.existsSync)(o)&&(console.log(`Use local apy key ${o}`),e=(0,y.readFileSync)(o,"utf8").trim()),e||c.program.error("Key not found, please login first"),e},o.findMainFile=()=>t(void 0,void 0,void 0,(function*(){var e,o,n,t;const i=/(main|index)\.(ts|js)$/;let r="";const s=process.cwd(),l=s.split("/").length;try{for(var d,c=!0,p=a(m(s));!(e=(d=yield p.next()).done);){t=d.value,c=!1;try{const e=t;if(e.split("/").length-l<=2&&i.test(e)){r=e,console.log("Found main file here",e);break}}finally{c=!0}}}catch(e){o={error:e}}finally{try{c||e||!(n=p.return)||(yield n.call(p))}finally{if(o)throw o.error}}return r})),o.formatError=e=>e?`\n${u.default.render(e)}`:"",o.getConfig=()=>t(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,d.loadConfig)()}catch(e){c.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)):e.from("app_versions").insert(o).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).select().single():e.from("channels").insert(o).select().single()})),o.useLogSnag=()=>new g.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.convertAppName=e=>e.replace(/\./g,"--"),o.verifyUser=(e,n,i=["all"])=>t(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,n,i);const{data:t,error:a}=yield e.rpc("get_user_id",{apikey:n}).single(),r=t?t.toString():"";return r&&!a||c.program.error(`Cannot verify user ${(0,o.formatError)(a)}`),r})),o.getHumanDate=e=>new Date(e||"").toLocaleString()},7778:e=>{e.exports=require("@capacitor/cli/dist/config")},6301:e=>{e.exports=require("@capgo/find-package-manager")},552:e=>{e.exports=require("@clack/prompts")},2885:e=>{e.exports=require("@supabase/supabase-js")},5906:e=>{e.exports=require("@tomasklaen/checksum")},7176:e=>{e.exports=require("@trufflesuite/spinnies")},3844:e=>{e.exports=require("adm-zip")},3422:e=>{e.exports=require("cloudflared")},7304:e=>{e.exports=require("commander")},3847:e=>{e.exports=require("console-table-printer")},4470:e=>{e.exports=require("fs-extra")},5362:e=>{e.exports=require("get-latest-version")},1133:e=>{e.exports=require("logsnag")},9011:e=>{e.exports=require("mime")},6634:e=>{e.exports=require("open")},9867:e=>{e.exports=require("prettyjson")},1616:e=>{e.exports=require("prompt-sync")},1121:e=>{e.exports=require("qrcode")},1505:e=>{e.exports=require("semver/preload")},2081:e=>{e.exports=require("child_process")},6113:e=>{e.exports=require("crypto")},7147:e=>{e.exports=require("fs")},2037:e=>{e.exports=require("os")},1017:e=>{e.exports=require("path")},4147:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"3.9.1","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"engines":{"npm":">=7.0.0","node":">=16.0.0"},"keywords":["appflow alternative","ionic","capacitor","auto update","live update","capgo","cli","upload","capgo-cli"],"scripts":{"dev":"set NODE_ENV=development && npx webpack --config webpack.config.js","no-debug":"node dist/index.js","test":"npx --yes ts-node -T src/index.ts","build":"npx --yes webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","types":"npx --yes supabase gen types typescript --project-id=xvwzpoazmxkqosrdewyv > src/types/supabase.types.ts","test_rls":"ts-node ./test/test_headers_rls.ts","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"4.7.1","@capgo/find-package-manager":"^0.0.7","@clack/prompts":"^0.6.3","@supabase/supabase-js":"^2.12.1","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","cloudflared":"^0.3.4","commander":"10.0.0","console-table-printer":"^2.11.1","fs-extra":"11.1.1","get-latest-version":"^5.0.1","logsnag":"^0.1.6","mime":"^3.0.0","open":"^8.4.2","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","qrcode":"^1.5.1","semver":"^7.3.8"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/fs-extra":"^11.0.1","@types/mime":"^3.0.1","@types/node":"^18.15.5","@types/open":"^6.2.1","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/qrcode":"^1.5.0","@types/semver":"^7.3.13","@typescript-eslint/eslint-plugin":"5.56.0","@typescript-eslint/parser":"5.56.0","eslint":"8.36.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.8.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.22","pkg":"5.8.1","prettier":"2.8.6","ts-loader":"^9.4.2","ts-node":"^10.9.1","tsconfig-paths":"4.1.2","typescript":"4.9.5","webpack":"5.76.3","webpack-cli":"^5.0.1","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var a=o[t]={exports:{}};return e[t].call(a.exports,a,a.exports,n),a.exports}(4819)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "3.9.0",
3
+ "version": "3.9.1",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/app/watch.ts CHANGED
@@ -16,10 +16,11 @@ export const watch = async (port: string, options: Options, shouldExit = true) =
16
16
  return false
17
17
  }
18
18
  await checkLatest();
19
- p.intro(`Capgo tunnel init`);
19
+ p.intro(`Capgo live reload`);
20
20
 
21
21
  // write in file .capgo the apikey in home directory
22
22
  try {
23
+
23
24
  const snag = useLogSnag()
24
25
 
25
26
  const supabase = createSupabaseClient(options.apikey)
@@ -33,19 +34,39 @@ export const watch = async (port: string, options: Options, shouldExit = true) =
33
34
  },
34
35
  notify: false,
35
36
  }).catch()
37
+ p.log.info(`Init tunnel`);
36
38
  const { url, connections, stop } = tunnel({ "--url": `localhost:${port}` });
37
39
 
40
+ p.log.info(`Get URL`);
41
+
38
42
  const link = await url;
43
+ // const link = 'https://google.com';
44
+ p.log.info(`Connection to tunnel`);
39
45
  await Promise.all(connections);
40
46
 
47
+
41
48
  p.log.info(`Tunnel ${link} connected to localhost:${port}`);
49
+ // add to supabase app_live
50
+ await supabase
51
+ .from('app_live')
52
+ .upsert({
53
+ id: userId,
54
+ url: link,
55
+ })
56
+ .throwOnError()
42
57
  const qrUrl = await QRCode.toString(link, { type: 'terminal', small: true });
43
58
  p.log.info(qrUrl);
44
59
  await p.confirm({ message: `When done say yes to close tunnel` });
45
60
  await stop();
61
+ // delete to supabase app_live
62
+ await supabase
63
+ .from('app_live')
64
+ .delete()
65
+ .eq('id', userId)
66
+ .throwOnError()
46
67
  p.log.info(`Tunnel closed`);
47
68
  } catch (e) {
48
- console.error(e);
69
+ console.error('Error', e);
49
70
  process.exit(1);
50
71
  }
51
72
  if (shouldExit) {
@@ -35,6 +35,26 @@ export interface Database {
35
35
  user_id?: string
36
36
  }
37
37
  }
38
+ app_live: {
39
+ Row: {
40
+ created_at: string | null
41
+ id: string
42
+ updated_at: string | null
43
+ url: string
44
+ }
45
+ Insert: {
46
+ created_at?: string | null
47
+ id: string
48
+ updated_at?: string | null
49
+ url: string
50
+ }
51
+ Update: {
52
+ created_at?: string | null
53
+ id?: string
54
+ updated_at?: string | null
55
+ url?: string
56
+ }
57
+ }
38
58
  app_stats: {
39
59
  Row: {
40
60
  app_id: string
@@ -135,8 +155,11 @@ export interface Database {
135
155
  checksum: string
136
156
  created_at: string | null
137
157
  devices: number | null
158
+ fails: number | null
138
159
  id: number
160
+ installs: number | null
139
161
  size: number
162
+ uninstalls: number | null
140
163
  updated_at: string | null
141
164
  user_id: string
142
165
  }
@@ -145,8 +168,11 @@ export interface Database {
145
168
  checksum: string
146
169
  created_at?: string | null
147
170
  devices?: number | null
171
+ fails?: number | null
148
172
  id?: number
173
+ installs?: number | null
149
174
  size: number
175
+ uninstalls?: number | null
150
176
  updated_at?: string | null
151
177
  user_id: string
152
178
  }
@@ -155,8 +181,11 @@ export interface Database {
155
181
  checksum?: string
156
182
  created_at?: string | null
157
183
  devices?: number | null
184
+ fails?: number | null
158
185
  id?: number
186
+ installs?: number | null
159
187
  size?: number
188
+ uninstalls?: number | null
160
189
  updated_at?: string | null
161
190
  user_id?: string
162
191
  }
@@ -595,6 +624,7 @@ export interface Database {
595
624
  created_at: string | null
596
625
  developer: string
597
626
  developer_email: string
627
+ developer_id: string | null
598
628
  error_get_framework: string
599
629
  error_get_info: string
600
630
  error_get_similar: string
@@ -603,6 +633,7 @@ export interface Database {
603
633
  icon: string
604
634
  installs: number
605
635
  kotlin: boolean
636
+ lang: string | null
606
637
  native_script: boolean
607
638
  onprem: boolean
608
639
  react_native: boolean
@@ -625,6 +656,7 @@ export interface Database {
625
656
  created_at?: string | null
626
657
  developer?: string
627
658
  developer_email?: string
659
+ developer_id?: string | null
628
660
  error_get_framework?: string
629
661
  error_get_info?: string
630
662
  error_get_similar?: string
@@ -633,6 +665,7 @@ export interface Database {
633
665
  icon?: string
634
666
  installs?: number
635
667
  kotlin?: boolean
668
+ lang?: string | null
636
669
  native_script?: boolean
637
670
  onprem?: boolean
638
671
  react_native?: boolean
@@ -655,6 +688,7 @@ export interface Database {
655
688
  created_at?: string | null
656
689
  developer?: string
657
690
  developer_email?: string
691
+ developer_id?: string | null
658
692
  error_get_framework?: string
659
693
  error_get_info?: string
660
694
  error_get_similar?: string
@@ -663,6 +697,7 @@ export interface Database {
663
697
  icon?: string
664
698
  installs?: number
665
699
  kotlin?: boolean
700
+ lang?: string | null
666
701
  native_script?: boolean
667
702
  onprem?: boolean
668
703
  react_native?: boolean
@@ -808,6 +843,29 @@ export interface Database {
808
843
  Args: Record<PropertyKey, never>
809
844
  Returns: number
810
845
  }
846
+ count_all_need_upgrade: {
847
+ Args: Record<PropertyKey, never>
848
+ Returns: number
849
+ }
850
+ count_all_onboarded: {
851
+ Args: Record<PropertyKey, never>
852
+ Returns: number
853
+ }
854
+ count_all_paying: {
855
+ Args: Record<PropertyKey, never>
856
+ Returns: number
857
+ }
858
+ count_all_plans: {
859
+ Args: Record<PropertyKey, never>
860
+ Returns: {
861
+ product_id: string
862
+ count: number
863
+ }[]
864
+ }
865
+ count_all_trial: {
866
+ Args: Record<PropertyKey, never>
867
+ Returns: number
868
+ }
811
869
  count_all_updates: {
812
870
  Args: Record<PropertyKey, never>
813
871
  Returns: number
@@ -865,6 +923,14 @@ export interface Database {
865
923
  name: string
866
924
  }[]
867
925
  }
926
+ find_missing_app_ids: {
927
+ Args: {
928
+ app_ids: string[]
929
+ }
930
+ Returns: {
931
+ missing_app_id: string
932
+ }[]
933
+ }
868
934
  get_app_versions: {
869
935
  Args: {
870
936
  appid: string
@@ -1154,6 +1220,16 @@ export interface Database {
1154
1220
  }
1155
1221
  Returns: boolean
1156
1222
  }
1223
+ update_version_stats: {
1224
+ Args: {
1225
+ app_id: string
1226
+ version_id: number
1227
+ install: number
1228
+ uninstall: number
1229
+ fail: number
1230
+ }
1231
+ Returns: undefined
1232
+ }
1157
1233
  }
1158
1234
  Enums: {
1159
1235
  app_mode: "prod" | "dev" | "livereload"