@capgo/cli 3.13.30 → 3.13.31
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 +7 -0
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/app/add.ts +2 -2
- package/src/app/debug.ts +2 -4
- package/src/app/delete.ts +2 -2
- package/src/bundle/unlink.ts +2 -2
- package/src/bundle/upload.ts +8 -8
- package/src/bundle/zip.ts +3 -3
- package/src/channel/add.ts +2 -2
- package/src/channel/delete.ts +1 -1
- package/src/channel/list.ts +2 -2
- package/src/channel/set.ts +2 -1
- package/src/login.ts +3 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [3.13.31](https://github.com/Cap-go/capgo-cli/compare/v3.13.30...v3.13.31) (2023-09-20)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* logsnag tracking issue ([695486a](https://github.com/Cap-go/capgo-cli/commit/695486a2a2aa39067b91db3af0d9027ffcb4d8ef))
|
|
11
|
+
|
|
5
12
|
### [3.13.30](https://github.com/Cap-go/capgo-cli/compare/v3.13.29...v3.13.30) (2023-09-19)
|
|
6
13
|
|
|
7
14
|
|
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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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=!0)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.rpc("exist_app_v2",{appid:o}).single();return t!==n||i})),o.checkAppExistsAndHasPermissionErr=(e,n,r=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.checkAppExistsAndHasPermission)(e,n,r))&&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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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),s=n(3847),c=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:s}=yield e.from("channels").select().eq("app_id",n).eq("created_by",t).eq("version",i.id);if(s&&l.program.error(`Cannot check Version ${n}@${i.name} ${(0,d.formatError)(s)}`),a&&a.length>0){if(c.intro(`❌ Version ${n}@${i.name} is used in ${a.length} channel`),yield c.confirm({message:"unlink it?"}))for(const t of a){const i=c.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");c.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 s.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?"✅":"❌"})})),c.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[s,c]=o.split(":"),d=(0,t.privateDecrypt)({key:n,padding:l,oaepHash:r},Buffer.from(c,a)),p=Buffer.from(s,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),s=(0,t.randomBytes)(16),c=(0,t.createCipheriv)(i,s,n);c.setAutoPadding(!0);const d=`${n.toString(a)}:${(0,t.publicEncrypt)({key:o,padding:l,oaepHash:r},s).toString(a)}`;return{encryptedData:Buffer.concat([c.update(e),c.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const l=n(7304),s=r(n(552)),c=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,c.formatError)(i)}`),t&&t.length>0)if(s.intro(`❌ Version ${o}@${n.name} is used in ${t.length} device override`),yield s.confirm({message:"unlink it?"}))for(const o of t){const n=s.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,c.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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 s=l(n(5362)),c=r(n(552)),d=l(n(4147));o.checkLatest=()=>a(void 0,void 0,void 0,(function*(){const e=yield(0,s.default)("@capgo/cli");e!==d.default.version&&c.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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),s=n(3847),c=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 s.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}:{}))})),c.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addCommand=o.addApp=void 0;const l=n(6113),s=n(9011),c=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"),c.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.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,!1);else if(yield(0,f.checkAppExistsAndHasPermission)(v,e,!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"),c.program.error("")),n&&d.log.info(`Adding ${e} to Capgo`),w&&(0,p.existsSync)(w)?(m=(0,p.readFileSync)(w),b=(0,s.getType)(w)||"image/png",d.log.warn(`Found app icon ${w}`)):(0,p.existsSync)(f.newIconPath)?(m=(0,p.readFileSync)(f.newIconPath),b=(0,s.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 k=`icon_${(0,l.randomUUID)()}`;let C="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(k,m,{contentType:b});o&&(d.log.error(`Could not add app ${(0,y.formatError)(o)}`),c.program.error(""));const{data:n}=yield v.storage.from(`images/${h}/${e}`).getPublicUrl(k);C=(null==n?void 0:n.publicUrl)||C}const{error:P}=yield v.from("apps").insert({icon_url:C,user_id:h,name:_,app_id:e});P&&(d.log.error(`Could not add app ${(0,y.formatError)(P)}`),c.program.error(""));const{error:O}=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 O&&(d.log.error(`Could not add app ${(0,y.formatError)(O)}`),c.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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)),s=n(7304),c=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,s)=>a(void 0,void 0,void 0,(function*(){let a=!0,c=(new Date).toISOString();const d=(0,p.convertAppName)(t),f=`${p.hostWeb}/app/p/${d}`;for(yield(0,o.markSnag)(e,r,i,"Use waitlog");a;){const d=n.from("stats").select("*").eq("app_id",t).order("created_at",{ascending:!1}).gte("created_at",c);s&&d.eq("device_id",s);const{data:p,error:y}=yield d.limit(1).single();if(p&&!y){if(l.log.info(`Device: ${p.device_id}`),"get"===p.action)l.log.info("Update Sent your your device, wait until event download complete"),yield(0,o.markSnag)(e,r,i,"done");else if(p.action.startsWith("download_")){const n=p.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"===p.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(p);"NoChannelOrOverride"===p.action?l.log.error(`No default channel or override (channel/device) found, please create it here ${f}`):"needPlanUpgrade"===p.action?l.log.error("Your are out of quota, please upgrade your plan here https://web.capgo.app/dashboard/settings/plans"):"missingBundle"===p.action?l.log.error("Your bundle is missing, please check how you build your app "):"noNew"===p.action?l.log.error(`Your version in ${p.platform} is the same as your version uploaded, change it to see the update`):"disablePlatformIos"===p.action?l.log.error(`iOS is disabled in the default channel and your device is an iOS device ${f}`):"disablePlatformAndroid"===p.action?l.log.error(`Android is disabled in the default channel and your device is an Android device ${f}`):"disableAutoUpdateToMajor"===p.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"===p.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"===p.action?(l.log.error(`Dev build is disabled in the default channel. ${f}`),l.log.error("Set your channel to allow it if you wanna test your app")):"disableEmulator"===p.action?(l.log.error(`Emulator is disabled in the default channel. ${f}`),l.log.error("Set your channel to allow it if you wanna test your app")):"cannotGetBundle"===p.action?(l.log.error(`We cannot get your bundle from the default channel. ${f}`),l.log.error("Are you sure your default channel has a bundle set?")):"set_fail"===p.action?l.log.error(`Your bundle seems to be corrupted, try to download from ${f} to identify the issue`):"reset"===p.action?l.log.error("Your device has been reset to the builtin bundle, did you added notifyAppReady in your code?"):"update_fail"===p.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"===p.action&&l.log.error("Your bundle has failed to validate checksum, please check your code and send it again to Capgo")}c=(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"),s.program.error("")),e||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),s.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,c.checkAppExistsAndHasPermissionErr)(a,e);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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const l=n(7304),s=r(n(552)),c=n(9218),d=n(6545);o.deleteApp=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;s.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,c.checkAppExistsAndHasPermissionErr)(r,e);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(),s.log.success("App deleted in Capgo"),s.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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)),s=i(n(5362)),c=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("[31m%s[0m","🚨 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 c.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,s.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("[31m%s[0m","🚨 Some dependencies are not up to date"),process.exit(1)),console.log("\n"),console.log("[32m%s[0m","✅ 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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=o.getActiveApps=void 0;const l=n(7304),s=n(3847),c=r(n(552)),d=n(6545),p=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,d.formatError)(t)} `),n})),o.listApp=e=>a(void 0,void 0,void 0,(function*(){c.intro("List apps in Capgo"),yield(0,p.checkLatest)(),e.apikey=e.apikey||(0,d.findSavedKey)();const n=(0,d.createSupabaseClient)(e.apikey),t=yield(0,d.verifyUser)(n,e.apikey);c.log.info("Getting active bundle in Capgo");const i=yield(0,o.getActiveApps)(n,t);c.log.info(`Active app in Capgo: ${null==i?void 0:i.length}`),(e=>{const o=new s.Table({title:"Apps",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,d.getHumanDate)(e.created_at)})})),c.log.success(o.render())})(i),c.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setApp=void 0;const l=n(6113),s=n(9011),c=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"),c.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.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);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"),c.program.error("")):g&&g<0&&(d.log.error("retention value cannot be less than 0"),c.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,s.getType)(y)||"image/png",d.log.warn(`Found app icon ${y}`)):(0,p.existsSync)(u.newIconPath)?(v=(0,p.readFileSync)(u.newIconPath),h=(0,s.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)}`),c.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)(_)}`),c.program.error("")),d.outro("Done ✅"),process.exit()}))},3515:function(e,o,n){var t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.searchInDirectory=void 0;const i=t(n(7147)),r=t(n(1017)),a=(e,o)=>i.default.readFileSync(e,"utf8").includes(o);o.searchInDirectory=(e,n)=>{const t=i.default.readdirSync(e);for(const l of t){const t=r.default.join(e,l),s=i.default.statSync(t);if(s.isDirectory()){if((0,o.searchInDirectory)(t,n))return!0}else if(s.isFile()&&".js"===r.default.extname(t)&&a(t,n))return!0}return!1}},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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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)}))}}},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupBundle=void 0;const c=n(7304),d=s(n(1505)),p=r(n(552)),u=s(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,s=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||c.program.error("Missing API key, you need to provide an API key to delete your app"),e||c.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),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 C=0;if(_.forEach((e=>{const o=w.find((o=>o===e.id));C<r||o?(e.keep=o?"✅ (Linked to channel)":"✅",C+=1):(e.keep="❌",k.push(e))})),0!==k.length){if((0,y.displayBundles)(_),!s&&"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,s;return a(void 0,void 0,void 0,(function*(){var a,c,d,u;try{for(i=!0,r=l(e);!(a=(s=yield r.next()).done);i=!0){u=s.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){c={error:e}}finally{try{i||a||!(d=r.return)||(yield d.call(r))}finally{if(c)throw c.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const l=n(7147),s=n(7304),c=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,a,f,y;c.intro("Decrypt zip file"),yield(0,u.checkLatest)(),(0,l.existsSync)(e)||s.program.error(`Zip not found at the path ${e}`);const g=yield(0,p.getConfig)(),{extConfig:v}=g.app;n.key||(0,l.existsSync)(p.baseKey)||(null===(i=null===(t=v.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===i?void 0:i.privateKey)||s.program.error(`Private Key not found at the path ${p.baseKey} or in ${g.app.extConfigFilePath}`);const h=n.key||p.baseKey;let m=null===(a=null===(r=null==v?void 0:v.plugins)||void 0===r?void 0:r.CapacitorUpdater)||void 0===a?void 0:a.privateKey;(0,l.existsSync)(h)||m?(0,l.existsSync)(h)&&(m=(0,l.readFileSync)(h).toString()):s.program.error(`Cannot find public key ${h} or as keyData option or in ${g.app.extConfigFilePath}`);const b=(0,l.readFileSync)(e),_=(0,d.decryptSource)(b,o,null!==(y=null!==(f=n.keyData)&&void 0!==f?f:m)&&void 0!==y?y:"");(0,l.writeFileSync)(`${e}_decrypted.zip`,_),c.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteBundle=void 0;const l=n(7304),s=r(n(552)),c=n(9218),d=n(6545),p=n(9656);o.deleteBundle=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i;s.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||(s.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(s.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,c.checkAppExistsAndHasPermissionErr)(a,o);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||(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 bundleId, or be in a capacitor project"),l.program.error("")),o||(s.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error("")),s.log.info(`Deleting bundle ${o}@${e} from Capgo`),yield(0,p.deleteSpecificVersion)(a,o,u,e),s.log.success(`Bundle ${o}@${e} deleted in Capgo`),s.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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 s=n(7147),c=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,s.existsSync)(e)||(p.log.error(`Error: Zip not found at the path ${e}`),c.program.error(""));const n=o.key||y.baseKeyPub;let t=o.keyData||"";(0,s.existsSync)(n)||t?(0,s.existsSync)(n)&&(t=(0,s.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"),c.program.error("")),(yield p.confirm({message:"Do you want to use our public key ?"}))||(p.log.error("Error: Missing public key"),c.program.error("")),t=y.defaulPublicKey);const i=(0,s.readFileSync)(e),r=(0,f.encryptSource)(i,t);p.log.success(`ivSessionKey: ${r.ivSessionKey}`),(0,s.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listBundle=void 0;const l=n(7304),s=r(n(552)),c=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;s.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||(s.log.error("Missing API key, you need to provide a API key to upload your bundle"),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 i=(0,p.createSupabaseClient)(o.apikey),r=yield(0,p.verifyUser)(i,o.apikey);s.log.info(`Querying available versions of: ${e} in Capgo`),yield(0,c.checkAppExistsAndHasPermissionErr)(i,e);const a=yield(0,d.getActiveAppVersions)(i,e,r);s.log.info(`Active versions in Capgo: ${null==a?void 0:a.length}`),(0,d.displayBundles)(a),s.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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 s=n(6113),c=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),_=n(3515);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:w,channel:k}=o;const{external:C,key:P=!1,displayIvSession:O}=o,x=o.apikey||(0,b.findSavedKey)(),S=(0,b.useLogSnag)();k=k||"dev";const j=yield(0,b.getConfig)(),$=!0===(j.app.extConfig.plugins&&j.app.extConfig.plugins.CapacitorUpdater&&j.app.extConfig.plugins.CapacitorUpdater.localS3),A=o.codeCheck;e=e||(null===(t=null==j?void 0:j.app)||void 0===t?void 0:t.appId);const M=(0,s.randomUUID)().split("-")[0];l=l||(null===(r=null===(i=null==j?void 0:j.app)||void 0===i?void 0:i.package)||void 0===r?void 0:r.version)||`0.0.1-beta.${M}`,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("")),w=w||(null===(a=null==j?void 0:j.app)||void 0===a?void 0:a.webDir),x||(u.log.error("Missing API key, you need to provide a API key to upload your bundle"),p.program.error("")),e&&l&&w||(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,c.existsSync)(w)||(u.log.error(`Path ${w} does not exist, build your app first, or provide a valid path`),p.program.error("")),(void 0===A||A)&&((0,_.searchInDirectory)(w,"notifyAppReady")||(u.log.error("Did not find a call to notifyAppReady() in the source code. see: https://capgo.app/docs/plugin/api/#notifyappready"),p.program.error(""))),u.log.info(`Upload ${e}@${l} started from path "${w}" to Capgo cloud`);const D=(0,b.createSupabaseClient)(x),I=yield(0,b.verifyUser)(D,x,["write","all","upload"]);yield(0,b.checkPlanValid)(D,I,!1),yield(0,h.checkAppExistsAndHasPermissionErr)(D,e);const{data:E,error:U}=yield D.rpc("is_trial",{userid:I}).single();(E&&E>0||U)&&(u.log.warn(`WARNING !!\nTrial expires in ${E} days`),u.log.warn(`Upgrade here: ${b.hostWeb}/dashboard/settings/plans`));const{data:q,error:K}=yield D.rpc("exist_app_versions",{appid:e,apikey:x,name_version:l}).single();(q||K)&&(u.log.error(`Version already exists ${(0,b.formatError)(K)}`),p.program.error(""));const B=`${l.replace(/[^a-zA-Z0-9-_.!*'()]/g,"__")}.zip`;let L,V="",F=null;if(C)C&&!C.startsWith("https://")?(u.log.error(`External link should should start with "https://" current is "${C}"`),p.program.error("")):(yield S.publish({channel:"app",event:"App external",icon:"📤",tags:{"user-id":I,"app-id":e},notify:!1}).catch(),L=o.ivSessionKey);else{const n=new d.default;n.addLocalFolder(w),F=n.toBuffer();const t=u.spinner();if(t.start("Calculating checksum"),V=yield(0,f.checksum)(F,"crc32"),t.stop(`Checksum: ${V}`),P||(0,c.existsSync)(b.baseKeyPub)){const n="string"==typeof P?P:b.baseKeyPub;let t=o.keyData||"";t||(0,c.existsSync)(n)||(u.log.error(`Cannot find public key ${n}`),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("")),t=b.defaulPublicKey),yield S.publish({channel:"app",event:"App encryption",icon:"🔑",tags:{"user-id":I,"app-id":e},notify:!1}).catch(),t||(t=(0,c.readFileSync)(n).toString()),u.log.info("Encrypting your bundle");const i=(0,m.encryptSource)(F,t);L=i.ivSessionKey,O&&u.log.info(`Your Iv Session key is ${L},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),F=i.encryptedData}const i=Math.floor(F.byteLength/1024/1024);i>20&&(u.log.warn(`WARNING !!\nThe app size is ${i} 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 S.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":I,"app-id":e},notify:!1}).catch())}const N={bucket_id:C?void 0:B,user_id:I,name:l,app_id:e,session_key:L,external_url:C,storage_provider:C?"external":"r2-direct",checksum:V},{error:z}=yield(0,b.updateOrCreateVersion)(D,N,x);if(z&&(u.log.error(`Cannot add bundle ${(0,b.formatError)(z)}`),p.program.error("")),!C&&F){const o=u.spinner();o.start("Uploading Bundle");const n=yield(0,b.uploadUrl)(D,e,B);n||(u.log.error("Cannot get upload url"),p.program.error("")),yield(0,g.default)({method:"put",url:n,data:F,headers:$?void 0:{"Content-Type":"application/octet-stream","Cache-Control":"public, max-age=456789, immutable","x-amz-meta-crc32":V}}),N.storage_provider="r2";const{error:t}=yield(0,b.updateOrCreateVersion)(D,N,x);t&&(u.log.error(`Cannot update bundle ${(0,b.formatError)(z)}`),p.program.error("")),o.stop("Bundle Uploaded 💪")}const{data:T}=yield D.rpc("get_app_versions",{apikey:x,name_version:l,appid:e}).single();if(T){const{error:n,data:t}=yield(0,b.updateOrCreateChannel)(D,{name:k,app_id:e,created_by:I,version:T});n&&(u.log.error('Cannot set channel, the upload key is not allowed to do that, use the "all" for this.'),p.program.error(""));const i=(0,b.convertAppName)(e),r=`${b.hostWeb}/app/p/${i}/channel/${t.id}`;(null==t?void 0:t.public)?u.log.info("Your update is now available in your public channel 🎉"):(null==t?void 0:t.id)&&u.log.info(`Link device to this bundle to try it: ${r}`),o.bundleUrl&&u.log.info(`Bundle url: ${r}`)}else u.log.warn("Cannot set bundle with upload key, use key with more rights for that"),p.program.error("");return yield S.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":I,"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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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 s=n(6113),c=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,s.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 C=Math.floor(_.byteLength/1024/1024);C>20&&(u.log.warn(`WARNING !!\nThe app size is ${C} 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 P=u.spinner();P.start(`Saving to ${e}_${a}.zip`),(0,c.writeFileSync)(`${e}_${a}.zip`,_),P.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addChannelCommand=o.addChannel=void 0;const l=n(7304),s=r(n(552)),c=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;s.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||(s.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(s.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,c.checkAppExistsAndHasPermissionErr)(u,o),s.log.info(`Creating channel ${o}#${e} to Capgo`);try{const n=yield(0,d.findUnknownVersion)(u,o);n||(s.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}),s.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 s.log.error("Cannot create Channel 🙀"),!1}return t&&(s.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteChannel=void 0;const l=n(7304),s=r(n(552)),c=n(9218),d=n(6824),p=n(6545);o.deleteChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t;s.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||(s.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(s.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,c.checkAppExistsAndHasPermissionErr)(a,o),s.log.info(`Deleting channel ${o}#${e} from Capgo`);try{yield(0,d.delChannel)(a,e,o,u),s.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){s.log.error("Cannot delete Channel 🙀")}s.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listChannels=void 0;const l=n(7304),s=r(n(552)),c=n(9218),d=n(6824),p=n(6545);o.listChannels=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;s.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||s.log.error("Missing API key, you need to provide a API key to upload your bundle"),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)(o.apikey),a=yield(0,p.verifyUser)(r,o.apikey,["write","all"]);yield(0,c.checkAppExistsAndHasPermissionErr)(r,e),s.log.info("Querying available channels in Capgo"),yield(0,c.checkAppExistsAndHasPermissionErr)(r,e);const u=yield(0,d.getActiveChannels)(r,e,a);s.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(),s.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const l=n(7304),s=r(n(552)),c=n(9218),d=n(6545);o.setChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i,r;s.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||(s.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(s.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,c.checkAppExistsAndHasPermissionErr)(u,o);const{bundle:y,latest:g,downgrade:v,upgrade:h,ios:m,android:b,selfAssign:_,state:w}=n;e||(s.log.error("Missing argument, you need to provide a channel"),l.program.error("")),g&&y&&(s.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==_&&(s.log.error("Missing argument, you need to provide a option to set"),l.program.error(""));try{yield(0,d.checkPlanValid)(u,f),yield(0,c.checkAppExistsAndHasPermissionErr)(u,o);const n={created_by:f,app_id:o,name:e,version:void 0},t=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!=t){const{data:i,error:r}=yield u.from("app_versions").select().eq("app_id",o).eq("name",t).eq("user_id",f).eq("deleted",!1).single();!r&&i||(s.log.error(`Cannot find version ${t}`),l.program.error("")),s.log.info(`Set ${o} channel: ${e} to @${t}`),n.version=i.id}null!=w&&("public"!==w&&"private"!==w||s.log.info(`Set ${o} channel: ${e} to public or private is deprecated, use default or normal instead`),s.log.info(`Set ${o} channel: ${e} to ${"public"===w||"default"===w?"default":"normal"}`),n.public="public"===w||"default"===w),null!=v&&(s.log.info(`Set ${o} channel: ${e} to ${v?"allow":"disallow"} downgrade`),n.disableAutoUpdateUnderNative=!v),null!=h&&(s.log.info(`Set ${o} channel: ${e} to ${h?"allow":"disallow"} upgrade`),n.disableAutoUpdateToMajor=!h),null!=m&&(s.log.info(`Set ${o} channel: ${e} to ${m?"allow":"disallow"} ios update`),n.ios=!!m),null!=b&&(s.log.info(`Set ${o} channel: ${e} to ${b?"allow":"disallow"} android update`),n.android=!!b),null!=_&&(s.log.info(`Set ${o} channel: ${e} to ${_?"allow":"disallow"} self assign to this channel`),n.allow_device_self_set=!!_);try{const{error:e}=yield(0,d.updateOrCreateChannel)(u,n);e&&(s.log.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.'),l.program.error(""))}catch(e){s.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){s.log.error(`Unknow error ${(0,d.formatError)(e)}`),l.program.error("")}s.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),s=n(7978),c=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),C=n(5789),P=n(6626),O=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 x=i.program.command("app").description("Manage app");x.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"),x.command("delete [appId]").alias("d").description("Delete an app in Capgo Cloud").action(P.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account"),x.command("list").alias("l").description("list apps in Capgo Cloud").action(m.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),x.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(O.debugApp),x.command("set [appId]").alias("s").description("Set an app in Capgo Cloud").action(C.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 S=i.program.command("bundle").description("Manage bundle");S.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("--iv-session-key <key>","Set the iv and session key for bundle url external").option("--key <key>","custom path for public signing key").option("--key-data <keyData>","base64 public signing key").option("--bundle-url","prints bundle url into stdout").option("--no-key","ignore signing key and send clear update").option("--no-code-check","Ignore checking if notifyAppReady() is called in soure code").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"),S.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"),S.command("list [appId]").alias("l").description("List bundle in Capgo Cloud").action(l.listBundle).option("-a, --apikey <apikey>","apikey to link to your account"),S.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"),S.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"),S.command("decrypt [zipPath] [sessionKey]").alias("l").description("Decrypt a signed zip bundle").action(s.decryptZip).option("--key <key>","custom path for private signing key").option("--key-data <keyData>","base64 private signing key"),S.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(c.encryptZip).option("--key <key>","custom path for private signing key").option("--key-data <keyData>","base64 private signing key"),S.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 $=i.program.command("key").description("Manage key");$.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"),$.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("--key-data <keyData>","base64 public signing key").option("--bundle-url","prints bundle url into stdout").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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.initApp=void 0;const l=n(7147),s=n(2081),c=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",C={stdio:"pipe"},P=(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),j=yield(0,m.verifyUser)(S,e,["upload","all","read","write"]);yield O(j,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 P(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)})))(j,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 P(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)})))(j,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 P(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,c.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,s.execSync)(`${n} ${t} @capgo/capacitor-updater@latest`,C),e.stop("Install Done ✅"))}else d.log.info('Run yourself "npm i @capgo/capacitor-updater@latest"');yield O(e,o,4)})))(j,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 P(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`)})))(j,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 P(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)})))(j,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 P(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,s.execSync)("npm run build && npx cap sync",C),e.stop("Build & Sync Done ✅")}else d.log.info("Build yourself with command: npm run build && npx cap sync");yield O(e,o,7)})))(j,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 P(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)})))(j,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 P(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,s.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)})))(j,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 P(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)})))(j,i,S,o),yield O(j,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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((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),s=n(7304),c=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"),s.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}`),s.program.error("")}return t&&(t.plugins||(t.plugins={extConfig:{},CapacitorUpdater:{}}),t.plugins.CapacitorUpdater||(t.plugins.CapacitorUpdater={}),t.plugins.CapacitorUpdater.privateKey=r,(0,c.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"),s.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"),s.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"),s.program.error("")}(0,l.writeFileSync)(u.baseKey,t);const i=yield(0,u.getConfig)(),{extConfig:r}=i.app;return r&&(r.plugins||(r.plugins={extConfig:{},CapacitorUpdater:{}}),r.plugins.CapacitorUpdater.privateKey=t,(0,c.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.loginCommand=o.login=void 0;const l=n(7147),s=n(2037),c=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&&c.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"),c.program.error("")),(0,l.writeFileSync)(".capgo",`${e}\n`),(0,l.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,s.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{s(t.next(e))}catch(e){r(e)}}function l(e){try{s(t.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}s((t=t.apply(e,o||[])).next())}))},l=this&&this.__await||function(e){return this instanceof l?(this.v=e,this):new l(e)},s=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.__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||s(e,o)}))})}function s(e,o){try{(n=i[e](o)).value instanceof l?Promise.resolve(n.value.v).then(c,d):p(r[0][2],n)}catch(e){p(r[0][3],e)}var n}function c(e){s("next",e)}function d(e){s("throw",e)}function p(e,o){e(o),r.shift(),r.length&&s(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.formatError=o.findMainFile=o.findSavedKey=o.checkPlanValid=o.isAllowedAction=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.defaulPublicKey=o.supaAnon=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=o.getConfig=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*c(s(w(o))))}}))}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})),(0,o.getConfig)().then((e=>{var n,t,i,r;e.app.extConfig.plugins&&e.app.extConfig.plugins.CapacitorUpdater&&(o.host=null!==(n=e.app.extConfig.plugins.CapacitorUpdater.localHost)&&void 0!==n?n:o.host,o.hostWeb=null!==(t=e.app.extConfig.plugins.CapacitorUpdater.localWebHost)&&void 0!==t?t:o.hostWeb,o.hostSupa=null!==(i=e.app.extConfig.plugins.CapacitorUpdater.localSupa)&&void 0!==i?i:o.hostSupa,o.supaAnon=null!==(r=e.app.extConfig.plugins.CapacitorUpdater.localSupaAnon)&&void 0!==r?r:o.supaAnon)})),o.baseKey=".capgo_key",o.baseKeyPub=`${o.baseKey}.pub`,o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostSupa="https://xvwzpoazmxkqosrdewyv.supabase.co",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh2d3pwb2F6bXhrcW9zcmRld3l2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTI4MjExOTcsImV4cCI6MjAwODM5NzE5N30.wjxOlMfJoM2IuiFOmLGeP6YxdkF7Scgcfwu8TnPw_fY",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.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),l=yield(0,o.isPaying)(e,t);a>0&&i&&!l&&_.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|tsx|js|jsx)$/;let r="";const a=process.cwd(),l=a.split("/").length;try{for(var c,d=!0,p=s(w(a));!(e=(c=yield p.next()).done);d=!0){t=c.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.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)=>a(void 0,void 0,void 0,(function*(){if(!o.app_id||!o.name||!o.created_by)return _.log.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();if(n&&!t){if(n.enable_progressive_deploy){if(_.log.info("Progressive deploy is enabled"),1!==n.secondaryVersionPercentage&&_.log.warn("Latest progressive deploy has not finished"),o.secondVersion=o.version,!n.secondVersion)return _.log.error("missing secondVersion"),Promise.reject(new Error("missing secondVersion"));o.version=n.secondVersion,o.secondaryVersionPercentage=.1,_.log.info("Started new progressive upload!")}return e.from("channels").update(o).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by).select().single()}return 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")},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")},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.30","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","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=!0)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.rpc("exist_app_v2",{appid:o}).single();return t!==n||i})),o.checkAppExistsAndHasPermissionErr=(e,n,r=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.checkAppExistsAndHasPermission)(e,n,r))&&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,!1);else if(yield(0,f.checkAppExistsAndHasPermission)(v,e,!1))return!1;let m,b,{name:_,icon:k}=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",k=k||"resources/icon.png",k&&_||(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`),k&&(0,p.existsSync)(k)?(m=(0,p.readFileSync)(k),b=(0,c.getType)(k)||"image/png",d.log.warn(`Found app icon ${k}`)):(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: ${k}, ${f.newIconPath}`);const w=`icon_${(0,l.randomUUID)()}`;let C="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(w,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(w);C=(null==n?void 0:n.publicUrl)||C}const{error:P}=yield v.from("apps").insert({icon_url:C,user_id:h,name:_,app_id:e});P&&(d.log.error(`Could not add app ${(0,y.formatError)(P)}`),s.program.error(""));const{error:O}=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 O&&(d.log.error(`Could not add app ${(0,y.formatError)(O)}`),s.program.error("")),yield g.track({channel:"app",event:"App Added",icon:"🎉",user_id:h,tags:{"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.track({channel:e,event:t,icon:i,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=(0,p.convertAppName)(t),f=`${p.hostWeb}/app/p/${d}`;for(yield(0,o.markSnag)(e,r,i,"Use waitlog");a;){const d=n.from("stats").select("*").eq("app_id",t).order("created_at",{ascending:!1}).gte("created_at",s);c&&d.eq("device_id",c);const{data:p,error:y}=yield d.limit(1).single();if(p&&!y){if(l.log.info(`Device: ${p.device_id}`),"get"===p.action)l.log.info("Update Sent your your device, wait until event download complete"),yield(0,o.markSnag)(e,r,i,"done");else if(p.action.startsWith("download_")){const n=p.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"===p.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(p);"NoChannelOrOverride"===p.action?l.log.error(`No default channel or override (channel/device) found, please create it here ${f}`):"needPlanUpgrade"===p.action?l.log.error("Your are out of quota, please upgrade your plan here https://web.capgo.app/dashboard/settings/plans"):"missingBundle"===p.action?l.log.error("Your bundle is missing, please check how you build your app "):"noNew"===p.action?l.log.error(`Your version in ${p.platform} is the same as your version uploaded, change it to see the update`):"disablePlatformIos"===p.action?l.log.error(`iOS is disabled in the default channel and your device is an iOS device ${f}`):"disablePlatformAndroid"===p.action?l.log.error(`Android is disabled in the default channel and your device is an Android device ${f}`):"disableAutoUpdateToMajor"===p.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"===p.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"===p.action?(l.log.error(`Dev build is disabled in the default channel. ${f}`),l.log.error("Set your channel to allow it if you wanna test your app")):"disableEmulator"===p.action?(l.log.error(`Emulator is disabled in the default channel. ${f}`),l.log.error("Set your channel to allow it if you wanna test your app")):"cannotGetBundle"===p.action?(l.log.error(`We cannot get your bundle from the default channel. ${f}`),l.log.error("Are you sure your default channel has a bundle set?")):"set_fail"===p.action?l.log.error(`Your bundle seems to be corrupted, try to download from ${f} to identify the issue`):"reset"===p.action?l.log.error("Your device has been reset to the builtin bundle, did you added notifyAppReady in your code?"):"update_fail"===p.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"===p.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);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);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.track({channel:"app",event:"App Deleted",icon:"🗑️",user_id:a,tags:{"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("[31m%s[0m","🚨 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("[31m%s[0m","🚨 Some dependencies are not up to date"),process.exit(1)),console.log("\n"),console.log("[32m%s[0m","✅ 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(6545),p=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,d.formatError)(t)} `),n})),o.listApp=e=>a(void 0,void 0,void 0,(function*(){s.intro("List apps in Capgo"),yield(0,p.checkLatest)(),e.apikey=e.apikey||(0,d.findSavedKey)();const n=(0,d.createSupabaseClient)(e.apikey),t=yield(0,d.verifyUser)(n,e.apikey);s.log.info("Getting active bundle in Capgo");const i=yield(0,o.getActiveApps)(n,t);s.log.info(`Active app in Capgo: ${null==i?void 0:i.length}`),(e=>{const o=new c.Table({title:"Apps",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,d.getHumanDate)(e.created_at)})})),s.log.success(o.render())})(i),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);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()}))},3515:function(e,o,n){var t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.searchInDirectory=void 0;const i=t(n(7147)),r=t(n(1017)),a=(e,o)=>i.default.readFileSync(e,"utf8").includes(o);o.searchInDirectory=(e,n)=>{const t=i.default.readdirSync(e);for(const l of t){const t=r.default.join(e,l),c=i.default.statSync(t);if(c.isDirectory()){if((0,o.searchInDirectory)(t,n))return!0}else if(c.isFile()&&".js"===r.default.extname(t)&&a(t,n))return!0}return!1}},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),p.log.info("Querying all available versions in Capgo");let _=yield(0,y.getActiveAppVersions)(m,e,b);const k=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 w=[];let C=0;if(_.forEach((e=>{const o=k.find((o=>o===e.id));C<r||o?(e.keep=o?"✅ (Linked to channel)":"✅",C+=1):(e.keep="❌",w.push(e))})),0!==w.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}}}))})(w,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,a,f,y;s.intro("Decrypt zip file"),yield(0,u.checkLatest)(),(0,l.existsSync)(e)||c.program.error(`Zip not found at the path ${e}`);const g=yield(0,p.getConfig)(),{extConfig:v}=g.app;n.key||(0,l.existsSync)(p.baseKey)||(null===(i=null===(t=v.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 ${g.app.extConfigFilePath}`);const h=n.key||p.baseKey;let m=null===(a=null===(r=null==v?void 0:v.plugins)||void 0===r?void 0:r.CapacitorUpdater)||void 0===a?void 0:a.privateKey;(0,l.existsSync)(h)||m?(0,l.existsSync)(h)&&(m=(0,l.readFileSync)(h).toString()):c.program.error(`Cannot find public key ${h} or as keyData option or in ${g.app.extConfigFilePath}`);const b=(0,l.readFileSync)(e),_=(0,d.decryptSource)(b,o,null!==(y=null!==(f=n.keyData)&&void 0!==f?f:m)&&void 0!==y?y:"");(0,l.writeFileSync)(`${e}_decrypted.zip`,_),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);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);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),_=n(3515);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:k,channel:w}=o;const{external:C,key:P=!1,displayIvSession:O}=o,x=o.apikey||(0,b.findSavedKey)(),S=(0,b.useLogSnag)();w=w||"dev";const j=yield(0,b.getConfig)(),$=!0===(j.app.extConfig.plugins&&j.app.extConfig.plugins.CapacitorUpdater&&j.app.extConfig.plugins.CapacitorUpdater.localS3),A=o.codeCheck;e=e||(null===(t=null==j?void 0:j.app)||void 0===t?void 0:t.appId);const M=(0,c.randomUUID)().split("-")[0];l=l||(null===(r=null===(i=null==j?void 0:j.app)||void 0===i?void 0:i.package)||void 0===r?void 0:r.version)||`0.0.1-beta.${M}`,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("")),k=k||(null===(a=null==j?void 0:j.app)||void 0===a?void 0:a.webDir),x||(u.log.error("Missing API key, you need to provide a API key to upload your bundle"),p.program.error("")),e&&l&&k||(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)(k)||(u.log.error(`Path ${k} does not exist, build your app first, or provide a valid path`),p.program.error("")),(void 0===A||A)&&((0,_.searchInDirectory)(k,"notifyAppReady")||(u.log.error("Did not find a call to notifyAppReady() in the source code. see: https://capgo.app/docs/plugin/api/#notifyappready"),p.program.error(""))),u.log.info(`Upload ${e}@${l} started from path "${k}" to Capgo cloud`);const D=(0,b.createSupabaseClient)(x),I=yield(0,b.verifyUser)(D,x,["write","all","upload"]);yield(0,b.checkPlanValid)(D,I,!1),yield(0,h.checkAppExistsAndHasPermissionErr)(D,e);const{data:E,error:U}=yield D.rpc("is_trial",{userid:I}).single();(E&&E>0||U)&&(u.log.warn(`WARNING !!\nTrial expires in ${E} days`),u.log.warn(`Upgrade here: ${b.hostWeb}/dashboard/settings/plans`));const{data:q,error:K}=yield D.rpc("exist_app_versions",{appid:e,apikey:x,name_version:l}).single();(q||K)&&(u.log.error(`Version already exists ${(0,b.formatError)(K)}`),p.program.error(""));const B=`${l.replace(/[^a-zA-Z0-9-_.!*'()]/g,"__")}.zip`;let L,V="",F=null;if(C)C&&!C.startsWith("https://")?(u.log.error(`External link should should start with "https://" current is "${C}"`),p.program.error("")):(yield S.track({channel:"app",event:"App external",icon:"📤",user_id:I,tags:{"app-id":e},notify:!1}).catch(),L=o.ivSessionKey);else{const n=new d.default;n.addLocalFolder(k),F=n.toBuffer();const t=u.spinner();if(t.start("Calculating checksum"),V=yield(0,f.checksum)(F,"crc32"),t.stop(`Checksum: ${V}`),P||(0,s.existsSync)(b.baseKeyPub)){const n="string"==typeof P?P:b.baseKeyPub;let t=o.keyData||"";t||(0,s.existsSync)(n)||(u.log.error(`Cannot find public key ${n}`),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("")),t=b.defaulPublicKey),yield S.track({channel:"app",event:"App encryption",icon:"🔑",user_id:I,tags:{"app-id":e},notify:!1}).catch(),t||(t=(0,s.readFileSync)(n).toString()),u.log.info("Encrypting your bundle");const i=(0,m.encryptSource)(F,t);L=i.ivSessionKey,O&&u.log.info(`Your Iv Session key is ${L},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),F=i.encryptedData}const i=Math.floor(F.byteLength/1024/1024);i>20&&(u.log.warn(`WARNING !!\nThe app size is ${i} 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 S.track({channel:"app-error",event:"App Too Large",icon:"🚛",user_id:I,tags:{"app-id":e},notify:!1}).catch())}const N={bucket_id:C?void 0:B,user_id:I,name:l,app_id:e,session_key:L,external_url:C,storage_provider:C?"external":"r2-direct",checksum:V},{error:z}=yield(0,b.updateOrCreateVersion)(D,N,x);if(z&&(u.log.error(`Cannot add bundle ${(0,b.formatError)(z)}`),p.program.error("")),!C&&F){const o=u.spinner();o.start("Uploading Bundle");const n=yield(0,b.uploadUrl)(D,e,B);n||(u.log.error("Cannot get upload url"),p.program.error("")),yield(0,g.default)({method:"put",url:n,data:F,headers:$?void 0:{"Content-Type":"application/octet-stream","Cache-Control":"public, max-age=456789, immutable","x-amz-meta-crc32":V}}),N.storage_provider="r2";const{error:t}=yield(0,b.updateOrCreateVersion)(D,N,x);t&&(u.log.error(`Cannot update bundle ${(0,b.formatError)(z)}`),p.program.error("")),o.stop("Bundle Uploaded 💪")}const{data:T}=yield D.rpc("get_app_versions",{apikey:x,name_version:l,appid:e}).single();if(T){const{error:n,data:t}=yield(0,b.updateOrCreateChannel)(D,{name:w,app_id:e,created_by:I,version:T});n&&(u.log.error('Cannot set channel, the upload key is not allowed to do that, use the "all" for this.'),p.program.error(""));const i=(0,b.convertAppName)(e),r=`${b.hostWeb}/app/p/${i}/channel/${t.id}`;(null==t?void 0:t.public)?u.log.info("Your update is now available in your public channel 🎉"):(null==t?void 0:t.id)&&u.log.info(`Link device to this bundle to try it: ${r}`),o.bundleUrl&&u.log.info(`Bundle url: ${r}`)}else u.log.warn("Cannot set bundle with upload key, use key with more rights for that"),p.program.error("");return yield S.track({channel:"app",event:"App Uploaded",icon:"⏫",user_id:I,tags:{"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 k=u.spinner();k.start("Calculating checksum");const w=yield(0,f.checksum)(_,"crc32");k.stop(`Checksum: ${w}`);const C=Math.floor(_.byteLength/1024/1024);C>20&&(u.log.warn(`WARNING !!\nThe app size is ${C} 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.track({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"app-id":e},notify:!1}).catch());const P=u.spinner();P.start(`Saving to ${e}_${a}.zip`),(0,s.writeFileSync)(`${e}_${a}.zip`,_),P.stop(`Saved to ${e}_${a}.zip`),yield v.track({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),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.track({channel:"channel",event:"Create channel",icon:"✅",user_id:f,tags:{"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),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.track({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),c.log.info("Querying available channels in Capgo"),yield(0,s.checkAppExistsAndHasPermissionErr)(r,e);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.track({channel:"channel",event:"List channel",icon:"✅",user_id:a,tags:{"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);const{bundle:y,latest:g,downgrade:v,upgrade:h,ios:m,android:b,selfAssign:_,state:k}=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==k&&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);const n={created_by:f,app_id:o,name:e,version:void 0},t=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!=t){const{data:i,error:r}=yield u.from("app_versions").select().eq("app_id",o).eq("name",t).eq("user_id",f).eq("deleted",!1).single();!r&&i||(c.log.error(`Cannot find version ${t}`),l.program.error("")),c.log.info(`Set ${o} channel: ${e} to @${t}`),n.version=i.id}null!=k&&("public"!==k&&"private"!==k||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"===k||"default"===k?"default":"normal"}`),n.public="public"===k||"default"===k),null!=v&&(c.log.info(`Set ${o} channel: ${e} to ${v?"allow":"disallow"} downgrade`),n.disableAutoUpdateUnderNative=!v),null!=h&&(c.log.info(`Set ${o} channel: ${e} to ${h?"allow":"disallow"} upgrade`),n.disableAutoUpdateToMajor=!h),null!=m&&(c.log.info(`Set ${o} channel: ${e} to ${m?"allow":"disallow"} ios update`),n.ios=!!m),null!=b&&(c.log.info(`Set ${o} channel: ${e} to ${b?"allow":"disallow"} android update`),n.android=!!b),null!=_&&(c.log.info(`Set ${o} channel: ${e} to ${_?"allow":"disallow"} self assign to this channel`),n.allow_device_self_set=!!_);try{const{error:e}=yield(0,d.updateOrCreateChannel)(u,n);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.track({channel:"channel",event:"Set channel",icon:"✅",user_id:f,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),k=n(7422),w=n(2667),C=n(5789),P=n(6626),O=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 x=i.program.command("app").description("Manage app");x.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"),x.command("delete [appId]").alias("d").description("Delete an app in Capgo Cloud").action(P.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account"),x.command("list").alias("l").description("list apps in Capgo Cloud").action(m.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),x.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(O.debugApp),x.command("set [appId]").alias("s").description("Set an app in Capgo Cloud").action(C.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 S=i.program.command("bundle").description("Manage bundle");S.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("--iv-session-key <key>","Set the iv and session key for bundle url external").option("--key <key>","custom path for public signing key").option("--key-data <keyData>","base64 public signing key").option("--bundle-url","prints bundle url into stdout").option("--no-key","ignore signing key and send clear update").option("--no-code-check","Ignore checking if notifyAppReady() is called in soure code").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"),S.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"),S.command("list [appId]").alias("l").description("List bundle in Capgo Cloud").action(l.listBundle).option("-a, --apikey <apikey>","apikey to link to your account"),S.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"),S.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"),S.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("--key-data <keyData>","base64 private signing key"),S.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(s.encryptZip).option("--key <key>","custom path for private signing key").option("--key-data <keyData>","base64 private signing key"),S.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(k.deleteChannel),j.command("list [appId]").alias("l").description("List channel").action(w.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 $=i.program.command("key").description("Manage key");$.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"),$.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("--key-data <keyData>","base64 public signing key").option("--bundle-url","prints bundle url into stdout").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()",k=/import.*from.*/g,w="production",C={stdio:"pipe"},P=(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),j=yield(0,m.verifyUser)(S,e,["upload","all","read","write"]);yield O(j,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 P(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)})))(j,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 ${w} for ${t} in Capgo?`});if(yield P(i,e,o),i){const e=d.spinner();e.start(`Running: npx @capgo/cli@latest channel add ${w} ${t} --default`),(yield(0,f.addChannel)(w,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 ${w} ${t} --default"`);yield O(e,o,3)})))(j,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 P(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`,C),e.stop("Install Done ✅"))}else d.log.info('Run yourself "npm i @capgo/capacitor-updater@latest"');yield O(e,o,4)})))(j,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 P(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(k),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`)})))(j,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 P(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)})))(j,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 P(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",C),e.stop("Build & Sync Done ✅")}else d.log.info("Build yourself with command: npm run build && npx cap sync");yield O(e,o,7)})))(j,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 P(i,e,o),i){const e=d.spinner();e.start("Running: npx @capgo/cli@latest bundle upload"),(yield(0,y.uploadBundle)(t,{channel:w,apikey:n},!1))?e.stop("Upload Done ✅"):(e.stop("Upload failed ❌"),process.exit())}else d.log.info("Upload yourself with command: npx @capgo/cli@latest bundle upload");yield O(e,o,8)})))(j,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 P(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)})))(j,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 P(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)})))(j,i,S,o),yield O(j,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={extConfig:{},CapacitorUpdater:{}}),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={extConfig:{},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.track({channel:"user-login",event:"User CLI login",icon:"✅",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.formatError=o.findMainFile=o.findSavedKey=o.checkPlanValid=o.isAllowedAction=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.defaulPublicKey=o.supaAnon=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=o.getConfig=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 k(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(k(o))))}}))}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})),(0,o.getConfig)().then((e=>{var n,t,i,r;e.app.extConfig.plugins&&e.app.extConfig.plugins.CapacitorUpdater&&(o.host=null!==(n=e.app.extConfig.plugins.CapacitorUpdater.localHost)&&void 0!==n?n:o.host,o.hostWeb=null!==(t=e.app.extConfig.plugins.CapacitorUpdater.localWebHost)&&void 0!==t?t:o.hostWeb,o.hostSupa=null!==(i=e.app.extConfig.plugins.CapacitorUpdater.localSupa)&&void 0!==i?i:o.hostSupa,o.supaAnon=null!==(r=e.app.extConfig.plugins.CapacitorUpdater.localSupaAnon)&&void 0!==r?r:o.supaAnon)})),o.baseKey=".capgo_key",o.baseKeyPub=`${o.baseKey}.pub`,o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostSupa="https://xvwzpoazmxkqosrdewyv.supabase.co",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh2d3pwb2F6bXhrcW9zcmRld3l2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTI4MjExOTcsImV4cCI6MjAwODM5NzE5N30.wjxOlMfJoM2IuiFOmLGeP6YxdkF7Scgcfwu8TnPw_fY",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.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),l=yield(0,o.isPaying)(e,t);a>0&&i&&!l&&_.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|tsx|js|jsx)$/;let r="";const a=process.cwd(),l=a.split("/").length;try{for(var s,d=!0,p=c(k(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.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)=>a(void 0,void 0,void 0,(function*(){if(!o.app_id||!o.name||!o.created_by)return _.log.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();if(n&&!t){if(n.enable_progressive_deploy){if(_.log.info("Progressive deploy is enabled"),1!==n.secondaryVersionPercentage&&_.log.warn("Latest progressive deploy has not finished"),o.secondVersion=o.version,!n.secondVersion)return _.log.error("missing secondVersion"),Promise.reject(new Error("missing secondVersion"));o.version=n.secondVersion,o.secondaryVersionPercentage=.1,_.log.info("Started new progressive upload!")}return e.from("channels").update(o).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by).select().single()}return 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")},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")},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.31","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","commander":"11.0.0","console-table-printer":"^2.11.2","fs-extra":"11.1.1","get-latest-version":"^5.1.0","logsnag":"1.0.0","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.
|
|
3
|
+
"version": "3.13.31",
|
|
4
4
|
"description": "A CLI to upload to capgo servers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"console-table-printer": "^2.11.2",
|
|
56
56
|
"fs-extra": "11.1.1",
|
|
57
57
|
"get-latest-version": "^5.1.0",
|
|
58
|
-
"logsnag": "
|
|
58
|
+
"logsnag": "1.0.0",
|
|
59
59
|
"mime": "^3.0.0",
|
|
60
60
|
"open": "^9.1.0",
|
|
61
61
|
"prettyjson": "^1.2.5",
|
package/src/app/add.ts
CHANGED
|
@@ -120,12 +120,12 @@ export const addApp = async (appId: string, options: Options, shouldExit = true)
|
|
|
120
120
|
p.log.error(`Could not add app ${formatError(dbVersionError)}`);
|
|
121
121
|
program.error('');
|
|
122
122
|
}
|
|
123
|
-
await snag.
|
|
123
|
+
await snag.track({
|
|
124
124
|
channel: 'app',
|
|
125
125
|
event: 'App Added',
|
|
126
126
|
icon: '🎉',
|
|
127
|
+
user_id: userId,
|
|
127
128
|
tags: {
|
|
128
|
-
'user-id': userId,
|
|
129
129
|
'app-id': appId,
|
|
130
130
|
},
|
|
131
131
|
notify: false,
|
package/src/app/debug.ts
CHANGED
|
@@ -16,13 +16,11 @@ export interface OptionsBaseDebug {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const markSnag = async (channel: string, userId: string, snag: LogSnag, event: string, icon = '✅') => {
|
|
19
|
-
await snag.
|
|
19
|
+
await snag.track({
|
|
20
20
|
channel,
|
|
21
21
|
event,
|
|
22
22
|
icon,
|
|
23
|
-
|
|
24
|
-
'user-id': userId,
|
|
25
|
-
},
|
|
23
|
+
user_id: userId,
|
|
26
24
|
notify: false,
|
|
27
25
|
}).catch()
|
|
28
26
|
}
|
package/src/app/delete.ts
CHANGED
|
@@ -47,12 +47,12 @@ export const deleteApp = async (appId: string, options: OptionsBase) => {
|
|
|
47
47
|
if (dbError) {
|
|
48
48
|
program.error(`Could not delete app ${formatError(dbError)}`);
|
|
49
49
|
}
|
|
50
|
-
await snag.
|
|
50
|
+
await snag.track({
|
|
51
51
|
channel: 'app',
|
|
52
52
|
event: 'App Deleted',
|
|
53
53
|
icon: '🗑️',
|
|
54
|
+
user_id: userId,
|
|
54
55
|
tags: {
|
|
55
|
-
'user-id': userId,
|
|
56
56
|
'app-id': appId,
|
|
57
57
|
},
|
|
58
58
|
notify: false,
|
package/src/bundle/unlink.ts
CHANGED
|
@@ -52,12 +52,12 @@ export const unlinkDevice = async (channel: string, appId: string, options: Opti
|
|
|
52
52
|
const versionData = await getVersionData(supabase, appId, userId, bundle);
|
|
53
53
|
await checkVersionNotUsedInChannel(supabase, appId, userId, versionData);
|
|
54
54
|
await checkVersionNotUsedInDeviceOverride(supabase, appId, versionData);
|
|
55
|
-
await snag.
|
|
55
|
+
await snag.track({
|
|
56
56
|
channel: 'bundle',
|
|
57
57
|
event: 'Unlink bundle',
|
|
58
58
|
icon: '✅',
|
|
59
|
+
user_id: userId,
|
|
59
60
|
tags: {
|
|
60
|
-
'user-id': userId,
|
|
61
61
|
'app-id': appId,
|
|
62
62
|
},
|
|
63
63
|
notify: false,
|
package/src/bundle/upload.ts
CHANGED
|
@@ -139,12 +139,12 @@ export const uploadBundle = async (appid: string, options: Options, shouldExit =
|
|
|
139
139
|
}
|
|
140
140
|
keyData = defaulPublicKey
|
|
141
141
|
}
|
|
142
|
-
await snag.
|
|
142
|
+
await snag.track({
|
|
143
143
|
channel: 'app',
|
|
144
144
|
event: 'App encryption',
|
|
145
145
|
icon: '🔑',
|
|
146
|
+
user_id: userId,
|
|
146
147
|
tags: {
|
|
147
|
-
'user-id': userId,
|
|
148
148
|
'app-id': appid,
|
|
149
149
|
},
|
|
150
150
|
notify: false,
|
|
@@ -169,12 +169,12 @@ It will be also visible in your dashboard\n`);
|
|
|
169
169
|
if (mbSize > alertMb) {
|
|
170
170
|
p.log.warn(`WARNING !!\nThe app size is ${mbSize} Mb, this may take a while to download for users\n`);
|
|
171
171
|
p.log.info(`Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n`);
|
|
172
|
-
await snag.
|
|
172
|
+
await snag.track({
|
|
173
173
|
channel: 'app-error',
|
|
174
174
|
event: 'App Too Large',
|
|
175
175
|
icon: '🚛',
|
|
176
|
+
user_id: userId,
|
|
176
177
|
tags: {
|
|
177
|
-
'user-id': userId,
|
|
178
178
|
'app-id': appid,
|
|
179
179
|
},
|
|
180
180
|
notify: false,
|
|
@@ -184,12 +184,12 @@ It will be also visible in your dashboard\n`);
|
|
|
184
184
|
p.log.error(`External link should should start with "https://" current is "${external}"`);
|
|
185
185
|
program.error('');
|
|
186
186
|
} else {
|
|
187
|
-
await snag.
|
|
187
|
+
await snag.track({
|
|
188
188
|
channel: 'app',
|
|
189
189
|
event: 'App external',
|
|
190
190
|
icon: '📤',
|
|
191
|
+
user_id: userId,
|
|
191
192
|
tags: {
|
|
192
|
-
'user-id': userId,
|
|
193
193
|
'app-id': appid,
|
|
194
194
|
},
|
|
195
195
|
notify: false,
|
|
@@ -268,12 +268,12 @@ It will be also visible in your dashboard\n`);
|
|
|
268
268
|
p.log.warn('Cannot set bundle with upload key, use key with more rights for that');
|
|
269
269
|
program.error('');
|
|
270
270
|
}
|
|
271
|
-
await snag.
|
|
271
|
+
await snag.track({
|
|
272
272
|
channel: 'app',
|
|
273
273
|
event: 'App Uploaded',
|
|
274
274
|
icon: '⏫',
|
|
275
|
+
user_id: userId,
|
|
275
276
|
tags: {
|
|
276
|
-
'user-id': userId,
|
|
277
277
|
'app-id': appid,
|
|
278
278
|
},
|
|
279
279
|
notify: false,
|
package/src/bundle/zip.ts
CHANGED
|
@@ -53,7 +53,7 @@ export const zipBundle = async (appId: string, options: Options) => {
|
|
|
53
53
|
if (mbSize > alertMb) {
|
|
54
54
|
p.log.warn(`WARNING !!\nThe app size is ${mbSize} Mb, this may take a while to download for users\n`);
|
|
55
55
|
p.log.warn(`Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n`);
|
|
56
|
-
await snag.
|
|
56
|
+
await snag.track({
|
|
57
57
|
channel: 'app-error',
|
|
58
58
|
event: 'App Too Large',
|
|
59
59
|
icon: '🚛',
|
|
@@ -67,7 +67,7 @@ export const zipBundle = async (appId: string, options: Options) => {
|
|
|
67
67
|
s2.start(`Saving to ${appId}_${bundle}.zip`);
|
|
68
68
|
writeFileSync(`${appId}_${bundle}.zip`, zipped);
|
|
69
69
|
s2.stop(`Saved to ${appId}_${bundle}.zip`);
|
|
70
|
-
await snag.
|
|
70
|
+
await snag.track({
|
|
71
71
|
channel: 'app',
|
|
72
72
|
event: 'App zip',
|
|
73
73
|
icon: '⏫',
|
|
@@ -78,4 +78,4 @@ export const zipBundle = async (appId: string, options: Options) => {
|
|
|
78
78
|
}).catch()
|
|
79
79
|
p.outro(`Done ✅`);
|
|
80
80
|
process.exit()
|
|
81
|
-
}
|
|
81
|
+
}
|
package/src/channel/add.ts
CHANGED
|
@@ -44,12 +44,12 @@ export const addChannel = async (channelId: string, appId: string, options: Opti
|
|
|
44
44
|
created_by: userId
|
|
45
45
|
});
|
|
46
46
|
p.log.success(`Channel created ✅`);
|
|
47
|
-
await snag.
|
|
47
|
+
await snag.track({
|
|
48
48
|
channel: 'channel',
|
|
49
49
|
event: 'Create channel',
|
|
50
50
|
icon: '✅',
|
|
51
|
+
user_id: userId,
|
|
51
52
|
tags: {
|
|
52
|
-
'user-id': userId,
|
|
53
53
|
'app-id': appId,
|
|
54
54
|
'channel': channelId,
|
|
55
55
|
},
|
package/src/channel/delete.ts
CHANGED
|
@@ -30,7 +30,7 @@ export const deleteChannel = async (channelId: string, appId: string, options: O
|
|
|
30
30
|
try {
|
|
31
31
|
await delChannel(supabase, channelId, appId, userId);
|
|
32
32
|
p.log.success(`Channel deleted`);
|
|
33
|
-
await snag.
|
|
33
|
+
await snag.track({
|
|
34
34
|
channel: 'channel',
|
|
35
35
|
event: 'Delete channel',
|
|
36
36
|
icon: '✅',
|
package/src/channel/list.ts
CHANGED
|
@@ -36,12 +36,12 @@ export const listChannels = async (appId: string, options: OptionsBase) => {
|
|
|
36
36
|
p.log.info(`Active channels in Capgo: ${allVersions?.length}`);
|
|
37
37
|
|
|
38
38
|
displayChannels(allVersions);
|
|
39
|
-
await snag.
|
|
39
|
+
await snag.track({
|
|
40
40
|
channel: 'channel',
|
|
41
41
|
event: 'List channel',
|
|
42
42
|
icon: '✅',
|
|
43
|
+
user_id: userId,
|
|
43
44
|
tags: {
|
|
44
|
-
'user-id': userId,
|
|
45
45
|
'app-id': appId,
|
|
46
46
|
},
|
|
47
47
|
notify: false,
|
package/src/channel/set.ts
CHANGED
|
@@ -126,10 +126,11 @@ export const setChannel = async (channel: string, appId: string, options: Option
|
|
|
126
126
|
p.log.error(`Cannot set channel the upload key is not allowed to do that, use the "all" for this.`);
|
|
127
127
|
program.error('');
|
|
128
128
|
}
|
|
129
|
-
await snag.
|
|
129
|
+
await snag.track({
|
|
130
130
|
channel: 'channel',
|
|
131
131
|
event: 'Set channel',
|
|
132
132
|
icon: '✅',
|
|
133
|
+
user_id: userId,
|
|
133
134
|
tags: {
|
|
134
135
|
'user-id': userId,
|
|
135
136
|
'app-id': appId,
|
package/src/login.ts
CHANGED
|
@@ -39,13 +39,11 @@ export const login = async (apikey: string, options: Options, shouldExit = true)
|
|
|
39
39
|
}
|
|
40
40
|
const supabase = createSupabaseClient(apikey)
|
|
41
41
|
const userId = await verifyUser(supabase, apikey, ['write', 'all', 'upload']);
|
|
42
|
-
await snag.
|
|
42
|
+
await snag.track({
|
|
43
43
|
channel: 'user-login',
|
|
44
44
|
event: 'User CLI login',
|
|
45
45
|
icon: '✅',
|
|
46
|
-
|
|
47
|
-
'user-id': userId,
|
|
48
|
-
},
|
|
46
|
+
user_id: userId,
|
|
49
47
|
notify: false,
|
|
50
48
|
}).catch()
|
|
51
49
|
p.log.success(`login saved into .capgo file in ${local ? 'local' : 'home'} directory`);
|
|
@@ -62,4 +60,4 @@ export const login = async (apikey: string, options: Options, shouldExit = true)
|
|
|
62
60
|
|
|
63
61
|
export const loginCommand = async (apikey: string, options: Options) => {
|
|
64
62
|
login(apikey, options, true)
|
|
65
|
-
}
|
|
63
|
+
}
|