@capgo/cli 3.13.31 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [3.14.0](https://github.com/Cap-go/capgo-cli/compare/v3.13.31...v3.14.0) (2023-09-27)
6
+
7
+
8
+ ### Features
9
+
10
+ * add index check in upload ([09bcecc](https://github.com/Cap-go/capgo-cli/commit/09bcecc75534e802fb0a415ff880219a096d3959))
11
+
5
12
  ### [3.13.31](https://github.com/Cap-go/capgo-cli/compare/v3.13.30...v3.13.31) (2023-09-20)
6
13
 
7
14
 
package/README.md CHANGED
@@ -21,7 +21,7 @@ Optionally, you can give:
21
21
  - `--local` to save the API key in the local folder.
22
22
 
23
23
  ## Add new app to Cloud
24
- `npx @capgo/cli add [appId]`
24
+ `npx @capgo/cli app add [appId]`
25
25
  `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init)
26
26
  > 💡 All option will be guessed in your config if not provided.
27
27
 
@@ -39,7 +39,7 @@ Example of capacitor.config.json for appId and AppName, the icon is guess in the
39
39
  }
40
40
  ```
41
41
  ### Send version to Cloud
42
- `npx @capgo/cli upload [appId]`
42
+ `npx @capgo/cli bundle upload [appId]`
43
43
  `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init)
44
44
  Optionally, you can give:
45
45
  - `--apikey [key]` API key to link to your account.
@@ -51,6 +51,7 @@ Optionally, you can give:
51
51
  - `--no-key` to ignore signing key and send clear update.
52
52
  - `--bundle [1.0.0]` to set the bundle version number of the file to upload.
53
53
  - `--iv-session-key [key]` to send a custom session key to the cloud.
54
+ - `--no-code-check` to ignore code check and send the update.
54
55
  - `--bundle-url` prints bundle url into stdout. Useful when [parsing bundle url from shell](https://github.com/Cap-go/CLI/pull/132).
55
56
 
56
57
  > ⭐️ External option help to unlock 2 cases: corporate with privacy concern, don't send the code to a third part and app bigger than 30 MB. With this setting, Capgo store only the link to the zip and send the link to all app.
@@ -104,22 +105,23 @@ Optionally, you can give:
104
105
  - `--apikey [key]` API key to link to your account.
105
106
 
106
107
  ### List versions
107
- `npx @capgo/cli list [appId] `
108
+ `npx @capgo/cli app list [appId] `
108
109
  `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init).
109
110
 
110
111
  ### Doctor installed package
111
112
  `npx @capgo/cli doctor`
112
113
  Learn info about the Capgo package installed on your project and see if update are available.
113
114
 
114
- ### Delete package to Cloud
115
- `npx @capgo/cli delete [appId]`
115
+ ### Delete bundle to Cloud
116
+ `npx @capgo/cli bundle delete [appId]`
116
117
  `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init).
117
118
 
118
119
  Optionally, you can give:
119
120
  - `--apikey [key]` API key to link to your account.
120
121
  - `--bundle [bundleVersion]` with the version number will only delete this version
121
- ### Cleanup older packages in a SemVer range for a major version to Cloud
122
- `npx @capgo/cli cleanup [appId] --bundle=[majorVersion] --keep=[numberToKeep]`
122
+
123
+ ### Cleanup older bundles in a SemVer range for a major version to Cloud
124
+ `npx @capgo/cli bundle cleanup [appId] --bundle=[majorVersion] --keep=[numberToKeep]`
123
125
  `[appId]` your app ID the format `com.test.app` is explained [here](https://capacitorjs.com/docs/cli/init).
124
126
 
125
127
  Optionally, you can give:
@@ -129,12 +131,12 @@ Optionally, you can give:
129
131
 
130
132
  For example:
131
133
  If you have 10 versions from 10.0.1 to 10.0.11, and you use
132
- `npx @capgo/cli cleanup [appId] --bundle=10.0.0`
134
+ `npx @capgo/cli bundle cleanup [appId] --bundle=10.0.0`
133
135
  it will remove 10.0.1 to 10.0.6.
134
136
  10.0.7 until 10.0.11 will be kept.
135
137
 
136
138
  If you have 20 versions in total, and you don't provide a bundle number like this:
137
- `npx @capgo/cli cleanup [appId] --keep=2`
139
+ `npx @capgo/cli bundle cleanup [appId] --keep=2`
138
140
  It will remove 18 versions, and keep the last 2.
139
141
 
140
142
  > This command will ask for confirmation, it shows a table of what it will be keeping and removing.
@@ -171,7 +173,7 @@ Optionally, you can give:
171
173
  This command is useful if you followed the recommendation and didn't commit the key in your app, and in the config.
172
174
 
173
175
  ### Encrypt zip with your key
174
- `npx @capgo/cli encrypt [path/to/zip]`
176
+ `npx @capgo/cli bundle encrypt [path/to/zip]`
175
177
  Optionally, you can give:
176
178
  `--key [/path/to/my/private_key]` the path of your private key.
177
179
  `--key-data [privateKey]` the private key data, if you want to use inline.
@@ -183,7 +185,7 @@ For CI/CD you can get the sssion key that way for next step: [parsing bundle url
183
185
 
184
186
 
185
187
  ### Decrypt zip with your key
186
- `npx @capgo/cli encrypt [path/to/zip] [ivSessionKey]`
188
+ `npx @capgo/cli bundle encrypt [path/to/zip] [ivSessionKey]`
187
189
 
188
190
  Optionally, you can give:
189
191
  `--key [/path/to/my/private_key]` the path of your private key.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- (()=>{"use strict";var e={9218:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.newIconPath=o.checkAppExistsAndHasPermissionErr=o.checkAppExistsAndHasPermission=void 0;const i=n(7304);o.checkAppExistsAndHasPermission=(e,o,n=!0)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.rpc("exist_app_v2",{appid:o}).single();return t!==n||i})),o.checkAppExistsAndHasPermissionErr=(e,n,r=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.checkAppExistsAndHasPermission)(e,n,r))&&i.program.error(`App ${n} does not exist or you don't have permission to access it`)})),o.newIconPath="assets/icon.png"},6824:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getActiveChannels=o.displayChannels=o.delChannel=o.createChannel=o.findUnknownVersion=o.checkVersionNotUsedInChannel=void 0;const l=n(7304),c=n(3847),s=r(n(552)),d=n(6545);o.checkVersionNotUsedInChannel=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){var r;const{data:a,error:c}=yield e.from("channels").select().eq("app_id",n).eq("created_by",t).eq("version",i.id);if(c&&l.program.error(`Cannot check Version ${n}@${i.name} ${(0,d.formatError)(c)}`),a&&a.length>0){if(s.intro(`❌ Version ${n}@${i.name} is used in ${a.length} channel`),yield s.confirm({message:"unlink it?"}))for(const t of a){const i=s.spinner();i.start(`Unlinking channel ${t.name}`);const{error:a}=yield e.from("channels").update({version:null===(r=yield(0,o.findUnknownVersion)(e,n))||void 0===r?void 0:r.id}).eq("id",t.id);a&&(i.stop(`Cannot update channel ${t.name} ${(0,d.formatError)(a)}`),process.exit(1)),i.stop(`✅ Channel ${t.name} unlinked`)}else l.program.error("unlink it first");s.outro(`Version unlinked from ${a.length} channel`)}})),o.findUnknownVersion=(e,o)=>e.from("app_versions").select("id").eq("app_id",o).eq("name","unknown").throwOnError().single().then((({data:e})=>e)),o.createChannel=(e,o)=>e.from("channels").insert(o).select().single(),o.delChannel=(e,o,n,t)=>e.from("channels").delete().eq("name",o).eq("app_id",n).eq("created_by",t).single(),o.displayChannels=e=>{const o=new c.Table({title:"Channels",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,d.getHumanDate)(e.created_at),Public:e.public?"✅":"❌"})})),s.log.success(o.render())},o.getActiveChannels=(e,o,n)=>a(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).order("created_at",{ascending:!1});return i&&l.program.error(`App ${o} not found in database ${(0,d.formatError)(i)} `),t}))},407:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createRSA=o.encryptSource=o.decryptSource=void 0;const t=n(6113),i="aes-128-cbc",r="sha256",a="base64",l=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[c,s]=o.split(":"),d=(0,t.privateDecrypt)({key:n,padding:l,oaepHash:r},Buffer.from(s,a)),p=Buffer.from(c,a),u=(0,t.createDecipheriv)(i,d,p);return u.setAutoPadding(!0),Buffer.concat([u.update(e),u.final()])},o.encryptSource=(e,o)=>{const n=(0,t.randomBytes)(16),c=(0,t.randomBytes)(16),s=(0,t.createCipheriv)(i,c,n);s.setAutoPadding(!0);const d=`${n.toString(a)}:${(0,t.publicEncrypt)({key:o,padding:l,oaepHash:r},c).toString(a)}`;return{encryptedData:Buffer.concat([s.update(e),s.final()]),ivSessionKey:d}},o.createRSA=()=>{const{publicKey:e,privateKey:o}=(0,t.generateKeyPairSync)("rsa",{modulusLength:2048});return{publicKey:e.export({type:"pkcs1",format:"pem"}),privateKey:o.export({type:"pkcs1",format:"pem"})}}},7863:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const l=n(7304),c=r(n(552)),s=n(6545);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>a(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);if(i&&l.program.error(`Cannot check Device override ${o}@${n.name} ${(0,s.formatError)(i)}`),t&&t.length>0)if(c.intro(`❌ Version ${o}@${n.name} is used in ${t.length} device override`),yield c.confirm({message:"unlink it?"}))for(const o of t){const n=c.spinner();n.start(`Unlinking device ${o.device_id}`);const{error:t}=yield e.from("devices_override").delete().eq("device_id",o.device_id);t&&(n.stop(`Cannot unlink device ${o.device_id} ${(0,s.formatError)(t)}`),process.exit(1)),n.stop(`✅ Device ${o.device_id} unlinked`)}else l.program.error("unlink it first")}))},1954:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(7304),r=n(6545);o.deleteFromStorage=(e,o,n,a,l)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${a.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${l} ${(0,r.formatError)(t)} `)}))},7482:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.checkLatest=void 0;const c=l(n(5362)),s=r(n(552)),d=l(n(4147));o.checkLatest=()=>a(void 0,void 0,void 0,(function*(){const e=yield(0,c.default)("@capgo/cli");e!==d.default.version&&s.log.warning(`🚨 You are using @capgo/cli@${d.default.version} it's not the latest version.\nPlease use @capgo/cli@${e}" or @capgo/cli@latest to keep up to date with the latest features and bug fixes.`)}))},9656:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getVersionData=o.getChannelsVersion=o.getActiveAppVersions=o.displayBundles=o.deleteSpecificVersion=o.deleteAppVersion=void 0;const l=n(7304),c=n(3847),s=r(n(552)),d=n(6545),p=n(6824),u=n(7863),f=n(1954);o.deleteAppVersion=(e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const{error:i}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("deleted",!1).eq("user_id",n).eq("name",t);i&&l.program.error(`App Version ${o}@${t} not found in database '${(0,d.formatError)(i)}'`)})),o.deleteSpecificVersion=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){const r=yield(0,o.getVersionData)(e,n,t,i);yield(0,p.checkVersionNotUsedInChannel)(e,n,t,r),yield(0,u.checkVersionNotUsedInDeviceOverride)(e,n,r),yield(0,f.deleteFromStorage)(e,t,n,r,i),yield(0,o.deleteAppVersion)(e,n,t,i)})),o.displayBundles=e=>{const o=new c.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,d.getHumanDate)(e.created_at)},null!=e.keep?{Keep:e.keep}:{}))})),s.log.success(o.render())},o.getActiveAppVersions=(e,o,n)=>a(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return i&&l.program.error(`App ${o} not found in database ${(0,d.formatError)(i)} `),t})),o.getChannelsVersion=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.from("channels").select("version").eq("app_id",o);return t&&l.program.error(`App ${o} not found in database ${(0,d.formatError)(t)} `),n.map((e=>e.version))})),o.getVersionData=(e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const{data:i,error:r}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("name",t).eq("deleted",!1).single();return i&&!r||l.program.error(`App Version ${o}@${t} doesn't exist ${(0,d.formatError)(r)}`),i}))},7171:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addCommand=o.addApp=void 0;const l=n(6113),c=n(9011),s=n(7304),d=r(n(552)),p=n(4470),u=n(7482),f=n(9218),y=n(6545);o.addApp=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){var t,i,r;n&&d.intro("Adding"),yield(0,u.checkLatest)(),o.apikey=o.apikey||(0,y.findSavedKey)();const a=yield(0,y.getConfig)();e=e||(null===(t=null==a?void 0:a.app)||void 0===t?void 0:t.appId);const g=(0,y.useLogSnag)();o.apikey||(d.log.error("Missing API key, you need to provide a API key to upload your bundle"),s.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),s.program.error(""));const v=(0,y.createSupabaseClient)(o.apikey),h=yield(0,y.verifyUser)(v,o.apikey,["write","all"]);if(n)yield(0,f.checkAppExistsAndHasPermissionErr)(v,e,!1);else if(yield(0,f.checkAppExistsAndHasPermission)(v,e,!1))return!1;let m,b,{name:_,icon:k}=o;e=e||(null===(i=null==a?void 0:a.app)||void 0===i?void 0:i.appId),_=_||(null===(r=null==a?void 0:a.app)||void 0===r?void 0:r.appName)||"Unknown",k=k||"resources/icon.png",k&&_||(d.log.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project"),s.program.error("")),n&&d.log.info(`Adding ${e} to Capgo`),k&&(0,p.existsSync)(k)?(m=(0,p.readFileSync)(k),b=(0,c.getType)(k)||"image/png",d.log.warn(`Found app icon ${k}`)):(0,p.existsSync)(f.newIconPath)?(m=(0,p.readFileSync)(f.newIconPath),b=(0,c.getType)(f.newIconPath)||"image/png",d.log.warn(`Found app icon ${f.newIconPath}`)):d.log.warn(`Cannot find app icon in any of the following locations: ${k}, ${f.newIconPath}`);const w=`icon_${(0,l.randomUUID)()}`;let C="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(m&&b){const{error:o}=yield v.storage.from(`images/${h}/${e}`).upload(w,m,{contentType:b});o&&(d.log.error(`Could not add app ${(0,y.formatError)(o)}`),s.program.error(""));const{data:n}=yield v.storage.from(`images/${h}/${e}`).getPublicUrl(w);C=(null==n?void 0:n.publicUrl)||C}const{error:P}=yield v.from("apps").insert({icon_url:C,user_id:h,name:_,app_id:e});P&&(d.log.error(`Could not add app ${(0,y.formatError)(P)}`),s.program.error(""));const{error:O}=yield v.from("app_versions").insert([{user_id:h,deleted:!0,name:"unknown",app_id:e},{user_id:h,deleted:!0,name:"builtin",app_id:e}]);return O&&(d.log.error(`Could not add app ${(0,y.formatError)(O)}`),s.program.error("")),yield g.track({channel:"app",event:"App Added",icon:"🎉",user_id:h,tags:{"app-id":e},notify:!1}).catch(),d.log.success(`App ${e} added to Capgo. ${n?"You can upload a bundle now":""}`),n&&(d.outro("Done ✅"),process.exit()),!0})),o.addCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.addApp)(e,n,!0)}))},7626:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.debugApp=o.waitLog=o.cancelCommand=o.markSnag=void 0;const l=r(n(552)),c=n(7304),s=n(9218),d=n(7482),p=n(6545),u=e=>new Promise((o=>{setTimeout(o,e)}));o.markSnag=(e,o,n,t,i="✅")=>a(void 0,void 0,void 0,(function*(){yield n.track({channel:e,event:t,icon:i,user_id:o,notify:!1}).catch()})),o.cancelCommand=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){l.isCancel(n)&&(yield(0,o.markSnag)(e,t,i,"canceled","🤷"),process.exit())})),o.waitLog=(e,n,t,i,r,c)=>a(void 0,void 0,void 0,(function*(){let a=!0,s=(new Date).toISOString();const d=(0,p.convertAppName)(t),f=`${p.hostWeb}/app/p/${d}`;for(yield(0,o.markSnag)(e,r,i,"Use waitlog");a;){const d=n.from("stats").select("*").eq("app_id",t).order("created_at",{ascending:!1}).gte("created_at",s);c&&d.eq("device_id",c);const{data:p,error:y}=yield d.limit(1).single();if(p&&!y){if(l.log.info(`Device: ${p.device_id}`),"get"===p.action)l.log.info("Update Sent your your device, wait until event download complete"),yield(0,o.markSnag)(e,r,i,"done");else if(p.action.startsWith("download_")){const n=p.action.split("_")[1];"complete"===n?(l.log.info("Your bundle has been downloaded on your device, background the app now and open it again to see the update"),yield(0,o.markSnag)(e,r,i,"downloaded")):"fail"===n?(l.log.error("Your bundle has failed to download on your device."),l.log.error("Please check if you have network connection and try again")):l.log.info(`Your bundle is downloading ${n}% ...`)}else{if("set"===p.action)return l.log.info("Your bundle has been set on your device ❤️"),a=!1,yield(0,o.markSnag)(e,r,i,"set"),Promise.resolve(p);"NoChannelOrOverride"===p.action?l.log.error(`No default channel or override (channel/device) found, please create it here ${f}`):"needPlanUpgrade"===p.action?l.log.error("Your are out of quota, please upgrade your plan here https://web.capgo.app/dashboard/settings/plans"):"missingBundle"===p.action?l.log.error("Your bundle is missing, please check how you build your app "):"noNew"===p.action?l.log.error(`Your version in ${p.platform} is the same as your version uploaded, change it to see the update`):"disablePlatformIos"===p.action?l.log.error(`iOS is disabled in the default channel and your device is an iOS device ${f}`):"disablePlatformAndroid"===p.action?l.log.error(`Android is disabled in the default channel and your device is an Android device ${f}`):"disableAutoUpdateToMajor"===p.action?(l.log.error("Auto update to major version is disabled in the default channel."),l.log.error("Set your app to the same major version as the default channel")):"disableAutoUpdateUnderNative"===p.action?(l.log.error("Auto update under native version is disabled in the default channel."),l.log.error("Set your app to the same native version as the default channel.")):"disableDevBuild"===p.action?(l.log.error(`Dev build is disabled in the default channel. ${f}`),l.log.error("Set your channel to allow it if you wanna test your app")):"disableEmulator"===p.action?(l.log.error(`Emulator is disabled in the default channel. ${f}`),l.log.error("Set your channel to allow it if you wanna test your app")):"cannotGetBundle"===p.action?(l.log.error(`We cannot get your bundle from the default channel. ${f}`),l.log.error("Are you sure your default channel has a bundle set?")):"set_fail"===p.action?l.log.error(`Your bundle seems to be corrupted, try to download from ${f} to identify the issue`):"reset"===p.action?l.log.error("Your device has been reset to the builtin bundle, did you added notifyAppReady in your code?"):"update_fail"===p.action?(l.log.error("Your bundle has been installed but failed to call notifyAppReady"),l.log.error("Please check if you have network connection and try again")):"checksum_fail"===p.action&&l.log.error("Your bundle has failed to validate checksum, please check your code and send it again to Capgo")}s=(new Date).toISOString()}yield u(1e3)}return Promise.resolve()})),o.debugApp=(e,n)=>a(void 0,void 0,void 0,(function*(){var t;l.intro("Debug Live update in Capgo"),yield(0,d.checkLatest)(),n.apikey=n.apikey||(0,p.findSavedKey)();const i=yield(0,p.getConfig)();e=e||(null===(t=null==i?void 0:i.app)||void 0===t?void 0:t.appId);const r=n.device;n.apikey||(l.log.error("Missing API key, you need to provide an API key to delete your app"),c.program.error("")),e||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.program.error(""));const a=(0,p.createSupabaseClient)(n.apikey),u=(0,p.useLogSnag)(),f=yield(0,p.verifyUser)(a,n.apikey);l.log.info("Getting active bundle in Capgo"),yield(0,s.checkAppExistsAndHasPermissionErr)(a,e);const y=yield l.confirm({message:"Automatic check if update working in device ?"});yield(0,o.cancelCommand)("debug",y,f,u),y?(l.log.info(`Wait logs sent to Capgo from ${e} device, Put the app in background and open it again.`),l.log.info("Waiting..."),yield(0,o.waitLog)("debug",a,e,u,f,r),l.outro("Done ✅")):l.outro("Canceled ❌"),l.outro("Done ✅"),process.exit()}))},6626:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6545);o.deleteApp=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;c.intro("Deleting"),o.apikey=o.apikey||(0,d.findSavedKey)();const t=yield(0,d.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId);const i=(0,d.useLogSnag)();o.apikey||l.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||l.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const r=(0,d.createSupabaseClient)(o.apikey),a=yield(0,d.verifyUser)(r,o.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(r,e);const{error:p}=yield r.storage.from(`images/${a}`).remove([e]);p&&l.program.error(`Could not add app ${(0,d.formatError)(p)}`);const{error:u}=yield r.storage.from(`apps/${e}/${a}`).remove(["versions"]);u&&l.program.error(`Could not delete app version ${(0,d.formatError)(u)}`);const{error:f}=yield r.from("apps").delete().eq("app_id",e).eq("user_id",a);f&&l.program.error(`Could not delete app ${(0,d.formatError)(f)}`),yield i.track({channel:"app",event:"App Deleted",icon:"🗑️",user_id:a,tags:{"app-id":e},notify:!1}).catch(),c.log.success("App deleted in Capgo"),c.outro("Done ✅"),process.exit()}))},1628:function(e,o,n){var t=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getInfo=void 0;const r=n(7147),a=n(1017),l=i(n(2037)),c=i(n(5362)),s=i(n(7176)),d=i(n(4147));o.getInfo=()=>t(void 0,void 0,void 0,(function*(){console.log(" 💊 Capgo Doctor 💊\n"),console.log(` OS: ${l.default.version()}\n`),console.log(" Installed Dependencies:\n");const e=yield t(void 0,void 0,void 0,(function*(){const{dependencies:e}=yield t(void 0,void 0,void 0,(function*(){const e=(0,r.readFileSync)((0,a.join)(process.cwd(),"package.json"));return JSON.parse(e)})),o={"@capgo/cli":d.default.version};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&n.startsWith("@capgo/")&&(o[n]=e[n]);return o}));0===Object.keys(e).length&&(console.log("\n"),console.log("%s","🚨 No dependencies found"),process.exit(1));for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const n=e[o];console.log(` ${o}: ${n}`)}console.log("\n");const o=new s.default;o.add("loading",{text:"Loading latest dependencies"});const n=yield(e=>t(void 0,void 0,void 0,(function*(){const o={},n=[];for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.push((0,c.default)(o));return yield Promise.all(n).then((n=>{const t=Object.keys(e);for(let e=0;e<n.length;e+=1){const i=n[e];i&&(o[t[e]]=i)}})),o})))(e);o.succeed("loading",{text:"Latest Dependencies:"}),console.log("\n");for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const o=n[e];console.log(` ${e}: ${o}`)}JSON.stringify(e)!==JSON.stringify(n)&&(console.log("\n"),console.log("%s","🚨 Some dependencies are not up to date"),process.exit(1)),console.log("\n"),console.log("%s","✅ All dependencies are up to date"),process.exit()}))},8373:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=o.getActiveApps=void 0;const l=n(7304),c=n(3847),s=r(n(552)),d=n(6545),p=n(7482);o.getActiveApps=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.from("apps").select().eq("user_id",o).order("created_at",{ascending:!1});return t&&l.program.error(`Apps not found in database ${(0,d.formatError)(t)} `),n})),o.listApp=e=>a(void 0,void 0,void 0,(function*(){s.intro("List apps in Capgo"),yield(0,p.checkLatest)(),e.apikey=e.apikey||(0,d.findSavedKey)();const n=(0,d.createSupabaseClient)(e.apikey),t=yield(0,d.verifyUser)(n,e.apikey);s.log.info("Getting active bundle in Capgo");const i=yield(0,o.getActiveApps)(n,t);s.log.info(`Active app in Capgo: ${null==i?void 0:i.length}`),(e=>{const o=new c.Table({title:"Apps",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,d.getHumanDate)(e.created_at)})})),s.log.success(o.render())})(i),s.outro("Done ✅"),process.exit()}))},5789:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setApp=void 0;const l=n(6113),c=n(9011),s=n(7304),d=r(n(552)),p=n(4470),u=n(9218),f=n(6545);o.setApp=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;d.intro("Set app"),o.apikey=o.apikey||(0,f.findSavedKey)();const t=yield(0,f.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||(d.log.error("Missing API key, you need to provide a API key to upload your bundle"),s.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),s.program.error(""));const i=(0,f.createSupabaseClient)(o.apikey),r=yield(0,f.verifyUser)(i,o.apikey,["write","all"]);yield(0,u.checkAppExistsAndHasPermissionErr)(i,e);const{name:a,icon:y,retention:g}=o;let v,h;g&&!Number.isNaN(Number(g))?(d.log.error("retention value must be a number"),s.program.error("")):g&&g<0&&(d.log.error("retention value cannot be less than 0"),s.program.error(""));const m=`icon_${(0,l.randomUUID)()}`;let b="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(y&&(0,p.existsSync)(y)?(v=(0,p.readFileSync)(y),h=(0,c.getType)(y)||"image/png",d.log.warn(`Found app icon ${y}`)):(0,p.existsSync)(u.newIconPath)?(v=(0,p.readFileSync)(u.newIconPath),h=(0,c.getType)(u.newIconPath)||"image/png",d.log.warn(`Found app icon ${u.newIconPath}`)):d.log.warn(`Cannot find app icon in any of the following locations: ${y}, ${u.newIconPath}`),v&&h){const{error:o}=yield i.storage.from(`images/${r}/${e}`).upload(m,v,{contentType:h});o&&(d.log.error(`Could not add app ${(0,f.formatError)(o)}`),s.program.error(""));const{data:n}=yield i.storage.from(`images/${r}/${e}`).getPublicUrl(m);b=(null==n?void 0:n.publicUrl)||b}const{error:_}=yield i.from("apps").update({icon_url:b,name:a,retention:g?24*g*60*60:void 0}).eq("app_id",e).eq("user_id",r);_&&(d.log.error(`Could not add app ${(0,f.formatError)(_)}`),s.program.error("")),d.outro("Done ✅"),process.exit()}))},3515:function(e,o,n){var t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.searchInDirectory=void 0;const i=t(n(7147)),r=t(n(1017)),a=(e,o)=>i.default.readFileSync(e,"utf8").includes(o);o.searchInDirectory=(e,n)=>{const t=i.default.readdirSync(e);for(const l of t){const t=r.default.join(e,l),c=i.default.statSync(t);if(c.isDirectory()){if((0,o.searchInDirectory)(t,n))return!0}else if(c.isFile()&&".js"===r.default.extname(t)&&a(t,n))return!0}return!1}},2393:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__asyncValues||function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),o={},t("next"),t("throw"),t("return"),o[Symbol.asyncIterator]=function(){return this},o);function t(n){o[n]=e[n]&&function(o){return new Promise((function(t,i){!function(e,o,n,t){Promise.resolve(t).then((function(o){e({value:o,done:n})}),o)}(t,i,(o=e[n](o)).done,o.value)}))}}},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupBundle=void 0;const s=n(7304),d=c(n(1505)),p=r(n(552)),u=c(n(1616)),f=n(6545),y=n(9656),g=n(9218),v=n(7482),h=(0,u.default)();o.cleanupBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;p.intro("Cleanup versions in Capgo"),yield(0,v.checkLatest)();const t=o.apikey||(0,f.findSavedKey)(),{bundle:i,keep:r=4}=o,c=o.force||!1,u=yield(0,f.getConfig)();e=e||(null===(n=null==u?void 0:u.app)||void 0===n?void 0:n.appId),t||s.program.error("Missing API key, you need to provide an API key to delete your app"),e||s.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const m=(0,f.createSupabaseClient)(t),b=yield(0,f.verifyUser)(m,t);yield(0,g.checkAppExistsAndHasPermissionErr)(m,e),p.log.info("Querying all available versions in Capgo");let _=yield(0,y.getActiveAppVersions)(m,e,b);const k=yield(0,y.getChannelsVersion)(m,e);if(p.log.info(`Total active versions in Capgo: ${null==_?void 0:_.length}`),0===(null==_?void 0:_.length))return void p.log.error("No versions found, aborting cleanup");if(i){const e=`${d.default.inc(i,"major")}`;p.log.info(`Querying available versions in Capgo between ${i} and ${e}`),_=((e,o,n)=>{const t=[];return null==e||e.forEach((e=>{d.default.gte(e.name,o)&&d.default.lt(e.name,`${n}`)&&t.push(e)})),t})(_,i,e),p.log.info(`Active versions in Capgo between ${i} and ${e}: ${null==_?void 0:_.length}`)}const w=[];let C=0;if(_.forEach((e=>{const o=k.find((o=>o===e.id));C<r||o?(e.keep=o?"✅ (Linked to channel)":"✅",C+=1):(e.keep="❌",w.push(e))})),0!==w.length){if((0,y.displayBundles)(_),!c&&"yes"!==h("Do you want to continue removing the versions specified? Type yes to confirm: "))return void p.log.warn("Not confirmed, aborting removal...");p.log.success("You have confirmed removal, removing versions now"),yield((e,o,n,t)=>{var i,r,c;return a(void 0,void 0,void 0,(function*(){var a,s,d,u;try{for(i=!0,r=l(e);!(a=(c=yield r.next()).done);i=!0){u=c.value,i=!1;const e=u;p.log.warn(`Removing ${e.name} created on ${(0,f.getHumanDate)(e.created_at)}`),yield(0,y.deleteSpecificVersion)(o,n,t,e.name)}}catch(e){s={error:e}}finally{try{i||a||!(d=r.return)||(yield d.call(r))}finally{if(s)throw s.error}}}))})(w,m,e,b),p.outro("Done ✅"),process.exit()}else p.log.warn("Nothing to be removed, aborting removal...")}))},7978:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const l=n(7147),c=n(7304),s=r(n(552)),d=n(407),p=n(6545),u=n(7482);o.decryptZip=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i,r,a,f,y;s.intro("Decrypt zip file"),yield(0,u.checkLatest)(),(0,l.existsSync)(e)||c.program.error(`Zip not found at the path ${e}`);const g=yield(0,p.getConfig)(),{extConfig:v}=g.app;n.key||(0,l.existsSync)(p.baseKey)||(null===(i=null===(t=v.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===i?void 0:i.privateKey)||c.program.error(`Private Key not found at the path ${p.baseKey} or in ${g.app.extConfigFilePath}`);const h=n.key||p.baseKey;let m=null===(a=null===(r=null==v?void 0:v.plugins)||void 0===r?void 0:r.CapacitorUpdater)||void 0===a?void 0:a.privateKey;(0,l.existsSync)(h)||m?(0,l.existsSync)(h)&&(m=(0,l.readFileSync)(h).toString()):c.program.error(`Cannot find public key ${h} or as keyData option or in ${g.app.extConfigFilePath}`);const b=(0,l.readFileSync)(e),_=(0,d.decryptSource)(b,o,null!==(y=null!==(f=n.keyData)&&void 0!==f?f:m)&&void 0!==y?y:"");(0,l.writeFileSync)(`${e}_decrypted.zip`,_),s.outro(`Decrypted zip file at ${e}_decrypted.zip`),process.exit()}))},3930:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteBundle=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6545),p=n(9656);o.deleteBundle=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i;c.intro("Delete bundle"),n.apikey=n.apikey||(0,d.findSavedKey)();const r=yield(0,d.getConfig)();o=o||(null===(t=null==r?void 0:r.app)||void 0===t?void 0:t.appId),n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const a=(0,d.createSupabaseClient)(n.apikey),u=yield(0,d.verifyUser)(a,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(a,o);const f=n.apikey||(0,d.findSavedKey)();o=o||(null===(i=null==r?void 0:r.app)||void 0===i?void 0:i.appId),f||(c.log.error("Missing API key, you need to provide an API key to delete your app"),l.program.error("")),e||(c.log.error("Missing argument, you need to provide a bundleId, or be in a capacitor project"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error("")),c.log.info(`Deleting bundle ${o}@${e} from Capgo`),yield(0,p.deleteSpecificVersion)(a,o,u,e),c.log.success(`Bundle ${o}@${e} deleted in Capgo`),c.outro("Done"),process.exit()}))},3333:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const c=n(7147),s=n(7304),d=l(n(7812)),p=r(n(552)),u=n(7482),f=n(407),y=n(6545);o.encryptZip=(e,o)=>a(void 0,void 0,void 0,(function*(){p.intro("Encryption"),yield(0,u.checkLatest)(),(0,c.existsSync)(e)||(p.log.error(`Error: Zip not found at the path ${e}`),s.program.error(""));const n=o.key||y.baseKeyPub;let t=o.keyData||"";(0,c.existsSync)(n)||t?(0,c.existsSync)(n)&&(t=(0,c.readFileSync)(n).toString()):(p.log.warning(`Cannot find public key ${n} or as keyData option`),d.default.isCI&&(p.log.error("Error: Missing public key"),s.program.error("")),(yield p.confirm({message:"Do you want to use our public key ?"}))||(p.log.error("Error: Missing public key"),s.program.error("")),t=y.defaulPublicKey);const i=(0,c.readFileSync)(e),r=(0,f.encryptSource)(i,t);p.log.success(`ivSessionKey: ${r.ivSessionKey}`),(0,c.writeFileSync)(`${e}_encrypted.zip`,r.encryptedData),p.log.success(`Encrypted zip saved at ${e}_encrypted.zip`),p.outro("Done ✅"),process.exit()}))},2083:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listBundle=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(9656),p=n(6545),u=n(7482);o.listBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;c.intro("List bundles"),yield(0,u.checkLatest)(),o.apikey=o.apikey||(0,p.findSavedKey)();const t=yield(0,p.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),e||(c.log.error("Missing argument, you need to provide a appid, or be in a capacitor project"),l.program.error(""));const i=(0,p.createSupabaseClient)(o.apikey),r=yield(0,p.verifyUser)(i,o.apikey);c.log.info(`Querying available versions of: ${e} in Capgo`),yield(0,s.checkAppExistsAndHasPermissionErr)(i,e);const a=yield(0,d.getActiveAppVersions)(i,e,r);c.log.info(`Active versions in Capgo: ${null==a?void 0:a.length}`),(0,d.displayBundles)(a),c.outro("Done ✅"),process.exit()}))},2510:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadDeprecatedCommand=o.uploadCommand=o.uploadBundle=void 0;const c=n(6113),s=n(7147),d=l(n(3844)),p=n(7304),u=r(n(552)),f=n(5906),y=l(n(7812)),g=l(n(2167)),v=n(7482),h=n(9218),m=n(407),b=n(6545),_=n(3515);o.uploadBundle=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){var t,i,r,a;u.intro("Uploading"),yield(0,v.checkLatest)();let{bundle:l,path:k,channel:w}=o;const{external:C,key:P=!1,displayIvSession:O}=o,x=o.apikey||(0,b.findSavedKey)(),S=(0,b.useLogSnag)();w=w||"dev";const j=yield(0,b.getConfig)(),$=!0===(j.app.extConfig.plugins&&j.app.extConfig.plugins.CapacitorUpdater&&j.app.extConfig.plugins.CapacitorUpdater.localS3),A=o.codeCheck;e=e||(null===(t=null==j?void 0:j.app)||void 0===t?void 0:t.appId);const M=(0,c.randomUUID)().split("-")[0];l=l||(null===(r=null===(i=null==j?void 0:j.app)||void 0===i?void 0:i.package)||void 0===r?void 0:r.version)||`0.0.1-beta.${M}`,b.regexSemver.test(l)||(u.log.error(`Your bundle name ${l}, is not valid it should follow semver convention : https://semver.org/`),p.program.error("")),k=k||(null===(a=null==j?void 0:j.app)||void 0===a?void 0:a.webDir),x||(u.log.error("Missing API key, you need to provide a API key to upload your bundle"),p.program.error("")),e&&l&&k||(u.log.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),p.program.error("")),(0,s.existsSync)(k)||(u.log.error(`Path ${k} does not exist, build your app first, or provide a valid path`),p.program.error("")),(void 0===A||A)&&((0,_.searchInDirectory)(k,"notifyAppReady")||(u.log.error("Did not find a call to notifyAppReady() in the source code. see: https://capgo.app/docs/plugin/api/#notifyappready"),p.program.error(""))),u.log.info(`Upload ${e}@${l} started from path "${k}" to Capgo cloud`);const D=(0,b.createSupabaseClient)(x),I=yield(0,b.verifyUser)(D,x,["write","all","upload"]);yield(0,b.checkPlanValid)(D,I,!1),yield(0,h.checkAppExistsAndHasPermissionErr)(D,e);const{data:E,error:U}=yield D.rpc("is_trial",{userid:I}).single();(E&&E>0||U)&&(u.log.warn(`WARNING !!\nTrial expires in ${E} days`),u.log.warn(`Upgrade here: ${b.hostWeb}/dashboard/settings/plans`));const{data:q,error:K}=yield D.rpc("exist_app_versions",{appid:e,apikey:x,name_version:l}).single();(q||K)&&(u.log.error(`Version already exists ${(0,b.formatError)(K)}`),p.program.error(""));const B=`${l.replace(/[^a-zA-Z0-9-_.!*'()]/g,"__")}.zip`;let L,V="",F=null;if(C)C&&!C.startsWith("https://")?(u.log.error(`External link should should start with "https://" current is "${C}"`),p.program.error("")):(yield S.track({channel:"app",event:"App external",icon:"📤",user_id:I,tags:{"app-id":e},notify:!1}).catch(),L=o.ivSessionKey);else{const n=new d.default;n.addLocalFolder(k),F=n.toBuffer();const t=u.spinner();if(t.start("Calculating checksum"),V=yield(0,f.checksum)(F,"crc32"),t.stop(`Checksum: ${V}`),P||(0,s.existsSync)(b.baseKeyPub)){const n="string"==typeof P?P:b.baseKeyPub;let t=o.keyData||"";t||(0,s.existsSync)(n)||(u.log.error(`Cannot find public key ${n}`),y.default.isCI&&p.program.error(""),(yield u.confirm({message:"Do you want to use our public key ?"}))||(u.log.error("Error: Missing public key"),p.program.error("")),t=b.defaulPublicKey),yield S.track({channel:"app",event:"App encryption",icon:"🔑",user_id:I,tags:{"app-id":e},notify:!1}).catch(),t||(t=(0,s.readFileSync)(n).toString()),u.log.info("Encrypting your bundle");const i=(0,m.encryptSource)(F,t);L=i.ivSessionKey,O&&u.log.info(`Your Iv Session key is ${L},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),F=i.encryptedData}const i=Math.floor(F.byteLength/1024/1024);i>20&&(u.log.warn(`WARNING !!\nThe app size is ${i} Mb, this may take a while to download for users\n`),u.log.info("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield S.track({channel:"app-error",event:"App Too Large",icon:"🚛",user_id:I,tags:{"app-id":e},notify:!1}).catch())}const N={bucket_id:C?void 0:B,user_id:I,name:l,app_id:e,session_key:L,external_url:C,storage_provider:C?"external":"r2-direct",checksum:V},{error:z}=yield(0,b.updateOrCreateVersion)(D,N,x);if(z&&(u.log.error(`Cannot add bundle ${(0,b.formatError)(z)}`),p.program.error("")),!C&&F){const o=u.spinner();o.start("Uploading Bundle");const n=yield(0,b.uploadUrl)(D,e,B);n||(u.log.error("Cannot get upload url"),p.program.error("")),yield(0,g.default)({method:"put",url:n,data:F,headers:$?void 0:{"Content-Type":"application/octet-stream","Cache-Control":"public, max-age=456789, immutable","x-amz-meta-crc32":V}}),N.storage_provider="r2";const{error:t}=yield(0,b.updateOrCreateVersion)(D,N,x);t&&(u.log.error(`Cannot update bundle ${(0,b.formatError)(z)}`),p.program.error("")),o.stop("Bundle Uploaded 💪")}const{data:T}=yield D.rpc("get_app_versions",{apikey:x,name_version:l,appid:e}).single();if(T){const{error:n,data:t}=yield(0,b.updateOrCreateChannel)(D,{name:w,app_id:e,created_by:I,version:T});n&&(u.log.error('Cannot set channel, the upload key is not allowed to do that, use the "all" for this.'),p.program.error(""));const i=(0,b.convertAppName)(e),r=`${b.hostWeb}/app/p/${i}/channel/${t.id}`;(null==t?void 0:t.public)?u.log.info("Your update is now available in your public channel 🎉"):(null==t?void 0:t.id)&&u.log.info(`Link device to this bundle to try it: ${r}`),o.bundleUrl&&u.log.info(`Bundle url: ${r}`)}else u.log.warn("Cannot set bundle with upload key, use key with more rights for that"),p.program.error("");return yield S.track({channel:"app",event:"App Uploaded",icon:"⏫",user_id:I,tags:{"app-id":e},notify:!1}).catch(),n&&(u.outro("Time to share your update to the world 🌍"),process.exit()),!0})),o.uploadCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){try{yield(0,o.uploadBundle)(e,n,!0)}catch(e){u.log.error(JSON.stringify(e)),p.program.error("")}})),o.uploadDeprecatedCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){u.log.warn('⚠️ This command is deprecated, use "npx @capgo/cli bundle upload" instead ⚠️');try{yield(0,o.uploadBundle)(e,n,!0)}catch(e){u.log.error(JSON.stringify(e)),p.program.error("")}}))},7103:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.zipBundle=void 0;const c=n(6113),s=n(7147),d=l(n(3844)),p=n(7304),u=r(n(552)),f=n(5906),y=n(7482),g=n(6545);o.zipBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n,t,i,r;yield(0,y.checkLatest)();let{bundle:a,path:l}=o;const v=(0,g.useLogSnag)(),h=yield(0,g.getConfig)();e=e||(null===(n=null==h?void 0:h.app)||void 0===n?void 0:n.appId);const m=(0,c.randomUUID)().split("-")[0];a=a||(null===(i=null===(t=null==h?void 0:h.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version)||`0.0.1-beta.${m}`,u.intro(`Zipping ${e}@${a}`),g.regexSemver.test(a)||(u.log.error(`Your bundle name ${a}, is not valid it should follow semver convention : https://semver.org/`),p.program.error("")),l=l||(null===(r=null==h?void 0:h.app)||void 0===r?void 0:r.webDir),e&&a&&l||(u.log.error("Missing argument, you need to provide a appId and a bundle and a path, or be in a capacitor project"),p.program.error("")),u.log.info(`Started from path "${l}"`);const b=new d.default;b.addLocalFolder(l);const _=b.toBuffer();u.log.info(`Zipped ${_.byteLength} bytes`);const k=u.spinner();k.start("Calculating checksum");const w=yield(0,f.checksum)(_,"crc32");k.stop(`Checksum: ${w}`);const C=Math.floor(_.byteLength/1024/1024);C>20&&(u.log.warn(`WARNING !!\nThe app size is ${C} Mb, this may take a while to download for users\n`),u.log.warn("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield v.track({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"app-id":e},notify:!1}).catch());const P=u.spinner();P.start(`Saving to ${e}_${a}.zip`),(0,s.writeFileSync)(`${e}_${a}.zip`,_),P.stop(`Saved to ${e}_${a}.zip`),yield v.track({channel:"app",event:"App zip",icon:"⏫",tags:{"app-id":e},notify:!1}).catch(),u.outro("Done ✅"),process.exit()}))},4402:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addChannelCommand=o.addChannel=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.addChannel=(e,o,n,t=!0)=>a(void 0,void 0,void 0,(function*(){var i;c.intro("Create channel"),n.apikey=n.apikey||(0,p.findSavedKey)();const r=yield(0,p.getConfig)();o=o||(null===(i=null==r?void 0:r.app)||void 0===i?void 0:i.appId);const a=(0,p.useLogSnag)();n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const u=(0,p.createSupabaseClient)(n.apikey),f=yield(0,p.verifyUser)(u,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(u,o),c.log.info(`Creating channel ${o}#${e} to Capgo`);try{const n=yield(0,d.findUnknownVersion)(u,o);n||(c.log.error("Cannot find default version for channel creation, please contact Capgo support 🤨"),l.program.error("")),yield(0,d.createChannel)(u,{name:e,app_id:o,version:n.id,created_by:f}),c.log.success("Channel created ✅"),yield a.track({channel:"channel",event:"Create channel",icon:"✅",user_id:f,tags:{"app-id":o,channel:e},notify:!1}).catch()}catch(e){return c.log.error("Cannot create Channel 🙀"),!1}return t&&(c.outro("Done ✅"),process.exit()),!0})),o.addChannelCommand=(e,n,t)=>a(void 0,void 0,void 0,(function*(){(0,o.addChannel)(e,n,t,!0)}))},7422:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteChannel=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.deleteChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t;c.intro("Delete channel"),n.apikey=n.apikey||(0,p.findSavedKey)();const i=yield(0,p.getConfig)();o=o||(null===(t=null==i?void 0:i.app)||void 0===t?void 0:t.appId);const r=(0,p.useLogSnag)();n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const a=(0,p.createSupabaseClient)(n.apikey),u=yield(0,p.verifyUser)(a,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(a,o),c.log.info(`Deleting channel ${o}#${e} from Capgo`);try{yield(0,d.delChannel)(a,e,o,u),c.log.success("Channel deleted"),yield r.track({channel:"channel",event:"Delete channel",icon:"✅",tags:{"user-id":u,"app-id":o,channel:e},notify:!1}).catch()}catch(e){c.log.error("Cannot delete Channel 🙀")}c.outro("Done ✅"),process.exit()}))},2667:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listChannels=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.listChannels=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;c.intro("List channels"),o.apikey=o.apikey||(0,p.findSavedKey)();const t=yield(0,p.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId);const i=(0,p.useLogSnag)();o.apikey||c.log.error("Missing API key, you need to provide a API key to upload your bundle"),e||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const r=(0,p.createSupabaseClient)(o.apikey),a=yield(0,p.verifyUser)(r,o.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(r,e),c.log.info("Querying available channels in Capgo"),yield(0,s.checkAppExistsAndHasPermissionErr)(r,e);const u=yield(0,d.getActiveChannels)(r,e,a);c.log.info(`Active channels in Capgo: ${null==u?void 0:u.length}`),(0,d.displayChannels)(u),yield i.track({channel:"channel",event:"List channel",icon:"✅",user_id:a,tags:{"app-id":e},notify:!1}).catch(),c.outro("Done ✅"),process.exit()}))},593:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const l=n(7304),c=r(n(552)),s=n(9218),d=n(6545);o.setChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i,r;c.intro("Set channel"),n.apikey=n.apikey||(0,d.findSavedKey)();const a=yield(0,d.getConfig)();o=o||(null===(t=null==a?void 0:a.app)||void 0===t?void 0:t.appId);const p=(0,d.useLogSnag)();n.apikey||(c.log.error("Missing API key, you need to provide a API key to upload your bundle"),l.program.error("")),o||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const u=(0,d.createSupabaseClient)(n.apikey),f=yield(0,d.verifyUser)(u,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(u,o);const{bundle:y,latest:g,downgrade:v,upgrade:h,ios:m,android:b,selfAssign:_,state:k}=n;e||(c.log.error("Missing argument, you need to provide a channel"),l.program.error("")),g&&y&&(c.log.error("Cannot set latest and bundle at the same time"),l.program.error("")),null==y&&null==k&&null==g&&null==v&&null==h&&null==m&&null==b&&null==_&&(c.log.error("Missing argument, you need to provide a option to set"),l.program.error(""));try{yield(0,d.checkPlanValid)(u,f),yield(0,s.checkAppExistsAndHasPermissionErr)(u,o);const n={created_by:f,app_id:o,name:e,version:void 0},t=g?null===(r=null===(i=null==a?void 0:a.app)||void 0===i?void 0:i.package)||void 0===r?void 0:r.version:y;if(null!=t){const{data:i,error:r}=yield u.from("app_versions").select().eq("app_id",o).eq("name",t).eq("user_id",f).eq("deleted",!1).single();!r&&i||(c.log.error(`Cannot find version ${t}`),l.program.error("")),c.log.info(`Set ${o} channel: ${e} to @${t}`),n.version=i.id}null!=k&&("public"!==k&&"private"!==k||c.log.info(`Set ${o} channel: ${e} to public or private is deprecated, use default or normal instead`),c.log.info(`Set ${o} channel: ${e} to ${"public"===k||"default"===k?"default":"normal"}`),n.public="public"===k||"default"===k),null!=v&&(c.log.info(`Set ${o} channel: ${e} to ${v?"allow":"disallow"} downgrade`),n.disableAutoUpdateUnderNative=!v),null!=h&&(c.log.info(`Set ${o} channel: ${e} to ${h?"allow":"disallow"} upgrade`),n.disableAutoUpdateToMajor=!h),null!=m&&(c.log.info(`Set ${o} channel: ${e} to ${m?"allow":"disallow"} ios update`),n.ios=!!m),null!=b&&(c.log.info(`Set ${o} channel: ${e} to ${b?"allow":"disallow"} android update`),n.android=!!b),null!=_&&(c.log.info(`Set ${o} channel: ${e} to ${_?"allow":"disallow"} self assign to this channel`),n.allow_device_self_set=!!_);try{const{error:e}=yield(0,d.updateOrCreateChannel)(u,n);e&&(c.log.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.'),l.program.error(""))}catch(e){c.log.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.'),l.program.error("")}yield p.track({channel:"channel",event:"Set channel",icon:"✅",user_id:f,tags:{"user-id":f,"app-id":o},notify:!1}).catch()}catch(e){c.log.error(`Unknow error ${(0,d.formatError)(e)}`),l.program.error("")}c.outro("Done ✅"),process.exit()}))},4999:function(e,o,n){var t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0});const i=n(7304),r=n(7103),a=n(6104),l=n(2083),c=n(7978),s=n(3333),d=n(7171),p=n(1628),u=n(6122),f=n(3930),y=n(593),g=n(2510),v=t(n(4147)),h=n(5041),m=n(8373),b=n(2393),_=n(4402),k=n(7422),w=n(2667),C=n(5789),P=n(6626),O=n(7626);i.program.name(v.default.name).description("Manage packages and bundle versions in Capgo Cloud").version(v.default.version),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(h.loginCommand).option("--local","Only save in local folder"),i.program.command("doctor").description("Get info about your Capgo app install").action(p.getInfo),i.program.command("init [apikey] [appId]").description("Init a new app").action(a.initApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account");const x=i.program.command("app").description("Manage app");x.command("add [appId]").alias("a").description("Add a new app in Capgo Cloud").action(d.addCommand).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),x.command("delete [appId]").alias("d").description("Delete an app in Capgo Cloud").action(P.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account"),x.command("list").alias("l").description("list apps in Capgo Cloud").action(m.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),x.command("debug [appId]").alias("d").description("Listen for live updates event in Capgo Cloud to debug your app").option("-a, --apikey <apikey>","apikey to link to your account").option("-d, --device <device>","the specific device to debug").action(O.debugApp),x.command("set [appId]").alias("s").description("Set an app in Capgo Cloud").action(C.setApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account").option("-r, --retention <retention>","retention period of app bundle in days");const S=i.program.command("bundle").description("Manage bundle");S.command("upload [appId]").alias("u").description("Upload a new bundle in Capgo Cloud").action(g.uploadCommand).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to Capgo Cloud").option("--iv-session-key <key>","Set the iv and session key for bundle url external").option("--key <key>","custom path for public signing key").option("--key-data <keyData>","base64 public signing key").option("--bundle-url","prints bundle url into stdout").option("--no-key","ignore signing key and send clear update").option("--no-code-check","Ignore checking if notifyAppReady() is called in soure code").option("--display-iv-session","Show in the console the iv and session key used to encrypt the update").option("-b, --bundle <bundle>","bundle version number of the bundle to upload"),S.command("delete [bundleId] [appId]").alias("d").description("Delete a bundle in Capgo Cloud").action(f.deleteBundle).option("-a, --apikey <apikey>","apikey to link to your account"),S.command("list [appId]").alias("l").description("List bundle in Capgo Cloud").action(l.listBundle).option("-a, --apikey <apikey>","apikey to link to your account"),S.command("unlink [appId]").alias("u").description("Unlink a bundle in Capgo Cloud").action(l.listBundle).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the bundle to unlink"),S.command("cleanup [appId]").alias("c").action(b.cleanupBundle).description("Cleanup bundle in Capgo Cloud").option("-b, --bundle <bundle>","bundle version number of the app to delete").option("-a, --apikey <apikey>","apikey to link to your account").option("-k, --keep <keep>","number of version to keep").option("-f, --force","force removal"),S.command("decrypt [zipPath] [sessionKey]").alias("l").description("Decrypt a signed zip bundle").action(c.decryptZip).option("--key <key>","custom path for private signing key").option("--key-data <keyData>","base64 private signing key"),S.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(s.encryptZip).option("--key <key>","custom path for private signing key").option("--key-data <keyData>","base64 private signing key"),S.command("zip [appId]").description("Zip a bundle").action(r.zipBundle).option("-p, --path <path>","path of the folder to upload").option("-b, --bundle <bundle>","bundle version number to name the zip file");const j=i.program.command("channel").description("Manage channel");j.command("add [channelId] [appId]").alias("a").description("Create channel").action(_.addChannelCommand).option("-d, --default","set the channel as default"),j.command("delete [channelId] [appId]").alias("d").description("Delete channel").action(k.deleteChannel),j.command("list [appId]").alias("l").description("List channel").action(w.listChannels),j.command("set [channelId] [appId]").alias("s").description("Set channel").action(y.setChannel).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the file to set").option("-s, --state <state>","set the state of the channel, default or normal").option("--latest","get the latest version key in the package.json to set it to the channel").option("--downgrade","Allow to downgrade to version under native one").option("--no-downgrade","Disable downgrade to version under native one").option("--upgrade","Allow to upgrade to version above native one").option("--no-upgrade","Disable upgrade to version above native one").option("--ios","Allow sending update to ios devices").option("--no-ios","Disable sending update to ios devices").option("--android","Allow sending update to android devices").option("--no-android","Disable sending update to android devices").option("--self-assign","Allow to device to self assign to this channel").option("--no-self-assign","Disable devices to self assign to this channel");const $=i.program.command("key").description("Manage key");$.command("save").description("Save base64 signing key in capacitor config, usefull for CI").action(u.saveKeyCommand).option("-f, --force","force generate a new one").option("--key","key path to save in capacitor config").option("--key-data","key data to save in capacitor config"),$.command("create").description("Create a new signing key").action(u.createKeyCommand).option("-f, --force","force generate a new one"),i.program.command("upload [appId]").alias("u").description("(Deprecated) Upload a new bundle to Capgo Cloud").action(g.uploadDeprecatedCommand).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to Capgo Cloud").option("--key <key>","custom path for public signing key").option("--key-data <keyData>","base64 public signing key").option("--bundle-url","prints bundle url into stdout").option("--no-key","ignore signing key and send clear update").option("--display-iv-session","Show in the console the iv and session key used to encrypt the update").option("-b, --bundle <bundle>","bundle version number of the file to upload"),i.program.parseAsync()},6104:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.initApp=void 0;const l=n(7147),c=n(2081),s=n(6301),d=r(n(552)),p=n(7626),u=n(6122),f=n(4402),y=n(2510),g=n(5041),v=n(7171),h=n(7482),m=n(6545),b="import { CapacitorUpdater } from '@capgo/capacitor-updater'",_="CapacitorUpdater.notifyAppReady()",k=/import.*from.*/g,w="production",C={stdio:"pipe"},P=(e,o,n)=>a(void 0,void 0,void 0,(function*(){d.isCancel(e)&&(yield(0,p.markSnag)("onboarding-v2",o,n,"canceled","🤷"),process.exit())})),O=(e,o,n)=>a(void 0,void 0,void 0,(function*(){return(0,p.markSnag)("onboarding-v2",e,o,`onboarding-step-${n}`)}));o.initApp=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t;d.intro("Capgo onboarding 🛫"),yield(0,h.checkLatest)();const i=(0,m.useLogSnag)(),r=yield(0,m.getConfig)();o=o||(null===(t=null==r?void 0:r.app)||void 0===t?void 0:t.appId),e=e||(0,m.findSavedKey)();const x=d.spinner();x.start("Running: npx @capgo/cli@latest login ***"),(yield(0,g.login)(e,n,!1))?x.stop("Login Done ✅"):x.stop("Login already done ✅");const S=(0,m.createSupabaseClient)(e),j=yield(0,m.verifyUser)(S,e,["upload","all","read","write"]);yield O(j,i,1),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Add ${n} in Capgo?`});if(yield P(i,e,o),i){const e=d.spinner();e.start(`Running: npx @capgo/cli@latest app add ${n}`),(yield(0,v.addApp)(n,t,!1))?e.stop("App add Done ✅"):e.stop("App already add ✅")}else d.log.info(`Run yourself "npx @capgo/cli@latest app add ${n}"`);yield O(e,o,2)})))(j,i,o,n),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Create default channel ${w} for ${t} in Capgo?`});if(yield P(i,e,o),i){const e=d.spinner();e.start(`Running: npx @capgo/cli@latest channel add ${w} ${t} --default`),(yield(0,f.addChannel)(w,t,{default:!0,apikey:n},!1))?e.stop("Channel add Done ✅"):e.stop("Channel already added ✅")}else d.log.info(`Run yourself "npx @capgo/cli@latest channel add ${w} ${t} --default"`);yield O(e,o,3)})))(j,i,e,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:`Automatic Install "@capgo/capacitor-updater" dependency in ${t}?`});if(yield P(n,e,o),n){const e=d.spinner();e.start("Checking if @capgo/capacitor-updater is installed");const o=JSON.parse((0,l.readFileSync)("package.json").toString()),n=(0,s.findPackageManagerType)();"unknown"===n&&(e.stop("Cannot reconize package manager, please run `capgo init` in a capacitor project with npm, pnpm or yarn"),process.exit());const t="yarn"===n?"add":"install";o.dependencies["@capgo/capacitor-updater"]?e.stop("Capgo already installed ✅"):(yield(0,c.execSync)(`${n} ${t} @capgo/capacitor-updater@latest`,C),e.stop("Install Done ✅"))}else d.log.info('Run yourself "npm i @capgo/capacitor-updater@latest"');yield O(e,o,4)})))(j,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:`Automatic Add "${_}" code and import in ${t}?`});if(yield P(n,e,o),n){const n=d.spinner();n.start("Adding @capacitor-updater to your main file");const t=yield(0,m.findMainFile)();t||(n.stop("No main.ts, main.js, index.ts or index.js file found, You need to add @capgo/capacitor-updater manually"),process.exit());const i=(0,l.readFileSync)(t).toString(),r=i.match(k),a=null==r?void 0:r.pop();if(a||(n.stop("Cannot find import line in main file, use manual installation: https://capgo.app/docs/plugin/installation/"),process.exit()),i.includes(_))n.stop(`Code already added to ${t} ✅`);else{const e=i.replace(a,`${a}\n${b};\n\n${_};\n`);(0,l.writeFileSync)(t,e),n.stop(`Code added to ${t} ✅`)}yield O(e,o,5)}else d.log.info(`Add to your main file the following code:\n\n${b};\n\n${_};\n`)})))(j,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:`Automatic configure end-to-end encryption in ${t} updates?`});if(yield P(n,e,o),n){const n=d.spinner();n.start("Running: npx @capgo/cli@latest key create"),(yield(0,u.createKey)({},!1))?n.stop("key created 🔑"):(n.stop("Cannot create key ❌"),process.exit(1)),(0,p.markSnag)("onboarding-v2",e,o,"Use encryption")}yield O(e,o,6)})))(j,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){var n;const i=yield d.confirm({message:`Automatic build ${t} with "npm run build" ?`});if(yield P(i,e,o),i){const e=d.spinner();e.start("Running: npm run build && npx cap sync"),(null===(n=JSON.parse((0,l.readFileSync)("package.json").toString()).scripts)||void 0===n?void 0:n.build)||(e.stop("Cannot find build script in package.json, please add it and run `capgo init` again"),process.exit()),(0,c.execSync)("npm run build && npx cap sync",C),e.stop("Build & Sync Done ✅")}else d.log.info("Build yourself with command: npm run build && npx cap sync");yield O(e,o,7)})))(j,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Automatic upload ${t} bundle to Capgo?`});if(yield P(i,e,o),i){const e=d.spinner();e.start("Running: npx @capgo/cli@latest bundle upload"),(yield(0,y.uploadBundle)(t,{channel:w,apikey:n},!1))?e.stop("Upload Done ✅"):(e.stop("Upload failed ❌"),process.exit())}else d.log.info("Upload yourself with command: npx @capgo/cli@latest bundle upload");yield O(e,o,8)})))(j,i,e,o),yield((e,o)=>a(void 0,void 0,void 0,(function*(){const n=yield d.confirm({message:"Run in device now ?"});if(yield P(n,e,o),n){const e=yield d.select({message:"Pick a platform to run your app",options:[{value:"ios",label:"IOS"},{value:"android",label:"Android"}]});d.isCancel(e)&&process.exit();const o=e,n=d.spinner();n.start(`Running: npx cap run ${o}`),yield(0,c.spawnSync)("npx",["cap","run",o],{stdio:"inherit"}),n.stop("Started Done ✅")}else d.log.info("Run yourself with command: npx cap run <ios|android>");yield O(e,o,9)})))(j,i),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:"Automatic check if update working in device ?"});if(yield P(i,e,o),i)d.log.info(`Wait logs sent to Capgo from ${t} device, Put the app in background and open it again.`),d.log.info("Waiting..."),yield(0,p.waitLog)("onboarding-v2",n,t,o,e);else{const e=(0,m.convertAppName)(t);d.log.info(`Check logs in https://web.capgo.app/app/p/${e}/logs to see if update works.`)}yield O(e,o,10)})))(j,i,S,o),yield O(j,i,0),d.log.info("Welcome onboard ✈️!"),d.log.info("Your Capgo update system is setup"),d.log.info("Next time use `npx @capgo/cli@latest bundle upload` to only upload your bundle"),d.outro("Bye 👋"),process.exit()}))},6122:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.createKeyCommand=o.createKey=o.saveKeyCommand=o.saveKey=void 0;const l=n(7147),c=n(7304),s=n(7778),d=r(n(552)),p=n(407),u=n(6545),f=n(7482);o.saveKey=(e,o=!0)=>a(void 0,void 0,void 0,(function*(){(0,l.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),c.program.error(""));const n=yield(0,u.getConfig)(),{extConfig:t}=n.app,i=e.key||u.baseKey;let r=e.keyData||"";if((0,l.existsSync)(i)||r)(0,l.existsSync)(i)&&(r=(0,l.readFileSync)(i).toString());else{if(!o)return!1;d.log.error(`Cannot find public key ${i} or as keyData option or in ${n.app.extConfigFilePath}`),c.program.error("")}return t&&(t.plugins||(t.plugins={extConfig:{},CapacitorUpdater:{}}),t.plugins.CapacitorUpdater||(t.plugins.CapacitorUpdater={}),t.plugins.CapacitorUpdater.privateKey=r,(0,s.writeConfig)(t,n.app.extConfigFilePath)),o&&(d.log.success(`private key saved into ${n.app.extConfigFilePath} file in local directory`),d.log.success("your app will decode the zip archive with this key")),!0})),o.saveKeyCommand=e=>a(void 0,void 0,void 0,(function*(){d.intro("Save keys 🔑"),yield(0,f.checkLatest)(),yield(0,o.saveKey)(e)})),o.createKey=(e,o=!0)=>a(void 0,void 0,void 0,(function*(){o&&d.intro("Create keys 🔑"),(0,l.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),c.program.error(""));const{publicKey:n,privateKey:t}=(0,p.createRSA)();if((0,l.existsSync)(u.baseKeyPub)&&!e.force){if(!o)return!1;d.log.error("Public Key already exists, use --force to overwrite"),c.program.error("")}if((0,l.writeFileSync)(u.baseKeyPub,n),(0,l.existsSync)(u.baseKey)&&!e.force){if(!o)return!1;d.log.error("Private Key already exists, use --force to overwrite"),c.program.error("")}(0,l.writeFileSync)(u.baseKey,t);const i=yield(0,u.getConfig)(),{extConfig:r}=i.app;return r&&(r.plugins||(r.plugins={extConfig:{},CapacitorUpdater:{}}),r.plugins.CapacitorUpdater.privateKey=t,(0,s.writeConfig)(r,i.app.extConfigFilePath)),o&&(d.log.success("Your RSA key has been generated"),d.log.success(`Public key saved in ${u.baseKeyPub}`),d.log.success("This key will be use to crypt your bundle before sending it to Capgo"),d.log.success("Than make them unreadable by Capgo and unmodifiable by anyone"),d.log.success(`Private key saved in ${i.app.extConfigFilePath}`),d.log.success("Your app will be the only one having it"),d.log.success("Only your users can decrypt your update"),d.log.success("Only you can send them an update"),d.outro("Done ✅")),!0})),o.createKeyCommand=e=>a(void 0,void 0,void 0,(function*(){yield(0,f.checkLatest)(),yield(0,o.createKey)(e)}))},5041:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.loginCommand=o.login=void 0;const l=n(7147),c=n(2037),s=n(7304),d=r(n(552)),p=n(6545),u=n(7482);o.login=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){if(n&&d.intro("Login to Capgo"),!e)return n&&s.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,u.checkLatest)();try{const{local:n}=o,t=(0,p.useLogSnag)();if(n)(0,l.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),s.program.error("")),(0,l.writeFileSync)(".capgo",`${e}\n`),(0,l.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,c.homedir)();(0,l.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const i=(0,p.createSupabaseClient)(e),r=yield(0,p.verifyUser)(i,e,["write","all","upload"]);yield t.track({channel:"user-login",event:"User CLI login",icon:"✅",user_id:r,notify:!1}).catch(),d.log.success(`login saved into .capgo file in ${n?"local":"home"} directory`)}catch(e){d.log.error("Error while saving login"),process.exit(1)}return n&&(d.outro("Done ✅"),process.exit()),!0})),o.loginCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.login)(e,n,!0)}))},6545:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{c(t.next(e))}catch(e){r(e)}}function l(e){try{c(t.throw(e))}catch(e){r(e)}}function c(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,l)}c((t=t.apply(e,o||[])).next())}))},l=this&&this.__await||function(e){return this instanceof l?(this.v=e,this):new l(e)},c=this&&this.__asyncValues||function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),o={},t("next"),t("throw"),t("return"),o[Symbol.asyncIterator]=function(){return this},o);function t(n){o[n]=e[n]&&function(o){return new Promise((function(t,i){!function(e,o,n,t){Promise.resolve(t).then((function(o){e({value:o,done:n})}),o)}(t,i,(o=e[n](o)).done,o.value)}))}}},s=this&&this.__asyncDelegator||function(e){var o,n;return o={},t("next"),t("throw",(function(e){throw e})),t("return"),o[Symbol.iterator]=function(){return this},o;function t(t,i){o[t]=e[t]?function(o){return(n=!n)?{value:l(e[t](o)),done:!1}:i?i(o):o}:i}},d=this&&this.__asyncGenerator||function(e,o,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,i=n.apply(e,o||[]),r=[];return t={},a("next"),a("throw"),a("return"),t[Symbol.asyncIterator]=function(){return this},t;function a(e){i[e]&&(t[e]=function(o){return new Promise((function(n,t){r.push([e,o,n,t])>1||c(e,o)}))})}function c(e,o){try{(n=i[e](o)).value instanceof l?Promise.resolve(n.value.v).then(s,d):p(r[0][2],n)}catch(e){p(r[0][3],e)}var n}function s(e){c("next",e)}function d(e){c("throw",e)}function p(e,o){e(o),r.shift(),r.length&&c(r[0][0],r[0][1])}},p=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getHumanDate=o.verifyUser=o.convertAppName=o.useLogSnag=o.updateOrCreateChannel=o.uploadUrl=o.updateOrCreateVersion=o.formatError=o.findMainFile=o.findSavedKey=o.checkPlanValid=o.isAllowedAction=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.defaulPublicKey=o.supaAnon=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=o.getConfig=void 0;const u=n(7147),f=n(2037),y=n(1017),g=n(7778),v=n(7304),h=n(2885),m=p(n(9867)),b=n(1133),_=r(n(552));function k(e){return d(this,arguments,(function*(){const o=yield l((0,u.readdirSync)(e,{withFileTypes:!0}));for(const n of o){const o=(0,y.resolve)(e,n.name);!n.isDirectory()||n.name.startsWith(".")||n.name.startsWith("node_modules")||n.name.startsWith("dist")?yield yield l(o):yield l(yield*s(c(k(o))))}}))}o.getConfig=()=>a(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,g.loadConfig)()}catch(e){v.program.error("No capacitor config file found, run `cap init` first")}return e})),(0,o.getConfig)().then((e=>{var n,t,i,r;e.app.extConfig.plugins&&e.app.extConfig.plugins.CapacitorUpdater&&(o.host=null!==(n=e.app.extConfig.plugins.CapacitorUpdater.localHost)&&void 0!==n?n:o.host,o.hostWeb=null!==(t=e.app.extConfig.plugins.CapacitorUpdater.localWebHost)&&void 0!==t?t:o.hostWeb,o.hostSupa=null!==(i=e.app.extConfig.plugins.CapacitorUpdater.localSupa)&&void 0!==i?i:o.hostSupa,o.supaAnon=null!==(r=e.app.extConfig.plugins.CapacitorUpdater.localSupaAnon)&&void 0!==r?r:o.supaAnon)})),o.baseKey=".capgo_key",o.baseKeyPub=`${o.baseKey}.pub`,o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostSupa="https://xvwzpoazmxkqosrdewyv.supabase.co",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh2d3pwb2F6bXhrcW9zcmRld3l2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTI4MjExOTcsImV4cCI6MjAwODM5NzE5N30.wjxOlMfJoM2IuiFOmLGeP6YxdkF7Scgcfwu8TnPw_fY",o.defaulPublicKey="-----BEGIN RSA PUBLIC KEY-----\n MIIBCgKCAQEA4pW9olT0FBXXivRCzd3xcImlWZrqkwcF2xTkX/FwXmj9eh9HkBLr\n sQmfsC+PJisRXIOGq6a0z3bsGq6jBpp3/Jr9jiaW5VuPGaKeMaZZBRvi/N5fIMG3\n hZXSOcy0IYg+E1Q7RkYO1xq5GLHseqG+PXvJsNe4R8R/Bmd/ngq0xh/cvcrHHpXw\n O0Aj9tfprlb+rHaVV79EkVRWYPidOLnK1n0EFHFJ1d/MyDIp10TEGm2xHpf/Brlb\n 1an8wXEuzoC0DgYaczgTjovwR+ewSGhSHJliQdM0Qa3o1iN87DldWtydImMsPjJ3\n DUwpsjAMRe5X8Et4+udFW2ciYnQo9H0CkwIDAQAB\n -----END RSA PUBLIC KEY-----",o.createSupabaseClient=e=>(0,h.createClient)(o.hostSupa,o.supaAnon,{auth:{persistSession:!1},global:{headers:{capgkey:e}}}),o.regexSemver=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,o.checkKey=(e,n,t)=>a(void 0,void 0,void 0,(function*(){const{data:i,error:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:t}).single();i&&!r||v.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(r)}`)})),o.isGoodPlan=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_good_plan_v3",{userid:o}).single();if(t)throw t;return n||!1})),o.isPaying=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_paying",{userid:o}).single();if(t)throw t;return n||!1})),o.isTrial=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_trial",{userid:o}).single();if(t)throw t;return n||0})),o.isAllowedAction=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_allowed_action_user",{userid:o}).single();if(t)throw t;return n})),o.checkPlanValid=(e,t,i=!0)=>a(void 0,void 0,void 0,(function*(){(yield(0,o.isAllowedAction)(e,t))||(_.log.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),setTimeout((()=>{Promise.resolve().then((()=>r(n(6634)))).then((e=>{e.default(`${o.hostWeb}/dashboard/settings/plans`)})),v.program.error("")}),1e3));const a=yield(0,o.isTrial)(e,t),l=yield(0,o.isPaying)(e,t);a>0&&i&&!l&&_.log.warn(`WARNING !!\nTrial expires in ${a} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e,o=`${(0,f.homedir)()}/.capgo`;return(0,u.existsSync)(o)&&(_.log.info(`Use global apy key ${o}`),e=(0,u.readFileSync)(o,"utf8").trim()),o=".capgo",!e&&(0,u.existsSync)(o)&&(_.log.info(`Use local apy key ${o}`),e=(0,u.readFileSync)(o,"utf8").trim()),e||v.program.error("Key not found, please login first"),e},o.findMainFile=()=>a(void 0,void 0,void 0,(function*(){var e,o,n,t;const i=/(main|index)\.(ts|tsx|js|jsx)$/;let r="";const a=process.cwd(),l=a.split("/").length;try{for(var s,d=!0,p=c(k(a));!(e=(s=yield p.next()).done);d=!0){t=s.value,d=!1;const e=t;if(e.split("/").length-l<=2&&i.test(e)){r=e,_.log.info(`Found main file here ${e}`);break}}}catch(e){o={error:e}}finally{try{d||e||!(n=p.return)||(yield n.call(p))}finally{if(o)throw o.error}}return r})),o.formatError=e=>e?`\n${m.default.render(e)}`:"",o.updateOrCreateVersion=(e,o,n)=>a(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.rpc("exist_app_versions",{appid:o.app_id,name_version:o.name,apikey:n}).single();return t&&!i?(o.deleted=!1,e.from("app_versions").update(o).eq("app_id",o.app_id).eq("name",o.name)):e.from("app_versions").insert(o)})),o.uploadUrl=function(e,o,n){return a(this,void 0,void 0,(function*(){const t={app_id:o,bucket_id:n};try{return(yield e.functions.invoke("upload_link",{body:JSON.stringify(t)})).data.url}catch(e){_.log.error(`Cannot get upload url ${JSON.stringify(e)}`)}return""}))},o.updateOrCreateChannel=(e,o)=>a(void 0,void 0,void 0,(function*(){if(!o.app_id||!o.name||!o.created_by)return _.log.error("missing app_id, name, or created_by"),Promise.reject(new Error("missing app_id, name, or created_by"));const{data:n,error:t}=yield e.from("channels").select("enable_progressive_deploy, secondaryVersionPercentage, secondVersion").eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by).single();if(n&&!t){if(n.enable_progressive_deploy){if(_.log.info("Progressive deploy is enabled"),1!==n.secondaryVersionPercentage&&_.log.warn("Latest progressive deploy has not finished"),o.secondVersion=o.version,!n.secondVersion)return _.log.error("missing secondVersion"),Promise.reject(new Error("missing secondVersion"));o.version=n.secondVersion,o.secondaryVersionPercentage=.1,_.log.info("Started new progressive upload!")}return e.from("channels").update(o).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by).select().single()}return e.from("channels").insert(o).select().single()})),o.useLogSnag=()=>new b.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.convertAppName=e=>e.replace(/\./g,"--"),o.verifyUser=(e,n,t=["all"])=>a(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,n,t);const{data:i,error:r}=yield e.rpc("get_user_id",{apikey:n}).single(),a=(i||"").toString();return a&&!r||v.program.error(`Cannot verify user ${(0,o.formatError)(r)}`),a})),o.getHumanDate=e=>new Date(e||"").toLocaleString()},7778:e=>{e.exports=require("@capacitor/cli/dist/config")},6301:e=>{e.exports=require("@capgo/find-package-manager")},552:e=>{e.exports=require("@clack/prompts")},2885:e=>{e.exports=require("@supabase/supabase-js")},5906:e=>{e.exports=require("@tomasklaen/checksum")},7176:e=>{e.exports=require("@trufflesuite/spinnies")},3844:e=>{e.exports=require("adm-zip")},2167:e=>{e.exports=require("axios")},7812:e=>{e.exports=require("ci-info")},7304:e=>{e.exports=require("commander")},3847:e=>{e.exports=require("console-table-printer")},4470:e=>{e.exports=require("fs-extra")},5362:e=>{e.exports=require("get-latest-version")},1133:e=>{e.exports=require("logsnag")},9011:e=>{e.exports=require("mime")},6634:e=>{e.exports=require("open")},9867:e=>{e.exports=require("prettyjson")},1616:e=>{e.exports=require("prompt-sync")},1505:e=>{e.exports=require("semver/preload")},2081:e=>{e.exports=require("child_process")},6113:e=>{e.exports=require("crypto")},7147:e=>{e.exports=require("fs")},2037:e=>{e.exports=require("os")},1017:e=>{e.exports=require("path")},4147:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"3.13.31","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"engines":{"npm":">=7.0.0","node":">=16.0.0"},"keywords":["appflow alternative","ionic","capacitor","auto update","live update","capgo","cli","upload","capgo-cli"],"scripts":{"dev":"set NODE_ENV=development && npx webpack --config webpack.config.js","no-debug":"node dist/index.js","test":"npx --yes ts-node -T src/index.ts","build":"npx --yes webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","types":"npx --yes supabase gen types typescript --project-id=xvwzpoazmxkqosrdewyv > src/types/supabase.types.ts","test_rls":"ts-node ./test/test_headers_rls.ts","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"5.2.2","@capgo/find-package-manager":"^0.0.7","@clack/prompts":"^0.7.0","@supabase/supabase-js":"^2.32.0","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","axios":"^1.4.0","ci-info":"^3.8.0","commander":"11.0.0","console-table-printer":"^2.11.2","fs-extra":"11.1.1","get-latest-version":"^5.1.0","logsnag":"1.0.0","mime":"^3.0.0","open":"^9.1.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","qrcode":"^1.5.3","semver":"^7.5.4"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/fs-extra":"^11.0.1","@types/mime":"^3.0.1","@types/node":"^20.4.9","@types/npmcli__ci-detect":"^2.0.0","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/qrcode":"^1.5.1","@types/semver":"^7.5.0","@typescript-eslint/eslint-plugin":"5.56.0","@typescript-eslint/parser":"5.56.0","eslint":"8.47.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^9.0.0","eslint-import-resolver-typescript":"3.6.0","eslint-plugin-import":"2.28.0","eslint-plugin-prettier":"^5.0.0","git-format-staged":"3.0.0","husky":"^8.0.3","nodemon":"3.0.1","pkg":"5.8.1","prettier":"3.0.2","ts-loader":"^9.4.4","ts-node":"^10.9.1","tsconfig-paths":"4.2.0","typescript":"5.1.6","webpack":"5.88.2","webpack-cli":"^5.1.4","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t].call(r.exports,r,r.exports,n),r.exports}(4999)})();
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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.newIconPath=o.checkAppExistsAndHasPermissionErr=o.checkAppExistsAndHasPermission=void 0;const i=n(7304);o.checkAppExistsAndHasPermission=(e,o,n=!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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getActiveChannels=o.displayChannels=o.delChannel=o.createChannel=o.findUnknownVersion=o.checkVersionNotUsedInChannel=void 0;const c=n(7304),l=n(3847),s=r(n(552)),d=n(6545);o.checkVersionNotUsedInChannel=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){var r;const{data:a,error:l}=yield e.from("channels").select().eq("app_id",n).eq("created_by",t).eq("version",i.id);if(l&&c.program.error(`Cannot check Version ${n}@${i.name} ${(0,d.formatError)(l)}`),a&&a.length>0){if(s.intro(`❌ Version ${n}@${i.name} is used in ${a.length} channel`),yield s.confirm({message:"unlink it?"}))for(const t of a){const i=s.spinner();i.start(`Unlinking channel ${t.name}`);const{error:a}=yield e.from("channels").update({version:null===(r=yield(0,o.findUnknownVersion)(e,n))||void 0===r?void 0:r.id}).eq("id",t.id);a&&(i.stop(`Cannot update channel ${t.name} ${(0,d.formatError)(a)}`),process.exit(1)),i.stop(`✅ Channel ${t.name} unlinked`)}else c.program.error("unlink it first");s.outro(`Version unlinked from ${a.length} channel`)}})),o.findUnknownVersion=(e,o)=>e.from("app_versions").select("id").eq("app_id",o).eq("name","unknown").throwOnError().single().then((({data:e})=>e)),o.createChannel=(e,o)=>e.from("channels").insert(o).select().single(),o.delChannel=(e,o,n,t)=>e.from("channels").delete().eq("name",o).eq("app_id",n).eq("created_by",t).single(),o.displayChannels=e=>{const o=new l.Table({title:"Channels",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,d.getHumanDate)(e.created_at),Public:e.public?"✅":"❌"})})),s.log.success(o.render())},o.getActiveChannels=(e,o,n)=>a(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).order("created_at",{ascending:!1});return i&&c.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",c=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[l,s]=o.split(":"),d=(0,t.privateDecrypt)({key:n,padding:c,oaepHash:r},Buffer.from(s,a)),p=Buffer.from(l,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),l=(0,t.randomBytes)(16),s=(0,t.createCipheriv)(i,l,n);s.setAutoPadding(!0);const d=`${n.toString(a)}:${(0,t.publicEncrypt)({key:o,padding:c,oaepHash:r},l).toString(a)}`;return{encryptedData:Buffer.concat([s.update(e),s.final()]),ivSessionKey:d}},o.createRSA=()=>{const{publicKey:e,privateKey:o}=(0,t.generateKeyPairSync)("rsa",{modulusLength:2048});return{publicKey:e.export({type:"pkcs1",format:"pem"}),privateKey:o.export({type:"pkcs1",format:"pem"})}}},7863:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const c=n(7304),l=r(n(552)),s=n(6545);o.checkVersionNotUsedInDeviceOverride=(e,o,n)=>a(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);if(i&&c.program.error(`Cannot check Device override ${o}@${n.name} ${(0,s.formatError)(i)}`),t&&t.length>0)if(l.intro(`❌ Version ${o}@${n.name} is used in ${t.length} device override`),yield l.confirm({message:"unlink it?"}))for(const o of t){const n=l.spinner();n.start(`Unlinking device ${o.device_id}`);const{error:t}=yield e.from("devices_override").delete().eq("device_id",o.device_id);t&&(n.stop(`Cannot unlink device ${o.device_id} ${(0,s.formatError)(t)}`),process.exit(1)),n.stop(`✅ Device ${o.device_id} unlinked`)}else c.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((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,c)=>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} @${c} ${(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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.checkLatest=void 0;const l=c(n(5362)),s=r(n(552)),d=c(n(4147));o.checkLatest=()=>a(void 0,void 0,void 0,(function*(){const e=yield(0,l.default)("@capgo/cli");e!==d.default.version&&s.log.warning(`🚨 You are using @capgo/cli@${d.default.version} it's not the latest version.\nPlease use @capgo/cli@${e}" or @capgo/cli@latest to keep up to date with the latest features and bug fixes.`)}))},9656:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((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 c=n(7304),l=n(3847),s=r(n(552)),d=n(6545),p=n(6824),u=n(7863),f=n(1954);o.deleteAppVersion=(e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const{error:i}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("deleted",!1).eq("user_id",n).eq("name",t);i&&c.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 l.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,d.getHumanDate)(e.created_at)},null!=e.keep?{Keep:e.keep}:{}))})),s.log.success(o.render())},o.getActiveAppVersions=(e,o,n)=>a(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1).order("created_at",{ascending:!1});return i&&c.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&&c.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||c.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addCommand=o.addApp=void 0;const c=n(6113),l=n(9011),s=n(7304),d=r(n(552)),p=n(4470),u=n(7482),f=n(9218),y=n(6545);o.addApp=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){var t,i,r;n&&d.intro("Adding"),yield(0,u.checkLatest)(),o.apikey=o.apikey||(0,y.findSavedKey)();const a=yield(0,y.getConfig)();e=e||(null===(t=null==a?void 0:a.app)||void 0===t?void 0:t.appId);const g=(0,y.useLogSnag)();o.apikey||(d.log.error("Missing API key, you need to provide a API key to upload your bundle"),s.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),s.program.error(""));const v=(0,y.createSupabaseClient)(o.apikey),h=yield(0,y.verifyUser)(v,o.apikey,["write","all"]);if(n)yield(0,f.checkAppExistsAndHasPermissionErr)(v,e,!1);else if(yield(0,f.checkAppExistsAndHasPermission)(v,e,!1))return!1;let m,b,{name:_,icon:k}=o;e=e||(null===(i=null==a?void 0:a.app)||void 0===i?void 0:i.appId),_=_||(null===(r=null==a?void 0:a.app)||void 0===r?void 0:r.appName)||"Unknown",k=k||"resources/icon.png",k&&_||(d.log.error("Missing argument, you need to provide a appId and a name, or be in a capacitor project"),s.program.error("")),n&&d.log.info(`Adding ${e} to Capgo`),k&&(0,p.existsSync)(k)?(m=(0,p.readFileSync)(k),b=(0,l.getType)(k)||"image/png",d.log.warn(`Found app icon ${k}`)):(0,p.existsSync)(f.newIconPath)?(m=(0,p.readFileSync)(f.newIconPath),b=(0,l.getType)(f.newIconPath)||"image/png",d.log.warn(`Found app icon ${f.newIconPath}`)):d.log.warn(`Cannot find app icon in any of the following locations: ${k}, ${f.newIconPath}`);const w=`icon_${(0,c.randomUUID)()}`;let C="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(m&&b){const{error:o}=yield v.storage.from(`images/${h}/${e}`).upload(w,m,{contentType:b});o&&(d.log.error(`Could not add app ${(0,y.formatError)(o)}`),s.program.error(""));const{data:n}=yield v.storage.from(`images/${h}/${e}`).getPublicUrl(w);C=(null==n?void 0:n.publicUrl)||C}const{error:P}=yield v.from("apps").insert({icon_url:C,user_id:h,name:_,app_id:e});P&&(d.log.error(`Could not add app ${(0,y.formatError)(P)}`),s.program.error(""));const{error:x}=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 x&&(d.log.error(`Could not add app ${(0,y.formatError)(x)}`),s.program.error("")),yield g.track({channel:"app",event:"App Added",icon:"🎉",user_id:h,tags:{"app-id":e},notify:!1}).catch(),d.log.success(`App ${e} added to Capgo. ${n?"You can upload a bundle now":""}`),n&&(d.outro("Done ✅"),process.exit()),!0})),o.addCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.addApp)(e,n,!0)}))},7626:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.debugApp=o.waitLog=o.cancelCommand=o.markSnag=void 0;const c=r(n(552)),l=n(7304),s=n(9218),d=n(7482),p=n(6545),u=e=>new Promise((o=>{setTimeout(o,e)}));o.markSnag=(e,o,n,t,i="✅")=>a(void 0,void 0,void 0,(function*(){yield n.track({channel:e,event:t,icon:i,user_id:o,notify:!1}).catch()})),o.cancelCommand=(e,n,t,i)=>a(void 0,void 0,void 0,(function*(){c.isCancel(n)&&(yield(0,o.markSnag)(e,t,i,"canceled","🤷"),process.exit())})),o.waitLog=(e,n,t,i,r,l)=>a(void 0,void 0,void 0,(function*(){let a=!0,s=(new Date).toISOString();const d=(0,p.convertAppName)(t),f=`${p.hostWeb}/app/p/${d}`;for(yield(0,o.markSnag)(e,r,i,"Use waitlog");a;){const d=n.from("stats").select("*").eq("app_id",t).order("created_at",{ascending:!1}).gte("created_at",s);l&&d.eq("device_id",l);const{data:p,error:y}=yield d.limit(1).single();if(p&&!y){if(c.log.info(`Device: ${p.device_id}`),"get"===p.action)c.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?(c.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?(c.log.error("Your bundle has failed to download on your device."),c.log.error("Please check if you have network connection and try again")):c.log.info(`Your bundle is downloading ${n}% ...`)}else{if("set"===p.action)return c.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?c.log.error(`No default channel or override (channel/device) found, please create it here ${f}`):"needPlanUpgrade"===p.action?c.log.error("Your are out of quota, please upgrade your plan here https://web.capgo.app/dashboard/settings/plans"):"missingBundle"===p.action?c.log.error("Your bundle is missing, please check how you build your app "):"noNew"===p.action?c.log.error(`Your version in ${p.platform} is the same as your version uploaded, change it to see the update`):"disablePlatformIos"===p.action?c.log.error(`iOS is disabled in the default channel and your device is an iOS device ${f}`):"disablePlatformAndroid"===p.action?c.log.error(`Android is disabled in the default channel and your device is an Android device ${f}`):"disableAutoUpdateToMajor"===p.action?(c.log.error("Auto update to major version is disabled in the default channel."),c.log.error("Set your app to the same major version as the default channel")):"disableAutoUpdateUnderNative"===p.action?(c.log.error("Auto update under native version is disabled in the default channel."),c.log.error("Set your app to the same native version as the default channel.")):"disableDevBuild"===p.action?(c.log.error(`Dev build is disabled in the default channel. ${f}`),c.log.error("Set your channel to allow it if you wanna test your app")):"disableEmulator"===p.action?(c.log.error(`Emulator is disabled in the default channel. ${f}`),c.log.error("Set your channel to allow it if you wanna test your app")):"cannotGetBundle"===p.action?(c.log.error(`We cannot get your bundle from the default channel. ${f}`),c.log.error("Are you sure your default channel has a bundle set?")):"set_fail"===p.action?c.log.error(`Your bundle seems to be corrupted, try to download from ${f} to identify the issue`):"reset"===p.action?c.log.error("Your device has been reset to the builtin bundle, did you added notifyAppReady in your code?"):"update_fail"===p.action?(c.log.error("Your bundle has been installed but failed to call notifyAppReady"),c.log.error("Please check if you have network connection and try again")):"checksum_fail"===p.action&&c.log.error("Your bundle has failed to validate checksum, please check your code and send it again to Capgo")}s=(new Date).toISOString()}yield u(1e3)}return Promise.resolve()})),o.debugApp=(e,n)=>a(void 0,void 0,void 0,(function*(){var t;c.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||(c.log.error("Missing API key, you need to provide an API key to delete your app"),l.program.error("")),e||(c.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),l.program.error(""));const a=(0,p.createSupabaseClient)(n.apikey),u=(0,p.useLogSnag)(),f=yield(0,p.verifyUser)(a,n.apikey);c.log.info("Getting active bundle in Capgo"),yield(0,s.checkAppExistsAndHasPermissionErr)(a,e);const y=yield c.confirm({message:"Automatic check if update working in device ?"});yield(0,o.cancelCommand)("debug",y,f,u),y?(c.log.info(`Wait logs sent to Capgo from ${e} device, Put the app in background and open it again.`),c.log.info("Waiting..."),yield(0,o.waitLog)("debug",a,e,u,f,r),c.outro("Done ✅")):c.outro("Canceled ❌"),c.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const c=n(7304),l=r(n(552)),s=n(9218),d=n(6545);o.deleteApp=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;l.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||c.program.error("Missing API key, you need to provide a API key to upload your bundle"),e||c.program.error("Missing argument, you need to provide a appId, or be in a capacitor project");const r=(0,d.createSupabaseClient)(o.apikey),a=yield(0,d.verifyUser)(r,o.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(r,e);const{error:p}=yield r.storage.from(`images/${a}`).remove([e]);p&&c.program.error(`Could not add app ${(0,d.formatError)(p)}`);const{error:u}=yield r.storage.from(`apps/${e}/${a}`).remove(["versions"]);u&&c.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&&c.program.error(`Could not delete app ${(0,d.formatError)(f)}`),yield i.track({channel:"app",event:"App Deleted",icon:"🗑️",user_id:a,tags:{"app-id":e},notify:!1}).catch(),l.log.success("App deleted in Capgo"),l.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getInfo=void 0;const r=n(7147),a=n(1017),c=i(n(2037)),l=i(n(5362)),s=i(n(7176)),d=i(n(4147));o.getInfo=()=>t(void 0,void 0,void 0,(function*(){console.log(" 💊 Capgo Doctor 💊\n"),console.log(` OS: ${c.default.version()}\n`),console.log(" Installed Dependencies:\n");const e=yield t(void 0,void 0,void 0,(function*(){const{dependencies:e}=yield t(void 0,void 0,void 0,(function*(){const e=(0,r.readFileSync)((0,a.join)(process.cwd(),"package.json"));return JSON.parse(e)})),o={"@capgo/cli":d.default.version};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&n.startsWith("@capgo/")&&(o[n]=e[n]);return o}));0===Object.keys(e).length&&(console.log("\n"),console.log("%s","🚨 No dependencies found"),process.exit(1));for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const n=e[o];console.log(` ${o}: ${n}`)}console.log("\n");const o=new s.default;o.add("loading",{text:"Loading latest dependencies"});const n=yield(e=>t(void 0,void 0,void 0,(function*(){const o={},n=[];for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.push((0,l.default)(o));return yield Promise.all(n).then((n=>{const t=Object.keys(e);for(let e=0;e<n.length;e+=1){const i=n[e];i&&(o[t[e]]=i)}})),o})))(e);o.succeed("loading",{text:"Latest Dependencies:"}),console.log("\n");for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const o=n[e];console.log(` ${e}: ${o}`)}JSON.stringify(e)!==JSON.stringify(n)&&(console.log("\n"),console.log("%s","🚨 Some dependencies are not up to date"),process.exit(1)),console.log("\n"),console.log("%s","✅ All dependencies are up to date"),process.exit()}))},8373:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=o.getActiveApps=void 0;const c=n(7304),l=n(3847),s=r(n(552)),d=n(6545),p=n(7482);o.getActiveApps=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.from("apps").select().eq("user_id",o).order("created_at",{ascending:!1});return t&&c.program.error(`Apps not found in database ${(0,d.formatError)(t)} `),n})),o.listApp=e=>a(void 0,void 0,void 0,(function*(){s.intro("List apps in Capgo"),yield(0,p.checkLatest)(),e.apikey=e.apikey||(0,d.findSavedKey)();const n=(0,d.createSupabaseClient)(e.apikey),t=yield(0,d.verifyUser)(n,e.apikey);s.log.info("Getting active bundle in Capgo");const i=yield(0,o.getActiveApps)(n,t);s.log.info(`Active app in Capgo: ${null==i?void 0:i.length}`),(e=>{const o=new l.Table({title:"Apps",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow({Name:e.name,Created:(0,d.getHumanDate)(e.created_at)})})),s.log.success(o.render())})(i),s.outro("Done ✅"),process.exit()}))},5789:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setApp=void 0;const c=n(6113),l=n(9011),s=n(7304),d=r(n(552)),p=n(4470),u=n(9218),f=n(6545);o.setApp=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;d.intro("Set app"),o.apikey=o.apikey||(0,f.findSavedKey)();const t=yield(0,f.getConfig)();e=e||(null===(n=null==t?void 0:t.app)||void 0===n?void 0:n.appId),o.apikey||(d.log.error("Missing API key, you need to provide a API key to upload your bundle"),s.program.error("")),e||(d.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),s.program.error(""));const i=(0,f.createSupabaseClient)(o.apikey),r=yield(0,f.verifyUser)(i,o.apikey,["write","all"]);yield(0,u.checkAppExistsAndHasPermissionErr)(i,e);const{name:a,icon:y,retention:g}=o;let v,h;g&&!Number.isNaN(Number(g))?(d.log.error("retention value must be a number"),s.program.error("")):g&&g<0&&(d.log.error("retention value cannot be less than 0"),s.program.error(""));const m=`icon_${(0,c.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,l.getType)(y)||"image/png",d.log.warn(`Found app icon ${y}`)):(0,p.existsSync)(u.newIconPath)?(v=(0,p.readFileSync)(u.newIconPath),h=(0,l.getType)(u.newIconPath)||"image/png",d.log.warn(`Found app icon ${u.newIconPath}`)):d.log.warn(`Cannot find app icon in any of the following locations: ${y}, ${u.newIconPath}`),v&&h){const{error:o}=yield i.storage.from(`images/${r}/${e}`).upload(m,v,{contentType:h});o&&(d.log.error(`Could not add app ${(0,f.formatError)(o)}`),s.program.error(""));const{data:n}=yield i.storage.from(`images/${r}/${e}`).getPublicUrl(m);b=(null==n?void 0:n.publicUrl)||b}const{error:_}=yield i.from("apps").update({icon_url:b,name:a,retention:g?24*g*60*60:void 0}).eq("app_id",e).eq("user_id",r);_&&(d.log.error(`Could not add app ${(0,f.formatError)(_)}`),s.program.error("")),d.outro("Done ✅"),process.exit()}))},3515:function(e,o,n){var t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.checkIndexPosition=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 c of t){const t=r.default.join(e,c),l=i.default.statSync(t);if(l.isDirectory()){if((0,o.searchInDirectory)(t,n))return!0}else if(l.isFile()&&".js"===r.default.extname(t)&&a(t,n))return!0}return!1},o.checkIndexPosition=e=>{const n=i.default.readdirSync(e);if(1===n.length){const t=r.default.join(e,n[0]);if(i.default.statSync(t).isDirectory())return(0,o.checkIndexPosition)(t)}return n.indexOf("index.html")>-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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))},c=this&&this.__asyncValues||function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),o={},t("next"),t("throw"),t("return"),o[Symbol.asyncIterator]=function(){return this},o);function t(n){o[n]=e[n]&&function(o){return new Promise((function(t,i){!function(e,o,n,t){Promise.resolve(t).then((function(o){e({value:o,done:n})}),o)}(t,i,(o=e[n](o)).done,o.value)}))}}},l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.cleanupBundle=void 0;const s=n(7304),d=l(n(1505)),p=r(n(552)),u=l(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,l=o.force||!1,u=yield(0,f.getConfig)();e=e||(null===(n=null==u?void 0:u.app)||void 0===n?void 0:n.appId),t||s.program.error("Missing API key, you need to provide an API key to delete your app"),e||s.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const m=(0,f.createSupabaseClient)(t),b=yield(0,f.verifyUser)(m,t);yield(0,g.checkAppExistsAndHasPermissionErr)(m,e),p.log.info("Querying all available versions in Capgo");let _=yield(0,y.getActiveAppVersions)(m,e,b);const k=yield(0,y.getChannelsVersion)(m,e);if(p.log.info(`Total active versions in Capgo: ${null==_?void 0:_.length}`),0===(null==_?void 0:_.length))return void p.log.error("No versions found, aborting cleanup");if(i){const e=`${d.default.inc(i,"major")}`;p.log.info(`Querying available versions in Capgo between ${i} and ${e}`),_=((e,o,n)=>{const t=[];return null==e||e.forEach((e=>{d.default.gte(e.name,o)&&d.default.lt(e.name,`${n}`)&&t.push(e)})),t})(_,i,e),p.log.info(`Active versions in Capgo between ${i} and ${e}: ${null==_?void 0:_.length}`)}const w=[];let C=0;if(_.forEach((e=>{const o=k.find((o=>o===e.id));C<r||o?(e.keep=o?"✅ (Linked to channel)":"✅",C+=1):(e.keep="❌",w.push(e))})),0!==w.length){if((0,y.displayBundles)(_),!l&&"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,l;return a(void 0,void 0,void 0,(function*(){var a,s,d,u;try{for(i=!0,r=c(e);!(a=(l=yield r.next()).done);i=!0){u=l.value,i=!1;const e=u;p.log.warn(`Removing ${e.name} created on ${(0,f.getHumanDate)(e.created_at)}`),yield(0,y.deleteSpecificVersion)(o,n,t,e.name)}}catch(e){s={error:e}}finally{try{i||a||!(d=r.return)||(yield d.call(r))}finally{if(s)throw s.error}}}))})(w,m,e,b),p.outro("Done ✅"),process.exit()}else p.log.warn("Nothing to be removed, aborting removal...")}))},7978:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const c=n(7147),l=n(7304),s=r(n(552)),d=n(407),p=n(6545),u=n(7482);o.decryptZip=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i,r,a,f,y;s.intro("Decrypt zip file"),yield(0,u.checkLatest)(),(0,c.existsSync)(e)||l.program.error(`Zip not found at the path ${e}`);const g=yield(0,p.getConfig)(),{extConfig:v}=g.app;n.key||(0,c.existsSync)(p.baseKey)||(null===(i=null===(t=v.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===i?void 0:i.privateKey)||l.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,c.existsSync)(h)||m?(0,c.existsSync)(h)&&(m=(0,c.readFileSync)(h).toString()):l.program.error(`Cannot find public key ${h} or as keyData option or in ${g.app.extConfigFilePath}`);const b=(0,c.readFileSync)(e),_=(0,d.decryptSource)(b,o,null!==(y=null!==(f=n.keyData)&&void 0!==f?f:m)&&void 0!==y?y:"");(0,c.writeFileSync)(`${e}_decrypted.zip`,_),s.outro(`Decrypted zip file at ${e}_decrypted.zip`),process.exit()}))},3930:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteBundle=void 0;const c=n(7304),l=r(n(552)),s=n(9218),d=n(6545),p=n(9656);o.deleteBundle=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i;l.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||(l.log.error("Missing API key, you need to provide a API key to upload your bundle"),c.program.error("")),o||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.program.error(""));const a=(0,d.createSupabaseClient)(n.apikey),u=yield(0,d.verifyUser)(a,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(a,o);const f=n.apikey||(0,d.findSavedKey)();o=o||(null===(i=null==r?void 0:r.app)||void 0===i?void 0:i.appId),f||(l.log.error("Missing API key, you need to provide an API key to delete your app"),c.program.error("")),e||(l.log.error("Missing argument, you need to provide a bundleId, or be in a capacitor project"),c.program.error("")),o||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.program.error("")),l.log.info(`Deleting bundle ${o}@${e} from Capgo`),yield(0,p.deleteSpecificVersion)(a,o,u,e),l.log.success(`Bundle ${o}@${e} deleted in Capgo`),l.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const l=n(7147),s=n(7304),d=c(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,l.existsSync)(e)||(p.log.error(`Error: Zip not found at the path ${e}`),s.program.error(""));const n=o.key||y.baseKeyPub;let t=o.keyData||"";(0,l.existsSync)(n)||t?(0,l.existsSync)(n)&&(t=(0,l.readFileSync)(n).toString()):(p.log.warning(`Cannot find public key ${n} or as keyData option`),d.default.isCI&&(p.log.error("Error: Missing public key"),s.program.error("")),(yield p.confirm({message:"Do you want to use our public key ?"}))||(p.log.error("Error: Missing public key"),s.program.error("")),t=y.defaulPublicKey);const i=(0,l.readFileSync)(e),r=(0,f.encryptSource)(i,t);p.log.success(`ivSessionKey: ${r.ivSessionKey}`),(0,l.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listBundle=void 0;const c=n(7304),l=r(n(552)),s=n(9218),d=n(9656),p=n(6545),u=n(7482);o.listBundle=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;l.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||(l.log.error("Missing API key, you need to provide a API key to upload your bundle"),c.program.error("")),e||(l.log.error("Missing argument, you need to provide a appid, or be in a capacitor project"),c.program.error(""));const i=(0,p.createSupabaseClient)(o.apikey),r=yield(0,p.verifyUser)(i,o.apikey);l.log.info(`Querying available versions of: ${e} in Capgo`),yield(0,s.checkAppExistsAndHasPermissionErr)(i,e);const a=yield(0,d.getActiveAppVersions)(i,e,r);l.log.info(`Active versions in Capgo: ${null==a?void 0:a.length}`),(0,d.displayBundles)(a),l.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.uploadDeprecatedCommand=o.uploadCommand=o.uploadBundle=void 0;const l=n(6113),s=n(7147),d=c(n(3844)),p=n(7304),u=r(n(552)),f=n(5906),y=c(n(7812)),g=c(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:c,path:k,channel:w}=o;const{external:C,key:P=!1,displayIvSession:x}=o,O=o.apikey||(0,b.findSavedKey)(),S=(0,b.useLogSnag)();w=w||"dev";const j=yield(0,b.getConfig)(),$=!0===(j.app.extConfig.plugins&&j.app.extConfig.plugins.CapacitorUpdater&&j.app.extConfig.plugins.CapacitorUpdater.localS3),A=o.codeCheck;e=e||(null===(t=null==j?void 0:j.app)||void 0===t?void 0:t.appId);const I=(0,l.randomUUID)().split("-")[0];c=c||(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.${I}`,b.regexSemver.test(c)||(u.log.error(`Your bundle name ${c}, is not valid it should follow semver convention : https://semver.org/`),p.program.error("")),k=k||(null===(a=null==j?void 0:j.app)||void 0===a?void 0:a.webDir),O||(u.log.error("Missing API key, you need to provide a API key to upload your bundle"),p.program.error("")),e&&c&&k||(u.log.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),p.program.error("")),(0,s.existsSync)(k)||(u.log.error(`Path ${k} does not exist, build your app first, or provide a valid path`),p.program.error("")),(void 0===A||A)&&((0,_.searchInDirectory)(k,"notifyAppReady")||(u.log.error("notifyAppReady() is missing in the source code. see: https://capgo.app/docs/plugin/api/#notifyappready"),p.program.error("")),(0,_.checkIndexPosition)(k)||(u.log.error("index.html is missing in the root folder or in the only folder in the root folder"),p.program.error(""))),u.log.info(`Upload ${e}@${c} started from path "${k}" to Capgo cloud`);const M=(0,b.createSupabaseClient)(O),D=yield(0,b.verifyUser)(M,O,["write","all","upload"]);yield(0,b.checkPlanValid)(M,D,!1),yield(0,h.checkAppExistsAndHasPermissionErr)(M,e);const{data:E,error:U}=yield M.rpc("is_trial",{userid:D}).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 M.rpc("exist_app_versions",{appid:e,apikey:O,name_version:c}).single();(q||K)&&(u.log.error(`Version already exists ${(0,b.formatError)(K)}`),p.program.error(""));const B=`${c.replace(/[^a-zA-Z0-9-_.!*'()]/g,"__")}.zip`;let L,V="",F=null;if(C)C&&!C.startsWith("https://")?(u.log.error(`External link should should start with "https://" current is "${C}"`),p.program.error("")):(yield S.track({channel:"app",event:"App external",icon:"📤",user_id:D,tags:{"app-id":e},notify:!1}).catch(),L=o.ivSessionKey);else{const n=new d.default;n.addLocalFolder(k),F=n.toBuffer();const t=u.spinner();if(t.start("Calculating checksum"),V=yield(0,f.checksum)(F,"crc32"),t.stop(`Checksum: ${V}`),P||(0,s.existsSync)(b.baseKeyPub)){const n="string"==typeof P?P:b.baseKeyPub;let t=o.keyData||"";t||(0,s.existsSync)(n)||(u.log.error(`Cannot find public key ${n}`),y.default.isCI&&p.program.error(""),(yield u.confirm({message:"Do you want to use our public key ?"}))||(u.log.error("Error: Missing public key"),p.program.error("")),t=b.defaulPublicKey),yield S.track({channel:"app",event:"App encryption",icon:"🔑",user_id:D,tags:{"app-id":e},notify:!1}).catch(),t||(t=(0,s.readFileSync)(n).toString()),u.log.info("Encrypting your bundle");const i=(0,m.encryptSource)(F,t);L=i.ivSessionKey,x&&u.log.info(`Your Iv Session key is ${L},\nkeep it safe, you will need it to decrypt your bundle.\nIt will be also visible in your dashboard\n`),F=i.encryptedData}const i=Math.floor(F.byteLength/1024/1024);i>20&&(u.log.warn(`WARNING !!\nThe app size is ${i} Mb, this may take a while to download for users\n`),u.log.info("Learn how to optimize your assets https://capgo.app/blog/optimise-your-images-for-updates/\n"),yield S.track({channel:"app-error",event:"App Too Large",icon:"🚛",user_id:D,tags:{"app-id":e},notify:!1}).catch())}const N={bucket_id:C?void 0:B,user_id:D,name:c,app_id:e,session_key:L,external_url:C,storage_provider:C?"external":"r2-direct",checksum:V},{error:z}=yield(0,b.updateOrCreateVersion)(M,N,O);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)(M,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)(M,N,O);t&&(u.log.error(`Cannot update bundle ${(0,b.formatError)(z)}`),p.program.error("")),o.stop("Bundle Uploaded 💪")}const{data:R}=yield M.rpc("get_app_versions",{apikey:O,name_version:c,appid:e}).single();if(R){const{error:n,data:t}=yield(0,b.updateOrCreateChannel)(M,{name:w,app_id:e,created_by:D,version:R});n&&(u.log.error('Cannot set channel, the upload key is not allowed to do that, use the "all" for this.'),p.program.error(""));const i=(0,b.convertAppName)(e),r=`${b.hostWeb}/app/p/${i}/channel/${t.id}`;(null==t?void 0:t.public)?u.log.info("Your update is now available in your public channel 🎉"):(null==t?void 0:t.id)&&u.log.info(`Link device to this bundle to try it: ${r}`),o.bundleUrl&&u.log.info(`Bundle url: ${r}`)}else u.log.warn("Cannot set bundle with upload key, use key with more rights for that"),p.program.error("");return yield S.track({channel:"app",event:"App Uploaded",icon:"⏫",user_id:D,tags:{"app-id":e},notify:!1}).catch(),n&&(u.outro("Time to share your update to the world 🌍"),process.exit()),!0})),o.uploadCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){try{yield(0,o.uploadBundle)(e,n,!0)}catch(e){u.log.error(JSON.stringify(e)),p.program.error("")}})),o.uploadDeprecatedCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){u.log.warn('⚠️ This command is deprecated, use "npx @capgo/cli bundle upload" instead ⚠️');try{yield(0,o.uploadBundle)(e,n,!0)}catch(e){u.log.error(JSON.stringify(e)),p.program.error("")}}))},7103:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.zipBundle=void 0;const l=n(6113),s=n(7147),d=c(n(3844)),p=n(7304),u=r(n(552)),f=n(5906),y=n(7482),g=n(6545),v=n(3515);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:c}=o;const h=(0,g.useLogSnag)(),m=yield(0,g.getConfig)();e=e||(null===(n=null==m?void 0:m.app)||void 0===n?void 0:n.appId);const b=(0,l.randomUUID)().split("-")[0];a=a||(null===(i=null===(t=null==m?void 0:m.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version)||`0.0.1-beta.${b}`,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("")),c=c||(null===(r=null==m?void 0:m.app)||void 0===r?void 0:r.webDir),e&&a&&c||(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 "${c}"`);const _=o.codeCheck;(void 0===_||_)&&((0,v.searchInDirectory)(c,"notifyAppReady")||(u.log.error("notifyAppReady() is missing in the source code. see: https://capgo.app/docs/plugin/api/#notifyappready"),p.program.error("")),(0,v.checkIndexPosition)(c)||(u.log.error("index.html is missing in the root folder or in the only folder in the root folder"),p.program.error("")));const k=new d.default;k.addLocalFolder(c);const w=k.toBuffer();u.log.info(`Zipped ${w.byteLength} bytes`);const C=u.spinner();C.start("Calculating checksum");const P=yield(0,f.checksum)(w,"crc32");C.stop(`Checksum: ${P}`);const x=Math.floor(w.byteLength/1024/1024);x>20&&(u.log.warn(`WARNING !!\nThe app size is ${x} 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 h.track({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"app-id":e},notify:!1}).catch());const O=u.spinner();O.start(`Saving to ${e}_${a}.zip`),(0,s.writeFileSync)(`${e}_${a}.zip`,w),O.stop(`Saved to ${e}_${a}.zip`),yield h.track({channel:"app",event:"App zip",icon:"⏫",tags:{"app-id":e},notify:!1}).catch(),u.outro("Done ✅"),process.exit()}))},4402:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addChannelCommand=o.addChannel=void 0;const c=n(7304),l=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.addChannel=(e,o,n,t=!0)=>a(void 0,void 0,void 0,(function*(){var i;l.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||(l.log.error("Missing API key, you need to provide a API key to upload your bundle"),c.program.error("")),o||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.program.error(""));const u=(0,p.createSupabaseClient)(n.apikey),f=yield(0,p.verifyUser)(u,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(u,o),l.log.info(`Creating channel ${o}#${e} to Capgo`);try{const n=yield(0,d.findUnknownVersion)(u,o);n||(l.log.error("Cannot find default version for channel creation, please contact Capgo support 🤨"),c.program.error("")),yield(0,d.createChannel)(u,{name:e,app_id:o,version:n.id,created_by:f}),l.log.success("Channel created ✅"),yield a.track({channel:"channel",event:"Create channel",icon:"✅",user_id:f,tags:{"app-id":o,channel:e},notify:!1}).catch()}catch(e){return l.log.error("Cannot create Channel 🙀"),!1}return t&&(l.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteChannel=void 0;const c=n(7304),l=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.deleteChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t;l.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||(l.log.error("Missing API key, you need to provide a API key to upload your bundle"),c.program.error("")),o||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.program.error(""));const a=(0,p.createSupabaseClient)(n.apikey),u=yield(0,p.verifyUser)(a,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(a,o),l.log.info(`Deleting channel ${o}#${e} from Capgo`);try{yield(0,d.delChannel)(a,e,o,u),l.log.success("Channel deleted"),yield r.track({channel:"channel",event:"Delete channel",icon:"✅",tags:{"user-id":u,"app-id":o,channel:e},notify:!1}).catch()}catch(e){l.log.error("Cannot delete Channel 🙀")}l.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listChannels=void 0;const c=n(7304),l=r(n(552)),s=n(9218),d=n(6824),p=n(6545);o.listChannels=(e,o)=>a(void 0,void 0,void 0,(function*(){var n;l.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||l.log.error("Missing API key, you need to provide a API key to upload your bundle"),e||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.program.error(""));const r=(0,p.createSupabaseClient)(o.apikey),a=yield(0,p.verifyUser)(r,o.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(r,e),l.log.info("Querying available channels in Capgo"),yield(0,s.checkAppExistsAndHasPermissionErr)(r,e);const u=yield(0,d.getActiveChannels)(r,e,a);l.log.info(`Active channels in Capgo: ${null==u?void 0:u.length}`),(0,d.displayChannels)(u),yield i.track({channel:"channel",event:"List channel",icon:"✅",user_id:a,tags:{"app-id":e},notify:!1}).catch(),l.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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const c=n(7304),l=r(n(552)),s=n(9218),d=n(6545);o.setChannel=(e,o,n)=>a(void 0,void 0,void 0,(function*(){var t,i,r;l.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||(l.log.error("Missing API key, you need to provide a API key to upload your bundle"),c.program.error("")),o||(l.log.error("Missing argument, you need to provide a appId, or be in a capacitor project"),c.program.error(""));const u=(0,d.createSupabaseClient)(n.apikey),f=yield(0,d.verifyUser)(u,n.apikey,["write","all"]);yield(0,s.checkAppExistsAndHasPermissionErr)(u,o);const{bundle:y,latest:g,downgrade:v,upgrade:h,ios:m,android:b,selfAssign:_,state:k}=n;e||(l.log.error("Missing argument, you need to provide a channel"),c.program.error("")),g&&y&&(l.log.error("Cannot set latest and bundle at the same time"),c.program.error("")),null==y&&null==k&&null==g&&null==v&&null==h&&null==m&&null==b&&null==_&&(l.log.error("Missing argument, you need to provide a option to set"),c.program.error(""));try{yield(0,d.checkPlanValid)(u,f),yield(0,s.checkAppExistsAndHasPermissionErr)(u,o);const n={created_by:f,app_id:o,name:e,version:void 0},t=g?null===(r=null===(i=null==a?void 0:a.app)||void 0===i?void 0:i.package)||void 0===r?void 0:r.version:y;if(null!=t){const{data:i,error:r}=yield u.from("app_versions").select().eq("app_id",o).eq("name",t).eq("user_id",f).eq("deleted",!1).single();!r&&i||(l.log.error(`Cannot find version ${t}`),c.program.error("")),l.log.info(`Set ${o} channel: ${e} to @${t}`),n.version=i.id}null!=k&&("public"!==k&&"private"!==k||l.log.info(`Set ${o} channel: ${e} to public or private is deprecated, use default or normal instead`),l.log.info(`Set ${o} channel: ${e} to ${"public"===k||"default"===k?"default":"normal"}`),n.public="public"===k||"default"===k),null!=v&&(l.log.info(`Set ${o} channel: ${e} to ${v?"allow":"disallow"} downgrade`),n.disableAutoUpdateUnderNative=!v),null!=h&&(l.log.info(`Set ${o} channel: ${e} to ${h?"allow":"disallow"} upgrade`),n.disableAutoUpdateToMajor=!h),null!=m&&(l.log.info(`Set ${o} channel: ${e} to ${m?"allow":"disallow"} ios update`),n.ios=!!m),null!=b&&(l.log.info(`Set ${o} channel: ${e} to ${b?"allow":"disallow"} android update`),n.android=!!b),null!=_&&(l.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&&(l.log.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.'),c.program.error(""))}catch(e){l.log.error('Cannot set channel the upload key is not allowed to do that, use the "all" for this.'),c.program.error("")}yield p.track({channel:"channel",event:"Set channel",icon:"✅",user_id:f,tags:{"user-id":f,"app-id":o},notify:!1}).catch()}catch(e){l.log.error(`Unknow error ${(0,d.formatError)(e)}`),c.program.error("")}l.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),c=n(2083),l=n(7978),s=n(3333),d=n(7171),p=n(1628),u=n(6122),f=n(3930),y=n(593),g=n(2510),v=t(n(4147)),h=n(5041),m=n(8373),b=n(2393),_=n(4402),k=n(7422),w=n(2667),C=n(5789),P=n(6626),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 O=i.program.command("app").description("Manage app");O.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"),O.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"),O.command("list").alias("l").description("list apps in Capgo Cloud").action(m.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),O.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),O.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 and index present in root folder").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(c.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(c.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(l.decryptZip).option("--key <key>","custom path for private signing key").option("--key-data <keyData>","base64 private signing key"),S.command("encrypt [zipPath]").description("Encrypt a zip bundle").action(s.encryptZip).option("--key <key>","custom path for private signing key").option("--key-data <keyData>","base64 private signing key"),S.command("zip [appId]").description("Zip a bundle").action(r.zipBundle).option("-p, --path <path>","path of the folder to upload").option("-b, --bundle <bundle>","bundle version number to name the zip file").option("--no-code-check","Ignore checking if notifyAppReady() is called in soure code and index present in root folder");const j=i.program.command("channel").description("Manage channel");j.command("add [channelId] [appId]").alias("a").description("Create channel").action(_.addChannelCommand).option("-d, --default","set the channel as default"),j.command("delete [channelId] [appId]").alias("d").description("Delete channel").action(k.deleteChannel),j.command("list [appId]").alias("l").description("List channel").action(w.listChannels),j.command("set [channelId] [appId]").alias("s").description("Set channel").action(y.setChannel).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the file to set").option("-s, --state <state>","set the state of the channel, default or normal").option("--latest","get the latest version key in the package.json to set it to the channel").option("--downgrade","Allow to downgrade to version under native one").option("--no-downgrade","Disable downgrade to version under native one").option("--upgrade","Allow to upgrade to version above native one").option("--no-upgrade","Disable upgrade to version above native one").option("--ios","Allow sending update to ios devices").option("--no-ios","Disable sending update to ios devices").option("--android","Allow sending update to android devices").option("--no-android","Disable sending update to android devices").option("--self-assign","Allow to device to self assign to this channel").option("--no-self-assign","Disable devices to self assign to this channel");const $=i.program.command("key").description("Manage key");$.command("save").description("Save base64 signing key in capacitor config, usefull for CI").action(u.saveKeyCommand).option("-f, --force","force generate a new one").option("--key","key path to save in capacitor config").option("--key-data","key data to save in capacitor config"),$.command("create").description("Create a new signing key").action(u.createKeyCommand).option("-f, --force","force generate a new one"),i.program.command("upload [appId]").alias("u").description("(Deprecated) Upload a new bundle to Capgo Cloud").action(g.uploadDeprecatedCommand).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to Capgo Cloud").option("--key <key>","custom path for public signing key").option("--key-data <keyData>","base64 public signing key").option("--bundle-url","prints bundle url into stdout").option("--no-key","ignore signing key and send clear update").option("--display-iv-session","Show in the console the iv and session key used to encrypt the update").option("-b, --bundle <bundle>","bundle version number of the file to upload"),i.program.parseAsync()},6104:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.initApp=void 0;const c=n(7147),l=n(2081),s=n(6301),d=r(n(552)),p=n(7626),u=n(6122),f=n(4402),y=n(2510),g=n(5041),v=n(7171),h=n(7482),m=n(6545),b="import { CapacitorUpdater } from '@capgo/capacitor-updater'",_="CapacitorUpdater.notifyAppReady()",k=/import.*from.*/g,w="production",C={stdio:"pipe"},P=(e,o,n)=>a(void 0,void 0,void 0,(function*(){d.isCancel(e)&&(yield(0,p.markSnag)("onboarding-v2",o,n,"canceled","🤷"),process.exit())})),x=(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 O=d.spinner();O.start("Running: npx @capgo/cli@latest login ***"),(yield(0,g.login)(e,n,!1))?O.stop("Login Done ✅"):O.stop("Login already done ✅");const S=(0,m.createSupabaseClient)(e),j=yield(0,m.verifyUser)(S,e,["upload","all","read","write"]);yield x(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 x(e,o,2)})))(j,i,o,n),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Create default channel ${w} for ${t} in Capgo?`});if(yield P(i,e,o),i){const e=d.spinner();e.start(`Running: npx @capgo/cli@latest channel add ${w} ${t} --default`),(yield(0,f.addChannel)(w,t,{default:!0,apikey:n},!1))?e.stop("Channel add Done ✅"):e.stop("Channel already added ✅")}else d.log.info(`Run yourself "npx @capgo/cli@latest channel add ${w} ${t} --default"`);yield x(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,c.readFileSync)("package.json").toString()),n=(0,s.findPackageManagerType)();"unknown"===n&&(e.stop("Cannot reconize package manager, please run `capgo init` in a capacitor project with npm, pnpm or yarn"),process.exit());const t="yarn"===n?"add":"install";o.dependencies["@capgo/capacitor-updater"]?e.stop("Capgo already installed ✅"):(yield(0,l.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 x(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,c.readFileSync)(t).toString(),r=i.match(k),a=null==r?void 0:r.pop();if(a||(n.stop("Cannot find import line in main file, use manual installation: https://capgo.app/docs/plugin/installation/"),process.exit()),i.includes(_))n.stop(`Code already added to ${t} ✅`);else{const e=i.replace(a,`${a}\n${b};\n\n${_};\n`);(0,c.writeFileSync)(t,e),n.stop(`Code added to ${t} ✅`)}yield x(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 x(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,c.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,l.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 x(e,o,7)})))(j,i,0,o),yield((e,o,n,t)=>a(void 0,void 0,void 0,(function*(){const i=yield d.confirm({message:`Automatic upload ${t} bundle to Capgo?`});if(yield P(i,e,o),i){const e=d.spinner();e.start("Running: npx @capgo/cli@latest bundle upload"),(yield(0,y.uploadBundle)(t,{channel:w,apikey:n},!1))?e.stop("Upload Done ✅"):(e.stop("Upload failed ❌"),process.exit())}else d.log.info("Upload yourself with command: npx @capgo/cli@latest bundle upload");yield x(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,l.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 x(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 x(e,o,10)})))(j,i,S,o),yield x(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{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.createKeyCommand=o.createKey=o.saveKeyCommand=o.saveKey=void 0;const c=n(7147),l=n(7304),s=n(7778),d=r(n(552)),p=n(407),u=n(6545),f=n(7482);o.saveKey=(e,o=!0)=>a(void 0,void 0,void 0,(function*(){(0,c.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),l.program.error(""));const n=yield(0,u.getConfig)(),{extConfig:t}=n.app,i=e.key||u.baseKey;let r=e.keyData||"";if((0,c.existsSync)(i)||r)(0,c.existsSync)(i)&&(r=(0,c.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}`),l.program.error("")}return t&&(t.plugins||(t.plugins={extConfig:{},CapacitorUpdater:{}}),t.plugins.CapacitorUpdater||(t.plugins.CapacitorUpdater={}),t.plugins.CapacitorUpdater.privateKey=r,(0,s.writeConfig)(t,n.app.extConfigFilePath)),o&&(d.log.success(`private key saved into ${n.app.extConfigFilePath} file in local directory`),d.log.success("your app will decode the zip archive with this key")),!0})),o.saveKeyCommand=e=>a(void 0,void 0,void 0,(function*(){d.intro("Save keys 🔑"),yield(0,f.checkLatest)(),yield(0,o.saveKey)(e)})),o.createKey=(e,o=!0)=>a(void 0,void 0,void 0,(function*(){o&&d.intro("Create keys 🔑"),(0,c.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),l.program.error(""));const{publicKey:n,privateKey:t}=(0,p.createRSA)();if((0,c.existsSync)(u.baseKeyPub)&&!e.force){if(!o)return!1;d.log.error("Public Key already exists, use --force to overwrite"),l.program.error("")}if((0,c.writeFileSync)(u.baseKeyPub,n),(0,c.existsSync)(u.baseKey)&&!e.force){if(!o)return!1;d.log.error("Private Key already exists, use --force to overwrite"),l.program.error("")}(0,c.writeFileSync)(u.baseKey,t);const i=yield(0,u.getConfig)(),{extConfig:r}=i.app;return r&&(r.plugins||(r.plugins={extConfig:{},CapacitorUpdater:{}}),r.plugins.CapacitorUpdater.privateKey=t,(0,s.writeConfig)(r,i.app.extConfigFilePath)),o&&(d.log.success("Your RSA key has been generated"),d.log.success(`Public key saved in ${u.baseKeyPub}`),d.log.success("This key will be use to crypt your bundle before sending it to Capgo"),d.log.success("Than make them unreadable by Capgo and unmodifiable by anyone"),d.log.success(`Private key saved in ${i.app.extConfigFilePath}`),d.log.success("Your app will be the only one having it"),d.log.success("Only your users can decrypt your update"),d.log.success("Only you can send them an update"),d.outro("Done ✅")),!0})),o.createKeyCommand=e=>a(void 0,void 0,void 0,(function*(){yield(0,f.checkLatest)(),yield(0,o.createKey)(e)}))},5041:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.loginCommand=o.login=void 0;const c=n(7147),l=n(2037),s=n(7304),d=r(n(552)),p=n(6545),u=n(7482);o.login=(e,o,n=!0)=>a(void 0,void 0,void 0,(function*(){if(n&&d.intro("Login to Capgo"),!e)return n&&s.program.error("Missing API key, you need to provide a API key to upload your bundle"),!1;yield(0,u.checkLatest)();try{const{local:n}=o,t=(0,p.useLogSnag)();if(n)(0,c.existsSync)(".git")||(d.log.error("To use local you should be in a git repository"),s.program.error("")),(0,c.writeFileSync)(".capgo",`${e}\n`),(0,c.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,l.homedir)();(0,c.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const i=(0,p.createSupabaseClient)(e),r=yield(0,p.verifyUser)(i,e,["write","all","upload"]);yield t.track({channel:"user-login",event:"User CLI login",icon:"✅",user_id:r,notify:!1}).catch(),d.log.success(`login saved into .capgo file in ${n?"local":"home"} directory`)}catch(e){d.log.error("Error while saving login"),process.exit(1)}return n&&(d.outro("Done ✅"),process.exit()),!0})),o.loginCommand=(e,n)=>a(void 0,void 0,void 0,(function*(){(0,o.login)(e,n,!0)}))},6545:function(e,o,n){var t=this&&this.__createBinding||(Object.create?function(e,o,n,t){void 0===t&&(t=n);var i=Object.getOwnPropertyDescriptor(o,n);i&&!("get"in i?!o.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return o[n]}}),Object.defineProperty(e,t,i)}:function(e,o,n,t){void 0===t&&(t=n),e[t]=o[n]}),i=this&&this.__setModuleDefault||(Object.create?function(e,o){Object.defineProperty(e,"default",{enumerable:!0,value:o})}:function(e,o){e.default=o}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(o,e,n);return i(o,e),o},a=this&&this.__awaiter||function(e,o,n,t){return new(n||(n=Promise))((function(i,r){function a(e){try{l(t.next(e))}catch(e){r(e)}}function c(e){try{l(t.throw(e))}catch(e){r(e)}}function l(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,c)}l((t=t.apply(e,o||[])).next())}))},c=this&&this.__await||function(e){return this instanceof c?(this.v=e,this):new c(e)},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.__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:c(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||l(e,o)}))})}function l(e,o){try{(n=i[e](o)).value instanceof c?Promise.resolve(n.value.v).then(s,d):p(r[0][2],n)}catch(e){p(r[0][3],e)}var n}function s(e){l("next",e)}function d(e){l("throw",e)}function p(e,o){e(o),r.shift(),r.length&&l(r[0][0],r[0][1])}},p=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.getHumanDate=o.verifyUser=o.convertAppName=o.useLogSnag=o.updateOrCreateChannel=o.uploadUrl=o.updateOrCreateVersion=o.formatError=o.findMainFile=o.findSavedKey=o.checkPlanValid=o.isAllowedAction=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.defaulPublicKey=o.supaAnon=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=o.getConfig=void 0;const u=n(7147),f=n(2037),y=n(1017),g=n(7778),v=n(7304),h=n(2885),m=p(n(9867)),b=n(1133),_=r(n(552));function k(e){return d(this,arguments,(function*(){const o=yield c((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 c(o):yield c(yield*s(l(k(o))))}}))}o.getConfig=()=>a(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,g.loadConfig)()}catch(e){v.program.error("No capacitor config file found, run `cap init` first")}return e})),(0,o.getConfig)().then((e=>{var n,t,i,r;e.app.extConfig.plugins&&e.app.extConfig.plugins.CapacitorUpdater&&(o.host=null!==(n=e.app.extConfig.plugins.CapacitorUpdater.localHost)&&void 0!==n?n:o.host,o.hostWeb=null!==(t=e.app.extConfig.plugins.CapacitorUpdater.localWebHost)&&void 0!==t?t:o.hostWeb,o.hostSupa=null!==(i=e.app.extConfig.plugins.CapacitorUpdater.localSupa)&&void 0!==i?i:o.hostSupa,o.supaAnon=null!==(r=e.app.extConfig.plugins.CapacitorUpdater.localSupaAnon)&&void 0!==r?r:o.supaAnon)})),o.baseKey=".capgo_key",o.baseKeyPub=`${o.baseKey}.pub`,o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostSupa="https://xvwzpoazmxkqosrdewyv.supabase.co",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh2d3pwb2F6bXhrcW9zcmRld3l2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTI4MjExOTcsImV4cCI6MjAwODM5NzE5N30.wjxOlMfJoM2IuiFOmLGeP6YxdkF7Scgcfwu8TnPw_fY",o.defaulPublicKey="-----BEGIN RSA PUBLIC KEY-----\n MIIBCgKCAQEA4pW9olT0FBXXivRCzd3xcImlWZrqkwcF2xTkX/FwXmj9eh9HkBLr\n sQmfsC+PJisRXIOGq6a0z3bsGq6jBpp3/Jr9jiaW5VuPGaKeMaZZBRvi/N5fIMG3\n hZXSOcy0IYg+E1Q7RkYO1xq5GLHseqG+PXvJsNe4R8R/Bmd/ngq0xh/cvcrHHpXw\n O0Aj9tfprlb+rHaVV79EkVRWYPidOLnK1n0EFHFJ1d/MyDIp10TEGm2xHpf/Brlb\n 1an8wXEuzoC0DgYaczgTjovwR+ewSGhSHJliQdM0Qa3o1iN87DldWtydImMsPjJ3\n DUwpsjAMRe5X8Et4+udFW2ciYnQo9H0CkwIDAQAB\n -----END RSA PUBLIC KEY-----",o.createSupabaseClient=e=>(0,h.createClient)(o.hostSupa,o.supaAnon,{auth:{persistSession:!1},global:{headers:{capgkey:e}}}),o.regexSemver=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,o.checkKey=(e,n,t)=>a(void 0,void 0,void 0,(function*(){const{data:i,error:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:t}).single();i&&!r||v.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(r)}`)})),o.isGoodPlan=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_good_plan_v3",{userid:o}).single();if(t)throw t;return n||!1})),o.isPaying=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_paying",{userid:o}).single();if(t)throw t;return n||!1})),o.isTrial=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_trial",{userid:o}).single();if(t)throw t;return n||0})),o.isAllowedAction=(e,o)=>a(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_allowed_action_user",{userid:o}).single();if(t)throw t;return n})),o.checkPlanValid=(e,t,i=!0)=>a(void 0,void 0,void 0,(function*(){(yield(0,o.isAllowedAction)(e,t))||(_.log.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),setTimeout((()=>{Promise.resolve().then((()=>r(n(6634)))).then((e=>{e.default(`${o.hostWeb}/dashboard/settings/plans`)})),v.program.error("")}),1e3));const a=yield(0,o.isTrial)(e,t),c=yield(0,o.isPaying)(e,t);a>0&&i&&!c&&_.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(),c=a.split("/").length;try{for(var s,d=!0,p=l(k(a));!(e=(s=yield p.next()).done);d=!0){t=s.value,d=!1;const e=t;if(e.split("/").length-c<=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.14.0","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"engines":{"npm":">=7.0.0","node":">=16.0.0"},"keywords":["appflow alternative","ionic","capacitor","auto update","live update","capgo","cli","upload","capgo-cli"],"scripts":{"dev":"set NODE_ENV=development && npx webpack --config webpack.config.js","no-debug":"node dist/index.js","test":"npx --yes ts-node -T src/index.ts","build":"npx --yes webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","types":"npx --yes supabase gen types typescript --project-id=xvwzpoazmxkqosrdewyv > src/types/supabase.types.ts","test_rls":"ts-node ./test/test_headers_rls.ts","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"5.2.2","@capgo/find-package-manager":"^0.0.7","@clack/prompts":"^0.7.0","@supabase/supabase-js":"^2.32.0","@tomasklaen/checksum":"^1.1.0","@trufflesuite/spinnies":"^0.1.1","adm-zip":"^0.5.10","axios":"^1.4.0","ci-info":"^3.8.0","commander":"11.0.0","console-table-printer":"^2.11.2","fs-extra":"11.1.1","get-latest-version":"^5.1.0","logsnag":"1.0.0","mime":"^3.0.0","open":"^9.1.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","qrcode":"^1.5.3","semver":"^7.5.4"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/fs-extra":"^11.0.1","@types/mime":"^3.0.1","@types/node":"^20.4.9","@types/npmcli__ci-detect":"^2.0.0","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/qrcode":"^1.5.1","@types/semver":"^7.5.0","@typescript-eslint/eslint-plugin":"5.56.0","@typescript-eslint/parser":"5.56.0","eslint":"8.47.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^9.0.0","eslint-import-resolver-typescript":"3.6.0","eslint-plugin-import":"2.28.0","eslint-plugin-prettier":"^5.0.0","git-format-staged":"3.0.0","husky":"^8.0.3","nodemon":"3.0.1","pkg":"5.8.1","prettier":"3.0.2","ts-loader":"^9.4.4","ts-node":"^10.9.1","tsconfig-paths":"4.2.0","typescript":"5.1.6","webpack":"5.88.2","webpack-cli":"^5.1.4","webpack-node-externals":"^3.0.0"}}')}},o={};!function n(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t].call(r.exports,r,r.exports,n),r.exports}(4999)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "3.13.31",
3
+ "version": "3.14.0",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -25,3 +25,20 @@ export const searchInDirectory = (dirPath: string, searchString: string) => {
25
25
 
26
26
  return false;
27
27
  };
28
+
29
+ export const checkIndexPosition = (dirPath: string): boolean => {
30
+ // look for index.html in the root folder or if there only one folder in the root folder look for index.html in this folder
31
+ const files = fs.readdirSync(dirPath);
32
+ if (files.length === 1) {
33
+ const filePath = path.join(dirPath, files[0]);
34
+ const stats = fs.statSync(filePath);
35
+ if (stats.isDirectory()) {
36
+ return checkIndexPosition(filePath);
37
+ }
38
+ }
39
+ const index = files.indexOf("index.html");
40
+ if (index > -1) {
41
+ return true;
42
+ }
43
+ return false;
44
+ };
@@ -17,7 +17,7 @@ import {
17
17
  formatError, findSavedKey, checkPlanValid,
18
18
  useLogSnag, verifyUser, regexSemver, baseKeyPub, convertAppName, defaulPublicKey
19
19
  } from '../utils';
20
- import { searchInDirectory } from './check';
20
+ import { checkIndexPosition, searchInDirectory } from './check';
21
21
 
22
22
  const alertMb = 20;
23
23
 
@@ -76,11 +76,15 @@ export const uploadBundle = async (appid: string, options: Options, shouldExit =
76
76
 
77
77
  if (typeof checkNotifyAppReady === 'undefined' || checkNotifyAppReady) {
78
78
  const isPluginConfigured = searchInDirectory(path, 'notifyAppReady')
79
-
80
79
  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`);
80
+ p.log.error(`notifyAppReady() is missing in the source code. see: https://capgo.app/docs/plugin/api/#notifyappready`);
82
81
  program.error('');
83
82
  }
83
+ const foundIndex = checkIndexPosition(path);
84
+ if (!foundIndex) {
85
+ p.log.error(`index.html is missing in the root folder or in the only folder in the root folder`);
86
+ program.error('');
87
+ }
84
88
  }
85
89
 
86
90
  p.log.info(`Upload ${appid}@${bundle} started from path "${path}" to Capgo cloud`);
package/src/bundle/zip.ts CHANGED
@@ -11,12 +11,14 @@ import {
11
11
  useLogSnag,
12
12
  regexSemver,
13
13
  } from '../utils';
14
+ import { checkIndexPosition, searchInDirectory } from './check';
14
15
 
15
16
  const alertMb = 20;
16
17
 
17
18
  interface Options extends OptionsBase {
18
19
  bundle?: string
19
20
  path?: string
21
+ codeCheck?: boolean
20
22
  }
21
23
 
22
24
  export const zipBundle = async (appId: string, options: Options) => {
@@ -41,6 +43,19 @@ export const zipBundle = async (appId: string, options: Options) => {
41
43
  program.error('');
42
44
  }
43
45
  p.log.info(`Started from path "${path}"`);
46
+ const checkNotifyAppReady = options.codeCheck
47
+ if (typeof checkNotifyAppReady === 'undefined' || checkNotifyAppReady) {
48
+ const isPluginConfigured = searchInDirectory(path, 'notifyAppReady')
49
+ if (!isPluginConfigured) {
50
+ p.log.error(`notifyAppReady() is missing in the source code. see: https://capgo.app/docs/plugin/api/#notifyappready`);
51
+ program.error('');
52
+ }
53
+ const foundIndex = checkIndexPosition(path);
54
+ if (!foundIndex) {
55
+ p.log.error(`index.html is missing in the root folder or in the only folder in the root folder`);
56
+ program.error('');
57
+ }
58
+ }
44
59
  const zip = new AdmZip();
45
60
  zip.addLocalFolder(path);
46
61
  const zipped = zip.toBuffer();
package/src/index.ts CHANGED
@@ -116,7 +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
+ .option('--no-code-check', 'Ignore checking if notifyAppReady() is called in soure code and index present in root folder')
120
120
  .option('--display-iv-session', 'Show in the console the iv and session key used to encrypt the update')
121
121
  .option('-b, --bundle <bundle>', 'bundle version number of the bundle to upload');
122
122
 
@@ -172,7 +172,8 @@ bundle
172
172
  .description('Zip a bundle')
173
173
  .action(zipBundle)
174
174
  .option('-p, --path <path>', 'path of the folder to upload')
175
- .option('-b, --bundle <bundle>', 'bundle version number to name the zip file');
175
+ .option('-b, --bundle <bundle>', 'bundle version number to name the zip file')
176
+ .option('--no-code-check', 'Ignore checking if notifyAppReady() is called in soure code and index present in root folder');
176
177
 
177
178
  const channel = program
178
179
  .command('channel')