@vendit-dev/thirdparty-adapters 0.3.31 → 0.4.0-beta.10

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,60 @@
1
+ import { UserServiceGrpcCaller } from '@vendit-dev/utility-modules';
2
+ import { AmanoHttpResponse, DeletePreDiscountInfoInput, DeletePreDiscountInfoResponse, FeeCarSearchInput, GetFeeCarSearchResponse, GetPreDiscountListInfoResponse, InsertPreDiscountInfoInput, InsertPreDiscountInfoResponse, PreDiscountListInfoInput, UpdatePreDiscountInfoInput, UpdatePreDiscountInfoResponse } from '../types/amanoKorea';
3
+ import MutexLock from '../utils/mutex';
4
+ declare type VenditAmanoKoreaAuthInfo = {
5
+ scope: string;
6
+ credential: {
7
+ lotAreaNo: string;
8
+ registUserId: string;
9
+ password: string;
10
+ eqpmNo: string;
11
+ discCodeNo: string;
12
+ };
13
+ };
14
+ export default class AmanoKoreaAdapter {
15
+ API_HOST: string;
16
+ API_PORT: number;
17
+ authenticator: UserServiceGrpcCaller;
18
+ redis: any;
19
+ PROVIDER_KEY: string;
20
+ mutexLock: MutexLock;
21
+ authorization: string;
22
+ dateFormat: string;
23
+ lotAreaNo: number;
24
+ discCodeNo: number;
25
+ constructor({ authenticator, redis, }: {
26
+ authenticator: UserServiceGrpcCaller;
27
+ redis: any;
28
+ });
29
+ parseJSONSafe: (str: string) => any | boolean;
30
+ static indexAccommodation: ({ accommodationId, }: {
31
+ accommodationId: string;
32
+ }) => string;
33
+ checkAmanoKoreaIntegration: ({ accommodationId, }: {
34
+ accommodationId: string;
35
+ }) => Promise<boolean>;
36
+ getAccommodationAuthInfo: ({ accommodationId, }: {
37
+ accommodationId: string;
38
+ }) => Promise<VenditAmanoKoreaAuthInfo | boolean>;
39
+ setAuthorization: ({ authorization }: {
40
+ authorization: string;
41
+ }) => void;
42
+ callAPI: <TRequestType, TReturnType extends AmanoHttpResponse<any> = AmanoHttpResponse<any>, TErrorType extends AmanoHttpResponse<any> = AmanoHttpResponse<any>>({ directory, resources, }: {
43
+ directory: string;
44
+ resources: TRequestType;
45
+ }) => Promise<TReturnType | TErrorType>;
46
+ getPreDiscountListInfo: (resources: PreDiscountListInfoInput) => Promise<AmanoHttpResponse<GetPreDiscountListInfoResponse>>;
47
+ insertPreDiscountInfo: ({ resources, }: {
48
+ resources: InsertPreDiscountInfoInput;
49
+ }) => Promise<AmanoHttpResponse<InsertPreDiscountInfoResponse>>;
50
+ updatePreDiscountInfo: ({ resources, }: {
51
+ resources: UpdatePreDiscountInfoInput;
52
+ }) => Promise<AmanoHttpResponse<UpdatePreDiscountInfoResponse>>;
53
+ deletePreDiscountInfo: ({ resources, }: {
54
+ resources: DeletePreDiscountInfoInput;
55
+ }) => Promise<AmanoHttpResponse<DeletePreDiscountInfoResponse>>;
56
+ getFeeCarSearch: ({ resources, }: {
57
+ resources: FeeCarSearchInput;
58
+ }) => Promise<AmanoHttpResponse<GetFeeCarSearchResponse>>;
59
+ }
60
+ export {};
@@ -0,0 +1,303 @@
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
+ var node_fetch_1 = __importDefault(require("node-fetch"));
54
+ var mutex_1 = __importDefault(require("../utils/mutex"));
55
+ var AmanoKoreaAdapter = /** @class */ (function () {
56
+ function AmanoKoreaAdapter(_a) {
57
+ var _this = this;
58
+ var authenticator = _a.authenticator, redis = _a.redis;
59
+ this.API_PORT = 9948;
60
+ this.PROVIDER_KEY = 'AmanoKorea';
61
+ // base64
62
+ this.authorization = '';
63
+ this.dateFormat = 'YYYYMMDDHHmmss';
64
+ this.lotAreaNo = 20;
65
+ this.discCodeNo = 99;
66
+ this.parseJSONSafe = function (str) {
67
+ try {
68
+ return JSON.parse(str);
69
+ }
70
+ catch (e) {
71
+ console.log('parseJSONSafe', e);
72
+ return false;
73
+ }
74
+ };
75
+ this.checkAmanoKoreaIntegration = function (_a) {
76
+ var accommodationId = _a.accommodationId;
77
+ return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_b) {
78
+ switch (_b.label) {
79
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
80
+ case 1: return [2 /*return*/, !!(_b.sent())];
81
+ }
82
+ }); });
83
+ };
84
+ this.getAccommodationAuthInfo = function (_a) {
85
+ var accommodationId = _a.accommodationId;
86
+ return __awaiter(_this, void 0, void 0, function () {
87
+ var existingAuth, parsedCredential, lockId, lockHash, parsedCredential_1, newAuth, parsedCredential, err_1;
88
+ return __generator(this, function (_b) {
89
+ switch (_b.label) {
90
+ case 0: return [4 /*yield*/, this.redis.get(AmanoKoreaAdapter.indexAccommodation({ accommodationId: accommodationId }))];
91
+ case 1:
92
+ existingAuth = _b.sent();
93
+ console.log('🚀 ~ file: amanoKorea.ts:113 ~ AmanoKoreaAdapter ~ existingAuth:', existingAuth);
94
+ if (existingAuth) {
95
+ parsedCredential = this.parseJSONSafe(existingAuth);
96
+ console.log('🚀 ~ file: amanoKorea.ts:111 ~ AmanoKoreaAdapter ~ parsedCredential:', parsedCredential);
97
+ if (parsedCredential === null || parsedCredential === void 0 ? void 0 : parsedCredential.authorization) {
98
+ this.setAuthorization({
99
+ authorization: parsedCredential.authorization,
100
+ });
101
+ this.API_HOST = parsedCredential.apiHost;
102
+ }
103
+ return [2 /*return*/, this.parseJSONSafe(existingAuth)];
104
+ }
105
+ lockId = "AMANO-HKEY|" + accommodationId;
106
+ return [4 /*yield*/, this.mutexLock.getMutexLock(lockId)];
107
+ case 2:
108
+ lockHash = _b.sent();
109
+ return [4 /*yield*/, this.redis.get(AmanoKoreaAdapter.indexAccommodation({ accommodationId: accommodationId }))];
110
+ case 3:
111
+ existingAuth = _b.sent();
112
+ _b.label = 4;
113
+ case 4:
114
+ _b.trys.push([4, 9, 10, 12]);
115
+ if (existingAuth) {
116
+ parsedCredential_1 = this.parseJSONSafe(existingAuth);
117
+ console.log('🚀 ~ file: amanoKorea.ts:124 ~ AmanoKoreaAdapter ~ parsedCredential:', parsedCredential_1);
118
+ if (parsedCredential_1 === null || parsedCredential_1 === void 0 ? void 0 : parsedCredential_1.authorization) {
119
+ this.setAuthorization({
120
+ authorization: parsedCredential_1.authorization,
121
+ });
122
+ this.API_HOST = parsedCredential_1.apiHost;
123
+ }
124
+ return [2 /*return*/, this.parseJSONSafe(existingAuth)];
125
+ }
126
+ return [4 /*yield*/, this.authenticator.getThirdPartyCredential({
127
+ accommodationId: accommodationId,
128
+ provider: this.PROVIDER_KEY,
129
+ })];
130
+ case 5:
131
+ newAuth = _b.sent();
132
+ if (!(!newAuth || !(newAuth === null || newAuth === void 0 ? void 0 : newAuth.credential))) return [3 /*break*/, 7];
133
+ return [4 /*yield*/, this.redis.set(AmanoKoreaAdapter.indexAccommodation({ accommodationId: accommodationId }), 'NOT_FOUND', 'EX', 60 * 5)];
134
+ case 6:
135
+ _b.sent();
136
+ return [2 /*return*/, false];
137
+ case 7:
138
+ parsedCredential = this.parseJSONSafe(newAuth.credential);
139
+ console.log('🚀 ~ file: amanoKorea.ts:151 ~ AmanoKoreaAdapter ~ parsedCredential:', parsedCredential);
140
+ if (parsedCredential === null || parsedCredential === void 0 ? void 0 : parsedCredential.authorization) {
141
+ this.setAuthorization({
142
+ authorization: parsedCredential.authorization,
143
+ });
144
+ this.API_HOST = parsedCredential.apiHost;
145
+ }
146
+ else {
147
+ throw new Error('Authorization is not found');
148
+ }
149
+ return [4 /*yield*/, this.redis.set(AmanoKoreaAdapter.indexAccommodation({ accommodationId: accommodationId }), JSON.stringify(newAuth), 'EX', 60 * 5)];
150
+ case 8:
151
+ _b.sent();
152
+ return [2 /*return*/, parsedCredential];
153
+ case 9:
154
+ err_1 = _b.sent();
155
+ console.log(err_1);
156
+ throw err_1;
157
+ case 10: return [4 /*yield*/, this.mutexLock.unlockMutexLock(lockId, lockHash)];
158
+ case 11:
159
+ _b.sent();
160
+ return [7 /*endfinally*/];
161
+ case 12: return [2 /*return*/];
162
+ }
163
+ });
164
+ });
165
+ };
166
+ this.setAuthorization = function (_a) {
167
+ var authorization = _a.authorization;
168
+ _this.authorization = authorization;
169
+ };
170
+ this.callAPI = function (_a) {
171
+ var directory = _a.directory, resources = _a.resources;
172
+ return __awaiter(_this, void 0, void 0, function () {
173
+ var fetchResult, fetchResultJson, data, err_2;
174
+ return __generator(this, function (_b) {
175
+ switch (_b.label) {
176
+ case 0:
177
+ console.log('callAPI', this.authorization);
178
+ _b.label = 1;
179
+ case 1:
180
+ _b.trys.push([1, 4, , 5]);
181
+ return [4 /*yield*/, node_fetch_1.default(this.API_HOST + ":" + this.API_PORT + "/interop/" + directory, {
182
+ method: 'POST',
183
+ headers: {
184
+ 'Content-Type': 'application/json',
185
+ Authorization: this.authorization,
186
+ },
187
+ body: JSON.stringify(__assign({}, resources)),
188
+ })];
189
+ case 2:
190
+ fetchResult = _b.sent();
191
+ console.log('fetchResult', fetchResult);
192
+ return [4 /*yield*/, (fetchResult === null || fetchResult === void 0 ? void 0 : fetchResult.json())];
193
+ case 3:
194
+ fetchResultJson = _b.sent();
195
+ console.log('🚀 ~ file: amanoKorea.ts:221 ~ AmanoKoreaAdapter ~ fetchResultJson:', fetchResultJson);
196
+ data = fetchResultJson.data;
197
+ return [2 /*return*/, data];
198
+ case 4:
199
+ err_2 = _b.sent();
200
+ console.error('err', err_2);
201
+ return [2 /*return*/, err_2];
202
+ case 5: return [2 /*return*/];
203
+ }
204
+ });
205
+ });
206
+ };
207
+ // syncTimeToMCS = async (): Promise<string> => {
208
+ // const fetchRes = await fetch(
209
+ // `${'http://deploy.amanopark.co.kr:9848/getTime'}`,
210
+ // {
211
+ // method: 'POST',
212
+ // headers: {
213
+ // 'Content-Type': 'application/json',
214
+ // Authorization: this.authorization,
215
+ // },
216
+ // body: JSON.stringify({}),
217
+ // },
218
+ // );
219
+ // const fetchResJson = await fetchRes.json();
220
+ // return fetchResJson;
221
+ // };
222
+ // 방문차량 등록 내역 조회
223
+ this.getPreDiscountListInfo = function (resources) { return __awaiter(_this, void 0, void 0, function () {
224
+ return __generator(this, function (_a) {
225
+ return [2 /*return*/, this.callAPI({
226
+ directory: 'getPreDiscountListInfo.do',
227
+ resources: resources,
228
+ })];
229
+ });
230
+ }); };
231
+ // 방문차량 등록
232
+ this.insertPreDiscountInfo = function (_a) {
233
+ var resources = _a.resources;
234
+ return __awaiter(_this, void 0, void 0, function () {
235
+ var _b, lotAreaNo, discCodeNo;
236
+ return __generator(this, function (_c) {
237
+ _b = this, lotAreaNo = _b.lotAreaNo, discCodeNo = _b.discCodeNo;
238
+ return [2 /*return*/, this.callAPI({
239
+ directory: 'insertPreDiscountInfo.do',
240
+ resources: __assign(__assign({}, resources), { lotAreaNo: lotAreaNo,
241
+ discCodeNo: discCodeNo }),
242
+ })];
243
+ });
244
+ });
245
+ };
246
+ // 방문차량 수정
247
+ this.updatePreDiscountInfo = function (_a) {
248
+ var resources = _a.resources;
249
+ return __awaiter(_this, void 0, void 0, function () {
250
+ var _b, lotAreaNo, discCodeNo;
251
+ return __generator(this, function (_c) {
252
+ _b = this, lotAreaNo = _b.lotAreaNo, discCodeNo = _b.discCodeNo;
253
+ return [2 /*return*/, this.callAPI({
254
+ directory: 'updatePreDiscountInfo.do',
255
+ resources: __assign(__assign({}, resources), { lotAreaNo: lotAreaNo,
256
+ discCodeNo: discCodeNo }),
257
+ })];
258
+ });
259
+ });
260
+ };
261
+ // 방문차량 삭제
262
+ this.deletePreDiscountInfo = function (_a) {
263
+ var resources = _a.resources;
264
+ return __awaiter(_this, void 0, void 0, function () {
265
+ var lotAreaNo;
266
+ return __generator(this, function (_b) {
267
+ lotAreaNo = this.lotAreaNo;
268
+ return [2 /*return*/, this.callAPI({
269
+ directory: 'deletePreDiscountInfo.do',
270
+ resources: __assign(__assign({}, resources), { lotAreaNo: lotAreaNo }),
271
+ })];
272
+ });
273
+ });
274
+ };
275
+ // 차량 조회 (요금 조회 대상)
276
+ this.getFeeCarSearch = function (_a) {
277
+ var resources = _a.resources;
278
+ return __awaiter(_this, void 0, void 0, function () {
279
+ var lotAreaNo;
280
+ return __generator(this, function (_b) {
281
+ lotAreaNo = this.lotAreaNo;
282
+ return [2 /*return*/, this.callAPI({
283
+ directory: 'getFeeCarSearch.do',
284
+ resources: __assign(__assign({}, resources), { lotAreaNo: lotAreaNo }),
285
+ })];
286
+ });
287
+ });
288
+ };
289
+ this.authenticator = authenticator;
290
+ this.redis = redis;
291
+ this.mutexLock = new mutex_1.default({
292
+ hashPrefix: 'RES_AMANO_MUTEX_',
293
+ mutexLockInterval: 50,
294
+ redis: redis,
295
+ });
296
+ }
297
+ AmanoKoreaAdapter.indexAccommodation = function (_a) {
298
+ var accommodationId = _a.accommodationId;
299
+ return "AUTH|AMANO-KOREA-API|" + accommodationId;
300
+ };
301
+ return AmanoKoreaAdapter;
302
+ }());
303
+ exports.default = AmanoKoreaAdapter;
@@ -1,18 +1,5 @@
1
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
- }
2
+ import MutexLock from '../utils/mutex';
16
3
  declare type OAuthTokenResponse = {
17
4
  accessToken: string;
18
5
  refreshToken: string;
@@ -31,7 +18,7 @@ declare type SmartAccessRoom = {
31
18
  path: string;
32
19
  };
33
20
  export default class SmartAccessAdapter {
34
- static indexAccommodation: ({ accommodationId }: {
21
+ static indexAccommodation: ({ accommodationId, }: {
35
22
  accommodationId: string;
36
23
  }) => string;
37
24
  static refineRawTokenSet: (rawTokenSet: OAuthRawTokenSet) => OAuthTokenResponse;
@@ -40,16 +27,16 @@ export default class SmartAccessAdapter {
40
27
  redis: any;
41
28
  PROVIDER_KEY: string;
42
29
  API_HOST: string;
43
- constructor({ authenticator, redis, apiHost }: {
30
+ constructor({ authenticator, redis, apiHost, }: {
44
31
  authenticator: UserServiceGrpcCaller;
45
32
  redis: any;
46
33
  apiHost: string;
47
34
  });
48
35
  parseJSONSafe: (str: string) => any | boolean;
49
- checkSmartAccessIntegration: ({ accommodationId }: {
36
+ checkSmartAccessIntegration: ({ accommodationId, }: {
50
37
  accommodationId: string;
51
38
  }) => Promise<boolean>;
52
- getAccommodationAuthInfo: ({ accommodationId }: {
39
+ getAccommodationAuthInfo: ({ accommodationId, }: {
53
40
  accommodationId: string;
54
41
  }) => Promise<OAuthTokenResponse | boolean>;
55
42
  getAccommodationAccessToken: (accommodationId: string) => Promise<string>;
@@ -60,7 +47,7 @@ export default class SmartAccessAdapter {
60
47
  method?: string | undefined;
61
48
  headers?: any;
62
49
  }) => Promise<any>;
63
- getRoomInfo: ({ accommodationId, roomId }: {
50
+ getRoomInfo: ({ accommodationId, roomId, }: {
64
51
  accommodationId: string;
65
52
  roomId: string;
66
53
  }) => Promise<SmartAccessRoom>;
@@ -83,19 +70,19 @@ export default class SmartAccessAdapter {
83
70
  startDate: Date;
84
71
  endDate: Date;
85
72
  }) => Promise<any>;
86
- deletePinCodeByKeyId: ({ keyId, accommodationId }: {
73
+ deletePinCodeByKeyId: ({ keyId, accommodationId, }: {
87
74
  keyId: string;
88
75
  accommodationId: string;
89
76
  }) => Promise<any>;
90
- openLockByRoomId: ({ accommodationId, roomId, keyId }: {
77
+ openLockByRoomId: ({ accommodationId, roomId, keyId, }: {
91
78
  accommodationId: string;
92
79
  roomId: string;
93
80
  keyId: string;
94
81
  }) => Promise<any>;
95
- getAccommodationCallbacks: ({ accommodationId }: {
82
+ getAccommodationCallbacks: ({ accommodationId, }: {
96
83
  accommodationId: string;
97
84
  }) => Promise<boolean>;
98
- getRoomByThirdPartyId: ({ accommodationId, thirdPartyId }: {
85
+ getRoomByThirdPartyId: ({ accommodationId, thirdPartyId, }: {
99
86
  accommodationId: string;
100
87
  thirdPartyId: string;
101
88
  }) => Promise<any>;
@@ -50,60 +50,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.MutexLock = void 0;
54
- var node_fetch_1 = __importDefault(require("node-fetch"));
55
53
  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;
54
+ var node_fetch_1 = __importDefault(require("node-fetch"));
55
+ var mutex_1 = __importDefault(require("../utils/mutex"));
107
56
  var SmartAccessAdapter = /** @class */ (function () {
108
57
  function SmartAccessAdapter(_a) {
109
58
  var _this = this;
@@ -155,7 +104,10 @@ var SmartAccessAdapter = /** @class */ (function () {
155
104
  if (existingAuth) {
156
105
  return [2 /*return*/, this.parseJSONSafe(existingAuth)];
157
106
  }
158
- return [4 /*yield*/, this.authenticator.getThirdPartyCredential({ accommodationId: accommodationId, provider: this.PROVIDER_KEY })];
107
+ return [4 /*yield*/, this.authenticator.getThirdPartyCredential({
108
+ accommodationId: accommodationId,
109
+ provider: this.PROVIDER_KEY,
110
+ })];
159
111
  case 5:
160
112
  newAuth = _b.sent();
161
113
  if (!(!newAuth || !(newAuth === null || newAuth === void 0 ? void 0 : newAuth.credential))) return [3 /*break*/, 7];
@@ -186,9 +138,11 @@ var SmartAccessAdapter = /** @class */ (function () {
186
138
  var authInfo;
187
139
  return __generator(this, function (_a) {
188
140
  switch (_a.label) {
189
- case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
141
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({
142
+ accommodationId: accommodationId,
143
+ })];
190
144
  case 1:
191
- authInfo = _a.sent();
145
+ authInfo = (_a.sent());
192
146
  if (!(authInfo === null || authInfo === void 0 ? void 0 : authInfo.accessToken))
193
147
  throw new Error('THIRDPARTH_AUTH_NOT_FOUND');
194
148
  return [2 /*return*/, authInfo.accessToken];
@@ -202,9 +156,9 @@ var SmartAccessAdapter = /** @class */ (function () {
202
156
  return __generator(this, function (_j) {
203
157
  switch (_j.label) {
204
158
  case 0:
205
- _c = [__assign({ method: method }, (method !== 'get' && ({
159
+ _c = [__assign({ method: method }, (method !== 'get' && {
206
160
  body: JSON.stringify(__assign({}, params)),
207
- })))];
161
+ }))];
208
162
  _d = {};
209
163
  _e = [{ 'Content-Type': 'application/json' }];
210
164
  _f = accommodationId;
@@ -213,7 +167,8 @@ var SmartAccessAdapter = /** @class */ (function () {
213
167
  _h = "Bearer ";
214
168
  return [4 /*yield*/, this.getAccommodationAccessToken(accommodationId)];
215
169
  case 1:
216
- _f = (_g.Authorization = _h + (_j.sent()), _g);
170
+ _f = (_g.Authorization = _h + (_j.sent()),
171
+ _g);
217
172
  _j.label = 2;
218
173
  case 2:
219
174
  requestArgs = __assign.apply(void 0, _c.concat([(_d.headers = __assign.apply(void 0, [__assign.apply(void 0, _e.concat([(_f)])), headers]), _d)]));
@@ -295,7 +250,9 @@ var SmartAccessAdapter = /** @class */ (function () {
295
250
  }
296
251
  return acc;
297
252
  }, {});
298
- roomsWithDevices = rooms.map(function (room) { return (__assign(__assign({}, room), { devices: devicesRoomIdMap[room.roomId] ? devicesRoomIdMap[room.roomId] : [] })); });
253
+ roomsWithDevices = rooms.map(function (room) { return (__assign(__assign({}, room), { devices: devicesRoomIdMap[room.roomId]
254
+ ? devicesRoomIdMap[room.roomId]
255
+ : [] })); });
299
256
  return [2 /*return*/, roomsWithDevices];
300
257
  }
301
258
  });
@@ -308,7 +265,9 @@ var SmartAccessAdapter = /** @class */ (function () {
308
265
  switch (_b.label) {
309
266
  case 0: return [4 /*yield*/, this.authenticator.getThirdPartyPropertyByRelatedId({
310
267
  accommodationId: accommodationId,
311
- provider: this.PROVIDER_KEY, relatedId: roomId, type: 'room',
268
+ provider: this.PROVIDER_KEY,
269
+ relatedId: roomId,
270
+ type: 'room',
312
271
  })];
313
272
  case 1:
314
273
  foundProperty = _b.sent();
@@ -323,7 +282,9 @@ var SmartAccessAdapter = /** @class */ (function () {
323
282
  keyType: keyType,
324
283
  pinCode: null,
325
284
  roomId: parsedProperty.thirdPartyId,
326
- accessStartDate: moment_1.default(startDate).add(9, 'hours').format('YYYYMMDDHHmm'),
285
+ accessStartDate: moment_1.default(startDate)
286
+ .add(9, 'hours')
287
+ .format('YYYYMMDDHHmm'),
327
288
  accessEndDate: moment_1.default(endDate).add(9, 'hours').format('YYYYMMDDHHmm'),
328
289
  },
329
290
  })];
@@ -356,7 +317,9 @@ var SmartAccessAdapter = /** @class */ (function () {
356
317
  params: {
357
318
  userType: userType,
358
319
  keyType: keyType,
359
- accessStartDate: moment_1.default(startDate).add(9, 'hours').format('YYYYMMDDHHmm'),
320
+ accessStartDate: moment_1.default(startDate)
321
+ .add(9, 'hours')
322
+ .format('YYYYMMDDHHmm'),
360
323
  accessEndDate: moment_1.default(endDate).add(9, 'hours').format('YYYYMMDDHHmm'),
361
324
  },
362
325
  })];
@@ -400,7 +363,9 @@ var SmartAccessAdapter = /** @class */ (function () {
400
363
  switch (_b.label) {
401
364
  case 0: return [4 /*yield*/, this.authenticator.getThirdPartyPropertyByRelatedId({
402
365
  accommodationId: accommodationId,
403
- provider: this.PROVIDER_KEY, relatedId: roomId, type: 'room',
366
+ provider: this.PROVIDER_KEY,
367
+ relatedId: roomId,
368
+ type: 'room',
404
369
  })];
405
370
  case 1:
406
371
  foundRoomProperty = _b.sent();
@@ -408,7 +373,9 @@ var SmartAccessAdapter = /** @class */ (function () {
408
373
  return [2 /*return*/, false];
409
374
  return [4 /*yield*/, this.authenticator.getThirdPartyPropertyByRelatedId({
410
375
  accommodationId: accommodationId,
411
- provider: this.PROVIDER_KEY, relatedId: JSON.parse(foundRoomProperty.data).thirdPartyId, type: 'doorlock',
376
+ provider: this.PROVIDER_KEY,
377
+ relatedId: JSON.parse(foundRoomProperty.data).thirdPartyId,
378
+ type: 'doorlock',
412
379
  })];
413
380
  case 2:
414
381
  foundDoorlockProperty = _b.sent();
@@ -473,7 +440,11 @@ var SmartAccessAdapter = /** @class */ (function () {
473
440
  this.authenticator = authenticator;
474
441
  this.API_HOST = apiHost;
475
442
  this.redis = redis;
476
- this.mutexLock = new MutexLock({ hashPrefix: 'RES_SMARTACCESS_MUTEX_', mutexLockInterval: 50, redis: redis });
443
+ this.mutexLock = new mutex_1.default({
444
+ hashPrefix: 'RES_SMARTACCESS_MUTEX_',
445
+ mutexLockInterval: 50,
446
+ redis: redis,
447
+ });
477
448
  }
478
449
  SmartAccessAdapter.indexAccommodation = function (_a) {
479
450
  var accommodationId = _a.accommodationId;
@@ -50,12 +50,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- /* eslint-disable camelcase */
54
- /* eslint-disable indent */
55
- /* eslint-disable no-mixed-spaces-and-tabs */
56
- /* eslint-disable no-tabs */
57
- var node_fetch_1 = __importDefault(require("node-fetch"));
58
53
  var moment_1 = __importDefault(require("moment"));
54
+ var node_fetch_1 = __importDefault(require("node-fetch"));
59
55
  var mutex_1 = __importDefault(require("../utils/mutex"));
60
56
  var ThemrIoTAdapter = /** @class */ (function () {
61
57
  function ThemrIoTAdapter(_a) {
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
+ import AmanoKoreaAdapter from './adapters/amanoKorea';
1
2
  import SanhaWingsAdapter from './adapters/sanhaWings';
2
3
  import SmartAccessAdapter from './adapters/smartAccess';
3
4
  import ThemrIoTAdapter from './adapters/themrIoT';
4
- export { SanhaWingsAdapter, SmartAccessAdapter, ThemrIoTAdapter as TheMRIoTAdapter, };
5
+ export { AmanoKoreaAdapter, SanhaWingsAdapter, SmartAccessAdapter, ThemrIoTAdapter as TheMRIoTAdapter, };
package/lib/index.js CHANGED
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TheMRIoTAdapter = exports.SmartAccessAdapter = exports.SanhaWingsAdapter = void 0;
6
+ exports.TheMRIoTAdapter = exports.SmartAccessAdapter = exports.SanhaWingsAdapter = exports.AmanoKoreaAdapter = void 0;
7
+ var amanoKorea_1 = __importDefault(require("./adapters/amanoKorea"));
8
+ exports.AmanoKoreaAdapter = amanoKorea_1.default;
7
9
  var sanhaWings_1 = __importDefault(require("./adapters/sanhaWings"));
8
10
  exports.SanhaWingsAdapter = sanhaWings_1.default;
9
11
  var smartAccess_1 = __importDefault(require("./adapters/smartAccess"));
@@ -0,0 +1,124 @@
1
+ declare type PreDiscountListInfoInput = {
2
+ lotAreaNo: number;
3
+ registUserId?: string;
4
+ discCodeNo: number;
5
+ carNo?: string;
6
+ fromRegiDtm: string;
7
+ toRegiDtm: string;
8
+ dongcode?: string;
9
+ hocode?: string;
10
+ };
11
+ declare type InsertPreDiscountInfoInput = {
12
+ lotAreaNo: number;
13
+ registUserId: string;
14
+ registUserName?: string;
15
+ preDiscountId: number;
16
+ discCodeNo: number;
17
+ carNo: string;
18
+ dcCount: number;
19
+ startDtm: string;
20
+ endDtm: string;
21
+ dongcode?: string;
22
+ hocode?: string;
23
+ memo?: string;
24
+ mobile?: string;
25
+ };
26
+ declare type UpdatePreDiscountInfoInput = {
27
+ lotAreaNo: number;
28
+ registUserId: string;
29
+ registUserName?: string;
30
+ preDiscountId: number;
31
+ discCodeNo?: number;
32
+ carNo?: string;
33
+ dcCount?: number;
34
+ startDtm?: string;
35
+ endDtm?: string;
36
+ dongcode?: string;
37
+ hocode?: string;
38
+ memo?: string;
39
+ mobile?: string;
40
+ };
41
+ declare type DeletePreDiscountInfoInput = {
42
+ lotAreaNo: number;
43
+ registUserId?: string;
44
+ preDiscountId: number;
45
+ };
46
+ declare type FeeCarSearchInput = {
47
+ lotAreaNo: number;
48
+ eqpmNo: number;
49
+ carNo4Dight: string;
50
+ };
51
+ interface AmanoHttpResponse<T> {
52
+ status: string;
53
+ statusMsg: string;
54
+ data: {
55
+ success: boolean;
56
+ errorMessage: string;
57
+ } & T;
58
+ }
59
+ interface GetPreDiscountListInfoResponse {
60
+ eventName: 'Get pre-discount list Information';
61
+ eventType: 'GetPreDiscountListInfo';
62
+ list: {
63
+ preDiscountId: number;
64
+ registUserId: string;
65
+ registUserName: string;
66
+ discCodeNo: number;
67
+ carNo: string;
68
+ dcCount: number;
69
+ startDtm: string;
70
+ endDtm: string;
71
+ regiDtm: string;
72
+ dongcode: string;
73
+ hocode: string;
74
+ memo: string;
75
+ mobile: string;
76
+ }[];
77
+ }
78
+ interface InsertPreDiscountInfoResponse {
79
+ eventName: 'Inser pre-discount information';
80
+ eventType: 'InsertPreDiscountInfo';
81
+ preDiscountId: number;
82
+ }
83
+ interface UpdatePreDiscountInfoResponse {
84
+ eventName: 'Update pre-discount information';
85
+ eventType: 'UpdatePreDiscountInfo';
86
+ preDiscountId: number;
87
+ }
88
+ interface DeletePreDiscountInfoResponse {
89
+ eventName: 'Delete pre-discount information';
90
+ eventType: 'DeletePreDiscountInfo';
91
+ }
92
+ declare type AmanoPaymentType = 'PAY_FLAG_NONE' | 'PAY_FLAG_COMPLETE' | 'PAY_FLAG_RECALCULATE' | 'PAY_FLAG_DEBITCARD_RECHARGE' | 'PAY_FLAG_DEBITCARD_SALE' | 'PAY_FLAG_USED_PASSCARD' | 'PAY_FLAG_USED_DEBITCARD' | 'PAY_FLAG_USED_EVENTCARD' | 'PAY_FLAG_CANSEL' | 'PAY_FLAG_LOSTTICKET' | 'PAY_FLAG_MINAB';
93
+ /**
94
+ * 0 : 입차 1 : 출차
95
+ */
96
+ declare type AmanoInOutStatus = 0 | 1;
97
+ interface GetFeeCarSearchResponse {
98
+ eventName: 'Get Fee Car search';
99
+ eventType: 'GetFeeCarSearch';
100
+ inCarInfos: {
101
+ dbTableName: string;
102
+ lotAreaNo: number;
103
+ parkingTrnsID: number;
104
+ ticketNo: number;
105
+ carNo: string;
106
+ carNoMain: string;
107
+ carNoSub: string;
108
+ inEqpmNo: number;
109
+ feeRateNo: number;
110
+ paymentType: AmanoPaymentType;
111
+ inOutStatus: AmanoInOutStatus;
112
+ inDtm: string;
113
+ payDtm: string;
114
+ outDtm: string;
115
+ inCarPicName: string;
116
+ outCarPicName: string;
117
+ manualCalcInDtm: string;
118
+ freeTimeZones: {
119
+ startDtm: string;
120
+ endDtm: string;
121
+ }[];
122
+ }[];
123
+ }
124
+ export { AmanoHttpResponse, DeletePreDiscountInfoInput, DeletePreDiscountInfoResponse, FeeCarSearchInput, GetFeeCarSearchResponse, GetPreDiscountListInfoResponse, InsertPreDiscountInfoInput, InsertPreDiscountInfoResponse, PreDiscountListInfoInput, UpdatePreDiscountInfoInput, UpdatePreDiscountInfoResponse, };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,7 +2,7 @@ export default class MutexLock {
2
2
  redis: any;
3
3
  hashPrefix: string;
4
4
  mutexLockInterval: number;
5
- constructor({ redis, hashPrefix, mutexLockInterval }: {
5
+ constructor({ redis, hashPrefix, mutexLockInterval, }: {
6
6
  redis: any;
7
7
  hashPrefix: string;
8
8
  mutexLockInterval?: number;
@@ -37,13 +37,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  var uuid_1 = require("uuid");
40
- var sleep = function (sleepTime) { return new Promise(function (resolve) { return setTimeout(resolve, sleepTime); }); };
40
+ var sleep = function (sleepTime) {
41
+ return new Promise(function (resolve) { return setTimeout(resolve, sleepTime); });
42
+ };
41
43
  var MutexLock = /** @class */ (function () {
42
44
  function MutexLock(_a) {
43
45
  var _this = this;
44
46
  var redis = _a.redis, hashPrefix = _a.hashPrefix, _b = _a.mutexLockInterval, mutexLockInterval = _b === void 0 ? 50 : _b;
45
47
  this.getMutexLockKey = function (id) { return "" + _this.hashPrefix + id; };
46
- this.tryMutexLock = function (streamId, lockHash) { return _this.redis.set(_this.getMutexLockKey(streamId), lockHash, 'EX', 60, 'NX'); };
48
+ this.tryMutexLock = function (streamId, lockHash) {
49
+ return _this.redis.set(_this.getMutexLockKey(streamId), lockHash, 'EX', 60, 'NX');
50
+ };
47
51
  this.getMutexLock = function (streamId) { return __awaiter(_this, void 0, void 0, function () {
48
52
  var lockHash, lock;
49
53
  return __generator(this, function (_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendit-dev/thirdparty-adapters",
3
- "version": "0.3.31",
3
+ "version": "0.4.0-beta.10",
4
4
  "description": "Third party adapters between v-cloud and other PMS/CMS providers.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -20,11 +20,12 @@
20
20
  "@babel/plugin-proposal-optional-chaining": "^7.10.4",
21
21
  "@babel/preset-env": "^7.10.4",
22
22
  "@babel/preset-flow": "^7.10.4",
23
+ "@types/ioredis": "^5.0.0",
23
24
  "@types/node": "^14.11.4",
24
25
  "@types/node-fetch": "^2.6.1",
25
26
  "@typescript-eslint/eslint-plugin": "^3.6.1",
26
27
  "@typescript-eslint/parser": "^3.6.1",
27
- "@vendit-dev/utility-modules": "^0.11.1",
28
+ "@vendit-dev/utility-modules": "^0.17.0",
28
29
  "babel-eslint": "^10.1.0",
29
30
  "babel-plugin-module-resolver": "^4.0.0",
30
31
  "cross-env": "^7.0.2",