@vendit-dev/thirdparty-adapters 0.3.26 → 0.3.28

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