blixify-server 0.1.13 → 0.1.15

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.
@@ -12,9 +12,13 @@ export declare class FirebaseWrapper {
12
12
  lib: WrapperLib;
13
13
  modelChecker: (obj: any) => boolean;
14
14
  constructor(fbAdmin: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib);
15
+ parseModel: (data: any) => any;
16
+ initBatchCreate: (req: any, res: any) => Promise<void>;
15
17
  initCreate: (req: any, res: any) => Promise<void>;
16
18
  initGet: (req: any, res: any) => Promise<void>;
19
+ initBatchUpdate: (req: any, res: any) => Promise<void>;
17
20
  initUpdate: (req: any, res: any) => Promise<void>;
21
+ initBatchDelete: (req: any, res: any) => Promise<void>;
18
22
  initDelete: (req: any, res: any) => Promise<void>;
19
23
  initList: (req: any, res: any) => Promise<void>;
20
24
  init: () => any;
@@ -1 +1 @@
1
- {"version":3,"file":"fbWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/fbWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;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,QAAe,GAAG,OAAO,GAAG,mBA8BpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA+DpC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAyCpC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAsHlC;IAEF,IAAI,YAuCF;CACH"}
1
+ {"version":3,"file":"fbWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/fbWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;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,QAAe,GAAG,OAAO,GAAG,mBA8CzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA8BpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAoEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA0DpC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBA6GzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAyCpC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAsHlC;IAEF,IAAI,YA0DF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,a,n,d){return new(n=n||Promise)(function(i,t){function s(e){try{r(d.next(e))}catch(e){t(e)}}function o(e){try{r(d.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?i(e.value):((t=e.value)instanceof n?t:new n(function(e){e(t)})).then(s,o)}r((d=d.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");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.initCreate=(i,s)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(i.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),e&&t?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),yield this.fbAdmin.firestore().collection(this.collection).doc(i.body.data.id).set(i.body.data),s.send({success:!0})):s.status(400).json({err:"Invalid Security Configuration"})):s.status(400).json({err:"Invalid Model Structure"})}catch(e){s.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.initUpdate=(d,c)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o,r,a=this.modelChecker(d.body.data)&&d.body.id,n=e=>(delete e.id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e);a?(e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),e&&t?d.body.sensitive?(i=yield this.fbAdmin.firestore().collection(this.collection).doc(a).get()).exists?(s=i.data(),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*s.baseUpdatedAt.seconds))?(o=n(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(a).update(Object.assign({},o)),c.send({success:!0})):c.status(400).json({err:"Refresh Sensitive Model"})):c.status(400).json({err:"Invalid Security Configuration"}):(r=n(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(a).update(Object.assign({},r)),c.send({success:!0})):c.status(400).json({err:"Invalid Security Configuration"})):c.status(400).json({err:"Invalid Model Structure"})}catch(e){c.status(400).json({err:e})}}),this.initDelete=(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,"delete",r,t),i)&&s?(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,c)=>__awaiter(this,void 0,void 0,function*(){try{var e=(0,QueryModel_1.checkBaseConfig)(this.config,d);if(e){let o=this.fbAdmin.firestore().collection(this.collection),r="";var t=d.body.query;if(t&&0<t.length&&t.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.limit){if(o=o.limit(d.body.limit),d.body.sort){var i=d.body.sort;if(r&&i.sortId!==r)return void c.status(400).json({err:"Invalid Search Sort Configuration"});r||(o=o.orderBy(i.sortId,"asc"===i.type?"asc":"desc"))}var s,a=yield(o=d.body.cursor?o.startAfter(d.body.cursor):o).get();let t=!0;const n=[];if(a&&a.forEach(e=>{e=e.data();n.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",d,e)||(t=!1)}),e&&t){let t="";if(n.length===d.body.limit){let e="id";d.body.sort&&(s=d.body.sort,e=s.sortId),t=n[d.body.limit-1][e]}c.send({data:n,count:t})}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Limit Configuration"})}else c.status(400).json({err:"Invalid Security Configuration"})}catch(e){c.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",this.initCreate),e.post("/get",this.initGet),e.post("/update",this.initUpdate),e.post("/delete",this.initDelete),e.post("/list",this.initList),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{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");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=(s,o)=>__awaiter(this,void 0,void 0,function*(){try{const i=this.fbAdmin.firestore().batch();if(Array.isArray(s.body.data)){let t=!0;if(s.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=(0,QueryModel_1.checkBaseConfig)(this.config,s);let t=!0;s.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",s,e)||(t=!1)}),e&&t?(yield Promise.all(s.body.data.map(t=>__awaiter(this,void 0,void 0,function*(){t.baseUpdatedAt=(0,moment_1.default)().toDate();var e=this.fbAdmin.firestore().collection(this.collection).doc(t.id);i.set(e,Object.assign({},t))}))),yield i.commit(),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})}else o.status(400).json({err:"Invalid Model Structure"})}else o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initCreate=(i,s)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(i.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),e&&t?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),yield this.fbAdmin.firestore().collection(this.collection).doc(i.body.data.id).set(i.body.data),s.send({success:!0})):s.status(400).json({err:"Invalid Security Configuration"})):s.status(400).json({err:"Invalid Model Structure"})}catch(e){s.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=(r,a)=>__awaiter(this,void 0,void 0,function*(){const o=this.fbAdmin.firestore().batch();try{if(this.modelChecker(r.body.data)&&r.body.id&&Array.isArray(r.body.id)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,r);let t=!0;if(r.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",r,e)||(t=!1)}),e&&t)if(r.body.sensitive){let s=!0;yield Promise.all(r.body.id.map(i=>__awaiter(this,void 0,void 0,function*(){var e,t=yield this.fbAdmin.firestore().collection(this.collection).doc(i).get();t.exists?(t=t.data(),(0,moment_1.default)(r.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))?(t=this.parseModel(r.body.data),e=this.fbAdmin.firestore().collection(this.collection).doc(i),o.update(e,Object.assign({},t))):s=!1):a.status(400).json({err:"Invalid Security Configuration"})}))),s&&(yield o.commit()),a.send({success:!0})}else{const i=this.parseModel(r.body.data);r.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=this.fbAdmin.firestore().collection(this.collection).doc(t);o.update(e,Object.assign({},i)),yield o.commit()}))}else a.status(400).json({err:"Invalid Security Configuration"})}}catch(e){}}),this.initUpdate=(d,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o,r,a=this.modelChecker(d.body.data)&&d.body.id;a?(e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),e&&t?d.body.sensitive?(i=yield this.fbAdmin.firestore().collection(this.collection).doc(a).get()).exists?(s=i.data(),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*s.baseUpdatedAt.seconds))?(o=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(a).update(Object.assign({},o)),n.send({success:!0})):n.status(400).json({err:"Refresh Sensitive Model"})):n.status(400).json({err:"Invalid Security Configuration"}):(r=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(a).update(Object.assign({},r)),n.send({success:!0})):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Model Structure"})}catch(e){n.status(400).json({err:e})}}),this.initBatchDelete=(n,c)=>__awaiter(this,void 0,void 0,function*(){try{const d=this.fbAdmin.firestore().batch();if(Array.isArray(n.body.id)){var e=yield this.fbAdmin.firestore().collection(this.collection).where("id","in",n.body.id).get(),i=(0,QueryModel_1.checkBaseConfig)(this.config,n);let t=!0;if(e&&e.forEach(e=>{e=e.data();(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,e)||(t=!1)}),!i||!t)return void c.status(400).json({err:"Invalid Security Configuration"});yield Promise.all(n.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(),c.send({success:!0})}else{let o=this.fbAdmin.firestore().collection(this.collection);var s=n.body.query,r=(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)}}),yield o.get()),a=(0,QueryModel_1.checkBaseConfig)(this.config,n);let t=!0;if(r&&r.forEach(e=>{e=e.data();(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,e)||(t=!1)}),!a||!t)return void c.status(400).json({err:"Invalid Security Configuration"});r.forEach(e=>{d.delete(e.ref)}),yield d.commit()}c.send({success:!0})}catch(e){c.status(400).json({err:e})}}),this.initDelete=(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,"delete",r,t),i)&&s?(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=(n,c)=>__awaiter(this,void 0,void 0,function*(){try{var e=(0,QueryModel_1.checkBaseConfig)(this.config,n);if(e){let o=this.fbAdmin.firestore().collection(this.collection),r="";var t=n.body.query;if(t&&0<t.length&&t.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)}}),n.body.limit){if(o=o.limit(n.body.limit),n.body.sort){var i=n.body.sort;if(r&&i.sortId!==r)return void c.status(400).json({err:"Invalid Search Sort Configuration"});r||(o=o.orderBy(i.sortId,"asc"===i.type?"asc":"desc"))}var s,a=yield(o=n.body.cursor?o.startAfter(n.body.cursor):o).get();let t=!0;const d=[];if(a&&a.forEach(e=>{e=e.data();d.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",n,e)||(t=!1)}),e&&t){let t="";if(d.length===n.body.limit){let e="id";n.body.sort&&(s=n.body.sort,e=s.sortId),t=d[n.body.limit-1][e]}c.send({data:d,count:t})}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Limit Configuration"})}else c.status(400).json({err:"Invalid Security Configuration"})}catch(e){c.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",this.initCreate),e.post("/batchCreate",this.initBatchCreate),e.post("/get",this.initGet),e.post("/update",this.initUpdate),e.post("/batchUpdate",this.initBatchUpdate),e.post("/delete",this.initDelete),e.post("/batchDelete",this.initBatchDelete),e.post("/list",this.initList),e},this.fbAdmin=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=r}}exports.FirebaseWrapper=FirebaseWrapper;
@@ -16,9 +16,13 @@ export declare class MongoWrapper {
16
16
  modelChecker: (obj: any) => boolean;
17
17
  tableId: string;
18
18
  constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib, tableId?: string);
19
+ parseModel: (data: any) => any;
20
+ initBatchCreate: (req: any, res: any) => Promise<void>;
19
21
  initCreate: (req: any, res: any) => Promise<void>;
20
22
  initGet: (req: any, res: any) => Promise<void>;
23
+ initBatchUpdate: (req: any, res: any) => Promise<void>;
21
24
  initUpdate: (req: any, res: any) => Promise<void>;
25
+ initBatchDelete: (req: any, res: any) => Promise<void>;
22
26
  initDelete: (req: any, res: any) => Promise<void>;
23
27
  initList: (req: any, res: any) => Promise<void>;
24
28
  init: () => any;
@@ -1 +1 @@
1
- {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB,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;IACF,OAAO,SAAM;gBAGX,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,EACf,OAAO,CAAC,EAAE,MAAM;IAYlB,UAAU,QAAe,GAAG,OAAO,GAAG,mBA6BpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA8BjC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAiEpC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAkCpC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBA8GlC;IAEF,IAAI,YAuCF;CACH"}
1
+ {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB,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;IACF,OAAO,SAAM;gBAGX,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,EACf,OAAO,CAAC,EAAE,MAAM;IAYlB,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBA+CzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA6BpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA8BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAuEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA4DpC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAoHzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAkCpC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBA8GlC;IAEF,IAAI,YA0DF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(t,a,r,d){return new(r=r||Promise)(function(i,e){function s(t){try{n(d.next(t))}catch(t){e(t)}}function o(t){try{n(d.throw(t))}catch(t){e(t)}}function n(t){var e;t.done?i(t.value):((e=t.value)instanceof r?e:new r(function(t){t(e)})).then(s,o)}n((d=d.apply(t,a||[])).next())})},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel");class MongoWrapper{constructor(t,e,i,s,o,n,a){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=t=>!1,this.tableId="",this.initCreate=(i,s)=>__awaiter(this,void 0,void 0,function*(){try{var t,e;this.modelChecker(i.body.data)?(t=(0,QueryModel_1.checkBaseConfig)(this.config,i),e=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),t&&e?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),yield this.mongoDB.db(this.tableId).collection(this.collection).insertOne(i.body.data),s.send({success:!0})):s.status(400).json({err:"Invalid Security Configuration"})):s.status(400).json({err:"Invalid Model Structure"})}catch(t){s.status(400).json({err:t})}}),this.initGet=(o,n)=>__awaiter(this,void 0,void 0,function*(){try{var t,e,i,s=o.body.id;s?(t=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:s}),e=(0,QueryModel_1.checkBaseConfig)(this.config,o),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",o,t),e&&i?n.send({data:t}):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Fields"})}catch(t){n.status(400).json({err:t})}}),this.initUpdate=(d,c)=>__awaiter(this,void 0,void 0,function*(){try{var t,e,i,s,o,n,a=this.modelChecker(d.body.data)&&d.body.id,r=t=>(delete t._id,t.baseUpdatedAt=(0,moment_1.default)().toDate(),t);a?(t=(0,QueryModel_1.checkBaseConfig)(this.config,d),e=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),t&&e?(i=this.mongoDB.db(this.tableId).collection(this.collection),d.body.sensitive?(s=yield i.findOne({_id:a}),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(s.baseUpdatedAt))?(o=r(d.body.data),yield i.updateOne({_id:a},{$set:Object.assign({},o)}),c.send({success:!0})):c.status(400).json({err:"Refresh Sensitive Model"})):(n=r(d.body.data),yield i.updateOne({_id:a},{$set:Object.assign({},n)}),c.send({success:!0}))):c.status(400).json({err:"Invalid Security Configuration"})):c.status(400).json({err:"Invalid Model Structure"})}catch(t){c.status(400).json({err:t})}}),this.initDelete=(n,a)=>__awaiter(this,void 0,void 0,function*(){try{var t,e,i,s,o=n.body.id;o?(e=yield(t=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:o}),i=(0,QueryModel_1.checkBaseConfig)(this.config,n),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,e),i&&s?(yield t.findOneAndDelete({_id:o}),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"})):a.status(400).json({err:"Invalid Fields"})}catch(t){a.status(400).json({err:t})}}),this.initList=(c,l)=>__awaiter(this,void 0,void 0,function*(){try{var i=(0,QueryModel_1.checkBaseConfig)(this.config,c);if(i){var s=c.body.query;const d={};s&&0<s.length&&s.map(t=>{var e,i=null!=(e=t.queryId)?e:"";const s=t.value;switch(t.type){case"search":t.searchIds&&0<t.searchIds.length&&(d.$or=[],t.searchIds.map(t=>{d.$or.push({[t]:{$regex:s,$options:"i"}})}));break;case"=":d[i]=s;break;case"!=":d[i]={$ne:s};break;case">":d[i]={$gt:s};break;case"<":d[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(d[i]={$gte:s[0],$lte:s[1]});break;case"in":d[i]={$in:s}}});let t=this.mongoDB.db(this.tableId).collection(this.collection).find(d);var o,n,a=yield t.count({}),r=(c.body.cursor&&(t=t.skip(c.body.cursor)),c.body.limit&&(t=t.limit(c.body.limit)),c.body.sort&&(n={[(o=c.body.sort).sortId]:"asc"===o.type?1:-1},t=t.sort(n)),yield t.toArray());let e=!0;0<r.length&&r.map(t=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",c,t)||(e=!1)}),i&&e?l.send({data:r,count:a}):l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Security Configuration"})}catch(t){l.status(400).json({err:t})}}),this.init=()=>{var t=this.lib.express.Router();return t.post("/create",this.initCreate),t.post("/get",this.initGet),t.post("/update",this.initUpdate),t.post("/delete",this.initDelete),t.post("/list",this.initList),t},this.mongoDB=t,this.collection=e,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=n;t=this.isProd?"prod":"dev";this.tableId=a?a+"-"+t:t}}exports.MongoWrapper=MongoWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,d,r){return new(d=d||Promise)(function(i,t){function s(e){try{a(r.next(e))}catch(e){t(e)}}function o(e){try{a(r.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,o)}a((r=r.apply(e,n||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel");class MongoWrapper{constructor(e,t,i,s,o,a,n){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.tableId="",this.parseModel=e=>(delete e._id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(o.body.data)){let t=!0;o.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||a.status(400).json({err:"Invalid Model Structure"});var e,s=(0,QueryModel_1.checkBaseConfig)(this.config,o);let i=!0;yield Promise.all(o.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",o,e)||(i=!1)})),s&&i?(e=o.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),yield this.mongoDB.db(this.tableId).collection(this.collection).insertMany(e),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"})}else a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initCreate=(i,s)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(i.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),e&&t?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),yield this.mongoDB.db(this.tableId).collection(this.collection).insertOne(i.body.data),s.send({success:!0})):s.status(400).json({err:"Invalid Security Configuration"})):s.status(400).json({err:"Invalid Model Structure"})}catch(e){s.status(400).json({err:e})}}),this.initGet=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=o.body.id;s?(e=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:s}),t=(0,QueryModel_1.checkBaseConfig)(this.config,o),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",o,e),t&&i?a.send({data:e}):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=(a,n)=>__awaiter(this,void 0,void 0,function*(){try{var e=this.modelChecker(a.body.data)&&a.body.id;if(Array.isArray(a.body.id)){var s=a.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),i=(0,QueryModel_1.checkBaseConfig)(this.config,a);let t=!0;if(yield Promise.all(a.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,e)||(t=!1)})),i&&t){const o=this.mongoDB.db(this.tableId).collection(this.collection);if(a.body.sensitive){let i=!0;yield Promise.all(a.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield o.findOne({_id:t});(0,moment_1.default)(a.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(e.baseUpdatedAt))?n.status(400).json({err:"Refresh Sensitive Model"}):i=!1}))),i&&(yield o.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0}))}else yield o.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0})}else n.status(400).json({err:"Invalid Security Configuration"})}}catch(e){}}),this.initUpdate=(d,r)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o,a,n=this.modelChecker(d.body.data)&&d.body.id;n?(e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),e&&t?(i=this.mongoDB.db(this.tableId).collection(this.collection),d.body.sensitive?(s=yield i.findOne({_id:n}),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(s.baseUpdatedAt))?(o=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},o)}),r.send({success:!0})):r.status(400).json({err:"Refresh Sensitive Model"})):(a=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},a)}),r.send({success:!0}))):r.status(400).json({err:"Invalid Security Configuration"})):r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initBatchDelete=(l,h)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(l.body.id)){var e=this.mongoDB.db(this.tableId).collection(this.collection),i=yield e.find({_id:{$in:l.body.id}}),s=(0,QueryModel_1.checkBaseConfig)(this.config,l),o=yield i.toArray();let t=!0;0<o.length&&(yield Promise.all(o.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",l,e)||(t=!1)}))),s&&t?(yield e.deleteMany({_id:{$in:l.body.id}}),h.send({success:!0})):h.status(400).json({err:"Invalid Security Configuration"})}else{var a=l.body.query;const c={};a&&0<a.length&&a.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(c.$or=[],e.searchIds.map(e=>{c.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":c[i]=s;break;case"!=":c[i]={$ne:s};break;case">":c[i]={$gt:s};break;case"<":c[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(c[i]={$gte:s[0],$lte:s[1]});break;case"in":c[i]={$in:s}}});var n=this.mongoDB.db(this.tableId).collection(this.collection),d=yield n.find(c).toArray(),r=(0,QueryModel_1.checkBaseConfig)(this.config,l);let t=!0;0<d.length&&d.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",l,e)||(t=!1)}),r&&t?(yield n.deleteMany(c),h.send({success:!0})):h.status(400).json({err:"Invalid Security Configuration"})}}catch(e){h.status(400).json({err:e})}}),this.initDelete=(a,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=a.body.id;o?(t=yield(e=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:o}),i=(0,QueryModel_1.checkBaseConfig)(this.config,a),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",a,t),i&&s?(yield e.findOneAndDelete({_id:o}),n.send({success:!0})):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initList=(c,l)=>__awaiter(this,void 0,void 0,function*(){try{var i=(0,QueryModel_1.checkBaseConfig)(this.config,c);if(i){var s=c.body.query;const r={};s&&0<s.length&&s.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(r.$or=[],e.searchIds.map(e=>{r.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":r[i]=s;break;case"!=":r[i]={$ne:s};break;case">":r[i]={$gt:s};break;case"<":r[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(r[i]={$gte:s[0],$lte:s[1]});break;case"in":r[i]={$in:s}}});let e=this.mongoDB.db(this.tableId).collection(this.collection).find(r);var o,a,n=yield e.count({}),d=(c.body.cursor&&(e=e.skip(c.body.cursor)),c.body.limit&&(e=e.limit(c.body.limit)),c.body.sort&&(a={[(o=c.body.sort).sortId]:"asc"===o.type?1:-1},e=e.sort(a)),yield e.toArray());let t=!0;0<d.length&&d.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",c,e)||(t=!1)}),i&&t?l.send({data:d,count:n}):l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Security Configuration"})}catch(e){l.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",this.initCreate),e.post("/batchCreate",this.initBatchCreate),e.post("/get",this.initGet),e.post("/update",this.initUpdate),e.post("/batchUpdate",this.initBatchUpdate),e.post("/delete",this.initDelete),e.post("/batchDelete",this.initBatchDelete),e.post("/list",this.initList),e},this.mongoDB=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=a;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e}}exports.MongoWrapper=MongoWrapper;
@@ -14,10 +14,12 @@ export declare class UploadWrapper {
14
14
  isProd: boolean;
15
15
  config: SecurityConfig;
16
16
  lib: UploadLib;
17
- modelChecker: (obj: any) => boolean;
17
+ modelChecker: (obj: any, isDeleteDirectory?: boolean) => boolean;
18
18
  constructor(fbAdmin: any, isProd: boolean, config: SecurityConfig, lib: UploadLib);
19
19
  initUpload: (req: any, res: any, type: "create" | "update") => Promise<void>;
20
20
  initDelete: (req: any, res: any) => Promise<void>;
21
+ deleteFolderContents: (folderRef: any) => Promise<void>;
22
+ initDeleteDirectory: (req: any, res: any) => Promise<void>;
21
23
  init: () => any;
22
24
  }
23
25
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"uploadWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/uploadWrapper.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,UAAU,SAAS;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,EAAE,GAAG,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,EAAE,GAAG,CAAM;IAClB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,SAAS,CAAC;IACf,YAAY,QAAS,GAAG,aAMtB;gBAGA,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,SAAS;IAQhB,UAAU,QAAe,GAAG,OAAO,GAAG,QAAQ,QAAQ,GAAG,QAAQ,mBA0D/D;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA8BpC;IAEF,IAAI,YA4CF;CACH"}
1
+ {"version":3,"file":"uploadWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/uploadWrapper.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,UAAU,SAAS;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,EAAE,GAAG,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,EAAE,GAAG,CAAM;IAClB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,SAAS,CAAC;IACf,YAAY,QAAS,GAAG,sBAAsB,OAAO,aAUnD;gBAGA,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,SAAS;IAQhB,UAAU,QAAe,GAAG,OAAO,GAAG,QAAQ,QAAQ,GAAG,QAAQ,mBA0D/D;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA8BpC;IAEF,oBAAoB,cAAqB,GAAG,mBAwB1C;IAEF,mBAAmB,QAAe,GAAG,OAAO,GAAG,mBA+B7C;IAEF,IAAI,YAmDF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,d){return new(r=r||Promise)(function(i,t){function s(e){try{o(d.next(e))}catch(e){t(e)}}function a(e){try{o(d.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((d=d.apply(e,n||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UploadWrapper=void 0;const QueryModel_1=require("../model/QueryModel");class UploadWrapper{constructor(e,t,i,s){this.fbAdmin="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!!(e.assetCollectionName&&e.assetParentId&&e.assetFileName),this.initUpload=(l,a,o)=>__awaiter(this,void 0,void 0,function*(){try{const n=l.body.data;if(this.modelChecker(n)&&(l.file||n.downloadLink)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,l),t=(0,QueryModel_1.checkOpsConfig)(this.config,o,l,n);if(e&&t){const r=this.fbAdmin.storage().bucket(),d=this.lib.randomUUID();var i,s=(a,o)=>new Promise((i,s)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===a,t={contentType:e?o.headers["content-type"]:l.file.mimetype,customMetadata:{"file-name":"buffer"===a?n.assetFileName:l.file.originalname},metadata:{firebaseStorageDownloadTokens:d}},t=r.file(`${n.assetCollectionName}/${n.assetParentId}/`+n.assetFileName).createWriteStream({metadata:t});t.end(e?o.data:l.file.buffer),t.on("error",s),t.on("finish",i)}));n.downloadLink?(i=yield this.lib.axios({method:"GET",url:n.downloadLink,responseType:"arraybuffer"})).data&&(yield s("buffer",i)):yield s("file"),a.send({data:d})}else a.status(400).json({err:"Invalid Security Configuration"})}else a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initDelete=(s,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i=s.body.data;this.modelChecker(i)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,s),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",s,i),e&&t?(yield this.fbAdmin.storage().bucket().file(`${i.assetCollectionName}/${i.assetParentId}/`+i.assetFileName).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.init=()=>{var e=this.lib.express.Router();return e.post("/upload",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"create")}),e.post("/update",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"update")}),e.post("/delete",this.initDelete),e},this.fbAdmin=e,this.isProd=t,this.config=i,this.lib=s}}exports.UploadWrapper=UploadWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,d){return new(r=r||Promise)(function(i,t){function s(e){try{a(d.next(e))}catch(e){t(e)}}function o(e){try{a(d.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,o)}a((d=d.apply(e,n||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UploadWrapper=void 0;const QueryModel_1=require("../model/QueryModel");class UploadWrapper{constructor(e,t,i,s){this.fbAdmin="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=(e,t)=>!(!e.assetCollectionName||!e.assetParentId||!t&&!e.assetFileName),this.initUpload=(l,o,a)=>__awaiter(this,void 0,void 0,function*(){try{const n=l.body.data;if(this.modelChecker(n)&&(l.file||n.downloadLink)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,l),t=(0,QueryModel_1.checkOpsConfig)(this.config,a,l,n);if(e&&t){const r=this.fbAdmin.storage().bucket(),d=this.lib.randomUUID();var i,s=(o,a)=>new Promise((i,s)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===o,t={contentType:e?a.headers["content-type"]:l.file.mimetype,customMetadata:{"file-name":"buffer"===o?n.assetFileName:l.file.originalname},metadata:{firebaseStorageDownloadTokens:d}},t=r.file(`${n.assetCollectionName}/${n.assetParentId}/`+n.assetFileName).createWriteStream({metadata:t});t.end(e?a.data:l.file.buffer),t.on("error",s),t.on("finish",i)}));n.downloadLink?(i=yield this.lib.axios({method:"GET",url:n.downloadLink,responseType:"arraybuffer"})).data&&(yield s("buffer",i)):yield s("file"),o.send({data:d})}else o.status(400).json({err:"Invalid Security Configuration"})}else o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initDelete=(s,o)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i=s.body.data;this.modelChecker(i)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,s),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",s,i),e&&t?(yield this.fbAdmin.storage().bucket().file(`${i.assetCollectionName}/${i.assetParentId}/`+i.assetFileName).delete(),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})):o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.deleteFolderContents=a=>__awaiter(this,void 0,void 0,function*(){try{var e={prefix:a.name,autoPaginate:!1},[t]=yield this.fbAdmin.storage().bucket().getFiles(e),i=[];for(const s of t)i.push(s.delete());for(const o of t)o.name.endsWith("/")&&i.push(this.deleteFolderContents(o));yield Promise.all(i)}catch(e){}}),this.initDeleteDirectory=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=o.body.data;this.modelChecker(s,!0)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,s),e&&t?(i=this.fbAdmin.storage().bucket().file(`${s.assetCollectionName}/${s.assetParentId}/`),yield this.deleteFolderContents(i),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.init=()=>{var e=this.lib.express.Router();return e.post("/upload",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"create")}),e.post("/update",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"update")}),e.post("/delete",this.initDelete),e.post("/deleteDirectory",this.initDeleteDirectory),e},this.fbAdmin=e,this.isProd=t,this.config=i,this.lib=s}}exports.UploadWrapper=UploadWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,