@overlaysymphony/twitch 0.1.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.
Files changed (95) hide show
  1. package/README.md +9 -0
  2. package/package.json +40 -0
  3. package/src/authentication/authentication.ts +107 -0
  4. package/src/authentication/index.ts +1 -0
  5. package/src/chat/chat.ts +160 -0
  6. package/src/chat/index.ts +6 -0
  7. package/src/chat/interfaces/events.ts +269 -0
  8. package/src/chat/interfaces/index.ts +9 -0
  9. package/src/chat/parser.ts +265 -0
  10. package/src/eventsub/events/channel.ad_break.begin.ts +51 -0
  11. package/src/eventsub/events/channel.ban.ts +59 -0
  12. package/src/eventsub/events/channel.channel_points_custom_reward._.ts +29 -0
  13. package/src/eventsub/events/channel.channel_points_custom_reward.add.ts +75 -0
  14. package/src/eventsub/events/channel.channel_points_custom_reward.remove.ts +77 -0
  15. package/src/eventsub/events/channel.channel_points_custom_reward.update.ts +77 -0
  16. package/src/eventsub/events/channel.channel_points_custom_reward_redemption._.ts +10 -0
  17. package/src/eventsub/events/channel.channel_points_custom_reward_redemption.add.ts +59 -0
  18. package/src/eventsub/events/channel.channel_points_custom_reward_redemption.update.ts +59 -0
  19. package/src/eventsub/events/channel.charity_campaign.donate.ts +66 -0
  20. package/src/eventsub/events/channel.charity_campaign.progress.ts +67 -0
  21. package/src/eventsub/events/channel.charity_campaign.start.ts +69 -0
  22. package/src/eventsub/events/channel.charity_campaign.stop.ts +69 -0
  23. package/src/eventsub/events/channel.chat.clear.ts +42 -0
  24. package/src/eventsub/events/channel.chat.clear_user_messages.ts +48 -0
  25. package/src/eventsub/events/channel.chat.message_delete.ts +50 -0
  26. package/src/eventsub/events/channel.chat.notification.ts +50 -0
  27. package/src/eventsub/events/channel.cheer.ts +51 -0
  28. package/src/eventsub/events/channel.follow.ts +50 -0
  29. package/src/eventsub/events/channel.goal.begin.ts +51 -0
  30. package/src/eventsub/events/channel.goal.end.ts +55 -0
  31. package/src/eventsub/events/channel.goal.progress.ts +51 -0
  32. package/src/eventsub/events/channel.guest_star_guest.update.ts +66 -0
  33. package/src/eventsub/events/channel.guest_star_session.begin.ts +46 -0
  34. package/src/eventsub/events/channel.guest_star_session.end.ts +48 -0
  35. package/src/eventsub/events/channel.guest_star_settings.update.ts +50 -0
  36. package/src/eventsub/events/channel.hype_train._.ts +12 -0
  37. package/src/eventsub/events/channel.hype_train.begin.ts +57 -0
  38. package/src/eventsub/events/channel.hype_train.end.ts +55 -0
  39. package/src/eventsub/events/channel.hype_train.progress.ts +70 -0
  40. package/src/eventsub/events/channel.moderator.add.ts +45 -0
  41. package/src/eventsub/events/channel.moderator.remove.ts +45 -0
  42. package/src/eventsub/events/channel.poll._.ts +26 -0
  43. package/src/eventsub/events/channel.poll.begin.ts +55 -0
  44. package/src/eventsub/events/channel.poll.end.ts +57 -0
  45. package/src/eventsub/events/channel.poll.progress.ts +55 -0
  46. package/src/eventsub/events/channel.prediction._.ts +25 -0
  47. package/src/eventsub/events/channel.prediction.begin.ts +51 -0
  48. package/src/eventsub/events/channel.prediction.end.ts +55 -0
  49. package/src/eventsub/events/channel.prediction.lock.ts +51 -0
  50. package/src/eventsub/events/channel.prediction.progress.ts +51 -0
  51. package/src/eventsub/events/channel.raid.ts +49 -0
  52. package/src/eventsub/events/channel.shield_mode.begin.ts +50 -0
  53. package/src/eventsub/events/channel.shield_mode.end.ts +50 -0
  54. package/src/eventsub/events/channel.shoutout.create.ts +62 -0
  55. package/src/eventsub/events/channel.shoutout.receive.ts +52 -0
  56. package/src/eventsub/events/channel.subscribe.ts +49 -0
  57. package/src/eventsub/events/channel.subscription.end.ts +49 -0
  58. package/src/eventsub/events/channel.subscription.gift.ts +53 -0
  59. package/src/eventsub/events/channel.subscription.message.ts +67 -0
  60. package/src/eventsub/events/channel.unban.ts +51 -0
  61. package/src/eventsub/events/channel.update.ts +49 -0
  62. package/src/eventsub/events/index.ts +284 -0
  63. package/src/eventsub/events/stream.offline.ts +39 -0
  64. package/src/eventsub/events/stream.online.ts +45 -0
  65. package/src/eventsub/events/user.update.ts +45 -0
  66. package/src/eventsub/events-helpers.ts +29 -0
  67. package/src/eventsub/eventsub.ts +88 -0
  68. package/src/eventsub/index.ts +7 -0
  69. package/src/eventsub/messages.ts +34 -0
  70. package/src/helix/channel-points/custom-rewards.ts +63 -0
  71. package/src/helix/channel-points/index.ts +1 -0
  72. package/src/helix/helix.ts +89 -0
  73. package/src/helix/subscriptions/index.ts +1 -0
  74. package/src/helix/subscriptions/subscriptions.ts +122 -0
  75. package/src/helix/users/index.ts +1 -0
  76. package/src/helix/users/users.ts +42 -0
  77. package/src/helpers/alerts/alerts.ts +60 -0
  78. package/src/helpers/alerts/index.ts +2 -0
  79. package/src/helpers/charity/charity.ts +89 -0
  80. package/src/helpers/charity/index.ts +1 -0
  81. package/src/helpers/goal/goal.ts +38 -0
  82. package/src/helpers/goal/index.ts +1 -0
  83. package/src/helpers/hype-train/hype-train.ts +51 -0
  84. package/src/helpers/hype-train/index.ts +1 -0
  85. package/src/helpers/poll/index.ts +1 -0
  86. package/src/helpers/poll/poll.ts +63 -0
  87. package/src/helpers/prediction/index.ts +1 -0
  88. package/src/helpers/prediction/prediction.ts +66 -0
  89. package/src/helpers/redemption/index.ts +1 -0
  90. package/src/helpers/redemption/redemption.ts +42 -0
  91. package/src/helpers/status/index.ts +1 -0
  92. package/src/helpers/status/status.ts +61 -0
  93. package/src/setupTests.ts +0 -0
  94. package/src/ui/authentication.ts +230 -0
  95. package/src/ui/popup.ts +115 -0
@@ -0,0 +1,284 @@
1
+ import { NotificationMessage } from "../events-helpers.js"
2
+
3
+ import { ChannelAdBreakBeginEvent, ChannelAdBreakBeginSubscription, makeChannelAdBreakBeginSubscription } from "./channel.ad_break.begin.js"
4
+ import { ChannelBanEvent, ChannelBanSubscription, makeChannelBanSubscription } from "./channel.ban.js"
5
+ import { ChannelPointsCustomRewardAddEvent, ChannelPointsCustomRewardAddSubscription, makeChannelPointsCustomRewardAddSubscription } from "./channel.channel_points_custom_reward.add.js"
6
+ import { ChannelPointsCustomRewardRemoveEvent, ChannelPointsCustomRewardRemoveSubscription, makeChannelPointsCustomRewardRemoveSubscription } from "./channel.channel_points_custom_reward.remove.js"
7
+ import { ChannelPointsCustomRewardUpdateEvent, ChannelPointsCustomRewardUpdateSubscription, makeChannelPointsCustomRewardUpdateSubscription } from "./channel.channel_points_custom_reward.update.js"
8
+ import { ChannelPointsCustomRewardRedemptionAddEvent, ChannelPointsCustomRewardRedemptionAddSubscription, makeChannelPointsCustomRewardRedemptionAddSubscription } from "./channel.channel_points_custom_reward_redemption.add.js"
9
+ import { ChannelPointsCustomRewardRedemptionUpdateEvent, ChannelPointsCustomRewardRedemptionUpdateSubscription, makeChannelPointsCustomRewardRedemptionUpdateSubscription } from "./channel.channel_points_custom_reward_redemption.update.js"
10
+ import { CharityDonationEvent, CharityDonationSubscription, makeCharityDonationSubscription } from "./channel.charity_campaign.donate.js"
11
+ import { CharityCampaignProgressEvent, CharityCampaignProgressSubscription, makeCharityCampaignProgressSubscription } from "./channel.charity_campaign.progress.js"
12
+ import { CharityCampaignStartEvent, CharityCampaignStartSubscription, makeCharityCampaignStartSubscription } from "./channel.charity_campaign.start.js"
13
+ import { CharityCampaignStopEvent, CharityCampaignStopSubscription, makeCharityCampaignStopSubscription } from "./channel.charity_campaign.stop.js"
14
+ import { ChannelChatClearEvent, ChannelChatClearSubscription, makeChannelChatClearSubscription } from "./channel.chat.clear.js"
15
+ import { ChannelChatClearUserMessagesEvent, ChannelChatClearUserMessagesSubscription, makeChannelChatClearUserMessagesSubscription } from "./channel.chat.clear_user_messages.js"
16
+ import { ChannelChatMessageDeleteEvent, ChannelChatMessageDeleteSubscription, makeChannelChatMessageDeleteSubscription } from "./channel.chat.message_delete.js"
17
+ import { ChannelChatNotificationEvent, ChannelChatNotificationSubscription, makeChannelChatNotificationSubscription } from "./channel.chat.notification.js"
18
+ import { ChannelCheerEvent, ChannelCheerSubscription, makeChannelCheerSubscription } from "./channel.cheer.js"
19
+ import { ChannelFollowEvent, ChannelFollowSubscription, makeChannelFollowSubscription } from "./channel.follow.js"
20
+ import { GoalBeginEvent, GoalBeginSubscription, makeGoalBeginSubscription } from "./channel.goal.begin.js"
21
+ import { GoalEndEvent, GoalEndSubscription, makeGoalEndSubscription } from "./channel.goal.end.js"
22
+ import { GoalProgressEvent, GoalProgressSubscription, makeGoalProgressSubscription } from "./channel.goal.progress.js"
23
+ import { ChannelGuestStarGuestUpdateEvent, ChannelGuestStarGuestUpdateSubscription, makeChannelGuestStarGuestUpdateSubscription } from "./channel.guest_star_guest.update.js"
24
+ import { ChannelGuestStarSessionBeginEvent, ChannelGuestStarSessionBeginSubscription, makeChannelGuestStarSessionBeginSubscription } from "./channel.guest_star_session.begin.js"
25
+ import { ChannelGuestStarSessionEndEvent, ChannelGuestStarSessionEndSubscription, makeChannelGuestStarSessionEndSubscription } from "./channel.guest_star_session.end.js"
26
+ import { ChannelGuestStarSettingsUpdateEvent, ChannelGuestStarSettingsUpdateSubscription, makeChannelGuestStarSettingsUpdateSubscription } from "./channel.guest_star_settings.update.js"
27
+ import { HypeTrainBeginEvent, HypeTrainBeginSubscription, makeHypeTrainBeginSubscription } from "./channel.hype_train.begin.js"
28
+ import { HypeTrainEndEvent, HypeTrainEndSubscription, makeHypeTrainEndSubscription } from "./channel.hype_train.end.js"
29
+ import { HypeTrainProgressEvent, HypeTrainProgressSubscription, makeHypeTrainProgressSubscription } from "./channel.hype_train.progress.js"
30
+ import { ChannelModeratorAddEvent, ChannelModeratorAddSubscription, makeChannelModeratorAddSubscription } from "./channel.moderator.add.js"
31
+ import { ChannelModeratorRemoveEvent, ChannelModeratorRemoveSubscription, makeChannelModeratorRemoveSubscription } from "./channel.moderator.remove.js"
32
+ import { ChannelPollBeginEvent, ChannelPollBeginSubscription, makeChannelPollBeginSubscription } from "./channel.poll.begin.js"
33
+ import { ChannelPollEndEvent, ChannelPollEndSubscription, makeChannelPollEndSubscription } from "./channel.poll.end.js"
34
+ import { ChannelPollProgressEvent, ChannelPollProgressSubscription, makeChannelPollProgressSubscription } from "./channel.poll.progress.js"
35
+ import { ChannelPredictionBeginEvent, ChannelPredictionBeginSubscription, makeChannelPredictionBeginSubscription } from "./channel.prediction.begin.js"
36
+ import { ChannelPredictionEndEvent, ChannelPredictionEndSubscription, makeChannelPredictionEndSubscription } from "./channel.prediction.end.js"
37
+ import { ChannelPredictionLockEvent, ChannelPredictionLockSubscription, makeChannelPredictionLockSubscription } from "./channel.prediction.lock.js"
38
+ import { ChannelPredictionProgressEvent, ChannelPredictionProgressSubscription, makeChannelPredictionProgressSubscription } from "./channel.prediction.progress.js"
39
+ import { ChannelRaidEvent, ChannelRaidSubscription, makeChannelRaidSubscription } from "./channel.raid.js"
40
+ import { ShieldModeBeginEvent, ShieldModeBeginSubscription, makeShieldModeBeginSubscription } from "./channel.shield_mode.begin.js"
41
+ import { ShieldModeEndEvent, ShieldModeEndSubscription, makeShieldModeEndSubscription } from "./channel.shield_mode.end.js"
42
+ import { ShoutoutCreateEvent, ShoutoutCreateSubscription, makeShoutoutCreateSubscription } from "./channel.shoutout.create.js"
43
+ import { ShoutoutReceiveEvent, ShoutoutReceiveSubscription, makeShoutoutReceiveSubscription } from "./channel.shoutout.receive.js"
44
+ import { ChannelSubscribeEvent, ChannelSubscribeSubscription, makeChannelSubscribeSubscription } from "./channel.subscribe.js"
45
+ import { ChannelSubscriptionEndEvent, ChannelSubscriptionEndSubscription, makeChannelSubscriptionEndSubscription } from "./channel.subscription.end.js"
46
+ import { ChannelSubscriptionGiftEvent, ChannelSubscriptionGiftSubscription, makeChannelSubscriptionGiftSubscription } from "./channel.subscription.gift.js"
47
+ import { ChannelSubscriptionMessageEvent, ChannelSubscriptionMessageSubscription, makeChannelSubscriptionMessageSubscription } from "./channel.subscription.message.js"
48
+ import { ChannelUnbanEvent, ChannelUnbanSubscription, makeChannelUnbanSubscription } from "./channel.unban.js"
49
+ import { ChannelUpdateEvent, ChannelUpdateSubscription, makeChannelUpdateSubscription } from "./channel.update.js"
50
+ import { StreamOfflineEvent, StreamOfflineSubscription, makeStreamOfflineSubscription } from "./stream.offline.js"
51
+ import { StreamOnlineEvent, StreamOnlineSubscription, makeStreamOnlineSubscription } from "./stream.online.js"
52
+ import { UserUpdateEvent, UserUpdateSubscription, makeUserUpdateSubscription } from "./user.update.js"
53
+
54
+ export * from "./channel.ad_break.begin.js"
55
+ export * from "./channel.ban.js"
56
+ export * from "./channel.channel_points_custom_reward.add.js"
57
+ export * from "./channel.channel_points_custom_reward.remove.js"
58
+ export * from "./channel.channel_points_custom_reward.update.js"
59
+ export * from "./channel.channel_points_custom_reward_redemption.add.js"
60
+ export * from "./channel.channel_points_custom_reward_redemption.update.js"
61
+ export * from "./channel.charity_campaign.donate.js"
62
+ export * from "./channel.charity_campaign.progress.js"
63
+ export * from "./channel.charity_campaign.start.js"
64
+ export * from "./channel.charity_campaign.stop.js"
65
+ export * from "./channel.chat.clear.js"
66
+ export * from "./channel.chat.clear_user_messages.js"
67
+ export * from "./channel.chat.message_delete.js"
68
+ export * from "./channel.chat.notification.js"
69
+ export * from "./channel.cheer.js"
70
+ export * from "./channel.follow.js"
71
+ export * from "./channel.goal.begin.js"
72
+ export * from "./channel.goal.end.js"
73
+ export * from "./channel.goal.progress.js"
74
+ export * from "./channel.guest_star_guest.update.js"
75
+ export * from "./channel.guest_star_session.begin.js"
76
+ export * from "./channel.guest_star_session.end.js"
77
+ export * from "./channel.guest_star_settings.update.js"
78
+ export * from "./channel.hype_train.begin.js"
79
+ export * from "./channel.hype_train.end.js"
80
+ export * from "./channel.hype_train.progress.js"
81
+ export * from "./channel.moderator.add.js"
82
+ export * from "./channel.moderator.remove.js"
83
+ export * from "./channel.poll.begin.js"
84
+ export * from "./channel.poll.end.js"
85
+ export * from "./channel.poll.progress.js"
86
+ export * from "./channel.prediction.begin.js"
87
+ export * from "./channel.prediction.end.js"
88
+ export * from "./channel.prediction.lock.js"
89
+ export * from "./channel.prediction.progress.js"
90
+ export * from "./channel.raid.js"
91
+ export * from "./channel.shield_mode.begin.js"
92
+ export * from "./channel.shield_mode.end.js"
93
+ export * from "./channel.shoutout.create.js"
94
+ export * from "./channel.shoutout.receive.js"
95
+ export * from "./channel.subscribe.js"
96
+ export * from "./channel.subscription.end.js"
97
+ export * from "./channel.subscription.gift.js"
98
+ export * from "./channel.subscription.message.js"
99
+ export * from "./channel.unban.js"
100
+ export * from "./channel.update.js"
101
+ export * from "./stream.offline.js"
102
+ export * from "./stream.online.js"
103
+ export * from "./user.update.js"
104
+
105
+ type AllSubscription =
106
+ | ChannelAdBreakBeginSubscription
107
+ | ChannelBanSubscription
108
+ | ChannelChatClearSubscription
109
+ | ChannelChatClearUserMessagesSubscription
110
+ | ChannelChatMessageDeleteSubscription
111
+ | ChannelChatNotificationSubscription
112
+ | ChannelCheerSubscription
113
+ | ChannelFollowSubscription
114
+ | ChannelGuestStarGuestUpdateSubscription
115
+ | ChannelGuestStarSessionBeginSubscription
116
+ | ChannelGuestStarSessionEndSubscription
117
+ | ChannelGuestStarSettingsUpdateSubscription
118
+ | ChannelModeratorAddSubscription
119
+ | ChannelModeratorRemoveSubscription
120
+ | ChannelPointsCustomRewardAddSubscription
121
+ | ChannelPointsCustomRewardRedemptionAddSubscription
122
+ | ChannelPointsCustomRewardRedemptionUpdateSubscription
123
+ | ChannelPointsCustomRewardRemoveSubscription
124
+ | ChannelPointsCustomRewardUpdateSubscription
125
+ | ChannelPollBeginSubscription
126
+ | ChannelPollEndSubscription
127
+ | ChannelPollProgressSubscription
128
+ | ChannelPredictionBeginSubscription
129
+ | ChannelPredictionEndSubscription
130
+ | ChannelPredictionLockSubscription
131
+ | ChannelPredictionProgressSubscription
132
+ | ChannelRaidSubscription
133
+ | ChannelSubscribeSubscription
134
+ | ChannelSubscriptionEndSubscription
135
+ | ChannelSubscriptionGiftSubscription
136
+ | ChannelSubscriptionMessageSubscription
137
+ | ChannelUnbanSubscription
138
+ | ChannelUpdateSubscription
139
+ | CharityCampaignProgressSubscription
140
+ | CharityCampaignStartSubscription
141
+ | CharityCampaignStopSubscription
142
+ | CharityDonationSubscription
143
+ | GoalBeginSubscription
144
+ | GoalEndSubscription
145
+ | GoalProgressSubscription
146
+ | HypeTrainBeginSubscription
147
+ | HypeTrainEndSubscription
148
+ | HypeTrainProgressSubscription
149
+ | ShieldModeBeginSubscription
150
+ | ShieldModeEndSubscription
151
+ | ShoutoutCreateSubscription
152
+ | ShoutoutReceiveSubscription
153
+ | StreamOfflineSubscription
154
+ | StreamOnlineSubscription
155
+ | UserUpdateSubscription
156
+
157
+ type AllNotificationMessage =
158
+ | NotificationMessage<ChannelAdBreakBeginSubscription, ChannelAdBreakBeginEvent>
159
+ | NotificationMessage<ChannelBanSubscription, ChannelBanEvent>
160
+ | NotificationMessage<ChannelChatClearSubscription, ChannelChatClearEvent>
161
+ | NotificationMessage<ChannelChatClearUserMessagesSubscription, ChannelChatClearUserMessagesEvent>
162
+ | NotificationMessage<ChannelChatMessageDeleteSubscription, ChannelChatMessageDeleteEvent>
163
+ | NotificationMessage<ChannelChatNotificationSubscription, ChannelChatNotificationEvent>
164
+ | NotificationMessage<ChannelCheerSubscription, ChannelCheerEvent>
165
+ | NotificationMessage<ChannelFollowSubscription, ChannelFollowEvent>
166
+ | NotificationMessage<ChannelGuestStarGuestUpdateSubscription, ChannelGuestStarGuestUpdateEvent>
167
+ | NotificationMessage<ChannelGuestStarSessionBeginSubscription, ChannelGuestStarSessionBeginEvent>
168
+ | NotificationMessage<ChannelGuestStarSessionEndSubscription, ChannelGuestStarSessionEndEvent>
169
+ | NotificationMessage<ChannelGuestStarSettingsUpdateSubscription, ChannelGuestStarSettingsUpdateEvent>
170
+ | NotificationMessage<ChannelModeratorAddSubscription, ChannelModeratorAddEvent>
171
+ | NotificationMessage<ChannelModeratorRemoveSubscription, ChannelModeratorRemoveEvent>
172
+ | NotificationMessage<ChannelPointsCustomRewardAddSubscription, ChannelPointsCustomRewardAddEvent>
173
+ | NotificationMessage<ChannelPointsCustomRewardRedemptionAddSubscription, ChannelPointsCustomRewardRedemptionAddEvent>
174
+ | NotificationMessage<ChannelPointsCustomRewardRedemptionUpdateSubscription, ChannelPointsCustomRewardRedemptionUpdateEvent>
175
+ | NotificationMessage<ChannelPointsCustomRewardRemoveSubscription, ChannelPointsCustomRewardRemoveEvent>
176
+ | NotificationMessage<ChannelPointsCustomRewardUpdateSubscription, ChannelPointsCustomRewardUpdateEvent>
177
+ | NotificationMessage<ChannelPollBeginSubscription, ChannelPollBeginEvent>
178
+ | NotificationMessage<ChannelPollEndSubscription, ChannelPollEndEvent>
179
+ | NotificationMessage<ChannelPollProgressSubscription, ChannelPollProgressEvent>
180
+ | NotificationMessage<ChannelPredictionBeginSubscription, ChannelPredictionBeginEvent>
181
+ | NotificationMessage<ChannelPredictionEndSubscription, ChannelPredictionEndEvent>
182
+ | NotificationMessage<ChannelPredictionLockSubscription, ChannelPredictionLockEvent>
183
+ | NotificationMessage<ChannelPredictionProgressSubscription, ChannelPredictionProgressEvent>
184
+ | NotificationMessage<ChannelRaidSubscription, ChannelRaidEvent>
185
+ | NotificationMessage<ChannelSubscribeSubscription, ChannelSubscribeEvent>
186
+ | NotificationMessage<ChannelSubscriptionEndSubscription, ChannelSubscriptionEndEvent>
187
+ | NotificationMessage<ChannelSubscriptionGiftSubscription, ChannelSubscriptionGiftEvent>
188
+ | NotificationMessage<ChannelSubscriptionMessageSubscription, ChannelSubscriptionMessageEvent>
189
+ | NotificationMessage<ChannelUnbanSubscription, ChannelUnbanEvent>
190
+ | NotificationMessage<ChannelUpdateSubscription, ChannelUpdateEvent>
191
+ | NotificationMessage<CharityCampaignProgressSubscription, CharityCampaignProgressEvent>
192
+ | NotificationMessage<CharityCampaignStartSubscription, CharityCampaignStartEvent>
193
+ | NotificationMessage<CharityCampaignStopSubscription, CharityCampaignStopEvent>
194
+ | NotificationMessage<CharityDonationSubscription, CharityDonationEvent>
195
+ | NotificationMessage<GoalBeginSubscription, GoalBeginEvent>
196
+ | NotificationMessage<GoalEndSubscription, GoalEndEvent>
197
+ | NotificationMessage<GoalProgressSubscription, GoalProgressEvent>
198
+ | NotificationMessage<HypeTrainBeginSubscription, HypeTrainBeginEvent>
199
+ | NotificationMessage<HypeTrainEndSubscription, HypeTrainEndEvent>
200
+ | NotificationMessage<HypeTrainProgressSubscription, HypeTrainProgressEvent>
201
+ | NotificationMessage<ShieldModeBeginSubscription, ShieldModeBeginEvent>
202
+ | NotificationMessage<ShieldModeEndSubscription, ShieldModeEndEvent>
203
+ | NotificationMessage<ShoutoutCreateSubscription, ShoutoutCreateEvent>
204
+ | NotificationMessage<ShoutoutReceiveSubscription, ShoutoutReceiveEvent>
205
+ | NotificationMessage<StreamOfflineSubscription, StreamOfflineEvent>
206
+ | NotificationMessage<StreamOnlineSubscription, StreamOnlineEvent>
207
+ | NotificationMessage<UserUpdateSubscription, UserUpdateEvent>
208
+
209
+ export type TwitchSubscriptionType = AllSubscription["type"]
210
+
211
+ export type TwitchSubscription<
212
+ Type extends TwitchSubscriptionType = TwitchSubscriptionType,
213
+ > = Extract<AllSubscription, { type: Type }>
214
+
215
+ export type TwitchNotificationMessage<
216
+ Type extends TwitchSubscriptionType = TwitchSubscriptionType,
217
+ > = Extract<AllNotificationMessage, { payload: { type: Type } }>
218
+
219
+ const subscriptionBuilders: {
220
+ [Type in TwitchSubscriptionType]: (userId: string) => TwitchSubscription<Type>
221
+ } = {
222
+ "channel.ad_break.begin": makeChannelAdBreakBeginSubscription,
223
+ "channel.ban": makeChannelBanSubscription,
224
+ "channel.channel_points_custom_reward.add": makeChannelPointsCustomRewardAddSubscription,
225
+ "channel.channel_points_custom_reward.remove": makeChannelPointsCustomRewardRemoveSubscription,
226
+ "channel.channel_points_custom_reward.update": makeChannelPointsCustomRewardUpdateSubscription,
227
+ "channel.channel_points_custom_reward_redemption.add": makeChannelPointsCustomRewardRedemptionAddSubscription,
228
+ "channel.channel_points_custom_reward_redemption.update": makeChannelPointsCustomRewardRedemptionUpdateSubscription,
229
+ "channel.charity_campaign.donate": makeCharityDonationSubscription,
230
+ "channel.charity_campaign.progress": makeCharityCampaignProgressSubscription,
231
+ "channel.charity_campaign.start": makeCharityCampaignStartSubscription,
232
+ "channel.charity_campaign.stop": makeCharityCampaignStopSubscription,
233
+ "channel.chat.clear": makeChannelChatClearSubscription,
234
+ "channel.chat.clear_user_messages": makeChannelChatClearUserMessagesSubscription,
235
+ "channel.chat.message_delete": makeChannelChatMessageDeleteSubscription,
236
+ "channel.chat.notification": makeChannelChatNotificationSubscription,
237
+ "channel.cheer": makeChannelCheerSubscription,
238
+ "channel.follow": makeChannelFollowSubscription,
239
+ "channel.goal.begin": makeGoalBeginSubscription,
240
+ "channel.goal.end": makeGoalEndSubscription,
241
+ "channel.goal.progress": makeGoalProgressSubscription,
242
+ "channel.guest_star_guest.update": makeChannelGuestStarGuestUpdateSubscription,
243
+ "channel.guest_star_session.begin": makeChannelGuestStarSessionBeginSubscription,
244
+ "channel.guest_star_session.end": makeChannelGuestStarSessionEndSubscription,
245
+ "channel.guest_star_settings.update": makeChannelGuestStarSettingsUpdateSubscription,
246
+ "channel.hype_train.begin": makeHypeTrainBeginSubscription,
247
+ "channel.hype_train.end": makeHypeTrainEndSubscription,
248
+ "channel.hype_train.progress": makeHypeTrainProgressSubscription,
249
+ "channel.moderator.add": makeChannelModeratorAddSubscription,
250
+ "channel.moderator.remove": makeChannelModeratorRemoveSubscription,
251
+ "channel.poll.begin": makeChannelPollBeginSubscription,
252
+ "channel.poll.end": makeChannelPollEndSubscription,
253
+ "channel.poll.progress": makeChannelPollProgressSubscription,
254
+ "channel.prediction.begin": makeChannelPredictionBeginSubscription,
255
+ "channel.prediction.end": makeChannelPredictionEndSubscription,
256
+ "channel.prediction.lock": makeChannelPredictionLockSubscription,
257
+ "channel.prediction.progress": makeChannelPredictionProgressSubscription,
258
+ "channel.raid": makeChannelRaidSubscription,
259
+ "channel.shield_mode.begin": makeShieldModeBeginSubscription,
260
+ "channel.shield_mode.end": makeShieldModeEndSubscription,
261
+ "channel.shoutout.create": makeShoutoutCreateSubscription,
262
+ "channel.shoutout.receive": makeShoutoutReceiveSubscription,
263
+ "channel.subscribe": makeChannelSubscribeSubscription,
264
+ "channel.subscription.end": makeChannelSubscriptionEndSubscription,
265
+ "channel.subscription.gift": makeChannelSubscriptionGiftSubscription,
266
+ "channel.subscription.message": makeChannelSubscriptionMessageSubscription,
267
+ "channel.unban": makeChannelUnbanSubscription,
268
+ "channel.update": makeChannelUpdateSubscription,
269
+ "stream.offline": makeStreamOfflineSubscription,
270
+ "stream.online": makeStreamOnlineSubscription,
271
+ "user.update": makeUserUpdateSubscription,
272
+ }
273
+
274
+ export function buildSubscription<
275
+ Type extends TwitchSubscriptionType,
276
+ Subscription extends TwitchSubscription<Type>,
277
+ >(type: Type, userId: string): Subscription {
278
+ const creator = subscriptionBuilders[type]
279
+ if (!creator) {
280
+ throw new Error(`Unknown type ${type}`)
281
+ }
282
+
283
+ return creator(userId) as Subscription
284
+ }
@@ -0,0 +1,39 @@
1
+ import { BaseSubscription } from "../events-helpers.js"
2
+
3
+ type StreamOfflineType = "stream.offline"
4
+ type StreamOfflineVersion = "1"
5
+
6
+ /** The parameters under which an event fires when The broadcaster stops a stream. */
7
+ export interface StreamOfflineCondition {
8
+ /** The user ID of the broadcaster. */
9
+ broadcaster_user_id: string
10
+ }
11
+
12
+ /** The event information when The broadcaster stops a stream. */
13
+ export interface StreamOfflineEvent {
14
+ /** The user ID of the broadcaster. */
15
+ broadcaster_user_id: string
16
+ /** The user login of the broadcaster. */
17
+ broadcaster_user_login: string
18
+ /** The user name of the broadcaster. */
19
+ broadcaster_user_name: string
20
+ }
21
+
22
+ /** The event notification received when The broadcaster stops a stream. */
23
+ export type StreamOfflineSubscription = BaseSubscription<
24
+ StreamOfflineType,
25
+ StreamOfflineVersion,
26
+ StreamOfflineCondition
27
+ >
28
+
29
+ export function makeStreamOfflineSubscription(
30
+ userId: string,
31
+ ): StreamOfflineSubscription {
32
+ return {
33
+ type: "stream.offline",
34
+ version: "1",
35
+ condition: {
36
+ broadcaster_user_id: userId,
37
+ },
38
+ }
39
+ }
@@ -0,0 +1,45 @@
1
+ import { BaseSubscription } from "../events-helpers.js"
2
+
3
+ type StreamOnlineType = "stream.online"
4
+ type StreamOnlineVersion = "1"
5
+
6
+ /** The parameters under which an event fires when The broadcaster starts a stream. */
7
+ export interface StreamOnlineCondition {
8
+ /** The user ID of the broadcaster. */
9
+ broadcaster_user_id: string
10
+ }
11
+
12
+ /** The event information when The broadcaster starts a stream. */
13
+ export interface StreamOnlineEvent {
14
+ /** The ID of the stream. */
15
+ id: string
16
+ /** The user ID of the broadcaster. */
17
+ broadcaster_user_id: string
18
+ /** The user login of the broadcaster. */
19
+ broadcaster_user_login: string
20
+ /** The user name of the broadcaster. */
21
+ broadcaster_user_name: string
22
+ /** The stream type. Valid values are: live, playlist, watch_party, premiere, rerun. */
23
+ type: string
24
+ /** The time the stream went online. */
25
+ started_at: Date
26
+ }
27
+
28
+ /** The event notification received when The broadcaster starts a stream. */
29
+ export type StreamOnlineSubscription = BaseSubscription<
30
+ StreamOnlineType,
31
+ StreamOnlineVersion,
32
+ StreamOnlineCondition
33
+ >
34
+
35
+ export function makeStreamOnlineSubscription(
36
+ userId: string,
37
+ ): StreamOnlineSubscription {
38
+ return {
39
+ type: "stream.online",
40
+ version: "1",
41
+ condition: {
42
+ broadcaster_user_id: userId,
43
+ },
44
+ }
45
+ }
@@ -0,0 +1,45 @@
1
+ import { BaseSubscription } from "../events-helpers.js"
2
+
3
+ type UserUpdateType = "user.update"
4
+ type UserUpdateVersion = "1"
5
+
6
+ /** The parameters under which an event fires when A user updateds their account. */
7
+ export interface UserUpdateCondition {
8
+ /** The user ID. */
9
+ user_id: string
10
+ }
11
+
12
+ /** The event information when A user updateds their account. */
13
+ export interface UserUpdateEvent {
14
+ /** The user ID of the user who was updated. */
15
+ user_id: string
16
+ /** The user login of the user who was updated. */
17
+ user_login: string
18
+ /** The user name of the user who was updated. */
19
+ user_name: string
20
+ /** The user email address. The event includes the user's email address only if the app used to request this event type includes the user:read:email scope for the user; otherwise, the field is set to an empty string. See Create EventSub Subscription. */
21
+ email: string
22
+ /** A Boolean value that determines whether Twitch has verified the user's email address. Is true if Twitch has verified the email address; otherwise, false.\n\nNOTE: Ignore this field if the email field contains an empty string. */
23
+ email_verified: boolean
24
+ /** The user description. */
25
+ description: string
26
+ }
27
+
28
+ /** The event notification received when A user updateds their account. */
29
+ export type UserUpdateSubscription = BaseSubscription<
30
+ UserUpdateType,
31
+ UserUpdateVersion,
32
+ UserUpdateCondition
33
+ >
34
+
35
+ export function makeUserUpdateSubscription(
36
+ userId: string,
37
+ ): UserUpdateSubscription {
38
+ return {
39
+ type: "user.update",
40
+ version: "1",
41
+ condition: {
42
+ user_id: userId,
43
+ },
44
+ }
45
+ }
@@ -0,0 +1,29 @@
1
+ export type BaseSubscription<
2
+ Type = unknown,
3
+ Version = unknown,
4
+ Condition = unknown,
5
+ > = {
6
+ type: Type
7
+ version: Version
8
+ condition: Condition
9
+ }
10
+
11
+ export interface NotificationMessage<
12
+ Subscription extends BaseSubscription,
13
+ Event,
14
+ > {
15
+ type: "notification"
16
+ metadata: {
17
+ message_id: string
18
+ message_type: "notification"
19
+ message_timestamp: Date
20
+ subscription_type: Subscription["type"]
21
+ subscription_version: Subscription["version"]
22
+ }
23
+ payload: {
24
+ id: string
25
+ type: Subscription["type"]
26
+ subscription: Subscription
27
+ event: Event
28
+ }
29
+ }
@@ -0,0 +1,88 @@
1
+ import createDefer from "@overlaysymphony/core/libs/defer"
2
+ import createPubSub from "@overlaysymphony/core/libs/pubsub"
3
+
4
+ import { Authentication } from "../authentication/index.js"
5
+ import { createSubscription } from "../helix/subscriptions/index.js"
6
+
7
+ import {
8
+ TwitchNotificationMessage,
9
+ TwitchSubscriptionType,
10
+ } from "./events/index.js"
11
+ import { TwitchMessage } from "./messages.js"
12
+
13
+ type EventSubListener = (
14
+ callback: (event: TwitchNotificationMessage["payload"]) => void,
15
+ ) => () => void
16
+
17
+ type EventSubSubscriber = <
18
+ EventType extends TwitchSubscriptionType,
19
+ Event extends TwitchNotificationMessage<EventType>["payload"],
20
+ >(
21
+ types: EventType[],
22
+ callback: (event: Event) => void,
23
+ ) => () => void
24
+
25
+ export interface TwitchEventSub {
26
+ listen: EventSubListener
27
+ subscribe: EventSubSubscriber
28
+ }
29
+
30
+ export async function createEventSub(
31
+ authentication: Authentication,
32
+ ): Promise<TwitchEventSub> {
33
+ const { promise, resolve } = createDefer<string>()
34
+
35
+ const pubsub = createPubSub<TwitchNotificationMessage["payload"]>()
36
+ const socket = new WebSocket("wss://eventsub.wss.twitch.tv/ws")
37
+
38
+ socket.addEventListener("message", async ({ data: rawData }) => {
39
+ const data = JSON.parse(rawData) as TwitchMessage
40
+ data.type = data.metadata.message_type
41
+
42
+ if (data.type === "session_welcome") {
43
+ resolve(data.payload.session.id)
44
+ return
45
+ }
46
+
47
+ if (data.type === "notification") {
48
+ data.payload.id = data.metadata.message_id
49
+ data.payload.type = data.payload.subscription.type
50
+
51
+ pubsub.dispatch(data.payload)
52
+ return
53
+ }
54
+ })
55
+
56
+ return promise.then((sessionId) => {
57
+ const subscriptions: Partial<Record<TwitchSubscriptionType, boolean>> = {}
58
+
59
+ const listen: EventSubListener = (callback) => {
60
+ return pubsub.subscribe((event) => {
61
+ // @ts-ignore
62
+ callback(event)
63
+ })
64
+ }
65
+
66
+ const subscribe: EventSubSubscriber = (types, callback) => {
67
+ for (const type of types) {
68
+ if (!subscriptions[type]) {
69
+ subscriptions[type] = true
70
+ createSubscription(sessionId, authentication, type)
71
+ }
72
+ }
73
+
74
+ return pubsub.subscribe((event) => {
75
+ // @ts-ignore
76
+ if (types.includes(event.type)) {
77
+ // @ts-ignore
78
+ callback(event)
79
+ }
80
+ })
81
+ }
82
+
83
+ return {
84
+ listen,
85
+ subscribe,
86
+ }
87
+ })
88
+ }
@@ -0,0 +1,7 @@
1
+ export type {
2
+ TwitchSubscriptionType,
3
+ TwitchSubscription,
4
+ TwitchNotificationMessage,
5
+ } from "./events/index.js"
6
+
7
+ export * from "./eventsub.js"
@@ -0,0 +1,34 @@
1
+ import { TwitchNotificationMessage } from "./events/index.js"
2
+
3
+ export interface SessionWelcomeMessage {
4
+ type: "session_welcome"
5
+ metadata: {
6
+ message_id: string
7
+ message_type: "session_welcome"
8
+ message_timestamp: Date
9
+ }
10
+ payload: {
11
+ session: {
12
+ id: string
13
+ status: "connected"
14
+ connected_at: Date
15
+ keepalive_timeout_seconds: number
16
+ reconnect_url: string | null
17
+ }
18
+ }
19
+ }
20
+
21
+ export interface SessionKeepaliveMessage {
22
+ type: "session_keepalive"
23
+ metadata: {
24
+ message_id: string
25
+ message_type: "session_keepalive"
26
+ message_timestamp: Date
27
+ }
28
+ payload: Record<string, never>
29
+ }
30
+
31
+ export type TwitchMessage =
32
+ | SessionWelcomeMessage
33
+ | SessionKeepaliveMessage
34
+ | TwitchNotificationMessage
@@ -0,0 +1,63 @@
1
+ import { Authentication } from "../../authentication/index.js"
2
+ import { helix } from "../helix.js"
3
+
4
+ interface CustomReward {
5
+ broadcaster_id: string
6
+ broadcaster_login: string
7
+ broadcaster_name: string
8
+ id: string
9
+ title: string
10
+ prompt: string
11
+ cost: number
12
+ image: {
13
+ url_1x: string
14
+ url_2x: string
15
+ url_4x: string
16
+ }
17
+ default_image: {
18
+ url_1x: string
19
+ url_2x: string
20
+ url_4x: string
21
+ }
22
+ background_color: string
23
+ is_enabled: boolean
24
+ is_user_input_required: boolean
25
+ max_per_stream_setting: {
26
+ is_enabled: boolean
27
+ max_per_stream: number
28
+ }
29
+ max_per_user_per_stream_setting: {
30
+ is_enabled: boolean
31
+ max_per_user_per_stream: number
32
+ }
33
+ global_cooldown_setting: {
34
+ is_enabled: boolean
35
+ global_cooldown_seconds: number
36
+ }
37
+ is_paused: boolean
38
+ is_in_stock: boolean
39
+ should_redemptions_skip_request_queue: boolean
40
+ redemptions_redeemed_current_stream: number
41
+ cooldown_expires_at: string
42
+ }
43
+
44
+ export async function getCustomRewards(
45
+ authentication: Authentication,
46
+ ): Promise<CustomReward[]> {
47
+ const subscriptions = await helix<
48
+ CustomReward,
49
+ never,
50
+ {
51
+ broadcaster_id: string
52
+ },
53
+ never
54
+ >(authentication, {
55
+ method: "get",
56
+ path: "/channel_points/custom_rewards",
57
+ params: {
58
+ broadcaster_id: authentication.user.id,
59
+ },
60
+ })
61
+
62
+ return subscriptions
63
+ }
@@ -0,0 +1 @@
1
+ export * from "./custom-rewards.js"