@vendit-dev/thirdparty-adapters 0.3.25 → 0.3.27

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.
@@ -121,7 +121,10 @@ var SmartAccessAdapter = /** @class */ (function () {
121
121
  this.checkSmartAccessIntegration = function (_a) {
122
122
  var accommodationId = _a.accommodationId;
123
123
  return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_b) {
124
- return [2 /*return*/, !!this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
124
+ switch (_b.label) {
125
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
126
+ case 1: return [2 /*return*/, !!(_b.sent())];
127
+ }
125
128
  }); });
126
129
  };
127
130
  this.getAccommodationAuthInfo = function (_a) {
@@ -133,13 +136,10 @@ var SmartAccessAdapter = /** @class */ (function () {
133
136
  case 0: return [4 /*yield*/, this.redis.get(SmartAccessAdapter.indexAccommodation({ accommodationId: accommodationId }))];
134
137
  case 1:
135
138
  existingAuth = _b.sent();
136
- console.log('AUTH 0', existingAuth);
137
139
  if (existingAuth) {
138
140
  if (existingAuth === 'NOT_FOUND') {
139
- // throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
140
141
  return [2 /*return*/, false];
141
142
  }
142
- console.log('AUTH 1', existingAuth);
143
143
  return [2 /*return*/, this.parseJSONSafe(existingAuth)];
144
144
  }
145
145
  lockId = "SMARTACCESS-HKEY|" + accommodationId;
@@ -149,28 +149,22 @@ var SmartAccessAdapter = /** @class */ (function () {
149
149
  return [4 /*yield*/, this.redis.get(SmartAccessAdapter.indexAccommodation({ accommodationId: accommodationId }))];
150
150
  case 3:
151
151
  existingAuth = _b.sent();
152
- console.log('AUTH 2', existingAuth);
153
152
  _b.label = 4;
154
153
  case 4:
155
154
  _b.trys.push([4, 9, 10, 12]);
156
155
  if (existingAuth) {
157
- console.log('AUTH 3', existingAuth);
158
156
  return [2 /*return*/, this.parseJSONSafe(existingAuth)];
159
157
  }
160
158
  return [4 /*yield*/, this.authenticator.getThirdPartyCredential({ accommodationId: accommodationId, provider: this.PROVIDER_KEY })];
161
159
  case 5:
162
160
  newAuth = _b.sent();
163
- console.log('AUTH 4', newAuth);
164
161
  if (!(!newAuth || !(newAuth === null || newAuth === void 0 ? void 0 : newAuth.credential))) return [3 /*break*/, 7];
165
162
  return [4 /*yield*/, this.redis.set(SmartAccessAdapter.indexAccommodation({ accommodationId: accommodationId }), 'NOT_FOUND', 'EX', 60 * 5)];
166
163
  case 6:
167
164
  _b.sent();
168
- // throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
169
165
  return [2 /*return*/, false];
170
166
  case 7:
171
- console.log('AUTH 5', existingAuth);
172
167
  parsedCredential = this.parseJSONSafe(newAuth.credential);
173
- console.log('AUTH 6', parsedCredential);
174
168
  return [4 /*yield*/, this.redis.set(SmartAccessAdapter.indexAccommodation({ accommodationId: accommodationId }), newAuth.credential, 'EX', 60 * 5)];
175
169
  case 8:
176
170
  _b.sent();
@@ -117,9 +117,10 @@ export default class ThemrIoTAdapter {
117
117
  }) => Promise<boolean>;
118
118
  getAccommodationAuthInfo: ({ accommodationId, }: {
119
119
  accommodationId: string;
120
- }) => Promise<VenditThemrIoTAuthInfo>;
120
+ }) => Promise<VenditThemrIoTAuthInfo | boolean>;
121
121
  getDefaultCheckInDate: () => string;
122
122
  getDefaultCheckOutDate: () => string;
123
+ getAccommodationAccessToken: (accommodationId: string) => Promise<string>;
123
124
  doorlockList: ({ accommodationId, roomAlias, }: {
124
125
  accommodationId: string;
125
126
  roomAlias?: string | undefined;
@@ -99,7 +99,10 @@ var ThemrIoTAdapter = /** @class */ (function () {
99
99
  this.checkTheMRIoTIntegration = function (_a) {
100
100
  var accommodationId = _a.accommodationId;
101
101
  return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_b) {
102
- return [2 /*return*/, !!this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
102
+ switch (_b.label) {
103
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
104
+ case 1: return [2 /*return*/, !!(_b.sent())];
105
+ }
103
106
  }); });
104
107
  };
105
108
  this.getAccommodationAuthInfo = function (_a) {
@@ -113,7 +116,7 @@ var ThemrIoTAdapter = /** @class */ (function () {
113
116
  existingAuth = _b.sent();
114
117
  if (existingAuth) {
115
118
  if (existingAuth === 'NOT_FOUND') {
116
- throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
119
+ return [2 /*return*/, false];
117
120
  }
118
121
  return [2 /*return*/, this.parseJSONSafe(existingAuth)];
119
122
  }
@@ -136,16 +139,18 @@ var ThemrIoTAdapter = /** @class */ (function () {
136
139
  })];
137
140
  case 5:
138
141
  newAuth = _b.sent();
139
- if (!!newAuth) return [3 /*break*/, 7];
142
+ if (!(!newAuth || !(newAuth === null || newAuth === void 0 ? void 0 : newAuth.credential))) return [3 /*break*/, 7];
140
143
  return [4 /*yield*/, this.redis.set(ThemrIoTAdapter.indexAccommodation({ accommodationId: accommodationId }), 'NOT_FOUND', 'EX', 60 * 10)];
141
144
  case 6:
142
145
  _b.sent();
143
- throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
146
+ return [2 /*return*/, false];
144
147
  case 7:
145
- newAuth.credential = JSON.parse(newAuth.credential);
148
+ console.log('Before Auth', newAuth);
149
+ newAuth.credential = this.parseJSONSafe(newAuth.credential);
146
150
  return [4 /*yield*/, this.redis.set(ThemrIoTAdapter.indexAccommodation({ accommodationId: accommodationId }), JSON.stringify(newAuth), 'EX', 60 * 10)];
147
151
  case 8:
148
152
  _b.sent();
153
+ console.log('After Auth', newAuth);
149
154
  return [2 /*return*/, newAuth];
150
155
  case 9:
151
156
  err_1 = _b.sent();
@@ -164,20 +169,34 @@ var ThemrIoTAdapter = /** @class */ (function () {
164
169
  this.getDefaultCheckOutDate = function () {
165
170
  return moment_1.default().add(3, 'd').format(_this.timeFormat);
166
171
  };
172
+ this.getAccommodationAccessToken = function (accommodationId) { return __awaiter(_this, void 0, void 0, function () {
173
+ var authInfo;
174
+ return __generator(this, function (_a) {
175
+ switch (_a.label) {
176
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({
177
+ accommodationId: accommodationId,
178
+ })];
179
+ case 1:
180
+ authInfo = (_a.sent());
181
+ if (!(authInfo === null || authInfo === void 0 ? void 0 : authInfo.accessToken))
182
+ throw new Error('THIRDPARTH_AUTH_NOT_FOUND');
183
+ return [2 /*return*/, authInfo.accessToken];
184
+ }
185
+ });
186
+ }); };
167
187
  // 3.3. 전체 객실/도어 정보 요청
168
188
  this.doorlockList = function (_a) {
169
189
  var accommodationId = _a.accommodationId, _b = _a.roomAlias, roomAlias = _b === void 0 ? '' : _b;
170
190
  return __awaiter(_this, void 0, void 0, function () {
171
- var authInfo, credential, data, doorLockList;
191
+ var token, data, doorLockList;
172
192
  return __generator(this, function (_c) {
173
193
  switch (_c.label) {
174
- case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
194
+ case 0: return [4 /*yield*/, this.getAccommodationAccessToken(accommodationId)];
175
195
  case 1:
176
- authInfo = _c.sent();
177
- credential = authInfo.credential;
196
+ token = _c.sent();
178
197
  return [4 /*yield*/, this.callTheMRApi({
179
198
  route: '/sc/v1/doorlocklist',
180
- params: __assign({ token: credential.accessToken }, (roomAlias && { roomAlias: roomAlias })),
199
+ params: __assign({ token: token }, (roomAlias && { roomAlias: roomAlias })),
181
200
  })];
182
201
  case 2:
183
202
  data = _c.sent();
@@ -194,17 +213,16 @@ var ThemrIoTAdapter = /** @class */ (function () {
194
213
  this.doorlockDetail = function (_a) {
195
214
  var accommodationId = _a.accommodationId, lockId = _a.lockId;
196
215
  return __awaiter(_this, void 0, void 0, function () {
197
- var authInfo, credential, data;
216
+ var token, data;
198
217
  return __generator(this, function (_b) {
199
218
  switch (_b.label) {
200
- case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
219
+ case 0: return [4 /*yield*/, this.getAccommodationAccessToken(accommodationId)];
201
220
  case 1:
202
- authInfo = _b.sent();
203
- credential = authInfo.credential;
221
+ token = _b.sent();
204
222
  return [4 /*yield*/, this.callTheMRApi({
205
223
  route: '/sc/v1/doorlockdetail',
206
224
  params: {
207
- token: credential.accessToken,
225
+ token: token,
208
226
  lockId: lockId,
209
227
  },
210
228
  })];
@@ -220,17 +238,16 @@ var ThemrIoTAdapter = /** @class */ (function () {
220
238
  this.getOTPPassCode = function (_a) {
221
239
  var accommodationId = _a.accommodationId, lockId = _a.lockId, _b = _a.checkinDate, checkinDate = _b === void 0 ? _this.getDefaultCheckInDate() : _b, _c = _a.checkoutDate, checkoutDate = _c === void 0 ? _this.getDefaultCheckOutDate() : _c;
222
240
  return __awaiter(_this, void 0, void 0, function () {
223
- var authInfo, credential, data;
241
+ var token, data;
224
242
  return __generator(this, function (_d) {
225
243
  switch (_d.label) {
226
- case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
244
+ case 0: return [4 /*yield*/, this.getAccommodationAccessToken(accommodationId)];
227
245
  case 1:
228
- authInfo = _d.sent();
229
- credential = authInfo.credential;
246
+ token = _d.sent();
230
247
  return [4 /*yield*/, this.callTheMRApi({
231
248
  route: '/sc/v1/getpasscode',
232
249
  params: {
233
- token: credential.accessToken,
250
+ token: token,
234
251
  lockId: lockId,
235
252
  checkinDate: checkinDate,
236
253
  checkoutDate: checkoutDate,
@@ -248,17 +265,16 @@ var ThemrIoTAdapter = /** @class */ (function () {
248
265
  this.writeAsyncRFCard = function (_a) {
249
266
  var accommodationId = _a.accommodationId, _b = _a.checkinDate, checkinDate = _b === void 0 ? _this.getDefaultCheckInDate() : _b, _c = _a.checkoutDate, checkoutDate = _c === void 0 ? _this.getDefaultCheckOutDate() : _c, _d = _a.build_no, build_no = _d === void 0 ? '1' : _d, _e = _a.floor_no, floor_no = _e === void 0 ? '1' : _e, lock_mac = _a.lock_mac, agent_id = _a.agent_id;
250
267
  return __awaiter(_this, void 0, void 0, function () {
251
- var authInfo, credential, data;
268
+ var token, data;
252
269
  return __generator(this, function (_f) {
253
270
  switch (_f.label) {
254
- case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
271
+ case 0: return [4 /*yield*/, this.getAccommodationAccessToken(accommodationId)];
255
272
  case 1:
256
- authInfo = _f.sent();
257
- credential = authInfo.credential;
273
+ token = _f.sent();
258
274
  return [4 /*yield*/, this.callTheMRApi({
259
275
  route: '/sc/v1/rfcardwritecall',
260
276
  params: {
261
- token: credential.accessToken,
277
+ token: token,
262
278
  checkinDate: checkinDate,
263
279
  checkoutDate: checkoutDate,
264
280
  build_no: build_no,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendit-dev/thirdparty-adapters",
3
- "version": "0.3.25",
3
+ "version": "0.3.27",
4
4
  "description": "Third party adapters between v-cloud and other PMS/CMS providers.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {