@capgo/cli 1.2.3 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.cz.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [tool.commitizen]
2
2
  name = "cz_conventional_commits"
3
3
  tag_format = "$major.$minor.$patch$prerelease"
4
- version = "1.2.3"
4
+ version = "1.3.1"
5
5
  version_files = [
6
6
  "package.json:version",
7
7
  ".cz.toml"
package/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 1.3.1 (2022-11-17)
2
+
3
+ ### Fix
4
+
5
+ - better loggin
6
+
7
+ ## 1.3.0 (2022-11-17)
8
+
9
+ ### Feat
10
+
11
+ - Add force option to cleanup command #26
12
+
13
+ ### Fix
14
+
15
+ - Keep is only removing the first version, not the given option. #25
16
+
1
17
  ## 1.2.3 (2022-11-17)
2
18
 
3
19
  ### Fix
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- (()=>{"use strict";var e={111: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkAppExistsAndHasPermission=void 0;const i=n(304);o.checkAppExistsAndHasPermission=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:r}=yield e.rpc("exist_app",{appid:o,apikey:n});t&&!r||i.program.error("No permission for this app")}))},708: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInChannel=void 0;const i=n(304),r=n(771);o.checkVersionNotUsedInChannel=(e,o,n,a,s)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:d}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).eq("version",a.id);(t&&t.length||d)&&i.program.error(`Version ${o}@${s} is used in a channel, unlink it first ${(0,r.formatError)(d)}`)}))},314: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const i=n(304),r=n(771);o.checkVersionNotUsedInDeviceOverride=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:s}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);(t&&t.length||s)&&i.program.error(`Version ${o} @${a} is used in a device override, unlink it first ${(0,r.formatError)(s)}`)}))},109: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(304);o.deleteFromStorage=(e,o,n,r,a)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${r.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${a} ${t} `)}))},87: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getVersionData=o.getActiveAppVersions=o.deleteSpecificVersion=o.deleteAppVersion=void 0;const i=n(304),r=n(771),a=n(708),s=n(314),d=n(109);o.deleteAppVersion=(e,o,n,r)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("user_id",n).eq("name",r);t&&i.program.error(`App ${o}@${r} not found in database '${t}'`)})),o.deleteSpecificVersion=(e,n,i,r)=>t(void 0,void 0,void 0,(function*(){const t=yield(0,o.getVersionData)(e,n,i,r);yield(0,a.checkVersionNotUsedInChannel)(e,n,i,t,r),yield(0,s.checkVersionNotUsedInDeviceOverride)(e,n,t,r),yield(0,d.deleteFromStorage)(e,i,n,t,r),yield(0,o.deleteAppVersion)(e,n,i,r)})),o.getActiveAppVersions=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:r}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1);return r&&i.program.error(`App ${o} not found in database ${r} `),t})),o.getVersionData=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:s}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("name",a).eq("deleted",!1).single();return t&&!s||i.program.error(`Version ${o}@${a} doesn't exist ${(0,r.formatError)(s)}`),t}))},107: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const i=n(304),r=n(113),a=n(147),s=n(470),d=n(11),p=n(771),l="assets/icon.png";o.addApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t;let{name:c,icon:u}=o;const v=o.apikey||(0,p.findSavedKey)(),f=yield(0,p.getConfig)(),g=(0,p.useLogSnag)();e=e||(null===(n=null==f?void 0:f.app)||void 0===n?void 0:n.appId),c=c||(null===(t=null==f?void 0:f.app)||void 0===t?void 0:t.appName)||"Unknown",u=u||"resources/icon.png",v||i.program.error("Missing API key, you need to provide a API key to add your app"),e&&c||i.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${e} to Capgo`);const y=(0,p.createSupabaseClient)(v),m=yield(0,p.verifyUser)(y,v,["write","all"]);let h,_;yield(0,p.checkPlanValid)(y,m),console.log("Adding..."),u&&(0,s.existsSync)(u)?(h=(0,a.readFileSync)(u),_=(0,d.getType)(u)||"image/png",console.warn(`Found app icon ${u}`)):(0,s.existsSync)(l)?(h=(0,a.readFileSync)(l),_=(0,d.getType)(l)||"image/png",console.warn(`Found app icon ${l}`)):console.warn(`Cannot find app icon in any of the following locations: ${u}, ${l}`);const{data:b,error:w}=yield y.rpc("exist_app",{appid:e,apikey:v});(b||w)&&i.program.error(`App already exists ${(0,p.formatError)(w)}`);const k=`icon_${(0,r.randomUUID)()}`;let $="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(h&&_){const{error:o}=yield y.storage.from(`images/${m}/${e}`).upload(k,h,{contentType:_});o&&i.program.error(`Could not add app ${(0,p.formatError)(o)}`);const{data:n}=yield y.storage.from(`images/${m}/${e}`).getPublicUrl(k);$=(null==n?void 0:n.publicURL)||$}const{error:x}=yield y.from("apps").insert({icon_url:$,user_id:m,name:c,app_id:e},{returning:"minimal"});x&&i.program.error(`Could not add app ${(0,p.formatError)(x)}`);const{error:A}=yield y.from("app_versions").insert([{user_id:m,deleted:!0,name:"unknown",app_id:e},{user_id:m,deleted:!0,name:"builtin",app_id:e}],{returning:"minimal"});A&&i.program.error(`Could not add app ${(0,p.formatError)(A)}`),g.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":m,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now")}))},176: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((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.cleanupApp=void 0;const r=n(304),a=i(n(505)),s=i(n(616)),d=n(771),p=n(87),l=n(111),c=(0,s.default)();o.cleanupApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,d.findSavedKey)(),{bundle:i,keep:s=4}=o,u=yield(0,d.getConfig)();e=e||(null===(n=null==u?void 0:u.app)||void 0===n?void 0:n.appId),t||r.program.error("Missing API key, you need to provide an API key to delete your app"),e||r.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const v=`${a.default.inc(i,"major")}`;console.log(`Querying available versions in Capgo between ${i} and ${v}`);const f=(0,d.createSupabaseClient)(t),g=yield(0,d.verifyUser)(f,t);yield(0,l.checkAppExistsAndHasPermission)(f,e,t);const y=yield(0,p.getActiveAppVersions)(f,e,g);if(console.log(`Total active versions in Capgo: ${null==y?void 0:y.length}`),0===(null==y?void 0:y.length))return;const m=((e,o,n)=>{const t=[];return null==e||e.forEach((e=>{a.default.gte(e.name,o)&&a.default.lt(e.name,`${n}`)&&t.push(e)})),t})(y,i,v);console.log(`Active versions in Capgo between ${i} and ${v}: ${null==m?void 0:m.length}`);const h=(e=!0)=>{const o=m.pop();if(o){const n=(0,d.getHumanDate)(o);e?console.log(`${o.name} created on ${n} will be kept as it's the last release`):console.log(`${o.name} created on ${n} will be kept due to config`)}};var _;h(!0),_=()=>h(!1),[...Array(s)].forEach(((e,o)=>_())),0!==m.length?(null==m||m.forEach((e=>{console.log(`${e.name} created on ${(0,d.getHumanDate)(e)} will be removed`)})),"yes"===c("Do you want to continue removing the versions specified? Type yes to confirm")?(console.log("You have confiremd removal, removing versions now"),((e,o,n,t)=>{null==e||e.forEach((e=>{console.log(`Removing ${e.name} created on ${(0,d.getHumanDate)(e)}`),(0,p.deleteSpecificVersion)(o,n,t,e.name)}))})(m,f,e,g)):console.log("Not confirmed, aborting removal...")):console.log("Nothing to be removed, aborting removal...")}))},605: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const i=n(304),r=n(771),a=n(87);o.deleteApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const{bundle:t}=o,s=o.apikey||(0,r.findSavedKey)(),d=yield(0,r.getConfig)(),p=(0,r.useLogSnag)();e=e||(null===(n=null==d?void 0:d.app)||void 0===n?void 0:n.appId),s||i.program.error("Missing API key, you need to provide an API key to delete your app"),e||i.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const l=(0,r.createSupabaseClient)(s),c=yield(0,r.verifyUser)(l,s),{data:u,error:v}=yield l.rpc("exist_app",{appid:e,apikey:s});if(u&&!v||i.program.error("No permission to delete"),t)return console.log(`Delete ${e}@${t} from Capgo`),yield(0,a.deleteSpecificVersion)(l,e,c,t),void console.log(`${e}@${t} deleted from server`);console.log(`Delete ${e} from Capgo`);const{data:f,error:g}=yield l.from("app_versions").select().eq("app_id",e).eq("user_id",c);if(g&&i.program.error(`App ${e} not found in database ${g} `),f&&f.length){const o=f.map((o=>`${c}/${e}/versions/${o.bucket_id} `)),{error:n}=yield l.storage.from("apps").remove(o);n&&i.program.error(`Cannot delete stored version for app ${e} from storage ${n} `)}const{error:y}=yield l.from("app_versions").delete().eq("app_id",e).eq("user_id",c);y&&i.program.error(`Cannot delete version for app ${e} from database ${y} `);const{error:m}=yield l.from("apps").delete().eq("app_id",e).eq("user_id",c);m&&i.program.error(`Cannot delete from database ${m} `),p.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":c,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`)}))},250: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(304),r=n(107),a=n(605),s=n(327),d=n(823),p=t(n(598)),l=n(829),c=n(501),u=n(176);i.program.description("Manage package and version in capgo Cloud").version(p.default.version),i.program.command("add [appid]").alias("a").description("Add a new app to capgo Cloud").action(r.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(l.login).option("--local","Only save in local folder"),i.program.command("upload [appid]").alias("u").description("Upload a new bundle to capgo Cloud").action(d.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the file 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("-f, --format <base64|hex|binary|utf8>","choose the upload format default base64").option("-b, --bundle <bundle>","bundle version number of the file to upload"),i.program.command("set [appid]").alias("s").description("Modify a channel configuration").action(s.setChannel).requiredOption("-c, --channel <channel>","channel to link to").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("--downgrade","Allow to downgrade to version under native one").option("--latest","get the latest version key in the package.json to set it to the channel").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"),i.program.command("delete [appid]").alias("d").description("Delete an app from capgo Cloud").action(a.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the app to delete"),i.program.command("list [appid]").alias("ls").description("List versions in capgo Cloud").action(c.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),i.program.command("cleanup [appid]").alias("c").description("Cleanup versions in capgo Cloud").action(u.cleanupApp).requiredOption("-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"),i.program.parse(process.argv)},501: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const i=n(304),r=n(771),a=n(111),s=n(87);o.listApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,r.findSavedKey)(),d=yield(0,r.getConfig)();e=e||(null===(n=null==d?void 0:d.app)||void 0===n?void 0:n.appId),t||i.program.error("Missing API key, you need to provide an API key to delete your app"),e||i.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),console.log("Querying available versions in Capgo");const p=(0,r.createSupabaseClient)(t),l=yield(0,r.verifyUser)(p,t);yield(0,a.checkAppExistsAndHasPermission)(p,e,t);const c=yield(0,s.getActiveAppVersions)(p,e,l);console.log(`Active versions in Capgo: ${null==c?void 0:c.length}`),null==c||c.forEach((e=>{console.log(`${e.name} created on ${(0,r.getHumanDate)(e)}`)}))}))},829: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((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.login=void 0;const r=n(304),a=i(n(147)),s=i(n(37)),d=n(771);o.login=(e,o)=>t(void 0,void 0,void 0,(function*(){const{local:n}=o,t=(0,d.useLogSnag)();if(n)a.default.existsSync(".git")||r.program.error("To use local you should be in a git repository"),a.default.writeFileSync(".capgo",`${e}\n`),a.default.appendFileSync(".gitignore",".capgo\n");else{const o=s.default.homedir();a.default.writeFileSync(`${o}/.capgo`,`${e}\n`)}const i=(0,d.createSupabaseClient)(e),p=yield(0,d.verifyUser)(i,e,["write","all","upload"]);t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":p},notify:!1}).catch(),console.log(`login saved into .capgo file in ${n?"local":"home"} directory`)}))},327: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const i=n(304),r=n(771);o.setChannel=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,a;const{bundle:s,latest:d,downgrade:p,upgrade:l,ios:c,android:u,selfAssign:v,channel:f,state:g}=o,y=o.apikey||(0,r.findSavedKey)(),m=yield(0,r.getConfig)(),h=(0,r.useLogSnag)();e=e||(null===(n=null==m?void 0:m.app)||void 0===n?void 0:n.appId),y||i.program.error("Missing API key, you need to provide a API key to add your app"),e||i.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),d&&s&&i.program.error("Cannot set latest and bundle at the same time"),void 0===s&&void 0===g&&void 0===d&&void 0===p&&void 0===l&&void 0===c&&void 0===u&&void 0===v&&i.program.error("Missing argument, you need to provide a option to set");try{const o=(0,r.createSupabaseClient)(y),n=yield(0,r.verifyUser)(o,y,["write","all"]);yield(0,r.checkPlanValid)(o,n);const _={created_by:n,app_id:e,name:f},b=d?null===(a=null===(t=null==m?void 0:m.app)||void 0===t?void 0:t.package)||void 0===a?void 0:a.version:s;if(b){const{data:t,error:r}=yield o.from("app_versions").select().eq("app_id",e).eq("name",b).eq("user_id",n).eq("deleted",!1);!r&&t&&t.length||i.program.error(`Cannot find version ${b}`),console.log(`Set ${e} channel: ${f} to @${s}`),_.version=t[0].id}void 0!==g&&("public"!==g&&"private"!==g||console.log(`Set ${e} channel: ${f} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${f} to ${"public"===g||"default"===g?"default":"normal"}`),_.public="public"===g||"default"===g),void 0!==p&&(console.log(`Set ${e} channel: ${f} to ${p?"allow":"disallow"} downgrade`),_.disableAutoUpdateUnderNative=!p),void 0!==l&&(console.log(`Set ${e} channel: ${f} to ${l?"allow":"disallow"} upgrade`),_.disableAutoUpdateToMajor=!l),void 0!==c&&(console.log(`Set ${e} channel: ${f} to ${c?"allow":"disallow"} ios update`),_.ios=!!c),void 0!==u&&(console.log(`Set ${e} channel: ${f} to ${u?"allow":"disallow"} android update`),_.android=!!u),void 0!==v&&(console.log(`Set ${e} channel: ${f} to ${v?"allow":"disallow"} self assign to this channel`),_.allow_device_self_set=!!v);try{const{error:e}=yield(0,r.updateOrCreateChannel)(o,_,y);e&&i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}catch(e){i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}h.publish({channel:"app",event:"Set app",icon:"✅",tags:{"user-id":n,"app-id":e},notify:!1}).catch()}catch(e){i.program.error(`Unknow error ${(0,r.formatError)(e)}`)}console.log("Done ✅")}))},823: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((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.uploadVersion=void 0;const r=i(n(844)),a=n(304),s=n(113),d=i(n(295)),p=n(906),l=n(771);o.uploadVersion=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,i,c;let{bundle:u,path:v,channel:f}=o;const{external:g}=o,y=o.apikey||(0,l.findSavedKey)(),m=(0,l.useLogSnag)();f=f||"dev";const h=yield(0,l.getConfig)();e=e||(null===(n=null==h?void 0:h.app)||void 0===n?void 0:n.appId),u=u||(null===(i=null===(t=null==h?void 0:h.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version),l.regexSemver.test(u)||a.program.error(`Your bundle name ${u}, is not valid it should follow semver convention : https://semver.org/`),v=v||(null===(c=null==h?void 0:h.app)||void 0===c?void 0:c.webDir),y||a.program.error("Missing API key, you need to provide a API key to add your app"),e&&u&&v||a.program.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),console.log(`Upload ${e}@${u} started from path "${v}" to Capgo cloud`);const _=(0,l.createSupabaseClient)(y),b=yield(0,l.verifyUser)(_,y,["write","all","upload"]);yield(0,l.checkPlanValid)(_,b,!1);const w=new d.default.MultiBar({clearOnComplete:!1,hideCursor:!0},d.default.Presets.shades_grey),k=w.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},d.default.Presets.shades_grey);k.start(7,0,{speed:"N/A"});const{data:$,error:x}=yield _.rpc("exist_app_versions",{apikey:y,name_version:u,appid:e});($||x)&&(w.stop(),a.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,l.formatError)(x)}`)),k.increment();const{data:A,error:C}=yield _.rpc("is_trial",{userid:b}).single();(A&&A>0||C)&&w.log(`WARNING !!\nTrial expires in ${A} days, upgrade here: ${l.hostWeb}/dashboard/settings/plans\n`),k.increment();const{data:S,error:P}=yield _.rpc("exist_app",{appid:e,apikey:y});S&&!P||(w.stop(),a.program.error(`Cannot find app ${e} in your account \n${(0,l.formatError)(P)}`)),k.increment();const{data:q,error:I}=yield _.rpc("exist_app_versions",{appid:e,apikey:y,name_version:u});(q||I)&&a.program.error(`Version already exists ${(0,l.formatError)(I)}`),k.increment();const j=(0,s.randomUUID)();let M="";if(g)g&&!g.startsWith("https://")&&(w.stop(),a.program.error(`External link should should start with "https://" current is "${g}"`));else{const o=new r.default;o.addLocalFolder(v);const n=o.toBuffer();M=yield(0,p.checksum)(n,"crc32");const t=Math.floor(n.byteLength/1024/1024),i=`apps/${b}/${e}/versions`;k.increment(),t>20&&(w.log(`WARNING !!\nThe app size is ${t} Mb, this may take a while to download for users\n`),m.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":b,"app-id":e},notify:!1}).catch());const{error:s}=yield _.storage.from(i).upload(j,n,{contentType:"application/zip"});s&&(w.stop(),a.program.error(`Cannot upload ${(0,l.formatError)(s)}`))}k.increment();const{data:D,error:V}=yield(0,l.updateOrCreateVersion)(_,{bucket_id:g?void 0:j,user_id:b,name:u,app_id:e,external_url:g,checksum:M},y);if(V&&(w.stop(),a.program.error(`Cannot add bundle ${(0,l.formatError)(V)}`)),k.increment(),D&&D.length){const{error:o}=yield(0,l.updateOrCreateChannel)(_,{name:f,app_id:e,created_by:b,version:D[0].id},y);o&&w.log("Cannot set bundle with upload key, use key with more rights for that\n")}else w.log("Cannot set bundle with upload key, use key with more rights for that\n");w.stop();const U=e.replace(/\./g,"--");console.log("App uploaded to server"),console.log(`Try it in mobile app: ${l.host}/app_mobile`),console.log(`Or set the channel ${f} as public here: ${l.hostWeb}/app/package/${U}`),console.log("To use with live update in your own app"),console.log(`You can link specific device to this bundle to make user try it first, here: ${l.hostWeb}/app/p/${U}/devices`),m.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":b,"app-id":e},notify:!1}).catch()}))},771: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((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.getHumanDate=o.verifyUser=o.useLogSnag=o.updateOrCreateChannel=o.updateOrCreateVersion=o.getConfig=o.formatError=o.findSavedKey=o.checkPlanValid=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.supaAnon=o.hostSupa=o.hostWeb=o.host=void 0;const r=n(778),a=n(304),s=n(885),d=i(n(867)),p=i(n(147)),l=i(n(37)),c=n(133);o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostSupa="https://xvwzpoazmxkqosrdewyv.supabase.co",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w",o.createSupabaseClient=e=>(0,s.createClient)(o.hostSupa,o.supaAnon,{headers:{capgkey:e}}),o.regexSemver=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,o.checkKey=(e,n,i)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:i});t&&!r||a.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(r)}`)})),o.isGoodPlan=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_good_plan_v2",{userid:o}).single();if(t)throw t;return n||!1})),o.isPaying=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_paying",{userid:o}).single();if(t)throw t;return n||!1})),o.isTrial=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_trial",{userid:o}).single();if(t)throw t;return n||0})),o.checkPlanValid=(e,n,i=!0)=>t(void 0,void 0,void 0,(function*(){const t=yield(0,o.isGoodPlan)(e,n),r=yield(0,o.isPaying)(e,n),s=yield(0,o.isTrial)(e,n);r&&t||!(s<0)||a.program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),s>0&&i&&!r&&console.log(`WARNING !!\nTrial expires in ${s} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e=`${l.default.homedir()}/.capgo`;return p.default.existsSync(e)?p.default.readFileSync(e,"utf8").trim():(e=".capgo",p.default.existsSync(e)?p.default.readFileSync(e,"utf8").trim():null)},o.formatError=e=>e?`\n${d.default.render(e)}`:"",o.getConfig=()=>t(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,r.loadConfig)()}catch(e){a.program.error("No capacitor config file found, run `cap init` first")}return e})),o.updateOrCreateVersion=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.rpc("exist_app_versions",{appid:o.app_id,name_version:o.name,apikey:n});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.updateOrCreateChannel=(e,o,n)=>t(void 0,void 0,void 0,(function*(){if(!o.app_id||!o.name||!o.created_by)return console.error("missing app_id, name, or created_by"),Promise.reject(new Error("missing app_id, name, or created_by"));const{data:t,error:i}=yield e.rpc("exist_channel",{appid:o.app_id,name_channel:o.name,apikey:n});return t&&!i?e.from("channels").update(o,{returning:"minimal"}).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by):e.from("channels").insert(o,{returning:"minimal"})})),o.useLogSnag=()=>new c.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.verifyUser=(e,n,i=["all"])=>t(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,n,i);const{data:t,error:r}=yield e.rpc("get_user_id",{apikey:n}),s=t?t.toString():"";return s&&!r||a.program.error(`Cannot verify user ${(0,o.formatError)(r)}`),s})),o.getHumanDate=e=>new Date(e.created_at||"").toLocaleString()},778:e=>{e.exports=require("@capacitor/cli/dist/config")},885:e=>{e.exports=require("@supabase/supabase-js")},906:e=>{e.exports=require("@tomasklaen/checksum")},844:e=>{e.exports=require("adm-zip")},295:e=>{e.exports=require("cli-progress")},304:e=>{e.exports=require("commander")},470:e=>{e.exports=require("fs-extra")},133:e=>{e.exports=require("logsnag")},11:e=>{e.exports=require("mime")},867:e=>{e.exports=require("prettyjson")},616:e=>{e.exports=require("prompt-sync")},505:e=>{e.exports=require("semver/preload")},113:e=>{e.exports=require("crypto")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},598:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"1.2.3","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"},"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","build":"npx webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","test_rls":"ts-node ./test/test_headers_rls.ts","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"4.4.0","@supabase/supabase-js":"^1.35.7","@tomasklaen/checksum":"^1.1.0","adm-zip":"^0.5.9","cli-progress":"3.11.2","commander":"9.4.1","fs-extra":"10.1.0","logsnag":"^0.1.5","mime":"^3.0.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","semver":"^7.3.8"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/cli-progress":"^3.11.0","@types/fs-extra":"^9.0.13","@types/mime":"^3.0.1","@types/node":"^18.11.9","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/semver":"^7.3.13","@typescript-eslint/eslint-plugin":"5.42.1","@typescript-eslint/parser":"5.42.1","eslint":"8.27.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"3.5.2","eslint-plugin-import":"2.26.0","eslint-plugin-prettier":"^4.2.1","git-format-staged":"3.0.0","husky":"^8.0.2","nodemon":"2.0.20","pkg":"5.8.0","prettier":"2.7.1","ts-loader":"^9.4.1","ts-node":"^10.9.1","tsconfig-paths":"4.1.0","typescript":"4.8.4","webpack":"5.74.0","webpack-cli":"^4.10.0","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}(250)})();
2
+ (()=>{"use strict";var e={111: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkAppExistsAndHasPermission=void 0;const i=n(304);o.checkAppExistsAndHasPermission=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:r}=yield e.rpc("exist_app",{appid:o,apikey:n});t&&!r||i.program.error("No permission for this app")}))},708: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInChannel=void 0;const i=n(304),r=n(771);o.checkVersionNotUsedInChannel=(e,o,n,a,s)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:d}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).eq("version",a.id);(t&&t.length||d)&&i.program.error(`Version ${o}@${s} is used in a channel, unlink it first ${(0,r.formatError)(d)}`)}))},314: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const i=n(304),r=n(771);o.checkVersionNotUsedInDeviceOverride=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:s}=yield e.from("devices_override").select().eq("app_id",o).eq("version",n.id);(t&&t.length||s)&&i.program.error(`Version ${o} @${a} is used in a device override, unlink it first ${(0,r.formatError)(s)}`)}))},109: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(304);o.deleteFromStorage=(e,o,n,r,a)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.storage.from("apps").remove([`${o}/${n}/versions/${r.bucket_id} `]);t&&i.program.error(`Something went wrong when trying to delete ${n} @${a} ${t} `)}))},87: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getVersionData=o.getActiveAppVersions=o.deleteSpecificVersion=o.deleteAppVersion=void 0;const i=n(304),r=n(771),a=n(708),s=n(314),d=n(109);o.deleteAppVersion=(e,o,n,r)=>t(void 0,void 0,void 0,(function*(){const{error:t}=yield e.from("app_versions").update({deleted:!0}).eq("app_id",o).eq("user_id",n).eq("name",r);t&&i.program.error(`App ${o}@${r} not found in database '${t}'`)})),o.deleteSpecificVersion=(e,n,i,r)=>t(void 0,void 0,void 0,(function*(){const t=yield(0,o.getVersionData)(e,n,i,r);yield(0,a.checkVersionNotUsedInChannel)(e,n,i,t,r),yield(0,s.checkVersionNotUsedInDeviceOverride)(e,n,t,r),yield(0,d.deleteFromStorage)(e,i,n,t,r),yield(0,o.deleteAppVersion)(e,n,i,r)})),o.getActiveAppVersions=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:r}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("deleted",!1);return r&&i.program.error(`App ${o} not found in database ${r} `),t})),o.getVersionData=(e,o,n,a)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:s}=yield e.from("app_versions").select().eq("app_id",o).eq("user_id",n).eq("name",a).eq("deleted",!1).single();return t&&!s||i.program.error(`Version ${o}@${a} doesn't exist ${(0,r.formatError)(s)}`),t}))},107: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const i=n(304),r=n(113),a=n(147),s=n(470),d=n(11),p=n(771),l="assets/icon.png";o.addApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t;let{name:c,icon:u}=o;const v=o.apikey||(0,p.findSavedKey)(),f=yield(0,p.getConfig)(),g=(0,p.useLogSnag)();e=e||(null===(n=null==f?void 0:f.app)||void 0===n?void 0:n.appId),c=c||(null===(t=null==f?void 0:f.app)||void 0===t?void 0:t.appName)||"Unknown",u=u||"resources/icon.png",v||i.program.error("Missing API key, you need to provide a API key to add your app"),e&&c||i.program.error("Missing argument, you need to provide a appid and a name, or be in a capacitor project"),console.log(`Add ${e} to Capgo`);const y=(0,p.createSupabaseClient)(v),m=yield(0,p.verifyUser)(y,v,["write","all"]);let h,_;yield(0,p.checkPlanValid)(y,m),console.log("Adding..."),u&&(0,s.existsSync)(u)?(h=(0,a.readFileSync)(u),_=(0,d.getType)(u)||"image/png",console.warn(`Found app icon ${u}`)):(0,s.existsSync)(l)?(h=(0,a.readFileSync)(l),_=(0,d.getType)(l)||"image/png",console.warn(`Found app icon ${l}`)):console.warn(`Cannot find app icon in any of the following locations: ${u}, ${l}`);const{data:b,error:w}=yield y.rpc("exist_app",{appid:e,apikey:v});(b||w)&&i.program.error(`App already exists ${(0,p.formatError)(w)}`);const k=`icon_${(0,r.randomUUID)()}`;let $="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(h&&_){const{error:o}=yield y.storage.from(`images/${m}/${e}`).upload(k,h,{contentType:_});o&&i.program.error(`Could not add app ${(0,p.formatError)(o)}`);const{data:n}=yield y.storage.from(`images/${m}/${e}`).getPublicUrl(k);$=(null==n?void 0:n.publicURL)||$}const{error:x}=yield y.from("apps").insert({icon_url:$,user_id:m,name:c,app_id:e},{returning:"minimal"});x&&i.program.error(`Could not add app ${(0,p.formatError)(x)}`);const{error:A}=yield y.from("app_versions").insert([{user_id:m,deleted:!0,name:"unknown",app_id:e},{user_id:m,deleted:!0,name:"builtin",app_id:e}],{returning:"minimal"});A&&i.program.error(`Could not add app ${(0,p.formatError)(A)}`),g.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":m,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now")}))},176: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((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.cleanupApp=void 0;const r=n(304),a=i(n(505)),s=i(n(616)),d=n(771),p=n(87),l=n(111),c=(0,s.default)();o.cleanupApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,d.findSavedKey)(),{bundle:i,keep:s=4}=o,u=o.force||!1,v=yield(0,d.getConfig)();e=e||(null===(n=null==v?void 0:v.app)||void 0===n?void 0:n.appId),t||r.program.error("Missing API key, you need to provide an API key to delete your app"),e||r.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const f=`${a.default.inc(i,"major")}`;console.log(`Querying available versions in Capgo between ${i} and ${f}`);const g=(0,d.createSupabaseClient)(t),y=yield(0,d.verifyUser)(g,t);yield(0,l.checkAppExistsAndHasPermission)(g,e,t);const m=yield(0,p.getActiveAppVersions)(g,e,y);if(console.log(`Total active versions in Capgo: ${null==m?void 0:m.length}`),0===(null==m?void 0:m.length))return;const h=((e,o,n)=>{const t=[];return null==e||e.forEach((e=>{a.default.gte(e.name,o)&&a.default.lt(e.name,`${n}`)&&t.push(e)})),t})(m,i,f).reverse();console.log(`Active versions in Capgo between ${i} and ${f}: ${null==h?void 0:h.length}`);const _=h.slice(0,s),b=h.slice(s);if(_.forEach((e=>{console.log(`${e.name} created on ${(0,d.getHumanDate)(e)} will be kept`)})),_.length&&console.log("==================================================="),0!==b.length){if(b.forEach((e=>{console.log(`${e.name} created on ${(0,d.getHumanDate)(e)} will be removed`)})),!u&&"yes"!==c("Do you want to continue removing the versions specified? Type yes to confirm"))return void console.log("Not confirmed, aborting removal...");console.log("You have confirmed removal, removing versions now"),((e,o,n,t)=>{null==e||e.forEach((e=>{console.log(`Removing ${e.name} created on ${(0,d.getHumanDate)(e)}`),(0,p.deleteSpecificVersion)(o,n,t,e.name)}))})(b,g,e,y)}else console.log("Nothing to be removed, aborting removal...")}))},605: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const i=n(304),r=n(771),a=n(87);o.deleteApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const{bundle:t}=o,s=o.apikey||(0,r.findSavedKey)(),d=yield(0,r.getConfig)(),p=(0,r.useLogSnag)();e=e||(null===(n=null==d?void 0:d.app)||void 0===n?void 0:n.appId),s||i.program.error("Missing API key, you need to provide an API key to delete your app"),e||i.program.error("Missing argument, you need to provide a appid, or be in a capacitor project");const l=(0,r.createSupabaseClient)(s),c=yield(0,r.verifyUser)(l,s),{data:u,error:v}=yield l.rpc("exist_app",{appid:e,apikey:s});if(u&&!v||i.program.error("No permission to delete"),t)return console.log(`Delete ${e}@${t} from Capgo`),yield(0,a.deleteSpecificVersion)(l,e,c,t),void console.log(`${e}@${t} deleted from server`);console.log(`Delete ${e} from Capgo`);const{data:f,error:g}=yield l.from("app_versions").select().eq("app_id",e).eq("user_id",c);if(g&&i.program.error(`App ${e} not found in database ${g} `),f&&f.length){const o=f.map((o=>`${c}/${e}/versions/${o.bucket_id} `)),{error:n}=yield l.storage.from("apps").remove(o);n&&i.program.error(`Cannot delete stored version for app ${e} from storage ${n} `)}const{error:y}=yield l.from("app_versions").delete().eq("app_id",e).eq("user_id",c);y&&i.program.error(`Cannot delete version for app ${e} from database ${y} `);const{error:m}=yield l.from("apps").delete().eq("app_id",e).eq("user_id",c);m&&i.program.error(`Cannot delete from database ${m} `),p.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":c,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`)}))},250: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(304),r=n(107),a=n(605),s=n(327),d=n(823),p=t(n(598)),l=n(829),c=n(501),u=n(176);i.program.description("Manage packages and bundle versions in capgo Cloud").version(p.default.version),i.program.command("add [appid]").alias("a").description("Add a new app to capgo Cloud").action(r.addApp).option("-n, --name <name>","app name").option("-i, --icon <icon>","app icon path").option("-a, --apikey <apikey>","apikey to link to your account"),i.program.command("login [apikey]").alias("l").description("Save apikey to your machine or folder").action(l.login).option("--local","Only save in local folder"),i.program.command("upload [appid]").alias("u").description("Upload a new bundle to capgo Cloud").action(d.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the file 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("-f, --format <base64|hex|binary|utf8>","choose the upload format default base64").option("-b, --bundle <bundle>","bundle version number of the file to upload"),i.program.command("set [appid]").alias("s").description("Modify a channel configuration").action(s.setChannel).requiredOption("-c, --channel <channel>","channel to link to").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("--downgrade","Allow to downgrade to version under native one").option("--latest","get the latest version key in the package.json to set it to the channel").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"),i.program.command("delete [appid]").alias("d").description("Delete an app from capgo Cloud").action(a.deleteApp).option("-a, --apikey <apikey>","apikey to link to your account").option("-b, --bundle <bundle>","bundle version number of the app to delete"),i.program.command("list [appid]").alias("ls").description("List versions in capgo Cloud").action(c.listApp).option("-a, --apikey <apikey>","apikey to link to your account"),i.program.command("cleanup [appid]").alias("c").description("Cleanup versions in capgo Cloud").action(u.cleanupApp).requiredOption("-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"),i.program.parse(process.argv)},501: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const i=n(304),r=n(771),a=n(111),s=n(87);o.listApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,r.findSavedKey)(),d=yield(0,r.getConfig)();e=e||(null===(n=null==d?void 0:d.app)||void 0===n?void 0:n.appId),t||i.program.error("Missing API key, you need to provide an API key to delete your app"),e||i.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),console.log("Querying available versions in Capgo");const p=(0,r.createSupabaseClient)(t),l=yield(0,r.verifyUser)(p,t);yield(0,a.checkAppExistsAndHasPermission)(p,e,t);const c=yield(0,s.getActiveAppVersions)(p,e,l);console.log(`Active versions in Capgo: ${null==c?void 0:c.length}`),null==c||c.forEach((e=>{console.log(`${e.name} created on ${(0,r.getHumanDate)(e)}`)}))}))},829: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((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.login=void 0;const r=n(304),a=i(n(147)),s=i(n(37)),d=n(771);o.login=(e,o)=>t(void 0,void 0,void 0,(function*(){const{local:n}=o,t=(0,d.useLogSnag)();if(n)a.default.existsSync(".git")||r.program.error("To use local you should be in a git repository"),a.default.writeFileSync(".capgo",`${e}\n`),a.default.appendFileSync(".gitignore",".capgo\n");else{const o=s.default.homedir();a.default.writeFileSync(`${o}/.capgo`,`${e}\n`)}const i=(0,d.createSupabaseClient)(e),p=yield(0,d.verifyUser)(i,e,["write","all","upload"]);t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":p},notify:!1}).catch(),console.log(`login saved into .capgo file in ${n?"local":"home"} directory`)}))},327: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const i=n(304),r=n(771);o.setChannel=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,a;const{bundle:s,latest:d,downgrade:p,upgrade:l,ios:c,android:u,selfAssign:v,channel:f,state:g}=o,y=o.apikey||(0,r.findSavedKey)(),m=yield(0,r.getConfig)(),h=(0,r.useLogSnag)();e=e||(null===(n=null==m?void 0:m.app)||void 0===n?void 0:n.appId),y||i.program.error("Missing API key, you need to provide a API key to add your app"),e||i.program.error("Missing argument, you need to provide a appid, or be in a capacitor project"),d&&s&&i.program.error("Cannot set latest and bundle at the same time"),void 0===s&&void 0===g&&void 0===d&&void 0===p&&void 0===l&&void 0===c&&void 0===u&&void 0===v&&i.program.error("Missing argument, you need to provide a option to set");try{const o=(0,r.createSupabaseClient)(y),n=yield(0,r.verifyUser)(o,y,["write","all"]);yield(0,r.checkPlanValid)(o,n);const _={created_by:n,app_id:e,name:f},b=d?null===(a=null===(t=null==m?void 0:m.app)||void 0===t?void 0:t.package)||void 0===a?void 0:a.version:s;if(b){const{data:t,error:r}=yield o.from("app_versions").select().eq("app_id",e).eq("name",b).eq("user_id",n).eq("deleted",!1);!r&&t&&t.length||i.program.error(`Cannot find version ${b}`),console.log(`Set ${e} channel: ${f} to @${s}`),_.version=t[0].id}void 0!==g&&("public"!==g&&"private"!==g||console.log(`Set ${e} channel: ${f} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${f} to ${"public"===g||"default"===g?"default":"normal"}`),_.public="public"===g||"default"===g),void 0!==p&&(console.log(`Set ${e} channel: ${f} to ${p?"allow":"disallow"} downgrade`),_.disableAutoUpdateUnderNative=!p),void 0!==l&&(console.log(`Set ${e} channel: ${f} to ${l?"allow":"disallow"} upgrade`),_.disableAutoUpdateToMajor=!l),void 0!==c&&(console.log(`Set ${e} channel: ${f} to ${c?"allow":"disallow"} ios update`),_.ios=!!c),void 0!==u&&(console.log(`Set ${e} channel: ${f} to ${u?"allow":"disallow"} android update`),_.android=!!u),void 0!==v&&(console.log(`Set ${e} channel: ${f} to ${v?"allow":"disallow"} self assign to this channel`),_.allow_device_self_set=!!v);try{const{error:e}=yield(0,r.updateOrCreateChannel)(o,_,y);e&&i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}catch(e){i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}h.publish({channel:"app",event:"Set app",icon:"✅",tags:{"user-id":n,"app-id":e},notify:!1}).catch()}catch(e){i.program.error(`Unknow error ${(0,r.formatError)(e)}`)}console.log("Done ✅")}))},823: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((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.uploadVersion=void 0;const r=i(n(844)),a=n(304),s=n(113),d=i(n(295)),p=n(906),l=n(771);o.uploadVersion=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,i,c;let{bundle:u,path:v,channel:f}=o;const{external:g}=o,y=o.apikey||(0,l.findSavedKey)(),m=(0,l.useLogSnag)();f=f||"dev";const h=yield(0,l.getConfig)();e=e||(null===(n=null==h?void 0:h.app)||void 0===n?void 0:n.appId),u=u||(null===(i=null===(t=null==h?void 0:h.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version),l.regexSemver.test(u)||a.program.error(`Your bundle name ${u}, is not valid it should follow semver convention : https://semver.org/`),v=v||(null===(c=null==h?void 0:h.app)||void 0===c?void 0:c.webDir),y||a.program.error("Missing API key, you need to provide a API key to add your app"),e&&u&&v||a.program.error("Missing argument, you need to provide a appid and a bundle and a path, or be in a capacitor project"),console.log(`Upload ${e}@${u} started from path "${v}" to Capgo cloud`);const _=(0,l.createSupabaseClient)(y),b=yield(0,l.verifyUser)(_,y,["write","all","upload"]);yield(0,l.checkPlanValid)(_,b,!1);const w=new d.default.MultiBar({clearOnComplete:!1,hideCursor:!0},d.default.Presets.shades_grey),k=w.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},d.default.Presets.shades_grey);k.start(7,0,{speed:"N/A"});const{data:$,error:x}=yield _.rpc("exist_app_versions",{apikey:y,name_version:u,appid:e});($||x)&&(w.stop(),a.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,l.formatError)(x)}`)),k.increment();const{data:A,error:C}=yield _.rpc("is_trial",{userid:b}).single();(A&&A>0||C)&&w.log(`WARNING !!\nTrial expires in ${A} days, upgrade here: ${l.hostWeb}/dashboard/settings/plans\n`),k.increment();const{data:S,error:P}=yield _.rpc("exist_app",{appid:e,apikey:y});S&&!P||(w.stop(),a.program.error(`Cannot find app ${e} in your account \n${(0,l.formatError)(P)}`)),k.increment();const{data:q,error:I}=yield _.rpc("exist_app_versions",{appid:e,apikey:y,name_version:u});(q||I)&&a.program.error(`Version already exists ${(0,l.formatError)(I)}`),k.increment();const j=(0,s.randomUUID)();let M="";if(g)g&&!g.startsWith("https://")&&(w.stop(),a.program.error(`External link should should start with "https://" current is "${g}"`));else{const o=new r.default;o.addLocalFolder(v);const n=o.toBuffer();M=yield(0,p.checksum)(n,"crc32");const t=Math.floor(n.byteLength/1024/1024),i=`apps/${b}/${e}/versions`;k.increment(),t>20&&(w.log(`WARNING !!\nThe app size is ${t} Mb, this may take a while to download for users\n`),m.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":b,"app-id":e},notify:!1}).catch());const{error:s}=yield _.storage.from(i).upload(j,n,{contentType:"application/zip"});s&&(w.stop(),a.program.error(`Cannot upload ${(0,l.formatError)(s)}`))}k.increment();const{data:D,error:V}=yield(0,l.updateOrCreateVersion)(_,{bucket_id:g?void 0:j,user_id:b,name:u,app_id:e,external_url:g,checksum:M},y);if(V&&(w.stop(),a.program.error(`Cannot add bundle ${(0,l.formatError)(V)}`)),k.increment(),D&&D.length){const{error:o}=yield(0,l.updateOrCreateChannel)(_,{name:f,app_id:e,created_by:b,version:D[0].id},y);o&&w.log("Cannot set bundle with upload key, use key with more rights for that\n")}else w.log("Cannot set bundle with upload key, use key with more rights for that\n");w.stop();const U=e.replace(/\./g,"--");console.log("App uploaded to server"),console.log(`Try it in mobile app: ${l.host}/app_mobile`),console.log(`Or set the channel ${f} as public here: ${l.hostWeb}/app/package/${U}`),console.log("To use with live update in your own app"),console.log(`You can link specific device to this bundle to make user try it first, here: ${l.hostWeb}/app/p/${U}/devices`),m.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":b,"app-id":e},notify:!1}).catch()}))},771: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{d(t.next(e))}catch(e){r(e)}}function s(e){try{d(t.throw(e))}catch(e){r(e)}}function d(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}d((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.getHumanDate=o.verifyUser=o.useLogSnag=o.updateOrCreateChannel=o.updateOrCreateVersion=o.getConfig=o.formatError=o.findSavedKey=o.checkPlanValid=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.supaAnon=o.hostSupa=o.hostWeb=o.host=void 0;const r=n(778),a=n(304),s=n(885),d=i(n(867)),p=i(n(147)),l=i(n(37)),c=n(133);o.host="https://capgo.app",o.hostWeb="https://web.capgo.app",o.hostSupa="https://xvwzpoazmxkqosrdewyv.supabase.co",o.supaAnon="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w",o.createSupabaseClient=e=>(0,s.createClient)(o.hostSupa,o.supaAnon,{headers:{capgkey:e}}),o.regexSemver=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,o.checkKey=(e,n,i)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:i});t&&!r||a.program.error(`Invalid API key or insufficient permissions ${(0,o.formatError)(r)}`)})),o.isGoodPlan=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_good_plan_v2",{userid:o}).single();if(t)throw t;return n||!1})),o.isPaying=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_paying",{userid:o}).single();if(t)throw t;return n||!1})),o.isTrial=(e,o)=>t(void 0,void 0,void 0,(function*(){const{data:n,error:t}=yield e.rpc("is_trial",{userid:o}).single();if(t)throw t;return n||0})),o.checkPlanValid=(e,n,i=!0)=>t(void 0,void 0,void 0,(function*(){const t=yield(0,o.isGoodPlan)(e,n),r=yield(0,o.isPaying)(e,n),s=yield(0,o.isTrial)(e,n);r&&t||!(s<0)||a.program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`),s>0&&i&&!r&&console.log(`WARNING !!\nTrial expires in ${s} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e=`${l.default.homedir()}/.capgo`;return p.default.existsSync(e)?p.default.readFileSync(e,"utf8").trim():(e=".capgo",p.default.existsSync(e)?p.default.readFileSync(e,"utf8").trim():null)},o.formatError=e=>e?`\n${d.default.render(e)}`:"",o.getConfig=()=>t(void 0,void 0,void 0,(function*(){let e;try{e=yield(0,r.loadConfig)()}catch(e){a.program.error("No capacitor config file found, run `cap init` first")}return e})),o.updateOrCreateVersion=(e,o,n)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:i}=yield e.rpc("exist_app_versions",{appid:o.app_id,name_version:o.name,apikey:n});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.updateOrCreateChannel=(e,o,n)=>t(void 0,void 0,void 0,(function*(){if(!o.app_id||!o.name||!o.created_by)return console.error("missing app_id, name, or created_by"),Promise.reject(new Error("missing app_id, name, or created_by"));const{data:t,error:i}=yield e.rpc("exist_channel",{appid:o.app_id,name_channel:o.name,apikey:n});return t&&!i?e.from("channels").update(o,{returning:"minimal"}).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by):e.from("channels").insert(o,{returning:"minimal"})})),o.useLogSnag=()=>new c.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.verifyUser=(e,n,i=["all"])=>t(void 0,void 0,void 0,(function*(){yield(0,o.checkKey)(e,n,i);const{data:t,error:r}=yield e.rpc("get_user_id",{apikey:n}),s=t?t.toString():"";return s&&!r||a.program.error(`Cannot verify user ${(0,o.formatError)(r)}`),s})),o.getHumanDate=e=>new Date(e.created_at||"").toLocaleString()},778:e=>{e.exports=require("@capacitor/cli/dist/config")},885:e=>{e.exports=require("@supabase/supabase-js")},906:e=>{e.exports=require("@tomasklaen/checksum")},844:e=>{e.exports=require("adm-zip")},295:e=>{e.exports=require("cli-progress")},304:e=>{e.exports=require("commander")},470:e=>{e.exports=require("fs-extra")},133:e=>{e.exports=require("logsnag")},11:e=>{e.exports=require("mime")},867:e=>{e.exports=require("prettyjson")},616:e=>{e.exports=require("prompt-sync")},505:e=>{e.exports=require("semver/preload")},113:e=>{e.exports=require("crypto")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},598:e=>{e.exports=JSON.parse('{"name":"@capgo/cli","version":"1.3.1","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"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","build":"npx webpack --config webpack.config.js","dev-build":"SUPA_DB=development npx webpack --config webpack.config.js","pack":"pkg","test_rls":"ts-node ./test/test_headers_rls.ts","lint":"eslint . --ext .ts --fix"},"author":"github.com/riderx","license":"Apache 2.0","dependencies":{"@capacitor/cli":"4.4.0","@supabase/supabase-js":"^1.35.7","@tomasklaen/checksum":"^1.1.0","adm-zip":"^0.5.9","cli-progress":"3.11.2","commander":"9.4.1","fs-extra":"10.1.0","logsnag":"^0.1.5","mime":"^3.0.0","prettyjson":"^1.2.5","prompt-sync":"^4.2.0","semver":"^7.3.8"},"devDependencies":{"@types/adm-zip":"0.5.0","@types/cli-progress":"^3.11.0","@types/fs-extra":"^9.0.13","@types/mime":"^3.0.1","@types/node":"^18.11.9","@types/prettyjson":"^0.0.30","@types/prompt-sync":"^4.2.0","@types/semver":"^7.3.13","@typescript-eslint/eslint-plugin":"5.42.1","@typescript-eslint/parser":"5.42.1","eslint":"8.27.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^8.5.0","eslint-import-resolver-typescript":"3.5.2","eslint-plugin-import":"2.26.0","eslint-plugin-prettier":"^4.2.1","git-format-staged":"3.0.0","husky":"^8.0.2","nodemon":"2.0.20","pkg":"5.8.0","prettier":"2.7.1","ts-loader":"^9.4.1","ts-node":"^10.9.1","tsconfig-paths":"4.1.0","typescript":"4.8.4","webpack":"5.74.0","webpack-cli":"^4.10.0","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}(250)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "1.2.3",
3
+ "version": "1.3.1",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -12,9 +12,9 @@ interface Options {
12
12
  version: string;
13
13
  bundle: string;
14
14
  keep: number;
15
+ force: boolean;
15
16
  }
16
17
 
17
-
18
18
  const prompt = promptSync();
19
19
 
20
20
  const removeVersions = (toRemove: definitions["app_versions"][], supabase: SupabaseClient, appid: string, userId: string) => {
@@ -35,13 +35,10 @@ const getRemovableVersionsInSemverRange = (data: definitions["app_versions"][],
35
35
  return toRemove;
36
36
  }
37
37
 
38
- const loop = (times: number, callback: (i: number) => unknown) => {
39
- [...Array(times)].forEach((item, i) => callback(i));
40
- };
41
-
42
38
  export const cleanupApp = async (appid: string, options: Options) => {
43
39
  const apikey = options.apikey || findSavedKey()
44
40
  const { bundle, keep = 4 } = options;
41
+ const force = options.force || false;
45
42
 
46
43
  const config = await getConfig();
47
44
 
@@ -73,46 +70,41 @@ export const cleanupApp = async (appid: string, options: Options) => {
73
70
  }
74
71
 
75
72
  // Get all app versions that are in the given range
76
- const toRemove = getRemovableVersionsInSemverRange(data, bundle, nextMajor);
77
-
78
- console.log(`Active versions in Capgo between ${bundle} and ${nextMajor}: ${toRemove?.length}`);
79
-
80
- const removeLast = (recent = true) => {
81
- const last = toRemove.pop();
82
- if (last) {
83
- const humanDate = getHumanDate(last);
84
- if (recent) {
85
- console.log(`${last.name} created on ${humanDate} will be kept as it's the last release`);
86
- } else {
87
- console.log(`${last.name} created on ${humanDate} will be kept due to config`);
88
- }
89
- }
90
- }
73
+ const allVersions = getRemovableVersionsInSemverRange(data, bundle, nextMajor).reverse();
91
74
 
92
- // Always keep the latest version
93
- removeLast(true);
75
+ console.log(`Active versions in Capgo between ${bundle} and ${nextMajor}: ${allVersions?.length}`);
94
76
 
95
- // loop call removeLast until we have use up the keep count
96
- loop(keep, () => removeLast(false));
77
+ // Slice to keep and remove
78
+ const toKeep = allVersions.slice(0, keep);
79
+ const toRemove = allVersions.slice(keep);
97
80
 
81
+ // Show the user what will be kept
82
+ toKeep.forEach(row => {
83
+ console.log(`${row.name} created on ${(getHumanDate(row))} will be kept`);
84
+ });
85
+ if (toKeep.length) {
86
+ console.log("===================================================");
87
+ }
98
88
  if (toRemove.length === 0) {
99
89
  console.log("Nothing to be removed, aborting removal...")
100
90
  return;
101
91
  }
102
92
 
103
93
  // Show the user what will be removed
104
- toRemove?.forEach(row => {
94
+ toRemove.forEach(row => {
105
95
  console.log(`${row.name} created on ${(getHumanDate(row))} will be removed`);
106
96
  });
107
97
 
108
98
  // Check user wants to clean that all up
109
- const result = prompt("Do you want to continue removing the versions specified? Type yes to confirm");
110
- if (result !== "yes") {
111
- console.log("Not confirmed, aborting removal...");
112
- return;
99
+ if (!force) {
100
+ const result = prompt("Do you want to continue removing the versions specified? Type yes to confirm");
101
+ if (result !== "yes") {
102
+ console.log("Not confirmed, aborting removal...");
103
+ return;
104
+ }
113
105
  }
114
106
 
115
107
  // Yes, lets clean it up
116
- console.log("You have confiremd removal, removing versions now");
108
+ console.log("You have confirmed removal, removing versions now");
117
109
  removeVersions(toRemove, supabase, appid, userId);
118
110
  }
package/src/bin/index.ts CHANGED
@@ -9,8 +9,8 @@ import { listApp } from './list';
9
9
  import { cleanupApp } from './cleanup';
10
10
 
11
11
  program
12
- .description('Manage package and version in capgo Cloud')
13
- .version(pack.version)
12
+ .description('Manage packages and bundle versions in capgo Cloud')
13
+ .version(pack.version);
14
14
 
15
15
  program
16
16
  .command('add [appid]').alias('a')
@@ -76,6 +76,7 @@ program
76
76
  .action(cleanupApp)
77
77
  .requiredOption('-b, --bundle <bundle>', 'bundle version number of the app to delete')
78
78
  .option('-a, --apikey <apikey>', 'apikey to link to your account')
79
- .option('-k, --keep <keep>', 'number of version to keep');
79
+ .option('-k, --keep <keep>', 'number of version to keep')
80
+ .option('-f, --force', 'force removal');
80
81
 
81
82
  program.parse(process.argv);