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

feat(backend): adding OpenPaymentsServerRouteError #2635

Merged
merged 14 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@graphql-tools/schema": "^10.0.3",
"@interledger/http-signature-utils": "2.0.2",
"@interledger/open-payments": "6.8.0",
"@interledger/openapi": "1.2.1",
"@interledger/openapi": "2.0.1",
"@interledger/pay": "0.4.0-alpha.9",
"@interledger/stream-receiver": "^0.3.3-alpha.3",
"@koa/cors": "^5.0.0",
Expand Down
103 changes: 71 additions & 32 deletions packages/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import { PaymentMethodHandlerService } from './payment-method/handler/service'
import { IlpPaymentService } from './payment-method/ilp/service'
import { TelemetryService } from './telemetry/service'
import { ApolloArmor } from '@escape.tech/graphql-armor'
import { openPaymentsServerErrorMiddleware } from './open_payments/route-errors'
export interface AppContextData {
logger: Logger
container: AppContainer
Expand Down Expand Up @@ -388,6 +389,7 @@ export class App {
router.get('/healthz', (ctx: AppContext): void => {
ctx.status = 200
})
router.use(openPaymentsServerErrorMiddleware)

const walletAddressKeyRoutes = await this.container.use(
'walletAddressKeyRoutes'
Expand All @@ -403,17 +405,26 @@ export class App {
const { resourceServerSpec, walletAddressServerSpec } =
await this.container.use('openApi')

const validatorMiddlewareOptions = {
validateRequest: true,
validateResponse: process.env.NODE_ENV !== 'production'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what the createValidatorMiddleware function was doing previously, now to keep the same behaviour, it has to be stated explicitly

https://github.com/interledger/open-payments/releases/tag/%40interledger%2Fopenapi%402.0.0

}

// POST /incoming-payments
// Create incoming payment
router.post<DefaultState, SignedCollectionContext<IncomingCreateBody>>(
'/incoming-payments',
createWalletAddressMiddleware(),
createValidatorMiddleware<
ContextType<SignedCollectionContext<IncomingCreateBody>>
>(resourceServerSpec, {
path: '/incoming-payments',
method: HttpMethod.POST
}),
>(
resourceServerSpec,
{
path: '/incoming-payments',
method: HttpMethod.POST
},
validatorMiddlewareOptions
),
createTokenIntrospectionMiddleware({
requestType: AccessType.IncomingPayment,
requestAction: RequestAction.Create
Expand All @@ -432,10 +443,14 @@ export class App {
createWalletAddressMiddleware(),
createValidatorMiddleware<
ContextType<SignedCollectionContext<never, GetCollectionQuery>>
>(resourceServerSpec, {
path: '/incoming-payments',
method: HttpMethod.GET
}),
>(
resourceServerSpec,
{
path: '/incoming-payments',
method: HttpMethod.GET
},
validatorMiddlewareOptions
),
createTokenIntrospectionMiddleware({
requestType: AccessType.IncomingPayment,
requestAction: RequestAction.List
Expand All @@ -451,10 +466,14 @@ export class App {
createWalletAddressMiddleware(),
createValidatorMiddleware<
ContextType<SignedCollectionContext<OutgoingCreateBody>>
>(resourceServerSpec, {
path: '/outgoing-payments',
method: HttpMethod.POST
}),
>(
resourceServerSpec,
{
path: '/outgoing-payments',
method: HttpMethod.POST
},
validatorMiddlewareOptions
),
createTokenIntrospectionMiddleware({
requestType: AccessType.OutgoingPayment,
requestAction: RequestAction.Create
Expand All @@ -473,10 +492,14 @@ export class App {
createWalletAddressMiddleware(),
createValidatorMiddleware<
ContextType<SignedCollectionContext<never, GetCollectionQuery>>
>(resourceServerSpec, {
path: '/outgoing-payments',
method: HttpMethod.GET
}),
>(
resourceServerSpec,
{
path: '/outgoing-payments',
method: HttpMethod.GET
},
validatorMiddlewareOptions
),
createTokenIntrospectionMiddleware({
requestType: AccessType.OutgoingPayment,
requestAction: RequestAction.List
Expand All @@ -492,10 +515,14 @@ export class App {
createWalletAddressMiddleware(),
createValidatorMiddleware<
ContextType<SignedCollectionContext<QuoteCreateBody>>
>(resourceServerSpec, {
path: '/quotes',
method: HttpMethod.POST
}),
>(
resourceServerSpec,
{
path: '/quotes',
method: HttpMethod.POST
},
validatorMiddlewareOptions
),
createTokenIntrospectionMiddleware({
requestType: AccessType.Quote,
requestAction: RequestAction.Create
Expand All @@ -511,10 +538,14 @@ export class App {
createWalletAddressMiddleware(),
createValidatorMiddleware<
ContextType<SubresourceContextWithAuthenticatedStatus>
>(resourceServerSpec, {
path: '/incoming-payments/{id}',
method: HttpMethod.GET
}),
>(
resourceServerSpec,
{
path: '/incoming-payments/{id}',
method: HttpMethod.GET
},
validatorMiddlewareOptions
),
createTokenIntrospectionMiddleware({
requestType: AccessType.IncomingPayment,
requestAction: RequestAction.Read,
Expand All @@ -534,7 +565,8 @@ export class App {
{
path: '/incoming-payments/{id}/complete',
method: HttpMethod.POST
}
},
validatorMiddlewareOptions
),
createTokenIntrospectionMiddleware({
requestType: AccessType.IncomingPayment,
Expand All @@ -554,7 +586,8 @@ export class App {
{
path: '/outgoing-payments/{id}',
method: HttpMethod.GET
}
},
validatorMiddlewareOptions
),
createTokenIntrospectionMiddleware({
requestType: AccessType.OutgoingPayment,
Expand All @@ -574,7 +607,8 @@ export class App {
{
path: '/quotes/{id}',
method: HttpMethod.GET
}
},
validatorMiddlewareOptions
),
createTokenIntrospectionMiddleware({
requestType: AccessType.Quote,
Expand All @@ -592,7 +626,8 @@ export class App {
{
path: '/jwks.json',
method: HttpMethod.GET
}
},
validatorMiddlewareOptions
),
async (ctx: WalletAddressKeysContext): Promise<void> =>
await walletAddressKeyRoutes.getKeysByWalletAddressId(ctx)
Expand All @@ -604,10 +639,14 @@ export class App {
WALLET_ADDRESS_PATH,
createWalletAddressMiddleware(),
createSpspMiddleware(this.config.spspEnabled),
createValidatorMiddleware<WalletAddressContext>(walletAddressServerSpec, {
path: '/',
method: HttpMethod.GET
}),
createValidatorMiddleware<WalletAddressContext>(
walletAddressServerSpec,
{
path: '/',
method: HttpMethod.GET
},
validatorMiddlewareOptions
),
walletAddressRoutes.get
)

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export function initIocContainer(
container.singleton('walletAddressKeyRoutes', async (deps) => {
return createWalletAddressKeyRoutes({
config: await deps.use('config'),
logger: await deps.use('logger'),
walletAddressKeyService: await deps.use('walletAddressKeyService'),
walletAddressService: await deps.use('walletAddressService')
})
Expand Down
Loading