feat: support new subject field, grant spent amounts#20
Conversation
🦋 Changeset detectedLatest commit: dbf2b04 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| test('properly references $ref to external ./schemas.yaml', async () => { | ||
| const openApi = await getResourceServerOpenAPI() | ||
|
|
||
| expect( | ||
| Object.keys( | ||
| openApi.paths?.['/incoming-payments']?.['post']?.['requestBody']?.[ | ||
| 'content' | ||
| ]['application/json']['schema']['properties']['incomingAmount'][ | ||
| 'properties' | ||
| ] | ||
| ).sort() | ||
| ).toEqual(['assetCode', 'assetScale', 'value'].sort()) | ||
| }) |
There was a problem hiding this comment.
These are no longer relevant nor testing what they are supposed to (references to external schema) because we got rid of the external schema.
This came on my radar because one of them broke since the details of the spec changed (subject field). Which means it's also quite flakey (even if we did need it). I think all these tests really need to do is just ensure it loads (specific details are irrelevant), which it still does.
| requestArgs: ResourceRequestArgs, | ||
| createArgs: CreateOutgoingPaymentArgs | ||
| ): Promise<OutgoingPaymentWithSpentAmounts> | ||
| getGrantSpentAmounts( |
There was a problem hiding this comment.
called like client.outgoingPayment.getGrantSpentAmounts. Makes it discoverable through outgoing payment which seems appropriate given the use case ("how much has been spent against the outgoing payemnt?") and a top-level method (client.outgoingPaymentGrant.getSpentAmounts) seemed like overkill and im not sure we intend on having more details for the outgoing payment grant exposed on this new endpoint, although it kinda fits the pattern more (/outgoing-payment, /incoming-payment, outgoing-payment-grant etc.). I think this ended up being the most reasonable way.
There was a problem hiding this comment.
Makes sense to me, since it's still "scoped" to the outgoing payments.
packages/open-payments/src/types.ts
Outdated
| access_token: { access: GrantRequestAccessItem[] } | ||
| client: ASOperations['post-request']['requestBody']['content']['application/json']['client'] | ||
| interact?: ASOperations['post-request']['requestBody']['content']['application/json']['interact'] | ||
| subject?: Subject |
There was a problem hiding this comment.
I think we can remove subject from GrantContinuation, since I imagine it was meant as the pending grant continuation return type (ie during polling). Maybe a better name for GrantContinuation is PendingGrantContinuation
There was a problem hiding this comment.
I can remove it but I just want to verify since I'm not sure im completely following.
The openapi spec for /continue/{id} defines subject as an optional property in the response. But we still don't want to expose it here, is that correct? Should it be on the response in the spec?
There was a problem hiding this comment.
It looks like the types are:
Grant: the result of calling/continue/{id}where we getcontinuewithaccess_tokenand/orsubject(i.e. a "finalized" grant)GrantContinuation: the result of calling/continue/{id}where we only getcontinue(what we get back during polling only)
As a result, I think subject belongs only on Grant and not on GrantContinuation
There was a problem hiding this comment.
gotcha, removed subject
| export type Grant = { | ||
| access_token: ASComponents['schemas']['access_token'] | ||
| continue: ASComponents['schemas']['continue'] | ||
| subject?: Subject |
There was a problem hiding this comment.
Technically, now the access_token becomes optional in this type since the client could have made the grant requests only with the subject. As a result, the isFinalizedGrant type guard becomes unclear. From the top of my head, maybe we can deprecate isFinalizedGrant, and then have something like isFinalizedGrantWithAccessToken | isFinalizedGrantWithSubject? What do you think?
There was a problem hiding this comment.
I think that makes sense. I added isFinalizedGrantWithSubject that verifies subject in grant. And madeaccess_token optional.
There was a problem hiding this comment.
Nice, thank you! Let's update the client README and the changeset with this.
There was a problem hiding this comment.
updated the changeset
There was a problem hiding this comment.
updated the readme with the isFinalizedGrantWithAccessToken typeguard in the example flow: dbf2b04
| requestArgs: ResourceRequestArgs, | ||
| createArgs: CreateOutgoingPaymentArgs | ||
| ): Promise<OutgoingPaymentWithSpentAmounts> | ||
| getGrantSpentAmounts( |
There was a problem hiding this comment.
Makes sense to me, since it's still "scoped" to the outgoing payments.
Co-authored-by: Max Kurapov <max@interledger.org>
mkurapov
left a comment
There was a problem hiding this comment.
Approving, but let's wait for the Rafiki release + test wallet to go through first
| export type Grant = { | ||
| access_token: ASComponents['schemas']['access_token'] | ||
| continue: ASComponents['schemas']['continue'] | ||
| subject?: Subject |
There was a problem hiding this comment.
Nice, thank you! Let's update the client README and the changeset with this.
client.outgoingPayment.getGrantSpentAmounts)fixes: #17
fixes: #19