-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
663/mk/open payments validate (#679)
* feat(open-payments-client): initial POC of open-payments-client * feat(open-payments-client): cleanup * feat(open-payments): remove open-payments-client folder * feat(open-payments): make open-payments folder and use script for type generation * feat(open-payments): fix rootDir * feat(open-payments): downgrading generation lib, updating how script is ran * feat(open-payments): update default config usage * feat(open-payments): update pnpm-lock.yaml * feat(open-payments): update pnpm-lock.yaml * feat(open-payments): adding tests * feat(open-payments): update pnpm-lock.yaml * feat(open-payments): simplify test * feat(open-payments): updating workflows * feat(open-payments): pin the open api spec to the most recent commit * feat(open-payments): adding openapi validation * feat(open-payments): adding openapi validation * feat(open-payments): adding tests * feat(open-payments): correcting test * feat(open-payments): use updated RS spec * feat(open-payments): build open api package on build step * feat(open-payments): building open-api package during workflow * Revert "feat(open-payments): building open-api package during workflow" This reverts commit e11ec65. * feat(open-payments): building open-api package during workflow * feat(open-payments): update naming * feat(open-payments): instantiate validator functions once * chore(openapi): add docs for usage * chore(openapi): update docs * chore(openapi): prettify docs * chore(openapi): update docs * feat(open-payments): adding logger as dependency * feat(open-payments): updating logging & error logic * feat(open-payments): remove unnecessary imports * feat(open-payments): update error handling & test
- Loading branch information
Showing
18 changed files
with
377 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
packages/open-payments/src/client/ilp-stream-connection.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import { createILPStreamConnectionRoutes } from './ilp-stream-connection' | ||
import { OpenAPI, HttpMethod, createOpenAPI } from 'openapi' | ||
import config from '../config' | ||
import { defaultAxiosInstance, silentLogger } from '../test/helpers' | ||
|
||
describe('ilp-stream-connection', (): void => { | ||
let openApi: OpenAPI | ||
|
||
beforeAll(async () => { | ||
openApi = await createOpenAPI(config.OPEN_PAYMENTS_OPEN_API_URL) | ||
}) | ||
|
||
const axiosInstance = defaultAxiosInstance | ||
const logger = silentLogger | ||
|
||
describe('createILPStreamConnectionRoutes', (): void => { | ||
test('calls createResponseValidator properly', async (): Promise<void> => { | ||
jest.spyOn(openApi, 'createResponseValidator') | ||
|
||
createILPStreamConnectionRoutes({ axiosInstance, openApi, logger }) | ||
expect(openApi.createResponseValidator).toHaveBeenCalledWith({ | ||
path: '/connections/{id}', | ||
method: HttpMethod.GET | ||
}) | ||
}) | ||
}) | ||
}) |
25 changes: 25 additions & 0 deletions
25
packages/open-payments/src/client/ilp-stream-connection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { HttpMethod } from 'openapi' | ||
import { ClientDeps } from '.' | ||
import { getPath, ILPStreamConnection } from '../types' | ||
import { GetArgs, get } from './requests' | ||
|
||
export interface ILPStreamConnectionRoutes { | ||
get(args: GetArgs): Promise<ILPStreamConnection> | ||
} | ||
|
||
export const createILPStreamConnectionRoutes = ( | ||
clientDeps: ClientDeps | ||
): ILPStreamConnectionRoutes => { | ||
const { axiosInstance, openApi, logger } = clientDeps | ||
|
||
const getILPStreamConnectionValidator = | ||
openApi.createResponseValidator<ILPStreamConnection>({ | ||
path: getPath('/connections/{id}'), | ||
method: HttpMethod.GET | ||
}) | ||
|
||
return { | ||
get: (args: GetArgs) => | ||
get({ axiosInstance, logger }, args, getILPStreamConnectionValidator) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/open-payments/src/client/incoming-payment.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import { createIncomingPaymentRoutes } from './incoming-payment' | ||
import { OpenAPI, HttpMethod, createOpenAPI } from 'openapi' | ||
import config from '../config' | ||
import { defaultAxiosInstance, silentLogger } from '../test/helpers' | ||
|
||
describe('incoming-payment', (): void => { | ||
let openApi: OpenAPI | ||
|
||
beforeAll(async () => { | ||
openApi = await createOpenAPI(config.OPEN_PAYMENTS_OPEN_API_URL) | ||
}) | ||
|
||
const axiosInstance = defaultAxiosInstance | ||
const logger = silentLogger | ||
|
||
describe('createIncomingPaymentRoutes', (): void => { | ||
test('calls createResponseValidator properly', async (): Promise<void> => { | ||
jest.spyOn(openApi, 'createResponseValidator') | ||
|
||
createIncomingPaymentRoutes({ | ||
axiosInstance, | ||
openApi, | ||
logger | ||
}) | ||
expect(openApi.createResponseValidator).toHaveBeenCalledWith({ | ||
path: '/incoming-payments/{id}', | ||
method: HttpMethod.GET | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { HttpMethod } from 'openapi' | ||
import { ClientDeps } from '.' | ||
import { IncomingPayment, getPath } from '../types' | ||
import { GetArgs, get } from './requests' | ||
|
||
export interface IncomingPaymentRoutes { | ||
get(args: GetArgs): Promise<IncomingPayment> | ||
} | ||
|
||
export const createIncomingPaymentRoutes = ( | ||
clientDeps: ClientDeps | ||
): IncomingPaymentRoutes => { | ||
const { axiosInstance, openApi, logger } = clientDeps | ||
|
||
const getIncomingPaymentValidator = | ||
openApi.createResponseValidator<IncomingPayment>({ | ||
path: getPath('/incoming-payments/{id}'), | ||
method: HttpMethod.GET | ||
}) | ||
|
||
return { | ||
get: (args: GetArgs) => | ||
get({ axiosInstance, logger }, args, getIncomingPaymentValidator) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createOpenAPI, OpenAPI } from 'openapi' | ||
import createLogger, { Logger } from 'pino' | ||
import config from '../config' | ||
import { | ||
createIncomingPaymentRoutes, | ||
IncomingPaymentRoutes | ||
} from './incoming-payment' | ||
import { | ||
createILPStreamConnectionRoutes, | ||
ILPStreamConnectionRoutes | ||
} from './ilp-stream-connection' | ||
import { createAxiosInstance } from './requests' | ||
import { AxiosInstance } from 'axios' | ||
|
||
export interface CreateOpenPaymentClientArgs { | ||
requestTimeoutMs?: number | ||
logger?: Logger | ||
} | ||
|
||
export interface ClientDeps { | ||
axiosInstance: AxiosInstance | ||
openApi: OpenAPI | ||
logger: Logger | ||
} | ||
|
||
export interface OpenPaymentsClient { | ||
incomingPayment: IncomingPaymentRoutes | ||
ilpStreamConnection: ILPStreamConnectionRoutes | ||
} | ||
|
||
export const createClient = async ( | ||
args?: CreateOpenPaymentClientArgs | ||
): Promise<OpenPaymentsClient> => { | ||
const axiosInstance = createAxiosInstance({ | ||
requestTimeoutMs: | ||
args?.requestTimeoutMs ?? config.DEFAULT_REQUEST_TIMEOUT_MS | ||
}) | ||
const openApi = await createOpenAPI(config.OPEN_PAYMENTS_OPEN_API_URL) | ||
const logger = args?.logger ?? createLogger() | ||
const deps = { axiosInstance, openApi, logger } | ||
|
||
return { | ||
incomingPayment: createIncomingPaymentRoutes(deps), | ||
ilpStreamConnection: createILPStreamConnectionRoutes(deps) | ||
} | ||
} |
Oops, something went wrong.