blixify-server 0.1.46 → 0.1.48

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.
@@ -1 +1 @@
1
- {"version":3,"file":"fbWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/fbWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAEhB,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU;IAUjB,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCA4E5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA6CtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAoItC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAkFtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAwH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA4CtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAkNlC;IAEF,IAAI,YA+EF;CACH"}
1
+ {"version":3,"file":"fbWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/fbWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAEhB,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU;IAUjB,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCA4E5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA6CtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAoItC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAkFtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAwH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA4CtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAoPlC;IAEF,IAAI,YA+EF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,a,d,n){return new(d=d||Promise)(function(i,t){function s(e){try{r(n.next(e))}catch(e){t(e)}}function o(e){try{r(n.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,o)}r((n=n.apply(e,a||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirebaseWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel"),utils_1=require("./utils");class FirebaseWrapper{constructor(e,t,i,s,o,r){this.fbAdmin="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.parseModel=e=>(delete e.id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(l,c,u)=>__awaiter(this,void 0,void 0,function*(){try{const o=this.fbAdmin.firestore().batch(),r=this.fbAdmin.firestore().collection(this.collection);if(Array.isArray(l.body.data)){let t=!0;if(l.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=l.body.data,i=(0,QueryModel_1.checkBaseConfig)(this.config,l);let t=!0;const a=[],d=[];if(e.map(e=>{a.push(e.id),(0,QueryModel_1.checkOpsConfig)(this.config,"update",l,e)||(t=!1),l.body.unique&&null!=e&&e[l.body.unique]&&d.push(null==e?void 0:e[l.body.unique])}),i&&t){if(0<d.length){var s=yield r.find(l.body.unique,"in",d).get();const n=[];if(s.empty||s.forEach(e=>{e=e.data();n.push(e)}),0<n.length)return void c.status(400).json({err:`Unique:${n.map(e=>null==e?void 0:e[l.body.unique])} exists`})}u&&(yield u(e)),yield Promise.all(e.map(t=>__awaiter(this,void 0,void 0,function*(){t.baseUpdatedAt=(0,moment_1.default)().toDate();var e=r.doc(t.id);o.set(e,Object.assign({},t))}))),yield o.commit(),c.send({success:a})}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Model Structure"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initCreate=(r,a,d)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(r.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"create",r,r.body.data);if(i&&s){var o=this.fbAdmin.firestore().collection(this.collection);if(r.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),r.body.unique&&null!=(e=r.body.data)&&e[r.body.unique])if(!(yield o.where(r.body.unique,"==",null==(t=r.body.data)?void 0:t[r.body.unique]).get()).empty)return void a.status(400).json({err:`Unique:${r.body.data[r.body.unique]} exists`});d&&(yield d(r.body.data)),yield o.doc(r.body.data.id).set(r.body.data),a.send({success:!0})}else a.status(400).json({err:"Invalid Security Configuration"})}else a.status(400).json({err:"Invalid Model Structure"})}catch(e){a.status(400).json({err:e})}}),this.initGet=(r,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=r.body.id;o?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(o).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",r,t),i)&&s?a.send({data:t}):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initBatchUpdate=(b,m,p)=>__awaiter(this,void 0,void 0,function*(){var e,t;const s=this.fbAdmin.firestore().batch();try{var i=this.modelChecker(b.body.data)&&b.body.query,o=this.parseModel(null!=(e=b.body.data)?e:[]),r=null!=(t=b.body.query)?t:[],a=b.body.isOr||!1,d=b.body.unsetData;if(i){var n=this.fbAdmin.firestore().collection(this.collection);const h=[];r.forEach(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"=":h.push(this.fbAdmin.firestore.Filter.where(i,"==",s));break;case"!=":h.push(this.fbAdmin.firestore.Filter.where(i,"!=",s));break;case">":h.push(this.fbAdmin.firestore.Filter.where(i,">",s));break;case"<":h.push(this.fbAdmin.firestore.Filter.where(i,"<",s));break;case"><":Array.isArray(s)&&2<=s.length&&h.push(this.fbAdmin.firestore.Filter.where(i,">=",s[0]),this.fbAdmin.firestore.Filter.where(i,"<=",s[1]));break;case"in":h.push(this.fbAdmin.firestore.Filter.where(i,"in",s))}});var l=a?this.fbAdmin.firestore.Filter.or(...h):this.fbAdmin.firestore.Filter.and(...h),c=yield n.where(l).get(),u=(0,QueryModel_1.checkBaseConfig)(this.config,b);let i=!0;const f=[],y=[];if(c&&c.forEach(e=>{var t=e.data(),t=(y.push(t.id),!b.body.sensitive||(0,moment_1.default)(b.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))||m.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",b,t)||(i=!1),(0,utils_1.compareUpdatedFields)(e,b.body.data))["workflowUpdateFields"];f.concat(t)}),u&&i){let t={};d&&d.forEach(e=>{t[e]=this.fbAdmin.firestore.FieldValue.delete()}),o&&(t=Object.assign(Object.assign({},o),t)),p&&(yield p(f)),yield Promise.all(y.map(e=>{e=this.fbAdmin.firestore().collection(this.collection).doc(e);s.update(e,Object.assign({},t))})),yield s.commit(),m.send({success:y})}else m.status(400).json({err:"Invalid Security Configuration"})}}catch(e){m.status(400).json({err:e})}}),this.initUpdate=(f,y,b)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=this.modelChecker(f.body.data)&&f.body.id;if(t){var i=this.fbAdmin.firestore().collection(this.collection),s=yield i.doc(t).get();if(s.exists){var o=s.data(),r=(0,QueryModel_1.checkBaseConfig)(this.config,f),a=(0,QueryModel_1.checkOpsConfig)(this.config,"update",f,o);if(r&&a){if(f.body.unique&&null!=o&&o[f.body.unique]){const h="id"===f.body.unique?f.body.id:null==(e=f.body.data)?void 0:e[f.body.unique];var d=yield i.where(f.body.unique,"==",h).get();d.empty||d.forEach(e=>{e=e.data();f.body.id!==e.id&&y.status(400).json({err:`${null!==h&&void 0!==h?h:"Unique Fields Data"} exists`})})}var n,l,{workflowUpdateFields:c,updatedFields:u}=(0,utils_1.compareUpdatedFields)(o,f.body.data);f.body.sensitive?(0,moment_1.default)(f.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*o.baseUpdatedAt.seconds))?(b&&(yield b(c)),n=this.parseModel(u),yield i.doc(t).update(Object.assign({},n)),y.send({success:!0})):y.status(400).json({err:"Refresh Sensitive Model"}):(b&&(yield b(c)),l=this.parseModel(u),yield i.doc(t).update(Object.assign({},l)),y.send({success:!0}))}else y.status(400).json({err:"Invalid Security Configuration"})}else y.status(400).json({err:"Invalid Security Configuration"})}else y.status(400).json({err:"Invalid Model Structure"})}catch(e){y.status(400).json({err:e})}}),this.initBatchDelete=(c,u,h)=>__awaiter(this,void 0,void 0,function*(){try{const d=this.fbAdmin.firestore().batch();if(Array.isArray(c.body.id)){var e=yield this.fbAdmin.firestore().collection(this.collection).where("id","in",c.body.id).get(),i=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const o=[];e&&e.forEach(e=>{e=e.data();o.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),i&&t?(h&&(yield h(o)),yield Promise.all(c.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield this.fbAdmin.firestore().collection(this.collection).doc(t);d.delete(e)}))),yield d.commit(),u.send({success:c.body.id})):u.status(400).json({err:"Invalid Security Configuration"})}else{let o=this.fbAdmin.firestore().collection(this.collection);var s=c.body.query;const n=[];s&&0<s.length&&s.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(o=o.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":o=o.where(i,"==",s);break;case"!=":o=o.where(i,"!=",s);break;case">":o=o.where(i,">",s);break;case"<":o=o.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(o=o.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":o=o.where(i,"in",s)}});var r=yield o.get(),a=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const l=[];r&&r.forEach(e=>{e=e.data();n.push(e.id),l.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),h&&(yield h(l)),a&&t?(r.forEach(e=>{d.delete(e.ref)}),yield d.commit(),u.send({success:n})):u.status(400).json({err:"Invalid Security Configuration"})}}catch(e){u.status(400).json({err:e})}}),this.initDelete=(r,a,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=r.body.id;o?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(o).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,t),i)&&s?(d&&(yield d(t)),yield this.fbAdmin.firestore().collection(this.collection).doc(o).delete(),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initList=(D,Y)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,a;try{var d=(0,QueryModel_1.checkBaseConfig)(this.config,D);if(d){var o=D.body.aggregate,n=null!=(e=D.body.query)?e:[];if(o){const C=null!=(t=o.queryId)?t:"";var r=null!=(i=o.dateId)?i:"baseUpdatedAt",l=null!=(s=o.range)?s:[],c=[];for(const j of l){let e=this.fbAdmin.firestore().collection(this.collection);var u=j.split("-"),[h,f=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=u,y=2===u.length,b=(0,moment_1.default)(h,"DD/MM/YYYY").isValid(),m=(0,moment_1.default)(f,"DD/MM/YYYY").isValid(),p=(0,moment_1.default)(h,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),v=(0,moment_1.default)(f,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!b||!m)return void Y.status(400).json({err:"Invalid Aggregate Range Configuration"});var g=y?j:"Begining until "+(0,moment_1.default)(p).format("DD/MM/YYYY");e=y?e.where(r,">=",(0,moment_1.default)(p).toDate()).where(r,"<=",(0,moment_1.default)(v).toDate()):e.where(r,"<",(0,moment_1.default)(p).toDate());let t=0;switch(o.type){case"count":var _=yield e.count().get();t=_.data().count;break;case"value":var A=yield(e=(e=e.limit(1)).orderBy(r,"desc")).get();A&&A.forEach(e=>{e=e.data(),e=JSON.parse(JSON.stringify(e));t=e[C]})}c.push({_id:g,value:t})}Y.send({data:c})}else{let o=this.fbAdmin.firestore().collection(this.collection),r="";if(n&&0<n.length&&n.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(r=e.searchIds[0],o=o.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":o=o.where(i,"==",s);break;case"!=":o=o.where(i,"!=",s);break;case">":o=o.where(i,">",s);break;case"<":o=o.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(o=o.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":o=o.where(i,"in",s)}}),D.body.stopLimit||(o=o.limit(null!=(a=D.body.limit)?a:10)),D.body.sort){var w=D.body.sort;if(r&&w.sortId!==r)return void Y.status(400).json({err:"Invalid Search Sort Configuration"});r||(o=o.orderBy(w.sortId,"asc"===w.type?"asc":"desc"))}var M,k=yield(o=D.body.cursor?o.startAfter(D.body.cursor):o).get();let t=!0;const I=[];if(k&&k.forEach(e=>{e=e.data();I.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",D,e)||(t=!1)}),d&&t){let t="";if(I.length===D.body.limit){let e="id";D.body.sort&&(M=D.body.sort,e=M.sortId),t=I[D.body.limit-1][e]}Y.send({data:I,count:t})}else Y.status(400).json({err:"Invalid Security Configuration"})}}else Y.status(400).json({err:"Invalid Security Configuration"})}catch(e){Y.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.fbAdmin=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=r}}exports.FirebaseWrapper=FirebaseWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,a,d,n){return new(d=d||Promise)(function(i,t){function s(e){try{o(n.next(e))}catch(e){t(e)}}function r(e){try{o(n.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,r)}o((n=n.apply(e,a||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirebaseWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel"),utils_1=require("./utils");class FirebaseWrapper{constructor(e,t,i,s,r,o){this.fbAdmin="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.parseModel=e=>(delete e.id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(l,c,u)=>__awaiter(this,void 0,void 0,function*(){try{const r=this.fbAdmin.firestore().batch(),o=this.fbAdmin.firestore().collection(this.collection);if(Array.isArray(l.body.data)){let t=!0;if(l.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=l.body.data,i=(0,QueryModel_1.checkBaseConfig)(this.config,l);let t=!0;const a=[],d=[];if(e.map(e=>{a.push(e.id),(0,QueryModel_1.checkOpsConfig)(this.config,"update",l,e)||(t=!1),l.body.unique&&null!=e&&e[l.body.unique]&&d.push(null==e?void 0:e[l.body.unique])}),i&&t){if(0<d.length){var s=yield o.find(l.body.unique,"in",d).get();const n=[];if(s.empty||s.forEach(e=>{e=e.data();n.push(e)}),0<n.length)return void c.status(400).json({err:`Unique:${n.map(e=>null==e?void 0:e[l.body.unique])} exists`})}u&&(yield u(e)),yield Promise.all(e.map(t=>__awaiter(this,void 0,void 0,function*(){t.baseUpdatedAt=(0,moment_1.default)().toDate();var e=o.doc(t.id);r.set(e,Object.assign({},t))}))),yield r.commit(),c.send({success:a})}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Model Structure"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initCreate=(o,a,d)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(o.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,o),s=(0,QueryModel_1.checkOpsConfig)(this.config,"create",o,o.body.data);if(i&&s){var r=this.fbAdmin.firestore().collection(this.collection);if(o.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),o.body.unique&&null!=(e=o.body.data)&&e[o.body.unique])if(!(yield r.where(o.body.unique,"==",null==(t=o.body.data)?void 0:t[o.body.unique]).get()).empty)return void a.status(400).json({err:`Unique:${o.body.data[o.body.unique]} exists`});d&&(yield d(o.body.data)),yield r.doc(o.body.data.id).set(o.body.data),a.send({success:!0})}else a.status(400).json({err:"Invalid Security Configuration"})}else a.status(400).json({err:"Invalid Model Structure"})}catch(e){a.status(400).json({err:e})}}),this.initGet=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,r=o.body.id;r?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(r).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,o),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",o,t),i)&&s?a.send({data:t}):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initBatchUpdate=(b,m,p)=>__awaiter(this,void 0,void 0,function*(){var e,t;const s=this.fbAdmin.firestore().batch();try{var i=this.modelChecker(b.body.data)&&b.body.query,r=this.parseModel(null!=(e=b.body.data)?e:[]),o=null!=(t=b.body.query)?t:[],a=b.body.isOr||!1,d=b.body.unsetData;if(i){var n=this.fbAdmin.firestore().collection(this.collection);const h=[];o.forEach(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"=":h.push(this.fbAdmin.firestore.Filter.where(i,"==",s));break;case"!=":h.push(this.fbAdmin.firestore.Filter.where(i,"!=",s));break;case">":h.push(this.fbAdmin.firestore.Filter.where(i,">",s));break;case"<":h.push(this.fbAdmin.firestore.Filter.where(i,"<",s));break;case"><":Array.isArray(s)&&2<=s.length&&h.push(this.fbAdmin.firestore.Filter.where(i,">=",s[0]),this.fbAdmin.firestore.Filter.where(i,"<=",s[1]));break;case"in":h.push(this.fbAdmin.firestore.Filter.where(i,"in",s))}});var l=a?this.fbAdmin.firestore.Filter.or(...h):this.fbAdmin.firestore.Filter.and(...h),c=yield n.where(l).get(),u=(0,QueryModel_1.checkBaseConfig)(this.config,b);let i=!0;const f=[],y=[];if(c&&c.forEach(e=>{var t=e.data(),t=(y.push(t.id),!b.body.sensitive||(0,moment_1.default)(b.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))||m.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",b,t)||(i=!1),(0,utils_1.compareUpdatedFields)(e,b.body.data))["workflowUpdateFields"];f.concat(t)}),u&&i){let t={};d&&d.forEach(e=>{t[e]=this.fbAdmin.firestore.FieldValue.delete()}),r&&(t=Object.assign(Object.assign({},r),t)),p&&(yield p(f)),yield Promise.all(y.map(e=>{e=this.fbAdmin.firestore().collection(this.collection).doc(e);s.update(e,Object.assign({},t))})),yield s.commit(),m.send({success:y})}else m.status(400).json({err:"Invalid Security Configuration"})}}catch(e){m.status(400).json({err:e})}}),this.initUpdate=(f,y,b)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=this.modelChecker(f.body.data)&&f.body.id;if(t){var i=this.fbAdmin.firestore().collection(this.collection),s=yield i.doc(t).get();if(s.exists){var r=s.data(),o=(0,QueryModel_1.checkBaseConfig)(this.config,f),a=(0,QueryModel_1.checkOpsConfig)(this.config,"update",f,r);if(o&&a){if(f.body.unique&&null!=r&&r[f.body.unique]){const h="id"===f.body.unique?f.body.id:null==(e=f.body.data)?void 0:e[f.body.unique];var d=yield i.where(f.body.unique,"==",h).get();d.empty||d.forEach(e=>{e=e.data();f.body.id!==e.id&&y.status(400).json({err:`${null!==h&&void 0!==h?h:"Unique Fields Data"} exists`})})}var n,l,{workflowUpdateFields:c,updatedFields:u}=(0,utils_1.compareUpdatedFields)(r,f.body.data);f.body.sensitive?(0,moment_1.default)(f.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*r.baseUpdatedAt.seconds))?(b&&(yield b(c)),n=this.parseModel(u),yield i.doc(t).update(Object.assign({},n)),y.send({success:!0})):y.status(400).json({err:"Refresh Sensitive Model"}):(b&&(yield b(c)),l=this.parseModel(u),yield i.doc(t).update(Object.assign({},l)),y.send({success:!0}))}else y.status(400).json({err:"Invalid Security Configuration"})}else y.status(400).json({err:"Invalid Security Configuration"})}else y.status(400).json({err:"Invalid Model Structure"})}catch(e){y.status(400).json({err:e})}}),this.initBatchDelete=(c,u,h)=>__awaiter(this,void 0,void 0,function*(){try{const d=this.fbAdmin.firestore().batch();if(Array.isArray(c.body.id)){var e=yield this.fbAdmin.firestore().collection(this.collection).where("id","in",c.body.id).get(),i=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const r=[];e&&e.forEach(e=>{e=e.data();r.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),i&&t?(h&&(yield h(r)),yield Promise.all(c.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield this.fbAdmin.firestore().collection(this.collection).doc(t);d.delete(e)}))),yield d.commit(),u.send({success:c.body.id})):u.status(400).json({err:"Invalid Security Configuration"})}else{let r=this.fbAdmin.firestore().collection(this.collection);var s=c.body.query;const n=[];s&&0<s.length&&s.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(r=r.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":r=r.where(i,"==",s);break;case"!=":r=r.where(i,"!=",s);break;case">":r=r.where(i,">",s);break;case"<":r=r.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(r=r.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":r=r.where(i,"in",s)}});var o=yield r.get(),a=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const l=[];o&&o.forEach(e=>{e=e.data();n.push(e.id),l.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),h&&(yield h(l)),a&&t?(o.forEach(e=>{d.delete(e.ref)}),yield d.commit(),u.send({success:n})):u.status(400).json({err:"Invalid Security Configuration"})}}catch(e){u.status(400).json({err:e})}}),this.initDelete=(o,a,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,r=o.body.id;r?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(r).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,o),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,t),i)&&s?(d&&(yield d(t)),yield this.fbAdmin.firestore().collection(this.collection).doc(r).delete(),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initList=(D,Y)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,a;try{var d=(0,QueryModel_1.checkBaseConfig)(this.config,D);if(d){var o=D.body.aggregate,n=null!=(e=D.body.query)?e:[];if(o){const C=null!=(t=o.queryId)?t:"";var l=null!=(i=o.dateId)?i:"baseUpdatedAt",r=null!=(s=o.range)?s:[],c=[];for(const j of r){let r=this.fbAdmin.firestore().collection(this.collection);n&&0<n.length&&n.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"=":r=r.where(i,"==",s);break;case"!=":r=r.where(i,"!=",s);break;case">":r=r.where(i,">",s);break;case"<":r=r.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(r=r.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":r=r.where(i,"in",s)}});var u=j.split("-"),[h,f=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=u,y=2===u.length,b=(0,moment_1.default)(h,"DD/MM/YYYY").isValid(),m=(0,moment_1.default)(f,"DD/MM/YYYY").isValid(),p=(0,moment_1.default)(h,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),v=(0,moment_1.default)(f,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!b||!m)return void Y.status(400).json({err:"Invalid Aggregate Range Configuration"});var g=y?j:"Begining until "+(0,moment_1.default)(p).format("DD/MM/YYYY");r=y?r.where(l,">=",(0,moment_1.default)(p).toDate()).where(l,"<=",(0,moment_1.default)(v).toDate()):r.where(l,"<",(0,moment_1.default)(p).toDate());let t=0;switch(o.type){case"count":var _=yield r.count().get();t=_.data().count;break;case"value":var w=yield(r=(r=r.limit(1)).orderBy(l,"desc")).get();w&&w.forEach(e=>{e=e.data(),e=JSON.parse(JSON.stringify(e));t=e[C]})}c.push({_id:g,value:t})}Y.send({data:c})}else{let r=this.fbAdmin.firestore().collection(this.collection),o="";if(n&&0<n.length&&n.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(o=e.searchIds[0],r=r.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":r=r.where(i,"==",s);break;case"!=":r=r.where(i,"!=",s);break;case">":r=r.where(i,">",s);break;case"<":r=r.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(r=r.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":r=r.where(i,"in",s)}}),D.body.stopLimit||(r=r.limit(null!=(a=D.body.limit)?a:10)),D.body.sort){var A=D.body.sort;if(o&&A.sortId!==o)return void Y.status(400).json({err:"Invalid Search Sort Configuration"});o||(r=r.orderBy(A.sortId,"asc"===A.type?"asc":"desc"))}var k,M=yield(r=D.body.cursor?r.startAfter(D.body.cursor):r).get();let t=!0;const I=[];if(M&&M.forEach(e=>{e=e.data();I.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",D,e)||(t=!1)}),d&&t){let t="";if(I.length===D.body.limit){let e="id";D.body.sort&&(k=D.body.sort,e=k.sortId),t=I[D.body.limit-1][e]}Y.send({data:I,count:t})}else Y.status(400).json({err:"Invalid Security Configuration"})}}else Y.status(400).json({err:"Invalid Security Configuration"})}catch(e){Y.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.fbAdmin=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=r,this.lib=o}}exports.FirebaseWrapper=FirebaseWrapper;
@@ -1 +1 @@
1
- {"version":3,"file":"mondayWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mondayWrapper.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,eAAO,MAAM,cAAc,UAClB,MAAM,SACN,GAAG,cACE,GAAG,qDAahB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,aAAa;IACxB,WAAW,SAAM;IACjB,OAAO,SAAM;IACb,OAAO,SAAM;IACb,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAEhB,YAAY,QAAS,GAAG,aAEtB;IACF,SAAS;cAAe,MAAM,EAAE;;;;MAK9B;gBAGA,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,SAAS,EAAE,MAAM;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE;YAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,EACpE,GAAG,EAAE,UAAU;IAWjB,UAAU,eAAgB;QACxB,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,MAAM,CAAC;QACb,aAAa,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;KAC9D,SAaC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAuDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBA4CjC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;mBAyElC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG;;mBAkFpC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBA0DtC;IAEF,IAAI,YA8CF;CACH"}
1
+ {"version":3,"file":"mondayWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mondayWrapper.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,eAAO,MAAM,cAAc,UAClB,MAAM,SACN,GAAG,cACE,GAAG,qDAchB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,aAAa;IACxB,WAAW,SAAM;IACjB,OAAO,SAAM;IACb,OAAO,SAAM;IACb,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAEhB,YAAY,QAAS,GAAG,aAEtB;IACF,SAAS;cAAe,MAAM,EAAE;;;;MAK9B;gBAGA,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,SAAS,EAAE,MAAM;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE;YAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,EACpE,GAAG,EAAE,UAAU;IAWjB,UAAU,eAAgB;QACxB,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,MAAM,CAAC;QACb,aAAa,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;KAC9D,SAaC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAuDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBA+CjC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;mBAiGlC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG;;mBAsFpC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBA8DtC;IAEF,IAAI,YA8CF;CACH"}
@@ -1,5 +1,5 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,d,r,n){return new(r=r||Promise)(function(i,t){function o(e){try{s(n.next(e))}catch(e){t(e)}}function a(e){try{s(n.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(o,a)}s((n=n.apply(e,d||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MondayWrapper=exports.queryMondayApi=void 0;const axios_1=__importDefault(require("axios")),QueryModel_1=require("../model/QueryModel"),queryMondayApi=(e,t,i)=>__awaiter(void 0,void 0,void 0,function*(){return yield axios_1.default.post("https://api.monday.com/v2",{query:t,variables:i},{headers:{"Content-Type":"application/json",Authorization:null!=e?e:""}})});exports.queryMondayApi=queryMondayApi;class MondayWrapper{constructor(e,t,i,o,a,s,d){this.mondayToken="",this.boardId="",this.groupId="",this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.modelType=()=>({read:[],write:{}}),this.parseModel=e=>{const i={id:e.id,name:e.name};return e.column_values.map(t=>{if("subitems"!==t.id){let e=!0;this.modelType().read.includes(t.id)&&(e=!1),i[t.id]=e?t.text:t.value}}),i},this.initCreate=(r,n,u)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(r.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,r),o=(0,QueryModel_1.checkOpsConfig)(this.config,"create",r,r.body.data);if(i&&o){var a=r.body.data,s=(u&&(yield u(a)),{boardId:Number(this.boardId),groupId:this.groupId,itemName:null!=(e=r.body.data.name)?e:"Item",columnValues:JSON.stringify(a)}),d={success:(yield(0,exports.queryMondayApi)(this.mondayToken,`
2
- mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,d,r,n){return new(r=r||Promise)(function(i,t){function s(e){try{o(n.next(e))}catch(e){t(e)}}function a(e){try{o(n.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,a)}o((n=n.apply(e,d||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MondayWrapper=exports.queryMondayApi=void 0;const axios_1=__importDefault(require("axios")),QueryModel_1=require("../model/QueryModel"),queryMondayApi=(e,t,i)=>__awaiter(void 0,void 0,void 0,function*(){return yield axios_1.default.post("https://api.monday.com/v2",{query:t,variables:i},{headers:{"Content-Type":"application/json",Authorization:null!=e?e:"","API-version":"2023-10"}})});exports.queryMondayApi=queryMondayApi;class MondayWrapper{constructor(e,t,i,s,a,o,d){this.mondayToken="",this.boardId="",this.groupId="",this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.modelType=()=>({read:[],write:{}}),this.parseModel=e=>{const i={id:e.id,name:e.name};return e.column_values.map(t=>{if("subitems"!==t.id){let e=!0;this.modelType().read.includes(t.id)&&(e=!1),i[t.id]=e?t.text:t.value}}),i},this.initCreate=(r,n,u)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(r.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"create",r,r.body.data);if(i&&s){var a=r.body.data,o=(u&&(yield u(a)),{boardId:this.boardId,groupId:this.groupId,itemName:null!=(e=r.body.data.name)?e:"Item",columnValues:JSON.stringify(a)}),d={success:(yield(0,exports.queryMondayApi)(this.mondayToken,`
2
+ mutation ($boardId: ID!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
3
3
  create_item (
4
4
  board_id: $boardId,
5
5
  group_id: $groupId,
@@ -9,44 +9,68 @@
9
9
  id
10
10
  }
11
11
  }
12
- `,s)).data.data.create_item.id};if(null!=(t=r.body)&&t.stopRes)return d;n.send(d)}else n.status(400).json({err:"Invalid Security Configuration"})}else n.status(400).json({err:"Invalid Model Structure"})}catch(e){n.status(400).json({err:e})}}),this.initGet=(r,n)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(r.body.id){var t=`{
13
- boards(ids: ${Number(this.boardId)}) {
14
- items(ids:${r.body.id}) {
15
- id
16
- name
17
- column_values {
12
+ `,o)).data.data.create_item.id};if(null!=(t=r.body)&&t.stopRes)return d;n.send(d)}else n.status(400).json({err:"Invalid Security Configuration"})}else n.status(400).json({err:"Invalid Model Structure"})}catch(e){n.status(400).json({err:e})}}),this.initGet=(r,n)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(r.body.id){var t=`query {
13
+ boards(ids: ${this.boardId}) {
14
+ items_page (limit: 1, query_params: {ids:${r.body.id}}) {
15
+ cursor
16
+ items {
18
17
  id
19
- text
20
- value
18
+ name
19
+ column_values {
20
+ id
21
+ text
22
+ value
23
+ }
21
24
  }
22
25
  }
23
26
  }
24
- }`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items;if(0<i.length){var o,a=this.parseModel(i[0]),s=(0,QueryModel_1.checkBaseConfig)(this.config,r),d=(0,QueryModel_1.checkOpsConfig)(this.config,"read",r,a);if(s&&d)return o={data:a},null!=(e=r.body)&&e.stopRes?o:void n.send(o);n.status(400).json({err:"Invalid Security Configuration"})}else n.send({data:null})}else n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initList=(m,h)=>__awaiter(this,void 0,void 0,function*(){var d;try{var e=(0,QueryModel_1.checkBaseConfig)(this.config,m);if(e){var r=m.body.query;let t=[],i="",o="",a="";if(m.body.limit&&(o="limit: "+m.body.limit),m.body.cursor&&(a="page : "+Number(m.body.cursor)),r&&0<r.length){var n=r[0],u=(o=o&&" , "+o,a=a&&" , "+a,i=`query {items_by_column_values (board_id: ${this.boardId}, column_id:"${n.queryId}" , column_value: "${n.value}"${o}${a}) {id name column_values {id text value}}}`,yield(0,exports.queryMondayApi)(this.mondayToken,i));t=u.data.data.items_by_column_values}else{let e="";e=o&&a?o+" , "+a:o||a,i=`query{
27
+ }`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items_page.items;if(0<i.length){var s,a=this.parseModel(i[0]),o=(0,QueryModel_1.checkBaseConfig)(this.config,r),d=(0,QueryModel_1.checkOpsConfig)(this.config,"read",r,a);if(o&&d)return s={data:a},null!=(e=r.body)&&e.stopRes?s:void n.send(s);n.status(400).json({err:"Invalid Security Configuration"})}else n.send({data:null})}else n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initList=(m,h)=>__awaiter(this,void 0,void 0,function*(){var d;try{var e=(0,QueryModel_1.checkBaseConfig)(this.config,m);if(e){var r=m.body.query;let t=[],i="",s="",a="";if(m.body.limit&&(s="limit: "+m.body.limit),m.body.cursor&&(a="page : "+Number(m.body.cursor)),r&&0<r.length){var n=r[0],u=(s=s&&" , "+s,a=a&&" , "+a,i=`query { items_page_by_column_values (${s} ${a} board_id: ${this.boardId}, columns: [{column_id: "${n.queryId}", column_values: ["${n.value}"]}]) { cursor items {id name column_values {id text value} }}}`,yield(0,exports.queryMondayApi)(this.mondayToken,i));t=u.data.data.items_page_by_column_values.items}else{let e="";e=s&&a?s+" , "+a:s||a,i=e?`query {
25
28
  boards(ids:${this.boardId}){
26
- items(${e}){
29
+ items_page(${e}) {
30
+ cursor
31
+ items {
32
+ id
33
+ name
34
+ column_values {
35
+ id
36
+ text
37
+ value
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }`:`query {
43
+ boards(ids:${this.boardId}){
44
+ items_page {
45
+ cursor
46
+ items {
47
+ id
48
+ name
49
+ column_values {
50
+ id
51
+ text
52
+ value
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }`;var l=yield(0,exports.queryMondayApi)(this.mondayToken,i);t=l.data.data.boards[0].items_page.items}let o=!0;const y=[];if(t.map(e=>{e=this.parseModel(e);y.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",m,e)||(o=!1)}),e&&o){let e=null;y.length===m.body.limit&&(e=!0);var c={data:y,count:e};if(null!=(d=m.body)&&d.stopRes)return c;h.send(c)}else h.status(400).json({err:"Invalid Security Configuration"})}else h.status(400).json({err:"Invalid Fields"})}catch(e){h.status(400).json({err:e})}}),this.initUpdate=(u,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(this.modelChecker(u.body.data)&&u.body.id){var t=`query {
58
+ boards(ids: ${this.boardId}) {
59
+ items_page (limit: 1, query_params: {ids:${u.body.id}}) {
60
+ cursor
61
+ items {
27
62
  id
28
63
  name
29
- column_values{
64
+ column_values {
30
65
  id
31
66
  text
32
67
  value
33
68
  }
34
69
  }
35
70
  }
36
- }`;var l=yield(0,exports.queryMondayApi)(this.mondayToken,i);t=l.data.data.boards[0].items}let s=!0;const y=[];if(t.map(e=>{e=this.parseModel(e);y.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",m,e)||(s=!1)}),e&&s){let e=null;y.length===m.body.limit&&(e=!0);var c={data:y,count:e};if(null!=(d=m.body)&&d.stopRes)return c;h.send(c)}else h.status(400).json({err:"Invalid Security Configuration"})}else h.status(400).json({err:"Invalid Fields"})}catch(e){h.status(400).json({err:e})}}),this.initUpdate=(u,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(this.modelChecker(u.body.data)&&u.body.id){var t=`{
37
- boards(ids: ${Number(this.boardId)}) {
38
- items(ids:${u.body.id}) {
39
- id
40
- name
41
- column_values {
42
- id
43
- text
44
- value
45
- }
46
- }
47
71
  }
48
- }`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items;if(i.length<=0)throw"Error";var o=this.parseModel(i[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,u),s=(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,o);if(a&&s){const r=u.body.data,n={boardId:Number(this.boardId),itemId:Number(u.body.id),columnValues:{}};Object.keys(r).map(t=>{if("id"!==t){var i=this.modelType().write;let e="";(e=i[t]?i[t]:e)?n.columnValues[t]={[e]:r[t]}:n.columnValues[t]=r[t]}}),n.columnValues=JSON.stringify(n.columnValues),yield(0,exports.queryMondayApi)(this.mondayToken,`
49
- mutation ($boardId: Int!, $itemId: Int!, $columnValues: JSON!) {
72
+ }`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items_page.items;if(i.length<=0)throw"Error";var s=this.parseModel(i[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,u),o=(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,s);if(a&&o){const r=u.body.data,n={boardId:this.boardId,itemId:u.body.id,columnValues:{}};Object.keys(r).map(t=>{if("id"!==t){var i=this.modelType().write;let e="";(e=i[t]?i[t]:e)?n.columnValues[t]={[e]:r[t]}:n.columnValues[t]=r[t]}}),n.columnValues=JSON.stringify(n.columnValues),yield(0,exports.queryMondayApi)(this.mondayToken,`
73
+ mutation ($boardId: ID!, $itemId: ID!, $columnValues: JSON!) {
50
74
  change_multiple_column_values(
51
75
  item_id: $itemId,
52
76
  board_id: $boardId,
@@ -55,22 +79,25 @@
55
79
  id
56
80
  }
57
81
  }
58
- `,n);var d={success:!0};if(null!=(e=u.body)&&e.stopRes)return d;l.send(d)}else l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Fields"})}catch(e){l.status(400).json({err:e})}}),this.initDelete=(n,u,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(n.body.id){var t=`{
59
- boards(ids: ${Number(this.boardId)}) {
60
- items(ids:${n.body.id}) {
61
- id
62
- name
63
- column_values {
82
+ `,n);var d={success:!0};if(null!=(e=u.body)&&e.stopRes)return d;l.send(d)}else l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Fields"})}catch(e){l.status(400).json({err:e})}}),this.initDelete=(n,u,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(n.body.id){var t=`query {
83
+ boards(ids: ${this.boardId}) {
84
+ items_page (limit: 1, query_params: {ids:${n.body.id}}) {
85
+ cursor
86
+ items {
64
87
  id
65
- text
66
- value
88
+ name
89
+ column_values {
90
+ id
91
+ text
92
+ value
93
+ }
67
94
  }
68
95
  }
69
96
  }
70
- }`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items;if(i.length<=0)throw"Error";var o=this.parseModel(i[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,n),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,o);if(a&&s){l&&(yield l(o));var d={itemId:Number(n.body.id)},r=(yield(0,exports.queryMondayApi)(this.mondayToken,`
71
- mutation ($itemId: Int!){
97
+ }`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items_page.items;if(i.length<=0)throw"Error";var s=this.parseModel(i[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,n),o=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,s);if(a&&o){l&&(yield l(s));var d={itemId:n.body.id},r=(yield(0,exports.queryMondayApi)(this.mondayToken,`
98
+ mutation ($itemId: ID!){
72
99
  delete_item (item_id: $itemId) {
73
100
  id
74
101
  }
75
102
  }
76
- `,d),{success:!0});if(null!=(e=n.body)&&e.stopRes)return r;u.send(r)}else u.status(400).json({err:"Invalid Security Configuration"})}else u.status(400).json({err:"Invalid Model Structure"})}catch(e){u.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e},this.mondayToken=e,this.boardId=t,this.groupId=i,this.config=o,this.modelChecker=a,this.modelType=s,this.lib=d}}exports.MondayWrapper=MondayWrapper;
103
+ `,d),{success:!0});if(null!=(e=n.body)&&e.stopRes)return r;u.send(r)}else u.status(400).json({err:"Invalid Security Configuration"})}else u.status(400).json({err:"Invalid Model Structure"})}catch(e){u.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e},this.mondayToken=e,this.boardId=t,this.groupId=i,this.config=s,this.modelChecker=a,this.modelType=o,this.lib=d}}exports.MondayWrapper=MondayWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.1.46",
3
+ "version": "0.1.48",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,