From dfc8be02b04dddf4e88eefaef3c26e58e25bfaca Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 19 Dec 2023 13:16:45 +0900 Subject: [PATCH 1/3] feat: get req key from param --- src/controllers/serviceController.ts | 6 +++--- src/service.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controllers/serviceController.ts b/src/controllers/serviceController.ts index f5bbfbe..869fb57 100644 --- a/src/controllers/serviceController.ts +++ b/src/controllers/serviceController.ts @@ -77,12 +77,12 @@ export default class ServiceController { return await this.ain.getValue(creditHistoryPath) as creditHistories; } - async request(serviceName: string, requestData: any) : Promise { + async request(serviceName: string, requestData: any, requestKey?: string) : Promise { this.checkRunning(serviceName); const result = await new Promise(async (resolve, reject) => { - const requestKey = Date.now(); + requestKey = requestKey || Date.now().toString(); const requesterAddress = this.ain.getAddress(); - const responsePath = Path.app(serviceName).response(requesterAddress, requestKey.toString()); + const responsePath = Path.app(serviceName).response(requesterAddress, requestKey); await this.handler.subscribe(responsePath, resolve); const requestPath = Path.app(serviceName).request(requesterAddress, requestKey); const requestOp = buildSetOperation("SET_VALUE", requestPath, requestData); diff --git a/src/service.ts b/src/service.ts index 24239da..5f94786 100644 --- a/src/service.ts +++ b/src/service.ts @@ -79,9 +79,9 @@ export default class Service { * @param {string} requestData String data for request to service. * @returns {string} Response data from service. */ - async request(requestData: any) { + async request(requestData: any, requestKey?: string) { this.isLoggedIn(); - return await this.serviceController.request(this.serviceName, requestData); + return await this.serviceController.request(this.serviceName, requestData, requestKey); } /** From 5b254c3c823eff3ccfc92aaae47f2b984d4933ba Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 20 Dec 2023 17:08:57 +0900 Subject: [PATCH 2/3] fix: throw error with reject --- src/controllers/serviceController.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/controllers/serviceController.ts b/src/controllers/serviceController.ts index f5bbfbe..3a450c8 100644 --- a/src/controllers/serviceController.ts +++ b/src/controllers/serviceController.ts @@ -81,16 +81,20 @@ export default class ServiceController { this.checkRunning(serviceName); const result = await new Promise(async (resolve, reject) => { const requestKey = Date.now(); - const requesterAddress = this.ain.getAddress(); - const responsePath = Path.app(serviceName).response(requesterAddress, requestKey.toString()); - await this.handler.subscribe(responsePath, resolve); - const requestPath = Path.app(serviceName).request(requesterAddress, requestKey); - const requestOp = buildSetOperation("SET_VALUE", requestPath, requestData); - const txBody = buildTxBody(requestOp); - await this.ain.sendTransaction(txBody); - return requestKey; + try { + const requesterAddress = this.ain.getAddress(); + const responsePath = Path.app(serviceName).response(requesterAddress, requestKey.toString()); + await this.handler.subscribe(responsePath, resolve); + const requestPath = Path.app(serviceName).request(requesterAddress, requestKey); + const requestOp = buildSetOperation("SET_VALUE", requestPath, requestData); + const txBody = buildTxBody(requestOp); + await this.ain.sendTransaction(txBody); + } catch (e: any) { + if (e instanceof Error) + return reject(new Error(e.message)); + } }); - return result as string; + return result; } async run(serviceName: string): Promise { From 341351651ae2f928b170fcad03f0731ea3cf9e81 Mon Sep 17 00:00:00 2001 From: yoojinko Date: Thu, 21 Dec 2023 01:21:20 +0000 Subject: [PATCH 3/3] Upgrade version to 1.0.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bb1727b..b3ebf7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ainize-team/ainize-js", - "version": "1.0.4", + "version": "1.0.5", "main": "dist/ainize.js", "types": "dist/ainize.d.ts", "scripts": {