@capgo/cli 2.3.7 → 2.3.9
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 +14 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/api/app.ts +2 -1
- package/src/api/channels.ts +6 -5
- package/src/api/devices_override.ts +6 -5
- package/src/api/storage.ts +3 -15
- package/src/api/versions.ts +5 -5
- package/src/bin/add.ts +4 -1
- package/src/bin/cleanup.ts +5 -4
- package/src/bin/set.ts +8 -3
- package/src/bin/upload.ts +2 -2
- package/src/bin/utils.ts +13 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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
|
+
### [2.3.9](https://github.com/Cap-go/capgo-cli/compare/v2.3.8...v2.3.9) (2022-12-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* cleanup stop use single ([edea602](https://github.com/Cap-go/capgo-cli/commit/edea602a5ad87de94b67a76ad48b2de2dba0dd7b))
|
|
11
|
+
|
|
12
|
+
### [2.3.8](https://github.com/Cap-go/capgo-cli/compare/v2.3.7...v2.3.8) (2022-12-07)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* typing supabase 2 ([add5191](https://github.com/Cap-go/capgo-cli/commit/add5191e5c810c2f3a3a522d732b591eab3d6628))
|
|
18
|
+
|
|
5
19
|
### [2.3.7](https://github.com/Cap-go/capgo-cli/compare/v2.3.6...v2.3.7) (2022-12-06)
|
|
6
20
|
|
|
7
21
|
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
(()=>{"use strict";var e={577: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((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}).single();t&&!r||i.program.error("No permission for this app")}))},978: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInChannel=void 0;const i=n(304),r=n(880);o.checkVersionNotUsedInChannel=(e,o,n,a,s)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:p}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).eq("version",a.id).single();if(t&&t.length||p){const e=(0,r.convertAppName)(o);i.program.error(`Version ${o}@${s} is used in a channel, unlink it first\nhttps://web.capgo.app/app/p/${e}/channel/${t.id}\n${(0,r.formatError)(p)}`)}}))},113:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createRSA=o.encryptSource=o.decryptSource=void 0;const t=n(663),i="aes-128-cbc",r="sha256",a="base64",s=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[p,d]=o.split(":"),c=(0,t.privateDecrypt)({key:n,padding:s,oaepHash:r},Buffer.from(d,a)),l=Buffer.from(p,a),u=c.toString(a);console.log("\nsessionB64",u);const y=(0,t.createDecipheriv)(i,c,l);return y.setAutoPadding(!0),Buffer.concat([y.update(e),y.final()])},o.encryptSource=(e,o)=>{const n=(0,t.randomBytes)(16),p=(0,t.randomBytes)(16),d=(0,t.createCipheriv)(i,p,n);d.setAutoPadding(!0);const c=`${n.toString(a)}:${(0,t.publicEncrypt)({key:o,padding:s,oaepHash:r},p).toString(a)}`;return{encryptedData:Buffer.concat([d.update(e),d.final()]),ivSessionKey:c}},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"})}}},386: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const i=n(304),r=n(880);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).single();if(t||s){const e=(0,r.convertAppName)(o);i.program.error(`Version ${o} @${a} is used in a device override, unlink it first\nhttps://web.capgo.app/app/p/${e}/d/${t.device_id}\n${(0,r.formatError)(s)}`)}}))},191: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(304),r=n(880);o.deleteFromStorage=(e,o,n,a,s)=>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} @${s} ${(0,r.formatError)(t)} `)}))},340: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getVersionData=o.getActiveAppVersions=o.displayBundles=o.deleteSpecificVersion=o.deleteAppVersion=void 0;const i=n(304),r=n(847),a=n(880),s=n(978),p=n(386),d=n(191);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 '${(0,a.formatError)(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,s.checkVersionNotUsedInChannel)(e,n,i,t,r),yield(0,p.checkVersionNotUsedInDeviceOverride)(e,n,t,r),yield(0,d.deleteFromStorage)(e,i,n,t,r),yield(0,o.deleteAppVersion)(e,n,i,r)})),o.displayBundles=e=>{const o=new r.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,a.getHumanDate)(e)},void 0!==e.keep?{Keep:e.keep}:{}))})),o.printTable()},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).order("id");return r&&i.program.error(`App ${o} not found in database ${(0,a.formatError)(r)} `),t})),o.getVersionData=(e,o,n,r)=>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",r).eq("deleted",!1).single();return t&&!s||i.program.error(`Version ${o}@${r} doesn't exist ${(0,a.formatError)(s)}`),t}))},870: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const i=n(304),r=n(663),a=n(147),s=n(470),p=n(11),d=n(880),c="assets/icon.png";o.addApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t;let{name:l,icon:u}=o;const y=o.apikey||(0,d.findSavedKey)(),g=yield(0,d.getConfig)(),v=(0,d.useLogSnag)();e=e||(null===(n=null==g?void 0:g.app)||void 0===n?void 0:n.appId),l=l||(null===(t=null==g?void 0:g.app)||void 0===t?void 0:t.appName)||"Unknown",u=u||"resources/icon.png",y||i.program.error("Missing API key, you need to provide a API key to add your app"),e&&l||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 f=(0,d.createSupabaseClient)(y),h=yield(0,d.verifyUser)(f,y,["write","all"]);let m,b;yield(0,d.checkPlanValid)(f,h),console.log("Adding..."),u&&(0,s.existsSync)(u)?(m=(0,a.readFileSync)(u),b=(0,p.getType)(u)||"image/png",console.warn(`Found app icon ${u}`)):(0,s.existsSync)(c)?(m=(0,a.readFileSync)(c),b=(0,p.getType)(c)||"image/png",console.warn(`Found app icon ${c}`)):console.warn(`Cannot find app icon in any of the following locations: ${u}, ${c}`);const{data:_,error:k}=yield f.rpc("exist_app",{appid:e,apikey:y}).single();(_||k)&&i.program.error(`App already exists ${(0,d.formatError)(k)}`);const w=`icon_${(0,r.randomUUID)()}`;let $="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(m&&b){const{error:o}=yield f.storage.from(`images/${h}/${e}`).upload(w,m,{contentType:b});o&&i.program.error(`Could not add app ${(0,d.formatError)(o)}`);const{data:n}=yield f.storage.from(`images/${h}/${e}`).getPublicUrl(w);$=(null==n?void 0:n.publicUrl)||$}const{error:x}=yield f.from("apps").insert({icon_url:$,user_id:h,name:l,app_id:e});x&&i.program.error(`Could not add app ${(0,d.formatError)(x)}`);const{error:S}=yield f.from("app_versions").insert([{user_id:h,deleted:!0,name:"unknown",app_id:e},{user_id:h,deleted:!0,name:"builtin",app_id:e}]);S&&i.program.error(`Could not add app ${(0,d.formatError)(S)}`),v.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":h,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now")}))},600: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((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)),p=n(880),d=n(340),c=n(577),l=(0,s.default)();o.cleanupApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,p.findSavedKey)(),{bundle:i,keep:s=4}=o,u=o.force||!1,y=yield(0,p.getConfig)();e=e||(null===(n=null==y?void 0:y.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 g=(0,p.createSupabaseClient)(t),v=yield(0,p.verifyUser)(g,t);yield(0,c.checkAppExistsAndHasPermission)(g,e,t),console.log("Querying all available versions in Capgo");let f=yield(0,d.getActiveAppVersions)(g,e,v);if(console.log(`Total active versions in Capgo: ${null==f?void 0:f.length}`),0===(null==f?void 0:f.length))return void console.log("No versions found, aborting cleanup");if(i){const e=`${a.default.inc(i,"major")}`;console.log(`Querying available versions in Capgo between ${i} and ${e}`),f=((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})(f,i,e).reverse(),console.log(`Active versions in Capgo between ${i} and ${e}: ${null==f?void 0:f.length}`)}const h=[];if(f.forEach(((e,o)=>{o<s?e.keep="✅":(e.keep="❌",h.push(e))})),0!==h.length){if((0,d.displayBundles)(f),!u&&"yes"!==l("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,p.getHumanDate)(e)}`),(0,d.deleteSpecificVersion)(o,n,t,e.name)}))})(h,g,e,v)}else console.log("Nothing to be removed, aborting removal...")}))},692: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const i=n(304),r=n(147),a=n(113),s=n(880);o.decryptZip=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,p,d;(0,r.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const c=yield(0,s.getConfig)(),{extConfig:l}=c.app;n.key||(0,r.existsSync)(s.baseKey)||(null===(p=null===(t=l.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===p?void 0:p.privateKey)||i.program.error(`Private Key not found at the path ${s.baseKey} or in ${c.app.extConfigFilePath}`);const u=n.key||s.baseKey;let{privateKey:y}=n.keyData||(null===(d=null==l?void 0:l.plugins)||void 0===d?void 0:d.CapacitorUpdater)||"";(0,r.existsSync)(u)||y?(0,r.existsSync)(u)&&(y=(0,r.readFileSync)(u).toString()):i.program.error(`Cannot find public key ${u} or as keyData option or in ${c.app.extConfigFilePath}`);const g=(0,r.readFileSync)(e),v=(0,a.decryptSource)(g,o,y);(0,r.writeFileSync)(`${e}_decrypted.zip`,v)}))},0: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const i=n(304),r=n(880),a=n(340);o.deleteApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const{bundle:t}=o,s=o.apikey||(0,r.findSavedKey)(),p=yield(0,r.getConfig)(),d=(0,r.useLogSnag)();e=e||(null===(n=null==p?void 0:p.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 c=(0,r.createSupabaseClient)(s),l=yield(0,r.verifyUser)(c,s),{data:u,error:y}=yield c.rpc("exist_app",{appid:e,apikey:s}).single();if(u&&!y||i.program.error("No permission to delete"),t)return console.log(`Delete ${e}@${t} from Capgo`),yield(0,a.deleteSpecificVersion)(c,e,l,t),void console.log(`${e}@${t} deleted from server`);console.log(`Delete ${e} from Capgo`);const{data:g,error:v}=yield c.from("app_versions").select().eq("app_id",e).eq("user_id",l);if(v&&i.program.error(`App ${e} not found in database ${(0,r.formatError)(v)} `),g&&g.length){const o=g.map((o=>`${l}/${e}/versions/${o.bucket_id} `)),{error:n}=yield c.storage.from("apps").remove(o);n&&i.program.error(`Cannot delete stored version for app ${e} from storage ${(0,r.formatError)(n)} `)}const{error:f}=yield c.from("app_versions").delete().eq("app_id",e).eq("user_id",l);f&&i.program.error(`Cannot delete version for app ${e} from database ${(0,r.formatError)(f)} `);const{error:h}=yield c.from("apps").delete().eq("app_id",e).eq("user_id",l);h&&i.program.error(`Cannot delete from database ${(0,r.formatError)(h)} `),d.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":l,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`)}))},128: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const i=n(304),r=n(147),a=n(113),s=n(880);o.encryptZip=(e,o)=>t(void 0,void 0,void 0,(function*(){(0,r.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const n=o.key||s.baseKeyPub;let t=o.keyData||"";(0,r.existsSync)(n)||t?(0,r.existsSync)(n)&&(t=(0,r.readFileSync)(n).toString()):i.program.error(`Cannot find public key ${n} or as keyData option`);const p=(0,r.readFileSync)(e),d=(0,a.encryptSource)(p,t);console.log("ivSessionKey",d.ivSessionKey),(0,r.writeFileSync)(`${e}_encrypted.zip`,d.encryptedData)}))},731: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(692),a=n(128),s=n(870),p=n(218),d=n(0),c=n(331),l=n(510),u=t(n(598)),y=n(621),g=n(272),v=n(600);i.program.description("Manage packages and bundle versions in capgo Cloud").version(u.default.version),i.program.command("add [appid]").alias("a").description("Add a new app to capgo Cloud").action(s.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(y.login).option("--local","Only save in local folder"),i.program.command("upload [appid]").alias("u").description("Upload a new bundle to capgo Cloud").action(l.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to capgo cloud").option("--key <key>","custom path for public signing key").option("--keyData <keyData>","base64 public signing key").option("--no-key","ignore signing key and send clear update").option("-b, --bundle <bundle>","bundle version number of the file to upload"),i.program.command("set [appid]").alias("s").description("Modify a channel configuration").action(c.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(d.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(g.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(v.cleanupApp).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"),i.program.command("key [option]").description("Save base64 signing key in capacitor config, usefull for CI").action(p.manageKey).option("-f, --force","force generate a new one"),i.program.command("decrypt [zipPath] [sessionKey]").description("Decrypt a signed zip update").action(r.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),i.program.command("encrypt [zipPath]").description("Encrypt a zip update").action(a.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),i.program.parse(process.argv)},218: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.manageKey=void 0;const i=n(304),r=n(147),a=n(778),s=n(113),p=n(880);o.manageKey=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,d;"save"===e?(n=o.key,d=o.keyData,t(void 0,void 0,void 0,(function*(){var e;(0,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const o=yield(0,p.getConfig)(),{extConfig:t}=o.app,s=n||p.baseKey;let{privateKey:c}=d||(null===(e=null==t?void 0:t.plugins)||void 0===e?void 0:e.CapacitorUpdater)||"";(0,r.existsSync)(s)||c?(0,r.existsSync)(s)&&(c=(0,r.readFileSync)(s).toString()):i.program.error(`Cannot find public key ${s} or as keyData option or in ${o.app.extConfigFilePath}`),t&&(t.plugins||(t.plugins={}),t.plugins.CapacitorUpdater||(t.plugins.CapacitorUpdater={}),t.plugins.CapacitorUpdater.privateKey=d,(0,a.writeConfig)(t,o.app.extConfigFilePath)),console.log(`private key saved into ${o.app.extConfigFilePath} file in local directory`),console.log("your app will decode the zip archive with this key\n")}))):"create"===e?(e=>{t(void 0,void 0,void 0,(function*(){(0,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const{publicKey:o,privateKey:n}=(0,s.createRSA)();(0,r.existsSync)(p.baseKeyPub)&&!e.force&&i.program.error("Public Key already exists, use --force to overwrite"),(0,r.writeFileSync)(p.baseKeyPub,o),(0,r.existsSync)(p.baseKey)&&!e.force&&i.program.error("Private Key already exists, use --force to overwrite"),(0,r.writeFileSync)(p.baseKey,n);const t=yield(0,p.getConfig)(),{extConfig:d}=t.app;d&&(d.plugins||(d.plugins={}),d.plugins.CapacitorUpdater||(d.plugins.CapacitorUpdater={}),d.plugins.CapacitorUpdater.privateKey=n,(0,a.writeConfig)(d,t.app.extConfigFilePath)),console.log("Your RSA key has been generated using node-rsa with this settings:\n\n- encryptionScheme — 'pkcs1_oaep'.\n- signingScheme — 'pkcs8-sha256'.\n- bits — 2048.\n- exp — 65537.\n"),console.log(`public key saved into ${p.baseKeyPub} file in local directory\n`),console.log("This key will be use to encode your zipped bundle before sending it to Capgo,\nthan make them unreadable by Capgo and unmodifiable by anyone\n"),console.log(`Private key saved into ${t.app.extConfigFilePath} file in local directory`),console.log("Your app will decode with this key the zipped bundle\n")}))})(o):i.program.error("You should provide a valid option (create or save)")}))},272: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const i=n(304),r=n(880),a=n(577),s=n(340);o.listApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,r.findSavedKey)(),p=yield(0,r.getConfig)();e=e||(null===(n=null==p?void 0:p.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 d=(0,r.createSupabaseClient)(t),c=yield(0,r.verifyUser)(d,t);yield(0,a.checkAppExistsAndHasPermission)(d,e,t);const l=yield(0,s.getActiveAppVersions)(d,e,c);console.log(`Active versions in Capgo: ${null==l?void 0:l.length}`),(0,s.displayBundles)(l)}))},621: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.login=void 0;const i=n(304),r=n(147),a=n(37),s=n(880);o.login=(e,o)=>t(void 0,void 0,void 0,(function*(){const{local:n}=o,t=(0,s.useLogSnag)();if(n)(0,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository"),(0,r.writeFileSync)(".capgo",`${e}\n`),(0,r.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,a.homedir)();(0,r.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const p=(0,s.createSupabaseClient)(e),d=yield(0,s.verifyUser)(p,e,["write","all","upload"]);t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":d},notify:!1}).catch(),console.log(`login saved into .capgo file in ${n?"local":"home"} directory`)}))},331: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const i=n(304),r=n(880);o.setChannel=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,a;const{bundle:s,latest:p,downgrade:d,upgrade:c,ios:l,android:u,selfAssign:y,channel:g,state:v}=o,f=o.apikey||(0,r.findSavedKey)(),h=yield(0,r.getConfig)(),m=(0,r.useLogSnag)();e=e||(null===(n=null==h?void 0:h.app)||void 0===n?void 0:n.appId),f||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"),p&&s&&i.program.error("Cannot set latest and bundle at the same time"),void 0===s&&void 0===v&&void 0===p&&void 0===d&&void 0===c&&void 0===l&&void 0===u&&void 0===y&&i.program.error("Missing argument, you need to provide a option to set");try{const o=(0,r.createSupabaseClient)(f),n=yield(0,r.verifyUser)(o,f,["write","all"]);yield(0,r.checkPlanValid)(o,n);const b={created_by:n,app_id:e,name:g},_=p?null===(a=null===(t=null==h?void 0:h.app)||void 0===t?void 0:t.package)||void 0===a?void 0:a.version:s;if(_){const{data:t,error:r}=yield o.from("app_versions").select().eq("app_id",e).eq("name",_).eq("user_id",n).eq("deleted",!1);!r&&t&&t.length||i.program.error(`Cannot find version ${_}`),console.log(`Set ${e} channel: ${g} to @${s}`),b.version=t[0].id}void 0!==v&&("public"!==v&&"private"!==v||console.log(`Set ${e} channel: ${g} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${g} to ${"public"===v||"default"===v?"default":"normal"}`),b.public="public"===v||"default"===v),void 0!==d&&(console.log(`Set ${e} channel: ${g} to ${d?"allow":"disallow"} downgrade`),b.disableAutoUpdateUnderNative=!d),void 0!==c&&(console.log(`Set ${e} channel: ${g} to ${c?"allow":"disallow"} upgrade`),b.disableAutoUpdateToMajor=!c),void 0!==l&&(console.log(`Set ${e} channel: ${g} to ${l?"allow":"disallow"} ios update`),b.ios=!!l),void 0!==u&&(console.log(`Set ${e} channel: ${g} to ${u?"allow":"disallow"} android update`),b.android=!!u),void 0!==y&&(console.log(`Set ${e} channel: ${g} to ${y?"allow":"disallow"} self assign to this channel`),b.allow_device_self_set=!!y);try{const{error:e}=yield(0,r.updateOrCreateChannel)(o,b,f);e&&i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}catch(e){i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}m.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 ✅")}))},510: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((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(663),p=i(n(295)),d=n(147),c=n(906),l=n(113),u=n(880);o.uploadVersion=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,i,y;let{bundle:g,path:v,channel:f}=o;const{external:h,key:m=!1}=o,b=o.apikey||(0,u.findSavedKey)(),_=(0,u.useLogSnag)();f=f||"dev";const k=yield(0,u.getConfig)();e=e||(null===(n=null==k?void 0:k.app)||void 0===n?void 0:n.appId),g=g||(null===(i=null===(t=null==k?void 0:k.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version),u.regexSemver.test(g)||a.program.error(`Your bundle name ${g}, is not valid it should follow semver convention : https://semver.org/`),v=v||(null===(y=null==k?void 0:k.app)||void 0===y?void 0:y.webDir),b||a.program.error("Missing API key, you need to provide a API key to add your app"),e&&g&&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}@${g} started from path "${v}" to Capgo cloud`);const w=(0,u.createSupabaseClient)(b),$=yield(0,u.verifyUser)(w,b,["write","all","upload"]);yield(0,u.checkPlanValid)(w,$,!1);const x=new p.default.MultiBar({clearOnComplete:!1,hideCursor:!0},p.default.Presets.shades_grey),S=x.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},p.default.Presets.shades_grey);S.start(7,0,{speed:"N/A"});const{data:C,error:A}=yield w.rpc("exist_app_versions",{apikey:b,name_version:g,appid:e}).single();(C||A)&&(x.stop(),a.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,u.formatError)(A)}`)),S.increment();const{data:P,error:K}=yield w.rpc("is_trial",{userid:$}).single();(P&&P>0||K)&&x.log(`WARNING !!\nTrial expires in ${P} days, upgrade here: ${u.hostWeb}/dashboard/settings/plans\n`),S.increment();const{data:D,error:q}=yield w.rpc("exist_app",{appid:e,apikey:b}).single();D&&!q||(x.stop(),a.program.error(`Cannot find app ${e} in your account \n${(0,u.formatError)(q)}`)),S.increment();const{data:j,error:I}=yield w.rpc("exist_app_versions",{appid:e,apikey:b,name_version:g}).single();(j||I)&&a.program.error(`Version already exists ${(0,u.formatError)(I)}`),S.increment();const U=(0,s.randomUUID)();let M,E="";if(h)h&&!h.startsWith("https://")&&(x.stop(),a.program.error(`External link should should start with "https://" current is "${h}"`));else{const o=new r.default;o.addLocalFolder(v);let n=o.toBuffer();if(E=yield(0,c.checksum)(n,"crc32"),m||(0,d.existsSync)(u.baseKeyPub)){const e="string"==typeof m?m:u.baseKeyPub;(0,d.existsSync)(e)||a.program.error(`Cannot find public key ${e}`);const o=(0,d.readFileSync)(e);x.log("Encrypting your bundle\n");const t=(0,l.encryptSource)(n,o.toString());M=t.ivSessionKey,n=t.encryptedData}const t=Math.floor(n.byteLength/1024/1024),i=`apps/${$}/${e}/versions`;S.increment(),t>20&&(x.log(`WARNING !!\nThe app size is ${t} Mb, this may take a while to download for users\n`),_.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":$,"app-id":e},notify:!1}).catch());const{error:s}=yield w.storage.from(i).upload(U,n,{contentType:"application/zip"});s&&(x.stop(),a.program.error(`Cannot upload ${(0,u.formatError)(s)}`))}S.increment();const{data:O,error:V}=yield(0,u.updateOrCreateVersion)(w,{bucket_id:h?void 0:U,user_id:$,name:g,app_id:e,session_key:M,external_url:h,checksum:E},b);if(V&&(x.stop(),a.program.error(`Cannot add bundle ${(0,u.formatError)(V)}`)),S.increment(),O&&O.length){const{error:o}=yield(0,u.updateOrCreateChannel)(w,{name:f,app_id:e,created_by:$,version:O[0].id},b);o&&x.log("Cannot set bundle with upload key, use key with more rights for that\n")}else x.log("Cannot set bundle with upload key, use key with more rights for that\n");x.stop();const N=(0,u.convertAppName)(e);console.log("App uploaded to server"),console.log(`Try it in mobile app: ${u.host}/app_mobile`),console.log(`Or set the channel ${f} as public here: ${u.hostWeb}/app/package/${N}`),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: ${u.hostWeb}/app/p/${N}/devices`),_.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":$,"app-id":e},notify:!1}).catch()}))},880: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((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.convertAppName=o.useLogSnag=o.updateOrCreateChannel=o.updateOrCreateVersion=o.getConfig=o.formatError=o.findSavedKey=o.checkPlanValid=o.isAllowedAction=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.supaAnon=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=void 0;const r=n(778),a=n(304),s=n(885),p=i(n(867)),d=n(147),c=n(37),l=n(133);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.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w",o.createSupabaseClient=e=>(0,s.createClient)(o.hostSupa,o.supaAnon,{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,i)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:i}).single();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.isAllowedAction=(e,o)=>t(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,n,i=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.isAllowedAction)(e,n))||a.program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`);const t=yield(0,o.isTrial)(e,n);t>0&&i&&console.log(`WARNING !!\nTrial expires in ${t} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e=`${(0,c.homedir)()}/.capgo`;return(0,d.existsSync)(e)?(console.log(`Use global apy key ${e}`),(0,d.readFileSync)(e,"utf8").trim()):(e=".capgo",(0,d.existsSync)(e)?(console.log(`Use local apy key ${e}`),(0,d.readFileSync)(e,"utf8").trim()):null)},o.formatError=e=>e?`\n${p.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}).single();return t&&!i?(o.deleted=!1,e.from("app_versions").update(o).eq("app_id",o.app_id).eq("name",o.name).single()):e.from("app_versions").insert(o).select().single()})),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}).single();return t&&!i?e.from("channels").update(o).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by).single():e.from("channels").insert(o).select().single()})),o.useLogSnag=()=>new l.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.convertAppName=e=>e.replace(/\./g,"--"),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}).single(),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")},847:e=>{e.exports=require("console-table-printer")},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")},663: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":"2.3.7","description":"A CLI to upload to capgo servers","main":"dist/index.js","bin":{"capgo":"dist/index.js"},"repository":{"type":"git","url":"git+https://github.com/Cap-go/capgo-cli.git"},"bugs":{"url":"https://github.com/Cap-go/capgo-cli/issues"},"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/bin/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":"4.6.0","@supabase/supabase-js":"^2.1.2","@tomasklaen/checksum":"^1.1.0","adm-zip":"^0.5.9","cli-progress":"3.11.2","commander":"9.4.1","console-table-printer":"^2.11.1","fs-extra":"11.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.45.0","@typescript-eslint/parser":"5.45.0","eslint":"8.29.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.8.0","ts-loader":"^9.4.1","ts-node":"^10.9.1","tsconfig-paths":"4.1.1","typescript":"4.9.3","webpack":"5.75.0","webpack-cli":"^5.0.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}(731)})();
|
|
2
|
+
(()=>{"use strict";var e={577: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((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}).single();t&&!r||i.program.error("No permission for this app")}))},978: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInChannel=void 0;const i=n(304),r=n(880);o.checkVersionNotUsedInChannel=(e,o,n,a,s)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:p}=yield e.from("channels").select().eq("app_id",o).eq("created_by",n).eq("version",a.id);if(p&&i.program.error(`Cannot check Version ${o}@${s} ${(0,r.formatError)(p)}`),t&&t.length>0){const e=(0,r.convertAppName)(o);i.program.error(`❌ Version ${o}@${s} is used in a channel, unlink it first\nhttps://web.capgo.app/app/p/${e}/channel/${t[0].id}\n${(0,r.formatError)(p)}`)}}))},113:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createRSA=o.encryptSource=o.decryptSource=void 0;const t=n(663),i="aes-128-cbc",r="sha256",a="base64",s=t.constants.RSA_PKCS1_OAEP_PADDING;o.decryptSource=(e,o,n)=>{const[p,d]=o.split(":"),c=(0,t.privateDecrypt)({key:n,padding:s,oaepHash:r},Buffer.from(d,a)),l=Buffer.from(p,a),u=c.toString(a);console.log("\nsessionB64",u);const y=(0,t.createDecipheriv)(i,c,l);return y.setAutoPadding(!0),Buffer.concat([y.update(e),y.final()])},o.encryptSource=(e,o)=>{const n=(0,t.randomBytes)(16),p=(0,t.randomBytes)(16),d=(0,t.createCipheriv)(i,p,n);d.setAutoPadding(!0);const c=`${n.toString(a)}:${(0,t.publicEncrypt)({key:o,padding:s,oaepHash:r},p).toString(a)}`;return{encryptedData:Buffer.concat([d.update(e),d.final()]),ivSessionKey:c}},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"})}}},386: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.checkVersionNotUsedInDeviceOverride=void 0;const i=n(304),r=n(880);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);if(s&&i.program.error(`Cannot check Device override ${o}@${a} ${(0,r.formatError)(s)}`),t&&t.length>0){const e=(0,r.convertAppName)(o);i.program.error(`❌ Version ${o} @${a} is used in a device override, unlink it first\nhttps://web.capgo.app/app/p/${e}/d/${t[0].device_id}\n${(0,r.formatError)(s)}`)}}))},191: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteFromStorage=void 0;const i=n(304),r=n(880);o.deleteFromStorage=(e,o,n,a,s)=>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} @${s} ${(0,r.formatError)(t)} `)}))},340: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.getVersionData=o.getActiveAppVersions=o.displayBundles=o.deleteSpecificVersion=o.deleteAppVersion=void 0;const i=n(304),r=n(847),a=n(880),s=n(978),p=n(386),d=n(191);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 '${(0,a.formatError)(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,s.checkVersionNotUsedInChannel)(e,n,i,t,r),yield(0,p.checkVersionNotUsedInDeviceOverride)(e,n,t,r),yield(0,d.deleteFromStorage)(e,i,n,t,r),yield(0,o.deleteAppVersion)(e,n,i,r)})),o.displayBundles=e=>{const o=new r.Table({title:"Bundles",charLength:{"❌":2,"✅":2}});e.reverse().forEach((e=>{o.addRow(Object.assign({Version:e.name,Created:(0,a.getHumanDate)(e)},void 0!==e.keep?{Keep:e.keep}:{}))})),o.printTable()},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).order("created_at",{ascending:!1});return r&&i.program.error(`App ${o} not found in database ${(0,a.formatError)(r)} `),t})),o.getVersionData=(e,o,n,r)=>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",r).eq("deleted",!1).single();return t&&!s||i.program.error(`Version ${o}@${r} doesn't exist ${(0,a.formatError)(s)}`),t}))},870: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.addApp=void 0;const i=n(304),r=n(663),a=n(147),s=n(470),p=n(11),d=n(880),c="assets/icon.png";o.addApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t;let{name:l,icon:u}=o;const y=o.apikey||(0,d.findSavedKey)(),g=yield(0,d.getConfig)(),v=(0,d.useLogSnag)();e=e||(null===(n=null==g?void 0:g.app)||void 0===n?void 0:n.appId),l=l||(null===(t=null==g?void 0:g.app)||void 0===t?void 0:t.appName)||"Unknown",u=u||"resources/icon.png",y||i.program.error("Missing API key, you need to provide a API key to add your app"),e&&l||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 f=(0,d.createSupabaseClient)(y),h=yield(0,d.verifyUser)(f,y,["write","all"]);let m,b;yield(0,d.checkPlanValid)(f,h),console.log("Adding..."),u&&(0,s.existsSync)(u)?(m=(0,a.readFileSync)(u),b=(0,p.getType)(u)||"image/png",console.warn(`Found app icon ${u}`)):(0,s.existsSync)(c)?(m=(0,a.readFileSync)(c),b=(0,p.getType)(c)||"image/png",console.warn(`Found app icon ${c}`)):console.warn(`Cannot find app icon in any of the following locations: ${u}, ${c}`);const{data:_,error:k}=yield f.rpc("exist_app",{appid:e,apikey:y}).single();(_||k)&&i.program.error(`App already exists ${(0,d.formatError)(k)}`);const w=`icon_${(0,r.randomUUID)()}`;let $="https://xvwzpoazmxkqosrdewyv.supabase.co/storage/v1/object/public/images/capgo.png";if(m&&b){const{error:o}=yield f.storage.from(`images/${h}/${e}`).upload(w,m,{contentType:b});o&&i.program.error(`Could not add app ${(0,d.formatError)(o)}`);const{data:n}=yield f.storage.from(`images/${h}/${e}`).getPublicUrl(w);$=(null==n?void 0:n.publicUrl)||$}const{error:x}=yield f.from("apps").insert({icon_url:$,user_id:h,name:l,app_id:e});x&&i.program.error(`Could not add app ${(0,d.formatError)(x)}`);const{error:S}=yield f.from("app_versions").insert([{user_id:h,deleted:!0,name:"unknown",app_id:e},{user_id:h,deleted:!0,name:"builtin",app_id:e}]);S&&i.program.error(`Could not add app ${(0,d.formatError)(S)}`),v.publish({channel:"app",event:"App Added",icon:"🎉",tags:{"user-id":h,"app-id":e},notify:!1}).catch(),console.log("App added to server, you can upload a bundle now")}))},600: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((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)),p=n(880),d=n(340),c=n(577),l=(0,s.default)();o.cleanupApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,p.findSavedKey)(),{bundle:i,keep:s=4}=o,u=o.force||!1,y=yield(0,p.getConfig)();e=e||(null===(n=null==y?void 0:y.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 g=(0,p.createSupabaseClient)(t),v=yield(0,p.verifyUser)(g,t);yield(0,c.checkAppExistsAndHasPermission)(g,e,t),console.log("Querying all available versions in Capgo");let f=yield(0,d.getActiveAppVersions)(g,e,v);if(console.log(`Total active versions in Capgo: ${null==f?void 0:f.length}`),0===(null==f?void 0:f.length))return void console.log("No versions found, aborting cleanup");if(i){const e=`${a.default.inc(i,"major")}`;console.log(`Querying available versions in Capgo between ${i} and ${e}`),f=((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})(f,i,e),console.log(`Active versions in Capgo between ${i} and ${e}: ${null==f?void 0:f.length}`)}const h=[];if(f.forEach(((e,o)=>{o<s?e.keep="✅":(e.keep="❌",h.push(e))})),0!==h.length){if((0,d.displayBundles)(f),!u&&"yes"!==l("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,p.getHumanDate)(e)}`),(0,d.deleteSpecificVersion)(o,n,t,e.name)}))})(h,g,e,v)}else console.log("Nothing to be removed, aborting removal...")}))},692: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.decryptZip=void 0;const i=n(304),r=n(147),a=n(113),s=n(880);o.decryptZip=(e,o,n)=>t(void 0,void 0,void 0,(function*(){var t,p,d;(0,r.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const c=yield(0,s.getConfig)(),{extConfig:l}=c.app;n.key||(0,r.existsSync)(s.baseKey)||(null===(p=null===(t=l.plugins)||void 0===t?void 0:t.CapacitorUpdater)||void 0===p?void 0:p.privateKey)||i.program.error(`Private Key not found at the path ${s.baseKey} or in ${c.app.extConfigFilePath}`);const u=n.key||s.baseKey;let{privateKey:y}=n.keyData||(null===(d=null==l?void 0:l.plugins)||void 0===d?void 0:d.CapacitorUpdater)||"";(0,r.existsSync)(u)||y?(0,r.existsSync)(u)&&(y=(0,r.readFileSync)(u).toString()):i.program.error(`Cannot find public key ${u} or as keyData option or in ${c.app.extConfigFilePath}`);const g=(0,r.readFileSync)(e),v=(0,a.decryptSource)(g,o,y);(0,r.writeFileSync)(`${e}_decrypted.zip`,v)}))},0: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.deleteApp=void 0;const i=n(304),r=n(880),a=n(340);o.deleteApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const{bundle:t}=o,s=o.apikey||(0,r.findSavedKey)(),p=yield(0,r.getConfig)(),d=(0,r.useLogSnag)();e=e||(null===(n=null==p?void 0:p.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 c=(0,r.createSupabaseClient)(s),l=yield(0,r.verifyUser)(c,s),{data:u,error:y}=yield c.rpc("exist_app",{appid:e,apikey:s}).single();if(u&&!y||i.program.error("No permission to delete"),t)return console.log(`Delete ${e}@${t} from Capgo`),yield(0,a.deleteSpecificVersion)(c,e,l,t),void console.log(`${e}@${t} deleted from server`);console.log(`Delete ${e} from Capgo`);const{data:g,error:v}=yield c.from("app_versions").select().eq("app_id",e).eq("user_id",l);if(v&&i.program.error(`App ${e} not found in database ${(0,r.formatError)(v)} `),g&&g.length){const o=g.map((o=>`${l}/${e}/versions/${o.bucket_id} `)),{error:n}=yield c.storage.from("apps").remove(o);n&&i.program.error(`Cannot delete stored version for app ${e} from storage ${(0,r.formatError)(n)} `)}const{error:f}=yield c.from("app_versions").delete().eq("app_id",e).eq("user_id",l);f&&i.program.error(`Cannot delete version for app ${e} from database ${(0,r.formatError)(f)} `);const{error:h}=yield c.from("apps").delete().eq("app_id",e).eq("user_id",l);h&&i.program.error(`Cannot delete from database ${(0,r.formatError)(h)} `),d.publish({channel:"app",event:"App Deleted",icon:"😱",tags:{"user-id":l,"app-id":e},notify:!1}).catch(),console.log(`${e} deleted from server`)}))},128: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.encryptZip=void 0;const i=n(304),r=n(147),a=n(113),s=n(880);o.encryptZip=(e,o)=>t(void 0,void 0,void 0,(function*(){(0,r.existsSync)(e)||i.program.error(`Zip not found at the path ${e}`);const n=o.key||s.baseKeyPub;let t=o.keyData||"";(0,r.existsSync)(n)||t?(0,r.existsSync)(n)&&(t=(0,r.readFileSync)(n).toString()):i.program.error(`Cannot find public key ${n} or as keyData option`);const p=(0,r.readFileSync)(e),d=(0,a.encryptSource)(p,t);console.log("ivSessionKey",d.ivSessionKey),(0,r.writeFileSync)(`${e}_encrypted.zip`,d.encryptedData)}))},731: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(692),a=n(128),s=n(870),p=n(218),d=n(0),c=n(331),l=n(510),u=t(n(598)),y=n(621),g=n(272),v=n(600);i.program.description("Manage packages and bundle versions in capgo Cloud").version(u.default.version),i.program.command("add [appid]").alias("a").description("Add a new app to capgo Cloud").action(s.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(y.login).option("--local","Only save in local folder"),i.program.command("upload [appid]").alias("u").description("Upload a new bundle to capgo Cloud").action(l.uploadVersion).option("-a, --apikey <apikey>","apikey to link to your account").option("-p, --path <path>","path of the folder to upload").option("-c, --channel <channel>","channel to link to").option("-e, --external <url>","link to external url intead of upload to capgo cloud").option("--key <key>","custom path for public signing key").option("--keyData <keyData>","base64 public signing key").option("--no-key","ignore signing key and send clear update").option("-b, --bundle <bundle>","bundle version number of the file to upload"),i.program.command("set [appid]").alias("s").description("Modify a channel configuration").action(c.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(d.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(g.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(v.cleanupApp).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"),i.program.command("key [option]").description("Save base64 signing key in capacitor config, usefull for CI").action(p.manageKey).option("-f, --force","force generate a new one"),i.program.command("decrypt [zipPath] [sessionKey]").description("Decrypt a signed zip update").action(r.decryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),i.program.command("encrypt [zipPath]").description("Encrypt a zip update").action(a.encryptZip).option("--key <key>","custom path for private signing key").option("--keyData <keyData>","base64 private signing key"),i.program.parse(process.argv)},218: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.manageKey=void 0;const i=n(304),r=n(147),a=n(778),s=n(113),p=n(880);o.manageKey=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,d;"save"===e?(n=o.key,d=o.keyData,t(void 0,void 0,void 0,(function*(){var e;(0,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const o=yield(0,p.getConfig)(),{extConfig:t}=o.app,s=n||p.baseKey;let{privateKey:c}=d||(null===(e=null==t?void 0:t.plugins)||void 0===e?void 0:e.CapacitorUpdater)||"";(0,r.existsSync)(s)||c?(0,r.existsSync)(s)&&(c=(0,r.readFileSync)(s).toString()):i.program.error(`Cannot find public key ${s} or as keyData option or in ${o.app.extConfigFilePath}`),t&&(t.plugins||(t.plugins={}),t.plugins.CapacitorUpdater||(t.plugins.CapacitorUpdater={}),t.plugins.CapacitorUpdater.privateKey=d,(0,a.writeConfig)(t,o.app.extConfigFilePath)),console.log(`private key saved into ${o.app.extConfigFilePath} file in local directory`),console.log("your app will decode the zip archive with this key\n")}))):"create"===e?(e=>{t(void 0,void 0,void 0,(function*(){(0,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository");const{publicKey:o,privateKey:n}=(0,s.createRSA)();(0,r.existsSync)(p.baseKeyPub)&&!e.force&&i.program.error("Public Key already exists, use --force to overwrite"),(0,r.writeFileSync)(p.baseKeyPub,o),(0,r.existsSync)(p.baseKey)&&!e.force&&i.program.error("Private Key already exists, use --force to overwrite"),(0,r.writeFileSync)(p.baseKey,n);const t=yield(0,p.getConfig)(),{extConfig:d}=t.app;d&&(d.plugins||(d.plugins={}),d.plugins.CapacitorUpdater||(d.plugins.CapacitorUpdater={}),d.plugins.CapacitorUpdater.privateKey=n,(0,a.writeConfig)(d,t.app.extConfigFilePath)),console.log("Your RSA key has been generated using node-rsa with this settings:\n\n- encryptionScheme — 'pkcs1_oaep'.\n- signingScheme — 'pkcs8-sha256'.\n- bits — 2048.\n- exp — 65537.\n"),console.log(`public key saved into ${p.baseKeyPub} file in local directory\n`),console.log("This key will be use to encode your zipped bundle before sending it to Capgo,\nthan make them unreadable by Capgo and unmodifiable by anyone\n"),console.log(`Private key saved into ${t.app.extConfigFilePath} file in local directory`),console.log("Your app will decode with this key the zipped bundle\n")}))})(o):i.program.error("You should provide a valid option (create or save)")}))},272: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.listApp=void 0;const i=n(304),r=n(880),a=n(577),s=n(340);o.listApp=(e,o)=>t(void 0,void 0,void 0,(function*(){var n;const t=o.apikey||(0,r.findSavedKey)(),p=yield(0,r.getConfig)();e=e||(null===(n=null==p?void 0:p.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 d=(0,r.createSupabaseClient)(t),c=yield(0,r.verifyUser)(d,t);yield(0,a.checkAppExistsAndHasPermission)(d,e,t);const l=yield(0,s.getActiveAppVersions)(d,e,c);console.log(`Active versions in Capgo: ${null==l?void 0:l.length}`),(0,s.displayBundles)(l)}))},621: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.login=void 0;const i=n(304),r=n(147),a=n(37),s=n(880);o.login=(e,o)=>t(void 0,void 0,void 0,(function*(){const{local:n}=o,t=(0,s.useLogSnag)();if(n)(0,r.existsSync)(".git")||i.program.error("To use local you should be in a git repository"),(0,r.writeFileSync)(".capgo",`${e}\n`),(0,r.appendFileSync)(".gitignore",".capgo\n");else{const o=(0,a.homedir)();(0,r.writeFileSync)(`${o}/.capgo`,`${e}\n`)}const p=(0,s.createSupabaseClient)(e),d=yield(0,s.verifyUser)(p,e,["write","all","upload"]);t.publish({channel:"user-login",event:"User CLI login",icon:"✅",tags:{"user-id":d},notify:!1}).catch(),console.log(`login saved into .capgo file in ${n?"local":"home"} directory`)}))},331: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((t=t.apply(e,o||[])).next())}))};Object.defineProperty(o,"__esModule",{value:!0}),o.setChannel=void 0;const i=n(304),r=n(880);o.setChannel=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,a;const{bundle:s,latest:p,downgrade:d,upgrade:c,ios:l,android:u,selfAssign:y,channel:g,state:v}=o,f=o.apikey||(0,r.findSavedKey)(),h=yield(0,r.getConfig)(),m=(0,r.useLogSnag)();e=e||(null===(n=null==h?void 0:h.app)||void 0===n?void 0:n.appId),f||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"),g||i.program.error("Missing argument, you need to provide a channel"),p&&s&&i.program.error("Cannot set latest and bundle at the same time"),void 0===s&&void 0===v&&void 0===p&&void 0===d&&void 0===c&&void 0===l&&void 0===u&&void 0===y&&i.program.error("Missing argument, you need to provide a option to set");try{const o=(0,r.createSupabaseClient)(f),n=yield(0,r.verifyUser)(o,f,["write","all"]);yield(0,r.checkPlanValid)(o,n);const b={created_by:n,app_id:e,name:g,version:-1},_=p?null===(a=null===(t=null==h?void 0:h.app)||void 0===t?void 0:t.package)||void 0===a?void 0:a.version:s;if(_){const{data:t,error:r}=yield o.from("app_versions").select().eq("app_id",e).eq("name",_).eq("user_id",n).eq("deleted",!1).single();!r&&t||i.program.error(`Cannot find version ${_}`),console.log(`Set ${e} channel: ${g} to @${s}`),b.version=t.id}void 0!==v&&("public"!==v&&"private"!==v||console.log(`Set ${e} channel: ${g} to public or private is deprecated, use default or normal instead`),console.log(`Set ${e} channel: ${g} to ${"public"===v||"default"===v?"default":"normal"}`),b.public="public"===v||"default"===v),void 0!==d&&(console.log(`Set ${e} channel: ${g} to ${d?"allow":"disallow"} downgrade`),b.disableAutoUpdateUnderNative=!d),void 0!==c&&(console.log(`Set ${e} channel: ${g} to ${c?"allow":"disallow"} upgrade`),b.disableAutoUpdateToMajor=!c),void 0!==l&&(console.log(`Set ${e} channel: ${g} to ${l?"allow":"disallow"} ios update`),b.ios=!!l),void 0!==u&&(console.log(`Set ${e} channel: ${g} to ${u?"allow":"disallow"} android update`),b.android=!!u),void 0!==y&&(console.log(`Set ${e} channel: ${g} to ${y?"allow":"disallow"} self assign to this channel`),b.allow_device_self_set=!!y);try{const{error:e}=yield(0,r.updateOrCreateChannel)(o,b,f);e&&i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}catch(e){i.program.error(`Cannot set channel ${(0,r.formatError)(e)}`)}m.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 ✅")}))},510: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((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(663),p=i(n(295)),d=n(147),c=n(906),l=n(113),u=n(880);o.uploadVersion=(e,o)=>t(void 0,void 0,void 0,(function*(){var n,t,i,y;let{bundle:g,path:v,channel:f}=o;const{external:h,key:m=!1}=o,b=o.apikey||(0,u.findSavedKey)(),_=(0,u.useLogSnag)();f=f||"dev";const k=yield(0,u.getConfig)();e=e||(null===(n=null==k?void 0:k.app)||void 0===n?void 0:n.appId),g=g||(null===(i=null===(t=null==k?void 0:k.app)||void 0===t?void 0:t.package)||void 0===i?void 0:i.version),u.regexSemver.test(g)||a.program.error(`Your bundle name ${g}, is not valid it should follow semver convention : https://semver.org/`),v=v||(null===(y=null==k?void 0:k.app)||void 0===y?void 0:y.webDir),b||a.program.error("Missing API key, you need to provide a API key to add your app"),e&&g&&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}@${g} started from path "${v}" to Capgo cloud`);const w=(0,u.createSupabaseClient)(b),$=yield(0,u.verifyUser)(w,b,["write","all","upload"]);yield(0,u.checkPlanValid)(w,$,!1);const x=new p.default.MultiBar({clearOnComplete:!1,hideCursor:!0},p.default.Presets.shades_grey),S=x.create(7,0,{format:"Uploading: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} Part"},p.default.Presets.shades_grey);S.start(7,0,{speed:"N/A"});const{data:C,error:A}=yield w.rpc("exist_app_versions",{apikey:b,name_version:g,appid:e}).single();(C||A)&&(x.stop(),a.program.error(`This app bundle already exist or was deleted, you cannot re-upload it ${(0,u.formatError)(A)}`)),S.increment();const{data:P,error:D}=yield w.rpc("is_trial",{userid:$}).single();(P&&P>0||D)&&x.log(`WARNING !!\nTrial expires in ${P} days, upgrade here: ${u.hostWeb}/dashboard/settings/plans\n`),S.increment();const{data:K,error:q}=yield w.rpc("exist_app",{appid:e,apikey:b}).single();K&&!q||(x.stop(),a.program.error(`Cannot find app ${e} in your account \n${(0,u.formatError)(q)}`)),S.increment();const{data:j,error:I}=yield w.rpc("exist_app_versions",{appid:e,apikey:b,name_version:g}).single();(j||I)&&a.program.error(`Version already exists ${(0,u.formatError)(I)}`),S.increment();const U=(0,s.randomUUID)();let E,M="";if(h)h&&!h.startsWith("https://")&&(x.stop(),a.program.error(`External link should should start with "https://" current is "${h}"`));else{const o=new r.default;o.addLocalFolder(v);let n=o.toBuffer();if(M=yield(0,c.checksum)(n,"crc32"),m||(0,d.existsSync)(u.baseKeyPub)){const e="string"==typeof m?m:u.baseKeyPub;(0,d.existsSync)(e)||a.program.error(`Cannot find public key ${e}`);const o=(0,d.readFileSync)(e);x.log("Encrypting your bundle\n");const t=(0,l.encryptSource)(n,o.toString());E=t.ivSessionKey,n=t.encryptedData}const t=Math.floor(n.byteLength/1024/1024),i=`apps/${$}/${e}/versions`;S.increment(),t>20&&(x.log(`WARNING !!\nThe app size is ${t} Mb, this may take a while to download for users\n`),_.publish({channel:"app-error",event:"App Too Large",icon:"🚛",tags:{"user-id":$,"app-id":e},notify:!1}).catch());const{error:s}=yield w.storage.from(i).upload(U,n,{contentType:"application/zip"});s&&(x.stop(),a.program.error(`Cannot upload ${(0,u.formatError)(s)}`))}S.increment();const{data:O,error:V}=yield(0,u.updateOrCreateVersion)(w,{bucket_id:h?void 0:U,user_id:$,name:g,app_id:e,session_key:E,external_url:h,checksum:M},b);if(V&&(x.stop(),a.program.error(`Cannot add bundle ${(0,u.formatError)(V)}`)),S.increment(),O){const{error:o}=yield(0,u.updateOrCreateChannel)(w,{name:f,app_id:e,created_by:$,version:O.id},b);o&&x.log("Cannot set bundle with upload key, use key with more rights for that\n")}else x.log("Cannot set bundle with upload key, use key with more rights for that\n");x.stop();const N=(0,u.convertAppName)(e);console.log("App uploaded to server"),console.log(`Try it in mobile app: ${u.host}/app_mobile`),console.log(`Or set the channel ${f} as public here: ${u.hostWeb}/app/package/${N}`),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: ${u.hostWeb}/app/p/${N}/devices`),_.publish({channel:"app",event:"App Uploaded",icon:"⏫",tags:{"user-id":$,"app-id":e},notify:!1}).catch()}))},880: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{p(t.next(e))}catch(e){r(e)}}function s(e){try{p(t.throw(e))}catch(e){r(e)}}function p(e){var o;e.done?i(e.value):(o=e.value,o instanceof n?o:new n((function(e){e(o)}))).then(a,s)}p((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.convertAppName=o.useLogSnag=o.updateOrCreateChannel=o.updateOrCreateVersion=o.getConfig=o.formatError=o.findSavedKey=o.checkPlanValid=o.isAllowedAction=o.isTrial=o.isPaying=o.isGoodPlan=o.checkKey=o.regexSemver=o.createSupabaseClient=o.supaAnon=o.hostSupa=o.hostWeb=o.host=o.baseKeyPub=o.baseKey=void 0;const r=n(778),a=n(304),s=n(885),p=i(n(867)),d=n(147),c=n(37),l=n(133);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.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNzgwNTAwOSwiZXhwIjoxOTUzMzgxMDA5fQ.8tgID1d4jodPwuo_fz4KHN4o1XKB9fnqyt0_GaJSj-w",o.createSupabaseClient=e=>(0,s.createClient)(o.hostSupa,o.supaAnon,{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,i)=>t(void 0,void 0,void 0,(function*(){const{data:t,error:r}=yield e.rpc("is_allowed_capgkey",{apikey:n,keymode:i}).single();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.isAllowedAction=(e,o)=>t(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,n,i=!0)=>t(void 0,void 0,void 0,(function*(){(yield(0,o.isAllowedAction)(e,n))||a.program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`);const t=yield(0,o.isTrial)(e,n);t>0&&i&&console.log(`WARNING !!\nTrial expires in ${t} days, upgrade here: ${o.hostWeb}/dashboard/settings/plans\n`)})),o.findSavedKey=()=>{let e=`${(0,c.homedir)()}/.capgo`;return(0,d.existsSync)(e)?(console.log(`Use global apy key ${e}`),(0,d.readFileSync)(e,"utf8").trim()):(e=".capgo",(0,d.existsSync)(e)?(console.log(`Use local apy key ${e}`),(0,d.readFileSync)(e,"utf8").trim()):null)},o.formatError=e=>e?`\n${p.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}).single();return t&&!i?(o.deleted=!1,e.from("app_versions").update(o).eq("app_id",o.app_id).eq("name",o.name).single()):e.from("app_versions").insert(o).select().single()})),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}).single();return t&&!i?e.from("channels").update(o).eq("app_id",o.app_id).eq("name",o.name).eq("created_by",o.created_by).single():e.from("channels").insert(o).select().single()})),o.useLogSnag=()=>new l.LogSnag({token:"c124f5e9d0ce5bdd14bbb48f815d5583",project:"capgo"}),o.convertAppName=e=>e.replace(/\./g,"--"),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}).single(),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")},847:e=>{e.exports=require("console-table-printer")},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")},663: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":"2.3.9","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","test":"npx --yes ts-node -T src/bin/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":"4.6.0","@supabase/supabase-js":"^2.1.2","@tomasklaen/checksum":"^1.1.0","adm-zip":"^0.5.9","cli-progress":"3.11.2","commander":"9.4.1","console-table-printer":"^2.11.1","fs-extra":"11.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.45.0","@typescript-eslint/parser":"5.45.0","eslint":"8.29.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.8.0","ts-loader":"^9.4.1","ts-node":"^10.9.1","tsconfig-paths":"4.1.1","typescript":"4.9.3","webpack":"5.75.0","webpack-cli":"^5.0.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}(731)})();
|
package/package.json
CHANGED
package/src/api/app.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
2
|
import { program } from 'commander';
|
|
3
|
+
import { Database } from 'types/supabase.types';
|
|
3
4
|
|
|
4
|
-
export const checkAppExistsAndHasPermission = async (supabase: SupabaseClient
|
|
5
|
+
export const checkAppExistsAndHasPermission = async (supabase: SupabaseClient<Database>, appid: string, apikey: string) => {
|
|
5
6
|
const { data: app, error: dbError0 } = await supabase
|
|
6
7
|
.rpc('exist_app', { appid, apikey })
|
|
7
8
|
.single();
|
package/src/api/channels.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Database } from 'types/supabase.types';
|
|
|
4
4
|
// import { definitions } from '../types/types_supabase';
|
|
5
5
|
import { convertAppName, formatError } from '../bin/utils';
|
|
6
6
|
|
|
7
|
-
export const checkVersionNotUsedInChannel = async (supabase: SupabaseClient
|
|
7
|
+
export const checkVersionNotUsedInChannel = async (supabase: SupabaseClient<Database>,
|
|
8
8
|
appid: string, userId: string, versionData: Database['public']['Tables']['app_versions']['Row'], bundle: string) => {
|
|
9
9
|
const { data: channelFound, error: errorChannel } = await supabase
|
|
10
10
|
.from('channels')
|
|
@@ -12,11 +12,12 @@ export const checkVersionNotUsedInChannel = async (supabase: SupabaseClient,
|
|
|
12
12
|
.eq('app_id', appid)
|
|
13
13
|
.eq('created_by', userId)
|
|
14
14
|
.eq('version', versionData.id)
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
if (errorChannel)
|
|
16
|
+
program.error(`Cannot check Version ${appid}@${bundle} ${formatError(errorChannel)}`);
|
|
17
|
+
if (channelFound && channelFound.length > 0) {
|
|
17
18
|
const appidWeb = convertAppName(appid)
|
|
18
|
-
program.error(
|
|
19
|
-
https://web.capgo.app/app/p/${appidWeb}/channel/${channelFound.id}
|
|
19
|
+
program.error(`❌ Version ${appid}@${bundle} is used in a channel, unlink it first
|
|
20
|
+
https://web.capgo.app/app/p/${appidWeb}/channel/${channelFound[0].id}
|
|
20
21
|
${formatError(errorChannel)}`);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -3,18 +3,19 @@ import { program } from 'commander';
|
|
|
3
3
|
import { Database } from 'types/supabase.types';
|
|
4
4
|
import { convertAppName, formatError } from '../bin/utils';
|
|
5
5
|
|
|
6
|
-
export const checkVersionNotUsedInDeviceOverride = async (supabase: SupabaseClient
|
|
6
|
+
export const checkVersionNotUsedInDeviceOverride = async (supabase: SupabaseClient<Database>,
|
|
7
7
|
appid: string, versionData: Database['public']['Tables']['app_versions']['Row'], bundle: string) => {
|
|
8
8
|
const { data: deviceFound, error: errorDevice } = await supabase
|
|
9
9
|
.from('devices_override')
|
|
10
10
|
.select()
|
|
11
11
|
.eq('app_id', appid)
|
|
12
12
|
.eq('version', versionData.id)
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
if (errorDevice)
|
|
14
|
+
program.error(`Cannot check Device override ${appid}@${bundle} ${formatError(errorDevice)}`);
|
|
15
|
+
if (deviceFound && deviceFound.length > 0) {
|
|
15
16
|
const appidWeb = convertAppName(appid)
|
|
16
|
-
program.error(
|
|
17
|
-
https://web.capgo.app/app/p/${appidWeb}/d/${deviceFound.device_id}
|
|
17
|
+
program.error(`❌ Version ${appid} @${bundle} is used in a device override, unlink it first
|
|
18
|
+
https://web.capgo.app/app/p/${appidWeb}/d/${deviceFound[0].device_id}
|
|
18
19
|
${formatError(errorDevice)}`);
|
|
19
20
|
}
|
|
20
21
|
}
|
package/src/api/storage.ts
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
2
|
import { program } from 'commander';
|
|
3
|
+
import { Database } from 'types/supabase.types';
|
|
3
4
|
import { formatError } from '../bin/utils';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
created_at?: string;
|
|
8
|
-
app_id: string;
|
|
9
|
-
name: string;
|
|
10
|
-
bucket_id?: string;
|
|
11
|
-
user_id: string;
|
|
12
|
-
updated_at?: string;
|
|
13
|
-
deleted: boolean;
|
|
14
|
-
external_url?: string;
|
|
15
|
-
checksum?: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const deleteFromStorage = async (supabase: SupabaseClient,
|
|
19
|
-
userId: string, appid: string, versionData: VersionData, bundle: string) => {
|
|
6
|
+
export const deleteFromStorage = async (supabase: SupabaseClient<Database>,
|
|
7
|
+
userId: string, appid: string, versionData: Database['public']['Tables']['app_versions']['Row'], bundle: string) => {
|
|
20
8
|
const { error: delError } = await supabase
|
|
21
9
|
.storage
|
|
22
10
|
.from('apps')
|
package/src/api/versions.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { checkVersionNotUsedInChannel } from './channels';
|
|
|
8
8
|
import { checkVersionNotUsedInDeviceOverride } from './devices_override';
|
|
9
9
|
import { deleteFromStorage } from './storage';
|
|
10
10
|
|
|
11
|
-
export const deleteAppVersion = async (supabase: SupabaseClient
|
|
11
|
+
export const deleteAppVersion = async (supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) => {
|
|
12
12
|
const { error: delAppSpecVersionError } = await supabase
|
|
13
13
|
.from('app_versions')
|
|
14
14
|
.update({
|
|
@@ -22,7 +22,7 @@ export const deleteAppVersion = async (supabase: SupabaseClient, appid: string,
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const deleteSpecificVersion = async (supabase: SupabaseClient
|
|
25
|
+
export const deleteSpecificVersion = async (supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) => {
|
|
26
26
|
const versionData = await getVersionData(supabase, appid, userId, bundle);
|
|
27
27
|
await checkVersionNotUsedInChannel(supabase, appid, userId, versionData, bundle);
|
|
28
28
|
await checkVersionNotUsedInDeviceOverride(supabase, appid, versionData, bundle);
|
|
@@ -50,14 +50,14 @@ export const displayBundles = (data: (Database['public']['Tables']['app_versions
|
|
|
50
50
|
p.printTable();
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export const getActiveAppVersions = async (supabase: SupabaseClient
|
|
53
|
+
export const getActiveAppVersions = async (supabase: SupabaseClient<Database>, appid: string, userId: string) => {
|
|
54
54
|
const { data, error: vError } = await supabase
|
|
55
55
|
.from('app_versions')
|
|
56
56
|
.select()
|
|
57
57
|
.eq('app_id', appid)
|
|
58
58
|
.eq('user_id', userId)
|
|
59
59
|
.eq('deleted', false)
|
|
60
|
-
.order('
|
|
60
|
+
.order('created_at', { ascending: false });
|
|
61
61
|
|
|
62
62
|
if (vError) {
|
|
63
63
|
program.error(`App ${appid} not found in database ${formatError(vError)} `);
|
|
@@ -65,7 +65,7 @@ export const getActiveAppVersions = async (supabase: SupabaseClient, appid: stri
|
|
|
65
65
|
return data;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export const getVersionData = async (supabase: SupabaseClient
|
|
68
|
+
export const getVersionData = async (supabase: SupabaseClient<Database>, appid: string, userId: string, bundle: string) => {
|
|
69
69
|
const { data: versionData, error: versionIdError } = await supabase
|
|
70
70
|
.from('app_versions')
|
|
71
71
|
.select()
|
package/src/bin/add.ts
CHANGED
|
@@ -3,7 +3,10 @@ import { randomUUID } from 'crypto';
|
|
|
3
3
|
import { readFileSync } from 'fs';
|
|
4
4
|
import { existsSync } from 'fs-extra';
|
|
5
5
|
import { getType } from 'mime';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
getConfig, createSupabaseClient,
|
|
8
|
+
formatError, findSavedKey, checkPlanValid, useLogSnag, verifyUser
|
|
9
|
+
} from './utils';
|
|
7
10
|
|
|
8
11
|
interface Options {
|
|
9
12
|
apikey: string;
|
package/src/bin/cleanup.ts
CHANGED
|
@@ -19,7 +19,8 @@ interface Options {
|
|
|
19
19
|
const prompt = promptSync();
|
|
20
20
|
|
|
21
21
|
const removeVersions = (toRemove: Database['public']['Tables']['app_versions']['Row'][],
|
|
22
|
-
supabase: SupabaseClient
|
|
22
|
+
supabase: SupabaseClient<Database>, appid: string, userId: string) => {
|
|
23
|
+
|
|
23
24
|
toRemove?.forEach(row => {
|
|
24
25
|
console.log(`Removing ${row.name} created on ${(getHumanDate(row))}`);
|
|
25
26
|
deleteSpecificVersion(supabase, appid, userId, row.name);
|
|
@@ -73,8 +74,8 @@ export const cleanupApp = async (appid: string, options: Options) => {
|
|
|
73
74
|
console.log(`Querying available versions in Capgo between ${bundle} and ${nextMajor}`);
|
|
74
75
|
|
|
75
76
|
// Get all app versions that are in the given range
|
|
76
|
-
allVersions = getRemovableVersionsInSemverRange(allVersions, bundle,
|
|
77
|
-
|
|
77
|
+
allVersions = getRemovableVersionsInSemverRange(allVersions, bundle,
|
|
78
|
+
nextMajor) as (Database['public']['Tables']['app_versions']['Row'] & { keep: string })[];
|
|
78
79
|
|
|
79
80
|
console.log(`Active versions in Capgo between ${bundle} and ${nextMajor}: ${allVersions?.length}`);
|
|
80
81
|
}
|
|
@@ -100,7 +101,7 @@ export const cleanupApp = async (appid: string, options: Options) => {
|
|
|
100
101
|
|
|
101
102
|
// Check user wants to clean that all up
|
|
102
103
|
if (!force) {
|
|
103
|
-
const result = prompt("Do you want to continue removing the versions specified? Type yes to confirm");
|
|
104
|
+
const result = prompt("Do you want to continue removing the versions specified? Type yes to confirm: ");
|
|
104
105
|
if (result !== "yes") {
|
|
105
106
|
console.log("Not confirmed, aborting removal...");
|
|
106
107
|
return;
|
package/src/bin/set.ts
CHANGED
|
@@ -32,6 +32,9 @@ export const setChannel = async (appid: string, options: Options) => {
|
|
|
32
32
|
if (!appid) {
|
|
33
33
|
program.error("Missing argument, you need to provide a appid, or be in a capacitor project");
|
|
34
34
|
}
|
|
35
|
+
if (!channel) {
|
|
36
|
+
program.error("Missing argument, you need to provide a channel");
|
|
37
|
+
}
|
|
35
38
|
if (latest && bundle) {
|
|
36
39
|
program.error("Cannot set latest and bundle at the same time");
|
|
37
40
|
}
|
|
@@ -49,10 +52,11 @@ export const setChannel = async (appid: string, options: Options) => {
|
|
|
49
52
|
const supabase = createSupabaseClient(apikey)
|
|
50
53
|
const userId = await verifyUser(supabase, apikey, ['write', 'all']);
|
|
51
54
|
await checkPlanValid(supabase, userId)
|
|
52
|
-
const channelPayload:
|
|
55
|
+
const channelPayload: Database['public']['Tables']['channels']['Insert'] = {
|
|
53
56
|
created_by: userId,
|
|
54
57
|
app_id: appid,
|
|
55
58
|
name: channel,
|
|
59
|
+
version: -1,
|
|
56
60
|
}
|
|
57
61
|
const bundleVersion = latest ? config?.app?.package?.version : bundle
|
|
58
62
|
if (bundleVersion) {
|
|
@@ -63,10 +67,11 @@ export const setChannel = async (appid: string, options: Options) => {
|
|
|
63
67
|
.eq('name', bundleVersion)
|
|
64
68
|
.eq('user_id', userId)
|
|
65
69
|
.eq('deleted', false)
|
|
66
|
-
|
|
70
|
+
.single()
|
|
71
|
+
if (vError || !data)
|
|
67
72
|
program.error(`Cannot find version ${bundleVersion}`);
|
|
68
73
|
console.log(`Set ${appid} channel: ${channel} to @${bundle}`);
|
|
69
|
-
channelPayload.version = data
|
|
74
|
+
channelPayload.version = data.id
|
|
70
75
|
}
|
|
71
76
|
if (state !== undefined) {
|
|
72
77
|
if (state === 'public' || state === 'private') {
|
package/src/bin/upload.ts
CHANGED
|
@@ -165,12 +165,12 @@ export const uploadVersion = async (appid: string, options: Options) => {
|
|
|
165
165
|
program.error(`Cannot add bundle ${formatError(dbError)}`)
|
|
166
166
|
}
|
|
167
167
|
b1.increment();
|
|
168
|
-
if (versionData
|
|
168
|
+
if (versionData) {
|
|
169
169
|
const { error: dbError3 } = await updateOrCreateChannel(supabase, {
|
|
170
170
|
name: channel,
|
|
171
171
|
app_id: appid,
|
|
172
172
|
created_by: userId,
|
|
173
|
-
version: versionData
|
|
173
|
+
version: versionData.id,
|
|
174
174
|
}, apikey)
|
|
175
175
|
if (dbError3) {
|
|
176
176
|
multibar.log('Cannot set bundle with upload key, use key with more rights for that\n');
|
package/src/bin/utils.ts
CHANGED
|
@@ -33,7 +33,8 @@ export const createSupabaseClient = (apikey: string) => createClient<Database>(h
|
|
|
33
33
|
// eslint-disable-next-line max-len
|
|
34
34
|
export const 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-]+)*))?$/
|
|
35
35
|
|
|
36
|
-
export const checkKey = async (supabase: SupabaseClient
|
|
36
|
+
export const checkKey = async (supabase: SupabaseClient<Database>, apikey: string,
|
|
37
|
+
keymode: Database['public']['Enums']['key_mode'][]) => {
|
|
37
38
|
const { data: apiAccess, error: apiAccessError } = await supabase
|
|
38
39
|
.rpc('is_allowed_capgkey', { apikey, keymode })
|
|
39
40
|
.single()
|
|
@@ -43,7 +44,7 @@ export const checkKey = async (supabase: SupabaseClient, apikey: string, keymode
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
export const isGoodPlan = async (supabase: SupabaseClient
|
|
47
|
+
export const isGoodPlan = async (supabase: SupabaseClient<Database>, userId: string): Promise<boolean> => {
|
|
47
48
|
const { data, error } = await supabase
|
|
48
49
|
.rpc('is_good_plan_v2', { userid: userId })
|
|
49
50
|
.single()
|
|
@@ -53,7 +54,7 @@ export const isGoodPlan = async (supabase: SupabaseClient, userId: string): Prom
|
|
|
53
54
|
return data || false
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
export const isPaying = async (supabase: SupabaseClient
|
|
57
|
+
export const isPaying = async (supabase: SupabaseClient<Database>, userId: string): Promise<boolean> => {
|
|
57
58
|
const { data, error } = await supabase
|
|
58
59
|
.rpc('is_paying', { userid: userId })
|
|
59
60
|
.single()
|
|
@@ -63,7 +64,7 @@ export const isPaying = async (supabase: SupabaseClient, userId: string): Promis
|
|
|
63
64
|
return data || false
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
export const isTrial = async (supabase: SupabaseClient
|
|
67
|
+
export const isTrial = async (supabase: SupabaseClient<Database>, userId: string): Promise<number> => {
|
|
67
68
|
const { data, error } = await supabase
|
|
68
69
|
.rpc('is_trial', { userid: userId })
|
|
69
70
|
.single()
|
|
@@ -73,7 +74,7 @@ export const isTrial = async (supabase: SupabaseClient, userId: string): Promise
|
|
|
73
74
|
return data || 0
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
export const isAllowedAction = async (supabase: SupabaseClient
|
|
77
|
+
export const isAllowedAction = async (supabase: SupabaseClient<Database>, userId: string): Promise<boolean> => {
|
|
77
78
|
const { data, error } = await supabase
|
|
78
79
|
.rpc('is_allowed_action_user', { userid: userId })
|
|
79
80
|
.single()
|
|
@@ -83,7 +84,7 @@ export const isAllowedAction = async (supabase: SupabaseClient, userId: string):
|
|
|
83
84
|
return data
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
export const checkPlanValid = async (supabase: SupabaseClient
|
|
87
|
+
export const checkPlanValid = async (supabase: SupabaseClient<Database>, userId: string, warning = true) => {
|
|
87
88
|
const validPlan = await isAllowedAction(supabase, userId)
|
|
88
89
|
if (!validPlan) {
|
|
89
90
|
program.error(`You need to upgrade your plan to continue to use capgo.\n Upgrade here: ${hostWeb}/dashboard/settings/plans\n`);
|
|
@@ -136,8 +137,8 @@ export const getConfig = async () => {
|
|
|
136
137
|
return config;
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
export const updateOrCreateVersion = async (supabase: SupabaseClient
|
|
140
|
-
update:
|
|
140
|
+
export const updateOrCreateVersion = async (supabase: SupabaseClient<Database>,
|
|
141
|
+
update: Database['public']['Tables']['app_versions']['Insert'], apikey: string) => {
|
|
141
142
|
// console.log('updateOrCreateVersion', update, apikey)
|
|
142
143
|
const { data, error } = await supabase
|
|
143
144
|
.rpc('exist_app_versions', { appid: update.app_id, name_version: update.name, apikey })
|
|
@@ -161,8 +162,8 @@ export const updateOrCreateVersion = async (supabase: SupabaseClient,
|
|
|
161
162
|
.single()
|
|
162
163
|
}
|
|
163
164
|
|
|
164
|
-
export const updateOrCreateChannel = async (supabase: SupabaseClient
|
|
165
|
-
update:
|
|
165
|
+
export const updateOrCreateChannel = async (supabase: SupabaseClient<Database>,
|
|
166
|
+
update: Database['public']['Tables']['channels']['Insert'], apikey: string) => {
|
|
166
167
|
// console.log('updateOrCreateChannel', update)
|
|
167
168
|
if (!update.app_id || !update.name || !update.created_by) {
|
|
168
169
|
console.error('missing app_id, name, or created_by')
|
|
@@ -200,7 +201,8 @@ export const useLogSnag = (): LogSnag => {
|
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
export const convertAppName = (appName: string) => appName.replace(/\./g, '--')
|
|
203
|
-
export const verifyUser = async (supabase: SupabaseClient
|
|
204
|
+
export const verifyUser = async (supabase: SupabaseClient<Database>, apikey: string,
|
|
205
|
+
keymod: Database['public']['Enums']['key_mode'][] = ['all']) => {
|
|
204
206
|
await checkKey(supabase, apikey, keymod);
|
|
205
207
|
|
|
206
208
|
const { data: dataUser, error: userIdError } = await supabase
|