biz-slide-core 1.2.80 → 1.2.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.
@@ -16,4 +16,5 @@ var CustomerSchema = new mongoose_1.Schema({
16
16
  }, {
17
17
  timestamps: true,
18
18
  });
19
+ CustomerSchema.index({ userId: 1 });
19
20
  exports.CustomerModel = (0, mongoose_1.model)("customer", CustomerSchema);
@@ -102,6 +102,28 @@ var authorize = function (roles) {
102
102
  };
103
103
  };
104
104
  exports.authorize = authorize;
105
+ var createUser = function (emailId, userId, appName) { return __awaiter(void 0, void 0, void 0, function () {
106
+ var customer, newCustomer;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0: return [4 /*yield*/, entity_1.CustomerModel.findOne({ userId: userId })];
110
+ case 1:
111
+ customer = _a.sent();
112
+ if (!!customer) return [3 /*break*/, 3];
113
+ newCustomer = new entity_1.CustomerModel({
114
+ appName: appName,
115
+ emailId: emailId,
116
+ emailTemplateStatus: {},
117
+ userId: userId
118
+ });
119
+ return [4 /*yield*/, newCustomer.save()];
120
+ case 2:
121
+ _a.sent();
122
+ _a.label = 3;
123
+ case 3: return [2 /*return*/];
124
+ }
125
+ });
126
+ }); };
105
127
  var authorizeWithSlideApp = function () {
106
128
  return function (req, res, next) {
107
129
  var _a;
@@ -115,7 +137,7 @@ var authorizeWithSlideApp = function () {
115
137
  if (!req.headers.authorization) {
116
138
  return [2 /*return*/, res.status(401).json({ message: 'Unauthorized' })];
117
139
  }
118
- if (!req.headers.authorization) return [3 /*break*/, 2];
140
+ if (!req.headers.authorization) return [3 /*break*/, 3];
119
141
  return [4 /*yield*/, (0, utilities_1.verifyUid)(req.headers.authorization)];
120
142
  case 1:
121
143
  token = _b.sent();
@@ -133,9 +155,12 @@ var authorizeWithSlideApp = function () {
133
155
  appName: req.headers['x-app-name'],
134
156
  email: (token === null || token === void 0 ? void 0 : token.customer_email) || ""
135
157
  };
158
+ return [4 /*yield*/, createUser(req.user.email, req.user.userId, req.user.appName)];
159
+ case 2:
160
+ _b.sent();
136
161
  next();
137
- _b.label = 2;
138
- case 2: return [2 /*return*/];
162
+ _b.label = 3;
163
+ case 3: return [2 /*return*/];
139
164
  }
140
165
  });
141
166
  });
@@ -154,7 +179,7 @@ var nonAuthorizeWithSlideApp = function () {
154
179
  sessionId = req.headers['x-fingerprint-key'];
155
180
  userId = "guest";
156
181
  email = "";
157
- if (!req.headers.authorization) return [3 /*break*/, 2];
182
+ if (!req.headers.authorization) return [3 /*break*/, 3];
158
183
  return [4 /*yield*/, (0, utilities_1.verifyUid)(req.headers.authorization)];
159
184
  case 1:
160
185
  token = _b.sent();
@@ -166,13 +191,16 @@ var nonAuthorizeWithSlideApp = function () {
166
191
  if (!userId) {
167
192
  return [2 /*return*/, res.status(401).json({ message: 'userId not found' })];
168
193
  }
169
- return [3 /*break*/, 3];
194
+ return [4 /*yield*/, createUser(email, userId, req.headers['x-app-name'])];
170
195
  case 2:
196
+ _b.sent();
197
+ return [3 /*break*/, 4];
198
+ case 3:
171
199
  if (!ipAddress || !sessionId) {
172
200
  return [2 /*return*/, res.status(401).json({ message: 'We are not able to track your actions' })];
173
201
  }
174
- _b.label = 3;
175
- case 3:
202
+ _b.label = 4;
203
+ case 4:
176
204
  req.user = {
177
205
  userId: userId,
178
206
  sessionId: sessionId,
@@ -188,6 +216,7 @@ var nonAuthorizeWithSlideApp = function () {
188
216
  };
189
217
  };
190
218
  exports.nonAuthorizeWithSlideApp = nonAuthorizeWithSlideApp;
219
+ // TODO: Delete It
191
220
  var authorizeWithGpt = function () {
192
221
  return function (req, res, next) {
193
222
  return __awaiter(this, void 0, void 0, function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "biz-slide-core",
3
- "version": "1.2.80",
3
+ "version": "1.2.81",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "tsc",