Skip to content

Commit

Permalink
good ol 609
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Sep 22, 2023
1 parent faba390 commit 67d95bc
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 171 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
},
"dependencies": {
"@supabase/supabase-js": "^2.34.0",
"@twurple/api": "7.0.2",
"@twurple/auth": "7.0.2",
"@twurple/chat": "7.0.2",
"@twurple/eventsub-base": "7.0.2",
"@twurple/api": "6.0.9",
"@twurple/auth": "6.0.9",
"@twurple/chat": "6.0.9",
"@twurple/eventsub-base": "6.0.9",
"@twurple/eventsub-http": "6.0.9",
"i18next": "^23.5.1",
"i18next-fs-backend": "^2.2.0",
"socket.io": "^4.7.2",
Expand Down
66 changes: 32 additions & 34 deletions packages/dota/src/twitch/lib/getAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,38 @@ export const getAuthProvider = function () {
authProvider = new RefreshingAuthProvider({
clientId: process.env.TWITCH_CLIENT_ID ?? '',
clientSecret: process.env.TWITCH_CLIENT_SECRET ?? '',
})

// eslint-disable-next-line @typescript-eslint/no-misused-promises
authProvider.onRefreshFailure(async (twitchId) => {
logger.error('[TWITCHSETUP] Failed to refresh twitch tokens', { twitchId })

await supabase
.from('accounts')
.update({
requires_refresh: true,
})
.eq('providerAccountId', twitchId)
.eq('provider', 'twitch')
})

// eslint-disable-next-line @typescript-eslint/no-misused-promises
authProvider.onRefresh(async (twitchId, newTokenData) => {
logger.info('[TWITCHSETUP] Refreshing twitch tokens', { twitchId })

await supabase
.from('accounts')
.update({
scope: newTokenData.scope.join(' '),
access_token: newTokenData.accessToken,
refresh_token: newTokenData.refreshToken!,
expires_at: Math.floor(
new Date(newTokenData.obtainmentTimestamp).getTime() / 1000 +
(newTokenData.expiresIn ?? 0),
),
expires_in: newTokenData.expiresIn ?? 0,
obtainment_timestamp: new Date(newTokenData.obtainmentTimestamp).toISOString(),
})
.eq('providerAccountId', twitchId)
.eq('provider', 'twitch')
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onRefreshFailure: async (twitchId) => {
logger.error('[TWITCHSETUP] Failed to refresh twitch tokens', { twitchId })

await supabase
.from('accounts')
.update({
requires_refresh: true,
})
.eq('providerAccountId', twitchId)
.eq('provider', 'twitch')
},
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onRefresh: async (twitchId, newTokenData) => {
logger.info('[TWITCHSETUP] Refreshing twitch tokens', { twitchId })

await supabase
.from('accounts')
.update({
scope: newTokenData.scope.join(' '),
access_token: newTokenData.accessToken,
refresh_token: newTokenData.refreshToken!,
expires_at: Math.floor(
new Date(newTokenData.obtainmentTimestamp).getTime() / 1000 +
(newTokenData.expiresIn ?? 0),
),
expires_in: newTokenData.expiresIn ?? 0,
obtainment_timestamp: new Date(newTokenData.obtainmentTimestamp).toISOString(),
})
.eq('providerAccountId', twitchId)
.eq('provider', 'twitch')
},
})

return authProvider
Expand Down
39 changes: 19 additions & 20 deletions packages/twitch/chat/src/twitch/lib/getAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@ export const getAuthProvider = function () {
authProvider = new RefreshingAuthProvider({
clientId: process.env.TWITCH_CLIENT_ID ?? '',
clientSecret: process.env.TWITCH_CLIENT_SECRET ?? '',
})

// eslint-disable-next-line @typescript-eslint/no-misused-promises
authProvider.onRefresh(async (twitchId, newTokenData) => {
console.log('[TWITCHSETUP] Refreshing twitch tokens', { twitchId })
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onRefresh: async (twitchId, newTokenData) => {
console.log('[TWITCHSETUP] Refreshing twitch tokens', { twitchId })

await supabase
.from('accounts')
.update({
scope: newTokenData.scope.join(' '),
access_token: newTokenData.accessToken,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
refresh_token: newTokenData.refreshToken!,
expires_at: Math.floor(
new Date(newTokenData.obtainmentTimestamp).getTime() / 1000 +
(newTokenData.expiresIn ?? 0),
),
expires_in: newTokenData.expiresIn ?? 0,
obtainment_timestamp: new Date(newTokenData.obtainmentTimestamp).toISOString(),
})
.eq('providerAccountId', twitchId)
await supabase
.from('accounts')
.update({
scope: newTokenData.scope.join(' '),
access_token: newTokenData.accessToken,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
refresh_token: newTokenData.refreshToken!,
expires_at: Math.floor(
new Date(newTokenData.obtainmentTimestamp).getTime() / 1000 +
(newTokenData.expiresIn ?? 0),
),
expires_in: newTokenData.expiresIn ?? 0,
obtainment_timestamp: new Date(newTokenData.obtainmentTimestamp).toISOString(),
})
.eq('providerAccountId', twitchId)
},
})

return authProvider
Expand Down
2 changes: 1 addition & 1 deletion packages/twitch/chat/src/twitch/lib/getChatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function getChatClient() {
webSocket: true,
})

chatClient.connect()
await chatClient.connect()
console.log('[TWITCHSETUP] Connected to chat client')

return chatClient
Expand Down
4 changes: 0 additions & 4 deletions packages/twitch/events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
"host:development": "nodemon -L --ext ts ./src/index.ts"
},
"dependencies": {
"@twurple/api": "6.0.9",
"@twurple/auth": "6.0.9",
"@twurple/eventsub-base": "6.0.9",
"@twurple/eventsub-http": "6.0.9",
"express": "^4.18.2",
"node-gyp": "^9.4.0",
"socket.io": "^4.7.2",
Expand Down
131 changes: 23 additions & 108 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ __metadata:
languageName: node
linkType: hard

"@d-fischer/connection@npm:^8.0.5":
"@d-fischer/connection@npm:^8.0.2":
version: 8.0.5
resolution: "@d-fischer/connection@npm:8.0.5"
dependencies:
Expand All @@ -979,15 +979,6 @@ __metadata:
languageName: node
linkType: hard

"@d-fischer/cross-fetch@npm:^5.0.1":
version: 5.0.2
resolution: "@d-fischer/cross-fetch@npm:5.0.2"
dependencies:
node-fetch: ^2.6.11
checksum: 541efa11b5a1769951e542b3d8dff4acdd88356d209ba2f3578be9343713a64fc07ef7783701985a0c86ef1a32970450621883220c412297edda86fad43aef99
languageName: node
linkType: hard

"@d-fischer/deprecate@npm:^2.0.2":
version: 2.0.2
resolution: "@d-fischer/deprecate@npm:2.0.2"
Expand Down Expand Up @@ -1074,7 +1065,7 @@ __metadata:
languageName: node
linkType: hard

"@d-fischer/shared-utils@npm:^3.0.1, @d-fischer/shared-utils@npm:^3.2.0, @d-fischer/shared-utils@npm:^3.4.0, @d-fischer/shared-utils@npm:^3.5.0, @d-fischer/shared-utils@npm:^3.6.1":
"@d-fischer/shared-utils@npm:^3.0.1, @d-fischer/shared-utils@npm:^3.2.0, @d-fischer/shared-utils@npm:^3.4.0, @d-fischer/shared-utils@npm:^3.5.0":
version: 3.6.3
resolution: "@d-fischer/shared-utils@npm:3.6.3"
dependencies:
Expand All @@ -1083,7 +1074,7 @@ __metadata:
languageName: node
linkType: hard

"@d-fischer/typed-event-emitter@npm:^3.3.0, @d-fischer/typed-event-emitter@npm:^3.3.1":
"@d-fischer/typed-event-emitter@npm:^3.3.0":
version: 3.3.2
resolution: "@d-fischer/typed-event-emitter@npm:3.3.2"
dependencies:
Expand Down Expand Up @@ -1231,10 +1222,6 @@ __metadata:
version: 0.0.0-use.local
resolution: "@dotabod/twitch-events@workspace:packages/twitch/events"
dependencies:
"@twurple/api": 6.0.9
"@twurple/auth": 6.0.9
"@twurple/eventsub-base": 6.0.9
"@twurple/eventsub-http": 6.0.9
"@types/express": ^4.17.17
express: ^4.18.2
node-gyp: ^9.4.0
Expand Down Expand Up @@ -2584,19 +2571,6 @@ __metadata:
languageName: node
linkType: hard

"@twurple/api-call@npm:7.0.2":
version: 7.0.2
resolution: "@twurple/api-call@npm:7.0.2"
dependencies:
"@d-fischer/cross-fetch": ^5.0.1
"@d-fischer/qs": ^7.0.2
"@d-fischer/shared-utils": ^3.6.1
"@twurple/common": 7.0.2
tslib: ^2.0.3
checksum: a662de7f1159c0090fc1b92c2b1c6396548bec201a2c0cc877cf96cde87b16b93d44a1f1cf66c47bf8033ebaa62e3834e497281bd3496fa846697c14d792251f
languageName: node
linkType: hard

"@twurple/api@npm:6.0.9":
version: 6.0.9
resolution: "@twurple/api@npm:6.0.9"
Expand All @@ -2616,27 +2590,6 @@ __metadata:
languageName: node
linkType: hard

"@twurple/api@npm:7.0.2":
version: 7.0.2
resolution: "@twurple/api@npm:7.0.2"
dependencies:
"@d-fischer/cache-decorators": ^3.0.0
"@d-fischer/cross-fetch": ^5.0.1
"@d-fischer/detect-node": ^3.0.1
"@d-fischer/logger": ^4.2.1
"@d-fischer/rate-limiter": ^0.7.2
"@d-fischer/shared-utils": ^3.6.1
"@d-fischer/typed-event-emitter": ^3.3.1
"@twurple/api-call": 7.0.2
"@twurple/common": 7.0.2
retry: ^0.13.1
tslib: ^2.0.3
peerDependencies:
"@twurple/auth": 7.0.2
checksum: 7a2d98ef2b934b6f77c61e4999d0e0e45b8587c47abf410be4b37d88f64952f5f2739ca2ccd2d3333b243d7f525e23c4a097aac7268b08ae956726421476c243
languageName: node
linkType: hard

"@twurple/auth@npm:6.0.9":
version: 6.0.9
resolution: "@twurple/auth@npm:6.0.9"
Expand All @@ -2650,36 +2603,22 @@ __metadata:
languageName: node
linkType: hard

"@twurple/auth@npm:7.0.2":
version: 7.0.2
resolution: "@twurple/auth@npm:7.0.2"
dependencies:
"@d-fischer/logger": ^4.2.1
"@d-fischer/shared-utils": ^3.6.1
"@d-fischer/typed-event-emitter": ^3.3.1
"@twurple/api-call": 7.0.2
"@twurple/common": 7.0.2
tslib: ^2.0.3
checksum: 339301ca5ad6dcb4cb1ee53c5e65b941cbb83cbb73a5910cb6f4bab176e0437145137afc4358f59d5e533933daecf818af11c82ce38a432a13246ec988a8fe30
languageName: node
linkType: hard

"@twurple/chat@npm:7.0.2":
version: 7.0.2
resolution: "@twurple/chat@npm:7.0.2"
"@twurple/chat@npm:6.0.9":
version: 6.0.9
resolution: "@twurple/chat@npm:6.0.9"
dependencies:
"@d-fischer/cache-decorators": ^3.0.0
"@d-fischer/deprecate": ^2.0.2
"@d-fischer/logger": ^4.2.1
"@d-fischer/rate-limiter": ^0.7.2
"@d-fischer/shared-utils": ^3.6.1
"@d-fischer/shared-utils": ^3.4.0
"@d-fischer/typed-event-emitter": ^3.3.0
"@twurple/common": 7.0.2
ircv3: ^0.32.3
"@twurple/common": 6.0.9
ircv3: ^0.31.6
tslib: ^2.0.3
peerDependencies:
"@twurple/auth": 7.0.2
checksum: 1597d0bb8a2ca9321550d0914eae17ff01fcde39ed8d78cbdb6fca722b8c547fa24d280a942afe39a6f399b1181fbd58023ce7513bed7672fe1ce9258115ab14
"@twurple/auth": 6.0.9
checksum: 0f35cacdb5cd7a36d886a51379e7efcb2af0c3e117b775d2e842dcabf9b5e7b4bfe2e2706da779aa3a0bf9150ae78a8fdec3071e9ade8fdfc593ff6aa59ae034
languageName: node
linkType: hard

Expand All @@ -2694,17 +2633,6 @@ __metadata:
languageName: node
linkType: hard

"@twurple/common@npm:7.0.2":
version: 7.0.2
resolution: "@twurple/common@npm:7.0.2"
dependencies:
"@d-fischer/shared-utils": ^3.6.1
klona: ^2.0.4
tslib: ^2.0.3
checksum: 2c79cd1728ae401670172fdf70c1caf8354eaa66e0b92e063a40ef739409ad56df36258d53743c17f3f6417b63be65d59b5b5c80f98610f64a5c56e6823059e8
languageName: node
linkType: hard

"@twurple/eventsub-base@npm:6.0.9":
version: 6.0.9
resolution: "@twurple/eventsub-base@npm:6.0.9"
Expand All @@ -2720,21 +2648,6 @@ __metadata:
languageName: node
linkType: hard

"@twurple/eventsub-base@npm:7.0.2":
version: 7.0.2
resolution: "@twurple/eventsub-base@npm:7.0.2"
dependencies:
"@d-fischer/logger": ^4.2.1
"@d-fischer/shared-utils": ^3.6.1
"@d-fischer/typed-event-emitter": ^3.3.0
"@twurple/api": 7.0.2
"@twurple/auth": 7.0.2
"@twurple/common": 7.0.2
tslib: ^2.0.3
checksum: 04601cd49181f802da8fd84b1021a3d1bd1fc8bef507c5c0a4e9243ea523f86206c80493795d4eed90510fa2952579ef7be93ac4cdd05ad7337964eb63f59f42
languageName: node
linkType: hard

"@twurple/eventsub-http@npm:6.0.9":
version: 6.0.9
resolution: "@twurple/eventsub-http@npm:6.0.9"
Expand Down Expand Up @@ -3048,7 +2961,7 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^14.11.2":
"@types/node@npm:^14.11.2, @types/node@npm:^14.14.19":
version: 14.18.62
resolution: "@types/node@npm:14.18.62"
checksum: 1335b4d58d2a21c7f60b8b78d0902ec0653a44f1ead4e921c37dd5f836910e0b00370abfde02c57bc3a73a35ebcbf4ef86b598be9a9ec13981a9a6d40e98fab0
Expand Down Expand Up @@ -4820,10 +4733,11 @@ __metadata:
resolution: "dotabod@workspace:."
dependencies:
"@supabase/supabase-js": ^2.34.0
"@twurple/api": 7.0.2
"@twurple/auth": 7.0.2
"@twurple/chat": 7.0.2
"@twurple/eventsub-base": 7.0.2
"@twurple/api": 6.0.9
"@twurple/auth": 6.0.9
"@twurple/chat": 6.0.9
"@twurple/eventsub-base": 6.0.9
"@twurple/eventsub-http": 6.0.9
"@types/node": ^20.6.2
"@typescript-eslint/eslint-plugin": ^6.7.2
"@typescript-eslint/parser": ^6.7.2
Expand Down Expand Up @@ -6499,18 +6413,19 @@ __metadata:
languageName: node
linkType: hard

"ircv3@npm:^0.32.3":
version: 0.32.3
resolution: "ircv3@npm:0.32.3"
"ircv3@npm:^0.31.6":
version: 0.31.7
resolution: "ircv3@npm:0.31.7"
dependencies:
"@d-fischer/connection": ^8.0.5
"@d-fischer/connection": ^8.0.2
"@d-fischer/escape-string-regexp": ^5.0.0
"@d-fischer/logger": ^4.2.1
"@d-fischer/shared-utils": ^3.5.0
"@d-fischer/typed-event-emitter": ^3.3.0
"@types/node": ^14.14.19
klona: ^2.0.5
tslib: ^2.4.1
checksum: e63e4971210baf2591f3a4cace5381af1eb485509661ee9271f614caf3951e863a9f47ca180b0da1c0d4df5cae7cfd7d62d4c24b20fc70cec1267824c2bac7cf
checksum: 767242bf8d4dd8ce473cf99b1f3447e1764df0474bd5c59810f6b79da6bf5aa43421ea58e994bb65209192aaee35e158ac9332e55ed62b10f2c6f2da381aa0b1
languageName: node
linkType: hard

Expand Down

0 comments on commit 67d95bc

Please sign in to comment.