@vendit-dev/thirdparty-adapters 0.1.4 → 0.2.0

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,92 @@
1
+ import { UserServiceGrpcCaller } from '@vendit-dev/utility-modules';
2
+ export declare class MutexLock {
3
+ redis: any;
4
+ hashPrefix: string;
5
+ mutexLockInterval: number;
6
+ constructor({ redis, hashPrefix, mutexLockInterval }: {
7
+ redis: any;
8
+ hashPrefix: string;
9
+ mutexLockInterval?: number;
10
+ });
11
+ getMutexLockKey: (id: string) => string;
12
+ tryMutexLock: (streamId: string, lockHash: string) => any;
13
+ getMutexLock: (streamId: string) => Promise<string>;
14
+ unlockMutexLock: (streamId: string, lockHash: string) => Promise<any>;
15
+ }
16
+ declare type OAuthTokenResponse = {
17
+ accessToken: string;
18
+ refreshToken: string;
19
+ tokenType: string;
20
+ expiresIn: number;
21
+ };
22
+ declare type OAuthRawTokenSet = {
23
+ refresh_token: string;
24
+ access_token: string;
25
+ expires_in: number;
26
+ token_type: string;
27
+ };
28
+ declare type SmartAccessRoom = {
29
+ roomId: string;
30
+ roomNumber: string;
31
+ path: string;
32
+ };
33
+ export default class SmartAccessAdapter {
34
+ static indexAccommodation: ({ accommodationId }: {
35
+ accommodationId: string;
36
+ }) => string;
37
+ static refineRawTokenSet: (rawTokenSet: OAuthRawTokenSet) => OAuthTokenResponse;
38
+ mutexLock: MutexLock;
39
+ authenticator: UserServiceGrpcCaller;
40
+ redis: any;
41
+ PROVIDER_KEY: string;
42
+ constructor({ authenticator, redis }: {
43
+ authenticator: UserServiceGrpcCaller;
44
+ redis: any;
45
+ });
46
+ checkSmartAccessIntegration: ({ accommodationId }: {
47
+ accommodationId: string;
48
+ }) => Promise<boolean>;
49
+ getAccommodationAuthInfo: ({ accommodationId }: {
50
+ accommodationId: string;
51
+ }) => Promise<OAuthTokenResponse>;
52
+ getAccommodationAccessToken: (accommodationId: string) => Promise<string>;
53
+ callSmartAccessApi: ({ route, accommodationId, params, method, headers, }: {
54
+ route: string;
55
+ accommodationId: string;
56
+ params?: any;
57
+ method?: string | undefined;
58
+ headers?: any;
59
+ }) => Promise<any>;
60
+ getRooms: (accommodationId: string) => Promise<SmartAccessRoom[]>;
61
+ getDevices: (accommodationId: string) => Promise<any>;
62
+ getRoomsWithDevices: (accommodationId: string) => Promise<SmartAccessRoom[]>;
63
+ createPinCodeForRoom: ({ roomId, accommodationId, userType, keyType, startDate, endDate, }: {
64
+ roomId: string;
65
+ accommodationId: string;
66
+ userType: 'GUEST' | 'EMPLOYEE';
67
+ keyType: 'SCHEDULE' | 'ONETIME';
68
+ startDate: Date;
69
+ endDate: Date;
70
+ }) => Promise<any>;
71
+ modifyPinCodeByKeyId: ({ keyId, accommodationId, userType, keyType, startDate, endDate, }: {
72
+ keyId: string;
73
+ accommodationId: string;
74
+ userType: 'GUEST' | 'EMPLOYEE';
75
+ keyType: 'SCHEDULE' | 'ONETIME';
76
+ startDate: Date;
77
+ endDate: Date;
78
+ }) => Promise<any>;
79
+ deletePinCodeByKeyId: ({ keyId, accommodationId }: {
80
+ keyId: string;
81
+ accommodationId: string;
82
+ }) => Promise<any>;
83
+ openLockByRoomId: ({ accommodationId, roomId, keyId }: {
84
+ accommodationId: string;
85
+ roomId: string;
86
+ keyId: string;
87
+ }) => Promise<any>;
88
+ getAccommodationCallbacks: ({ accommodationId }: {
89
+ accommodationId: string;
90
+ }) => Promise<boolean>;
91
+ }
92
+ export {};
@@ -0,0 +1,445 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.MutexLock = void 0;
54
+ var node_fetch_1 = __importDefault(require("node-fetch"));
55
+ var moment_1 = __importDefault(require("moment"));
56
+ var uuid_1 = require("uuid");
57
+ var sleep = function (sleepTime) { return new Promise(function (resolve) { return setTimeout(resolve, sleepTime); }); };
58
+ var MutexLock = /** @class */ (function () {
59
+ function MutexLock(_a) {
60
+ var _this = this;
61
+ var redis = _a.redis, hashPrefix = _a.hashPrefix, _b = _a.mutexLockInterval, mutexLockInterval = _b === void 0 ? 50 : _b;
62
+ this.getMutexLockKey = function (id) { return "" + _this.hashPrefix + id; };
63
+ this.tryMutexLock = function (streamId, lockHash) { return _this.redis.set(_this.getMutexLockKey(streamId), lockHash, 'EX', 60, 'NX'); };
64
+ this.getMutexLock = function (streamId) { return __awaiter(_this, void 0, void 0, function () {
65
+ var lockHash, lock;
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0:
69
+ lockHash = uuid_1.v4();
70
+ _a.label = 1;
71
+ case 1:
72
+ if (!!lock) return [3 /*break*/, 4];
73
+ return [4 /*yield*/, this.tryMutexLock(streamId, lockHash)];
74
+ case 2:
75
+ lock = _a.sent(); // eslint-disable-line
76
+ return [4 /*yield*/, sleep(this.mutexLockInterval)];
77
+ case 3:
78
+ _a.sent(); // eslint-disable-line
79
+ return [3 /*break*/, 1];
80
+ case 4: return [2 /*return*/, lockHash];
81
+ }
82
+ });
83
+ }); };
84
+ this.unlockMutexLock = function (streamId, lockHash) { return __awaiter(_this, void 0, void 0, function () {
85
+ var existingLockHash;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0: return [4 /*yield*/, this.redis.get(this.getMutexLockKey(streamId))];
89
+ case 1:
90
+ existingLockHash = _a.sent();
91
+ if (!(existingLockHash === lockHash)) return [3 /*break*/, 3];
92
+ return [4 /*yield*/, this.redis.del(this.getMutexLockKey(streamId))];
93
+ case 2:
94
+ _a.sent();
95
+ return [2 /*return*/, existingLockHash];
96
+ case 3: return [2 /*return*/, null];
97
+ }
98
+ });
99
+ }); };
100
+ this.redis = redis;
101
+ this.hashPrefix = hashPrefix;
102
+ this.mutexLockInterval = mutexLockInterval;
103
+ }
104
+ return MutexLock;
105
+ }());
106
+ exports.MutexLock = MutexLock;
107
+ var SmartAccessAdapter = /** @class */ (function () {
108
+ function SmartAccessAdapter(_a) {
109
+ var _this = this;
110
+ var authenticator = _a.authenticator, redis = _a.redis;
111
+ this.PROVIDER_KEY = 'SamsungSmartAccess';
112
+ this.checkSmartAccessIntegration = function (_a) {
113
+ var accommodationId = _a.accommodationId;
114
+ return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_b) {
115
+ return [2 /*return*/, !!this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
116
+ }); });
117
+ };
118
+ this.getAccommodationAuthInfo = function (_a) {
119
+ var accommodationId = _a.accommodationId;
120
+ return __awaiter(_this, void 0, void 0, function () {
121
+ var existingAuth, lockId, lockHash, newAuth, parsedCredential, err_1;
122
+ return __generator(this, function (_b) {
123
+ switch (_b.label) {
124
+ case 0: return [4 /*yield*/, this.redis.get(SmartAccessAdapter.indexAccommodation({ accommodationId: accommodationId }))];
125
+ case 1:
126
+ existingAuth = _b.sent();
127
+ if (existingAuth) {
128
+ if (existingAuth === 'NOT_FOUND') {
129
+ throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
130
+ }
131
+ return [2 /*return*/, JSON.parse(existingAuth)];
132
+ }
133
+ lockId = "SMARTACCESS-HKEY|" + accommodationId;
134
+ return [4 /*yield*/, this.mutexLock.getMutexLock(lockId)];
135
+ case 2:
136
+ lockHash = _b.sent();
137
+ return [4 /*yield*/, this.redis.get(SmartAccessAdapter.indexAccommodation({ accommodationId: accommodationId }))];
138
+ case 3:
139
+ existingAuth = _b.sent();
140
+ _b.label = 4;
141
+ case 4:
142
+ _b.trys.push([4, 9, 10, 12]);
143
+ if (existingAuth) {
144
+ return [2 /*return*/, JSON.parse(existingAuth)];
145
+ }
146
+ return [4 /*yield*/, this.authenticator.getThirdPartyCredential({ accommodationId: accommodationId, provider: this.PROVIDER_KEY })];
147
+ case 5:
148
+ newAuth = _b.sent();
149
+ if (!!newAuth) return [3 /*break*/, 7];
150
+ return [4 /*yield*/, this.redis.set(SmartAccessAdapter.indexAccommodation({ accommodationId: accommodationId }), 'NOT_FOUND', 'EX', 60 * 5)];
151
+ case 6:
152
+ _b.sent();
153
+ throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
154
+ case 7:
155
+ parsedCredential = JSON.parse(newAuth.credential);
156
+ return [4 /*yield*/, this.redis.set(SmartAccessAdapter.indexAccommodation({ accommodationId: accommodationId }), newAuth.credential, 'EX', 60 * 5)];
157
+ case 8:
158
+ _b.sent();
159
+ return [2 /*return*/, parsedCredential];
160
+ case 9:
161
+ err_1 = _b.sent();
162
+ console.log(err_1);
163
+ throw err_1;
164
+ case 10: return [4 /*yield*/, this.mutexLock.unlockMutexLock(lockId, lockHash)];
165
+ case 11:
166
+ _b.sent();
167
+ return [7 /*endfinally*/];
168
+ case 12: return [2 /*return*/];
169
+ }
170
+ });
171
+ });
172
+ };
173
+ this.getAccommodationAccessToken = function (accommodationId) { return __awaiter(_this, void 0, void 0, function () {
174
+ var authInfo;
175
+ return __generator(this, function (_a) {
176
+ switch (_a.label) {
177
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
178
+ case 1:
179
+ authInfo = _a.sent();
180
+ console.log(authInfo);
181
+ return [2 /*return*/, authInfo.accessToken];
182
+ }
183
+ });
184
+ }); };
185
+ this.callSmartAccessApi = function (_a) {
186
+ var route = _a.route, accommodationId = _a.accommodationId, params = _a.params, _b = _a.method, method = _b === void 0 ? 'post' : _b, headers = _a.headers;
187
+ return __awaiter(_this, void 0, void 0, function () {
188
+ var requestArgs, _c, _d, _e, _f, _g, _h, response, jsonResponse;
189
+ return __generator(this, function (_j) {
190
+ switch (_j.label) {
191
+ case 0:
192
+ _c = [__assign({ method: method }, (method !== 'get' && ({
193
+ body: JSON.stringify(__assign({}, params)),
194
+ })))];
195
+ _d = {};
196
+ _e = [{ 'Content-Type': 'application/json' }];
197
+ _f = accommodationId;
198
+ if (!_f) return [3 /*break*/, 2];
199
+ _g = {};
200
+ _h = "Bearer ";
201
+ return [4 /*yield*/, this.getAccommodationAccessToken(accommodationId)];
202
+ case 1:
203
+ _f = (_g.Authorization = _h + (_j.sent()), _g);
204
+ _j.label = 2;
205
+ case 2:
206
+ requestArgs = __assign.apply(void 0, _c.concat([(_d.headers = __assign.apply(void 0, [__assign.apply(void 0, _e.concat([(_f)])), headers]), _d)]));
207
+ console.log(requestArgs);
208
+ return [4 /*yield*/, node_fetch_1.default("https://oauth-iot-stg.samsung-ihp.com/sa/oauth/" + route, requestArgs)];
209
+ case 3:
210
+ response = _j.sent();
211
+ console.log(response);
212
+ return [4 /*yield*/, response.json()];
213
+ case 4:
214
+ jsonResponse = _j.sent();
215
+ return [2 /*return*/, jsonResponse];
216
+ }
217
+ });
218
+ });
219
+ };
220
+ this.getRooms = function (accommodationId) { return __awaiter(_this, void 0, void 0, function () {
221
+ var roomResponse;
222
+ return __generator(this, function (_a) {
223
+ switch (_a.label) {
224
+ case 0: return [4 /*yield*/, this.callSmartAccessApi({
225
+ accommodationId: accommodationId,
226
+ method: 'get',
227
+ route: 'v1/room/list',
228
+ })];
229
+ case 1:
230
+ roomResponse = _a.sent();
231
+ return [2 /*return*/, roomResponse.roomList];
232
+ }
233
+ });
234
+ }); };
235
+ this.getDevices = function (accommodationId) { return __awaiter(_this, void 0, void 0, function () {
236
+ var deviceResponse;
237
+ return __generator(this, function (_a) {
238
+ switch (_a.label) {
239
+ case 0: return [4 /*yield*/, this.callSmartAccessApi({
240
+ accommodationId: accommodationId,
241
+ method: 'get',
242
+ route: 'v1/device/list',
243
+ })];
244
+ case 1:
245
+ deviceResponse = _a.sent();
246
+ return [2 /*return*/, deviceResponse.lockList];
247
+ }
248
+ });
249
+ }); };
250
+ this.getRoomsWithDevices = function (accommodationId) { return __awaiter(_this, void 0, void 0, function () {
251
+ var rooms, devices, devicesRoomIdMap, roomsWithDevices;
252
+ return __generator(this, function (_a) {
253
+ switch (_a.label) {
254
+ case 0: return [4 /*yield*/, this.getRooms(accommodationId)];
255
+ case 1:
256
+ rooms = _a.sent();
257
+ return [4 /*yield*/, this.getDevices(accommodationId)];
258
+ case 2:
259
+ devices = _a.sent();
260
+ devicesRoomIdMap = devices.reduce(function (acc, device) {
261
+ if (acc[device.roomId]) {
262
+ acc[device.roomId].push(device);
263
+ }
264
+ else {
265
+ acc[device.roomId] = [device];
266
+ }
267
+ return acc;
268
+ }, {});
269
+ roomsWithDevices = rooms.map(function (room) { return (__assign(__assign({}, room), { devices: devicesRoomIdMap[room.roomId] ? devicesRoomIdMap[room.roomId] : [] })); });
270
+ return [2 /*return*/, roomsWithDevices];
271
+ }
272
+ });
273
+ }); };
274
+ this.createPinCodeForRoom = function (_a) {
275
+ var roomId = _a.roomId, accommodationId = _a.accommodationId, userType = _a.userType, keyType = _a.keyType, startDate = _a.startDate, endDate = _a.endDate;
276
+ return __awaiter(_this, void 0, void 0, function () {
277
+ var foundProperty, data, parsedProperty, pinCodeResult, keyId, pinCodeQuery;
278
+ return __generator(this, function (_b) {
279
+ switch (_b.label) {
280
+ case 0: return [4 /*yield*/, this.authenticator.getThirdPartyPropertyByRelatedId({
281
+ accommodationId: accommodationId,
282
+ provider: this.PROVIDER_KEY, relatedId: roomId, type: 'room',
283
+ })];
284
+ case 1:
285
+ foundProperty = _b.sent();
286
+ if (!(foundProperty === null || foundProperty === void 0 ? void 0 : foundProperty.result)) return [3 /*break*/, 4];
287
+ data = foundProperty.data;
288
+ parsedProperty = JSON.parse(data);
289
+ return [4 /*yield*/, this.callSmartAccessApi({
290
+ accommodationId: accommodationId,
291
+ route: 'v1/key/pincode',
292
+ params: {
293
+ userType: userType,
294
+ keyType: keyType,
295
+ pinCode: null,
296
+ roomId: parsedProperty.thirdPartyId,
297
+ accessStartDate: moment_1.default(startDate).add(9, 'hours').format('YYYYMMDDHHmm'),
298
+ accessEndDate: moment_1.default(endDate).add(9, 'hours').format('YYYYMMDDHHmm'),
299
+ },
300
+ })];
301
+ case 2:
302
+ pinCodeResult = _b.sent();
303
+ keyId = pinCodeResult.keyId;
304
+ return [4 /*yield*/, this.callSmartAccessApi({
305
+ accommodationId: accommodationId,
306
+ method: 'get',
307
+ route: "v1/key/" + keyId + "/pincode",
308
+ })];
309
+ case 3:
310
+ pinCodeQuery = _b.sent();
311
+ return [2 /*return*/, __assign(__assign({}, pinCodeQuery.lockList[0]), { keyId: keyId })];
312
+ case 4: return [2 /*return*/];
313
+ }
314
+ });
315
+ });
316
+ };
317
+ this.modifyPinCodeByKeyId = function (_a) {
318
+ var keyId = _a.keyId, accommodationId = _a.accommodationId, userType = _a.userType, keyType = _a.keyType, startDate = _a.startDate, endDate = _a.endDate;
319
+ return __awaiter(_this, void 0, void 0, function () {
320
+ var pinCodeResult, pinCodeQuery;
321
+ return __generator(this, function (_b) {
322
+ switch (_b.label) {
323
+ case 0: return [4 /*yield*/, this.callSmartAccessApi({
324
+ accommodationId: accommodationId,
325
+ method: 'put',
326
+ route: "v1/key/" + keyId + "/pincode",
327
+ params: {
328
+ userType: userType,
329
+ keyType: keyType,
330
+ accessStartDate: moment_1.default(startDate).add(9, 'hours').format('YYYYMMDDHHmm'),
331
+ accessEndDate: moment_1.default(endDate).add(9, 'hours').format('YYYYMMDDHHmm'),
332
+ },
333
+ })];
334
+ case 1:
335
+ pinCodeResult = _b.sent();
336
+ return [4 /*yield*/, this.callSmartAccessApi({
337
+ accommodationId: accommodationId,
338
+ method: 'get',
339
+ route: "v1/key/" + keyId + "/pincode",
340
+ })];
341
+ case 2:
342
+ pinCodeQuery = _b.sent();
343
+ return [2 /*return*/, __assign(__assign({}, pinCodeQuery.lockList[0]), { keyId: keyId })];
344
+ }
345
+ });
346
+ });
347
+ };
348
+ this.deletePinCodeByKeyId = function (_a) {
349
+ var keyId = _a.keyId, accommodationId = _a.accommodationId;
350
+ return __awaiter(_this, void 0, void 0, function () {
351
+ var pinCodeResult;
352
+ return __generator(this, function (_b) {
353
+ switch (_b.label) {
354
+ case 0: return [4 /*yield*/, this.callSmartAccessApi({
355
+ accommodationId: accommodationId,
356
+ method: 'put',
357
+ route: "v1/key/" + keyId + "/delete",
358
+ })];
359
+ case 1:
360
+ pinCodeResult = _b.sent();
361
+ return [2 /*return*/, pinCodeResult];
362
+ }
363
+ });
364
+ });
365
+ };
366
+ this.openLockByRoomId = function (_a) {
367
+ var accommodationId = _a.accommodationId, roomId = _a.roomId, keyId = _a.keyId;
368
+ return __awaiter(_this, void 0, void 0, function () {
369
+ var foundRoomProperty, foundDoorlockProperty, data, parsedProperty, deviceId, res;
370
+ return __generator(this, function (_b) {
371
+ switch (_b.label) {
372
+ case 0: return [4 /*yield*/, this.authenticator.getThirdPartyPropertyByRelatedId({
373
+ accommodationId: accommodationId,
374
+ provider: this.PROVIDER_KEY, relatedId: roomId, type: 'room',
375
+ })];
376
+ case 1:
377
+ foundRoomProperty = _b.sent();
378
+ if (!(foundRoomProperty === null || foundRoomProperty === void 0 ? void 0 : foundRoomProperty.result))
379
+ return [2 /*return*/, false];
380
+ return [4 /*yield*/, this.authenticator.getThirdPartyPropertyByRelatedId({
381
+ accommodationId: accommodationId,
382
+ provider: this.PROVIDER_KEY, relatedId: JSON.parse(foundRoomProperty.data).thirdPartyId, type: 'doorlock',
383
+ })];
384
+ case 2:
385
+ foundDoorlockProperty = _b.sent();
386
+ if (!(foundDoorlockProperty === null || foundDoorlockProperty === void 0 ? void 0 : foundDoorlockProperty.result)) return [3 /*break*/, 4];
387
+ data = foundDoorlockProperty.data;
388
+ parsedProperty = JSON.parse(data);
389
+ deviceId = parsedProperty.thirdPartyId;
390
+ return [4 /*yield*/, this.callSmartAccessApi({
391
+ accommodationId: accommodationId,
392
+ route: "v1/device/" + deviceId + "/open",
393
+ params: {
394
+ keyId: keyId,
395
+ },
396
+ })];
397
+ case 3:
398
+ res = _b.sent();
399
+ console.log(res);
400
+ return [2 /*return*/, true];
401
+ case 4: return [2 /*return*/];
402
+ }
403
+ });
404
+ });
405
+ };
406
+ this.getAccommodationCallbacks = function (_a) {
407
+ var accommodationId = _a.accommodationId;
408
+ return __awaiter(_this, void 0, void 0, function () {
409
+ var response;
410
+ return __generator(this, function (_b) {
411
+ switch (_b.label) {
412
+ case 0: return [4 /*yield*/, this.callSmartAccessApi({
413
+ accommodationId: accommodationId,
414
+ method: 'get',
415
+ route: 'v1/callback/access',
416
+ })];
417
+ case 1:
418
+ response = _b.sent();
419
+ console.log(response);
420
+ return [2 /*return*/, true];
421
+ }
422
+ });
423
+ });
424
+ };
425
+ this.authenticator = authenticator;
426
+ this.redis = redis;
427
+ this.mutexLock = new MutexLock({ hashPrefix: 'RES_SMARTACCESS_MUTEX_', mutexLockInterval: 50, redis: redis });
428
+ }
429
+ SmartAccessAdapter.indexAccommodation = function (_a) {
430
+ var accommodationId = _a.accommodationId;
431
+ return "AUTH|SMARTACCESS-API|" + accommodationId;
432
+ };
433
+ SmartAccessAdapter.refineRawTokenSet = function (rawTokenSet) {
434
+ var refreshToken = rawTokenSet.refresh_token, accessToken = rawTokenSet.access_token, expiresIn = rawTokenSet.expires_in, tokenType = rawTokenSet.token_type;
435
+ var tokenSet = {
436
+ refreshToken: refreshToken,
437
+ accessToken: accessToken,
438
+ expiresIn: expiresIn,
439
+ tokenType: tokenType,
440
+ };
441
+ return tokenSet;
442
+ };
443
+ return SmartAccessAdapter;
444
+ }());
445
+ exports.default = SmartAccessAdapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendit-dev/thirdparty-adapters",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Third party adapters between v-cloud and other PMS/CMS providers.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -24,7 +24,7 @@
24
24
  "@types/node-fetch": "^2.6.1",
25
25
  "@typescript-eslint/eslint-plugin": "^3.6.1",
26
26
  "@typescript-eslint/parser": "^3.6.1",
27
- "@vendit-dev/utility-modules": "^0.10.3",
27
+ "@vendit-dev/utility-modules": "^0.11.1",
28
28
  "babel-eslint": "^10.1.0",
29
29
  "babel-plugin-module-resolver": "^4.0.0",
30
30
  "cross-env": "^7.0.2",