@discordjs/rest 0.4.0-dev.1649505800-3c0bbac → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,92 @@
1
- # `@discordjs/rest`
1
+ <div align="center">
2
+ <br />
3
+ <p>
4
+ <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
5
+ </p>
6
+ <br />
7
+ <p>
8
+ <a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
9
+ <a href="https://www.npmjs.com/package/@discordjs/rest"><img src="https://img.shields.io/npm/v/@discordjs/rest.svg?maxAge=3600" alt="npm version" /></a>
10
+ <a href="https://www.npmjs.com/package/@discordjs/rest"><img src="https://img.shields.io/npm/dt/@discordjs/rest.svg?maxAge=3600" alt="npm downloads" /></a>
11
+ <a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Tests status" /></a>
12
+ </p>
13
+ </div>
2
14
 
3
- > The REST API module for Discord.js
15
+ ## Installation
16
+
17
+ **Node.js 16.9.0 or newer is required.**
18
+
19
+ ```sh-session
20
+ npm install @discordjs/rest
21
+ yarn add @discordjs/rest
22
+ pnpm add @discordjs/rest
23
+ ```
24
+
25
+ ## Examples
26
+
27
+ Install all required dependencies:
28
+
29
+ ```sh-session
30
+ npm install @discordjs/rest discord-api-types
31
+ yarn add @discordjs/rest discord-api-types
32
+ pnpm add @discordjs/rest discord-api-types
33
+ ```
34
+
35
+ Send a basic message:
36
+
37
+ ```js
38
+ import { REST } from '@discordjs/rest';
39
+ import { Routes } from 'discord-api-types/v10';
40
+
41
+ const rest = new REST({ version: '10' }).setToken('token');
42
+
43
+ try {
44
+ await rest.post(Routes.channelMessages(CHANNEL_ID), {
45
+ body: {
46
+ content: 'A message via REST!',
47
+ },
48
+ });
49
+ } catch (error) {
50
+ console.error(error);
51
+ }
52
+ ```
53
+
54
+ Create a thread from an existing message to be archived after 60 minutes of inactivity:
55
+
56
+ ```js
57
+ import { REST } from '@discordjs/rest';
58
+ import { Routes } from 'discord-api-types/v10';
59
+
60
+ const rest = new REST({ version: '10' }).setToken('token');
61
+
62
+ try {
63
+ await rest.post(Routes.threads(CHANNEL_ID, MESSAGE_ID), {
64
+ body: {
65
+ name: 'Thread',
66
+ auto_archive_duration: 60,
67
+ },
68
+ });
69
+ } catch (error) {
70
+ console.error(error);
71
+ }
72
+ ```
73
+
74
+ ## Links
75
+
76
+ - [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))
77
+ - [Dev documentation](https://discord.js.org/#/docs/rest/main/general/welcome) (stable coming soon)
78
+ - [discord.js Discord server](https://discord.gg/djs)
79
+ - [Discord API Discord server](https://discord.gg/discord-api)
80
+ - [GitHub](https://github.com/discordjs/discord.js/tree/main/packages/rest)
81
+ - [npm](https://www.npmjs.com/package/@discordjs/rest)
82
+ - [Related libraries](https://discord.com/developers/docs/topics/community-resources#libraries)
83
+
84
+ ## Contributing
85
+
86
+ Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
87
+ [documentation](https://discord.js.org/#/docs/rest/main/general/welcome).
88
+ See [the contribution guide](https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md) if you'd like to submit a PR.
89
+
90
+ ## Help
91
+
92
+ If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server](https://discord.gg/djs).
package/dist/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './lib/errors/RateLimitError';
6
6
  export * from './lib/RequestManager';
7
7
  export * from './lib/REST';
8
8
  export * from './lib/utils/constants';
9
+ export { makeURLSearchParams } from './lib/utils/utils';
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
10
9
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
10
  var __commonJS = (cb, mod) => function __require() {
12
11
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -15,22 +14,16 @@ var __export = (target, all) => {
15
14
  for (var name in all)
16
15
  __defProp(target, name, { get: all[name], enumerable: true });
17
16
  };
18
- var __reExport = (target, module2, copyDefault, desc) => {
19
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
20
- for (let key of __getOwnPropNames(module2))
21
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
22
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
22
  }
24
- return target;
23
+ return to;
25
24
  };
26
- var __toESM = (module2, isNodeMode) => {
27
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
28
- };
29
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
30
- return (module2, temp) => {
31
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
32
- };
33
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var __publicField = (obj, key, value) => {
35
28
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
36
29
  return value;
@@ -59,7 +52,7 @@ var require_package = __commonJS({
59
52
  "package.json"(exports, module2) {
60
53
  module2.exports = {
61
54
  name: "@discordjs/rest",
62
- version: "0.4.0-dev",
55
+ version: "0.4.0",
63
56
  description: "The REST API for discord.js",
64
57
  scripts: {
65
58
  build: "tsup && tsc --emitDeclarationOnly --incremental",
@@ -110,35 +103,35 @@ var require_package = __commonJS({
110
103
  homepage: "https://discord.js.org",
111
104
  dependencies: {
112
105
  "@discordjs/collection": "workspace:^",
113
- "@sapphire/async-queue": "^1.2.0",
114
- "@sapphire/snowflake": "^3.1.0",
115
- "@types/node-fetch": "^2.5.12",
106
+ "@sapphire/async-queue": "^1.3.1",
107
+ "@sapphire/snowflake": "^3.2.1",
108
+ "@types/node-fetch": "^2.6.1",
116
109
  "discord-api-types": "^0.29.0",
117
110
  "form-data": "^4.0.0",
118
111
  "node-fetch": "^2.6.7",
119
112
  tslib: "^2.3.1"
120
113
  },
121
114
  devDependencies: {
122
- "@babel/core": "^7.17.2",
123
- "@babel/plugin-proposal-decorators": "^7.17.2",
115
+ "@babel/core": "^7.17.9",
116
+ "@babel/plugin-proposal-decorators": "^7.17.9",
124
117
  "@babel/preset-env": "^7.16.11",
125
118
  "@babel/preset-typescript": "^7.16.7",
126
- "@discordjs/ts-docgen": "^0.3.4",
127
- "@types/jest": "^27.4.0",
128
- "@typescript-eslint/eslint-plugin": "^5.11.0",
129
- "@typescript-eslint/parser": "^5.11.0",
119
+ "@discordjs/ts-docgen": "^0.4.1",
120
+ "@types/jest": "^27.4.1",
121
+ "@typescript-eslint/eslint-plugin": "^5.19.0",
122
+ "@typescript-eslint/parser": "^5.19.0",
130
123
  "babel-plugin-const-enum": "^1.2.0",
131
124
  "babel-plugin-transform-typescript-metadata": "^0.3.2",
132
- eslint: "^8.9.0",
133
- "eslint-config-marine": "^9.3.2",
134
- "eslint-config-prettier": "^8.3.0",
135
- "eslint-plugin-prettier": "^4.0.0",
125
+ eslint: "^8.13.0",
126
+ "eslint-config-marine": "^9.4.1",
127
+ "eslint-config-prettier": "^8.5.0",
128
+ "eslint-plugin-import": "^2.26.0",
136
129
  jest: "^27.5.1",
137
130
  nock: "^13.2.4",
138
- prettier: "^2.5.1",
139
- tsup: "^5.11.13",
140
- typedoc: "^0.22.11",
141
- typescript: "^4.5.5"
131
+ prettier: "^2.6.2",
132
+ tsup: "^5.12.5",
133
+ typedoc: "^0.22.15",
134
+ typescript: "^4.6.3"
142
135
  },
143
136
  engines: {
144
137
  node: ">=16.9.0"
@@ -165,8 +158,10 @@ __export(src_exports, {
165
158
  RESTEvents: () => RESTEvents,
166
159
  RateLimitError: () => RateLimitError,
167
160
  RequestManager: () => RequestManager,
168
- RequestMethod: () => RequestMethod
161
+ RequestMethod: () => RequestMethod,
162
+ makeURLSearchParams: () => makeURLSearchParams
169
163
  });
164
+ module.exports = __toCommonJS(src_exports);
170
165
 
171
166
  // src/lib/utils/constants.ts
172
167
  var import_v10 = require("discord-api-types/v10");
@@ -377,12 +372,12 @@ var RateLimitError = class extends Error {
377
372
  __name(RateLimitError, "RateLimitError");
378
373
 
379
374
  // src/lib/RequestManager.ts
380
- var import_collection = __toESM(require("@discordjs/collection"));
381
- var import_form_data = __toESM(require("form-data"));
382
- var import_snowflake = require("@sapphire/snowflake");
383
375
  var import_node_events = require("events");
384
- var import_node_https = require("https");
385
376
  var import_node_http = require("http");
377
+ var import_node_https = require("https");
378
+ var import_collection = __toESM(require("@discordjs/collection"));
379
+ var import_snowflake = require("@sapphire/snowflake");
380
+ var import_form_data = __toESM(require("form-data"));
386
381
 
387
382
  // src/lib/handlers/SequentialHandler.ts
388
383
  var import_promises = require("timers/promises");
@@ -390,6 +385,40 @@ var import_async_queue = require("@sapphire/async-queue");
390
385
  var import_node_fetch = __toESM(require("node-fetch"));
391
386
 
392
387
  // src/lib/utils/utils.ts
388
+ function serializeSearchParam(value) {
389
+ switch (typeof value) {
390
+ case "string":
391
+ return value;
392
+ case "number":
393
+ case "bigint":
394
+ case "boolean":
395
+ return value.toString();
396
+ case "object":
397
+ if (value === null)
398
+ return null;
399
+ if (value instanceof Date) {
400
+ return Number.isNaN(value.getTime()) ? null : value.toISOString();
401
+ }
402
+ if (typeof value.toString === "function" && value.toString !== Object.prototype.toString)
403
+ return value.toString();
404
+ return null;
405
+ default:
406
+ return null;
407
+ }
408
+ }
409
+ __name(serializeSearchParam, "serializeSearchParam");
410
+ function makeURLSearchParams(options) {
411
+ const params = new URLSearchParams();
412
+ if (!options)
413
+ return params;
414
+ for (const [key, value] of Object.entries(options)) {
415
+ const serialized = serializeSearchParam(value);
416
+ if (serialized !== null)
417
+ params.append(key, serialized);
418
+ }
419
+ return params;
420
+ }
421
+ __name(makeURLSearchParams, "makeURLSearchParams");
393
422
  function parseResponse(res) {
394
423
  if (res.headers.get("Content-Type")?.startsWith("application/json")) {
395
424
  return res.json();
@@ -908,7 +937,6 @@ var REST = class extends import_node_events2.EventEmitter {
908
937
  }
909
938
  };
910
939
  __name(REST, "REST");
911
- module.exports = __toCommonJS(src_exports);
912
940
  // Annotate the CommonJS export names for ESM import in node:
913
941
  0 && (module.exports = {
914
942
  ALLOWED_EXTENSIONS,
@@ -923,6 +951,7 @@ module.exports = __toCommonJS(src_exports);
923
951
  RESTEvents,
924
952
  RateLimitError,
925
953
  RequestManager,
926
- RequestMethod
954
+ RequestMethod,
955
+ makeURLSearchParams
927
956
  });
928
957
  //# sourceMappingURL=index.js.map