@opentabs-dev/opentabs-plugin-twitch 0.0.74
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 +159 -0
- package/dist/adapter.iife.js +15103 -0
- package/dist/adapter.iife.js.map +7 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/get-channel-emotes.d.ts +10 -0
- package/dist/tools/get-channel-emotes.d.ts.map +1 -0
- package/dist/tools/get-channel-emotes.js +38 -0
- package/dist/tools/get-channel-emotes.js.map +1 -0
- package/dist/tools/get-current-user.d.ts +18 -0
- package/dist/tools/get-current-user.d.ts.map +1 -0
- package/dist/tools/get-current-user.js +27 -0
- package/dist/tools/get-current-user.js.map +1 -0
- package/dist/tools/get-game-clips.d.ts +31 -0
- package/dist/tools/get-game-clips.d.ts.map +1 -0
- package/dist/tools/get-game-clips.js +44 -0
- package/dist/tools/get-game-clips.js.map +1 -0
- package/dist/tools/get-game.d.ts +15 -0
- package/dist/tools/get-game.d.ts.map +1 -0
- package/dist/tools/get-game.js +32 -0
- package/dist/tools/get-game.js.map +1 -0
- package/dist/tools/get-stream.d.ts +24 -0
- package/dist/tools/get-stream.d.ts.map +1 -0
- package/dist/tools/get-stream.js +36 -0
- package/dist/tools/get-stream.js.map +1 -0
- package/dist/tools/get-streams-by-game.d.ts +25 -0
- package/dist/tools/get-streams-by-game.d.ts.map +1 -0
- package/dist/tools/get-streams-by-game.js +44 -0
- package/dist/tools/get-streams-by-game.js.map +1 -0
- package/dist/tools/get-top-games.d.ts +14 -0
- package/dist/tools/get-top-games.d.ts.map +1 -0
- package/dist/tools/get-top-games.js +30 -0
- package/dist/tools/get-top-games.js.map +1 -0
- package/dist/tools/get-top-streams.d.ts +23 -0
- package/dist/tools/get-top-streams.d.ts.map +1 -0
- package/dist/tools/get-top-streams.js +34 -0
- package/dist/tools/get-top-streams.js.map +1 -0
- package/dist/tools/get-user-clips.d.ts +31 -0
- package/dist/tools/get-user-clips.d.ts.map +1 -0
- package/dist/tools/get-user-clips.js +44 -0
- package/dist/tools/get-user-clips.js.map +1 -0
- package/dist/tools/get-user-profile.d.ts +20 -0
- package/dist/tools/get-user-profile.d.ts.map +1 -0
- package/dist/tools/get-user-profile.js +31 -0
- package/dist/tools/get-user-profile.js.map +1 -0
- package/dist/tools/get-user-videos.d.ts +30 -0
- package/dist/tools/get-user-videos.d.ts.map +1 -0
- package/dist/tools/get-user-videos.js +58 -0
- package/dist/tools/get-user-videos.js.map +1 -0
- package/dist/tools/get-video.d.ts +23 -0
- package/dist/tools/get-video.d.ts.map +1 -0
- package/dist/tools/get-video.js +50 -0
- package/dist/tools/get-video.js.map +1 -0
- package/dist/tools/schemas.d.ts +153 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/schemas.js +160 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/search-categories.d.ts +14 -0
- package/dist/tools/search-categories.d.ts.map +1 -0
- package/dist/tools/search-categories.js +29 -0
- package/dist/tools/search-categories.js.map +1 -0
- package/dist/tools/search-channels.d.ts +31 -0
- package/dist/tools/search-channels.d.ts.map +1 -0
- package/dist/tools/search-channels.js +56 -0
- package/dist/tools/search-channels.js.map +1 -0
- package/dist/tools.json +1492 -0
- package/dist/twitch-api.d.ts +6 -0
- package/dist/twitch-api.d.ts.map +1 -0
- package/dist/twitch-api.js +90 -0
- package/dist/twitch-api.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const isAuthenticated: () => boolean;
|
|
2
|
+
export declare const waitForAuth: () => Promise<boolean>;
|
|
3
|
+
export declare const getUserId: () => string;
|
|
4
|
+
export declare const getLogin: () => string;
|
|
5
|
+
export declare const gql: <T>(query: string, variables?: Record<string, unknown>) => Promise<T>;
|
|
6
|
+
//# sourceMappingURL=twitch-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twitch-api.d.ts","sourceRoot":"","sources":["../src/twitch-api.ts"],"names":[],"mappings":"AA8CA,eAAO,MAAM,eAAe,QAAO,OAA6B,CAAC;AAEjE,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,OAAO,CAOnD,CAAC;AAEF,eAAO,MAAM,SAAS,QAAO,MAI5B,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,MAI3B,CAAC;AAQF,eAAO,MAAM,GAAG,GAAU,CAAC,EAAE,OAAO,MAAM,EAAE,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,OAAO,CAAC,CAAC,CA6C1F,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ToolError, fetchFromPage, httpStatusToToolError, getCookie, getAuthCache, setAuthCache, clearAuthCache, waitUntil, } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
const GQL_URL = 'https://gql.twitch.tv/gql';
|
|
3
|
+
const CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
|
|
4
|
+
const getAuth = () => {
|
|
5
|
+
const cached = getAuthCache('twitch');
|
|
6
|
+
if (cached)
|
|
7
|
+
return cached;
|
|
8
|
+
const token = getCookie('auth-token');
|
|
9
|
+
if (!token)
|
|
10
|
+
return null;
|
|
11
|
+
// twilight-user cookie has user info as URL-encoded JSON
|
|
12
|
+
let userId = '';
|
|
13
|
+
let login = '';
|
|
14
|
+
const twilightUser = getCookie('twilight-user');
|
|
15
|
+
if (twilightUser) {
|
|
16
|
+
try {
|
|
17
|
+
const parsed = JSON.parse(decodeURIComponent(twilightUser));
|
|
18
|
+
userId = parsed.id ?? '';
|
|
19
|
+
login = parsed.login ?? '';
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// ignore parse errors
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const auth = { token, userId, login };
|
|
26
|
+
setAuthCache('twitch', auth);
|
|
27
|
+
return auth;
|
|
28
|
+
};
|
|
29
|
+
export const isAuthenticated = () => getAuth() !== null;
|
|
30
|
+
export const waitForAuth = async () => {
|
|
31
|
+
try {
|
|
32
|
+
await waitUntil(() => isAuthenticated(), { interval: 500, timeout: 5000 });
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const getUserId = () => {
|
|
40
|
+
const auth = getAuth();
|
|
41
|
+
if (!auth)
|
|
42
|
+
throw ToolError.auth('Not authenticated — please log in to Twitch.');
|
|
43
|
+
return auth.userId;
|
|
44
|
+
};
|
|
45
|
+
export const getLogin = () => {
|
|
46
|
+
const auth = getAuth();
|
|
47
|
+
if (!auth)
|
|
48
|
+
throw ToolError.auth('Not authenticated — please log in to Twitch.');
|
|
49
|
+
return auth.login;
|
|
50
|
+
};
|
|
51
|
+
export const gql = async (query, variables) => {
|
|
52
|
+
const auth = getAuth();
|
|
53
|
+
if (!auth)
|
|
54
|
+
throw ToolError.auth('Not authenticated — please log in to Twitch.');
|
|
55
|
+
const body = { query };
|
|
56
|
+
if (variables)
|
|
57
|
+
body.variables = variables;
|
|
58
|
+
// gql.twitch.tv uses Access-Control-Allow-Origin: * which is incompatible with
|
|
59
|
+
// credentials:'include'. Auth is via the OAuth header, not cookies.
|
|
60
|
+
const response = await fetchFromPage(GQL_URL, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
credentials: 'omit',
|
|
63
|
+
headers: {
|
|
64
|
+
'Client-Id': CLIENT_ID,
|
|
65
|
+
Authorization: `OAuth ${auth.token}`,
|
|
66
|
+
'Content-Type': 'application/json',
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(body),
|
|
69
|
+
});
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
if (response.status === 401 || response.status === 403) {
|
|
72
|
+
clearAuthCache('twitch');
|
|
73
|
+
}
|
|
74
|
+
throw httpStatusToToolError(response, 'Twitch GQL request failed');
|
|
75
|
+
}
|
|
76
|
+
const result = (await response.json());
|
|
77
|
+
// GraphQL can return both data and errors — only throw if there's no data
|
|
78
|
+
if (result.errors?.length && !result.data) {
|
|
79
|
+
const msg = result.errors.map(e => e.message).join('; ');
|
|
80
|
+
if (msg.includes('failed integrity check')) {
|
|
81
|
+
throw ToolError.auth('This operation requires Twitch integrity verification and cannot be performed via the plugin.');
|
|
82
|
+
}
|
|
83
|
+
throw ToolError.internal(`Twitch GQL error: ${msg}`);
|
|
84
|
+
}
|
|
85
|
+
if (!result.data) {
|
|
86
|
+
throw ToolError.internal('Twitch GQL returned no data');
|
|
87
|
+
}
|
|
88
|
+
return result.data;
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=twitch-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twitch-api.js","sourceRoot":"","sources":["../src/twitch-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,SAAS,GACV,MAAM,0BAA0B,CAAC;AAElC,MAAM,OAAO,GAAG,2BAA2B,CAAC;AAC5C,MAAM,SAAS,GAAG,gCAAgC,CAAC;AAQnD,MAAM,OAAO,GAAG,GAAsB,EAAE;IACtC,MAAM,MAAM,GAAG,YAAY,CAAa,QAAQ,CAAC,CAAC;IAClD,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,yDAAyD;IACzD,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,MAAM,YAAY,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;IAChD,IAAI,YAAY,EAAE,CAAC;QACjB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,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AAI,GAAG,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAC3C,MAAM,SAAS,CAAC,IAAI,CAClB,+FAA+F,CAChG,CAAC;QACJ,CAAC;QACD,MAAM,SAAS,CAAC,QAAQ,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,SAAS,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opentabs-dev/opentabs-plugin-twitch",
|
|
3
|
+
"description": "OpenTabs plugin for Twitch",
|
|
4
|
+
"version": "0.0.74",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/adapter.iife.js",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"opentabs-plugin"
|
|
9
|
+
],
|
|
10
|
+
"opentabs": {
|
|
11
|
+
"displayName": "Twitch",
|
|
12
|
+
"description": "OpenTabs plugin for Twitch \u2014 browse streams, search channels and games, view clips and videos",
|
|
13
|
+
"urlPatterns": [
|
|
14
|
+
"*://*.twitch.tv/*"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://www.twitch.tv"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc && opentabs-plugin build",
|
|
30
|
+
"dev": "tsc --watch --preserveWatchOutput & opentabs-plugin build --watch",
|
|
31
|
+
"type-check": "tsc --noEmit",
|
|
32
|
+
"lint": "biome lint src/",
|
|
33
|
+
"lint:fix": "biome lint --fix src/",
|
|
34
|
+
"format:check": "biome format src/",
|
|
35
|
+
"format": "biome format --write src/",
|
|
36
|
+
"check": "npm run build && npm run type-check && npm run lint && npm run format:check"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"zod": "^4.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@opentabs-dev/plugin-sdk": "^0.0.74"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@biomejs/biome": "2.4.6",
|
|
49
|
+
"@opentabs-dev/plugin-tools": "^0.0.74",
|
|
50
|
+
"jiti": "^2.6.1",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"zod": "^4.3.6"
|
|
53
|
+
}
|
|
54
|
+
}
|