-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
663/mk/open payments validate #679
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
d3470c4
feat(open-payments-client): initial POC of open-payments-client
mkurapov 7f968c3
feat(open-payments-client): cleanup
mkurapov 79e7cd7
feat(open-payments): remove open-payments-client folder
mkurapov 32e2a31
feat(open-payments): make open-payments folder and use script for typ…
mkurapov 050ebef
feat(open-payments): fix rootDir
mkurapov 9893029
feat(open-payments): downgrading generation lib, updating how script …
mkurapov c15fdbc
feat(open-payments): update default config usage
mkurapov 130e310
feat(open-payments): update pnpm-lock.yaml
mkurapov e067011
feat(open-payments): update pnpm-lock.yaml
mkurapov dc28878
feat(open-payments): adding tests
mkurapov 39b561b
feat(open-payments): update pnpm-lock.yaml
mkurapov 9393e47
feat(open-payments): simplify test
mkurapov 3c3a0b7
feat(open-payments): updating workflows
mkurapov 120dcae
feat(open-payments): pin the open api spec to the most recent commit
mkurapov 80d9856
feat(open-payments): adding openapi validation
mkurapov 218f1f0
feat(open-payments): adding openapi validation
mkurapov d7c203c
feat(open-payments): adding tests
mkurapov dfc07cb
feat(open-payments): correcting test
mkurapov d59c2ea
Merge branch 'main' into 663/mk/open-payments-validate
mkurapov 43335f6
feat(open-payments): use updated RS spec
mkurapov 723de2f
Merge branch '663/mk/op-client-1' into 663/mk/open-payments-validate
mkurapov 02b8f9f
Merge branch 'main' into 663/mk/open-payments-validate
mkurapov f8c1846
feat(open-payments): build open api package on build step
mkurapov f560c79
Merge branch 'main' into 663/mk/op-client-1
mkurapov e11ec65
feat(open-payments): building open-api package during workflow
mkurapov 0dad54d
Revert "feat(open-payments): building open-api package during workflow"
mkurapov 000fc9b
Merge branch '663/mk/op-client-1' into 663/mk/open-payments-validate
mkurapov 25d2617
feat(open-payments): building open-api package during workflow
mkurapov f734dff
Merge branch 'main' into 663/mk/open-payments-validate
mkurapov 4552188
feat(open-payments): update naming
mkurapov 85db136
feat(open-payments): instantiate validator functions once
mkurapov dc4aa0f
chore(openapi): add docs for usage
mkurapov c927291
chore(openapi): update docs
mkurapov 3ed946b
chore(openapi): prettify docs
mkurapov 347075a
chore(openapi): update docs
mkurapov 90bc6b0
feat(open-payments): adding logger as dependency
mkurapov 3129f2a
feat(open-payments): updating logging & error logic
mkurapov 05b6cfb
feat(open-payments): remove unnecessary imports
mkurapov f1d2412
Merge branch 'main' into 663/mk/open-payments-validate
mkurapov f6eb6a8
feat(open-payments): update error handling & test
mkurapov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using the same version to validate the Open API as was used for generating the types in the first place |
||
const logger = args?.logger ?? createLogger() | ||
const deps = { axiosInstance, openApi, logger } | ||
|
||
return { | ||
incomingPayment: createIncomingPaymentRoutes(deps), | ||
ilpStreamConnection: createILPStreamConnectionRoutes(deps) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how important these tests in particular are, but I thought it was worth making sure we are adding the correct path for the response validator