diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f697b08..f04f4ec5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - node-version: [12.x, 14.x, 15.x, 16.x] + node-version: [18.x, 19.x, 20.x, 22.x] steps: - uses: actions/checkout@v2 diff --git a/package.json b/package.json index 93214fb8..32333fb0 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "2.2.15", "description": "A simple and easy to use client for the Notion API", "engines": { - "node": ">=12" + "node": ">=18" }, "homepage": "https://developers.notion.com/docs/getting-started", "bugs": { @@ -39,10 +39,6 @@ "build/package.json", "build/src/**" ], - "dependencies": { - "@types/node-fetch": "^2.5.10", - "node-fetch": "^2.6.1" - }, "devDependencies": { "@types/jest": "^28.1.4", "@typescript-eslint/eslint-plugin": "^5.39.0", diff --git a/src/Client.ts b/src/Client.ts index 338807b9..bbf5b5bc 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -77,12 +77,10 @@ import { OauthTokenParameters, oauthToken, } from "./api-endpoints" -import nodeFetch from "node-fetch" import { version as PACKAGE_VERSION, name as PACKAGE_NAME, } from "../package.json" -import { SupportedFetch } from "./fetch-types" export interface ClientOptions { auth?: string @@ -91,7 +89,6 @@ export interface ClientOptions { logLevel?: LogLevel logger?: Logger notionVersion?: string - fetch?: SupportedFetch /** Silently ignored in the browser */ agent?: Agent } @@ -121,8 +118,6 @@ export default class Client { #prefixUrl: string #timeoutMs: number #notionVersion: string - #fetch: SupportedFetch - #agent: Agent | undefined #userAgent: string static readonly defaultNotionVersion = "2022-06-28" @@ -134,8 +129,6 @@ export default class Client { this.#prefixUrl = (options?.baseUrl ?? "https://api.notion.com") + "/v1/" this.#timeoutMs = options?.timeoutMs ?? 60_000 this.#notionVersion = options?.notionVersion ?? Client.defaultNotionVersion - this.#fetch = options?.fetch ?? nodeFetch - this.#agent = options?.agent this.#userAgent = `notionhq-client/${PACKAGE_VERSION}` } @@ -204,11 +197,10 @@ export default class Client { } try { const response = await RequestTimeoutError.rejectAfterTimeout( - this.#fetch(url.toString(), { + fetch(url.toString(), { method: method.toUpperCase(), headers, body: bodyAsJsonString, - agent: this.#agent, }), this.#timeoutMs ) diff --git a/src/errors.ts b/src/errors.ts index cfec919b..9496f0e2 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,4 +1,3 @@ -import { SupportedResponse } from "./fetch-types" import { isObject } from "./utils" import { Assert } from "./type-utils" @@ -125,14 +124,14 @@ class HTTPResponseError< readonly name: string = "HTTPResponseError" readonly code: Code readonly status: number - readonly headers: SupportedResponse["headers"] + readonly headers: Headers readonly body: string constructor(args: { code: Code status: number message: string - headers: SupportedResponse["headers"] + headers: Headers rawBodyText: string }) { super(args.message) @@ -184,7 +183,7 @@ export class UnknownHTTPResponseError extends HTTPResponseError { } export function buildRequestError( - response: SupportedResponse, + response: Response, bodyText: string ): APIResponseError | UnknownHTTPResponseError { const apiErrorResponseBody = parseAPIErrorResponseBody(bodyText) diff --git a/src/fetch-types.ts b/src/fetch-types.ts deleted file mode 100644 index efaf8cfa..00000000 --- a/src/fetch-types.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { Agent } from "http" -import type { Assert } from "./type-utils" -import type NodeFetchFn from "node-fetch" -import type { - RequestInfo as NodeFetchRequestInfo, - RequestInit as NodeFetchRequestInit, - Response as NodeFetchResponse, -} from "node-fetch" - -// The `Supported` types should be kept up to date in order to exactly match what we use in the client. This ensures maximal compatibility with other `fetch` implementations. -export type SupportedRequestInfo = string -// We can't assert against the browser or native Node fetch types without complicating the package structure (see #401), so perform a best effort against `node-fetch`, which we use by default. -type _assertSupportedInfoIsSubtypeOfNodeFetch = Assert< - NodeFetchRequestInfo, - SupportedRequestInfo -> - -export type SupportedRequestInit = { - agent?: Agent - body?: string - headers?: Record - method?: string -} -type _assertSupportedInitIsSubtypeOfNodeFetch = Assert< - NodeFetchRequestInit, - SupportedRequestInit -> - -export type SupportedResponse = { - ok: boolean - text: () => Promise - headers: unknown - status: number -} -type _assertSupportedResponseIsSubtypeOfNodeFetch = Assert< - SupportedResponse, - NodeFetchResponse -> - -export type SupportedFetch = ( - url: SupportedRequestInfo, - init?: SupportedRequestInit -) => Promise -type _assertSupportedFetchIsSubtypeOfNodeFetch = Assert< - SupportedFetch, - typeof NodeFetchFn ->