@discordeno/rest 19.0.0-next.f41fe4d → 19.0.0-next.f5abd83
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/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +45 -52
- package/dist/manager.js.map +1 -1
- package/dist/types.d.ts +4 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
package/dist/manager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAmEA,OAAO,KAAK,EAA4B,wBAAwB,EAAE,WAAW,EAAsB,MAAM,YAAY,CAAA;AAKrH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAmEA,OAAO,KAAK,EAA4B,wBAAwB,EAAE,WAAW,EAAsB,MAAM,YAAY,CAAA;AAKrH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,WAAW,CAmsDhF"}
|
package/dist/manager.js
CHANGED
|
@@ -545,46 +545,47 @@ export function createRestManager(options) {
|
|
|
545
545
|
if (typeof obj === 'bigint') return obj.toString();
|
|
546
546
|
return obj;
|
|
547
547
|
},
|
|
548
|
-
|
|
548
|
+
createRequestBody (method, options) {
|
|
549
549
|
const headers = {
|
|
550
550
|
'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`
|
|
551
551
|
};
|
|
552
|
-
if (!options
|
|
552
|
+
if (!options?.unauthorized) headers.authorization = `Bot ${rest.token}`;
|
|
553
553
|
// IF A REASON IS PROVIDED ENCODE IT IN HEADERS
|
|
554
|
-
if (options
|
|
555
|
-
headers['x-audit-log-reason'] = encodeURIComponent(options
|
|
554
|
+
if (options?.reason !== undefined) {
|
|
555
|
+
headers['x-audit-log-reason'] = encodeURIComponent(options?.reason);
|
|
556
556
|
}
|
|
557
557
|
let body;
|
|
558
558
|
// TODO: check if we need to add specific check for GET method
|
|
559
559
|
// Since GET does not allow bodies
|
|
560
560
|
// Have to check for attachments first, since body then has to be send in a different way.
|
|
561
|
-
if (options
|
|
561
|
+
if (options?.files !== undefined) {
|
|
562
562
|
const form = new FormData();
|
|
563
|
-
for(let i = 0; i < options.
|
|
564
|
-
form.append(`file${i}`, options.
|
|
563
|
+
for(let i = 0; i < options.files.length; ++i){
|
|
564
|
+
form.append(`file${i}`, options.files[i].blob, options.files[i].name);
|
|
565
565
|
}
|
|
566
|
-
form.append('payload_json', JSON.stringify(
|
|
566
|
+
form.append('payload_json', JSON.stringify({
|
|
567
|
+
...options.body,
|
|
568
|
+
files: undefined
|
|
569
|
+
}));
|
|
567
570
|
body = form;
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
headers['content-type'] = `multipart/form-data`;
|
|
571
|
-
} else if (options.body !== undefined) {
|
|
571
|
+
// No need to set the `content-type` header since `fetch` does that automatically for us when we use a `FormData` object.
|
|
572
|
+
} else if (options?.body !== undefined) {
|
|
572
573
|
if (options.body instanceof FormData) {
|
|
573
574
|
body = options.body;
|
|
574
|
-
|
|
575
|
+
// No need to set the `content-type` header since `fetch` does that automatically for us when we use a `FormData` object.
|
|
575
576
|
} else {
|
|
576
|
-
body = JSON.stringify(options.body);
|
|
577
|
+
body = JSON.stringify(rest.changeToDiscordFormat(options.body));
|
|
577
578
|
headers['content-type'] = `application/json`;
|
|
578
579
|
}
|
|
579
580
|
}
|
|
580
581
|
// SOMETIMES SPECIAL HEADERS (E.G. CUSTOM AUTHORIZATION) NEED TO BE USED
|
|
581
|
-
if (options
|
|
582
|
+
if (options?.headers) {
|
|
582
583
|
Object.assign(headers, options.headers);
|
|
583
584
|
}
|
|
584
585
|
return {
|
|
585
586
|
body,
|
|
586
587
|
headers,
|
|
587
|
-
method
|
|
588
|
+
method
|
|
588
589
|
};
|
|
589
590
|
},
|
|
590
591
|
processRateLimitedPaths () {
|
|
@@ -679,12 +680,7 @@ export function createRestManager(options) {
|
|
|
679
680
|
},
|
|
680
681
|
async sendRequest (options) {
|
|
681
682
|
const url = options.url.startsWith('https://') ? options.url : `${rest.baseUrl}/v${rest.version}${options.url}`;
|
|
682
|
-
const payload = rest.
|
|
683
|
-
method: options.method,
|
|
684
|
-
url: options.url,
|
|
685
|
-
body: options.options?.body,
|
|
686
|
-
...options.options
|
|
687
|
-
});
|
|
683
|
+
const payload = rest.createRequestBody(options.method, options.requestBodyOptions);
|
|
688
684
|
logger.debug(`sending request to ${url}`, 'with payload:', {
|
|
689
685
|
...payload,
|
|
690
686
|
headers: {
|
|
@@ -825,7 +821,7 @@ export function createRestManager(options) {
|
|
|
825
821
|
const payload = {
|
|
826
822
|
url,
|
|
827
823
|
method,
|
|
828
|
-
options,
|
|
824
|
+
requestBodyOptions: options,
|
|
829
825
|
retryCount: 0,
|
|
830
826
|
retryRequest: async function(payload) {
|
|
831
827
|
rest.processRequest(payload);
|
|
@@ -838,30 +834,20 @@ export function createRestManager(options) {
|
|
|
838
834
|
rest.processRequest(payload);
|
|
839
835
|
});
|
|
840
836
|
},
|
|
841
|
-
async get (url,
|
|
842
|
-
return camelize(await rest.makeRequest('GET', url,
|
|
843
|
-
body
|
|
844
|
-
}));
|
|
837
|
+
async get (url, options) {
|
|
838
|
+
return camelize(await rest.makeRequest('GET', url, options));
|
|
845
839
|
},
|
|
846
|
-
async post (url,
|
|
847
|
-
return camelize(await rest.makeRequest('POST', url,
|
|
848
|
-
body
|
|
849
|
-
}));
|
|
840
|
+
async post (url, options) {
|
|
841
|
+
return camelize(await rest.makeRequest('POST', url, options));
|
|
850
842
|
},
|
|
851
|
-
async delete (url,
|
|
852
|
-
camelize(await rest.makeRequest('DELETE', url,
|
|
853
|
-
body
|
|
854
|
-
}));
|
|
843
|
+
async delete (url, options) {
|
|
844
|
+
camelize(await rest.makeRequest('DELETE', url, options));
|
|
855
845
|
},
|
|
856
|
-
async patch (url,
|
|
857
|
-
return camelize(await rest.makeRequest('PATCH', url,
|
|
858
|
-
body
|
|
859
|
-
}));
|
|
846
|
+
async patch (url, options) {
|
|
847
|
+
return camelize(await rest.makeRequest('PATCH', url, options));
|
|
860
848
|
},
|
|
861
|
-
async put (url,
|
|
862
|
-
return camelize(await rest.makeRequest('PUT', url,
|
|
863
|
-
body
|
|
864
|
-
}));
|
|
849
|
+
async put (url, options) {
|
|
850
|
+
return camelize(await rest.makeRequest('PUT', url, options));
|
|
865
851
|
},
|
|
866
852
|
async addReaction (channelId, messageId, reaction) {
|
|
867
853
|
reaction = processReactionString(reaction);
|
|
@@ -941,7 +927,8 @@ export function createRestManager(options) {
|
|
|
941
927
|
},
|
|
942
928
|
async createForumThread (channelId, body) {
|
|
943
929
|
return await rest.post(rest.routes.channels.forum(channelId), {
|
|
944
|
-
body
|
|
930
|
+
body,
|
|
931
|
+
files: body.files
|
|
945
932
|
});
|
|
946
933
|
},
|
|
947
934
|
async createInvite (channelId, body = {}) {
|
|
@@ -1121,7 +1108,8 @@ export function createRestManager(options) {
|
|
|
1121
1108
|
},
|
|
1122
1109
|
async editFollowupMessage (token, messageId, body) {
|
|
1123
1110
|
return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
|
|
1124
|
-
body
|
|
1111
|
+
body,
|
|
1112
|
+
files: body.files
|
|
1125
1113
|
});
|
|
1126
1114
|
},
|
|
1127
1115
|
async editGlobalApplicationCommand (commandId, body) {
|
|
@@ -1164,7 +1152,8 @@ export function createRestManager(options) {
|
|
|
1164
1152
|
},
|
|
1165
1153
|
async editOriginalInteractionResponse (token, body) {
|
|
1166
1154
|
return await rest.patch(rest.routes.interactions.responses.original(rest.applicationId, token), {
|
|
1167
|
-
body
|
|
1155
|
+
body,
|
|
1156
|
+
files: body.files
|
|
1168
1157
|
});
|
|
1169
1158
|
},
|
|
1170
1159
|
async editOriginalWebhookMessage (webhookId, token, options) {
|
|
@@ -1172,7 +1161,8 @@ export function createRestManager(options) {
|
|
|
1172
1161
|
body: {
|
|
1173
1162
|
type: InteractionResponseTypes.UpdateMessage,
|
|
1174
1163
|
data: options
|
|
1175
|
-
}
|
|
1164
|
+
},
|
|
1165
|
+
files: options.files
|
|
1176
1166
|
});
|
|
1177
1167
|
},
|
|
1178
1168
|
async editOwnVoiceState (guildId, options) {
|
|
@@ -1218,7 +1208,8 @@ export function createRestManager(options) {
|
|
|
1218
1208
|
},
|
|
1219
1209
|
async editWebhookMessage (webhookId, token, messageId, options) {
|
|
1220
1210
|
return await rest.patch(rest.routes.webhooks.message(webhookId, token, messageId, options), {
|
|
1221
|
-
body: options
|
|
1211
|
+
body: options,
|
|
1212
|
+
files: options.files
|
|
1222
1213
|
});
|
|
1223
1214
|
},
|
|
1224
1215
|
async editWebhookWithToken (webhookId, token, body) {
|
|
@@ -1463,8 +1454,9 @@ export function createRestManager(options) {
|
|
|
1463
1454
|
rest.sendRequest({
|
|
1464
1455
|
url: rest.routes.webhooks.webhook(rest.applicationId, token),
|
|
1465
1456
|
method: 'POST',
|
|
1466
|
-
|
|
1467
|
-
body: options
|
|
1457
|
+
requestBodyOptions: {
|
|
1458
|
+
body: options,
|
|
1459
|
+
files: options.files
|
|
1468
1460
|
},
|
|
1469
1461
|
retryCount: 0,
|
|
1470
1462
|
retryRequest: async function(options) {
|
|
@@ -1484,7 +1476,7 @@ export function createRestManager(options) {
|
|
|
1484
1476
|
rest.sendRequest({
|
|
1485
1477
|
url: rest.routes.interactions.responses.callback(interactionId, token),
|
|
1486
1478
|
method: 'POST',
|
|
1487
|
-
|
|
1479
|
+
requestBodyOptions: {
|
|
1488
1480
|
body: options
|
|
1489
1481
|
},
|
|
1490
1482
|
retryCount: 0,
|
|
@@ -1501,7 +1493,8 @@ export function createRestManager(options) {
|
|
|
1501
1493
|
},
|
|
1502
1494
|
async sendMessage (channelId, body) {
|
|
1503
1495
|
return await rest.post(rest.routes.channels.messages(channelId), {
|
|
1504
|
-
body
|
|
1496
|
+
body,
|
|
1497
|
+
files: body.files
|
|
1505
1498
|
});
|
|
1506
1499
|
},
|
|
1507
1500
|
async startThreadWithMessage (channelId, messageId, body) {
|