0.0.2 • Published 2 years ago
@msa-makers/txios v0.0.2
@msa-makers/txios
TL;DR
txios
.start(rtId, payload)
.then((txResponse) => /* response */ )
.catch((txError) => /* error */ );
install
yarn add @msa-makers/txios
# or
npm i @msa-makers/txios
##JavaScript app.js
import { Txios } from "@msa-makers/txios";
// create txios
const txios = Txios.create({
runnerUrl: "http://localhost:3000/runner/routeRequest", // check SOP Proxy
notifierUrl: "wss://notifier.msamaker.bespinglobal.com/txresult",
});
// routing Id
const rtid = "rt_20230224064821";
// payload
const order = {
service_name: "order",
payload: {
Combine: {
index: 1,
},
},
};
// request
txios
.start(rtid, order)
.then((txResponse) => console.log("txResponse", txResponse))
.catch((txError) => console.log("txError", txError));
##TypeScript app.ts
import { Txios, TxiosError, TxResponse } from "@msa-makers/txios";
// create txios
const txios = Txios.create({
runnerUrl: "http://localhost:3000/runner/routeRequest", // check SOP Proxy
notifierUrl: "wss://notifier.msamaker.bespinglobal.com/txresult",
});
// routing Id
const rtid = "rt_20230127132114";
// payload
const order: Order = {
service_name: "order",
payload: {
Combine: {
index: 1,
},
},
};
// request
txios
.start<Order, OrderResult>(rtid, payload)
.then((txResponse: TxResponse<OrderResult>) =>
console.log("txResponse", txResponse)
)
.catch((txError: TxiosError) => console.log("txError", txError));
// Type define
interface Order {
service_name: string;
payload: {
Combine: {
index: number;
};
};
}
interface OrderResult {
Combine: { index: number };
Delivery: { index: number };
Order: { index: number };
Payment: { index: number };
Stock: { index: number };
}
in Project
src/apis/txios/index.ts
import Txios from "@msa-makers/txios";
const txios = Txios.create({
runnerUrl: "http://localhost:3000/runner/routeRequest",
notifierUrl: "wss://notifier.cnakj.shop/txresult",
});
/* set globally optional */
// txios.setTimeout(15) // change timeout
export { txios };
src/app.ts
import { txios } from "@/apis/txios";
const rtid = "rt_20230127132114";
const order = {
service_name: "member",
payload: {
money: 2,
point: 1,
},
};
txios
.start(rtid, order)
.then((txResponse) => console.log("txResponse", txResponse))
.catch((txError) => console.log("txError", txError));
Txios
클래스 | 함수 | 설명 | 기본값 |
---|---|---|---|
Txios | static create(config: TxiosConfig): Txios | Txios인스턴스 생성 | notNull |
Txios | start<P, R>(rtId: string, payload: P): Promise<TxResponse<R>> | payload와 함께 rtid 라우팅 룰 실행 | rtid(NotNull), payload(Optional) |
Txios | setTimeout(sec: number) | 타임아웃 시간 변경 | 10 |
Txios | setHeaders(headers) | 트랜잭션 요청 헤더 변경(global) | { "Content-Type": "application/json" } |
Txios | enableCallStackLog(isPrint: boolean) | 요청 순서를 콘솔에 출력(디버깅용) | false |
Txios | createTransaction() | 트랜잭션 인스턴스 생성 | - |
TxiosError
클래스 | 필드 | 설명 |
---|---|---|
TxiosError | errorCode: TxiosErrorCode | 현재 에러 유형 코드 (TxiosErrorCode참조) |
TxiosError | errorMessage: unknown | 에러 메시지 및 정보 |
TxiosErrorCode
클래스 | 코드 | 설명 |
---|---|---|
TxiosErrorCode | RUNNER_REQUEST_FAIL | Runner요청 중 오류가 발생한 경우 |
TxiosErrorCode | RUNNER_RESPONSE_FAIL | Runner응답 TxId가 undefined 인경우 |
TxiosErrorCode | NOTIFIER_SOCKET_CLOSED | Transaction.call 호출 전 소켓이 닫혀 있는 경우 |
TxiosErrorCode | TIMEOUT | 제한시간내에 응답을 받지 못했을 경우(default: 10sec) |
TxiosErrorCode | UNKNOWN | 정의되지 않은 에러 |
date: "2023-01-30T07:17:30.526Z" author: Bespin