Skip to content

Commit

Permalink
feat: remove node-fetch (#303)
Browse files Browse the repository at this point in the history
* feat: remove node-fetch

* fix: pass fetch directly as fetchApi
  • Loading branch information
SgtPooki authored Jul 17, 2023
1 parent 4984128 commit 750b1db
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
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

0 comments on commit 750b1db

Please sign in to comment.