@capgo/cli 3.13.27 → 3.13.30
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 +16 -0
- package/dist/index.js +1 -1
- package/package.json +1 -2
- package/src/bundle/decrypt.ts +3 -2
- package/src/bundle/upload.ts +8 -4
- package/src/index.ts +7 -6
- package/src/key.ts +8 -5
- package/src/live.ts +5 -4
- package/src/utils.ts +22 -1
- package/src/app/watch.ts +0 -90
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
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.30](https://github.com/Cap-go/capgo-cli/compare/v3.13.29...v3.13.30) (2023-09-19)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* lint ([2fee360](https://github.com/Cap-go/capgo-cli/commit/2fee360ebe64b39dae68ab2d071301c1044e7501))
|
|
11
|
+
|
|
12
|
+
### [3.13.29](https://github.com/Cap-go/capgo-cli/compare/v3.13.28...v3.13.29) (2023-09-19)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* comment old cloudflare for now ([e7f0b26](https://github.com/Cap-go/capgo-cli/commit/e7f0b26a49a9ee5df766bf8829f00333b95f711b))
|
|
18
|
+
|
|
19
|
+
### [3.13.28](https://github.com/Cap-go/capgo-cli/compare/v3.13.27...v3.13.28) (2023-09-19)
|
|
20
|
+
|
|
5
21
|
### [3.13.27](https://github.com/Cap-go/capgo-cli/compare/v3.13.26...v3.13.27) (2023-09-19)
|
|
6
22
|
|
|
7
23
|
|
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()}))},4635:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{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.watchApp=o.watch=void 0;const s=n(7304),c=r(n(552)),d=l(n(1121)),p=n(3422),u=n(6545),f=n(7482);o.watch=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){if(o.apikey=o.apikey||(0,u.findSavedKey)(),!o.apikey)return n&&s.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,f.checkLatest)(),c.intro("Capgo live reload");try{const n=(0,u.useLogSnag)(),t=(0,u.createSupabaseClient)(o.apikey),i=yield(0,u.verifyUser)(t,o.apikey,["write","all","upload"]);yield n.publish({channel:"app",event:"live reload",icon:"🔄",tags:{"user-id":i},notify:!1}).catch(),c.log.info("Init to tunnel");const{url:r,connections:a,stop:l}=(0,p.tunnel)({"--url":`localhost:${e}`});c.log.info("Connection to tunnel"),yield a[0],c.log.info("Get URL");const s=yield r;if(!s)throw new Error("No link found");c.log.info(`Tunnel ${s} connected to localhost:${e}`),yield t.from("app_live").upsert({id:i,url:s}).throwOnError();const f=yield d.default.toString(s,{type:"terminal",small:!0});c.log.info(f),yield c.confirm({message:"When done say yes to close tunnel"}),yield l(),yield t.from("app_live").delete().eq("id",i).throwOnError(),c.log.info("Tunnel closed")}catch(e){console.error("Error",e),process.exit(1)}return n&&(c.outro("Done ✅"),process.exit()),!0})),o.watchApp=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.watch)(e,n,!0)}))},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;c.intro("Decrypt zip file"),yield(0,u.checkLatest)(),(0,l.existsSync)(e)||s.program.error(`Zip not found at the path ${e}`);const a=yield(0,p.getConfig)(),{extConfig:f}=a.app;n.key||(0,l.existsSync)(p.baseKey)||(null===(i=null===(t=f.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===i?void 0:i.privateKey)||s.program.error(`Private Key not found at the path ${p.baseKey} or in ${a.app.extConfigFilePath}`);const y=n.key||p.baseKey;let{privateKey:g}=n.keyData||(null===(r=null==f?void 0:f.plugins)||void 0===r?void 0:r.CapacitorUpdater)||"";(0,l.existsSync)(y)||g?(0,l.existsSync)(y)&&(g=(0,l.readFileSync)(y).toString()):s.program.error(`Cannot find public key ${y} or as keyData option or in ${a.app.extConfigFilePath}`);const v=(0,l.readFileSync)(e),h=(0,d.decryptSource)(v,o,g);(0,l.writeFileSync)(`${e}_decrypted.zip`,h),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);e=e||(null===(t=null==j?void 0:j.app)||void 0===t?void 0:t.appId);const A=(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.${A}`,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("")),(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 M=(0,b.createSupabaseClient)(x),D=yield(0,b.verifyUser)(M,x,["write","all","upload"]);yield(0,b.checkPlanValid)(M,D,!1),yield(0,h.checkAppExistsAndHasPermissionErr)(M,e);const{data:I,error:E}=yield M.rpc("is_trial",{userid:D}).single();(I&&I>0||E)&&(u.log.warn(`WARNING !!\nTrial expires in ${I} days`),u.log.warn(`Upgrade here: ${b.hostWeb}/dashboard/settings/plans`));const{data:U,error:q}=yield M.rpc("exist_app_versions",{appid:e,apikey:x,name_version:l}).single();(U||q)&&(u.log.error(`Version already exists ${(0,b.formatError)(q)}`),p.program.error(""));const K=`${l.replace(/[^a-zA-Z0-9-_.!*'()]/g,"__")}.zip`;let B,L="",V=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":D,"app-id":e},notify:!1}).catch(),B=o.ivSessionKey);else{const n=new d.default;n.addLocalFolder(w),V=n.toBuffer();const t=u.spinner();if(t.start("Calculating checksum"),L=yield(0,f.checksum)(V,"crc32"),t.stop(`Checksum: ${L}`),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":D,"app-id":e},notify:!1}).catch(),t||(t=(0,c.readFileSync)(n).toString()),u.log.info("Encrypting your bundle");const i=(0,m.encryptSource)(V,t);B=i.ivSessionKey,O&&u.log.info(`Your Iv Session key is ${B},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),V=i.encryptedData}const i=Math.floor(V.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":D,"app-id":e},notify:!1}).catch())}const N={bucket_id:C?void 0:K,user_id:D,name:l,app_id:e,session_key:B,external_url:C,storage_provider:C?"external":"r2-direct",checksum:L},{error:F}=yield(0,b.updateOrCreateVersion)(M,N,x);if(F&&(u.log.error(`Cannot add bundle ${(0,b.formatError)(F)}`),p.program.error("")),!C&&V){const o=u.spinner();o.start("Uploading Bundle");const n=yield(0,b.uploadUrl)(M,e,K);n||(u.log.error("Cannot get upload url"),p.program.error("")),yield(0,g.default)({method:"put",url:n,data:V,headers:$?void 0:{"Content-Type":"application/octet-stream","Cache-Control":"public, max-age=456789, immutable","x-amz-meta-crc32":L}}),N.storage_provider="r2";const{error:t}=yield(0,b.updateOrCreateVersion)(M,N,x);t&&(u.log.error(`Cannot update bundle ${(0,b.formatError)(F)}`),p.program.error("")),o.stop("Bundle Uploaded 💪")}const{data:z}=yield M.rpc("get_app_versions",{apikey:x,name_version:l,appid:e}).single();if(z){const{error:n,data:t}=yield(0,b.updateOrCreateChannel)(M,{name:k,app_id:e,created_by:D,version:z});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":D,"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(4635),x=n(7626);i.program.name(v.default.name).description("Manage packages and bundle versions in Capgo Cloud").version(v.default.version),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(h.loginCommand).option("--local","Only save in local folder"),i.program.command("doctor").description("Get info about your Capgo app install").action(p.getInfo),i.program.command("init [apikey] [appId]").description("Init a new app").action(a.initApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account");const S=i.program.command("app").description("Manage app");S.command("add [appId]").alias("a").description("Add a new app in Capgo Cloud").action(d.addCommand).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),S.command("delete [appId]").alias("d").description("Delete an app in Capgo Cloud").action(P.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account"),S.command("list").alias("l").description("list apps in Capgo Cloud").action(m.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),S.command("debug [appId]").alias("d").description("Listen for live updates event in Capgo Cloud to debug your app").option("-a, --apikey <apikey>","apikey to link to your account").option("-d, --device <device>","the specific device to debug").action(x.debugApp),S.command("watch [port]").alias("w").description("watch for changes in your app and allow capgo app or your app to see changes in live").action(O.watchApp),S.command("set [appId]").alias("s").description("Set an app in Capgo Cloud").action(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 j=i.program.command("bundle").description("Manage bundle");j.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("--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"),j.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"),j.command("list [appId]").alias("l").description("List bundle in Capgo Cloud").action(l.listBundle).option("-a, --apikey <apikey>","apikey to link to your account"),j.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"),j.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"),j.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"),j.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"),j.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 $=i.program.command("channel").description("Manage channel");$.command("add [channelId] [appId]").alias("a").description("Create channel").action(_.addChannelCommand).option("-d, --default","set the channel as default"),$.command("delete [channelId] [appId]").alias("d").description("Delete channel").action(w.deleteChannel),$.command("list [appId]").alias("l").description("List channel").action(k.listChannels),$.command("set [channelId] [appId]").alias("s").description("Set channel").action(y.setChannel).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the file to set").option("-s, --state <state>","set the state of the channel, default or normal").option("--latest","get the latest version key in the package.json to set it to the channel").option("--downgrade","Allow to downgrade to version under native one").option("--no-downgrade","Disable downgrade to version under native one").option("--upgrade","Allow to upgrade to version above native one").option("--no-upgrade","Disable upgrade to version above native one").option("--ios","Allow sending update to ios devices").option("--no-ios","Disable sending update to ios devices").option("--android","Allow sending update to android devices").option("--no-android","Disable sending update to android devices").option("--self-assign","Allow to device to self assign to this channel").option("--no-self-assign","Disable devices to self assign to this channel");const A=i.program.command("key").description("Manage key");A.command("save").description("Save base64 signing key in capacitor config, usefull for CI").action(u.saveKeyCommand).option("-f, --force","force generate a new one").option("--key","key path to save in capacitor config").option("--key-data","key data to save in capacitor config"),A.command("create").description("Create a new signing key").action(u.createKeyCommand).option("-f, --force","force generate a new one"),i.program.command("upload [appId]").alias("u").description("(Deprecated) Upload a new bundle to Capgo Cloud").action(g.uploadDeprecatedCommand).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to Capgo Cloud").option("--key <key>","custom path for public signing key").option("--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={}),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={}),r.plugins.CapacitorUpdater||(r.plugins.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")},3422:e=>{e.exports=require("cloudflared")},7304:e=>{e.exports=require("commander")},3847:e=>{e.exports=require("console-table-printer")},4470:e=>{e.exports=require("fs-extra")},5362:e=>{e.exports=require("get-latest-version")},1133:e=>{e.exports=require("logsnag")},9011:e=>{e.exports=require("mime")},6634:e=>{e.exports=require("open")},9867:e=>{e.exports=require("prettyjson")},1616:e=>{e.exports=require("prompt-sync")},1121:e=>{e.exports=require("qrcode")},1505:e=>{e.exports=require("semver/preload")},2081:e=>{e.exports=require("child_process")},6113:e=>{e.exports=require("crypto")},7147:e=>{e.exports=require("fs")},2037:e=>{e.exports=require("os")},1017:e=>{e.exports=require("path")},4147:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"3.13.27","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"engines":{"npm":">=7.0.0","node":">=16.0.0"},"keywords":["appflow alternative","ionic","capacitor","auto update","live update","capgo","cli","upload","capgo-cli"],"scripts":{"dev":"set NODE_ENV=development && npx webpack --config webpack.config.js","no-debug":"node dist/index.js","test":"npx --yes ts-node -T src/index.ts","build":"npx --yes webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","types":"npx --yes supabase gen types typescript --project-id=xvwzpoazmxkqosrdewyv > src/types/supabase.types.ts","test_rls":"ts-node ./test/test_headers_rls.ts","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"5.2.2","@capgo/find-package-manager":"^0.0.7","@clack/prompts":"^0.7.0","@supabase/supabase-js":"^2.32.0","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","axios":"^1.4.0","ci-info":"^3.8.0","cloudflared":"^0.4.0","commander":"11.0.0","console-table-printer":"^2.11.2","fs-extra":"11.1.1","get-latest-version":"^5.1.0","logsnag":"^0.1.8","mime":"^3.0.0","open":"^9.1.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","qrcode":"^1.5.3","semver":"^7.5.4"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/fs-extra":"^11.0.1","@types/mime":"^3.0.1","@types/node":"^20.4.9","@types/npmcli__ci-detect":"^2.0.0","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/qrcode":"^1.5.1","@types/semver":"^7.5.0","@typescript-eslint/eslint-plugin":"5.56.0","@typescript-eslint/parser":"5.56.0","eslint":"8.47.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^9.0.0","eslint-import-resolver-typescript":"3.6.0","eslint-plugin-import":"2.28.0","eslint-plugin-prettier":"^5.0.0","git-format-staged":"3.0.0","husky":"^8.0.3","nodemon":"3.0.1","pkg":"5.8.1","prettier":"3.0.2","ts-loader":"^9.4.4","ts-node":"^10.9.1","tsconfig-paths":"4.2.0","typescript":"5.1.6","webpack":"5.88.2","webpack-cli":"^5.1.4","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t].call(r.exports,r,r.exports,n),r.exports}(4999)})();
|
|
2
|
+
(()=>{"use strict";var e={9218:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{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)})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/cli",
|
|
3
|
-
"version": "3.13.
|
|
3
|
+
"version": "3.13.30",
|
|
4
4
|
"description": "A CLI to upload to capgo servers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -51,7 +51,6 @@
|
|
|
51
51
|
"adm-zip": "^0.5.10",
|
|
52
52
|
"axios": "^1.4.0",
|
|
53
53
|
"ci-info": "^3.8.0",
|
|
54
|
-
"cloudflared": "^0.4.0",
|
|
55
54
|
"commander": "11.0.0",
|
|
56
55
|
"console-table-printer": "^2.11.2",
|
|
57
56
|
"fs-extra": "11.1.1",
|
package/src/bundle/decrypt.ts
CHANGED
|
@@ -28,7 +28,7 @@ export const decryptZip = async (zipPath: string, ivsessionKey: string, options:
|
|
|
28
28
|
const keyPath = options.key || baseKey
|
|
29
29
|
// check if publicKey exist
|
|
30
30
|
|
|
31
|
-
let
|
|
31
|
+
let privateKey = extConfig?.plugins?.CapacitorUpdater?.privateKey
|
|
32
32
|
|
|
33
33
|
if (!existsSync(keyPath) && !privateKey) {
|
|
34
34
|
program.error(`Cannot find public key ${keyPath} or as keyData option or in ${config.app.extConfigFilePath}`)
|
|
@@ -40,7 +40,8 @@ export const decryptZip = async (zipPath: string, ivsessionKey: string, options:
|
|
|
40
40
|
// console.log('privateKey', privateKey)
|
|
41
41
|
|
|
42
42
|
const zipFile = readFileSync(zipPath)
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
const decodedZip = decryptSource(zipFile, ivsessionKey, options.keyData ?? privateKey ?? '')
|
|
44
45
|
// write decodedZip in a file
|
|
45
46
|
writeFileSync(`${zipPath}_decrypted.zip`, decodedZip)
|
|
46
47
|
p.outro(`Decrypted zip file at ${zipPath}_decrypted.zip`);
|
package/src/bundle/upload.ts
CHANGED
|
@@ -31,6 +31,7 @@ interface Options extends OptionsBase {
|
|
|
31
31
|
keyData?: string,
|
|
32
32
|
ivSessionKey?: string,
|
|
33
33
|
bundleUrl?: boolean
|
|
34
|
+
codeCheck?: boolean
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export const uploadBundle = async (appid: string, options: Options, shouldExit = true) => {
|
|
@@ -48,6 +49,7 @@ export const uploadBundle = async (appid: string, options: Options, shouldExit =
|
|
|
48
49
|
const localS3: boolean = (config.app.extConfig.plugins && config.app.extConfig.plugins.CapacitorUpdater
|
|
49
50
|
&& config.app.extConfig.plugins.CapacitorUpdater.localS3) === true;
|
|
50
51
|
|
|
52
|
+
const checkNotifyAppReady = options.codeCheck
|
|
51
53
|
appid = appid || config?.app?.appId
|
|
52
54
|
// create bundle name format : 1.0.0-beta.x where x is a uuid
|
|
53
55
|
const uuid = randomUUID().split('-')[0];
|
|
@@ -72,11 +74,13 @@ export const uploadBundle = async (appid: string, options: Options, shouldExit =
|
|
|
72
74
|
program.error('');
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
if (typeof checkNotifyAppReady === 'undefined' || checkNotifyAppReady) {
|
|
78
|
+
const isPluginConfigured = searchInDirectory(path, 'notifyAppReady')
|
|
76
79
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
if (!isPluginConfigured) {
|
|
81
|
+
p.log.error(`Did not find a call to notifyAppReady() in the source code. see: https://capgo.app/docs/plugin/api/#notifyappready`);
|
|
82
|
+
program.error('');
|
|
83
|
+
}
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
p.log.info(`Upload ${appid}@${bundle} started from path "${path}" to Capgo cloud`);
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { deleteChannel } from './channel/delete';
|
|
|
19
19
|
import { listChannels } from './channel/list';
|
|
20
20
|
import { setApp } from './app/set';
|
|
21
21
|
import { deleteApp } from './app/delete';
|
|
22
|
-
import { watchApp } from './app/watch';
|
|
22
|
+
// import { watchApp } from './app/watch';
|
|
23
23
|
import { debugApp } from './app/debug';
|
|
24
24
|
|
|
25
25
|
program
|
|
@@ -82,11 +82,11 @@ app
|
|
|
82
82
|
.option('-d, --device <device>', 'the specific device to debug')
|
|
83
83
|
.action(debugApp);
|
|
84
84
|
|
|
85
|
-
app
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
// app
|
|
86
|
+
// .command('watch [port]')
|
|
87
|
+
// .alias('w')
|
|
88
|
+
// .description('watch for changes in your app and allow capgo app or your app to see changes in live')
|
|
89
|
+
// .action(watchApp);
|
|
90
90
|
|
|
91
91
|
app
|
|
92
92
|
.command('set [appId]')
|
|
@@ -116,6 +116,7 @@ bundle
|
|
|
116
116
|
.option('--key-data <keyData>', 'base64 public signing key')
|
|
117
117
|
.option('--bundle-url', 'prints bundle url into stdout')
|
|
118
118
|
.option('--no-key', 'ignore signing key and send clear update')
|
|
119
|
+
.option('--no-code-check', 'Ignore checking if notifyAppReady() is called in soure code')
|
|
119
120
|
.option('--display-iv-session', 'Show in the console the iv and session key used to encrypt the update')
|
|
120
121
|
.option('-b, --bundle <bundle>', 'bundle version number of the bundle to upload');
|
|
121
122
|
|
package/src/key.ts
CHANGED
|
@@ -43,7 +43,10 @@ export const saveKey = async (options: saveOptions, log = true) => {
|
|
|
43
43
|
|
|
44
44
|
if (extConfig) {
|
|
45
45
|
if (!extConfig.plugins) {
|
|
46
|
-
extConfig.plugins = {
|
|
46
|
+
extConfig.plugins = {
|
|
47
|
+
extConfig: {},
|
|
48
|
+
CapacitorUpdater: {}
|
|
49
|
+
};
|
|
47
50
|
}
|
|
48
51
|
if (!extConfig.plugins.CapacitorUpdater) {
|
|
49
52
|
extConfig.plugins.CapacitorUpdater = {};
|
|
@@ -99,10 +102,10 @@ export const createKey = async (options: Options, log = true) => {
|
|
|
99
102
|
const { extConfig } = config.app;
|
|
100
103
|
if (extConfig) {
|
|
101
104
|
if (!extConfig.plugins) {
|
|
102
|
-
extConfig.plugins = {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
extConfig.plugins = {
|
|
106
|
+
extConfig: {},
|
|
107
|
+
CapacitorUpdater: {}
|
|
108
|
+
};
|
|
106
109
|
}
|
|
107
110
|
extConfig.plugins.CapacitorUpdater.privateKey = privateKey;
|
|
108
111
|
// console.log('extConfig', extConfig)
|
package/src/live.ts
CHANGED
|
@@ -10,13 +10,14 @@ export const setLive = async (options: Options) => {
|
|
|
10
10
|
const config = await getConfig();
|
|
11
11
|
const { extConfig } = config.app;
|
|
12
12
|
let server = {}
|
|
13
|
-
if (
|
|
14
|
-
extConfig.server = {
|
|
13
|
+
if (typeof extConfig.server !== 'undefined') {
|
|
14
|
+
extConfig.server = {
|
|
15
|
+
url: options.url!,
|
|
16
|
+
cleartext: true
|
|
17
|
+
};
|
|
15
18
|
} else {
|
|
16
19
|
server = extConfig.server;
|
|
17
20
|
}
|
|
18
|
-
extConfig.server.url = options.url;
|
|
19
|
-
extConfig.server.cleartext = true;
|
|
20
21
|
writeConfig(extConfig, config.app.extConfigFilePath);
|
|
21
22
|
return server
|
|
22
23
|
}
|
package/src/utils.ts
CHANGED
|
@@ -203,7 +203,28 @@ interface Config {
|
|
|
203
203
|
version: string;
|
|
204
204
|
};
|
|
205
205
|
extConfigFilePath: string;
|
|
206
|
-
extConfig:
|
|
206
|
+
extConfig: {
|
|
207
|
+
extConfig: object;
|
|
208
|
+
plugins: {
|
|
209
|
+
extConfig: object;
|
|
210
|
+
CapacitorUpdater: {
|
|
211
|
+
autoUpdate?: boolean;
|
|
212
|
+
localS3?: boolean;
|
|
213
|
+
localHost?: string;
|
|
214
|
+
localWebHost?: string;
|
|
215
|
+
localSupa?: string;
|
|
216
|
+
localSupaAnon?: string;
|
|
217
|
+
statsUrl?: string;
|
|
218
|
+
channelUrl?: string;
|
|
219
|
+
updateUrl?: string;
|
|
220
|
+
privateKey?: string;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
server: {
|
|
224
|
+
cleartext: boolean
|
|
225
|
+
url: string
|
|
226
|
+
}
|
|
227
|
+
}
|
|
207
228
|
};
|
|
208
229
|
}
|
|
209
230
|
|
package/src/app/watch.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { program } from 'commander';
|
|
2
|
-
import * as p from '@clack/prompts';
|
|
3
|
-
import QRCode from 'qrcode';
|
|
4
|
-
import { tunnel } from "cloudflared";
|
|
5
|
-
import { Options } from '../api/app';
|
|
6
|
-
import { createSupabaseClient, findSavedKey, useLogSnag, verifyUser } from '../utils';
|
|
7
|
-
import { checkLatest } from '../api/update';
|
|
8
|
-
|
|
9
|
-
export const watch = async (port: string, options: Options, shouldExit = true) => {
|
|
10
|
-
|
|
11
|
-
options.apikey = options.apikey || findSavedKey()
|
|
12
|
-
if (!options.apikey) {
|
|
13
|
-
if (shouldExit) {
|
|
14
|
-
program.error("Missing API key, you need to provide a API key to upload your bundle");
|
|
15
|
-
}
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
await checkLatest();
|
|
19
|
-
p.intro(`Capgo live reload`);
|
|
20
|
-
|
|
21
|
-
// write in file .capgo the apikey in home directory
|
|
22
|
-
try {
|
|
23
|
-
|
|
24
|
-
const snag = useLogSnag()
|
|
25
|
-
|
|
26
|
-
const supabase = createSupabaseClient(options.apikey)
|
|
27
|
-
const userId = await verifyUser(supabase, options.apikey, ['write', 'all', 'upload']);
|
|
28
|
-
await snag.publish({
|
|
29
|
-
channel: 'app',
|
|
30
|
-
event: 'live reload',
|
|
31
|
-
icon: '🔄',
|
|
32
|
-
tags: {
|
|
33
|
-
'user-id': userId,
|
|
34
|
-
},
|
|
35
|
-
notify: false,
|
|
36
|
-
}).catch()
|
|
37
|
-
p.log.info(`Init to tunnel`);
|
|
38
|
-
const { url, connections, stop } = tunnel({ "--url": `localhost:${port}` });
|
|
39
|
-
|
|
40
|
-
p.log.info(`Connection to tunnel`);
|
|
41
|
-
await connections[0];
|
|
42
|
-
|
|
43
|
-
p.log.info(`Get URL`);
|
|
44
|
-
|
|
45
|
-
const link = await url;
|
|
46
|
-
// const link = 'https://google.com';
|
|
47
|
-
if (!link) {
|
|
48
|
-
throw new Error('No link found');
|
|
49
|
-
}
|
|
50
|
-
p.log.info(`Tunnel ${link} connected to localhost:${port}`);
|
|
51
|
-
// add to supabase app_live
|
|
52
|
-
await supabase
|
|
53
|
-
.from('app_live')
|
|
54
|
-
.upsert({
|
|
55
|
-
id: userId,
|
|
56
|
-
url: link,
|
|
57
|
-
})
|
|
58
|
-
.throwOnError()
|
|
59
|
-
const qrUrl = await QRCode.toString(link, { type: 'terminal', small: true });
|
|
60
|
-
p.log.info(qrUrl);
|
|
61
|
-
// loop on connections and wait for all to be done
|
|
62
|
-
// for (const connection of connections) {
|
|
63
|
-
// console.log('connection done', res);
|
|
64
|
-
// }
|
|
65
|
-
// await Promise.all(connections);
|
|
66
|
-
// Promise.all(connections).then();
|
|
67
|
-
|
|
68
|
-
await p.confirm({ message: `When done say yes to close tunnel` });
|
|
69
|
-
await stop();
|
|
70
|
-
// delete to supabase app_live
|
|
71
|
-
await supabase
|
|
72
|
-
.from('app_live')
|
|
73
|
-
.delete()
|
|
74
|
-
.eq('id', userId)
|
|
75
|
-
.throwOnError()
|
|
76
|
-
p.log.info(`Tunnel closed`);
|
|
77
|
-
} catch (e) {
|
|
78
|
-
console.error('Error', e);
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
if (shouldExit) {
|
|
82
|
-
p.outro(`Done ✅`);
|
|
83
|
-
process.exit()
|
|
84
|
-
}
|
|
85
|
-
return true
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export const watchApp = async (apikey: string, options: Options) => {
|
|
89
|
-
watch(apikey, options, true)
|
|
90
|
-
}
|