Skip to content

Commit

Permalink
add utility typescript for specific return value for function
Browse files Browse the repository at this point in the history
  • Loading branch information
restuwahyu13 committed Feb 5, 2021
1 parent 4e4df32 commit 564f9c1
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 125 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## BUILD STAGE ONE

FROM node:12-alpine as midtrans-node
FROM node:14-alpine as midtrans-node
COPY package*.json \
.coveralls.yml \
.editorconfig \
Expand All @@ -21,7 +21,7 @@ RUN apk add make \
## BUILD STAGE TWO

FROM midtrans-node
WORKDIR /app
COPY --from=midtrans-node ./ /app
WORKDIR /usr/src/app
COPY --from=midtrans-node ./ /usr/src/app
RUN make build
CMD docker images
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Midtrans Node

[![Build Status](https://travis-ci.org/restuwahyu13/midtrans-node.svg?branch=main)](https://travis-ci.org/restuwahyu13/midtrans-node) [![Coverage Status](https://coveralls.io/repos/github/restuwahyu13/nodejs-midtrans-client/badge.svg?branch=main)](https://coveralls.io/github/restuwahyu13/nodejs-midtrans-client?branch=main) ![node-current](https://img.shields.io/node/v/midtrans-node-client?style=flat-square) ![npm](https://img.shields.io/npm/dm/midtrans-node-client) ![npm](https://img.shields.io/npm/dt/midtrans-node-client) ![npm bundle size](https://img.shields.io/bundlephobia/min/midtrans-node-client) ![npm bundle size (version)](https://img.shields.io/bundlephobia/minzip/midtrans-node-client) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/midtrans-node-client?style=flat-square) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/restuwahyu13/midtrans-node/blob/main/CONTRIBUTING.md)
[![Build Status](https://travis-ci.org/restuwahyu13/midtrans-node.svg?branch=main)](https://travis-ci.org/restuwahyu13/midtrans-node) [![Coverage Status](https://coveralls.io/repos/github/restuwahyu13/nodejs-midtrans-client/badge.svg?branch=main)](https://coveralls.io/github/restuwahyu13/nodejs-midtrans-client?branch=main) ![node-current](https://img.shields.io/node/v/midtrans-node-client?style=flat-square) ![npm](https://img.shields.io/npm/dm/midtrans-node-client) ![npm bundle size](https://img.shields.io/bundlephobia/min/midtrans-node-client) ![npm bundle size (version)](https://img.shields.io/bundlephobia/minzip/midtrans-node-client) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/midtrans-node-client?style=flat-square) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/restuwahyu13/midtrans-node/blob/main/CONTRIBUTING.md)

- [Installation](#installation)
- [API Documentation](#api-documentation)
Expand Down
75 changes: 1 addition & 74 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "midtrans-node-client",
"version": "0.0.1",
"version": "0.0.2",
"description": "Unoffficial Midtrans Payment API Client for Node JS | Alternative for Midtrans Official Module",
"main": "./dist/index.js",
"files": [
Expand All @@ -10,11 +10,10 @@
"clean": "rimraf dist",
"compiler": "npm run clean && tsc --pretty",
"build": "npm run compiler",
"start": "ts-node index.ts",
"test": "jest",
"test:watch": "jest --watchAll",
"test:coverage": "jest --coverage --no-cache",
"test:coveralls": "jest --coverage --no-cache && coveralls < coverage/lcov.info",
"test:coverage": "jest --coverage",
"test:coveralls": "jest --coverage && coveralls < coverage/lcov.info",
"lint": "eslint src/**/*.{ts,spec.ts,test.ts} --fix",
"format": "prettier src/**/*.{ts,spec.ts,test.ts} --write",
"lint:fix": "npm run format && npm run lint"
Expand All @@ -36,6 +35,7 @@
"npm": ">=6"
},
"keywords": [
"midtrans-node-client",
"payment",
"payment gateway",
"midtrans",
Expand All @@ -53,7 +53,6 @@
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/eslint": "^7.2.6",
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.167",
"@types/node": "^14.14.20",
Expand All @@ -72,7 +71,6 @@
"jest": "^26.6.3",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"streambox-collection": "0.0.2",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
Expand Down
10 changes: 5 additions & 5 deletions src/lib/apiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ApiConfig {
* @return {Object} object contains isProduction, serverKey, clientKey
*/

public get(): ApiConfigGetter {
public get(): ReturnType<() => ApiConfigGetter> {
const currentConfig: ApiConfigOptions = {
isProduction: this.isProduction,
serverKey: this.serverKey,
Expand All @@ -46,7 +46,7 @@ export class ApiConfig {
* @param {Object} options - object contains isProduction, serverKey, clientKey]
*/

public set<T extends Partial<ApiConfigOptions>>(options: T | Record<any, any>): void {
public set<T extends Partial<ApiConfigOptions>>(options: T | Record<any, any>): ReturnType<() => void> {
const currentConfig: ApiConfigOptions = {
isProduction: this.isProduction,
serverKey: this.serverKey,
Expand All @@ -65,23 +65,23 @@ export class ApiConfig {
* @return {String} core api base url
*/

public getCoreApiBaseUrl(): string {
public getCoreApiBaseUrl(): ReturnType<() => string> {
return this.isProduction ? ApiConfig.CORE_PRODUCTION_BASE_URL : ApiConfig.CORE_SANDBOX_BASE_URL
}

/**
* @return {String} snap api base url
*/

public getSnapApiBaseUrl(): string {
public getSnapApiBaseUrl(): ReturnType<() => string> {
return this.isProduction ? ApiConfig.SNAP_PRODUCTION_BASE_URL : ApiConfig.SNAP_SANDBOX_BASE_URL
}

/**
* @return {String} Iris api base url
*/

public getIrisApiBaseUrl(): string {
public getIrisApiBaseUrl(): ReturnType<() => string> {
return this.isProduction ? ApiConfig.IRIS_PRODUCTION_BASE_URL : ApiConfig.IRIS_SANDBOX_BASE_URL
}
}
12 changes: 7 additions & 5 deletions src/lib/coreApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class CoreApi {

public charge<T extends Partial<ChargeTypeRequest>>(
parameter: T | Record<string, any>
): Promise<Record<string, any>> {
): ReturnType<() => Promise<Record<string, any>>> {
this.apiUrl = this.apiConfig.getCoreApiBaseUrl() + '/charge'
const res = parameter
return this.httpClient.request({
Expand All @@ -57,7 +57,9 @@ export class CoreApi {
* @return {Promise} - Promise contains Object from JSON decoded response
*/

public capture<T extends Partial<CaptureRequest>>(parameter: T | Record<string, any>): Promise<Record<string, any>> {
public capture<T extends Partial<CaptureRequest>>(
parameter: T | Record<string, any>
): ReturnType<() => Promise<Record<string, any>>> {
this.apiUrl = this.apiConfig.getCoreApiBaseUrl() + '/capture'
return this.httpClient.request({
requestUrl: this.apiUrl,
Expand All @@ -75,7 +77,7 @@ export class CoreApi {

public cardRegister<T extends Partial<CardRegisterRequest>>(
parameter: T | Record<any, any>
): Promise<Record<string, any>> {
): ReturnType<() => Promise<Record<string, any>>> {
this.apiUrl = this.apiConfig.getCoreApiBaseUrl() + '/card/register'
return this.httpClient.request({
requestUrl: this.apiUrl,
Expand All @@ -93,7 +95,7 @@ export class CoreApi {

public cardToken<T extends Partial<CardTokenRequest>>(
parameter: T | Record<string, any>
): Promise<Record<string, any>> {
): ReturnType<() => Promise<Record<string, any>>> {
this.apiUrl = this.apiConfig.getCoreApiBaseUrl() + '/token'
return this.httpClient.request({
requestUrl: this.apiUrl,
Expand All @@ -109,7 +111,7 @@ export class CoreApi {
* @return {Promise} - Promise contains Object from JSON decoded response
*/

public cardPointInquiry(tokenId: string): Promise<Record<string, any>> {
public cardPointInquiry(tokenId: string): ReturnType<() => Promise<Record<string, any>>> {
this.apiUrl = this.apiConfig.getCoreApiBaseUrl() + '/point_inquiry/' + tokenId
return this.httpClient.request({
requestUrl: this.apiUrl,
Expand Down
4 changes: 3 additions & 1 deletion src/lib/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export class HttpClient {
this.requestParam = {}
}

public request<T extends Partial<RequestOptions>>(options: T | Record<any, any>): Promise<Record<string, any>> {
public request<T extends Partial<RequestOptions>>(
options: T | Record<any, any>
): ReturnType<() => Promise<Record<string, any>>> {
const headers = this.headers

let requestBody = this.requestBody
Expand Down
Loading

0 comments on commit 564f9c1

Please sign in to comment.