blixify-server 0.1.4 → 0.1.6
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/dist/apis/fbWrapper.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import SecurityConfig from "../model/SecurityConfig";
|
|
2
|
+
import { WrapperLib } from "./mongoWrapper";
|
|
2
3
|
/**
|
|
3
4
|
* @Wrapper
|
|
4
5
|
*
|
|
@@ -8,8 +9,14 @@ export declare class FirebaseWrapper {
|
|
|
8
9
|
collection: string;
|
|
9
10
|
isProd: boolean;
|
|
10
11
|
config: SecurityConfig;
|
|
12
|
+
lib: WrapperLib;
|
|
11
13
|
modelChecker: (obj: any) => boolean;
|
|
12
|
-
constructor(fbAdmin: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean);
|
|
14
|
+
constructor(fbAdmin: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib);
|
|
15
|
+
initCreate: (req: any, res: any) => Promise<void>;
|
|
16
|
+
initGet: (req: any, res: any) => Promise<void>;
|
|
17
|
+
initUpdate: (req: any, res: any) => Promise<void>;
|
|
18
|
+
initDelete: (req: any, res: any) => Promise<void>;
|
|
19
|
+
initList: (req: any, res: any) => Promise<void>;
|
|
13
20
|
init: () => any;
|
|
14
21
|
}
|
|
15
22
|
//# sourceMappingURL=fbWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fbWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/fbWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;
|
|
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,mBAmHlC;IAEF,IAAI,YAuCF;CACH"}
|
package/dist/apis/fbWrapper.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,a,d
|
|
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"><":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,4 +1,7 @@
|
|
|
1
1
|
import SecurityConfig from "../model/SecurityConfig";
|
|
2
|
+
export interface WrapperLib {
|
|
3
|
+
express?: any;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @Wrapper
|
|
4
7
|
* collection - MongoDB Collection
|
|
@@ -9,8 +12,14 @@ export declare class MongoWrapper {
|
|
|
9
12
|
collection: string;
|
|
10
13
|
isProd: boolean;
|
|
11
14
|
config: SecurityConfig;
|
|
15
|
+
lib: WrapperLib;
|
|
12
16
|
modelChecker: (obj: any) => boolean;
|
|
13
|
-
constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean);
|
|
17
|
+
constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib);
|
|
18
|
+
initCreate: (req: any, res: any) => Promise<void>;
|
|
19
|
+
initGet: (req: any, res: any) => Promise<void>;
|
|
20
|
+
initUpdate: (req: any, res: any) => Promise<void>;
|
|
21
|
+
initDelete: (req: any, res: any) => Promise<void>;
|
|
22
|
+
initList: (req: any, res: any) => Promise<void>;
|
|
14
23
|
init: () => any;
|
|
15
24
|
}
|
|
16
25
|
//# sourceMappingURL=mongoWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;
|
|
1
|
+
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,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;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,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,mBAyGlC;IAEF,IAAI,YAuCF;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,r,d,a){return new(d=d||Promise)(function(i,e){function o(t){try{n(a.next(t))}catch(t){e(t)}}function s(t){try{n(a.throw(t))}catch(t){e(t)}}function n(t){var e;t.done?i(t.value):((e=t.value)instanceof d?e:new d(function(t){t(e)})).then(o,s)}n((a=a.apply(t,r||[])).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"),ObjectId=require("mongodb")["ObjectId"];class MongoWrapper{constructor(t,e,i,o,s,n){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=t=>!1,this.initCreate=(i,o)=>__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.isProd?"prod":"dev").collection(this.collection).insertOne(i.body.data),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})):o.status(400).json({err:"Invalid Model Structure"})}catch(t){o.status(400).json({err:t})}}),this.initGet=(s,n)=>__awaiter(this,void 0,void 0,function*(){try{var t,e,i,o=s.body.id;o?(t=yield this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection).findOne({_id:ObjectId(o)}),e=(0,QueryModel_1.checkBaseConfig)(this.config,s),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",s,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=(a,c)=>__awaiter(this,void 0,void 0,function*(){try{var t,e,i,o,s,n,r=this.modelChecker(a.body.data)&&a.body.id,d=t=>(delete t._id,t.baseUpdatedAt=(0,moment_1.default)().toDate(),t);r?(t=(0,QueryModel_1.checkBaseConfig)(this.config,a),e=(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,a.body.data),t&&e?(i=this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection),a.body.sensitive?(o=yield i.findOne({_id:ObjectId(r)}),(0,moment_1.default)(a.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(o.baseUpdatedAt))?(s=d(a.body.data),yield i.updateOne({_id:ObjectId(r)},{$set:Object.assign({},s)}),c.send({success:!0})):c.status(400).json({err:"Refresh Sensitive Model"})):(n=d(a.body.data),yield i.updateOne({_id:ObjectId(r)},{$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,r)=>__awaiter(this,void 0,void 0,function*(){try{var t,e,i,o,s=n.body.id;s?(e=yield(t=this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection)).findOne({_id:ObjectId(s)}),i=(0,QueryModel_1.checkBaseConfig)(this.config,n),o=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,e),i&&o?(yield t.findOneAndDelete({_id:ObjectId(s)}),r.send({success:!0})):r.status(400).json({err:"Invalid Security Configuration"})):r.status(400).json({err:"Invalid Fields"})}catch(t){r.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 o=c.body.query;const a={};o&&0<o.length&&o.map(t=>{var e,i=null!=(e=t.queryId)?e:"";const o=t.value;switch(t.type){case"search":t.searchIds&&0<t.searchIds.length&&(a.$or=[],t.searchIds.map(t=>{a.$or.push({[t]:{$regex:o,$options:"i"}})}));break;case"=":a[i]=o;break;case">":a[i]={$gt:o};break;case"<":a[i]={$lt:o};break;case"><":Array.isArray(o)&&2<=o.length&&(a[i]={$gte:o[0],$lte:o[1]});break;case"in":a[i]={$in:o}}});let t=this.mongoDB.db(this.isProd?"prod":"dev").collection(this.collection).find(a);var s,n,r=yield t.count({}),d=(c.body.cursor&&(t=t.skip(c.body.cursor)),c.body.limit&&(t=t.limit(c.body.limit)),c.body.sort&&(n={[(s=c.body.sort).sortId]:"asc"===s.type?1:-1},t=t.sort(n)),yield t.toArray());let e=!0;0<d.length&&d.map(t=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",c,t)||(e=!1)}),i&&e?l.send({data:d,count:r}):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=o,this.modelChecker=s,this.lib=n}}exports.MongoWrapper=MongoWrapper;
|