@capgo/cli 3.13.5 → 3.13.7

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,15 @@
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.13.7](https://github.com/Cap-go/capgo-cli/compare/v3.13.6...v3.13.7) (2023-08-24)
6
+
7
+ ### [3.13.6](https://github.com/Cap-go/capgo-cli/compare/v3.13.5...v3.13.6) (2023-08-23)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * upload issues ([c9618a1](https://github.com/Cap-go/capgo-cli/commit/c9618a1d631682b193821de1c41e036074ada10b))
13
+
5
14
  ### [3.13.5](https://github.com/Cap-go/capgo-cli/compare/v3.13.4...v3.13.5) (2023-08-21)
6
15
 
7
16
  ### [3.13.4](https://github.com/Cap-go/capgo-cli/compare/v3.13.3...v3.13.4) (2023-08-17)
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- (()=>{"use strict";var e={9218:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((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:r}=yield e.rpc("exist_app",{appid:o,apikey:n}).single();return t!==i||r})),o.checkAppExistsAndHasPermissionErr=(e,n,r,a=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.checkAppExistsAndHasPermission)(e,n,r,a))&&i.program.error(`App ${n} does not exist or you don't have permission to access it`)})),o.newIconPath="assets/icon.png"},6824: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((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 l=n(7304),c=n(3847),s=r(n(552)),d=n(6545);o.checkVersionNotUsedInChannel=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){var r;const{data:a,error:c}=yield e.from("channels").select().eq("app_id",n).eq("created_by",t).eq("version",i.id);if(c&&l.program.error(`Cannot check Version ${n}@${i.name} ${(0,d.formatError)(c)}`),a&&a.length>0){if(s.intro(`❌ Version ${n}@${i.name} is used in ${a.length} channel`),yield s.confirm({message:"unlink it?"}))for(const t of a){const i=s.spinner();i.start(`Unlinking channel ${t.name}`);const{error:a}=yield e.from("channels").update({version:null===(r=yield(0,o.findUnknownVersion)(e,n))||void 0===r?void 0:r.id}).eq("id",t.id);a&&(i.stop(`Cannot update channel ${t.name} ${(0,d.formatError)(a)}`),process.exit(1)),i.stop(`✅ Channel ${t.name} unlinked`)}else l.program.error("unlink it first");s.outro(`Version unlinked from ${a.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 c.Table({title:"Channels",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,d.getHumanDate)(e.created_at),Public:e.public?"✅":"❌"})})),s.log.success(o.render())},o.getActiveChannels=(e,o,n)=>a(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&&l.program.error(`App ${o} not found in database ${(0,d.formatError)(i)} `),t}))},407:(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",r="sha256",a="base64",l=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[c,s]=o.split(":"),d=(0,t.privateDecrypt)({key:n,padding:l,oaepHash:r},Buffer.from(s,a)),p=Buffer.from(c,a),u=(0,t.createDecipheriv)(i,d,p);return u.setAutoPadding(!0),Buffer.concat([u.update(e),u.final()])},o.encryptSource=(e,o)=>{const n=(0,t.randomBytes)(16),c=(0,t.randomBytes)(16),s=(0,t.createCipheriv)(i,c,n);s.setAutoPadding(!0);const d=`${n.toString(a)}:${(0,t.publicEncrypt)({key:o,padding:l,oaepHash:r},c).toString(a)}`;return{encryptedData:Buffer.concat([s.update(e),s.final()]),ivSessionKey:d}},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"})}}},7863: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const l=n(7304),c=r(n(552)),s=n(6545);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>a(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&&l.program.error(`Cannot check Device override ${o}@${n.name} ${(0,s.formatError)(i)}`),t&&t.length>0)if(c.intro(`❌ Version ${o}@${n.name} is used in ${t.length} device override`),yield c.confirm({message:"unlink it?"}))for(const o of t){const n=c.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,s.formatError)(t)}`),process.exit(1)),n.stop(`✅ Device ${o.device_id} unlinked`)}else l.program.error("unlink it first")}))},1954:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(7304),r=n(6545);o.deleteFromStorage=(e,o,n,a,l)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${a.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${l} ${(0,r.formatError)(t)} `)}))},7482: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.checkLatest=void 0;const c=l(n(5362)),s=r(n(552)),d=l(n(4147));o.checkLatest=()=>a(void 0,void 0,void 0,(function*(){const e=yield(0,c.default)("@capgo/cli");e!==d.default.version&&s.log.warning(`🚨 You are using @capgo/cli@${d.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.`)}))},9656: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getVersionData=o.getChannelsVersion=o.getActiveAppVersions=o.displayBundles=o.deleteSpecificVersion=o.deleteAppVersion=void 0;const l=n(7304),c=n(3847),s=r(n(552)),d=n(6545),p=n(6824),u=n(7863),f=n(1954);o.deleteAppVersion=(e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const{error:i}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("deleted",!1).eq("user_id",n).eq("name",t);i&&l.program.error(`App Version ${o}@${t} not found in database '${(0,d.formatError)(i)}'`)})),o.deleteSpecificVersion=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){const r=yield(0,o.getVersionData)(e,n,t,i);yield(0,p.checkVersionNotUsedInChannel)(e,n,t,r),yield(0,u.checkVersionNotUsedInDeviceOverride)(e,n,r),yield(0,f.deleteFromStorage)(e,t,n,r,i),yield(0,o.deleteAppVersion)(e,n,t,i)})),o.displayBundles=e=>{const o=new c.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,d.getHumanDate)(e.created_at)},null!=e.keep?{Keep:e.keep}:{}))})),s.log.success(o.render())},o.getActiveAppVersions=(e,o,n)=>a(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return i&&l.program.error(`App ${o} not found in database ${(0,d.formatError)(i)} `),t})),o.getChannelsVersion=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.from("channels").select("version").eq("app_id",o);return t&&l.program.error(`App ${o} not found in database ${(0,d.formatError)(t)} `),n.map((e=>e.version))})),o.getVersionData=(e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const{data:i,error:r}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("name",t).eq("deleted",!1).single();return i&&!r||l.program.error(`App Version ${o}@${t} doesn't exist ${(0,d.formatError)(r)}`),i}))},7171: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addCommand=o.addApp=void 0;const l=n(6113),c=n(9011),s=n(7304),d=r(n(552)),p=n(4470),u=n(7482),f=n(9218),y=n(6545);o.addApp=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){var t,i,r;n&&d.intro("Adding"),yield(0,u.checkLatest)(),o.apikey=o.apikey||(0,y.findSavedKey)();const a=yield(0,y.getConfig)();e=e||(null===(t=null==a?void 0:a.app)||void 0===t?void 0:t.appId);const g=(0,y.useLogSnag)();o.apikey||(d.log.error("Missing API key, you need to provide a API key to upload your bundle"),s.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),s.program.error(""));const v=(0,y.createSupabaseClient)(o.apikey),h=yield(0,y.verifyUser)(v,o.apikey,["write","all"]);if(n)yield(0,f.checkAppExistsAndHasPermissionErr)(v,e,o.apikey,!1);else if(yield(0,f.checkAppExistsAndHasPermission)(v,e,o.apikey,!1))return!1;let m,b,{name:_,icon:w}=o;e=e||(null===(i=null==a?void 0:a.app)||void 0===i?void 0:i.appId),_=_||(null===(r=null==a?void 0:a.app)||void 0===r?void 0:r.appName)||"Unknown",w=w||"resources/icon.png",w&&_||(d.log.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project"),s.program.error("")),n&&d.log.info(`Adding ${e} to Capgo`),w&&(0,p.existsSync)(w)?(m=(0,p.readFileSync)(w),b=(0,c.getType)(w)||"image/png",d.log.warn(`Found app icon ${w}`)):(0,p.existsSync)(f.newIconPath)?(m=(0,p.readFileSync)(f.newIconPath),b=(0,c.getType)(f.newIconPath)||"image/png",d.log.warn(`Found app icon ${f.newIconPath}`)):d.log.warn(`Cannot find app icon in any of the following locations: ${w}, ${f.newIconPath}`);const{data:k,error:P}=yield v.rpc("exist_app_v2",{appid:e}).single();(k||P)&&(d.log.error(`App ${e} already exists ${(0,y.formatError)(P)}`),s.program.error(""));const C=`icon_${(0,l.randomUUID)()}`;let O="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(m&&b){const{error:o}=yield v.storage.from(`images/${h}/${e}`).upload(C,m,{contentType:b});o&&(d.log.error(`Could not add app ${(0,y.formatError)(o)}`),s.program.error(""));const{data:n}=yield v.storage.from(`images/${h}/${e}`).getPublicUrl(C);O=(null==n?void 0:n.publicUrl)||O}const{error:x}=yield v.from("apps").insert({icon_url:O,user_id:h,name:_,app_id:e});x&&(d.log.error(`Could not add app ${(0,y.formatError)(x)}`),s.program.error(""));const{error:S}=yield v.from("app_versions").insert([{user_id:h,deleted:!0,name:"unknown",app_id:e},{user_id:h,deleted:!0,name:"builtin",app_id:e}]);return S&&(d.log.error(`Could not add app ${(0,y.formatError)(S)}`),s.program.error("")),yield g.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":h,"app-id":e},notify:!1}).catch(),d.log.success(`App ${e} added to Capgo. ${n?"You can upload a bundle now":""}`),n&&(d.outro("Done ✅"),process.exit()),!0})),o.addCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.addApp)(e,n,!0)}))},7626: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.debugApp=o.waitLog=o.cancelCommand=o.markSnag=void 0;const l=r(n(552)),c=n(7304),s=n(9218),d=n(7482),p=n(6545),u=e=>new Promise((o=>{setTimeout(o,e)}));o.markSnag=(e,o,n,t,i="✅")=>a(void 0,void 0,void 0,(function*(){yield n.publish({channel:e,event:t,icon:i,tags:{"user-id":o},notify:!1}).catch()})),o.cancelCommand=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){l.isCancel(n)&&(yield(0,o.markSnag)(e,t,i,"canceled","🤷"),process.exit())})),o.waitLog=(e,n,t,i,r,c)=>a(void 0,void 0,void 0,(function*(){let a=!0,s=(new Date).toISOString();const d=`https://web.capgo.app/app/p/${(0,p.convertAppName)(t)}`;for(yield(0,o.markSnag)(e,r,i,"Use waitlog");a;){const p=n.from("stats").select("*").eq("app_id",t).order("created_at",{ascending:!1}).gte("created_at",s);c&&p.eq("device_id",c);const{data:f,error:y}=yield p.limit(1).single();if(f&&!y){if(l.log.info(`Device: ${f.device_id}`),"get"===f.action)l.log.info("Update Sent your your device, wait until event download complete"),yield(0,o.markSnag)(e,r,i,"done");else if(f.action.startsWith("download_")){const n=f.action.split("_")[1];"complete"===n?(l.log.info("Your bundle has been downloaded on your device, background the app now and open it again to see the update"),yield(0,o.markSnag)(e,r,i,"downloaded")):"fail"===n?(l.log.error("Your bundle has failed to download on your device."),l.log.error("Please check if you have network connection and try again")):l.log.info(`Your bundle is downloading ${n}% ...`)}else{if("set"===f.action)return l.log.info("Your bundle has been set on your device ❤️"),a=!1,yield(0,o.markSnag)(e,r,i,"set"),Promise.resolve(f);"NoChannelOrOverride"===f.action?l.log.error(`No default channel or override (channel/device) found, please create it here ${d}`):"needPlanUpgrade"===f.action?l.log.error("Your are out of quota, please upgrade your plan here https://web.capgo.app/dashboard/settings/plans"):"missingBundle"===f.action?l.log.error("Your bundle is missing, please check how you build your app "):"noNew"===f.action?l.log.error(`Your version in ${f.platform} is the same as your version uploaded, change it to see the update`):"disablePlatformIos"===f.action?l.log.error(`iOS is disabled in the default channel and your device is an iOS device ${d}`):"disablePlatformAndroid"===f.action?l.log.error(`Android is disabled in the default channel and your device is an Android device ${d}`):"disableAutoUpdateToMajor"===f.action?(l.log.error("Auto update to major version is disabled in the default channel."),l.log.error("Set your app to the same major version as the default channel")):"disableAutoUpdateUnderNative"===f.action?(l.log.error("Auto update under native version is disabled in the default channel."),l.log.error("Set your app to the same native version as the default channel.")):"disableDevBuild"===f.action?(l.log.error(`Dev build is disabled in the default channel. ${d}`),l.log.error("Set your channel to allow it if you wanna test your app")):"disableEmulator"===f.action?(l.log.error(`Emulator is disabled in the default channel. ${d}`),l.log.error("Set your channel to allow it if you wanna test your app")):"cannotGetBundle"===f.action?(l.log.error(`We cannot get your bundle from the default channel. ${d}`),l.log.error("Are you sure your default channel has a bundle set?")):"set_fail"===f.action?l.log.error(`Your bundle seems to be corrupted, try to download from ${d} to identify the issue`):"reset"===f.action?l.log.error("Your device has been reset to the builtin bundle, did you added notifyAppReady in your code?"):"update_fail"===f.action?(l.log.error("Your bundle has been installed but failed to call notifyAppReady"),l.log.error("Please check if you have network connection and try again")):"checksum_fail"===f.action&&l.log.error("Your bundle has failed to validate checksum, please check your code and send it again to Capgo")}s=(new Date).toISOString()}yield u(1e3)}return Promise.resolve()})),o.debugApp=(e,n)=>a(void 0,void 0,void 0,(function*(){var t;l.intro("Debug Live update in Capgo"),yield(0,d.checkLatest)(),n.apikey=n.apikey||(0,p.findSavedKey)();const i=yield(0,p.getConfig)();e=e||(null===(t=null==i?void 0:i.app)||void 0===t?void 0:t.appId);const r=n.device;n.apikey||(l.log.error("Missing API key, you need to provide an API key to delete your app"),c.program.error("")),e||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.program.error(""));const a=(0,p.createSupabaseClient)(n.apikey),u=(0,p.useLogSnag)(),f=yield(0,p.verifyUser)(a,n.apikey);l.log.info("Getting active bundle in Capgo"),yield(0,s.checkAppExistsAndHasPermissionErr)(a,e,n.apikey);const y=yield l.confirm({message:"Automatic check if update working in device ?"});yield(0,o.cancelCommand)("debug",y,f,u),y?(l.log.info(`Wait logs sent to Capgo from ${e} device, Put the app in background and open it again.`),l.log.info("Waiting..."),yield(0,o.waitLog)("debug",a,e,u,f,r),l.outro("Done ✅")):l.outro("Canceled ❌"),l.outro("Done ✅"),process.exit()}))},6626: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6545);o.deleteApp=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;c.intro("Deleting"),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);const i=(0,d.useLogSnag)();o.apikey||l.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||l.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const r=(0,d.createSupabaseClient)(o.apikey),a=yield(0,d.verifyUser)(r,o.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(r,e,o.apikey);const{error:p}=yield r.storage.from(`images/${a}`).remove([e]);p&&l.program.error(`Could not add app ${(0,d.formatError)(p)}`);const{error:u}=yield r.storage.from(`apps/${e}/${a}`).remove(["versions"]);u&&l.program.error(`Could not delete app version ${(0,d.formatError)(u)}`);const{error:f}=yield r.from("apps").delete().eq("app_id",e).eq("user_id",a);f&&l.program.error(`Could not delete app ${(0,d.formatError)(f)}`),yield i.publish({channel:"app",event:"App Deleted",icon:"🗑️",tags:{"user-id":a,"app-id":e},notify:!1}).catch(),c.log.success("App deleted in Capgo"),c.outro("Done ✅"),process.exit()}))},1628:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getInfo=void 0;const r=n(7147),a=n(1017),l=i(n(2037)),c=i(n(5362)),s=i(n(7176)),d=i(n(4147));o.getInfo=()=>t(void 0,void 0,void 0,(function*(){console.log(" 💊 Capgo Doctor 💊\n"),console.log(` OS: ${l.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,r.readFileSync)((0,a.join)(process.cwd(),"package.json"));return JSON.parse(e)})),o={"@capgo/cli":d.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 s.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,c.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()}))},8373: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=o.getActiveApps=void 0;const l=n(7304),c=n(3847),s=r(n(552)),d=n(9218),p=n(6545),u=n(7482);o.getActiveApps=(e,o)=>a(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&&l.program.error(`Apps not found in database ${(0,p.formatError)(t)} `),n})),o.listApp=(e,n)=>a(void 0,void 0,void 0,(function*(){var t;s.intro("List apps in Capgo"),yield(0,u.checkLatest)(),n.apikey=n.apikey||(0,p.findSavedKey)();const i=yield(0,p.getConfig)();e=e||(null===(t=null==i?void 0:i.app)||void 0===t?void 0:t.appId),n.apikey||(s.log.error("Missing API key, you need to provide an API key to delete your app"),l.program.error("")),e||(s.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const r=(0,p.createSupabaseClient)(n.apikey),a=yield(0,p.verifyUser)(r,n.apikey);s.log.info("Getting active bundle in Capgo"),yield(0,d.checkAppExistsAndHasPermissionErr)(r,e,n.apikey);const f=yield(0,o.getActiveApps)(r,a);s.log.info(`Active app in Capgo: ${null==f?void 0:f.length}`),(e=>{const o=new c.Table({title:"Apps",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,p.getHumanDate)(e.created_at)})})),s.log.success(o.render())})(f),s.outro("Done ✅"),process.exit()}))},5789: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setApp=void 0;const l=n(6113),c=n(9011),s=n(7304),d=r(n(552)),p=n(4470),u=n(9218),f=n(6545);o.setApp=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;d.intro("Set app"),o.apikey=o.apikey||(0,f.findSavedKey)();const t=yield(0,f.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||(d.log.error("Missing API key, you need to provide a API key to upload your bundle"),s.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),s.program.error(""));const i=(0,f.createSupabaseClient)(o.apikey),r=yield(0,f.verifyUser)(i,o.apikey,["write","all"]);yield(0,u.checkAppExistsAndHasPermissionErr)(i,e,o.apikey);const{name:a,icon:y,retention:g}=o;let v,h;g&&!Number.isNaN(Number(g))?(d.log.error("retention value must be a number"),s.program.error("")):g&&g<0&&(d.log.error("retention value cannot be less than 0"),s.program.error(""));const m=`icon_${(0,l.randomUUID)()}`;let b="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(y&&(0,p.existsSync)(y)?(v=(0,p.readFileSync)(y),h=(0,c.getType)(y)||"image/png",d.log.warn(`Found app icon ${y}`)):(0,p.existsSync)(u.newIconPath)?(v=(0,p.readFileSync)(u.newIconPath),h=(0,c.getType)(u.newIconPath)||"image/png",d.log.warn(`Found app icon ${u.newIconPath}`)):d.log.warn(`Cannot find app icon in any of the following locations: ${y}, ${u.newIconPath}`),v&&h){const{error:o}=yield i.storage.from(`images/${r}/${e}`).upload(m,v,{contentType:h});o&&(d.log.error(`Could not add app ${(0,f.formatError)(o)}`),s.program.error(""));const{data:n}=yield i.storage.from(`images/${r}/${e}`).getPublicUrl(m);b=(null==n?void 0:n.publicUrl)||b}const{error:_}=yield i.from("apps").update({icon_url:b,name:a,retention:g?24*g*60*60:null}).eq("app_id",e).eq("user_id",r);_&&(d.log.error(`Could not add app ${(0,f.formatError)(_)}`),s.program.error("")),d.outro("Done ✅"),process.exit()}))},4635: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=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 c=n(7304),s=r(n(552)),d=l(n(1121)),p=n(3422),u=n(6545),f=n(7482);o.watch=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){if(o.apikey=o.apikey||(0,u.findSavedKey)(),!o.apikey)return n&&c.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,f.checkLatest)(),s.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(),s.log.info("Init to tunnel");const{url:r,connections:a,stop:l}=(0,p.tunnel)({"--url":`localhost:${e}`});s.log.info("Connection to tunnel"),yield a[0],s.log.info("Get URL");const c=yield r;if(!c)throw new Error("No link found");s.log.info(`Tunnel ${c} connected to localhost:${e}`),yield t.from("app_live").upsert({id:i,url:c}).throwOnError();const f=yield d.default.toString(c,{type:"terminal",small:!0});s.log.info(f),yield s.confirm({message:"When done say yes to close tunnel"}),yield l(),yield t.from("app_live").delete().eq("id",i).throwOnError(),s.log.info("Tunnel closed")}catch(e){console.error("Error",e),process.exit(1)}return n&&(s.outro("Done ✅"),process.exit()),!0})),o.watchApp=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.watch)(e,n,!0)}))},2393: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=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)}))}}},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupBundle=void 0;const s=n(7304),d=c(n(1505)),p=r(n(552)),u=c(n(1616)),f=n(6545),y=n(9656),g=n(9218),v=n(7482),h=(0,u.default)();o.cleanupBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;p.intro("Cleanup versions in Capgo"),yield(0,v.checkLatest)();const t=o.apikey||(0,f.findSavedKey)(),{bundle:i,keep:r=4}=o,c=o.force||!1,u=yield(0,f.getConfig)();e=e||(null===(n=null==u?void 0:u.app)||void 0===n?void 0:n.appId),t||s.program.error("Missing API key, you need to provide an API key to delete your app"),e||s.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const m=(0,f.createSupabaseClient)(t),b=yield(0,f.verifyUser)(m,t);yield(0,g.checkAppExistsAndHasPermissionErr)(m,e,t),p.log.info("Querying all available versions in Capgo");let _=yield(0,y.getActiveAppVersions)(m,e,b);const w=yield(0,y.getChannelsVersion)(m,e);if(p.log.info(`Total active versions in Capgo: ${null==_?void 0:_.length}`),0===(null==_?void 0:_.length))return void p.log.error("No versions found, aborting cleanup");if(i){const e=`${d.default.inc(i,"major")}`;p.log.info(`Querying available versions in Capgo between ${i} and ${e}`),_=((e,o,n)=>{const t=[];return null==e||e.forEach((e=>{d.default.gte(e.name,o)&&d.default.lt(e.name,`${n}`)&&t.push(e)})),t})(_,i,e),p.log.info(`Active versions in Capgo between ${i} and ${e}: ${null==_?void 0:_.length}`)}const k=[];let P=0;if(_.forEach((e=>{const o=w.find((o=>o===e.id));P<r||o?(e.keep=o?"✅ (Linked to channel)":"✅",P+=1):(e.keep="❌",k.push(e))})),0!==k.length){if((0,y.displayBundles)(_),!c&&"yes"!==h("Do you want to continue removing the versions specified? Type yes to confirm: "))return void p.log.warn("Not confirmed, aborting removal...");p.log.success("You have confirmed removal, removing versions now"),yield((e,o,n,t)=>{var i,r,c;return a(void 0,void 0,void 0,(function*(){var a,s,d,u;try{for(i=!0,r=l(e);!(a=(c=yield r.next()).done);i=!0){u=c.value,i=!1;const e=u;p.log.warn(`Removing ${e.name} created on ${(0,f.getHumanDate)(e.created_at)}`),yield(0,y.deleteSpecificVersion)(o,n,t,e.name)}}catch(e){s={error:e}}finally{try{i||a||!(d=r.return)||(yield d.call(r))}finally{if(s)throw s.error}}}))})(k,m,e,b),p.outro("Done ✅"),process.exit()}else p.log.warn("Nothing to be removed, aborting removal...")}))},7978: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const l=n(7147),c=n(7304),s=r(n(552)),d=n(407),p=n(6545),u=n(7482);o.decryptZip=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i,r;s.intro("Decrypt zip file"),yield(0,u.checkLatest)(),(0,l.existsSync)(e)||c.program.error(`Zip not found at the path ${e}`);const a=yield(0,p.getConfig)(),{extConfig:f}=a.app;n.key||(0,l.existsSync)(p.baseKey)||(null===(i=null===(t=f.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===i?void 0:i.privateKey)||c.program.error(`Private Key not found at the path ${p.baseKey} or in ${a.app.extConfigFilePath}`);const y=n.key||p.baseKey;let{privateKey:g}=n.keyData||(null===(r=null==f?void 0:f.plugins)||void 0===r?void 0:r.CapacitorUpdater)||"";(0,l.existsSync)(y)||g?(0,l.existsSync)(y)&&(g=(0,l.readFileSync)(y).toString()):c.program.error(`Cannot find public key ${y} or as keyData option or in ${a.app.extConfigFilePath}`);const v=(0,l.readFileSync)(e),h=(0,d.decryptSource)(v,o,g);(0,l.writeFileSync)(`${e}_decrypted.zip`,h),s.outro(`Decrypted zip file at ${e}_decrypted.zip`),process.exit()}))},3930: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteBundle=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6545),p=n(9656);o.deleteBundle=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i;c.intro("Delete bundle"),n.apikey=n.apikey||(0,d.findSavedKey)();const r=yield(0,d.getConfig)();o=o||(null===(t=null==r?void 0:r.app)||void 0===t?void 0:t.appId),n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const a=(0,d.createSupabaseClient)(n.apikey),u=yield(0,d.verifyUser)(a,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(a,o,n.apikey);const f=n.apikey||(0,d.findSavedKey)();o=o||(null===(i=null==r?void 0:r.app)||void 0===i?void 0:i.appId),f||(c.log.error("Missing API key, you need to provide an API key to delete your app"),l.program.error("")),e||(c.log.error("Missing argument, you need to provide a bundleId, or be in a capacitor project"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error("")),c.log.info(`Deleting bundle ${o}@${e} from Capgo`),yield(0,p.deleteSpecificVersion)(a,o,u,e),c.log.success(`Bundle ${o}@${e} deleted in Capgo`),c.outro("Done"),process.exit()}))},3333: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const c=n(7147),s=n(7304),d=l(n(7812)),p=r(n(552)),u=n(7482),f=n(407),y=n(6545);o.encryptZip=(e,o)=>a(void 0,void 0,void 0,(function*(){p.intro("Encryption"),yield(0,u.checkLatest)(),(0,c.existsSync)(e)||(p.log.error(`Error: Zip not found at the path ${e}`),s.program.error(""));const n=o.key||y.baseKeyPub;let t=o.keyData||"";(0,c.existsSync)(n)||t?(0,c.existsSync)(n)&&(t=(0,c.readFileSync)(n).toString()):(p.log.warning(`Cannot find public key ${n} or as keyData option`),d.default.isCI&&(p.log.error("Error: Missing public key"),s.program.error("")),(yield p.confirm({message:"Do you want to use our public key ?"}))||(p.log.error("Error: Missing public key"),s.program.error("")),t=y.defaulPublicKey);const i=(0,c.readFileSync)(e),r=(0,f.encryptSource)(i,t);p.log.success(`ivSessionKey: ${r.ivSessionKey}`),(0,c.writeFileSync)(`${e}_encrypted.zip`,r.encryptedData),p.log.success(`Encrypted zip saved at ${e}_encrypted.zip`),p.outro("Done ✅"),process.exit()}))},2083: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listBundle=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(9656),p=n(6545),u=n(7482);o.listBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;c.intro("List bundles"),yield(0,u.checkLatest)(),o.apikey=o.apikey||(0,p.findSavedKey)();const t=yield(0,p.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),e||(c.log.error("Missing argument, you need to provide a appid, or be in a capacitor project"),l.program.error(""));const i=(0,p.createSupabaseClient)(o.apikey),r=yield(0,p.verifyUser)(i,o.apikey);c.log.info(`Querying available versions of: ${e} in Capgo`),yield(0,s.checkAppExistsAndHasPermissionErr)(i,e,o.apikey);const a=yield(0,d.getActiveAppVersions)(i,e,r);c.log.info(`Active versions in Capgo: ${null==a?void 0:a.length}`),(0,d.displayBundles)(a),c.outro("Done ✅"),process.exit()}))},2510: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=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 c=n(6113),s=n(7147),d=l(n(3844)),p=n(7304),u=r(n(552)),f=n(5906),y=l(n(7812)),g=l(n(2167)),v=n(7482),h=n(9218),m=n(407),b=n(6545);o.uploadBundle=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){var t,i,r,a;u.intro("Uploading"),yield(0,v.checkLatest)();let{bundle:l,path:_,channel:w}=o;const{external:k,key:P=!1,displayIvSession:C}=o,O=o.apikey||(0,b.findSavedKey)(),x=(0,b.useLogSnag)();w=w||"dev";const S=yield(0,b.getConfig)();e=e||(null===(t=null==S?void 0:S.app)||void 0===t?void 0:t.appId);const $=(0,c.randomUUID)().split("-")[0];l=l||(null===(r=null===(i=null==S?void 0:S.app)||void 0===i?void 0:i.package)||void 0===r?void 0:r.version)||`0.0.1-beta.${$}`,b.regexSemver.test(l)||(u.log.error(`Your bundle name ${l}, is not valid it should follow semver convention : https://semver.org/`),p.program.error("")),_=_||(null===(a=null==S?void 0:S.app)||void 0===a?void 0:a.webDir),O||(u.log.error("Missing API key, you need to provide a API key to upload your bundle"),p.program.error("")),e&&l&&_||(u.log.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),p.program.error("")),(0,s.existsSync)(_)||(u.log.error(`Path ${_} does not exist, build your app first, or provide a valid path`),p.program.error("")),u.log.info(`Upload ${e}@${l} started from path "${_}" to Capgo cloud`);const j=(0,b.createSupabaseClient)(O),A=yield(0,b.verifyUser)(j,O,["write","all","upload"]);yield(0,b.checkPlanValid)(j,A,!1),yield(0,h.checkAppExistsAndHasPermissionErr)(j,e,O);const{data:M,error:D}=yield j.rpc("exist_app_versions",{apikey:O,name_version:l,appid:e}).single();(M||D)&&(u.log.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,b.formatError)(D)}`),p.program.error(""));const{data:I,error:E}=yield j.rpc("is_trial",{userid:A}).single();(I&&I>0||E)&&(u.log.warn(`WARNING !!\nTrial expires in ${I} days`),u.log.warn(`Upgrade here: ${b.hostWeb}/dashboard/settings/plans`));const{data:U,error:q}=yield j.rpc("exist_app",{appid:e,apikey:O}).single();U&&!q||(u.log.error(`Cannot find app ${e} in your account ${(0,b.formatError)(q)}`),p.program.error(""));const{data:K,error:B}=yield j.rpc("exist_app_versions",{appid:e,apikey:O,name_version:l}).single();(K||B)&&(u.log.error(`Version already exists ${(0,b.formatError)(B)}`),p.program.error(""));const L=`${l.replace(/[^a-zA-Z0-9-_.!*'()]/g,"__")}.zip`;let N,z="",F=null;if(k)k&&!k.startsWith("https://")?(u.log.error(`External link should should start with "https://" current is "${k}"`),p.program.error("")):yield x.publish({channel:"app",event:"App external",icon:"📤",tags:{"user-id":A,"app-id":e},notify:!1}).catch();else{const o=new d.default;o.addLocalFolder(_),F=o.toBuffer();const n=u.spinner();if(n.start("Calculating checksum"),z=yield(0,f.checksum)(F,"crc32"),n.stop(`Checksum: ${z}`),P||(0,s.existsSync)(b.baseKeyPub)){const o="string"==typeof P?P:b.baseKeyPub;let n="";(0,s.existsSync)(o)||(u.log.error(`Cannot find public key ${o}`),y.default.isCI&&p.program.error(""),(yield u.confirm({message:"Do you want to use our public key ?"}))||(u.log.error("Error: Missing public key"),p.program.error("")),n=b.defaulPublicKey),yield x.publish({channel:"app",event:"App encryption",icon:"🔑",tags:{"user-id":A,"app-id":e},notify:!1}).catch(),n=(0,s.readFileSync)(o).toString(),u.log.info("Encrypting your bundle");const t=(0,m.encryptSource)(F,n);N=t.ivSessionKey,C&&u.log.info(`Your Iv Session key is ${N},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),F=t.encryptedData}const t=Math.floor(F.byteLength/1024/1024);t>20&&(u.log.warn(`WARNING !!\nThe app size is ${t} Mb, this may take a while to download for users\n`),u.log.info("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield x.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":A,"app-id":e},notify:!1}).catch())}const V={bucket_id:k?void 0:L,user_id:A,name:l,app_id:e,session_key:N,external_url:k,storage_provider:k?"external":"r2-direct",checksum:z},{error:T}=yield(0,b.updateOrCreateVersion)(j,V,O);if(T&&(u.log.error(`Cannot add bundle ${(0,b.formatError)(T)}`),p.program.error("")),!k&&F){const o=u.spinner();o.start("Uploading Bundle");const n=yield(0,b.uploadUrl)(j,e,L);n||(u.log.error("Cannot get upload url"),p.program.error("")),yield(0,g.default)({method:"put",url:n,data:F,headers:{"Content-Type":"application/octet-stream","Cache-Control":"public, max-age=456789, immutable","x-amz-meta-crc32":z}}),V.storage_provider="r2";const{error:t}=yield(0,b.updateOrCreateVersion)(j,V,O);t&&(u.log.error(`Cannot update bundle ${(0,b.formatError)(T)}`),p.program.error("")),o.stop("Bundle Uploaded 💪")}const{data:R}=yield j.rpc("get_app_versions",{apikey:O,name_version:l,appid:e}).single();if(R){const{error:o,data:n}=yield(0,b.updateOrCreateChannel)(j,{name:w,app_id:e,created_by:A,version:R},O);o&&(u.log.error('Cannot set channel, the upload key is not allowed to do that, use the "all" for this.'),p.program.error(""));const t=(0,b.convertAppName)(e);(null==n?void 0:n.public)?u.log.info("Your update is now available in your public channel 🎉"):(null==n?void 0:n.id)&&u.log.info(`Link device to this bundle to try it: ${b.hostWeb}/app/p/${t}/channel/${n.id}`)}else u.log.warn("Cannot set bundle with upload key, use key with more rights for that"),p.program.error("");return yield x.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":A,"app-id":e},notify:!1}).catch(),n&&(u.outro("Time to share your update to the world 🌍"),process.exit()),!0})),o.uploadCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){try{yield(0,o.uploadBundle)(e,n,!0)}catch(e){u.log.error(JSON.stringify(e)),p.program.error("")}})),o.uploadDeprecatedCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){u.log.warn('⚠️ This command is deprecated, use "npx @capgo/cli bundle upload" instead ⚠️');try{yield(0,o.uploadBundle)(e,n,!0)}catch(e){u.log.error(JSON.stringify(e)),p.program.error("")}}))},7103: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.zipBundle=void 0;const c=n(6113),s=n(7147),d=l(n(3844)),p=n(7304),u=r(n(552)),f=n(5906),y=n(7482),g=n(6545);o.zipBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n,t,i,r;yield(0,y.checkLatest)();let{bundle:a,path:l}=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];a=a||(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}`,u.intro(`Zipping ${e}@${a}`),g.regexSemver.test(a)||(u.log.error(`Your bundle name ${a}, is not valid it should follow semver convention : https://semver.org/`),p.program.error("")),l=l||(null===(r=null==h?void 0:h.app)||void 0===r?void 0:r.webDir),e&&a&&l||(u.log.error("Missing argument, you need to provide a appId and a bundle and a path, or be in a capacitor project"),p.program.error("")),u.log.info(`Started from path "${l}"`);const b=new d.default;b.addLocalFolder(l);const _=b.toBuffer();u.log.info(`Zipped ${_.byteLength} bytes`);const w=u.spinner();w.start("Calculating checksum");const k=yield(0,f.checksum)(_,"crc32");w.stop(`Checksum: ${k}`);const P=Math.floor(_.byteLength/1024/1024);P>20&&(u.log.warn(`WARNING !!\nThe app size is ${P} Mb, this may take a while to download for users\n`),u.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=u.spinner();C.start(`Saving to ${e}_${a}.zip`),(0,s.writeFileSync)(`${e}_${a}.zip`,_),C.stop(`Saved to ${e}_${a}.zip`),yield v.publish({channel:"app",event:"App zip",icon:"⏫",tags:{"app-id":e},notify:!1}).catch(),u.outro("Done ✅"),process.exit()}))},4402: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addChannelCommand=o.addChannel=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.addChannel=(e,o,n,t=!0)=>a(void 0,void 0,void 0,(function*(){var i;c.intro("Create channel"),n.apikey=n.apikey||(0,p.findSavedKey)();const r=yield(0,p.getConfig)();o=o||(null===(i=null==r?void 0:r.app)||void 0===i?void 0:i.appId);const a=(0,p.useLogSnag)();n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const u=(0,p.createSupabaseClient)(n.apikey),f=yield(0,p.verifyUser)(u,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(u,o,n.apikey),c.log.info(`Creating channel ${o}#${e} to Capgo`);try{const n=yield(0,d.findUnknownVersion)(u,o);n||(c.log.error("Cannot find default version for channel creation, please contact Capgo support 🤨"),l.program.error("")),yield(0,d.createChannel)(u,{name:e,app_id:o,version:n.id,created_by:f}),c.log.success("Channel created ✅"),yield a.publish({channel:"channel",event:"Create channel",icon:"✅",tags:{"user-id":f,"app-id":o,channel:e},notify:!1}).catch()}catch(e){return c.log.error("Cannot create Channel 🙀"),!1}return t&&(c.outro("Done ✅"),process.exit()),!0})),o.addChannelCommand=(e,n,t)=>a(void 0,void 0,void 0,(function*(){(0,o.addChannel)(e,n,t,!0)}))},7422: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteChannel=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.deleteChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t;c.intro("Delete channel"),n.apikey=n.apikey||(0,p.findSavedKey)();const i=yield(0,p.getConfig)();o=o||(null===(t=null==i?void 0:i.app)||void 0===t?void 0:t.appId);const r=(0,p.useLogSnag)();n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const a=(0,p.createSupabaseClient)(n.apikey),u=yield(0,p.verifyUser)(a,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(a,o,n.apikey),c.log.info(`Deleting channel ${o}#${e} from Capgo`);try{yield(0,d.delChannel)(a,e,o,u),c.log.success("Channel deleted"),yield r.publish({channel:"channel",event:"Delete channel",icon:"✅",tags:{"user-id":u,"app-id":o,channel:e},notify:!1}).catch()}catch(e){c.log.error("Cannot delete Channel 🙀")}c.outro("Done ✅"),process.exit()}))},2667: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listChannels=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.listChannels=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;c.intro("List channels"),o.apikey=o.apikey||(0,p.findSavedKey)();const t=yield(0,p.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId);const i=(0,p.useLogSnag)();o.apikey||c.log.error("Missing API key, you need to provide a API key to upload your bundle"),e||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const r=(0,p.createSupabaseClient)(o.apikey),a=yield(0,p.verifyUser)(r,o.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(r,e,o.apikey),c.log.info("Querying available channels in Capgo"),yield(0,s.checkAppExistsAndHasPermissionErr)(r,e,o.apikey);const u=yield(0,d.getActiveChannels)(r,e,a);c.log.info(`Active channels in Capgo: ${null==u?void 0:u.length}`),(0,d.displayChannels)(u),yield i.publish({channel:"channel",event:"List channel",icon:"✅",tags:{"user-id":a,"app-id":e},notify:!1}).catch(),c.outro("Done ✅"),process.exit()}))},593: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6545);o.setChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i,r;c.intro("Set channel"),n.apikey=n.apikey||(0,d.findSavedKey)();const a=yield(0,d.getConfig)();o=o||(null===(t=null==a?void 0:a.app)||void 0===t?void 0:t.appId);const p=(0,d.useLogSnag)();n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const u=(0,d.createSupabaseClient)(n.apikey),f=yield(0,d.verifyUser)(u,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(u,o,n.apikey);const{bundle:y,latest:g,downgrade:v,upgrade:h,ios:m,android:b,selfAssign:_,state:w}=n;e||(c.log.error("Missing argument, you need to provide a channel"),l.program.error("")),g&&y&&(c.log.error("Cannot set latest and bundle at the same time"),l.program.error("")),null==y&&null==w&&null==g&&null==v&&null==h&&null==m&&null==b&&null==_&&(c.log.error("Missing argument, you need to provide a option to set"),l.program.error(""));try{yield(0,d.checkPlanValid)(u,f),yield(0,s.checkAppExistsAndHasPermissionErr)(u,o,n.apikey);const t={created_by:f,app_id:o,name:e,version:void 0},k=g?null===(r=null===(i=null==a?void 0:a.app)||void 0===i?void 0:i.package)||void 0===r?void 0:r.version:y;if(null!=k){const{data:n,error:i}=yield u.from("app_versions").select().eq("app_id",o).eq("name",k).eq("user_id",f).eq("deleted",!1).single();!i&&n||(c.log.error(`Cannot find version ${k}`),l.program.error("")),c.log.info(`Set ${o} channel: ${e} to @${k}`),t.version=n.id}null!=w&&("public"!==w&&"private"!==w||c.log.info(`Set ${o} channel: ${e} to public or private is deprecated, use default or normal instead`),c.log.info(`Set ${o} channel: ${e} to ${"public"===w||"default"===w?"default":"normal"}`),t.public="public"===w||"default"===w),null!=v&&(c.log.info(`Set ${o} channel: ${e} to ${v?"allow":"disallow"} downgrade`),t.disableAutoUpdateUnderNative=!v),null!=h&&(c.log.info(`Set ${o} channel: ${e} to ${h?"allow":"disallow"} upgrade`),t.disableAutoUpdateToMajor=!h),null!=m&&(c.log.info(`Set ${o} channel: ${e} to ${m?"allow":"disallow"} ios update`),t.ios=!!m),null!=b&&(c.log.info(`Set ${o} channel: ${e} to ${b?"allow":"disallow"} android update`),t.android=!!b),null!=_&&(c.log.info(`Set ${o} channel: ${e} to ${_?"allow":"disallow"} self assign to this channel`),t.allow_device_self_set=!!_);try{const{error:e}=yield(0,d.updateOrCreateChannel)(u,t,n.apikey);e&&(c.log.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.'),l.program.error(""))}catch(e){c.log.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.'),l.program.error("")}yield p.publish({channel:"channel",event:"Set channel",icon:"✅",tags:{"user-id":f,"app-id":o},notify:!1}).catch()}catch(e){c.log.error(`Unknow error ${(0,d.formatError)(e)}`),l.program.error("")}c.outro("Done ✅"),process.exit()}))},4999: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),r=n(7103),a=n(6104),l=n(2083),c=n(7978),s=n(3333),d=n(7171),p=n(1628),u=n(6122),f=n(3930),y=n(593),g=n(2510),v=t(n(4147)),h=n(5041),m=n(8373),b=n(2393),_=n(4402),w=n(7422),k=n(2667),P=n(5789),C=n(6626),O=n(4635),x=n(7626);i.program.name(v.default.name).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(a.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(d.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("debug [appId]").alias("d").description("Listen for live updates event in Capgo Cloud to debug your app").option("-a, --apikey <apikey>","apikey to link to your account").option("-d, --device <device>","the specific device to debug").action(x.debugApp),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(O.watchApp),S.command("set [appId]").alias("s").description("Set an app in Capgo Cloud").action(P.setApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account").option("-r, --retention <retention>","retention period of app bundle in days");const $=i.program.command("bundle").description("Manage bundle");$.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"),$.command("delete [bundleId] [appId]").alias("d").description("Delete a bundle in Capgo Cloud").action(f.deleteBundle).option("-a, --apikey <apikey>","apikey to link to your account"),$.command("list [appId]").alias("l").description("List bundle in Capgo Cloud").action(l.listBundle).option("-a, --apikey <apikey>","apikey to link to your account"),$.command("unlink [appId]").alias("u").description("Unlink a bundle in Capgo Cloud").action(l.listBundle).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the bundle to unlink"),$.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"),$.command("decrypt [zipPath] [sessionKey]").alias("l").description("Decrypt a signed zip bundle").action(c.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),$.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(s.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),$.command("zip [appId]").description("Zip a bundle").action(r.zipBundle).option("-p, --path <path>","path of the folder to upload").option("-b, --bundle <bundle>","bundle version number to name the zip file");const j=i.program.command("channel").description("Manage channel");j.command("add [channelId] [appId]").alias("a").description("Create channel").action(_.addChannelCommand).option("-d, --default","set the channel as default"),j.command("delete [channelId] [appId]").alias("d").description("Delete channel").action(w.deleteChannel),j.command("list [appId]").alias("l").description("List channel").action(k.listChannels),j.command("set [channelId] [appId]").alias("s").description("Set channel").action(y.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 A=i.program.command("key").description("Manage key");A.command("save").description("Save base64 signing key in capacitor config, usefull for CI").action(u.saveKeyCommand).option("-f, --force","force generate a new one").option("--key","key path to save in capacitor config").option("--key-data","key data to save in capacitor config"),A.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()},6104: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.initApp=void 0;const l=n(7147),c=n(2081),s=n(6301),d=r(n(552)),p=n(7626),u=n(6122),f=n(4402),y=n(2510),g=n(5041),v=n(7171),h=n(7482),m=n(6545),b="import { CapacitorUpdater } from '@capgo/capacitor-updater'",_="CapacitorUpdater.notifyAppReady()",w=/import.*from.*/g,k="production",P={stdio:"pipe"},C=(e,o,n)=>a(void 0,void 0,void 0,(function*(){d.isCancel(e)&&(yield(0,p.markSnag)("onboarding-v2",o,n,"canceled","🤷"),process.exit())})),O=(e,o,n)=>a(void 0,void 0,void 0,(function*(){return(0,p.markSnag)("onboarding-v2",e,o,`onboarding-step-${n}`)}));o.initApp=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t;d.intro("Capgo onboarding 🛫"),yield(0,h.checkLatest)();const i=(0,m.useLogSnag)(),r=yield(0,m.getConfig)();o=o||(null===(t=null==r?void 0:r.app)||void 0===t?void 0:t.appId),e=e||(0,m.findSavedKey)();const x=d.spinner();x.start("Running: npx @capgo/cli@latest login ***"),(yield(0,g.login)(e,n,!1))?x.stop("Login Done ✅"):x.stop("Login already done ✅");const S=(0,m.createSupabaseClient)(e),$=yield(0,m.verifyUser)(S,e,["upload","all","read","write"]);yield O($,i,1),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Add ${n} in Capgo?`});if(yield C(i,e,o),i){const e=d.spinner();e.start(`Running: npx @capgo/cli@latest app add ${n}`),(yield(0,v.addApp)(n,t,!1))?e.stop("App add Done ✅"):e.stop("App already add ✅")}else d.log.info(`Run yourself "npx @capgo/cli@latest app add ${n}"`);yield O(e,o,2)})))($,i,o,n),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Create default channel ${k} for ${t} in Capgo?`});if(yield C(i,e,o),i){const e=d.spinner();e.start(`Running: npx @capgo/cli@latest channel add ${k} ${t} --default`),(yield(0,f.addChannel)(k,t,{default:!0,apikey:n},!1))?e.stop("Channel add Done ✅"):e.stop("Channel already added ✅")}else d.log.info(`Run yourself "npx @capgo/cli@latest channel add ${k} ${t} --default"`);yield O(e,o,3)})))($,i,e,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:`Automatic Install "@capgo/capacitor-updater" dependency in ${t}?`});if(yield C(n,e,o),n){const e=d.spinner();e.start("Checking if @capgo/capacitor-updater is installed");const o=JSON.parse((0,l.readFileSync)("package.json").toString()),n=(0,s.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,c.execSync)(`${n} ${t} @capgo/capacitor-updater@latest`,P),e.stop("Install Done ✅"))}else d.log.info('Run yourself "npm i @capgo/capacitor-updater@latest"');yield O(e,o,4)})))($,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:`Automatic Add "${_}" code and import in ${t}?`});if(yield C(n,e,o),n){const n=d.spinner();n.start("Adding @capacitor-updater to your main file");const t=yield(0,m.findMainFile)();t||(n.stop("No main.ts, main.js, index.ts or index.js file found, You need to add @capgo/capacitor-updater manually"),process.exit());const i=(0,l.readFileSync)(t).toString(),r=i.match(w),a=null==r?void 0:r.pop();if(a||(n.stop("Cannot find import line in main file, use manual installation: https://capgo.app/docs/plugin/installation/"),process.exit()),i.includes(_))n.stop(`Code already added to ${t} ✅`);else{const e=i.replace(a,`${a}\n${b};\n\n${_};\n`);(0,l.writeFileSync)(t,e),n.stop(`Code added to ${t} ✅`)}yield O(e,o,5)}else d.log.info(`Add to your main file the following code:\n\n${b};\n\n${_};\n`)})))($,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:`Automatic configure end-to-end encryption in ${t} updates?`});if(yield C(n,e,o),n){const n=d.spinner();n.start("Running: npx @capgo/cli@latest key create"),(yield(0,u.createKey)({},!1))?n.stop("key created 🔑"):(n.stop("Cannot create key ❌"),process.exit(1)),(0,p.markSnag)("onboarding-v2",e,o,"Use encryption")}yield O(e,o,6)})))($,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){var n;const i=yield d.confirm({message:`Automatic build ${t} with "npm run build" ?`});if(yield C(i,e,o),i){const e=d.spinner();e.start("Running: npm run build && npx cap sync"),(null===(n=JSON.parse((0,l.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,c.execSync)("npm run build && npx cap sync",P),e.stop("Build & Sync Done ✅")}else d.log.info("Build yourself with command: npm run build && npx cap sync");yield O(e,o,7)})))($,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Automatic upload ${t} bundle to Capgo?`});if(yield C(i,e,o),i){const e=d.spinner();e.start("Running: npx @capgo/cli@latest bundle upload"),(yield(0,y.uploadBundle)(t,{channel:k,apikey:n},!1))?e.stop("Upload Done ✅"):(e.stop("Upload failed ❌"),process.exit())}else d.log.info("Upload yourself with command: npx @capgo/cli@latest bundle upload");yield O(e,o,8)})))($,i,e,o),yield((e,o)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:"Run in device now ?"});if(yield C(n,e,o),n){const e=yield d.select({message:"Pick a platform to run your app",options:[{value:"ios",label:"IOS"},{value:"android",label:"Android"}]});d.isCancel(e)&&process.exit();const o=e,n=d.spinner();n.start(`Running: npx cap run ${o}`),yield(0,c.spawnSync)("npx",["cap","run",o],{stdio:"inherit"}),n.stop("Started Done ✅")}else d.log.info("Run yourself with command: npx cap run <ios|android>");yield O(e,o,9)})))($,i),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:"Automatic check if update working in device ?"});if(yield C(i,e,o),i)d.log.info(`Wait logs sent to Capgo from ${t} device, Put the app in background and open it again.`),d.log.info("Waiting..."),yield(0,p.waitLog)("onboarding-v2",n,t,o,e);else{const e=(0,m.convertAppName)(t);d.log.info(`Check logs in https://web.capgo.app/app/p/${e}/logs to see if update works.`)}yield O(e,o,10)})))($,i,S,o),yield O($,i,0),d.log.info("Welcome onboard ✈️!"),d.log.info("Your Capgo update system is setup"),d.log.info("Next time use `npx @capgo/cli@latest bundle upload` to only upload your bundle"),d.outro("Bye 👋"),process.exit()}))},6122: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.createKeyCommand=o.createKey=o.saveKeyCommand=o.saveKey=void 0;const l=n(7147),c=n(7304),s=n(7778),d=r(n(552)),p=n(407),u=n(6545),f=n(7482);o.saveKey=(e,o=!0)=>a(void 0,void 0,void 0,(function*(){(0,l.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),c.program.error(""));const n=yield(0,u.getConfig)(),{extConfig:t}=n.app,i=e.key||u.baseKey;let r=e.keyData||"";if((0,l.existsSync)(i)||r)(0,l.existsSync)(i)&&(r=(0,l.readFileSync)(i).toString());else{if(!o)return!1;d.log.error(`Cannot find public key ${i} or as keyData option or in ${n.app.extConfigFilePath}`),c.program.error("")}return t&&(t.plugins||(t.plugins={}),t.plugins.CapacitorUpdater||(t.plugins.CapacitorUpdater={}),t.plugins.CapacitorUpdater.privateKey=r,(0,s.writeConfig)(t,n.app.extConfigFilePath)),o&&(d.log.success(`private key saved into ${n.app.extConfigFilePath} file in local directory`),d.log.success("your app will decode the zip archive with this key")),!0})),o.saveKeyCommand=e=>a(void 0,void 0,void 0,(function*(){d.intro("Save keys 🔑"),yield(0,f.checkLatest)(),yield(0,o.saveKey)(e)})),o.createKey=(e,o=!0)=>a(void 0,void 0,void 0,(function*(){o&&d.intro("Create keys 🔑"),(0,l.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),c.program.error(""));const{publicKey:n,privateKey:t}=(0,p.createRSA)();if((0,l.existsSync)(u.baseKeyPub)&&!e.force){if(!o)return!1;d.log.error("Public Key already exists, use --force to overwrite"),c.program.error("")}if((0,l.writeFileSync)(u.baseKeyPub,n),(0,l.existsSync)(u.baseKey)&&!e.force){if(!o)return!1;d.log.error("Private Key already exists, use --force to overwrite"),c.program.error("")}(0,l.writeFileSync)(u.baseKey,t);const i=yield(0,u.getConfig)(),{extConfig:r}=i.app;return r&&(r.plugins||(r.plugins={}),r.plugins.CapacitorUpdater||(r.plugins.CapacitorUpdater={}),r.plugins.CapacitorUpdater.privateKey=t,(0,s.writeConfig)(r,i.app.extConfigFilePath)),o&&(d.log.success("Your RSA key has been generated"),d.log.success(`Public key saved in ${u.baseKeyPub}`),d.log.success("This key will be use to crypt your bundle before sending it to Capgo"),d.log.success("Than make them unreadable by Capgo and unmodifiable by anyone"),d.log.success(`Private key saved in ${i.app.extConfigFilePath}`),d.log.success("Your app will be the only one having it"),d.log.success("Only your users can decrypt your update"),d.log.success("Only you can send them an update"),d.outro("Done ✅")),!0})),o.createKeyCommand=e=>a(void 0,void 0,void 0,(function*(){yield(0,f.checkLatest)(),yield(0,o.createKey)(e)}))},5041: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.loginCommand=o.login=void 0;const l=n(7147),c=n(2037),s=n(7304),d=r(n(552)),p=n(6545),u=n(7482);o.login=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){if(n&&d.intro("Login to Capgo"),!e)return n&&s.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,u.checkLatest)();try{const{local:n}=o,t=(0,p.useLogSnag)();if(n)(0,l.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),s.program.error("")),(0,l.writeFileSync)(".capgo",`${e}\n`),(0,l.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,c.homedir)();(0,l.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const i=(0,p.createSupabaseClient)(e),r=yield(0,p.verifyUser)(i,e,["write","all","upload"]);yield t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":r},notify:!1}).catch(),d.log.success(`login saved into .capgo file in ${n?"local":"home"} directory`)}catch(e){d.log.error("Error while saving login"),process.exit(1)}return n&&(d.outro("Done ✅"),process.exit()),!0})),o.loginCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.login)(e,n,!0)}))},6545: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__await||function(e){return this instanceof l?(this.v=e,this):new l(e)},c=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)}))}}},s=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,i){o[t]=e[t]?function(o){return(n=!n)?{value:l(e[t](o)),done:!1}:i?i(o):o}:i}},d=this&&this.__asyncGenerator||function(e,o,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,i=n.apply(e,o||[]),r=[];return t={},a("next"),a("throw"),a("return"),t[Symbol.asyncIterator]=function(){return this},t;function a(e){i[e]&&(t[e]=function(o){return new Promise((function(n,t){r.push([e,o,n,t])>1||c(e,o)}))})}function c(e,o){try{(n=i[e](o)).value instanceof l?Promise.resolve(n.value.v).then(s,d):p(r[0][2],n)}catch(e){p(r[0][3],e)}var n}function s(e){c("next",e)}function d(e){c("throw",e)}function p(e,o){e(o),r.shift(),r.length&&c(r[0][0],r[0][1])}},p=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.uploadUrl=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.defaulPublicKey=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=void 0;const u=n(7147),f=n(2037),y=n(1017),g=n(7778),v=n(7304),h=n(2885),m=p(n(9867)),b=n(1133),_=r(n(552));function w(e){return d(this,arguments,(function*(){const o=yield l((0,u.readdirSync)(e,{withFileTypes:!0}));for(const n of o){const o=(0,y.resolve)(e,n.name);!n.isDirectory()||n.name.startsWith(".")||n.name.startsWith("node_modules")||n.name.startsWith("dist")?yield yield l(o):yield l(yield*s(c(w(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.defaulPublicKey="-----BEGIN RSA PUBLIC KEY-----\n MIIBCgKCAQEA4pW9olT0FBXXivRCzd3xcImlWZrqkwcF2xTkX/FwXmj9eh9HkBLr\n sQmfsC+PJisRXIOGq6a0z3bsGq6jBpp3/Jr9jiaW5VuPGaKeMaZZBRvi/N5fIMG3\n hZXSOcy0IYg+E1Q7RkYO1xq5GLHseqG+PXvJsNe4R8R/Bmd/ngq0xh/cvcrHHpXw\n O0Aj9tfprlb+rHaVV79EkVRWYPidOLnK1n0EFHFJ1d/MyDIp10TEGm2xHpf/Brlb\n 1an8wXEuzoC0DgYaczgTjovwR+ewSGhSHJliQdM0Qa3o1iN87DldWtydImMsPjJ3\n DUwpsjAMRe5X8Et4+udFW2ciYnQo9H0CkwIDAQAB\n -----END RSA PUBLIC KEY-----",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w",o.createSupabaseClient=e=>(0,h.createClient)(o.hostSupa,o.supaAnon,{auth:{persistSession:!1},global:{headers:{capgkey:e}}}),o.regexSemver=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,o.checkKey=(e,n,t)=>a(void 0,void 0,void 0,(function*(){const{data:i,error:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:t}).single();i&&!r||v.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(r)}`)})),o.isGoodPlan=(e,o)=>a(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)=>a(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)=>a(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)=>a(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,t,i=!0)=>a(void 0,void 0,void 0,(function*(){(yield(0,o.isAllowedAction)(e,t))||(_.log.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),setTimeout((()=>{Promise.resolve().then((()=>r(n(6634)))).then((e=>{e.default(`${o.hostWeb}/dashboard/settings/plans`)})),v.program.error("")}),1e3));const a=yield(0,o.isTrial)(e,t);a>0&&i&&_.log.warn(`WARNING !!\nTrial expires in ${a} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e,o=`${(0,f.homedir)()}/.capgo`;return(0,u.existsSync)(o)&&(_.log.info(`Use global apy key ${o}`),e=(0,u.readFileSync)(o,"utf8").trim()),o=".capgo",!e&&(0,u.existsSync)(o)&&(_.log.info(`Use local apy key ${o}`),e=(0,u.readFileSync)(o,"utf8").trim()),e||v.program.error("Key not found, please login first"),e},o.findMainFile=()=>a(void 0,void 0,void 0,(function*(){var e,o,n,t;const i=/(main|index)\.(ts|js)$/;let r="";const a=process.cwd(),l=a.split("/").length;try{for(var s,d=!0,p=c(w(a));!(e=(s=yield p.next()).done);d=!0){t=s.value,d=!1;const e=t;if(e.split("/").length-l<=2&&i.test(e)){r=e,_.log.info(`Found main file here ${e}`);break}}}catch(e){o={error:e}}finally{try{d||e||!(n=p.return)||(yield n.call(p))}finally{if(o)throw o.error}}return r})),o.formatError=e=>e?`\n${m.default.render(e)}`:"",o.getConfig=()=>a(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,g.loadConfig)()}catch(e){v.program.error("No capacitor config file found, run `cap init` first")}return e})),o.updateOrCreateVersion=(e,o,n)=>a(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)})),o.uploadUrl=function(e,o,n){return a(this,void 0,void 0,(function*(){const t={app_id:o,bucket_id:n};try{return(yield e.functions.invoke("upload_link",{body:JSON.stringify(t)})).data.url}catch(e){_.log.error(`Cannot get upload url ${JSON.stringify(e)}`)}return""}))},o.updateOrCreateChannel=(e,o,n)=>a(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 b.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.convertAppName=e=>e.replace(/\./g,"--"),o.verifyUser=(e,n,t=["all"])=>a(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,n,t);const{data:i,error:r}=yield e.rpc("get_user_id",{apikey:n}).single(),a=(i||"").toString();return a&&!r||v.program.error(`Cannot verify user ${(0,o.formatError)(r)}`),a})),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")},2167:e=>{e.exports=require("axios")},7812:e=>{e.exports=require("ci-info")},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.13.5","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"engines":{"npm":">=7.0.0","node":">=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":"5.2.2","@capgo/find-package-manager":"^0.0.7","@clack/prompts":"^0.7.0","@supabase/supabase-js":"^2.32.0","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","axios":"^1.4.0","ci-info":"^3.8.0","cloudflared":"^0.4.0","commander":"11.0.0","console-table-printer":"^2.11.2","fs-extra":"11.1.1","get-latest-version":"^5.1.0","logsnag":"^0.1.8","mime":"^3.0.0","open":"^9.1.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","qrcode":"^1.5.3","semver":"^7.5.4"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/fs-extra":"^11.0.1","@types/mime":"^3.0.1","@types/node":"^20.4.9","@types/npmcli__ci-detect":"^2.0.0","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/qrcode":"^1.5.1","@types/semver":"^7.5.0","@typescript-eslint/eslint-plugin":"5.56.0","@typescript-eslint/parser":"5.56.0","eslint":"8.47.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^9.0.0","eslint-import-resolver-typescript":"3.6.0","eslint-plugin-import":"2.28.0","eslint-plugin-prettier":"^5.0.0","git-format-staged":"3.0.0","husky":"^8.0.3","nodemon":"3.0.1","pkg":"5.8.1","prettier":"3.0.2","ts-loader":"^9.4.4","ts-node":"^10.9.1","tsconfig-paths":"4.2.0","typescript":"5.1.6","webpack":"5.88.2","webpack-cli":"^5.1.4","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t].call(r.exports,r,r.exports,n),r.exports}(4999)})();
2
+ (()=>{"use strict";var e={9218:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((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:r}=yield e.rpc("exist_app",{appid:o,apikey:n}).single();return t!==i||r})),o.checkAppExistsAndHasPermissionErr=(e,n,r,a=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.checkAppExistsAndHasPermission)(e,n,r,a))&&i.program.error(`App ${n} does not exist or you don't have permission to access it`)})),o.newIconPath="assets/icon.png"},6824: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((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 l=n(7304),c=n(3847),s=r(n(552)),d=n(6545);o.checkVersionNotUsedInChannel=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){var r;const{data:a,error:c}=yield e.from("channels").select().eq("app_id",n).eq("created_by",t).eq("version",i.id);if(c&&l.program.error(`Cannot check Version ${n}@${i.name} ${(0,d.formatError)(c)}`),a&&a.length>0){if(s.intro(`❌ Version ${n}@${i.name} is used in ${a.length} channel`),yield s.confirm({message:"unlink it?"}))for(const t of a){const i=s.spinner();i.start(`Unlinking channel ${t.name}`);const{error:a}=yield e.from("channels").update({version:null===(r=yield(0,o.findUnknownVersion)(e,n))||void 0===r?void 0:r.id}).eq("id",t.id);a&&(i.stop(`Cannot update channel ${t.name} ${(0,d.formatError)(a)}`),process.exit(1)),i.stop(`✅ Channel ${t.name} unlinked`)}else l.program.error("unlink it first");s.outro(`Version unlinked from ${a.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 c.Table({title:"Channels",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,d.getHumanDate)(e.created_at),Public:e.public?"✅":"❌"})})),s.log.success(o.render())},o.getActiveChannels=(e,o,n)=>a(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&&l.program.error(`App ${o} not found in database ${(0,d.formatError)(i)} `),t}))},407:(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",r="sha256",a="base64",l=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[c,s]=o.split(":"),d=(0,t.privateDecrypt)({key:n,padding:l,oaepHash:r},Buffer.from(s,a)),p=Buffer.from(c,a),u=(0,t.createDecipheriv)(i,d,p);return u.setAutoPadding(!0),Buffer.concat([u.update(e),u.final()])},o.encryptSource=(e,o)=>{const n=(0,t.randomBytes)(16),c=(0,t.randomBytes)(16),s=(0,t.createCipheriv)(i,c,n);s.setAutoPadding(!0);const d=`${n.toString(a)}:${(0,t.publicEncrypt)({key:o,padding:l,oaepHash:r},c).toString(a)}`;return{encryptedData:Buffer.concat([s.update(e),s.final()]),ivSessionKey:d}},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"})}}},7863: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const l=n(7304),c=r(n(552)),s=n(6545);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>a(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&&l.program.error(`Cannot check Device override ${o}@${n.name} ${(0,s.formatError)(i)}`),t&&t.length>0)if(c.intro(`❌ Version ${o}@${n.name} is used in ${t.length} device override`),yield c.confirm({message:"unlink it?"}))for(const o of t){const n=c.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,s.formatError)(t)}`),process.exit(1)),n.stop(`✅ Device ${o.device_id} unlinked`)}else l.program.error("unlink it first")}))},1954:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(7304),r=n(6545);o.deleteFromStorage=(e,o,n,a,l)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${a.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${l} ${(0,r.formatError)(t)} `)}))},7482: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.checkLatest=void 0;const c=l(n(5362)),s=r(n(552)),d=l(n(4147));o.checkLatest=()=>a(void 0,void 0,void 0,(function*(){const e=yield(0,c.default)("@capgo/cli");e!==d.default.version&&s.log.warning(`🚨 You are using @capgo/cli@${d.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.`)}))},9656: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getVersionData=o.getChannelsVersion=o.getActiveAppVersions=o.displayBundles=o.deleteSpecificVersion=o.deleteAppVersion=void 0;const l=n(7304),c=n(3847),s=r(n(552)),d=n(6545),p=n(6824),u=n(7863),f=n(1954);o.deleteAppVersion=(e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const{error:i}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("deleted",!1).eq("user_id",n).eq("name",t);i&&l.program.error(`App Version ${o}@${t} not found in database '${(0,d.formatError)(i)}'`)})),o.deleteSpecificVersion=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){const r=yield(0,o.getVersionData)(e,n,t,i);yield(0,p.checkVersionNotUsedInChannel)(e,n,t,r),yield(0,u.checkVersionNotUsedInDeviceOverride)(e,n,r),yield(0,f.deleteFromStorage)(e,t,n,r,i),yield(0,o.deleteAppVersion)(e,n,t,i)})),o.displayBundles=e=>{const o=new c.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,d.getHumanDate)(e.created_at)},null!=e.keep?{Keep:e.keep}:{}))})),s.log.success(o.render())},o.getActiveAppVersions=(e,o,n)=>a(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return i&&l.program.error(`App ${o} not found in database ${(0,d.formatError)(i)} `),t})),o.getChannelsVersion=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.from("channels").select("version").eq("app_id",o);return t&&l.program.error(`App ${o} not found in database ${(0,d.formatError)(t)} `),n.map((e=>e.version))})),o.getVersionData=(e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const{data:i,error:r}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("name",t).eq("deleted",!1).single();return i&&!r||l.program.error(`App Version ${o}@${t} doesn't exist ${(0,d.formatError)(r)}`),i}))},7171: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addCommand=o.addApp=void 0;const l=n(6113),c=n(9011),s=n(7304),d=r(n(552)),p=n(4470),u=n(7482),f=n(9218),y=n(6545);o.addApp=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){var t,i,r;n&&d.intro("Adding"),yield(0,u.checkLatest)(),o.apikey=o.apikey||(0,y.findSavedKey)();const a=yield(0,y.getConfig)();e=e||(null===(t=null==a?void 0:a.app)||void 0===t?void 0:t.appId);const g=(0,y.useLogSnag)();o.apikey||(d.log.error("Missing API key, you need to provide a API key to upload your bundle"),s.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),s.program.error(""));const v=(0,y.createSupabaseClient)(o.apikey),h=yield(0,y.verifyUser)(v,o.apikey,["write","all"]);if(n)yield(0,f.checkAppExistsAndHasPermissionErr)(v,e,o.apikey,!1);else if(yield(0,f.checkAppExistsAndHasPermission)(v,e,o.apikey,!1))return!1;let m,b,{name:_,icon:w}=o;e=e||(null===(i=null==a?void 0:a.app)||void 0===i?void 0:i.appId),_=_||(null===(r=null==a?void 0:a.app)||void 0===r?void 0:r.appName)||"Unknown",w=w||"resources/icon.png",w&&_||(d.log.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project"),s.program.error("")),n&&d.log.info(`Adding ${e} to Capgo`),w&&(0,p.existsSync)(w)?(m=(0,p.readFileSync)(w),b=(0,c.getType)(w)||"image/png",d.log.warn(`Found app icon ${w}`)):(0,p.existsSync)(f.newIconPath)?(m=(0,p.readFileSync)(f.newIconPath),b=(0,c.getType)(f.newIconPath)||"image/png",d.log.warn(`Found app icon ${f.newIconPath}`)):d.log.warn(`Cannot find app icon in any of the following locations: ${w}, ${f.newIconPath}`);const{data:k,error:P}=yield v.rpc("exist_app_v2",{appid:e}).single();(k||P)&&(d.log.error(`App ${e} already exists ${(0,y.formatError)(P)}`),s.program.error(""));const C=`icon_${(0,l.randomUUID)()}`;let O="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(m&&b){const{error:o}=yield v.storage.from(`images/${h}/${e}`).upload(C,m,{contentType:b});o&&(d.log.error(`Could not add app ${(0,y.formatError)(o)}`),s.program.error(""));const{data:n}=yield v.storage.from(`images/${h}/${e}`).getPublicUrl(C);O=(null==n?void 0:n.publicUrl)||O}const{error:x}=yield v.from("apps").insert({icon_url:O,user_id:h,name:_,app_id:e});x&&(d.log.error(`Could not add app ${(0,y.formatError)(x)}`),s.program.error(""));const{error:S}=yield v.from("app_versions").insert([{user_id:h,deleted:!0,name:"unknown",app_id:e},{user_id:h,deleted:!0,name:"builtin",app_id:e}]);return S&&(d.log.error(`Could not add app ${(0,y.formatError)(S)}`),s.program.error("")),yield g.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":h,"app-id":e},notify:!1}).catch(),d.log.success(`App ${e} added to Capgo. ${n?"You can upload a bundle now":""}`),n&&(d.outro("Done ✅"),process.exit()),!0})),o.addCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.addApp)(e,n,!0)}))},7626: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.debugApp=o.waitLog=o.cancelCommand=o.markSnag=void 0;const l=r(n(552)),c=n(7304),s=n(9218),d=n(7482),p=n(6545),u=e=>new Promise((o=>{setTimeout(o,e)}));o.markSnag=(e,o,n,t,i="✅")=>a(void 0,void 0,void 0,(function*(){yield n.publish({channel:e,event:t,icon:i,tags:{"user-id":o},notify:!1}).catch()})),o.cancelCommand=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){l.isCancel(n)&&(yield(0,o.markSnag)(e,t,i,"canceled","🤷"),process.exit())})),o.waitLog=(e,n,t,i,r,c)=>a(void 0,void 0,void 0,(function*(){let a=!0,s=(new Date).toISOString();const d=`https://web.capgo.app/app/p/${(0,p.convertAppName)(t)}`;for(yield(0,o.markSnag)(e,r,i,"Use waitlog");a;){const p=n.from("stats").select("*").eq("app_id",t).order("created_at",{ascending:!1}).gte("created_at",s);c&&p.eq("device_id",c);const{data:f,error:y}=yield p.limit(1).single();if(f&&!y){if(l.log.info(`Device: ${f.device_id}`),"get"===f.action)l.log.info("Update Sent your your device, wait until event download complete"),yield(0,o.markSnag)(e,r,i,"done");else if(f.action.startsWith("download_")){const n=f.action.split("_")[1];"complete"===n?(l.log.info("Your bundle has been downloaded on your device, background the app now and open it again to see the update"),yield(0,o.markSnag)(e,r,i,"downloaded")):"fail"===n?(l.log.error("Your bundle has failed to download on your device."),l.log.error("Please check if you have network connection and try again")):l.log.info(`Your bundle is downloading ${n}% ...`)}else{if("set"===f.action)return l.log.info("Your bundle has been set on your device ❤️"),a=!1,yield(0,o.markSnag)(e,r,i,"set"),Promise.resolve(f);"NoChannelOrOverride"===f.action?l.log.error(`No default channel or override (channel/device) found, please create it here ${d}`):"needPlanUpgrade"===f.action?l.log.error("Your are out of quota, please upgrade your plan here https://web.capgo.app/dashboard/settings/plans"):"missingBundle"===f.action?l.log.error("Your bundle is missing, please check how you build your app "):"noNew"===f.action?l.log.error(`Your version in ${f.platform} is the same as your version uploaded, change it to see the update`):"disablePlatformIos"===f.action?l.log.error(`iOS is disabled in the default channel and your device is an iOS device ${d}`):"disablePlatformAndroid"===f.action?l.log.error(`Android is disabled in the default channel and your device is an Android device ${d}`):"disableAutoUpdateToMajor"===f.action?(l.log.error("Auto update to major version is disabled in the default channel."),l.log.error("Set your app to the same major version as the default channel")):"disableAutoUpdateUnderNative"===f.action?(l.log.error("Auto update under native version is disabled in the default channel."),l.log.error("Set your app to the same native version as the default channel.")):"disableDevBuild"===f.action?(l.log.error(`Dev build is disabled in the default channel. ${d}`),l.log.error("Set your channel to allow it if you wanna test your app")):"disableEmulator"===f.action?(l.log.error(`Emulator is disabled in the default channel. ${d}`),l.log.error("Set your channel to allow it if you wanna test your app")):"cannotGetBundle"===f.action?(l.log.error(`We cannot get your bundle from the default channel. ${d}`),l.log.error("Are you sure your default channel has a bundle set?")):"set_fail"===f.action?l.log.error(`Your bundle seems to be corrupted, try to download from ${d} to identify the issue`):"reset"===f.action?l.log.error("Your device has been reset to the builtin bundle, did you added notifyAppReady in your code?"):"update_fail"===f.action?(l.log.error("Your bundle has been installed but failed to call notifyAppReady"),l.log.error("Please check if you have network connection and try again")):"checksum_fail"===f.action&&l.log.error("Your bundle has failed to validate checksum, please check your code and send it again to Capgo")}s=(new Date).toISOString()}yield u(1e3)}return Promise.resolve()})),o.debugApp=(e,n)=>a(void 0,void 0,void 0,(function*(){var t;l.intro("Debug Live update in Capgo"),yield(0,d.checkLatest)(),n.apikey=n.apikey||(0,p.findSavedKey)();const i=yield(0,p.getConfig)();e=e||(null===(t=null==i?void 0:i.app)||void 0===t?void 0:t.appId);const r=n.device;n.apikey||(l.log.error("Missing API key, you need to provide an API key to delete your app"),c.program.error("")),e||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.program.error(""));const a=(0,p.createSupabaseClient)(n.apikey),u=(0,p.useLogSnag)(),f=yield(0,p.verifyUser)(a,n.apikey);l.log.info("Getting active bundle in Capgo"),yield(0,s.checkAppExistsAndHasPermissionErr)(a,e,n.apikey);const y=yield l.confirm({message:"Automatic check if update working in device ?"});yield(0,o.cancelCommand)("debug",y,f,u),y?(l.log.info(`Wait logs sent to Capgo from ${e} device, Put the app in background and open it again.`),l.log.info("Waiting..."),yield(0,o.waitLog)("debug",a,e,u,f,r),l.outro("Done ✅")):l.outro("Canceled ❌"),l.outro("Done ✅"),process.exit()}))},6626: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6545);o.deleteApp=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;c.intro("Deleting"),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);const i=(0,d.useLogSnag)();o.apikey||l.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||l.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const r=(0,d.createSupabaseClient)(o.apikey),a=yield(0,d.verifyUser)(r,o.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(r,e,o.apikey);const{error:p}=yield r.storage.from(`images/${a}`).remove([e]);p&&l.program.error(`Could not add app ${(0,d.formatError)(p)}`);const{error:u}=yield r.storage.from(`apps/${e}/${a}`).remove(["versions"]);u&&l.program.error(`Could not delete app version ${(0,d.formatError)(u)}`);const{error:f}=yield r.from("apps").delete().eq("app_id",e).eq("user_id",a);f&&l.program.error(`Could not delete app ${(0,d.formatError)(f)}`),yield i.publish({channel:"app",event:"App Deleted",icon:"🗑️",tags:{"user-id":a,"app-id":e},notify:!1}).catch(),c.log.success("App deleted in Capgo"),c.outro("Done ✅"),process.exit()}))},1628:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getInfo=void 0;const r=n(7147),a=n(1017),l=i(n(2037)),c=i(n(5362)),s=i(n(7176)),d=i(n(4147));o.getInfo=()=>t(void 0,void 0,void 0,(function*(){console.log(" 💊 Capgo Doctor 💊\n"),console.log(` OS: ${l.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,r.readFileSync)((0,a.join)(process.cwd(),"package.json"));return JSON.parse(e)})),o={"@capgo/cli":d.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 s.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,c.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()}))},8373: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=o.getActiveApps=void 0;const l=n(7304),c=n(3847),s=r(n(552)),d=n(9218),p=n(6545),u=n(7482);o.getActiveApps=(e,o)=>a(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&&l.program.error(`Apps not found in database ${(0,p.formatError)(t)} `),n})),o.listApp=(e,n)=>a(void 0,void 0,void 0,(function*(){var t;s.intro("List apps in Capgo"),yield(0,u.checkLatest)(),n.apikey=n.apikey||(0,p.findSavedKey)();const i=yield(0,p.getConfig)();e=e||(null===(t=null==i?void 0:i.app)||void 0===t?void 0:t.appId),n.apikey||(s.log.error("Missing API key, you need to provide an API key to delete your app"),l.program.error("")),e||(s.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const r=(0,p.createSupabaseClient)(n.apikey),a=yield(0,p.verifyUser)(r,n.apikey);s.log.info("Getting active bundle in Capgo"),yield(0,d.checkAppExistsAndHasPermissionErr)(r,e,n.apikey);const f=yield(0,o.getActiveApps)(r,a);s.log.info(`Active app in Capgo: ${null==f?void 0:f.length}`),(e=>{const o=new c.Table({title:"Apps",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,p.getHumanDate)(e.created_at)})})),s.log.success(o.render())})(f),s.outro("Done ✅"),process.exit()}))},5789: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setApp=void 0;const l=n(6113),c=n(9011),s=n(7304),d=r(n(552)),p=n(4470),u=n(9218),f=n(6545);o.setApp=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;d.intro("Set app"),o.apikey=o.apikey||(0,f.findSavedKey)();const t=yield(0,f.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||(d.log.error("Missing API key, you need to provide a API key to upload your bundle"),s.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),s.program.error(""));const i=(0,f.createSupabaseClient)(o.apikey),r=yield(0,f.verifyUser)(i,o.apikey,["write","all"]);yield(0,u.checkAppExistsAndHasPermissionErr)(i,e,o.apikey);const{name:a,icon:y,retention:g}=o;let v,h;g&&!Number.isNaN(Number(g))?(d.log.error("retention value must be a number"),s.program.error("")):g&&g<0&&(d.log.error("retention value cannot be less than 0"),s.program.error(""));const m=`icon_${(0,l.randomUUID)()}`;let b="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(y&&(0,p.existsSync)(y)?(v=(0,p.readFileSync)(y),h=(0,c.getType)(y)||"image/png",d.log.warn(`Found app icon ${y}`)):(0,p.existsSync)(u.newIconPath)?(v=(0,p.readFileSync)(u.newIconPath),h=(0,c.getType)(u.newIconPath)||"image/png",d.log.warn(`Found app icon ${u.newIconPath}`)):d.log.warn(`Cannot find app icon in any of the following locations: ${y}, ${u.newIconPath}`),v&&h){const{error:o}=yield i.storage.from(`images/${r}/${e}`).upload(m,v,{contentType:h});o&&(d.log.error(`Could not add app ${(0,f.formatError)(o)}`),s.program.error(""));const{data:n}=yield i.storage.from(`images/${r}/${e}`).getPublicUrl(m);b=(null==n?void 0:n.publicUrl)||b}const{error:_}=yield i.from("apps").update({icon_url:b,name:a,retention:g?24*g*60*60:void 0}).eq("app_id",e).eq("user_id",r);_&&(d.log.error(`Could not add app ${(0,f.formatError)(_)}`),s.program.error("")),d.outro("Done ✅"),process.exit()}))},4635: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=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 c=n(7304),s=r(n(552)),d=l(n(1121)),p=n(3422),u=n(6545),f=n(7482);o.watch=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){if(o.apikey=o.apikey||(0,u.findSavedKey)(),!o.apikey)return n&&c.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,f.checkLatest)(),s.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(),s.log.info("Init to tunnel");const{url:r,connections:a,stop:l}=(0,p.tunnel)({"--url":`localhost:${e}`});s.log.info("Connection to tunnel"),yield a[0],s.log.info("Get URL");const c=yield r;if(!c)throw new Error("No link found");s.log.info(`Tunnel ${c} connected to localhost:${e}`),yield t.from("app_live").upsert({id:i,url:c}).throwOnError();const f=yield d.default.toString(c,{type:"terminal",small:!0});s.log.info(f),yield s.confirm({message:"When done say yes to close tunnel"}),yield l(),yield t.from("app_live").delete().eq("id",i).throwOnError(),s.log.info("Tunnel closed")}catch(e){console.error("Error",e),process.exit(1)}return n&&(s.outro("Done ✅"),process.exit()),!0})),o.watchApp=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.watch)(e,n,!0)}))},2393: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=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)}))}}},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupBundle=void 0;const s=n(7304),d=c(n(1505)),p=r(n(552)),u=c(n(1616)),f=n(6545),y=n(9656),g=n(9218),v=n(7482),h=(0,u.default)();o.cleanupBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;p.intro("Cleanup versions in Capgo"),yield(0,v.checkLatest)();const t=o.apikey||(0,f.findSavedKey)(),{bundle:i,keep:r=4}=o,c=o.force||!1,u=yield(0,f.getConfig)();e=e||(null===(n=null==u?void 0:u.app)||void 0===n?void 0:n.appId),t||s.program.error("Missing API key, you need to provide an API key to delete your app"),e||s.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const m=(0,f.createSupabaseClient)(t),b=yield(0,f.verifyUser)(m,t);yield(0,g.checkAppExistsAndHasPermissionErr)(m,e,t),p.log.info("Querying all available versions in Capgo");let _=yield(0,y.getActiveAppVersions)(m,e,b);const w=yield(0,y.getChannelsVersion)(m,e);if(p.log.info(`Total active versions in Capgo: ${null==_?void 0:_.length}`),0===(null==_?void 0:_.length))return void p.log.error("No versions found, aborting cleanup");if(i){const e=`${d.default.inc(i,"major")}`;p.log.info(`Querying available versions in Capgo between ${i} and ${e}`),_=((e,o,n)=>{const t=[];return null==e||e.forEach((e=>{d.default.gte(e.name,o)&&d.default.lt(e.name,`${n}`)&&t.push(e)})),t})(_,i,e),p.log.info(`Active versions in Capgo between ${i} and ${e}: ${null==_?void 0:_.length}`)}const k=[];let P=0;if(_.forEach((e=>{const o=w.find((o=>o===e.id));P<r||o?(e.keep=o?"✅ (Linked to channel)":"✅",P+=1):(e.keep="❌",k.push(e))})),0!==k.length){if((0,y.displayBundles)(_),!c&&"yes"!==h("Do you want to continue removing the versions specified? Type yes to confirm: "))return void p.log.warn("Not confirmed, aborting removal...");p.log.success("You have confirmed removal, removing versions now"),yield((e,o,n,t)=>{var i,r,c;return a(void 0,void 0,void 0,(function*(){var a,s,d,u;try{for(i=!0,r=l(e);!(a=(c=yield r.next()).done);i=!0){u=c.value,i=!1;const e=u;p.log.warn(`Removing ${e.name} created on ${(0,f.getHumanDate)(e.created_at)}`),yield(0,y.deleteSpecificVersion)(o,n,t,e.name)}}catch(e){s={error:e}}finally{try{i||a||!(d=r.return)||(yield d.call(r))}finally{if(s)throw s.error}}}))})(k,m,e,b),p.outro("Done ✅"),process.exit()}else p.log.warn("Nothing to be removed, aborting removal...")}))},7978: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const l=n(7147),c=n(7304),s=r(n(552)),d=n(407),p=n(6545),u=n(7482);o.decryptZip=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i,r;s.intro("Decrypt zip file"),yield(0,u.checkLatest)(),(0,l.existsSync)(e)||c.program.error(`Zip not found at the path ${e}`);const a=yield(0,p.getConfig)(),{extConfig:f}=a.app;n.key||(0,l.existsSync)(p.baseKey)||(null===(i=null===(t=f.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===i?void 0:i.privateKey)||c.program.error(`Private Key not found at the path ${p.baseKey} or in ${a.app.extConfigFilePath}`);const y=n.key||p.baseKey;let{privateKey:g}=n.keyData||(null===(r=null==f?void 0:f.plugins)||void 0===r?void 0:r.CapacitorUpdater)||"";(0,l.existsSync)(y)||g?(0,l.existsSync)(y)&&(g=(0,l.readFileSync)(y).toString()):c.program.error(`Cannot find public key ${y} or as keyData option or in ${a.app.extConfigFilePath}`);const v=(0,l.readFileSync)(e),h=(0,d.decryptSource)(v,o,g);(0,l.writeFileSync)(`${e}_decrypted.zip`,h),s.outro(`Decrypted zip file at ${e}_decrypted.zip`),process.exit()}))},3930: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteBundle=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6545),p=n(9656);o.deleteBundle=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i;c.intro("Delete bundle"),n.apikey=n.apikey||(0,d.findSavedKey)();const r=yield(0,d.getConfig)();o=o||(null===(t=null==r?void 0:r.app)||void 0===t?void 0:t.appId),n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const a=(0,d.createSupabaseClient)(n.apikey),u=yield(0,d.verifyUser)(a,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(a,o,n.apikey);const f=n.apikey||(0,d.findSavedKey)();o=o||(null===(i=null==r?void 0:r.app)||void 0===i?void 0:i.appId),f||(c.log.error("Missing API key, you need to provide an API key to delete your app"),l.program.error("")),e||(c.log.error("Missing argument, you need to provide a bundleId, or be in a capacitor project"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error("")),c.log.info(`Deleting bundle ${o}@${e} from Capgo`),yield(0,p.deleteSpecificVersion)(a,o,u,e),c.log.success(`Bundle ${o}@${e} deleted in Capgo`),c.outro("Done"),process.exit()}))},3333: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const c=n(7147),s=n(7304),d=l(n(7812)),p=r(n(552)),u=n(7482),f=n(407),y=n(6545);o.encryptZip=(e,o)=>a(void 0,void 0,void 0,(function*(){p.intro("Encryption"),yield(0,u.checkLatest)(),(0,c.existsSync)(e)||(p.log.error(`Error: Zip not found at the path ${e}`),s.program.error(""));const n=o.key||y.baseKeyPub;let t=o.keyData||"";(0,c.existsSync)(n)||t?(0,c.existsSync)(n)&&(t=(0,c.readFileSync)(n).toString()):(p.log.warning(`Cannot find public key ${n} or as keyData option`),d.default.isCI&&(p.log.error("Error: Missing public key"),s.program.error("")),(yield p.confirm({message:"Do you want to use our public key ?"}))||(p.log.error("Error: Missing public key"),s.program.error("")),t=y.defaulPublicKey);const i=(0,c.readFileSync)(e),r=(0,f.encryptSource)(i,t);p.log.success(`ivSessionKey: ${r.ivSessionKey}`),(0,c.writeFileSync)(`${e}_encrypted.zip`,r.encryptedData),p.log.success(`Encrypted zip saved at ${e}_encrypted.zip`),p.outro("Done ✅"),process.exit()}))},2083: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listBundle=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(9656),p=n(6545),u=n(7482);o.listBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;c.intro("List bundles"),yield(0,u.checkLatest)(),o.apikey=o.apikey||(0,p.findSavedKey)();const t=yield(0,p.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),e||(c.log.error("Missing argument, you need to provide a appid, or be in a capacitor project"),l.program.error(""));const i=(0,p.createSupabaseClient)(o.apikey),r=yield(0,p.verifyUser)(i,o.apikey);c.log.info(`Querying available versions of: ${e} in Capgo`),yield(0,s.checkAppExistsAndHasPermissionErr)(i,e,o.apikey);const a=yield(0,d.getActiveAppVersions)(i,e,r);c.log.info(`Active versions in Capgo: ${null==a?void 0:a.length}`),(0,d.displayBundles)(a),c.outro("Done ✅"),process.exit()}))},2510: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=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 c=n(6113),s=n(7147),d=l(n(3844)),p=n(7304),u=r(n(552)),f=n(5906),y=l(n(7812)),g=l(n(2167)),v=n(7482),h=n(9218),m=n(407),b=n(6545);o.uploadBundle=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){var t,i,r,a;u.intro("Uploading"),yield(0,v.checkLatest)();let{bundle:l,path:_,channel:w}=o;const{external:k,key:P=!1,displayIvSession:C}=o,O=o.apikey||(0,b.findSavedKey)(),x=(0,b.useLogSnag)();w=w||"dev";const S=yield(0,b.getConfig)();e=e||(null===(t=null==S?void 0:S.app)||void 0===t?void 0:t.appId);const $=(0,c.randomUUID)().split("-")[0];l=l||(null===(r=null===(i=null==S?void 0:S.app)||void 0===i?void 0:i.package)||void 0===r?void 0:r.version)||`0.0.1-beta.${$}`,b.regexSemver.test(l)||(u.log.error(`Your bundle name ${l}, is not valid it should follow semver convention : https://semver.org/`),p.program.error("")),_=_||(null===(a=null==S?void 0:S.app)||void 0===a?void 0:a.webDir),O||(u.log.error("Missing API key, you need to provide a API key to upload your bundle"),p.program.error("")),e&&l&&_||(u.log.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),p.program.error("")),(0,s.existsSync)(_)||(u.log.error(`Path ${_} does not exist, build your app first, or provide a valid path`),p.program.error("")),u.log.info(`Upload ${e}@${l} started from path "${_}" to Capgo cloud`);const j=(0,b.createSupabaseClient)(O),A=yield(0,b.verifyUser)(j,O,["write","all","upload"]);yield(0,b.checkPlanValid)(j,A,!1),yield(0,h.checkAppExistsAndHasPermissionErr)(j,e,O);const{data:M,error:I}=yield j.rpc("exist_app_versions",{apikey:O,name_version:l,appid:e}).single();(M||I)&&(u.log.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,b.formatError)(I)}`),p.program.error(""));const{data:D,error:E}=yield j.rpc("is_trial",{userid:A}).single();(D&&D>0||E)&&(u.log.warn(`WARNING !!\nTrial expires in ${D} days`),u.log.warn(`Upgrade here: ${b.hostWeb}/dashboard/settings/plans`));const{data:U,error:q}=yield j.rpc("exist_app",{appid:e,apikey:O}).single();U&&!q||(u.log.error(`Cannot find app ${e} in your account ${(0,b.formatError)(q)}`),p.program.error(""));const{data:K,error:B}=yield j.rpc("exist_app_versions",{appid:e,apikey:O,name_version:l}).single();(K||B)&&(u.log.error(`Version already exists ${(0,b.formatError)(B)}`),p.program.error(""));const L=`${l.replace(/[^a-zA-Z0-9-_.!*'()]/g,"__")}.zip`;let N,V="",F=null;if(k)k&&!k.startsWith("https://")?(u.log.error(`External link should should start with "https://" current is "${k}"`),p.program.error("")):yield x.publish({channel:"app",event:"App external",icon:"📤",tags:{"user-id":A,"app-id":e},notify:!1}).catch();else{const o=new d.default;o.addLocalFolder(_),F=o.toBuffer();const n=u.spinner();if(n.start("Calculating checksum"),V=yield(0,f.checksum)(F,"crc32"),n.stop(`Checksum: ${V}`),P||(0,s.existsSync)(b.baseKeyPub)){const o="string"==typeof P?P:b.baseKeyPub;let n="";(0,s.existsSync)(o)||(u.log.error(`Cannot find public key ${o}`),y.default.isCI&&p.program.error(""),(yield u.confirm({message:"Do you want to use our public key ?"}))||(u.log.error("Error: Missing public key"),p.program.error("")),n=b.defaulPublicKey),yield x.publish({channel:"app",event:"App encryption",icon:"🔑",tags:{"user-id":A,"app-id":e},notify:!1}).catch(),n=(0,s.readFileSync)(o).toString(),u.log.info("Encrypting your bundle");const t=(0,m.encryptSource)(F,n);N=t.ivSessionKey,C&&u.log.info(`Your Iv Session key is ${N},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),F=t.encryptedData}const t=Math.floor(F.byteLength/1024/1024);t>20&&(u.log.warn(`WARNING !!\nThe app size is ${t} Mb, this may take a while to download for users\n`),u.log.info("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield x.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":A,"app-id":e},notify:!1}).catch())}const z={bucket_id:k?void 0:L,user_id:A,name:l,app_id:e,session_key:N,external_url:k,storage_provider:k?"external":"r2-direct",checksum:V},{error:T}=yield(0,b.updateOrCreateVersion)(j,z,O);if(T&&(u.log.error(`Cannot add bundle ${(0,b.formatError)(T)}`),p.program.error("")),!k&&F){const o=u.spinner();o.start("Uploading Bundle");const n=yield(0,b.uploadUrl)(j,e,L);n||(u.log.error("Cannot get upload url"),p.program.error("")),yield(0,g.default)({method:"put",url:n,data:F,headers:{"Content-Type":"application/octet-stream","Cache-Control":"public, max-age=456789, immutable","x-amz-meta-crc32":V}}),z.storage_provider="r2";const{error:t}=yield(0,b.updateOrCreateVersion)(j,z,O);t&&(u.log.error(`Cannot update bundle ${(0,b.formatError)(T)}`),p.program.error("")),o.stop("Bundle Uploaded 💪")}const{data:R}=yield j.rpc("get_app_versions",{apikey:O,name_version:l,appid:e}).single();if(R){const{error:o,data:n}=yield(0,b.updateOrCreateChannel)(j,{name:w,app_id:e,created_by:A,version:R},O);o&&(u.log.error('Cannot set channel, the upload key is not allowed to do that, use the "all" for this.'),p.program.error(""));const t=(0,b.convertAppName)(e);(null==n?void 0:n.public)?u.log.info("Your update is now available in your public channel 🎉"):(null==n?void 0:n.id)&&u.log.info(`Link device to this bundle to try it: ${b.hostWeb}/app/p/${t}/channel/${n.id}`)}else u.log.warn("Cannot set bundle with upload key, use key with more rights for that"),p.program.error("");return yield x.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":A,"app-id":e},notify:!1}).catch(),n&&(u.outro("Time to share your update to the world 🌍"),process.exit()),!0})),o.uploadCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){try{yield(0,o.uploadBundle)(e,n,!0)}catch(e){u.log.error(JSON.stringify(e)),p.program.error("")}})),o.uploadDeprecatedCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){u.log.warn('⚠️ This command is deprecated, use "npx @capgo/cli bundle upload" instead ⚠️');try{yield(0,o.uploadBundle)(e,n,!0)}catch(e){u.log.error(JSON.stringify(e)),p.program.error("")}}))},7103: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.zipBundle=void 0;const c=n(6113),s=n(7147),d=l(n(3844)),p=n(7304),u=r(n(552)),f=n(5906),y=n(7482),g=n(6545);o.zipBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n,t,i,r;yield(0,y.checkLatest)();let{bundle:a,path:l}=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];a=a||(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}`,u.intro(`Zipping ${e}@${a}`),g.regexSemver.test(a)||(u.log.error(`Your bundle name ${a}, is not valid it should follow semver convention : https://semver.org/`),p.program.error("")),l=l||(null===(r=null==h?void 0:h.app)||void 0===r?void 0:r.webDir),e&&a&&l||(u.log.error("Missing argument, you need to provide a appId and a bundle and a path, or be in a capacitor project"),p.program.error("")),u.log.info(`Started from path "${l}"`);const b=new d.default;b.addLocalFolder(l);const _=b.toBuffer();u.log.info(`Zipped ${_.byteLength} bytes`);const w=u.spinner();w.start("Calculating checksum");const k=yield(0,f.checksum)(_,"crc32");w.stop(`Checksum: ${k}`);const P=Math.floor(_.byteLength/1024/1024);P>20&&(u.log.warn(`WARNING !!\nThe app size is ${P} Mb, this may take a while to download for users\n`),u.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=u.spinner();C.start(`Saving to ${e}_${a}.zip`),(0,s.writeFileSync)(`${e}_${a}.zip`,_),C.stop(`Saved to ${e}_${a}.zip`),yield v.publish({channel:"app",event:"App zip",icon:"⏫",tags:{"app-id":e},notify:!1}).catch(),u.outro("Done ✅"),process.exit()}))},4402: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addChannelCommand=o.addChannel=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.addChannel=(e,o,n,t=!0)=>a(void 0,void 0,void 0,(function*(){var i;c.intro("Create channel"),n.apikey=n.apikey||(0,p.findSavedKey)();const r=yield(0,p.getConfig)();o=o||(null===(i=null==r?void 0:r.app)||void 0===i?void 0:i.appId);const a=(0,p.useLogSnag)();n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const u=(0,p.createSupabaseClient)(n.apikey),f=yield(0,p.verifyUser)(u,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(u,o,n.apikey),c.log.info(`Creating channel ${o}#${e} to Capgo`);try{const n=yield(0,d.findUnknownVersion)(u,o);n||(c.log.error("Cannot find default version for channel creation, please contact Capgo support 🤨"),l.program.error("")),yield(0,d.createChannel)(u,{name:e,app_id:o,version:n.id,created_by:f}),c.log.success("Channel created ✅"),yield a.publish({channel:"channel",event:"Create channel",icon:"✅",tags:{"user-id":f,"app-id":o,channel:e},notify:!1}).catch()}catch(e){return c.log.error("Cannot create Channel 🙀"),!1}return t&&(c.outro("Done ✅"),process.exit()),!0})),o.addChannelCommand=(e,n,t)=>a(void 0,void 0,void 0,(function*(){(0,o.addChannel)(e,n,t,!0)}))},7422: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteChannel=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.deleteChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t;c.intro("Delete channel"),n.apikey=n.apikey||(0,p.findSavedKey)();const i=yield(0,p.getConfig)();o=o||(null===(t=null==i?void 0:i.app)||void 0===t?void 0:t.appId);const r=(0,p.useLogSnag)();n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const a=(0,p.createSupabaseClient)(n.apikey),u=yield(0,p.verifyUser)(a,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(a,o,n.apikey),c.log.info(`Deleting channel ${o}#${e} from Capgo`);try{yield(0,d.delChannel)(a,e,o,u),c.log.success("Channel deleted"),yield r.publish({channel:"channel",event:"Delete channel",icon:"✅",tags:{"user-id":u,"app-id":o,channel:e},notify:!1}).catch()}catch(e){c.log.error("Cannot delete Channel 🙀")}c.outro("Done ✅"),process.exit()}))},2667: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listChannels=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.listChannels=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;c.intro("List channels"),o.apikey=o.apikey||(0,p.findSavedKey)();const t=yield(0,p.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId);const i=(0,p.useLogSnag)();o.apikey||c.log.error("Missing API key, you need to provide a API key to upload your bundle"),e||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const r=(0,p.createSupabaseClient)(o.apikey),a=yield(0,p.verifyUser)(r,o.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(r,e,o.apikey),c.log.info("Querying available channels in Capgo"),yield(0,s.checkAppExistsAndHasPermissionErr)(r,e,o.apikey);const u=yield(0,d.getActiveChannels)(r,e,a);c.log.info(`Active channels in Capgo: ${null==u?void 0:u.length}`),(0,d.displayChannels)(u),yield i.publish({channel:"channel",event:"List channel",icon:"✅",tags:{"user-id":a,"app-id":e},notify:!1}).catch(),c.outro("Done ✅"),process.exit()}))},593: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6545);o.setChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i,r;c.intro("Set channel"),n.apikey=n.apikey||(0,d.findSavedKey)();const a=yield(0,d.getConfig)();o=o||(null===(t=null==a?void 0:a.app)||void 0===t?void 0:t.appId);const p=(0,d.useLogSnag)();n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const u=(0,d.createSupabaseClient)(n.apikey),f=yield(0,d.verifyUser)(u,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(u,o,n.apikey);const{bundle:y,latest:g,downgrade:v,upgrade:h,ios:m,android:b,selfAssign:_,state:w}=n;e||(c.log.error("Missing argument, you need to provide a channel"),l.program.error("")),g&&y&&(c.log.error("Cannot set latest and bundle at the same time"),l.program.error("")),null==y&&null==w&&null==g&&null==v&&null==h&&null==m&&null==b&&null==_&&(c.log.error("Missing argument, you need to provide a option to set"),l.program.error(""));try{yield(0,d.checkPlanValid)(u,f),yield(0,s.checkAppExistsAndHasPermissionErr)(u,o,n.apikey);const t={created_by:f,app_id:o,name:e,version:void 0},k=g?null===(r=null===(i=null==a?void 0:a.app)||void 0===i?void 0:i.package)||void 0===r?void 0:r.version:y;if(null!=k){const{data:n,error:i}=yield u.from("app_versions").select().eq("app_id",o).eq("name",k).eq("user_id",f).eq("deleted",!1).single();!i&&n||(c.log.error(`Cannot find version ${k}`),l.program.error("")),c.log.info(`Set ${o} channel: ${e} to @${k}`),t.version=n.id}null!=w&&("public"!==w&&"private"!==w||c.log.info(`Set ${o} channel: ${e} to public or private is deprecated, use default or normal instead`),c.log.info(`Set ${o} channel: ${e} to ${"public"===w||"default"===w?"default":"normal"}`),t.public="public"===w||"default"===w),null!=v&&(c.log.info(`Set ${o} channel: ${e} to ${v?"allow":"disallow"} downgrade`),t.disableAutoUpdateUnderNative=!v),null!=h&&(c.log.info(`Set ${o} channel: ${e} to ${h?"allow":"disallow"} upgrade`),t.disableAutoUpdateToMajor=!h),null!=m&&(c.log.info(`Set ${o} channel: ${e} to ${m?"allow":"disallow"} ios update`),t.ios=!!m),null!=b&&(c.log.info(`Set ${o} channel: ${e} to ${b?"allow":"disallow"} android update`),t.android=!!b),null!=_&&(c.log.info(`Set ${o} channel: ${e} to ${_?"allow":"disallow"} self assign to this channel`),t.allow_device_self_set=!!_);try{const{error:e}=yield(0,d.updateOrCreateChannel)(u,t,n.apikey);e&&(c.log.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.'),l.program.error(""))}catch(e){c.log.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.'),l.program.error("")}yield p.publish({channel:"channel",event:"Set channel",icon:"✅",tags:{"user-id":f,"app-id":o},notify:!1}).catch()}catch(e){c.log.error(`Unknow error ${(0,d.formatError)(e)}`),l.program.error("")}c.outro("Done ✅"),process.exit()}))},4999: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),r=n(7103),a=n(6104),l=n(2083),c=n(7978),s=n(3333),d=n(7171),p=n(1628),u=n(6122),f=n(3930),y=n(593),g=n(2510),v=t(n(4147)),h=n(5041),m=n(8373),b=n(2393),_=n(4402),w=n(7422),k=n(2667),P=n(5789),C=n(6626),O=n(4635),x=n(7626);i.program.name(v.default.name).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(a.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(d.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("debug [appId]").alias("d").description("Listen for live updates event in Capgo Cloud to debug your app").option("-a, --apikey <apikey>","apikey to link to your account").option("-d, --device <device>","the specific device to debug").action(x.debugApp),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(O.watchApp),S.command("set [appId]").alias("s").description("Set an app in Capgo Cloud").action(P.setApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account").option("-r, --retention <retention>","retention period of app bundle in days");const $=i.program.command("bundle").description("Manage bundle");$.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"),$.command("delete [bundleId] [appId]").alias("d").description("Delete a bundle in Capgo Cloud").action(f.deleteBundle).option("-a, --apikey <apikey>","apikey to link to your account"),$.command("list [appId]").alias("l").description("List bundle in Capgo Cloud").action(l.listBundle).option("-a, --apikey <apikey>","apikey to link to your account"),$.command("unlink [appId]").alias("u").description("Unlink a bundle in Capgo Cloud").action(l.listBundle).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the bundle to unlink"),$.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"),$.command("decrypt [zipPath] [sessionKey]").alias("l").description("Decrypt a signed zip bundle").action(c.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),$.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(s.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),$.command("zip [appId]").description("Zip a bundle").action(r.zipBundle).option("-p, --path <path>","path of the folder to upload").option("-b, --bundle <bundle>","bundle version number to name the zip file");const j=i.program.command("channel").description("Manage channel");j.command("add [channelId] [appId]").alias("a").description("Create channel").action(_.addChannelCommand).option("-d, --default","set the channel as default"),j.command("delete [channelId] [appId]").alias("d").description("Delete channel").action(w.deleteChannel),j.command("list [appId]").alias("l").description("List channel").action(k.listChannels),j.command("set [channelId] [appId]").alias("s").description("Set channel").action(y.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 A=i.program.command("key").description("Manage key");A.command("save").description("Save base64 signing key in capacitor config, usefull for CI").action(u.saveKeyCommand).option("-f, --force","force generate a new one").option("--key","key path to save in capacitor config").option("--key-data","key data to save in capacitor config"),A.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()},6104: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.initApp=void 0;const l=n(7147),c=n(2081),s=n(6301),d=r(n(552)),p=n(7626),u=n(6122),f=n(4402),y=n(2510),g=n(5041),v=n(7171),h=n(7482),m=n(6545),b="import { CapacitorUpdater } from '@capgo/capacitor-updater'",_="CapacitorUpdater.notifyAppReady()",w=/import.*from.*/g,k="production",P={stdio:"pipe"},C=(e,o,n)=>a(void 0,void 0,void 0,(function*(){d.isCancel(e)&&(yield(0,p.markSnag)("onboarding-v2",o,n,"canceled","🤷"),process.exit())})),O=(e,o,n)=>a(void 0,void 0,void 0,(function*(){return(0,p.markSnag)("onboarding-v2",e,o,`onboarding-step-${n}`)}));o.initApp=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t;d.intro("Capgo onboarding 🛫"),yield(0,h.checkLatest)();const i=(0,m.useLogSnag)(),r=yield(0,m.getConfig)();o=o||(null===(t=null==r?void 0:r.app)||void 0===t?void 0:t.appId),e=e||(0,m.findSavedKey)();const x=d.spinner();x.start("Running: npx @capgo/cli@latest login ***"),(yield(0,g.login)(e,n,!1))?x.stop("Login Done ✅"):x.stop("Login already done ✅");const S=(0,m.createSupabaseClient)(e),$=yield(0,m.verifyUser)(S,e,["upload","all","read","write"]);yield O($,i,1),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Add ${n} in Capgo?`});if(yield C(i,e,o),i){const e=d.spinner();e.start(`Running: npx @capgo/cli@latest app add ${n}`),(yield(0,v.addApp)(n,t,!1))?e.stop("App add Done ✅"):e.stop("App already add ✅")}else d.log.info(`Run yourself "npx @capgo/cli@latest app add ${n}"`);yield O(e,o,2)})))($,i,o,n),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Create default channel ${k} for ${t} in Capgo?`});if(yield C(i,e,o),i){const e=d.spinner();e.start(`Running: npx @capgo/cli@latest channel add ${k} ${t} --default`),(yield(0,f.addChannel)(k,t,{default:!0,apikey:n},!1))?e.stop("Channel add Done ✅"):e.stop("Channel already added ✅")}else d.log.info(`Run yourself "npx @capgo/cli@latest channel add ${k} ${t} --default"`);yield O(e,o,3)})))($,i,e,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:`Automatic Install "@capgo/capacitor-updater" dependency in ${t}?`});if(yield C(n,e,o),n){const e=d.spinner();e.start("Checking if @capgo/capacitor-updater is installed");const o=JSON.parse((0,l.readFileSync)("package.json").toString()),n=(0,s.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,c.execSync)(`${n} ${t} @capgo/capacitor-updater@latest`,P),e.stop("Install Done ✅"))}else d.log.info('Run yourself "npm i @capgo/capacitor-updater@latest"');yield O(e,o,4)})))($,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:`Automatic Add "${_}" code and import in ${t}?`});if(yield C(n,e,o),n){const n=d.spinner();n.start("Adding @capacitor-updater to your main file");const t=yield(0,m.findMainFile)();t||(n.stop("No main.ts, main.js, index.ts or index.js file found, You need to add @capgo/capacitor-updater manually"),process.exit());const i=(0,l.readFileSync)(t).toString(),r=i.match(w),a=null==r?void 0:r.pop();if(a||(n.stop("Cannot find import line in main file, use manual installation: https://capgo.app/docs/plugin/installation/"),process.exit()),i.includes(_))n.stop(`Code already added to ${t} ✅`);else{const e=i.replace(a,`${a}\n${b};\n\n${_};\n`);(0,l.writeFileSync)(t,e),n.stop(`Code added to ${t} ✅`)}yield O(e,o,5)}else d.log.info(`Add to your main file the following code:\n\n${b};\n\n${_};\n`)})))($,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:`Automatic configure end-to-end encryption in ${t} updates?`});if(yield C(n,e,o),n){const n=d.spinner();n.start("Running: npx @capgo/cli@latest key create"),(yield(0,u.createKey)({},!1))?n.stop("key created 🔑"):(n.stop("Cannot create key ❌"),process.exit(1)),(0,p.markSnag)("onboarding-v2",e,o,"Use encryption")}yield O(e,o,6)})))($,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){var n;const i=yield d.confirm({message:`Automatic build ${t} with "npm run build" ?`});if(yield C(i,e,o),i){const e=d.spinner();e.start("Running: npm run build && npx cap sync"),(null===(n=JSON.parse((0,l.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,c.execSync)("npm run build && npx cap sync",P),e.stop("Build & Sync Done ✅")}else d.log.info("Build yourself with command: npm run build && npx cap sync");yield O(e,o,7)})))($,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Automatic upload ${t} bundle to Capgo?`});if(yield C(i,e,o),i){const e=d.spinner();e.start("Running: npx @capgo/cli@latest bundle upload"),(yield(0,y.uploadBundle)(t,{channel:k,apikey:n},!1))?e.stop("Upload Done ✅"):(e.stop("Upload failed ❌"),process.exit())}else d.log.info("Upload yourself with command: npx @capgo/cli@latest bundle upload");yield O(e,o,8)})))($,i,e,o),yield((e,o)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:"Run in device now ?"});if(yield C(n,e,o),n){const e=yield d.select({message:"Pick a platform to run your app",options:[{value:"ios",label:"IOS"},{value:"android",label:"Android"}]});d.isCancel(e)&&process.exit();const o=e,n=d.spinner();n.start(`Running: npx cap run ${o}`),yield(0,c.spawnSync)("npx",["cap","run",o],{stdio:"inherit"}),n.stop("Started Done ✅")}else d.log.info("Run yourself with command: npx cap run <ios|android>");yield O(e,o,9)})))($,i),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:"Automatic check if update working in device ?"});if(yield C(i,e,o),i)d.log.info(`Wait logs sent to Capgo from ${t} device, Put the app in background and open it again.`),d.log.info("Waiting..."),yield(0,p.waitLog)("onboarding-v2",n,t,o,e);else{const e=(0,m.convertAppName)(t);d.log.info(`Check logs in https://web.capgo.app/app/p/${e}/logs to see if update works.`)}yield O(e,o,10)})))($,i,S,o),yield O($,i,0),d.log.info("Welcome onboard ✈️!"),d.log.info("Your Capgo update system is setup"),d.log.info("Next time use `npx @capgo/cli@latest bundle upload` to only upload your bundle"),d.outro("Bye 👋"),process.exit()}))},6122: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.createKeyCommand=o.createKey=o.saveKeyCommand=o.saveKey=void 0;const l=n(7147),c=n(7304),s=n(7778),d=r(n(552)),p=n(407),u=n(6545),f=n(7482);o.saveKey=(e,o=!0)=>a(void 0,void 0,void 0,(function*(){(0,l.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),c.program.error(""));const n=yield(0,u.getConfig)(),{extConfig:t}=n.app,i=e.key||u.baseKey;let r=e.keyData||"";if((0,l.existsSync)(i)||r)(0,l.existsSync)(i)&&(r=(0,l.readFileSync)(i).toString());else{if(!o)return!1;d.log.error(`Cannot find public key ${i} or as keyData option or in ${n.app.extConfigFilePath}`),c.program.error("")}return t&&(t.plugins||(t.plugins={}),t.plugins.CapacitorUpdater||(t.plugins.CapacitorUpdater={}),t.plugins.CapacitorUpdater.privateKey=r,(0,s.writeConfig)(t,n.app.extConfigFilePath)),o&&(d.log.success(`private key saved into ${n.app.extConfigFilePath} file in local directory`),d.log.success("your app will decode the zip archive with this key")),!0})),o.saveKeyCommand=e=>a(void 0,void 0,void 0,(function*(){d.intro("Save keys 🔑"),yield(0,f.checkLatest)(),yield(0,o.saveKey)(e)})),o.createKey=(e,o=!0)=>a(void 0,void 0,void 0,(function*(){o&&d.intro("Create keys 🔑"),(0,l.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),c.program.error(""));const{publicKey:n,privateKey:t}=(0,p.createRSA)();if((0,l.existsSync)(u.baseKeyPub)&&!e.force){if(!o)return!1;d.log.error("Public Key already exists, use --force to overwrite"),c.program.error("")}if((0,l.writeFileSync)(u.baseKeyPub,n),(0,l.existsSync)(u.baseKey)&&!e.force){if(!o)return!1;d.log.error("Private Key already exists, use --force to overwrite"),c.program.error("")}(0,l.writeFileSync)(u.baseKey,t);const i=yield(0,u.getConfig)(),{extConfig:r}=i.app;return r&&(r.plugins||(r.plugins={}),r.plugins.CapacitorUpdater||(r.plugins.CapacitorUpdater={}),r.plugins.CapacitorUpdater.privateKey=t,(0,s.writeConfig)(r,i.app.extConfigFilePath)),o&&(d.log.success("Your RSA key has been generated"),d.log.success(`Public key saved in ${u.baseKeyPub}`),d.log.success("This key will be use to crypt your bundle before sending it to Capgo"),d.log.success("Than make them unreadable by Capgo and unmodifiable by anyone"),d.log.success(`Private key saved in ${i.app.extConfigFilePath}`),d.log.success("Your app will be the only one having it"),d.log.success("Only your users can decrypt your update"),d.log.success("Only you can send them an update"),d.outro("Done ✅")),!0})),o.createKeyCommand=e=>a(void 0,void 0,void 0,(function*(){yield(0,f.checkLatest)(),yield(0,o.createKey)(e)}))},5041: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.loginCommand=o.login=void 0;const l=n(7147),c=n(2037),s=n(7304),d=r(n(552)),p=n(6545),u=n(7482);o.login=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){if(n&&d.intro("Login to Capgo"),!e)return n&&s.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,u.checkLatest)();try{const{local:n}=o,t=(0,p.useLogSnag)();if(n)(0,l.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),s.program.error("")),(0,l.writeFileSync)(".capgo",`${e}\n`),(0,l.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,c.homedir)();(0,l.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const i=(0,p.createSupabaseClient)(e),r=yield(0,p.verifyUser)(i,e,["write","all","upload"]);yield t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":r},notify:!1}).catch(),d.log.success(`login saved into .capgo file in ${n?"local":"home"} directory`)}catch(e){d.log.error("Error while saving login"),process.exit(1)}return n&&(d.outro("Done ✅"),process.exit()),!0})),o.loginCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.login)(e,n,!0)}))},6545: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}),r=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},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__await||function(e){return this instanceof l?(this.v=e,this):new l(e)},c=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)}))}}},s=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,i){o[t]=e[t]?function(o){return(n=!n)?{value:l(e[t](o)),done:!1}:i?i(o):o}:i}},d=this&&this.__asyncGenerator||function(e,o,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,i=n.apply(e,o||[]),r=[];return t={},a("next"),a("throw"),a("return"),t[Symbol.asyncIterator]=function(){return this},t;function a(e){i[e]&&(t[e]=function(o){return new Promise((function(n,t){r.push([e,o,n,t])>1||c(e,o)}))})}function c(e,o){try{(n=i[e](o)).value instanceof l?Promise.resolve(n.value.v).then(s,d):p(r[0][2],n)}catch(e){p(r[0][3],e)}var n}function s(e){c("next",e)}function d(e){c("throw",e)}function p(e,o){e(o),r.shift(),r.length&&c(r[0][0],r[0][1])}},p=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.uploadUrl=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.defaulPublicKey=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=void 0;const u=n(7147),f=n(2037),y=n(1017),g=n(7778),v=n(7304),h=n(2885),m=p(n(9867)),b=n(1133),_=r(n(552));function w(e){return d(this,arguments,(function*(){const o=yield l((0,u.readdirSync)(e,{withFileTypes:!0}));for(const n of o){const o=(0,y.resolve)(e,n.name);!n.isDirectory()||n.name.startsWith(".")||n.name.startsWith("node_modules")||n.name.startsWith("dist")?yield yield l(o):yield l(yield*s(c(w(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.defaulPublicKey="-----BEGIN RSA PUBLIC KEY-----\n MIIBCgKCAQEA4pW9olT0FBXXivRCzd3xcImlWZrqkwcF2xTkX/FwXmj9eh9HkBLr\n sQmfsC+PJisRXIOGq6a0z3bsGq6jBpp3/Jr9jiaW5VuPGaKeMaZZBRvi/N5fIMG3\n hZXSOcy0IYg+E1Q7RkYO1xq5GLHseqG+PXvJsNe4R8R/Bmd/ngq0xh/cvcrHHpXw\n O0Aj9tfprlb+rHaVV79EkVRWYPidOLnK1n0EFHFJ1d/MyDIp10TEGm2xHpf/Brlb\n 1an8wXEuzoC0DgYaczgTjovwR+ewSGhSHJliQdM0Qa3o1iN87DldWtydImMsPjJ3\n DUwpsjAMRe5X8Et4+udFW2ciYnQo9H0CkwIDAQAB\n -----END RSA PUBLIC KEY-----",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh2d3pwb2F6bXhrcW9zcmRld3l2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTI4MjExOTcsImV4cCI6MjAwODM5NzE5N30.wjxOlMfJoM2IuiFOmLGeP6YxdkF7Scgcfwu8TnPw_fY",o.createSupabaseClient=e=>(0,h.createClient)(o.hostSupa,o.supaAnon,{auth:{persistSession:!1},global:{headers:{capgkey:e}}}),o.regexSemver=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,o.checkKey=(e,n,t)=>a(void 0,void 0,void 0,(function*(){const{data:i,error:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:t}).single();i&&!r||v.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(r)}`)})),o.isGoodPlan=(e,o)=>a(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)=>a(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)=>a(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)=>a(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,t,i=!0)=>a(void 0,void 0,void 0,(function*(){(yield(0,o.isAllowedAction)(e,t))||(_.log.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),setTimeout((()=>{Promise.resolve().then((()=>r(n(6634)))).then((e=>{e.default(`${o.hostWeb}/dashboard/settings/plans`)})),v.program.error("")}),1e3));const a=yield(0,o.isTrial)(e,t);a>0&&i&&_.log.warn(`WARNING !!\nTrial expires in ${a} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e,o=`${(0,f.homedir)()}/.capgo`;return(0,u.existsSync)(o)&&(_.log.info(`Use global apy key ${o}`),e=(0,u.readFileSync)(o,"utf8").trim()),o=".capgo",!e&&(0,u.existsSync)(o)&&(_.log.info(`Use local apy key ${o}`),e=(0,u.readFileSync)(o,"utf8").trim()),e||v.program.error("Key not found, please login first"),e},o.findMainFile=()=>a(void 0,void 0,void 0,(function*(){var e,o,n,t;const i=/(main|index)\.(ts|js)$/;let r="";const a=process.cwd(),l=a.split("/").length;try{for(var s,d=!0,p=c(w(a));!(e=(s=yield p.next()).done);d=!0){t=s.value,d=!1;const e=t;if(e.split("/").length-l<=2&&i.test(e)){r=e,_.log.info(`Found main file here ${e}`);break}}}catch(e){o={error:e}}finally{try{d||e||!(n=p.return)||(yield n.call(p))}finally{if(o)throw o.error}}return r})),o.formatError=e=>e?`\n${m.default.render(e)}`:"",o.getConfig=()=>a(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,g.loadConfig)()}catch(e){v.program.error("No capacitor config file found, run `cap init` first")}return e})),o.updateOrCreateVersion=(e,o,n)=>a(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)})),o.uploadUrl=function(e,o,n){return a(this,void 0,void 0,(function*(){const t={app_id:o,bucket_id:n};try{return(yield e.functions.invoke("upload_link",{body:JSON.stringify(t)})).data.url}catch(e){_.log.error(`Cannot get upload url ${JSON.stringify(e)}`)}return""}))},o.updateOrCreateChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){if(!o.app_id||!o.name||!o.created_by)return console.error("missing app_id, name, or created_by"),Promise.reject(new Error("missing app_id, name, or created_by"));const{data:n,error:t}=yield e.from("channels").select("enable_progressive_deploy, secondaryVersionPercentage, secondVersion").eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by).single();return console.log("create Channel",n,t,o),n&&!t?(n.enable_progressive_deploy&&(_.log.info("Progressive deploy is enabled"),1!==n.secondaryVersionPercentage&&_.log.warn("Latest progressive deploy has not finished"),o.secondVersion=o.version,o.version=n.secondVersion,o.secondaryVersionPercentage=.1,_.log.info("Started new progressive upload!")),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 b.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.convertAppName=e=>e.replace(/\./g,"--"),o.verifyUser=(e,n,t=["all"])=>a(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,n,t);const{data:i,error:r}=yield e.rpc("get_user_id",{apikey:n}).single(),a=(i||"").toString();return a&&!r||v.program.error(`Cannot verify user ${(0,o.formatError)(r)}`),a})),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")},2167:e=>{e.exports=require("axios")},7812:e=>{e.exports=require("ci-info")},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.13.7","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"engines":{"npm":">=7.0.0","node":">=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":"5.2.2","@capgo/find-package-manager":"^0.0.7","@clack/prompts":"^0.7.0","@supabase/supabase-js":"^2.32.0","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","axios":"^1.4.0","ci-info":"^3.8.0","cloudflared":"^0.4.0","commander":"11.0.0","console-table-printer":"^2.11.2","fs-extra":"11.1.1","get-latest-version":"^5.1.0","logsnag":"^0.1.8","mime":"^3.0.0","open":"^9.1.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","qrcode":"^1.5.3","semver":"^7.5.4"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/fs-extra":"^11.0.1","@types/mime":"^3.0.1","@types/node":"^20.4.9","@types/npmcli__ci-detect":"^2.0.0","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/qrcode":"^1.5.1","@types/semver":"^7.5.0","@typescript-eslint/eslint-plugin":"5.56.0","@typescript-eslint/parser":"5.56.0","eslint":"8.47.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^9.0.0","eslint-import-resolver-typescript":"3.6.0","eslint-plugin-import":"2.28.0","eslint-plugin-prettier":"^5.0.0","git-format-staged":"3.0.0","husky":"^8.0.3","nodemon":"3.0.1","pkg":"5.8.1","prettier":"3.0.2","ts-loader":"^9.4.4","ts-node":"^10.9.1","tsconfig-paths":"4.2.0","typescript":"5.1.6","webpack":"5.88.2","webpack-cli":"^5.1.4","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t].call(r.exports,r,r.exports,n),r.exports}(4999)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "3.13.5",
3
+ "version": "3.13.7",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/app/set.ts CHANGED
@@ -78,7 +78,7 @@ export const setApp = async (appId: string, options: Options) => {
78
78
  .update({
79
79
  icon_url: signedURL,
80
80
  name,
81
- retention: !retention ? null : retention * 24 * 60 * 60,
81
+ retention: !retention ? undefined : retention * 24 * 60 * 60,
82
82
  })
83
83
  .eq('app_id', appId)
84
84
  .eq('user_id', userId)
@@ -198,6 +198,7 @@ export interface Database {
198
198
  id: string | null
199
199
  last_version: string | null
200
200
  name: string | null
201
+ retention: number
201
202
  updated_at: string | null
202
203
  user_id: string
203
204
  }
@@ -208,6 +209,7 @@ export interface Database {
208
209
  id?: string | null
209
210
  last_version?: string | null
210
211
  name?: string | null
212
+ retention?: number
211
213
  updated_at?: string | null
212
214
  user_id: string
213
215
  }
@@ -218,6 +220,7 @@ export interface Database {
218
220
  id?: string | null
219
221
  last_version?: string | null
220
222
  name?: string | null
223
+ retention?: number
221
224
  updated_at?: string | null
222
225
  user_id?: string
223
226
  }
@@ -289,10 +292,14 @@ export interface Database {
289
292
  created_by: string
290
293
  disableAutoUpdateToMajor: boolean
291
294
  disableAutoUpdateUnderNative: boolean
295
+ enable_progressive_deploy: boolean
296
+ enableAbTesting: boolean
292
297
  id: number
293
298
  ios: boolean
294
299
  name: string
295
300
  public: boolean
301
+ secondaryVersionPercentage: number
302
+ secondVersion: number
296
303
  updated_at: string
297
304
  version: number
298
305
  }
@@ -307,12 +314,16 @@ export interface Database {
307
314
  created_by: string
308
315
  disableAutoUpdateToMajor?: boolean
309
316
  disableAutoUpdateUnderNative?: boolean
317
+ enable_progressive_deploy?: boolean
318
+ enableAbTesting?: boolean
310
319
  id?: number
311
320
  ios?: boolean
312
321
  name: string
313
322
  public?: boolean
323
+ secondaryVersionPercentage?: number
324
+ secondVersion?: number
314
325
  updated_at?: string
315
- version: number
326
+ version?: number
316
327
  }
317
328
  Update: {
318
329
  allow_dev?: boolean
@@ -325,10 +336,14 @@ export interface Database {
325
336
  created_by?: string
326
337
  disableAutoUpdateToMajor?: boolean
327
338
  disableAutoUpdateUnderNative?: boolean
339
+ enable_progressive_deploy?: boolean
340
+ enableAbTesting?: boolean
328
341
  id?: number
329
342
  ios?: boolean
330
343
  name?: string
331
344
  public?: boolean
345
+ secondaryVersionPercentage?: number
346
+ secondVersion?: number
332
347
  updated_at?: string
333
348
  version?: number
334
349
  }
package/src/utils.ts CHANGED
@@ -30,7 +30,7 @@ if (process.env.SUPA_DB !== 'production') {
30
30
  }
31
31
  /* eslint-disable */
32
32
  export const supaAnon = process.env.SUPA_DB === 'production'
33
- ? 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w'
33
+ ? 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh2d3pwb2F6bXhrcW9zcmRld3l2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTI4MjExOTcsImV4cCI6MjAwODM5NzE5N30.wjxOlMfJoM2IuiFOmLGeP6YxdkF7Scgcfwu8TnPw_fY'
34
34
  : process.env.SUPA_ANON || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImF1Y3N5YnZuaGF2b2dkbXp3dGN3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTQ1Mzk1MDYsImV4cCI6MTk3MDExNTUwNn0.HyuZmo_EjF5fgZQU3g37bdNardK1CLHgxXmYqtr59bo'
35
35
  /* eslint-enable */
36
36
 
@@ -235,11 +235,28 @@ export const updateOrCreateChannel = async (supabase: SupabaseClient<Database>,
235
235
  return Promise.reject(new Error('missing app_id, name, or created_by'))
236
236
  }
237
237
  const { data, error } = await supabase
238
- .rpc('exist_channel', { appid: update.app_id, name_channel: update.name, apikey })
238
+ .from('channels')
239
+ .select('enable_progressive_deploy, secondaryVersionPercentage, secondVersion')
240
+ .eq('app_id', update.app_id)
241
+ .eq('name', update.name)
242
+ .eq('created_by', update.created_by)
239
243
  .single()
240
- // console.log('create Channel', data, error, update)
244
+ console.log('create Channel', data, error, update)
241
245
 
242
246
  if (data && !error) {
247
+ if (data.enable_progressive_deploy) {
248
+ p.log.info('Progressive deploy is enabled')
249
+
250
+ if (data.secondaryVersionPercentage !== 1)
251
+ p.log.warn('Latest progressive deploy has not finished')
252
+
253
+ update.secondVersion = update.version
254
+ update.version = data.secondVersion
255
+ update.secondaryVersionPercentage = 0.1
256
+ p.log.info('Started new progressive upload!')
257
+
258
+ // update.version = undefined
259
+ }
243
260
  return supabase
244
261
  .from('channels')
245
262
  .update(update)