blixify-server 0.1.79 → 0.1.81

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.
@@ -0,0 +1,17 @@
1
+ import { WrapperLib } from "./mongoWrapper";
2
+ /**
3
+ * @Wrapper
4
+ *
5
+ */
6
+ export declare class AuthWrapper {
7
+ fbAdmin: any;
8
+ isProd: boolean;
9
+ lib: WrapperLib;
10
+ constructor(fbAdmin: any, isProd: boolean, lib: WrapperLib);
11
+ initDisableAccount: (req: any, res: any) => Promise<void>;
12
+ initUpdatePassword: (req: any, res: any) => Promise<void>;
13
+ initUpdateEmail: (req: any, res: any, workflow?: () => Promise<any>) => Promise<void>;
14
+ initUpdateMobileNo: (req: any, res: any, workflow?: () => Promise<any>) => Promise<void>;
15
+ init: () => any;
16
+ }
17
+ //# sourceMappingURL=authWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/authWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,EAAE,GAAG,CAAM;IAClB,MAAM,UAAS;IACf,GAAG,EAAE,UAAU,CAAC;gBAEJ,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU;IAM1D,kBAAkB,QAAe,GAAG,OAAO,GAAG,mBAU5C;IAEF,kBAAkB,QAAe,GAAG,OAAO,GAAG,mBAW5C;IAEF,eAAe,QACR,GAAG,OACH,GAAG,aACG,MAAM,QAAQ,GAAG,CAAC,mBAa7B;IAEF,kBAAkB,QACX,GAAG,OACH,GAAG,aACG,MAAM,QAAQ,GAAG,CAAC,mBAa7B;IAEF,IAAI,YAuCF;CACH"}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AuthWrapper = void 0;
13
+ /**
14
+ * @Wrapper
15
+ *
16
+ */
17
+ class AuthWrapper {
18
+ constructor(fbAdmin, isProd, lib) {
19
+ this.fbAdmin = "";
20
+ this.isProd = false;
21
+ this.initDisableAccount = (req, res) => __awaiter(this, void 0, void 0, function* () {
22
+ const adminAuth = this.fbAdmin.auth();
23
+ try {
24
+ const userId = req.body.userId;
25
+ if (!userId)
26
+ throw "Invalid Configuration";
27
+ yield adminAuth.updateUser(userId, { disabled: true });
28
+ res.send({ success: true });
29
+ }
30
+ catch (err) {
31
+ res.status(400).json({ err: err });
32
+ }
33
+ });
34
+ this.initUpdatePassword = (req, res) => __awaiter(this, void 0, void 0, function* () {
35
+ const adminAuth = this.fbAdmin.auth();
36
+ try {
37
+ const userId = req.body.userId;
38
+ const password = req.body.password;
39
+ if (!userId || !password)
40
+ throw "Invalid Configuration";
41
+ yield adminAuth.updateUser(userId, { password: password });
42
+ res.send({ success: true });
43
+ }
44
+ catch (err) {
45
+ res.status(400).json({ err: err });
46
+ }
47
+ });
48
+ this.initUpdateEmail = (req, res, workflow) => __awaiter(this, void 0, void 0, function* () {
49
+ const adminAuth = this.fbAdmin.auth();
50
+ try {
51
+ const userId = req.body.userId;
52
+ const email = req.body.email;
53
+ if (!userId || !email)
54
+ throw "Invalid Configuration";
55
+ yield adminAuth.updateUser(userId, { email: email });
56
+ if (workflow)
57
+ yield workflow();
58
+ res.send({ success: true });
59
+ }
60
+ catch (err) {
61
+ res.status(400).json({ err: err });
62
+ }
63
+ });
64
+ this.initUpdateMobileNo = (req, res, workflow) => __awaiter(this, void 0, void 0, function* () {
65
+ const adminAuth = this.fbAdmin.auth();
66
+ try {
67
+ const userId = req.body.userId;
68
+ const phoneNumber = req.body.phoneNumber;
69
+ if (!userId || !phoneNumber)
70
+ throw "Invalid Configuration";
71
+ yield adminAuth.updateUser(userId, { phoneNumber: phoneNumber });
72
+ if (workflow)
73
+ yield workflow();
74
+ res.send({ success: true });
75
+ }
76
+ catch (err) {
77
+ res.status(400).json({ err: err });
78
+ }
79
+ });
80
+ this.init = () => {
81
+ const router = this.lib.express.Router();
82
+ /**
83
+ * @Input
84
+ * userId - string
85
+ */
86
+ router.post("/disable", (req, res) => {
87
+ this.initDisableAccount(req, res);
88
+ });
89
+ /**
90
+ * @Input
91
+ * userId - string
92
+ * password - string
93
+ */
94
+ router.post("/reset", (req, res) => {
95
+ this.initUpdatePassword(req, res);
96
+ });
97
+ /**
98
+ * @Input
99
+ * userId - string
100
+ * email - string
101
+ */
102
+ router.post("/email", (req, res) => {
103
+ this.initUpdateEmail(req, res);
104
+ });
105
+ /**
106
+ * @Input
107
+ * userId - string
108
+ * password - string
109
+ */
110
+ router.post("/mobile", (req, res) => {
111
+ this.initUpdateMobileNo(req, res);
112
+ });
113
+ return router;
114
+ };
115
+ this.fbAdmin = fbAdmin;
116
+ this.isProd = isProd;
117
+ this.lib = lib;
118
+ }
119
+ }
120
+ exports.AuthWrapper = AuthWrapper;
@@ -15,9 +15,10 @@ export declare class MongoWrapper {
15
15
  lib: WrapperLib;
16
16
  tableId: string;
17
17
  logId: string;
18
+ logWorkflow: any;
18
19
  debug: any;
19
20
  modelChecker: (obj: any) => boolean;
20
- constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib, tableId?: string, logId?: string, debug?: (reqBody: any, curBody: any, errMsg: any) => void);
21
+ constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib, tableId?: string, logId?: string, logWorkflow?: (data: any) => Promise<any>, debug?: (reqBody: any, curBody: any, errMsg: any) => void);
21
22
  parseModel: (data: any) => any;
22
23
  handleLogging: (mongoId: any, type: "create" | "update" | "delete", req: any, value?: {
23
24
  new?: any;
@@ -1 +1 @@
1
- {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAUA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAmGD;;;;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;IAChB,OAAO,SAAM;IACb,KAAK,SAAM;IACX,KAAK,EAAE,GAAG,CAAC;IAEX,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,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI;IAc3D,UAAU,SAAU,GAAG,SAIrB;IAEF,aAAa,YACF,GAAG,QACN,QAAQ,GAAG,QAAQ,GAAG,QAAQ,OAC/B,GAAG,UACA;QACN,GAAG,CAAC,EAAE,GAAG,CAAC;QACV,GAAG,CAAC,EAAE,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126
126
  class MongoWrapper {
127
- constructor(mongoDB, collection, isProd, config, modelChecker, lib, tableId, logId, debug) {
127
+ constructor(mongoDB, collection, isProd, config, modelChecker, lib, tableId, logId, logWorkflow, debug) {
128
128
  this.mongoDB = "";
129
129
  this.collection = "";
130
130
  this.isProd = false;
@@ -188,6 +188,8 @@ class MongoWrapper {
188
188
  .db(this.tableId)
189
189
  .collection(this.logId);
190
190
  yield mongoLogCollection.insertOne(logItem);
191
+ if (this.logWorkflow)
192
+ yield this.logWorkflow(logItem);
191
193
  }
192
194
  catch (err) { }
193
195
  });
@@ -286,7 +288,7 @@ class MongoWrapper {
286
288
  yield workflow(req.body.data);
287
289
  const mongoResult = yield mongoCollection.insertOne(req.body.data);
288
290
  const mongoId = mongoResult.insertedId.toString();
289
- this.handleLogging(mongoId, "create", req);
291
+ yield this.handleLogging(mongoId, "create", req);
290
292
  const resBody = { success: true };
291
293
  if ((_c = req.body) === null || _c === void 0 ? void 0 : _c.stopRes)
292
294
  return resBody;
@@ -520,7 +522,7 @@ class MongoWrapper {
520
522
  Object.keys(data).map((eachUpdateKey) => {
521
523
  oldData[eachUpdateKey] = mongoData[eachUpdateKey];
522
524
  });
523
- this.handleLogging(valid, "update", req, {
525
+ yield this.handleLogging(valid, "update", req, {
524
526
  old: oldData,
525
527
  new: data,
526
528
  });
@@ -682,7 +684,9 @@ class MongoWrapper {
682
684
  yield mongoCollection.findOneAndDelete({
683
685
  _id: valid,
684
686
  });
685
- this.handleLogging(mongoData._id, "delete", req, { new: mongoData });
687
+ yield this.handleLogging(mongoData._id, "delete", req, {
688
+ new: mongoData,
689
+ });
686
690
  const resBody = { success: true };
687
691
  if ((_o = req.body) === null || _o === void 0 ? void 0 : _o.stopRes)
688
692
  return resBody;
@@ -1000,6 +1004,7 @@ class MongoWrapper {
1000
1004
  const tableSuffix = this.isProd ? "prod" : "dev";
1001
1005
  this.tableId = tableId ? `${tableId}-${tableSuffix}` : tableSuffix;
1002
1006
  this.logId = logId !== null && logId !== void 0 ? logId : "";
1007
+ this.logWorkflow = logWorkflow;
1003
1008
  this.debug = debug;
1004
1009
  }
1005
1010
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.1.79",
3
+ "version": "0.1.81",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,
@@ -24,6 +24,7 @@
24
24
  "start:postgres": "cd dist && node postgresServer.js",
25
25
  "start:mongo": "cd dist && node mongoServer.js",
26
26
  "start:fb": "cd dist && node firebaseServer.js",
27
+ "start:auth": "cd dist && node authServer.js",
27
28
  "start:aws": "cd dist && node awsServer.js",
28
29
  "start:monday": "cd dist && node mondayServer.js",
29
30
  "install:husky": "yarn husky install"