Skip to content
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 40 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
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 Oct 12, 2022
7f968c3
feat(open-payments-client): cleanup
mkurapov Oct 12, 2022
79e7cd7
feat(open-payments): remove open-payments-client folder
mkurapov Oct 13, 2022
32e2a31
feat(open-payments): make open-payments folder and use script for typ…
mkurapov Oct 13, 2022
050ebef
feat(open-payments): fix rootDir
mkurapov Oct 13, 2022
9893029
feat(open-payments): downgrading generation lib, updating how script …
mkurapov Oct 14, 2022
c15fdbc
feat(open-payments): update default config usage
mkurapov Oct 14, 2022
130e310
feat(open-payments): update pnpm-lock.yaml
mkurapov Oct 14, 2022
e067011
feat(open-payments): update pnpm-lock.yaml
mkurapov Oct 14, 2022
dc28878
feat(open-payments): adding tests
mkurapov Oct 14, 2022
39b561b
feat(open-payments): update pnpm-lock.yaml
mkurapov Oct 14, 2022
9393e47
feat(open-payments): simplify test
mkurapov Oct 14, 2022
3c3a0b7
feat(open-payments): updating workflows
mkurapov Oct 14, 2022
120dcae
feat(open-payments): pin the open api spec to the most recent commit
mkurapov Oct 14, 2022
80d9856
feat(open-payments): adding openapi validation
mkurapov Oct 18, 2022
218f1f0
feat(open-payments): adding openapi validation
mkurapov Oct 18, 2022
d7c203c
feat(open-payments): adding tests
mkurapov Oct 18, 2022
dfc07cb
feat(open-payments): correcting test
mkurapov Oct 18, 2022
d59c2ea
Merge branch 'main' into 663/mk/open-payments-validate
mkurapov Oct 21, 2022
43335f6
feat(open-payments): use updated RS spec
mkurapov Oct 21, 2022
723de2f
Merge branch '663/mk/op-client-1' into 663/mk/open-payments-validate
mkurapov Oct 21, 2022
02b8f9f
Merge branch 'main' into 663/mk/open-payments-validate
mkurapov Oct 24, 2022
f8c1846
feat(open-payments): build open api package on build step
mkurapov Oct 24, 2022
f560c79
Merge branch 'main' into 663/mk/op-client-1
mkurapov Oct 24, 2022
e11ec65
feat(open-payments): building open-api package during workflow
mkurapov Oct 24, 2022
0dad54d
Revert "feat(open-payments): building open-api package during workflow"
mkurapov Oct 24, 2022
000fc9b
Merge branch '663/mk/op-client-1' into 663/mk/open-payments-validate
mkurapov Oct 24, 2022
25d2617
feat(open-payments): building open-api package during workflow
mkurapov Oct 24, 2022
f734dff
Merge branch 'main' into 663/mk/open-payments-validate
mkurapov Oct 24, 2022
4552188
feat(open-payments): update naming
mkurapov Oct 24, 2022
85db136
feat(open-payments): instantiate validator functions once
mkurapov Oct 25, 2022
dc4aa0f
chore(openapi): add docs for usage
mkurapov Oct 25, 2022
c927291
chore(openapi): update docs
mkurapov Oct 25, 2022
3ed946b
chore(openapi): prettify docs
mkurapov Oct 25, 2022
347075a
chore(openapi): update docs
mkurapov Oct 25, 2022
90bc6b0
feat(open-payments): adding logger as dependency
mkurapov Oct 25, 2022
3129f2a
feat(open-payments): updating logging & error logic
mkurapov Oct 25, 2022
05b6cfb
feat(open-payments): remove unnecessary imports
mkurapov Oct 25, 2022
f1d2412
Merge branch 'main' into 663/mk/open-payments-validate
mkurapov Oct 25, 2022
f6eb6a8
feat(open-payments): update error handling & test
mkurapov Oct 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint_test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm --filter openapi build
- run: pnpm --filter open-payments test

build:
Expand Down
7 changes: 5 additions & 2 deletions packages/open-payments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dist/**/*"
],
"scripts": {
"build": "pnpm clean && tsc --build tsconfig.json",
"build:deps": "pnpm --filter openapi build",
"build": "pnpm build:deps && pnpm clean && tsc --build tsconfig.json",
"clean": "rm -fr dist/",
"generate:types": "npx ts-node scripts/generate-types.ts",
"prepack": "pnpm build",
Expand All @@ -21,6 +22,8 @@
"typescript": "^4.3.0"
},
"dependencies": {
"axios": "^1.1.2"
"axios": "^1.1.2",
"openapi": "workspace:../openapi",
"pino": "^8.4.2"
}
}
67 changes: 0 additions & 67 deletions packages/open-payments/src/client.test.ts

This file was deleted.

67 changes: 0 additions & 67 deletions packages/open-payments/src/client.ts

This file was deleted.

28 changes: 28 additions & 0 deletions packages/open-payments/src/client/ilp-stream-connection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable @typescript-eslint/no-empty-function */
Copy link
Contributor Author

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

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 packages/open-payments/src/client/ilp-stream-connection.ts
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 packages/open-payments/src/client/incoming-payment.test.ts
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
})
})
})
})
25 changes: 25 additions & 0 deletions packages/open-payments/src/client/incoming-payment.ts
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)
}
}
46 changes: 46 additions & 0 deletions packages/open-payments/src/client/index.ts
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
}
}
Loading