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: remove node-fetch #303

Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 15 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@
"marked": "^4.0.16",
"marked-terminal": "^5.1.1",
"multiformats": "^9.6.5",
"node-fetch": "^3.2.4",
"oas2joi": "^2.0.2",
"p-defer": "^4.0.0",
"p-queue": "^7.2.0",
Expand Down
5 changes: 2 additions & 3 deletions src/ApiCall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { Schema, ValidationError, ValidationResult } from '@hapi/joi'
import { Request } from 'node-fetch'
import type { RequestInit, Response } from 'node-fetch'
import type { Logger } from 'winston'
import pDefer from 'p-defer'

Expand Down Expand Up @@ -146,7 +144,8 @@ class ApiCall<T extends PinsApiResponseTypes, P extends PinsApiResponseTypes = n
}

get httpRequest () {
const request = new Request(this.requestContext.url, this.requestContext.init as RequestInit)
const { init, url } = this.requestContext
const request = new Request(url, init)

return request
}
Expand Down
14 changes: 3 additions & 11 deletions src/clientFromServiceAndTokenPair.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import fetch from 'node-fetch'
import type { RequestInfo, RequestInit } from 'node-fetch'

import { RemotePinningServiceClient, Configuration, NodeFetch } from '@ipfs-shipyard/pinning-service-client'
import { RemotePinningServiceClient, Configuration } from '@ipfs-shipyard/pinning-service-client'

import { requestResponseLogger, RequestResponseLoggerOptions } from './middleware/requestReponseLogger.js'
import type { ServiceAndTokenPair } from './types.js'

function clientFromServiceAndTokenPair ([endpointUrl, accessToken]: ServiceAndTokenPair, middleWareOptions?: Omit<RequestResponseLoggerOptions, 'pair'>): RemotePinningServiceClient {
const requestResponseLoggerOptions: RequestResponseLoggerOptions = { ...middleWareOptions, pair: [endpointUrl, accessToken] }
const config = new (Configuration as typeof NodeFetch.Configuration)({
const config = new Configuration({
endpointUrl,
accessToken,
fetchApi: async (url: RequestInfo, init?: RequestInit) => {
return await fetch(url, {
...init,
highWaterMark: 1024 * 1024 * 2
})
},
fetchApi: fetch,
middleware: [
requestResponseLogger(requestResponseLoggerOptions)
]
Expand Down
1 change: 0 additions & 1 deletion src/middleware/requestReponseLogger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NodeFetch, Pin } from '@ipfs-shipyard/pinning-service-client'
import type { Response } from 'node-fetch'

import { waitForDate } from '../utils/waitForDate.js'
import type { ComplianceCheckDetailsCallbackArg, ServiceAndTokenPair } from '../types.js'
Expand Down
2 changes: 0 additions & 2 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Response } from 'node-fetch'
import type fetch from 'node-fetch'
import type {
NodeFetch,
ConfigurationParameters as ConfigurationParameters_og,
Expand Down