-
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
feat(open-payments): adding open-payments package #669
Merged
Merged
Changes from 6 commits
Commits
Show all changes
18 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 43335f6
feat(open-payments): use updated RS spec
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "open-payments", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"scripts": { | ||
"build": "pnpm clean && tsc --build tsconfig.json", | ||
"clean": "rm -fr dist/", | ||
"prepack": "pnpm build", | ||
"generate:types": "npx ts-node scripts/generate-types.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.7.12", | ||
"openapi-typescript": "^4.5.0", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.3.0" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.1.2" | ||
} | ||
} |
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,19 @@ | ||
import fs from 'fs' | ||
import openapiTS from 'openapi-typescript' | ||
import config from '../src/config' | ||
;(async () => { | ||
try { | ||
const output = await openapiTS(config.OPEN_PAYMENTS_OPEN_API_URL) | ||
const fileName = 'src/generated/types.ts' | ||
|
||
fs.writeFile(fileName, output, (error) => { | ||
if (error) { | ||
console.log(`Error when writing types to ${fileName}`, { error }) | ||
} | ||
}) | ||
} catch (error) { | ||
console.log('Error when generating types', { | ||
error | ||
}) | ||
} | ||
})() |
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,57 @@ | ||
import { ILPStreamConnection, IncomingPayment } from './types' | ||
import axios, { AxiosInstance } from 'axios' | ||
import config from './config' | ||
|
||
interface CreateOpenPaymentClientArgs { | ||
timeout?: number | ||
} | ||
|
||
interface GetArgs { | ||
url: string | ||
accessToken: string | ||
} | ||
|
||
export interface OpenPaymentsClient { | ||
incomingPayment: { | ||
get(args: GetArgs): Promise<IncomingPayment> | ||
} | ||
ilpStreamConnection: { | ||
get(args: GetArgs): Promise<ILPStreamConnection> | ||
} | ||
} | ||
|
||
const get = async <T>(axios: AxiosInstance, args: GetArgs): Promise<T> => { | ||
const { url, accessToken } = args | ||
|
||
const { data } = await axios.get(url, { | ||
headers: accessToken | ||
? { | ||
Authorization: `GNAP ${accessToken}`, | ||
Signature: 'TODO', | ||
'Signature-Input': 'TODO' | ||
} | ||
: {} | ||
}) | ||
|
||
return data | ||
} | ||
|
||
export const createClient = ( | ||
args?: CreateOpenPaymentClientArgs | ||
): OpenPaymentsClient => { | ||
const defaultTimeout = config.DEFAULT_REQUEST_TIMEOUT || 3_000 | ||
const axiosInstance = axios.create({ | ||
timeout: args.timeout ?? defaultTimeout | ||
}) | ||
|
||
axiosInstance.defaults.headers.common['Content-Type'] = 'application/json' | ||
|
||
return { | ||
incomingPayment: { | ||
get: (args: GetArgs) => get<IncomingPayment>(axios, args) | ||
}, | ||
ilpStreamConnection: { | ||
get: (args: GetArgs) => get<ILPStreamConnection>(axios, args) | ||
} | ||
} | ||
} |
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,5 @@ | ||
export default { | ||
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. want to make sure the same URL is used for type generation and (soon to be added) open API response validation |
||
'https://raw.githubusercontent.com/interledger/open-payments/main/open-api-spec.yaml', | ||
mkurapov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
DEFAULT_REQUEST_TIMEOUT: 3_000 | ||
} |
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.
I wrested quite a bit with this, but I wasn't able to use the newest version of this library. Using the programmatic way of generating types via
openapiTS
anything above v5 does not work and result inERR_REQUIRE_ESM
errors. Versions 5 and above do not support backwards compatibility with CommonJS, especially given the fact that havingtype: module
inpackage.json
breaks using this package as a workspace in the/backend
project.one two three are the related issues in the
openapi-typescript
repo.