mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
refactor(rest): switch api to fetch-like and provide strategies (#9416)
BREAKING CHANGE: NodeJS v18+ is required when using node due to the use of global `fetch` BREAKING CHANGE: The raw method of REST now returns a web compatible `Respone` object. BREAKING CHANGE: The `parseResponse` utility method has been updated to operate on a web compatible `Response` object. BREAKING CHANGE: Many underlying internals have changed, some of which were exported. BREAKING CHANGE: `DefaultRestOptions` used to contain a default `agent`, which is now set to `null` instead.
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import process from 'node:process';
|
||||
import { lazy } from '@discordjs/util';
|
||||
import { APIVersion } from 'discord-api-types/v10';
|
||||
import { Agent } from 'undici';
|
||||
import type { RESTOptions } from '../REST.js';
|
||||
|
||||
const getUndiciRequest = lazy(async () => {
|
||||
return import('../../strategies/undiciRequest.js');
|
||||
});
|
||||
|
||||
export const DefaultUserAgent =
|
||||
`DiscordBot (https://discord.js.org, [VI]{{inject}}[/VI])` as `DiscordBot (https://discord.js.org, ${string})`;
|
||||
|
||||
@@ -12,13 +16,7 @@ export const DefaultUserAgent =
|
||||
export const DefaultUserAgentAppendix = process.release?.name === 'node' ? `Node.js/${process.version}` : '';
|
||||
|
||||
export const DefaultRestOptions = {
|
||||
get agent() {
|
||||
return new Agent({
|
||||
connect: {
|
||||
timeout: 30_000,
|
||||
},
|
||||
});
|
||||
},
|
||||
agent: null,
|
||||
api: 'https://discord.com/api',
|
||||
authPrefix: 'Bot',
|
||||
cdn: 'https://cdn.discordapp.com',
|
||||
@@ -34,6 +32,10 @@ export const DefaultRestOptions = {
|
||||
hashSweepInterval: 14_400_000, // 4 Hours
|
||||
hashLifetime: 86_400_000, // 24 Hours
|
||||
handlerSweepInterval: 3_600_000, // 1 Hour
|
||||
async makeRequest(...args) {
|
||||
const strategy = await getUndiciRequest();
|
||||
return strategy.makeRequest(...args);
|
||||
},
|
||||
} as const satisfies Required<RESTOptions>;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user