@duque.edits/sdk 0.1.5 → 0.1.6
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/index.js +4 -31
- package/dist/managers/base.js +26 -0
- package/dist/managers/buffer/BufferManager.js +2 -2
- package/dist/managers/guild/GuildManager.js +42 -25
- package/dist/managers/index.js +23 -0
- package/dist/managers/match/GuildMatchManager.js +42 -31
- package/dist/managers/message/MessagesManager.js +48 -0
- package/dist/managers/permission/GuildPermissionManager.js +29 -52
- package/dist/managers/ticket/TicketManager.js +77 -0
- package/dist/managers/user/GuildUserManager.js +73 -85
- package/dist/managers/vipmember/VipMemberManager.js +23 -23
- package/dist/rest/REST.js +40 -24
- package/dist/rest/Routes.js +15 -17
- package/dist/rest/index.js +19 -0
- package/dist/structures/Collection.js +1 -1
- package/dist/structures/guild/Guild.js +59 -94
- package/dist/structures/index.js +22 -0
- package/dist/structures/match/GuildMatch.js +64 -111
- package/dist/structures/ticket/Ticket.js +119 -0
- package/dist/structures/user/GuildUser.js +46 -40
- package/dist/structures/vipmember/VipMember.js +5 -5
- package/dist/types/api/APILogMessage.js +2 -0
- package/dist/types/api/index.js +36 -0
- package/dist/types/index.js +1 -22
- package/package.json +11 -18
- package/types/index.d.ts +4 -0
- package/types/managers/base.d.ts +17 -0
- package/{dist → types}/managers/buffer/BufferManager.d.ts +2 -1
- package/{dist → types}/managers/guild/GuildManager.d.ts +12 -4
- package/types/managers/index.d.ts +7 -0
- package/{dist → types}/managers/match/GuildMatchManager.d.ts +10 -12
- package/types/managers/message/MessagesManager.d.ts +17 -0
- package/types/managers/permission/GuildPermissionManager.d.ts +8 -0
- package/types/managers/ticket/TicketManager.d.ts +22 -0
- package/types/managers/user/GuildUserManager.d.ts +19 -0
- package/{dist → types}/managers/vipmember/VipMemberManager.d.ts +8 -8
- package/types/rest/APIEndpoints.d.ts +11 -0
- package/{dist → types}/rest/REST.d.ts +9 -18
- package/{dist → types}/rest/Routes.d.ts +2 -2
- package/types/rest/index.d.ts +3 -0
- package/{dist → types}/structures/guild/Guild.d.ts +12 -29
- package/types/structures/index.d.ts +6 -0
- package/{dist → types}/structures/match/GuildMatch.d.ts +12 -22
- package/types/structures/ticket/Ticket.d.ts +30 -0
- package/{dist → types}/structures/user/GuildUser.d.ts +5 -3
- package/{dist → types}/structures/vipmember/VipMember.d.ts +1 -1
- package/types/types/RestTypes.d.ts +34 -0
- package/{dist → types}/types/api/APIGuild.d.ts +9 -2
- package/{dist → types}/types/api/APIGuildMatch.d.ts +9 -7
- package/types/types/api/APIGuildTicket.d.ts +16 -0
- package/{dist → types}/types/api/APIGuildUser.d.ts +3 -1
- package/types/types/api/APILogMessage.d.ts +7 -0
- package/{dist → types}/types/api/APIMessage.d.ts +3 -4
- package/{dist → types}/types/api/APIPlayer.d.ts +1 -1
- package/{dist → types}/types/api/index.d.ts +23 -1
- package/types/types/index.d.ts +2 -0
- package/dist/index.d.ts +0 -31
- package/dist/managers/bet/GuildBetManager.d.ts +0 -35
- package/dist/managers/bet/GuildBetManager.js +0 -126
- package/dist/managers/betuser/GuildBetUserManager.d.ts +0 -36
- package/dist/managers/betuser/GuildBetUserManager.js +0 -151
- package/dist/managers/channel/ChannelManager.d.ts +0 -39
- package/dist/managers/channel/ChannelManager.js +0 -148
- package/dist/managers/giveaway/GiveawayManager.d.ts +0 -16
- package/dist/managers/giveaway/GiveawayManager.js +0 -57
- package/dist/managers/groupedchannel/GroupedChannelManager.d.ts +0 -34
- package/dist/managers/groupedchannel/GroupedChannelManager.js +0 -92
- package/dist/managers/mediator/GuildMediatorManager.d.ts +0 -32
- package/dist/managers/mediator/GuildMediatorManager.js +0 -98
- package/dist/managers/messages/MessagesManager.d.ts +0 -32
- package/dist/managers/messages/MessagesManager.js +0 -89
- package/dist/managers/permission/GuildPermissionManager.d.ts +0 -26
- package/dist/managers/product/GuildProductManager.d.ts +0 -32
- package/dist/managers/product/GuildProductManager.js +0 -103
- package/dist/managers/ticket/GuildTicketManager.d.ts +0 -32
- package/dist/managers/ticket/GuildTicketManager.js +0 -100
- package/dist/managers/user/GuildUserManager.d.ts +0 -33
- package/dist/rest/APIEndpoints.d.ts +0 -11
- package/dist/structures/bet/GuildBet.d.ts +0 -87
- package/dist/structures/bet/GuildBet.js +0 -286
- package/dist/structures/betuser/GuildBetUser.d.ts +0 -85
- package/dist/structures/betuser/GuildBetUser.js +0 -211
- package/dist/structures/channel/Channel.d.ts +0 -31
- package/dist/structures/channel/Channel.js +0 -57
- package/dist/structures/giveaway/Giveaway.d.ts +0 -37
- package/dist/structures/giveaway/Giveaway.js +0 -208
- package/dist/structures/groupedchannel/GroupedChannel.d.ts +0 -34
- package/dist/structures/groupedchannel/GroupedChannel.js +0 -121
- package/dist/structures/mediator/GuildMediator.d.ts +0 -41
- package/dist/structures/mediator/GuildMediator.js +0 -131
- package/dist/structures/product/GuildProduct.d.ts +0 -52
- package/dist/structures/product/GuildProduct.js +0 -175
- package/dist/structures/shop/GuildShop.d.ts +0 -34
- package/dist/structures/shop/GuildShop.js +0 -80
- package/dist/structures/ticket/GuildTicket.d.ts +0 -52
- package/dist/structures/ticket/GuildTicket.js +0 -172
- package/dist/types/api/APIGuildTicket.d.ts +0 -26
- package/dist/types/index.d.ts +0 -23
- /package/dist/types/{api/APIGuildMessage.js → RestTypes.js} +0 -0
- /package/{dist → types}/structures/Collection.d.ts +0 -0
- /package/{dist → types}/types/api/APIBaseChannel.d.ts +0 -0
- /package/{dist → types}/types/api/APIBetChannel.d.ts +0 -0
- /package/{dist → types}/types/api/APIBetMessage.d.ts +0 -0
- /package/{dist → types}/types/api/APIGiveaway.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildBet.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildBetUser.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildChannel.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildEmoji.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildGroupedChannel.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildMediator.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildMessage.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildPermissions.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildRole.d.ts +0 -0
- /package/{dist → types}/types/api/APIGuildShop.d.ts +0 -0
- /package/{dist → types}/types/api/APIProduct.d.ts +0 -0
- /package/{dist → types}/types/api/APIVipMember.d.ts +0 -0
- /package/{dist → types}/utils/Assertion.d.ts +0 -0
- /package/{dist → types}/utils/getRandomNumber.d.ts +0 -0
|
@@ -2,114 +2,102 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GuildUserManager = void 0;
|
|
4
4
|
const Routes_1 = require("../../rest/Routes");
|
|
5
|
-
const GuildUser_1 = require("../../structures/user/GuildUser");
|
|
6
5
|
const Collection_1 = require("../../structures/Collection");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
rest;
|
|
13
|
-
/** Bet user guild */
|
|
14
|
-
guild;
|
|
15
|
-
/**
|
|
16
|
-
* Manage users with the given client
|
|
17
|
-
* @param users An array of users
|
|
18
|
-
* @param rest The rest client
|
|
19
|
-
*/
|
|
20
|
-
constructor(guild, rest) {
|
|
6
|
+
const GuildUser_1 = require("../../structures/user/GuildUser");
|
|
7
|
+
const base_1 = require("../base");
|
|
8
|
+
class GuildUserManager extends base_1.BaseManager {
|
|
9
|
+
constructor(guild) {
|
|
10
|
+
super(guild);
|
|
21
11
|
this.guild = guild;
|
|
22
|
-
this.rest = rest;
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Fetch a user
|
|
27
|
-
* @param id Id of the user to fetch
|
|
28
|
-
* @returns GuildUser
|
|
29
|
-
*/
|
|
30
|
-
async fetch(id, name) {
|
|
31
|
-
const route = Routes_1.Routes.guilds.users.get(this.guild.id, id);
|
|
32
|
-
const response = await this.rest.request({
|
|
33
|
-
method: "get",
|
|
34
|
-
url: route,
|
|
35
|
-
payload: { name },
|
|
36
|
-
});
|
|
37
|
-
if (!response)
|
|
38
|
-
return this.cache.get(id);
|
|
39
|
-
const user = new GuildUser_1.GuildUser(response, this, this.rest);
|
|
40
|
-
this.cache.set(user?.id, user);
|
|
41
|
-
this.rest.users.set(user?.id, user);
|
|
42
|
-
return user;
|
|
12
|
+
this.rest = guild.rest;
|
|
13
|
+
this.base_url = Routes_1.Routes.guilds.users.getAll(guild.id);
|
|
14
|
+
this.cache = new Collection_1.Collection();
|
|
43
15
|
}
|
|
44
|
-
async
|
|
45
|
-
|
|
46
|
-
const response = await this.rest.request({
|
|
47
|
-
method: "get",
|
|
48
|
-
url: route,
|
|
49
|
-
});
|
|
50
|
-
if (Array.isArray(response) && response.length === 0) {
|
|
51
|
-
this.cache.clear();
|
|
16
|
+
async fetch(options) {
|
|
17
|
+
if (options && options.cache)
|
|
52
18
|
return this.cache;
|
|
19
|
+
if (options && options.userId) {
|
|
20
|
+
const route = Routes_1.Routes.fields(this.base_url, options.userId);
|
|
21
|
+
const response = await this.rest.request({
|
|
22
|
+
method: "GET",
|
|
23
|
+
url: route,
|
|
24
|
+
});
|
|
25
|
+
const user = new GuildUser_1.GuildUser(response, this);
|
|
26
|
+
this.cache.set(user.id, user);
|
|
27
|
+
return user;
|
|
53
28
|
}
|
|
54
|
-
this.
|
|
55
|
-
return this.cache;
|
|
56
|
-
}
|
|
57
|
-
async updateUser(id, name, data) {
|
|
58
|
-
const route = Routes_1.Routes.guilds.users.update(this.guild.id, id);
|
|
59
|
-
const payload = { ...data, name };
|
|
29
|
+
const route = this.base_url;
|
|
60
30
|
const response = await this.rest.request({
|
|
61
|
-
method: "
|
|
31
|
+
method: "GET",
|
|
62
32
|
url: route,
|
|
63
|
-
payload,
|
|
64
33
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return;
|
|
71
|
-
const user = new GuildUser_1.GuildUser(data, this, this.rest);
|
|
72
|
-
this.cache.set(user?.id, user);
|
|
73
|
-
this.rest.users.set(user?.id, user);
|
|
74
|
-
return user;
|
|
75
|
-
}
|
|
76
|
-
setAll(data) {
|
|
77
|
-
if (!data)
|
|
78
|
-
return this.cache;
|
|
79
|
-
for (let user of data)
|
|
80
|
-
this.set(user);
|
|
34
|
+
this.cache.clear();
|
|
35
|
+
for (let userData of response) {
|
|
36
|
+
const user = new GuildUser_1.GuildUser(userData, this);
|
|
37
|
+
this.cache.set(user.id, user);
|
|
38
|
+
}
|
|
81
39
|
return this.cache;
|
|
82
40
|
}
|
|
83
|
-
async
|
|
84
|
-
const route =
|
|
41
|
+
async updateMany(users) {
|
|
42
|
+
const route = this.base_url;
|
|
85
43
|
const response = await this.rest.request({
|
|
86
|
-
method: "
|
|
44
|
+
method: "PATCH",
|
|
87
45
|
url: route,
|
|
46
|
+
payload: users,
|
|
88
47
|
});
|
|
89
|
-
|
|
48
|
+
for (const userData of response) {
|
|
49
|
+
const user = new GuildUser_1.GuildUser(userData, this);
|
|
50
|
+
this.cache.set(user.id, user);
|
|
51
|
+
}
|
|
90
52
|
return this.cache;
|
|
91
53
|
}
|
|
92
|
-
async
|
|
93
|
-
|
|
94
|
-
const route = Routes_1.Routes.guilds.users.delete(id, this.guild.id);
|
|
95
|
-
const user = this.cache.get(id);
|
|
96
|
-
this.rest.emit("userDelete", user);
|
|
54
|
+
async deleteAll() {
|
|
55
|
+
const route = this.base_url;
|
|
97
56
|
await this.rest.request({
|
|
98
57
|
method: "DELETE",
|
|
99
58
|
url: route,
|
|
100
59
|
});
|
|
101
|
-
this.cache.
|
|
102
|
-
return this.cache;
|
|
60
|
+
this.cache.clear();
|
|
103
61
|
}
|
|
104
|
-
async
|
|
105
|
-
const route =
|
|
106
|
-
this.rest.
|
|
107
|
-
|
|
108
|
-
method: "DELETE",
|
|
62
|
+
async resetAll() {
|
|
63
|
+
const route = this.base_url;
|
|
64
|
+
const response = await this.rest.request({
|
|
65
|
+
method: "put",
|
|
109
66
|
url: route,
|
|
110
67
|
});
|
|
111
68
|
this.cache.clear();
|
|
112
|
-
|
|
69
|
+
this._setUsers(response);
|
|
70
|
+
return this.cache;
|
|
71
|
+
}
|
|
72
|
+
_setUsers(data) {
|
|
73
|
+
if (Array.isArray(data)) {
|
|
74
|
+
for (let ud of data) {
|
|
75
|
+
const us = new GuildUser_1.GuildUser(ud, this);
|
|
76
|
+
this.cache.set(us.id, us);
|
|
77
|
+
this.rest.users.set(us.id, us);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const us = new GuildUser_1.GuildUser(data, this);
|
|
82
|
+
this.cache.set(us.id, us);
|
|
83
|
+
this.rest.users.set(us.id, us);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
set(data) {
|
|
87
|
+
if (!data)
|
|
88
|
+
return this.cache;
|
|
89
|
+
if (Array.isArray(data)) {
|
|
90
|
+
for (let _user of data) {
|
|
91
|
+
const user = new GuildUser_1.GuildUser(_user, this);
|
|
92
|
+
this.cache.set(user.id, user);
|
|
93
|
+
}
|
|
94
|
+
return this.cache;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const user = new GuildUser_1.GuildUser(data, this);
|
|
98
|
+
this.cache.set(user.id, user);
|
|
99
|
+
return user;
|
|
100
|
+
}
|
|
113
101
|
}
|
|
114
102
|
}
|
|
115
103
|
exports.GuildUserManager = GuildUserManager;
|
|
@@ -5,20 +5,18 @@ const Routes_1 = require("../../rest/Routes");
|
|
|
5
5
|
const VipMember_1 = require("../../structures/vipmember/VipMember");
|
|
6
6
|
const Collection_1 = require("../../structures/Collection");
|
|
7
7
|
const Assertion_1 = require("../../utils/Assertion");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
cache;
|
|
11
|
-
/** The rest client */
|
|
12
|
-
rest;
|
|
13
|
-
guild;
|
|
8
|
+
const base_1 = require("../base");
|
|
9
|
+
class VipMemberManager extends base_1.BaseManager {
|
|
14
10
|
/**
|
|
15
11
|
* Manage vipmembers with the given client
|
|
16
12
|
* @param vipmembers An array of vipmembers
|
|
17
13
|
* @param rest The rest client
|
|
18
14
|
*/
|
|
19
15
|
constructor(guild, rest) {
|
|
16
|
+
super(guild);
|
|
20
17
|
this.rest = rest;
|
|
21
18
|
this.guild = guild;
|
|
19
|
+
this.base_url = Routes_1.Routes.guilds.resource(guild.id, "vipmembers");
|
|
22
20
|
this.cache = new Collection_1.Collection("vipmembers");
|
|
23
21
|
}
|
|
24
22
|
async create(data) {
|
|
@@ -29,7 +27,7 @@ class VipMemberManager {
|
|
|
29
27
|
url: route,
|
|
30
28
|
payload,
|
|
31
29
|
});
|
|
32
|
-
const member = new VipMember_1.VipMember(response, this
|
|
30
|
+
const member = new VipMember_1.VipMember(response, this);
|
|
33
31
|
this.cache.set(member?.id, member);
|
|
34
32
|
return member;
|
|
35
33
|
}
|
|
@@ -38,21 +36,23 @@ class VipMemberManager {
|
|
|
38
36
|
* @param id Id of the member to fetch
|
|
39
37
|
* @returns VipMember
|
|
40
38
|
*/
|
|
41
|
-
async fetch(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
async fetch(options) {
|
|
40
|
+
if (options && options.cache)
|
|
41
|
+
return this.cache;
|
|
42
|
+
if (options && options.memberId) {
|
|
43
|
+
const route = Routes_1.Routes.vipmembers.get(this.guild.id, options.memberId);
|
|
44
|
+
const payload = { guild_id: this.guild.id };
|
|
45
|
+
const response = await this.rest.request({
|
|
46
|
+
method: "get",
|
|
47
|
+
url: route,
|
|
48
|
+
payload,
|
|
49
|
+
});
|
|
50
|
+
if (!response)
|
|
51
|
+
return this.cache.get(options.memberId);
|
|
52
|
+
const member = new VipMember_1.VipMember(response, this);
|
|
53
|
+
this.cache.set(member?.id, member);
|
|
54
|
+
return member;
|
|
55
|
+
}
|
|
56
56
|
const route = Routes_1.Routes.vipmembers.getAll(this.guild.id);
|
|
57
57
|
const response = await this.rest.request({
|
|
58
58
|
method: "get",
|
|
@@ -79,7 +79,7 @@ class VipMemberManager {
|
|
|
79
79
|
set(data) {
|
|
80
80
|
if (!data?.id)
|
|
81
81
|
return;
|
|
82
|
-
const member = new VipMember_1.VipMember(data, this
|
|
82
|
+
const member = new VipMember_1.VipMember(data, this);
|
|
83
83
|
this.cache.set(member.id, member);
|
|
84
84
|
return member;
|
|
85
85
|
}
|
package/dist/rest/REST.js
CHANGED
|
@@ -4,15 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.REST = void 0;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
+
dotenv_1.default.config();
|
|
7
9
|
const events_1 = __importDefault(require("events"));
|
|
8
10
|
const Assertion_1 = require("../utils/Assertion");
|
|
9
11
|
const undici_1 = require("undici");
|
|
10
12
|
const Routes_1 = require("./Routes");
|
|
11
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
12
13
|
const GuildManager_1 = require("../managers/guild/GuildManager");
|
|
13
14
|
const Collection_1 = require("../structures/Collection");
|
|
14
|
-
const GiveawayManager_1 = require("../managers/giveaway/GiveawayManager");
|
|
15
|
-
dotenv_1.default.config();
|
|
16
15
|
const Reset = "\x1b[0m";
|
|
17
16
|
const FgGreen = "\x1b[32m";
|
|
18
17
|
const FgRed = "\x1b[31m";
|
|
@@ -28,29 +27,18 @@ class REST extends events_1.default {
|
|
|
28
27
|
key;
|
|
29
28
|
/** The guild manager */
|
|
30
29
|
guilds;
|
|
31
|
-
giveaways;
|
|
32
|
-
bets;
|
|
33
|
-
matches;
|
|
34
|
-
betUsers;
|
|
35
30
|
users;
|
|
36
|
-
|
|
31
|
+
matches;
|
|
37
32
|
/**
|
|
38
33
|
*
|
|
39
34
|
* @param key The unique key for he client
|
|
40
35
|
*/
|
|
41
36
|
constructor(key) {
|
|
42
37
|
super({ captureRejections: true });
|
|
43
|
-
|
|
44
|
-
Assertion_1.Assertion.assertString(key);
|
|
45
|
-
this.key = key;
|
|
46
|
-
}
|
|
38
|
+
this.key = key ?? "";
|
|
47
39
|
this.guilds = new GuildManager_1.GuildManager(this);
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.matches = new Collection_1.Collection("matches");
|
|
51
|
-
this.betUsers = new Collection_1.Collection("betUsers");
|
|
52
|
-
this.users = new Collection_1.Collection("users");
|
|
53
|
-
this.mediators = new Collection_1.Collection("mediators");
|
|
40
|
+
this.users = new Collection_1.Collection();
|
|
41
|
+
this.matches = new Collection_1.Collection();
|
|
54
42
|
}
|
|
55
43
|
/**
|
|
56
44
|
* Set the api key
|
|
@@ -61,9 +49,20 @@ class REST extends events_1.default {
|
|
|
61
49
|
}
|
|
62
50
|
/** Initialize the caching sistem */
|
|
63
51
|
async init() {
|
|
64
|
-
|
|
52
|
+
if (!this.key)
|
|
53
|
+
throw new Error("Key is necessary");
|
|
54
|
+
await Promise.all([this.guilds.fetch()]);
|
|
65
55
|
return this;
|
|
66
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Ping the api
|
|
59
|
+
*/
|
|
60
|
+
async ping() {
|
|
61
|
+
return this.request({
|
|
62
|
+
url: "/status",
|
|
63
|
+
method: "get",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
67
66
|
/**
|
|
68
67
|
* Request Data from a certain url
|
|
69
68
|
* @param options
|
|
@@ -77,23 +76,40 @@ class REST extends events_1.default {
|
|
|
77
76
|
method = method.toUpperCase();
|
|
78
77
|
url = Routes_1.Routes.base + url;
|
|
79
78
|
const headers = new undici_1.Headers();
|
|
80
|
-
headers.append("
|
|
79
|
+
headers.append("authorization", process.env.AUTH);
|
|
80
|
+
headers.append("client_key", this.key);
|
|
81
81
|
headers.append("Content-Type", "application/json");
|
|
82
|
-
headers.append("duque-client-key", this.key);
|
|
83
82
|
const before = Date.now();
|
|
84
83
|
this.emit("debug", [`[Request] ${FgBlue}${method} ${FgCyan}${url}`, Reset].join("\n"));
|
|
84
|
+
const body = { ...payload };
|
|
85
85
|
const res = await (0, undici_1.request)(url, {
|
|
86
86
|
method,
|
|
87
87
|
headers,
|
|
88
|
-
body:
|
|
88
|
+
body: JSON.stringify(body),
|
|
89
89
|
});
|
|
90
|
-
const
|
|
91
|
-
const { data, message } =
|
|
90
|
+
const responseBody = await res.body.json();
|
|
91
|
+
const { data, message } = responseBody;
|
|
92
92
|
const now = new Date().getTime();
|
|
93
|
+
if (!data || res.body.errored) {
|
|
94
|
+
if (message)
|
|
95
|
+
this.emit("debug", `${FgRed}${message}${Reset}`);
|
|
96
|
+
this.emit("debug", `[No data]${FgGreen} ${(now - before) / 1000}${Reset}`);
|
|
97
|
+
return "No data available.";
|
|
98
|
+
}
|
|
93
99
|
if (message)
|
|
94
100
|
this.emit("debug", `${FgRed}${message}${Reset}`);
|
|
95
101
|
this.emit("debug", `[Request]${FgGreen} ${(now - before) / 1000}s done.${Reset}`);
|
|
96
102
|
return data;
|
|
97
103
|
}
|
|
104
|
+
emit(event, ...args // tuple type is spread automatically
|
|
105
|
+
) {
|
|
106
|
+
return super.emit(event, ...args);
|
|
107
|
+
}
|
|
108
|
+
on(event, listener) {
|
|
109
|
+
return super.on(event, listener);
|
|
110
|
+
}
|
|
111
|
+
once(event, listener) {
|
|
112
|
+
return super.once(event, listener);
|
|
113
|
+
}
|
|
98
114
|
}
|
|
99
115
|
exports.REST = REST;
|
package/dist/rest/Routes.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Routes =
|
|
4
|
-
const Route = (route) => route;
|
|
5
|
-
exports.Route = Route;
|
|
3
|
+
exports.Routes = void 0;
|
|
6
4
|
exports.Routes = {
|
|
7
|
-
|
|
8
|
-
base: "https://
|
|
5
|
+
base: "http://localhost:80/api/v1",
|
|
6
|
+
//base: "https://dpqd.shardweb.app/api/v1",
|
|
9
7
|
field: (field) => `${field}`,
|
|
10
8
|
fields: (...fields) => `${fields.join("/")}`,
|
|
11
9
|
guilds: {
|
|
@@ -14,8 +12,8 @@ exports.Routes = {
|
|
|
14
12
|
getAll: () => `/guilds`,
|
|
15
13
|
delete: (guildId) => `/guilds/${guildId}`,
|
|
16
14
|
deleteAll: () => `/guilds`,
|
|
17
|
-
resource: (guildId, resource) => `/guilds/${guildId}/${resource}`,
|
|
18
|
-
resources: (guildId, ...resourcess) => `/guilds/${guildId}/${resourcess.join("/")}`,
|
|
15
|
+
resource: (guildId, resource) => `/guilds/${guildId}/manage/${resource}`,
|
|
16
|
+
resources: (guildId, ...resourcess) => `/guilds/${guildId}/manage/${resourcess.join("/")}`,
|
|
19
17
|
users: {
|
|
20
18
|
create: (guildId) => `/guilds/${guildId}/users`,
|
|
21
19
|
update: (guildId, userId) => `/guilds/${guildId}/users/${userId}`,
|
|
@@ -71,18 +69,18 @@ exports.Routes = {
|
|
|
71
69
|
resource: (guildId, mediatorId, ...resources) => `/guilds/${guildId}/mediators/${mediatorId}/${resources.join("/")}`,
|
|
72
70
|
},
|
|
73
71
|
shop: {
|
|
74
|
-
get: (guildId) => `/guilds/${guildId}/shop`,
|
|
75
|
-
update: (guildId) => `/guilds/${guildId}/shop`,
|
|
76
|
-
delete: (guildId) => `/guilds/${guildId}/shop/ `,
|
|
77
|
-
resource: (guildId, ...resources) => `/guilds/${guildId}/shop/${resources.join("/")}`,
|
|
72
|
+
get: (guildId) => `/guilds/${guildId}/manage/shop`,
|
|
73
|
+
update: (guildId) => `/guilds/${guildId}/manage/shop`,
|
|
74
|
+
delete: (guildId) => `/guilds/${guildId}/manage/shop/ `,
|
|
75
|
+
resource: (guildId, ...resources) => `/guilds/${guildId}/manage/shop/${resources.join("/")}`,
|
|
78
76
|
products: {
|
|
79
|
-
getAll: (guildId) => `/guilds/${guildId}/shop/products`,
|
|
80
|
-
get: (guildId, productId) => `/guilds/${guildId}/shop/${productId}/products`,
|
|
81
|
-
create: (guildId) => `/guilds/${guildId}/shop/products`,
|
|
82
|
-
update: (guildId, productId) => `/guilds/${guildId}/shop/products/${productId}`,
|
|
83
|
-
delete: (guildId, productId) => `/guilds/${guildId}/shop/products/${productId}`,
|
|
77
|
+
getAll: (guildId) => `/guilds/${guildId}/manage/shop/products`,
|
|
78
|
+
get: (guildId, productId) => `/guilds/${guildId}/manage/shop/${productId}/products`,
|
|
79
|
+
create: (guildId) => `/guilds/${guildId}/manage/shop/products`,
|
|
80
|
+
update: (guildId, productId) => `/guilds/${guildId}/manage/shop/products/${productId}`,
|
|
81
|
+
delete: (guildId, productId) => `/guilds/${guildId}/manage/shop/products/${productId}`,
|
|
84
82
|
deleteAll: (guildId) => `/guilds/${guildId}/products/shop`,
|
|
85
|
-
resource: (guildId, productId, ...resources) => `/guilds/${guildId}/shop/products/${productId}/${resources.join("/")}`,
|
|
83
|
+
resource: (guildId, productId, ...resources) => `/guilds/${guildId}/manage/shop/products/${productId}/${resources.join("/")}`,
|
|
86
84
|
},
|
|
87
85
|
},
|
|
88
86
|
},
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./APIEndpoints"), exports);
|
|
18
|
+
__exportStar(require("./Routes"), exports);
|
|
19
|
+
__exportStar(require("./REST"), exports);
|