hischool.js 0.0.1
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 +41 -0
- package/lib/cjs/Client.d.ts +166 -0
- package/lib/cjs/Client.d.ts.map +1 -0
- package/lib/cjs/Client.js +221 -0
- package/lib/cjs/api/baseURL.d.ts +2 -0
- package/lib/cjs/api/baseURL.d.ts.map +1 -0
- package/lib/cjs/api/baseURL.js +5 -0
- package/lib/cjs/api/index.d.ts +177 -0
- package/lib/cjs/api/index.d.ts.map +1 -0
- package/lib/cjs/api/index.js +150 -0
- package/lib/cjs/api/params.d.ts +285 -0
- package/lib/cjs/api/params.d.ts.map +1 -0
- package/lib/cjs/api/params.js +194 -0
- package/lib/cjs/api/routes.d.ts +1089 -0
- package/lib/cjs/api/routes.d.ts.map +1 -0
- package/lib/cjs/api/routes.js +2 -0
- package/lib/cjs/api/schema.d.ts +4705 -0
- package/lib/cjs/api/schema.d.ts.map +1 -0
- package/lib/cjs/api/schema.js +2 -0
- package/lib/cjs/api/types.d.ts +131 -0
- package/lib/cjs/api/types.d.ts.map +1 -0
- package/lib/cjs/api/types.js +2 -0
- package/lib/cjs/classes/BannedUser.d.ts +18 -0
- package/lib/cjs/classes/BannedUser.d.ts.map +1 -0
- package/lib/cjs/classes/BannedUser.js +21 -0
- package/lib/cjs/classes/Bot.d.ts +82 -0
- package/lib/cjs/classes/Bot.d.ts.map +1 -0
- package/lib/cjs/classes/Bot.js +145 -0
- package/lib/cjs/classes/Channel.d.ts +465 -0
- package/lib/cjs/classes/Channel.d.ts.map +1 -0
- package/lib/cjs/classes/Channel.js +599 -0
- package/lib/cjs/classes/ChannelUnread.d.ts +27 -0
- package/lib/cjs/classes/ChannelUnread.d.ts.map +1 -0
- package/lib/cjs/classes/ChannelUnread.js +50 -0
- package/lib/cjs/classes/ChannelWebhook.d.ts +53 -0
- package/lib/cjs/classes/ChannelWebhook.d.ts.map +1 -0
- package/lib/cjs/classes/ChannelWebhook.js +113 -0
- package/lib/cjs/classes/Emoji.d.ts +57 -0
- package/lib/cjs/classes/Emoji.d.ts.map +1 -0
- package/lib/cjs/classes/Emoji.js +104 -0
- package/lib/cjs/classes/File.d.ts +67 -0
- package/lib/cjs/classes/File.d.ts.map +1 -0
- package/lib/cjs/classes/File.js +102 -0
- package/lib/cjs/classes/Invite.d.ts +60 -0
- package/lib/cjs/classes/Invite.d.ts.map +1 -0
- package/lib/cjs/classes/Invite.js +91 -0
- package/lib/cjs/classes/MFA.d.ts +83 -0
- package/lib/cjs/classes/MFA.d.ts.map +1 -0
- package/lib/cjs/classes/MFA.js +196 -0
- package/lib/cjs/classes/Message.d.ts +484 -0
- package/lib/cjs/classes/Message.d.ts.map +1 -0
- package/lib/cjs/classes/Message.js +341 -0
- package/lib/cjs/classes/MessageEmbed.d.ts +122 -0
- package/lib/cjs/classes/MessageEmbed.d.ts.map +1 -0
- package/lib/cjs/classes/MessageEmbed.js +181 -0
- package/lib/cjs/classes/PublicBot.d.ts +28 -0
- package/lib/cjs/classes/PublicBot.d.ts.map +1 -0
- package/lib/cjs/classes/PublicBot.js +60 -0
- package/lib/cjs/classes/PublicInvite.d.ts +57 -0
- package/lib/cjs/classes/PublicInvite.d.ts.map +1 -0
- package/lib/cjs/classes/PublicInvite.js +104 -0
- package/lib/cjs/classes/Server.d.ts +473 -0
- package/lib/cjs/classes/Server.d.ts.map +1 -0
- package/lib/cjs/classes/Server.js +585 -0
- package/lib/cjs/classes/ServerBan.d.ts +26 -0
- package/lib/cjs/classes/ServerBan.d.ts.map +1 -0
- package/lib/cjs/classes/ServerBan.js +44 -0
- package/lib/cjs/classes/ServerMember.d.ts +138 -0
- package/lib/cjs/classes/ServerMember.d.ts.map +1 -0
- package/lib/cjs/classes/ServerMember.js +234 -0
- package/lib/cjs/classes/Session.d.ts +45 -0
- package/lib/cjs/classes/Session.d.ts.map +1 -0
- package/lib/cjs/classes/Session.js +94 -0
- package/lib/cjs/classes/SystemMessage.d.ts +127 -0
- package/lib/cjs/classes/SystemMessage.d.ts.map +1 -0
- package/lib/cjs/classes/SystemMessage.js +172 -0
- package/lib/cjs/classes/User.d.ts +203 -0
- package/lib/cjs/classes/User.d.ts.map +1 -0
- package/lib/cjs/classes/User.js +299 -0
- package/lib/cjs/classes/UserProfile.d.ts +23 -0
- package/lib/cjs/classes/UserProfile.d.ts.map +1 -0
- package/lib/cjs/classes/UserProfile.js +35 -0
- package/lib/cjs/classes/index.d.ts +21 -0
- package/lib/cjs/classes/index.d.ts.map +1 -0
- package/lib/cjs/classes/index.js +36 -0
- package/lib/cjs/collections/AccountCollection.d.ts +91 -0
- package/lib/cjs/collections/AccountCollection.d.ts.map +1 -0
- package/lib/cjs/collections/AccountCollection.js +150 -0
- package/lib/cjs/collections/BotCollection.d.ts +39 -0
- package/lib/cjs/collections/BotCollection.d.ts.map +1 -0
- package/lib/cjs/collections/BotCollection.js +89 -0
- package/lib/cjs/collections/ChannelCollection.d.ts +39 -0
- package/lib/cjs/collections/ChannelCollection.d.ts.map +1 -0
- package/lib/cjs/collections/ChannelCollection.js +93 -0
- package/lib/cjs/collections/ChannelUnreadCollection.d.ts +24 -0
- package/lib/cjs/collections/ChannelUnreadCollection.d.ts.map +1 -0
- package/lib/cjs/collections/ChannelUnreadCollection.js +56 -0
- package/lib/cjs/collections/ChannelWebhookCollection.d.ts +29 -0
- package/lib/cjs/collections/ChannelWebhookCollection.d.ts.map +1 -0
- package/lib/cjs/collections/ChannelWebhookCollection.js +69 -0
- package/lib/cjs/collections/Collection.d.ts +153 -0
- package/lib/cjs/collections/Collection.d.ts.map +1 -0
- package/lib/cjs/collections/Collection.js +170 -0
- package/lib/cjs/collections/EmojiCollection.d.ts +27 -0
- package/lib/cjs/collections/EmojiCollection.d.ts.map +1 -0
- package/lib/cjs/collections/EmojiCollection.js +67 -0
- package/lib/cjs/collections/MessageCollection.d.ts +28 -0
- package/lib/cjs/collections/MessageCollection.d.ts.map +1 -0
- package/lib/cjs/collections/MessageCollection.js +69 -0
- package/lib/cjs/collections/ServerCollection.d.ts +36 -0
- package/lib/cjs/collections/ServerCollection.d.ts.map +1 -0
- package/lib/cjs/collections/ServerCollection.js +96 -0
- package/lib/cjs/collections/ServerMemberCollection.d.ts +45 -0
- package/lib/cjs/collections/ServerMemberCollection.d.ts.map +1 -0
- package/lib/cjs/collections/ServerMemberCollection.js +95 -0
- package/lib/cjs/collections/SessionCollection.d.ts +27 -0
- package/lib/cjs/collections/SessionCollection.d.ts.map +1 -0
- package/lib/cjs/collections/SessionCollection.js +63 -0
- package/lib/cjs/collections/UserCollection.d.ts +31 -0
- package/lib/cjs/collections/UserCollection.d.ts.map +1 -0
- package/lib/cjs/collections/UserCollection.js +81 -0
- package/lib/cjs/collections/index.d.ts +12 -0
- package/lib/cjs/collections/index.d.ts.map +1 -0
- package/lib/cjs/collections/index.js +38 -0
- package/lib/cjs/events/EventClient.d.ts +89 -0
- package/lib/cjs/events/EventClient.d.ts.map +1 -0
- package/lib/cjs/events/EventClient.js +186 -0
- package/lib/cjs/events/index.d.ts +18 -0
- package/lib/cjs/events/index.d.ts.map +1 -0
- package/lib/cjs/events/index.js +20 -0
- package/lib/cjs/events/v1.d.ts +214 -0
- package/lib/cjs/events/v1.d.ts.map +1 -0
- package/lib/cjs/events/v1.js +502 -0
- package/lib/cjs/hydration/bot.d.ts +21 -0
- package/lib/cjs/hydration/bot.d.ts.map +1 -0
- package/lib/cjs/hydration/bot.js +31 -0
- package/lib/cjs/hydration/channel.d.ts +25 -0
- package/lib/cjs/hydration/channel.d.ts.map +1 -0
- package/lib/cjs/hydration/channel.js +40 -0
- package/lib/cjs/hydration/channelUnread.d.ts +11 -0
- package/lib/cjs/hydration/channelUnread.d.ts.map +1 -0
- package/lib/cjs/hydration/channelUnread.js +19 -0
- package/lib/cjs/hydration/channelWebhook.d.ts +12 -0
- package/lib/cjs/hydration/channelWebhook.d.ts.map +1 -0
- package/lib/cjs/hydration/channelWebhook.js +21 -0
- package/lib/cjs/hydration/emoji.d.ts +13 -0
- package/lib/cjs/hydration/emoji.d.ts.map +1 -0
- package/lib/cjs/hydration/emoji.js +18 -0
- package/lib/cjs/hydration/index.d.ts +1404 -0
- package/lib/cjs/hydration/index.d.ts.map +1 -0
- package/lib/cjs/hydration/index.js +68 -0
- package/lib/cjs/hydration/message.d.ts +25 -0
- package/lib/cjs/hydration/message.d.ts.map +1 -0
- package/lib/cjs/hydration/message.js +48 -0
- package/lib/cjs/hydration/server.d.ts +31 -0
- package/lib/cjs/hydration/server.d.ts.map +1 -0
- package/lib/cjs/hydration/server.js +44 -0
- package/lib/cjs/hydration/serverMember.d.ts +14 -0
- package/lib/cjs/hydration/serverMember.d.ts.map +1 -0
- package/lib/cjs/hydration/serverMember.js +21 -0
- package/lib/cjs/hydration/session.d.ts +8 -0
- package/lib/cjs/hydration/session.d.ts.map +1 -0
- package/lib/cjs/hydration/session.js +13 -0
- package/lib/cjs/hydration/user.d.ts +43 -0
- package/lib/cjs/hydration/user.d.ts.map +1 -0
- package/lib/cjs/hydration/user.js +53 -0
- package/lib/cjs/index.d.ts +9 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +43 -0
- package/lib/cjs/lib/merge.d.ts +15 -0
- package/lib/cjs/lib/merge.d.ts.map +1 -0
- package/lib/cjs/lib/merge.js +2 -0
- package/lib/cjs/lib/regex.d.ts +13 -0
- package/lib/cjs/lib/regex.d.ts.map +1 -0
- package/lib/cjs/lib/regex.js +15 -0
- package/lib/cjs/permissions/calculator.d.ts +19 -0
- package/lib/cjs/permissions/calculator.d.ts.map +1 -0
- package/lib/cjs/permissions/calculator.js +136 -0
- package/lib/cjs/permissions/definitions.d.ts +73 -0
- package/lib/cjs/permissions/definitions.d.ts.map +1 -0
- package/lib/cjs/permissions/definitions.js +124 -0
- package/lib/cjs/storage/ObjectStorage.d.ts +28 -0
- package/lib/cjs/storage/ObjectStorage.d.ts.map +1 -0
- package/lib/cjs/storage/ObjectStorage.js +41 -0
- package/lib/esm/Client.d.ts +166 -0
- package/lib/esm/Client.d.ts.map +1 -0
- package/lib/esm/Client.js +214 -0
- package/lib/esm/api/baseURL.d.ts +2 -0
- package/lib/esm/api/baseURL.d.ts.map +1 -0
- package/lib/esm/api/baseURL.js +2 -0
- package/lib/esm/api/index.d.ts +177 -0
- package/lib/esm/api/index.d.ts.map +1 -0
- package/lib/esm/api/index.js +139 -0
- package/lib/esm/api/params.d.ts +285 -0
- package/lib/esm/api/params.d.ts.map +1 -0
- package/lib/esm/api/params.js +191 -0
- package/lib/esm/api/routes.d.ts +1089 -0
- package/lib/esm/api/routes.d.ts.map +1 -0
- package/lib/esm/api/routes.js +1 -0
- package/lib/esm/api/schema.d.ts +4705 -0
- package/lib/esm/api/schema.d.ts.map +1 -0
- package/lib/esm/api/schema.js +1 -0
- package/lib/esm/api/types.d.ts +131 -0
- package/lib/esm/api/types.d.ts.map +1 -0
- package/lib/esm/api/types.js +1 -0
- package/lib/esm/classes/BannedUser.d.ts +18 -0
- package/lib/esm/classes/BannedUser.d.ts.map +1 -0
- package/lib/esm/classes/BannedUser.js +21 -0
- package/lib/esm/classes/Bot.d.ts +82 -0
- package/lib/esm/classes/Bot.d.ts.map +1 -0
- package/lib/esm/classes/Bot.js +116 -0
- package/lib/esm/classes/Channel.d.ts +465 -0
- package/lib/esm/classes/Channel.d.ts.map +1 -0
- package/lib/esm/classes/Channel.js +529 -0
- package/lib/esm/classes/ChannelUnread.d.ts +27 -0
- package/lib/esm/classes/ChannelUnread.d.ts.map +1 -0
- package/lib/esm/classes/ChannelUnread.js +34 -0
- package/lib/esm/classes/ChannelWebhook.d.ts +53 -0
- package/lib/esm/classes/ChannelWebhook.d.ts.map +1 -0
- package/lib/esm/classes/ChannelWebhook.js +83 -0
- package/lib/esm/classes/Emoji.d.ts +57 -0
- package/lib/esm/classes/Emoji.d.ts.map +1 -0
- package/lib/esm/classes/Emoji.js +77 -0
- package/lib/esm/classes/File.d.ts +67 -0
- package/lib/esm/classes/File.d.ts.map +1 -0
- package/lib/esm/classes/File.js +105 -0
- package/lib/esm/classes/Invite.d.ts +60 -0
- package/lib/esm/classes/Invite.d.ts.map +1 -0
- package/lib/esm/classes/Invite.js +80 -0
- package/lib/esm/classes/MFA.d.ts +83 -0
- package/lib/esm/classes/MFA.d.ts.map +1 -0
- package/lib/esm/classes/MFA.js +165 -0
- package/lib/esm/classes/Message.d.ts +484 -0
- package/lib/esm/classes/Message.d.ts.map +1 -0
- package/lib/esm/classes/Message.js +300 -0
- package/lib/esm/classes/MessageEmbed.d.ts +122 -0
- package/lib/esm/classes/MessageEmbed.d.ts.map +1 -0
- package/lib/esm/classes/MessageEmbed.js +192 -0
- package/lib/esm/classes/PublicBot.d.ts +28 -0
- package/lib/esm/classes/PublicBot.d.ts.map +1 -0
- package/lib/esm/classes/PublicBot.js +47 -0
- package/lib/esm/classes/PublicInvite.d.ts +57 -0
- package/lib/esm/classes/PublicInvite.d.ts.map +1 -0
- package/lib/esm/classes/PublicInvite.js +100 -0
- package/lib/esm/classes/Server.d.ts +473 -0
- package/lib/esm/classes/Server.d.ts.map +1 -0
- package/lib/esm/classes/Server.js +522 -0
- package/lib/esm/classes/ServerBan.d.ts +26 -0
- package/lib/esm/classes/ServerBan.d.ts.map +1 -0
- package/lib/esm/classes/ServerBan.js +33 -0
- package/lib/esm/classes/ServerMember.d.ts +138 -0
- package/lib/esm/classes/ServerMember.d.ts.map +1 -0
- package/lib/esm/classes/ServerMember.js +199 -0
- package/lib/esm/classes/Session.d.ts +45 -0
- package/lib/esm/classes/Session.d.ts.map +1 -0
- package/lib/esm/classes/Session.js +65 -0
- package/lib/esm/classes/SystemMessage.d.ts +127 -0
- package/lib/esm/classes/SystemMessage.d.ts.map +1 -0
- package/lib/esm/classes/SystemMessage.js +171 -0
- package/lib/esm/classes/User.d.ts +203 -0
- package/lib/esm/classes/User.d.ts.map +1 -0
- package/lib/esm/classes/User.js +252 -0
- package/lib/esm/classes/UserProfile.d.ts +23 -0
- package/lib/esm/classes/UserProfile.d.ts.map +1 -0
- package/lib/esm/classes/UserProfile.js +31 -0
- package/lib/esm/classes/index.d.ts +21 -0
- package/lib/esm/classes/index.d.ts.map +1 -0
- package/lib/esm/classes/index.js +20 -0
- package/lib/esm/collections/AccountCollection.d.ts +91 -0
- package/lib/esm/collections/AccountCollection.d.ts.map +1 -0
- package/lib/esm/collections/AccountCollection.js +139 -0
- package/lib/esm/collections/BotCollection.d.ts +39 -0
- package/lib/esm/collections/BotCollection.d.ts.map +1 -0
- package/lib/esm/collections/BotCollection.js +68 -0
- package/lib/esm/collections/ChannelCollection.d.ts +39 -0
- package/lib/esm/collections/ChannelCollection.d.ts.map +1 -0
- package/lib/esm/collections/ChannelCollection.js +75 -0
- package/lib/esm/collections/ChannelUnreadCollection.d.ts +24 -0
- package/lib/esm/collections/ChannelUnreadCollection.d.ts.map +1 -0
- package/lib/esm/collections/ChannelUnreadCollection.js +41 -0
- package/lib/esm/collections/ChannelWebhookCollection.d.ts +29 -0
- package/lib/esm/collections/ChannelWebhookCollection.d.ts.map +1 -0
- package/lib/esm/collections/ChannelWebhookCollection.js +52 -0
- package/lib/esm/collections/Collection.d.ts +153 -0
- package/lib/esm/collections/Collection.d.ts.map +1 -0
- package/lib/esm/collections/Collection.js +160 -0
- package/lib/esm/collections/EmojiCollection.d.ts +27 -0
- package/lib/esm/collections/EmojiCollection.d.ts.map +1 -0
- package/lib/esm/collections/EmojiCollection.js +52 -0
- package/lib/esm/collections/MessageCollection.d.ts +28 -0
- package/lib/esm/collections/MessageCollection.d.ts.map +1 -0
- package/lib/esm/collections/MessageCollection.js +54 -0
- package/lib/esm/collections/ServerCollection.d.ts +36 -0
- package/lib/esm/collections/ServerCollection.d.ts.map +1 -0
- package/lib/esm/collections/ServerCollection.js +79 -0
- package/lib/esm/collections/ServerMemberCollection.d.ts +45 -0
- package/lib/esm/collections/ServerMemberCollection.d.ts.map +1 -0
- package/lib/esm/collections/ServerMemberCollection.js +80 -0
- package/lib/esm/collections/SessionCollection.d.ts +27 -0
- package/lib/esm/collections/SessionCollection.d.ts.map +1 -0
- package/lib/esm/collections/SessionCollection.js +46 -0
- package/lib/esm/collections/UserCollection.d.ts +31 -0
- package/lib/esm/collections/UserCollection.d.ts.map +1 -0
- package/lib/esm/collections/UserCollection.js +66 -0
- package/lib/esm/collections/index.d.ts +12 -0
- package/lib/esm/collections/index.d.ts.map +1 -0
- package/lib/esm/collections/index.js +11 -0
- package/lib/esm/events/EventClient.d.ts +89 -0
- package/lib/esm/events/EventClient.d.ts.map +1 -0
- package/lib/esm/events/EventClient.js +175 -0
- package/lib/esm/events/index.d.ts +18 -0
- package/lib/esm/events/index.d.ts.map +1 -0
- package/lib/esm/events/index.js +2 -0
- package/lib/esm/events/v1.d.ts +214 -0
- package/lib/esm/events/v1.d.ts.map +1 -0
- package/lib/esm/events/v1.js +514 -0
- package/lib/esm/hydration/bot.d.ts +21 -0
- package/lib/esm/hydration/bot.d.ts.map +1 -0
- package/lib/esm/hydration/bot.js +28 -0
- package/lib/esm/hydration/channel.d.ts +25 -0
- package/lib/esm/hydration/channel.d.ts.map +1 -0
- package/lib/esm/hydration/channel.js +37 -0
- package/lib/esm/hydration/channelUnread.d.ts +11 -0
- package/lib/esm/hydration/channelUnread.d.ts.map +1 -0
- package/lib/esm/hydration/channelUnread.js +16 -0
- package/lib/esm/hydration/channelWebhook.d.ts +12 -0
- package/lib/esm/hydration/channelWebhook.d.ts.map +1 -0
- package/lib/esm/hydration/channelWebhook.js +18 -0
- package/lib/esm/hydration/emoji.d.ts +13 -0
- package/lib/esm/hydration/emoji.d.ts.map +1 -0
- package/lib/esm/hydration/emoji.js +15 -0
- package/lib/esm/hydration/index.d.ts +1404 -0
- package/lib/esm/hydration/index.d.ts.map +1 -0
- package/lib/esm/hydration/index.js +65 -0
- package/lib/esm/hydration/message.d.ts +25 -0
- package/lib/esm/hydration/message.d.ts.map +1 -0
- package/lib/esm/hydration/message.js +45 -0
- package/lib/esm/hydration/server.d.ts +31 -0
- package/lib/esm/hydration/server.d.ts.map +1 -0
- package/lib/esm/hydration/server.js +41 -0
- package/lib/esm/hydration/serverMember.d.ts +14 -0
- package/lib/esm/hydration/serverMember.d.ts.map +1 -0
- package/lib/esm/hydration/serverMember.js +18 -0
- package/lib/esm/hydration/session.d.ts +8 -0
- package/lib/esm/hydration/session.d.ts.map +1 -0
- package/lib/esm/hydration/session.js +10 -0
- package/lib/esm/hydration/user.d.ts +43 -0
- package/lib/esm/hydration/user.d.ts.map +1 -0
- package/lib/esm/hydration/user.js +50 -0
- package/lib/esm/index.d.ts +9 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +8 -0
- package/lib/esm/lib/merge.d.ts +15 -0
- package/lib/esm/lib/merge.d.ts.map +1 -0
- package/lib/esm/lib/merge.js +1 -0
- package/lib/esm/lib/regex.d.ts +13 -0
- package/lib/esm/lib/regex.d.ts.map +1 -0
- package/lib/esm/lib/regex.js +12 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/permissions/calculator.d.ts +19 -0
- package/lib/esm/permissions/calculator.d.ts.map +1 -0
- package/lib/esm/permissions/calculator.js +129 -0
- package/lib/esm/permissions/definitions.d.ts +73 -0
- package/lib/esm/permissions/definitions.d.ts.map +1 -0
- package/lib/esm/permissions/definitions.js +121 -0
- package/lib/esm/storage/ObjectStorage.d.ts +28 -0
- package/lib/esm/storage/ObjectStorage.d.ts.map +1 -0
- package/lib/esm/storage/ObjectStorage.js +39 -0
- package/package.json +59 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { API } from "./api";
|
|
2
|
+
import { AccountCollection } from "./collections/AccountCollection.js";
|
|
3
|
+
import { BotCollection, ChannelCollection, ChannelUnreadCollection, ChannelWebhookCollection, EmojiCollection, MessageCollection, ServerCollection, ServerMemberCollection, SessionCollection, UserCollection, } from "./collections/index.js";
|
|
4
|
+
import { ConnectionState, EventClient, handleEventV1, } from "./events/index.js";
|
|
5
|
+
import { RE_CHANNELS, RE_MENTIONS, RE_SPOILER } from "./lib/regex.js";
|
|
6
|
+
import EventEmitter from "eventemitter3";
|
|
7
|
+
import { batch, createSignal } from "solid-js";
|
|
8
|
+
/**
|
|
9
|
+
* Hischool.js Clients
|
|
10
|
+
*/
|
|
11
|
+
export class Client extends EventEmitter {
|
|
12
|
+
account;
|
|
13
|
+
bots;
|
|
14
|
+
channels;
|
|
15
|
+
channelUnreads;
|
|
16
|
+
channelWebhooks;
|
|
17
|
+
emojis;
|
|
18
|
+
messages;
|
|
19
|
+
servers;
|
|
20
|
+
serverMembers;
|
|
21
|
+
sessions;
|
|
22
|
+
users;
|
|
23
|
+
api;
|
|
24
|
+
options;
|
|
25
|
+
events;
|
|
26
|
+
configuration;
|
|
27
|
+
#session;
|
|
28
|
+
user;
|
|
29
|
+
ready;
|
|
30
|
+
#setReady;
|
|
31
|
+
connectionFailureCount;
|
|
32
|
+
#setConnectionFailureCount;
|
|
33
|
+
#reconnectTimeout;
|
|
34
|
+
/**
|
|
35
|
+
* Create Hischool.js Client
|
|
36
|
+
*/
|
|
37
|
+
constructor(options, configuration) {
|
|
38
|
+
super();
|
|
39
|
+
this.options = {
|
|
40
|
+
baseURL: "https://api.hischool.mn",
|
|
41
|
+
partials: false,
|
|
42
|
+
eagerFetching: true,
|
|
43
|
+
syncUnreads: false,
|
|
44
|
+
autoReconnect: true,
|
|
45
|
+
messageRewrites: true,
|
|
46
|
+
/**
|
|
47
|
+
* Retry delay function
|
|
48
|
+
* @param retryCount Count
|
|
49
|
+
* @returns Delay in seconds
|
|
50
|
+
*/
|
|
51
|
+
retryDelayFunction(retryCount) {
|
|
52
|
+
return (Math.pow(2, retryCount) - 1) * (0.8 + Math.random() * 0.4);
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Check whether a channel is muted
|
|
56
|
+
* @param channel Channel
|
|
57
|
+
* @return Whether it is muted
|
|
58
|
+
*/
|
|
59
|
+
channelIsMuted() {
|
|
60
|
+
return false;
|
|
61
|
+
},
|
|
62
|
+
...options,
|
|
63
|
+
};
|
|
64
|
+
this.configuration = configuration;
|
|
65
|
+
this.api = new API({
|
|
66
|
+
baseURL: this.options.baseURL,
|
|
67
|
+
});
|
|
68
|
+
const [ready, setReady] = createSignal(false);
|
|
69
|
+
this.ready = ready;
|
|
70
|
+
this.#setReady = setReady;
|
|
71
|
+
const [connectionFailureCount, setConnectionFailureCount] = createSignal(0);
|
|
72
|
+
this.connectionFailureCount = connectionFailureCount;
|
|
73
|
+
this.#setConnectionFailureCount = setConnectionFailureCount;
|
|
74
|
+
this.account = new AccountCollection(this);
|
|
75
|
+
this.bots = new BotCollection(this);
|
|
76
|
+
this.channels = new ChannelCollection(this);
|
|
77
|
+
this.channelUnreads = new ChannelUnreadCollection(this);
|
|
78
|
+
this.channelWebhooks = new ChannelWebhookCollection(this);
|
|
79
|
+
this.emojis = new EmojiCollection(this);
|
|
80
|
+
this.messages = new MessageCollection(this);
|
|
81
|
+
this.servers = new ServerCollection(this);
|
|
82
|
+
this.serverMembers = new ServerMemberCollection(this);
|
|
83
|
+
this.sessions = new SessionCollection(this);
|
|
84
|
+
this.users = new UserCollection(this);
|
|
85
|
+
this.events = new EventClient(1, "json", this.options);
|
|
86
|
+
this.events.on("error", (error) => this.emit("error", error));
|
|
87
|
+
this.events.on("state", (state) => {
|
|
88
|
+
switch (state) {
|
|
89
|
+
case ConnectionState.Connected:
|
|
90
|
+
batch(() => {
|
|
91
|
+
this.servers.forEach((server) => server.resetSyncStatus());
|
|
92
|
+
this.#setConnectionFailureCount(0);
|
|
93
|
+
this.emit("connected");
|
|
94
|
+
});
|
|
95
|
+
break;
|
|
96
|
+
case ConnectionState.Connecting:
|
|
97
|
+
this.emit("connecting");
|
|
98
|
+
break;
|
|
99
|
+
case ConnectionState.Disconnected:
|
|
100
|
+
this.emit("disconnected");
|
|
101
|
+
if (this.options.autoReconnect) {
|
|
102
|
+
this.#reconnectTimeout = setTimeout(() => this.connect(), this.options.retryDelayFunction(this.connectionFailureCount()) *
|
|
103
|
+
1e3);
|
|
104
|
+
this.#setConnectionFailureCount((count) => count + 1);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
this.events.on("event", (event) => handleEventV1(this, event, this.#setReady));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Current session id
|
|
113
|
+
*/
|
|
114
|
+
get sessionId() {
|
|
115
|
+
return typeof this.#session === "string" ? undefined : this.#session?._id;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Connect to Hischool
|
|
119
|
+
*/
|
|
120
|
+
connect() {
|
|
121
|
+
clearTimeout(this.#reconnectTimeout);
|
|
122
|
+
this.events.disconnect();
|
|
123
|
+
this.#setReady(false);
|
|
124
|
+
this.events.connect(this.configuration?.ws ?? "wss://ws.hischool.mn", typeof this.#session === "string" ? this.#session : this.#session.token);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Fetches the configuration of the server if it has not been already fetched.
|
|
128
|
+
*/
|
|
129
|
+
async #fetchConfiguration() {
|
|
130
|
+
if (!this.configuration) {
|
|
131
|
+
this.configuration = await this.api.get("/");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Update API object to use authentication.
|
|
136
|
+
*/
|
|
137
|
+
#updateHeaders() {
|
|
138
|
+
this.api = new API({
|
|
139
|
+
baseURL: this.options.baseURL,
|
|
140
|
+
authentication: {
|
|
141
|
+
hischool: this.#session,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Log in with auth data, creating a new session in the process.
|
|
147
|
+
* @param details Login data object
|
|
148
|
+
* @returns An on-boarding function if on-boarding is required, undefined otherwise
|
|
149
|
+
*/
|
|
150
|
+
async login(details) {
|
|
151
|
+
await this.#fetchConfiguration();
|
|
152
|
+
const data = await this.api.post("/auth/session/login", details);
|
|
153
|
+
if (data.result === "Success") {
|
|
154
|
+
this.#session = data;
|
|
155
|
+
// TODO: return await this.connect();
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
throw "MFA not implemented!";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Use an existing session
|
|
163
|
+
*/
|
|
164
|
+
async useExistingSession(session) {
|
|
165
|
+
this.#session = session;
|
|
166
|
+
this.#updateHeaders();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Log in as a bot
|
|
170
|
+
* @param token Bot token
|
|
171
|
+
*/
|
|
172
|
+
async loginBot(token) {
|
|
173
|
+
await this.#fetchConfiguration();
|
|
174
|
+
this.#session = token;
|
|
175
|
+
this.#updateHeaders();
|
|
176
|
+
this.connect();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Prepare a markdown-based message to be displayed to the user as plain text.
|
|
180
|
+
* @param source Source markdown text
|
|
181
|
+
* @returns Modified plain text
|
|
182
|
+
*/
|
|
183
|
+
markdownToText(source) {
|
|
184
|
+
return source
|
|
185
|
+
.replace(RE_MENTIONS, (sub, id) => {
|
|
186
|
+
const user = this.users.get(id);
|
|
187
|
+
if (user) {
|
|
188
|
+
return `@${user.username}`;
|
|
189
|
+
}
|
|
190
|
+
return sub;
|
|
191
|
+
})
|
|
192
|
+
.replace(RE_CHANNELS, (sub, id) => {
|
|
193
|
+
const channel = this.channels.get(id);
|
|
194
|
+
if (channel) {
|
|
195
|
+
return `#${channel.displayName}`;
|
|
196
|
+
}
|
|
197
|
+
return sub;
|
|
198
|
+
})
|
|
199
|
+
.replace(RE_SPOILER, "<spoiler>");
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Proxy a file through January.
|
|
203
|
+
* @param url URL to proxy
|
|
204
|
+
* @returns Proxied media URL
|
|
205
|
+
*/
|
|
206
|
+
proxyFile(url) {
|
|
207
|
+
if (this.configuration?.features.january.enabled) {
|
|
208
|
+
return `${this.configuration.features.january.url}/proxy?url=${encodeURIComponent(url)}`;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
return url;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseURL.d.ts","sourceRoot":"","sources":["../../../src/api/baseURL.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { APIRoutes } from "./routes";
|
|
2
|
+
import type { AxiosRequestConfig } from "axios";
|
|
3
|
+
export * from "./types";
|
|
4
|
+
type Methods = APIRoutes["method"];
|
|
5
|
+
type PickRoutes<Method extends Methods> = APIRoutes & {
|
|
6
|
+
method: Method;
|
|
7
|
+
};
|
|
8
|
+
type GetRoutes = PickRoutes<"get">;
|
|
9
|
+
type PatchRoutes = PickRoutes<"patch">;
|
|
10
|
+
type PutRoutes = PickRoutes<"put">;
|
|
11
|
+
type DeleteRoutes = PickRoutes<"delete">;
|
|
12
|
+
type PostRoutes = PickRoutes<"post">;
|
|
13
|
+
type Count<Str extends string, SubStr extends string, Matches extends null[] = []> = Str extends `${infer _}${SubStr}${infer After}` ? Count<After, SubStr, [...Matches, null]> : Matches["length"];
|
|
14
|
+
/**
|
|
15
|
+
* Get the specific path name of any given path.
|
|
16
|
+
* @param anyPath Any path
|
|
17
|
+
* @returns Specific path
|
|
18
|
+
*/
|
|
19
|
+
export declare function getPathName(anyPath: string): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Client configuration options
|
|
22
|
+
*/
|
|
23
|
+
export interface Options {
|
|
24
|
+
/**
|
|
25
|
+
* Base URL of the Hischool node
|
|
26
|
+
*/
|
|
27
|
+
baseURL: string;
|
|
28
|
+
/**
|
|
29
|
+
* Authentication used for requests
|
|
30
|
+
*/
|
|
31
|
+
authentication: {
|
|
32
|
+
rauth?: string | undefined;
|
|
33
|
+
hischool?: {
|
|
34
|
+
token: string;
|
|
35
|
+
} | string | undefined;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* API Client
|
|
40
|
+
*/
|
|
41
|
+
export declare class API {
|
|
42
|
+
private baseURL;
|
|
43
|
+
private authentication;
|
|
44
|
+
constructor({ baseURL, authentication }?: Partial<Options>);
|
|
45
|
+
/**
|
|
46
|
+
* Generate authentication options.
|
|
47
|
+
*/
|
|
48
|
+
get auth(): AxiosRequestConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Generate config to pass through to API.
|
|
51
|
+
*/
|
|
52
|
+
get config(): AxiosRequestConfig;
|
|
53
|
+
/**
|
|
54
|
+
* Send any arbitrary request.
|
|
55
|
+
* @param method HTTP Method
|
|
56
|
+
* @param path Path
|
|
57
|
+
* @param params Body or Query Parameters
|
|
58
|
+
* @param config Axios configuration
|
|
59
|
+
* @returns Typed Response Data
|
|
60
|
+
*/
|
|
61
|
+
req<Method extends Methods, Routes extends PickRoutes<Method>, Path extends Routes["path"], Route extends Routes & {
|
|
62
|
+
path: Path;
|
|
63
|
+
parts: Count<Path, "/">;
|
|
64
|
+
}>(method: Method, path: Path, params: Route["params"], config?: AxiosRequestConfig): Promise<Route["response"]>;
|
|
65
|
+
/**
|
|
66
|
+
* Send HTTP GET request.
|
|
67
|
+
* @param path Path
|
|
68
|
+
* @param params Body or Query Parameters
|
|
69
|
+
* @param config Axios configuration
|
|
70
|
+
* @returns Typed Response Data
|
|
71
|
+
*/
|
|
72
|
+
get<Path extends GetRoutes["path"], Route extends GetRoutes & {
|
|
73
|
+
path: Path;
|
|
74
|
+
parts: Count<Path, "/">;
|
|
75
|
+
}>(path: Path, params: Route["params"], config?: AxiosRequestConfig): Promise<Route["response"]>;
|
|
76
|
+
/**
|
|
77
|
+
* Send HTTP GET request.
|
|
78
|
+
* @param path Path
|
|
79
|
+
* @returns Typed Response Data
|
|
80
|
+
*/
|
|
81
|
+
get<Path extends (GetRoutes & {
|
|
82
|
+
params: undefined;
|
|
83
|
+
})["path"], Route extends GetRoutes & {
|
|
84
|
+
path: Path;
|
|
85
|
+
parts: Count<Path, "/">;
|
|
86
|
+
}>(path: Path): Promise<Route["response"]>;
|
|
87
|
+
/**
|
|
88
|
+
* Send HTTP PATCH request.
|
|
89
|
+
* @param path Path
|
|
90
|
+
* @param params Body or Query Parameters
|
|
91
|
+
* @param config Axios configuration
|
|
92
|
+
* @returns Typed Response Data
|
|
93
|
+
*/
|
|
94
|
+
patch<Path extends PatchRoutes["path"], Route extends PatchRoutes & {
|
|
95
|
+
path: Path;
|
|
96
|
+
parts: Count<Path, "/">;
|
|
97
|
+
}>(path: Path, params: Route["params"], config?: AxiosRequestConfig): Promise<Route["response"]>;
|
|
98
|
+
/**
|
|
99
|
+
* Send HTTP PATCH request.
|
|
100
|
+
* @param path Path
|
|
101
|
+
* @returns Typed Response Data
|
|
102
|
+
*/
|
|
103
|
+
patch<Path extends (PatchRoutes & {
|
|
104
|
+
params: undefined;
|
|
105
|
+
})["path"], Route extends PatchRoutes & {
|
|
106
|
+
path: Path;
|
|
107
|
+
parts: Count<Path, "/">;
|
|
108
|
+
}>(path: Path): Promise<Route["response"]>;
|
|
109
|
+
/**
|
|
110
|
+
* Send HTTP PUT request.
|
|
111
|
+
* @param path Path
|
|
112
|
+
* @param params Body or Query Parameters
|
|
113
|
+
* @param config Axios configuration
|
|
114
|
+
* @returns Typed Response Data
|
|
115
|
+
*/
|
|
116
|
+
put<Path extends PutRoutes["path"], Route extends PutRoutes & {
|
|
117
|
+
path: Path;
|
|
118
|
+
parts: Count<Path, "/">;
|
|
119
|
+
}>(path: Path, params: Route["params"], config?: AxiosRequestConfig): Promise<Route["response"]>;
|
|
120
|
+
/**
|
|
121
|
+
* Send HTTP PUT request.
|
|
122
|
+
* @param path Path
|
|
123
|
+
* @returns Typed Response Data
|
|
124
|
+
*/
|
|
125
|
+
put<Path extends (PutRoutes & {
|
|
126
|
+
params: undefined;
|
|
127
|
+
})["path"], Route extends PutRoutes & {
|
|
128
|
+
path: Path;
|
|
129
|
+
parts: Count<Path, "/">;
|
|
130
|
+
}>(path: Path): Promise<Route["response"]>;
|
|
131
|
+
/**
|
|
132
|
+
* Send HTTP DELETE request.
|
|
133
|
+
* @param path Path
|
|
134
|
+
* @param params Body or Query Parameters
|
|
135
|
+
* @param config Axios configuration
|
|
136
|
+
* @returns Typed Response Data
|
|
137
|
+
*/
|
|
138
|
+
delete<Path extends DeleteRoutes["path"], Route extends DeleteRoutes & {
|
|
139
|
+
path: Path;
|
|
140
|
+
parts: Count<Path, "/">;
|
|
141
|
+
}>(path: Path, params?: any, config?: AxiosRequestConfig): Promise<Route["response"]>;
|
|
142
|
+
/**
|
|
143
|
+
* Send HTTP DELETE request.
|
|
144
|
+
* @param path Path
|
|
145
|
+
* @param params Body or Query Parameters
|
|
146
|
+
* @returns Typed Response Data
|
|
147
|
+
*/
|
|
148
|
+
delete<Path extends (DeleteRoutes & {
|
|
149
|
+
params: undefined;
|
|
150
|
+
})["path"], Route extends DeleteRoutes & {
|
|
151
|
+
path: Path;
|
|
152
|
+
parts: Count<Path, "/">;
|
|
153
|
+
}>(path: Path, params?: any): Promise<Route["response"]>;
|
|
154
|
+
/**
|
|
155
|
+
* Send HTTP POST request.
|
|
156
|
+
* @param path Path
|
|
157
|
+
* @param params Body or Query Parameters
|
|
158
|
+
* @param config Axios configuration
|
|
159
|
+
* @returns Typed Response Data
|
|
160
|
+
*/
|
|
161
|
+
post<Path extends PostRoutes["path"], Route extends PostRoutes & {
|
|
162
|
+
path: Path;
|
|
163
|
+
parts: Count<Path, "/">;
|
|
164
|
+
}>(path: Path, params: Route["params"], config?: AxiosRequestConfig): Promise<Route["response"]>;
|
|
165
|
+
/**
|
|
166
|
+
* Send HTTP POST request.
|
|
167
|
+
* @param path Path
|
|
168
|
+
* @returns Typed Response Data
|
|
169
|
+
*/
|
|
170
|
+
post<Path extends (PostRoutes & {
|
|
171
|
+
params: undefined;
|
|
172
|
+
})["path"], Route extends PostRoutes & {
|
|
173
|
+
path: Path;
|
|
174
|
+
parts: Count<Path, "/">;
|
|
175
|
+
}>(path: Path): Promise<Route["response"]>;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAGhD,cAAc,SAAS,CAAC;AAExB,KAAK,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AACnC,KAAK,UAAU,CAAC,MAAM,SAAS,OAAO,IAAI,SAAS,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,KAAK,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;AACnC,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;AACvC,KAAK,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;AACnC,KAAK,YAAY,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AACzC,KAAK,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAErC,KAAK,KAAK,CACR,GAAG,SAAS,MAAM,EAClB,MAAM,SAAS,MAAM,EACrB,OAAO,SAAS,IAAI,EAAE,GAAG,EAAE,IACzB,GAAG,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,KAAK,EAAE,GAC/C,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,GACxC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEtB;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,sBAmB1C;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;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I,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;KAAE,EAElE,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,EACvB,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE7B;;;;OAIG;IACH,IAAI,CACF,IAAI,SAAS,CAAC,UAAU,GAAG;QAAE,MAAM,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC,MAAM,CAAC,EACzD,KAAK,SAAS,UAAU,GAAG;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;KAAE,EAClE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;CAM1C"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// API
|
|
2
|
+
import { defaultBaseURL } from "./baseURL";
|
|
3
|
+
import { pathResolve, queryParams } from "./params";
|
|
4
|
+
import Axios from "axios";
|
|
5
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
6
|
+
export * from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Get the specific path name of any given path.
|
|
9
|
+
* @param anyPath Any path
|
|
10
|
+
* @returns Specific path
|
|
11
|
+
*/
|
|
12
|
+
export function getPathName(anyPath) {
|
|
13
|
+
const segments = anyPath.split("/");
|
|
14
|
+
const list = pathResolve[(segments.length - 1).toString()] || [];
|
|
15
|
+
for (const entry of list) {
|
|
16
|
+
let i = 1;
|
|
17
|
+
let copy = [...segments];
|
|
18
|
+
for (i; i < segments.length; i++) {
|
|
19
|
+
if (Array.isArray(entry[i - 1])) {
|
|
20
|
+
copy[i] = entry[i - 1];
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
else if (entry[i - 1] !== segments[i])
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
if (i === segments.length)
|
|
27
|
+
return copy.join("/");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* API Client
|
|
32
|
+
*/
|
|
33
|
+
export class API {
|
|
34
|
+
baseURL;
|
|
35
|
+
authentication;
|
|
36
|
+
constructor({ baseURL, authentication } = {}) {
|
|
37
|
+
this.baseURL = baseURL || defaultBaseURL;
|
|
38
|
+
this.authentication = authentication || {};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Generate authentication options.
|
|
42
|
+
*/
|
|
43
|
+
get auth() {
|
|
44
|
+
if (this.authentication.rauth) {
|
|
45
|
+
if (typeof this.authentication.rauth === "string") {
|
|
46
|
+
return {
|
|
47
|
+
headers: {
|
|
48
|
+
"X-Session-Token": this.authentication.rauth,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (this.authentication.hischool) {
|
|
54
|
+
switch (typeof this.authentication.hischool) {
|
|
55
|
+
case "string": {
|
|
56
|
+
return {
|
|
57
|
+
headers: {
|
|
58
|
+
"X-Bot-Token": this.authentication.hischool,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
case "object": {
|
|
63
|
+
return {
|
|
64
|
+
headers: {
|
|
65
|
+
"X-Session-Token": this.authentication.hischool.token,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Generate config to pass through to API.
|
|
75
|
+
*/
|
|
76
|
+
get config() {
|
|
77
|
+
return {
|
|
78
|
+
baseURL: this.baseURL,
|
|
79
|
+
...this.auth,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Send any arbitrary request.
|
|
84
|
+
* @param method HTTP Method
|
|
85
|
+
* @param path Path
|
|
86
|
+
* @param params Body or Query Parameters
|
|
87
|
+
* @param config Axios configuration
|
|
88
|
+
* @returns Typed Response Data
|
|
89
|
+
*/
|
|
90
|
+
req(method, path, params, config) {
|
|
91
|
+
let query, body;
|
|
92
|
+
let named = getPathName(path);
|
|
93
|
+
// If we are aware of this route, then match the parameters given.
|
|
94
|
+
if (named && typeof params === "object") {
|
|
95
|
+
const route = queryParams[named];
|
|
96
|
+
const allowed_query = route[method];
|
|
97
|
+
// Map each parameter to the correct object.
|
|
98
|
+
for (const parameter of Object.keys(params)) {
|
|
99
|
+
if (allowed_query?.includes(parameter)) {
|
|
100
|
+
query = {
|
|
101
|
+
...(query || {}),
|
|
102
|
+
[parameter]: params[parameter],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
body = {
|
|
107
|
+
...(body || {}),
|
|
108
|
+
[parameter]: params[parameter],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return Axios(path, defaultsDeep({
|
|
114
|
+
method,
|
|
115
|
+
params: query,
|
|
116
|
+
data: body,
|
|
117
|
+
}, defaultsDeep(config, this.config))).then((res) => res.data);
|
|
118
|
+
}
|
|
119
|
+
get(path, params, config) {
|
|
120
|
+
// @ts-ignore-next-line
|
|
121
|
+
return this.req("get", path, params, config);
|
|
122
|
+
}
|
|
123
|
+
patch(path, params, config) {
|
|
124
|
+
// @ts-ignore-next-line
|
|
125
|
+
return this.req("patch", path, params, config);
|
|
126
|
+
}
|
|
127
|
+
put(path, params, config) {
|
|
128
|
+
// @ts-ignore-next-line
|
|
129
|
+
return this.req("put", path, params, config);
|
|
130
|
+
}
|
|
131
|
+
delete(path, params, config) {
|
|
132
|
+
// @ts-ignore-next-line
|
|
133
|
+
return this.req("delete", path, params, config);
|
|
134
|
+
}
|
|
135
|
+
post(path, params, config) {
|
|
136
|
+
// @ts-ignore-next-line
|
|
137
|
+
return this.req("post", path, params, config);
|
|
138
|
+
}
|
|
139
|
+
}
|