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

Use isomorphic fetch #506

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 1 addition & 9 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -91,7 +89,6 @@ export interface ClientOptions {
logLevel?: LogLevel
logger?: Logger
notionVersion?: string
fetch?: SupportedFetch
/** Silently ignored in the browser */
agent?: Agent
}
Expand Down Expand Up @@ -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"
Expand All @@ -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}`
}

Expand Down Expand Up @@ -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
)
Expand Down
9 changes: 4 additions & 5 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SupportedResponse } from "./fetch-types"
import { isObject } from "./utils"
import { Assert } from "./type-utils"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -184,7 +183,7 @@ export class UnknownHTTPResponseError extends HTTPResponseError<ClientErrorCode.
constructor(args: {
status: number
message: string | undefined
headers: SupportedResponse["headers"]
headers: Headers
rawBodyText: string
}) {
super({
Expand Down Expand Up @@ -232,7 +231,7 @@ export class APIResponseError extends HTTPResponseError<APIErrorCode> {
}

export function buildRequestError(
response: SupportedResponse,
response: Response,
bodyText: string
): APIResponseError | UnknownHTTPResponseError {
const apiErrorResponseBody = parseAPIErrorResponseBody(bodyText)
Expand Down
47 changes: 0 additions & 47 deletions src/fetch-types.ts

This file was deleted.